Saturday, 15 January 2011

compilation - How to compile a C code during execution time, and get a pointer to the corresponding function? -



compilation - How to compile a C code during execution time, and get a pointer to the corresponding function? -

suppose generate c programme during execution time:

source = "int add_x_y(int x, int y){ homecoming x + y; }"; source_size = 42;

i want next function:

void* compile(char* source, int source_size);

such that:

int (*f)(int,int) = compile(source, source_size); printf("%d\n",f(2,3));

outputs:

5

and compile can't depend on external tools (compilers), i'd utilize in emscripten (which converts c programme .js file).

is possible?

someone else can fill in of specifics improve i, if don't mind calling out gcc or linking it, should doable. if write code out file, compile file shared library (.so). there, it's simple matter of loading shared library , getting address of desired symbol.

c compilation jit

No comments:

Post a Comment