llvm clang struct creating functions on the fly

Posted by anon on Stack Overflow See other posts from Stack Overflow or by anon
Published on 2010-04-04T05:48:31Z Indexed on 2010/04/04 5:53 UTC
Read the original article Hit count: 275

Filed under:
|

I'm using LLVM-clang on Linux.

Suppose in foo.cpp I have:

struct Foo {
  int x, y;
};

How can I create a function "magic" such that:

typedef (Foo) SomeFunc(Foo a, Foo b);

SomeFunc func = magic("struct Foo { int x, y; };");

so that:

func(SomeFunc a, SomeFunc b); // returns a.x + b.y;

?

Note:

So basically, "magic" needs to take a char*, have LLVM parse it to get how C++ lays out the struct, then create a function on the fly that returns a.x + b.y;

Thanks!

© Stack Overflow or respective owner

Related posts about llvm

Related posts about jit