Id like to write a self-hosting LLVM compiler. How should I interface with the LLVM middle-end optimizers and back-end code generators?
Your compiler front-end will communicate with LLVM by creating a module in the LLVM intermediate representation (IR) format. Assuming you want to write your language’s compiler in the language itself (rather than C++), there are 3 major ways to tackle generating LLVM IR from a front-end: • Call into the LLVM libraries code using your language’s FFI (foreign function interface). • for: best tracks changes to the LLVM IR, .ll syntax, and .bc format • for: enables running LLVM optimization passes without a emit/parse overhead • for: adapts well to a JIT context • against: lots of ugly glue code to write • Emit LLVM assembly from your compiler’s native language. • for: very straightforward to get started • against: the .ll parser is slower than the bitcode reader when interfacing to the middle end • against: you’ll have to re-engineer the LLVM IR object model and asm writer in your language • against: it may be harder to track changes to the IR • Emit LLVM bitcode from your compiler’s nati
Related Questions
- Once loaded you can write programs that communicate with instruments through the GPIB card via the Interface Select code 7. 10 OUTPUT 705;"*IDN?
- Id like to write a self-hosting LLVM compiler. How should I interface with the LLVM middle-end optimizers and back-end code generators?
- Why should an ASIC designer write code that can target an FPGA?