[LLVMdev] Compile, link and run on the fly
rnk at mit.edu
Thu Apr 15 13:21:59 PDT 2010
2010/4/15 Radovan Baranec <rado.baranec at gmail.com>:
> First of all thanks for fast replay. I appreciated it:-)
>> Is your compiler written in C++ or something that can interface with
>> it easily? If so, you should probably check out the JIT, and the
>> tutorial here:
> Yes my compiler is written in C++ and I had followed tutorial you mentioned.
>> It sounds like you're generating LLVM IL and dumping it to a .ll file
>> in your own compiler, so you'll probably have to just add some driver
>> code to your compiler that drives llvm-as, opt, llvm-link, and llc.
> Yes I am generating LLVM IR and dumping it to, so far only, .s file using my
> compiler. Other two modules are already manually written so I need the one
> that I generate to link with other two and run. And this was precisely my
> question about. Is it even possible to do so? Can I generate only one
> module, link it with other two and run, everything on the fly in my
> compiler? It will be like glued everything together in one binary file
> (compiler), all phases: compiling, linking, running using single binary.
> From your answer I partially assumed that it is possible. Can you recommend
> me some other tutorial or sample code?
No, you can link the modules and run them on the fly. If you look at
the source code for llvm-link, opt, and lli, you can see that they are
thin wrappers around LLVM library functions that you should be able to
call yourself from your own code.
So you would probably compile each module, link them together with
Linker::LinkModules, optimize them via your own FuncitonPassManager,
and run them with the JIT ExecutionEngine.
More information about the llvm-dev