tir/builder — AST to TIR Translation

Walks a type-checked AST and produces Vec<TIROp>. Target-independent.

Files

File Purpose Key symbols
mod.rs Core struct and entry points TIRBuilder, build_file, build_fn
stmt.rs Statement emission build_block, build_stmt, build_match
expr.rs Expression emission build_expr, build_var_expr, build_field_access, build_index
call.rs Function call dispatch build_call (~40 intrinsics), build_user_call
helpers.rs Stack and control helpers parse_spill_effect, flush_stack_effects, emit_and_push, fresh_label
layout.rs Type width and struct layout format_type_name, resolve_type_width, register_struct_layout_from_type
tests.rs Unit tests builder output verification, spill parser tests

How it works

TIRBuilder maintains a StackManager that models the runtime stack with LRU spill/reload to RAM. As it walks the AST, it pushes TIROp variants and keeps the stack model in sync. Structural control flow (IfElse, Loop) captures nested bodies as Vec<TIROp> rather than emitting flat labels.

Data flow

  1. build_file — pre-scans for functions, structs, events, constants; emits preamble; iterates items
  2. build_fn — registers params on stack, walks body via build_block
  3. build_stmt — dispatches per statement kind (let/assign/if/for/match/emit/seal/asm)
  4. build_expr — dispatches per expression kind (literal/var/binop/call/tuple/array/struct)
  5. build_call — resolves intrinsics or delegates to build_user_call

Dependencies

  • TIROp — the IR operations this builder produces
  • StackManager — stack depth tracking and spill/reload
  • TerrainConfig — VM parameters (stack depth, field widths)
  • MonoInstance — resolved generic instantiations

Pages in this namespace

Local Graph