ilusm.dev

ilu

Bytecode builder surface for the machine (mch) domain - lower an AST instruction to its bytecode encoding, build a validated program object from an instruction list, compute the total encoded byte length of an instruction sequence, and patch a 16-bit jump target into an instruction.

Load with: use ilu

What this module does

ilu is the thin bridge between the compiler's instruction list and the mcde (machine code) backend. It wraps four mcde primitives - lowering, building, layout, and jump patching - behind the stable ilu.* namespace so that compiler passes don't need to import mcde directly.

A typical compiler pipeline: produce an instruction list → call ilu.layout to know the byte offset of each instruction → back-patch jumps with ilu.jmp16 → call ilu.build to get a validated program object → hand it to emit.ilbc.

Quick example

use ilu

ins = compiler_output_instructions()

# Compute total byte length
total = ilu.layout(ins)

# Patch a jump at instruction index 3 to target instruction 10
ilu.jmp16(ins, 3, 10)

# Build a validated program object
prog = ilu.build(ins, constants, names, defs)

# Write bytecode
emit.ilbc(prog, "out/main.ilbc")

Functions

Lowering and building

ilu.lower(ins) / ilulo(ins)

Lowers an AST instruction to its encoded bytecode representation via mcdulo.

ilu.build(ins, cs, nm, df) / ilubld(ins, cs, nm, df)

Assembles a program object {cd: ins, cs, nm, df} from an instruction list, constant pool (cs), name table (nm), and definitions (df). Validates the program with mcdchk and returns it.

Layout and patching

ilu.layout(ins) / ilula(ins)

Computes the total encoded byte length of an instruction sequence by iterating through the list and summing mcdlen for each instruction. Use the result to compute jump target byte offsets.

ilu.jmp16(ins, jmp_ix, target_ix) / ilujmp(ins, jmp_ix, target_ix)

Patches a 16-bit jump operand at instruction index jmp_ix to point to target_ix via mcdat16. Call after computing the final layout.

Notes

  • All functions delegate directly to mcde.ilu in the backend directory.
  • Requires the backend mcde module.