Skip to content
La3 Docs
Browse docs

LLVM Backend

The native backend, scalar codegen, aggregate layout, control flow, objects, and executable linking.

Backend role

The backend should translate MIR faithfully instead of owning language semantics.

The frontend and MIR layers decide what the program means. The LLVM backend is responsible for producing verified modules, objects, and linked binaries that implement those decisions.

  • The backend consumes typed MIR.
  • It emits LLVM IR with exact scalar semantics.
  • It links against the native runtime where helper symbols are needed.
  • It should report unsupported values honestly instead of emitting misleading code.

Scalars

Scalar codegen is the first correctness layer because every larger value eventually depends on it.

  • Integers compile width-exact.
  • Signedness matters for comparisons and shifts.
  • Integer division truncates toward zero.
  • Remainder keeps the left sign.
  • ** lowers through floating-point semantics.

Aggregates

Structs, tuples, and enums need stable by-value representations.

  • Structs and tuples are built field by field.
  • Enums lower to tagged unions.
  • Variant construction writes a tag and payload.
  • Matching reads the discriminant and downcasts to the payload.

Native output

The build path turns MIR into an object and links it into a runnable executable.

  • The compiler writes a native object.
  • The linker pulls in the runtime library.
  • An integer main result becomes the process exit code.
  • Compiled output is checked against interpreter output in the differential harness.