This is an example of how to prepare a function JIT compile it and call it. Here is the equavalent function we will be creating.
int add(int X, int Y)
{
auto val = X + Y;
return val;
}
- Create the context and module
- Create function header/prototype
- Extract the function parameters to be used with instructions
- Create function body block structure
- Create instructions for the block
- Create JIT compiler and add the module we prepared
- Lookup the prepared function
- Call the function
find_package(LLVM REQUIRED CONFIG)
llvm_map_components_to_libnames(LLVM_LIBS core native orcjit support)
target_link_libraries(${PROJECT_NAME} PRIVATE ${LLVM_LIBS})