Day 09 of 30 · LLVM IR
Generate IR from your AST
- Time
- About 150 minutes: 45 reading, 75 lab, 20 testing, 10 notes.
Toolchain: LLVM 17
Use your LLVM 17 clang++, llvm-as and opt for book exercises, by explicit path. Use the matching archived documentation. Do not mix headers, libraries or plugins with your current-main build. Setup guide
Learn
- LLVMContext, Module, IRBuilder and the verification boundary.
Read Reading
- R1 · Learn LLVM 17, Second Edition
Chapter 4: AST-to-IR generation · 35 min - R7 · LLVM frontend tutorial
Tutorial chapter 3, as a reference only · 10 min
Reading budgets cover selected sections, not whole chapters. Link to the book; this site does not reproduce it.
Build Build or investigate
- Extend the existing expression project to generate an i32-returning function using the LLVM 17 C++ API.
- Start with literals, addition and multiplication.
- Verify the module and print IR.
- Bind the build to the LLVM 17 CMake package.
Done when
The same frontend produces valid IR for three expressions; no second toy compiler is required.
Recall question
What catches a malformed IR function before it reaches machine-code generation?
Completion checks
Progress tracking needs JavaScript. The lesson above is complete without it.
Notes
Saved only in this browser. Keep it short enough to finish in ten minutes; none of the prompts are required. All notes, export and import