Day 09 of 30 · LLVM IR

Generate IR from your AST

Time
About 150 minutes: 45 reading, 75 lab, 20 testing, 10 notes.
Prerequisites
Day 06: Check meaning before generating code, Day 08: Read LLVM intermediate representation

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

Reading budgets cover selected sections, not whole chapters. Link to the book; this site does not reproduce it.

Build Build or investigate

  1. Extend the existing expression project to generate an i32-returning function using the LLVM 17 C++ API.
  2. Start with literals, addition and multiplication.
  3. Verify the module and print IR.
  4. 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.

Required to complete day 09

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