Reputation: 41
I'm writing a compiler that embeds the LLVM API. By copying code from the llc tool, I can output assembly language or object files that I can turn into binaries using clang or an assembler.
But I want my compiler to be self contained. Is it possible to turn LLIR into binaries using LLVM? This seems like the sort of thing that should be in the LLVM toolkit.
Upvotes: 2
Views: 910
Reputation: 34411
Yes, it is possible and this is also done by llc
with -filetype=obj
argument.
You can consult the compileModule
function to learn how to use the programmatic API.
Note that this will only generate an object file for a given translation unit. You will also need a linker to convert it into a proper executable or library. The LLVM linker, lld
, can also be embedded into client applications as a library, so in the end you will be able to create a self-hosting compiler.
Upvotes: 2