Skip to content

Source: MoonLiveIr.h

moonlive_ir

The typed form between the front-end and the per-ISA assembler.

The front-end lowers an AST to a flat list of three-address ops over virtual registers, and each backend lowers that same list to machine bytes. Compile-time only, consumed during lowering and never present at run time.

Classes

Name Description
IrInst
DeclaredControl
IrProgram

IrInst

struct IrInst
src/core/moonlive/MoonLiveIr.h:88

Public Attributes

IrOp op : Which operation this instruction performs.

VReg dst = 0 : The destination register.

VReg a = 0 : The source registers, which each opcode reads as it needs.

VReg b = 0

VReg c = 0

VReg d = 0

int32_t imm = 0 : The immediate, or an address offset, by opcode.

HostCallFn callFn = nullptr : The host function a Call targets.

const void * ptr = nullptr : The address a ConstPtr materializes.

InlineOp inlineOp {} : The neutral opcode tag an Inline op carries.

DeclaredControl

struct DeclaredControl
src/core/moonlive/MoonLiveIr.h:107

Public Attributes

const char * name = nullptr : The name the script declared, pointing into the source buffer.

int32_t min = 0 : The UI range, as wide as the widest member a control can bind.

int32_t max = 255

int32_t def = 0 : The initializer, wide enough for the widest member type.

uint8_t nameLen = 0 : How many characters of name are used.

CtrlType type = CtrlType::Int : The member's element type, from which its width derives.

uint8_t offset = 0 : Byte offset into the controls arena, which everything downstream keys on.

uint8_t count = 1 : Elements: 1 for a scalar, the length for an array.

IrProgram

struct IrProgram
src/core/moonlive/MoonLiveIr.h:171

Public Attributes

IrInst * ops = nullptr : The lowered ops, heap-allocated and sized to the script.

uint16_t cap = 0 : How many op entries are allocated.

uint16_t count = 0 : How many ops the program holds.

VReg vregsUsed = kFirstTemp : The high-water mark of virtual registers this program names.

uint8_t localSlots = 0 : Frame slots the front end allocated for script variables.

uint16_t fnIrStart = {} : Where each named function's code starts, filled in as the lowering walks the ops.

uint16_t fnOffset = {} : The byte each named function starts at, which the lowering fills.

uint8_t fnCount = 0 : How many named functions the program defines.

Public Methods

IrProgram() = default : An empty program, until reserve sizes its op array.

inline ~IrProgram() : Release the op array.

IrProgram(const IrProgram &) = delete : Never copied: it owns a buffer, and two owners would double-free.

inline bool reserve(uint16_t n) : Size the op array to n entries, returning false when it cannot be allocated.

inline bool push(const IrInst & i) : Append one op, returning false when it names a register outside the budget.

inline void swap(IrProgram & o) : Exchange contents with o.

inline bool hasInline(InlineOp which) const : Which inline ops this program contains, so a backend reserves only the scratch it needs.

inline bool hasScriptCall() const : Whether any function calls another, which is when the recursion depth guard is emitted.

More info

It knows operations, not targets

The IR names no instruction set and no domain: a buffer write is an inline op carrying a tag the host registered.

Virtual registers

Plain indices a backend maps to machine registers. The host arguments arrive in fixed ones, named neutrally, so the front-end refers to them without knowing the calling convention.