Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Id like to write a self-hosting LLVM compiler. How should I interface with the LLVM middle-end optimizers and back-end code generators?

0
Posted

Id like to write a self-hosting LLVM compiler. How should I interface with the LLVM middle-end optimizers and back-end code generators?

0

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

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123