我在 Linux 上使用 LLVM-clang。
假设在 foo.cpp 我有:
struct Foo {
int x, y;
};
我怎样才能创建一个函数“魔术”,这样:
typedef (Foo) SomeFunc(Foo a, Foo b);
SomeFunc func = magic("struct Foo { int x, y; };");
以便:
func(SomeFunc a, SomeFunc b); // returns a.x + b.y;
?
笔记:
所以基本上,“魔术”需要一个char*
,让 LLVM 解析它以获取 C++ 如何布局结构,然后动态创建一个返回的函数a.x + b.y;