Master the fundamental concepts of intermediate representation through this focused micro-challenge.
Three-address code (TAC) is the classic intermediate representation between AST and machine code. Each instruction has at most one operator and three operands: t1 = a + b. GCC lowers to GIMPLE; many textbooks use quadruples or triples. TAC flattens tree-shaped expressions into linear instruction sequences.
Binary ops: t = a op b. Copies: t = a. Jumps: goto L, if t goto L. Labels mark join points. Function calls use param and call instructions. Temporaries hold intermediate results.
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 design a simple three-address code IR with instruction and operand types. This exercise asks you to define the data structures representing TAC before you write the generator that emits them from the AST.
Design and implement a simple three-address code intermediate representation.
Define data structures:
Supported operations:
Implementation functions:
Output format: t1 = b * c t2 = a + t1 x = t2
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