Reputation: 673
I have a c++ program which can generate LLVM IR at runtime. Now I want to compile this IR into a binary from my c++ program and invoke the binary. Also before invoking I want to pass data from my c++ program to the generated binary. I am new to LLVM and I couldnt find any documentation regarding this. Could someone point to a documentation about this or let me know how this can be done.
Upvotes: 0
Views: 282
Reputation: 8088
Here are the general block and tackle steps that come to mind even though you didn't state how you want to invoke the emitted code so I will assume it is as though you are invoking another executable:
In your executable
system
, clang that will generate the new executable program from the LLVM IR.system
, call the newly generated executable and pass the data as command line arguments.LLVM IR Generated
main
function definition that takes argc and argv
as that will be what consumes the passed data that you are sending. main
body you would need to handle the command line input appropriately and call the code you originally wanted exercised.However: there are variations of this. For example, if you wanted to generate a dynamic library you could omit the generation of the main
function and instead do a run-time load of the dynamic library you just created and resolve the function entry point.
Upvotes: 1