Master the fundamental concepts of intermediate representation through this focused micro-challenge.
LLVM's -S flag prints human-readable .ll files; GCC dumps GIMPLE with -fdump-tree-ssa. A pretty-printer turns your internal IR into text you can diff, test, and round-trip. Compiler engineers spend hours reading printed IR when optimizations go wrong.
Walk instructions and emit syntax: t1 = add t2, t3. Labels on their own lines. Functions as named regions. A parser that reads the same format validates your printer and enables file-based test cases.
cLoading…
Production compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will write an IR pretty-printer and optional round-trip parser. This exercise asks you to serialize your instruction list to text and verify that parsed output reconstructs the same structure.
Implement a pretty-printer and parser for your three-address code IR that support round-trip conversion.
Format instructions:
result = arg1 op arg2result = arg1label_name:goto labelif condition goto labelAdd structure:
Output:
Read instructions:
Error handling:
Validation:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github