3

I have some troubles wrapping my head around what LLVM actually does... Am I right to assume that it could be used to parse mathematical expressions at runtime in a C++ program?

Right now at runtime, I'm getting the math expressions and build a C program out of it, compile it on the fly by doing system call to gcc. Then I dynamically load the .so produced by gcc and extract my eval function...

I'd like to replace this workflow by something simpler, maybe even faster... Can LLVM help me out? Any resources out there to get me started?

v3h3mental
  • 33
  • 1
  • 4

1 Answers1

2

You're describing using LLVM as a JIT compiler, which is absolutely possible. If you generate LLVM IR code (in memory) and hand it off to the library, it will generate machine code for you (still in memory). You can then run that code however you like.

If you want to generate LLVM IR from C code, you can also link clang as a library.

Here is a PDF I found at this answer, which has some examples of how to use LLVM as a JIT.

Community
  • 1
  • 1
Carl Norum
  • 219,201
  • 40
  • 422
  • 469