Master the fundamental concepts of code generation through this focused micro-challenge.
The stack frame holds return address, saved frame pointer, callee-saved registers, spill slots, and local variables. Clang computes frame layout in TargetFrameLowering; debug info references stack offsets for each variable.
Growing downward from high addresses: incoming arguments, return address, saved rbp, callee-saved regs, spill slots, local arrays, scalar locals. Each slot gets a negative offset from rbp or rsp.
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 and implement stack frame layout for functions. This exercise requires assigning stack offsets to locals and spill slots and generating addressing modes that reference them.
Implement stack frame layout for function calls.
Requirements:
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