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;
If you really want to do this kind of stuff, you have to link in the whole CLang, and learn how to use its complicated and constantly changing API. Are you so sure you actually need it?