10

Is it possible to do these things from a native C or C++-compiled program (gcc):

  1. Call clang and compile given C code of a function, passed as const char *.
  2. Obtain a pointer and run it in the LLVM virtual machine.
  3. Acquire the result in the native program and continue.

How?

5

1 Answer 1

7
+100

For a minimalistic example, see Clang interpreter.

Cling is bit more practical example of such an approach.

Sign up to request clarification or add additional context in comments.

2 Comments

@James, it is an interactive C++ interpreter based on LLVM and Clang and optionally integrated into ROOT. Sort of a replacement for their older Cint thing.
This is what I posted below the code. Cling implements JIT which is offered by llvm, see this link on how to use it: llvm.org/docs/tutorial/LangImpl4.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.