[cfe-dev] Compile MemoryBuffer

David PirrĂ² david.pirro at gmail.com
Wed Nov 3 09:31:56 PDT 2010


Dear Developers,

First, thank you very much for your work.
I believe clang is a great tool and I can't wait to use it in my programs.

I'm totally new to clang, but I'm willing to learn.
.... With your help :)

I believe this has been asked already many times...

So, here's my question: 
I would like to use clang in my application for scripting and definition jit-compilation of functions to be used as callbacks in the c++ application.
This is the "big" (and unclear I know) frame.
But let's go step by step...

My question is how can I jit-compile and evaluate c / c++ code packed into a string like:
"int foo(int a, int b) { int r; r=a+b; return r;}"
and then in a subsequent step evaluate:
"foo(2,3)"

I think I understood this is done using MemoryBuffers.
But I can't get it to work.
I'm currently basing my experiments on the clang-interpreter example code.

I know there are some code snippetts around the web about this issue but I can't get them all together working.
It would be extremely helpful if someone could post some "working" code to do this so that I can then use, look, experiment and understand better what's going on.
That would be great!

Thank you very much for you help in advance.

Bests,

David






More information about the cfe-dev mailing list