0

I have a C++ file, which hassome functions, such as:int myMax(int a,int b), and compile it to a llvm IR. Now I want to operate the IR in another C++ file, I don't know how to call the function(such as: myMax)in my C++ file.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
Kun Lee
  • 97
  • 1
  • 8

1 Answers1

0

You can compile IR to an object file for your platform (using llc). This object file is like any other object file produced by, say, a C++ compiler. So you can call it from your C++ code.

More concretely. You compile a file with int myMax(int a, int b) into some object file, say mymax.o. Your "user" C++ code needs to:

  1. See the declaration of myMax by including the appropriate header, or just declaring the function prototype.
  2. Link to mymax.o to have the implementation in the final executable.

Alternatively, you can use the existing JIT capability of LLVM to JIT the IR module in your C++ code and then use getPointerToFunction to access it.

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412