Files
Odin/core/rexcode/ir/status.odin
Brendan Punsky daa5b7cb79 rexcode: add core:rexcode/ir — the IR API layer (no concrete IR yet)
A sibling to core:rexcode/isa for the intermediate representations (WASM,
SPIR-V, LLVM bitcode + the LLVM dialects AIR/DXIL). Holds the shared
vocabulary every IR package builds on, implements no specific IR.

Design stance (see docs/ir_design.md): keep the ISA layer's spirit, but
where IRs are structurally MORE uniform than ISAs (SSA + a type system
regularize the operand/module shape), the shared core is richer. ir/ owns:

  status.odin  Error/Error_Code (shape-identical to isa.Error)
  refs.odin    Id/Ref/Ref_Space/Symbol_Table (the label analog: structural
               id references, not PC-relative byte offsets)
  types.odin   Type/Type_Ref/Type_Kind (the type table -- no ISA analog)
  module.odin  Module/Function/Block/Operation/Operand/Result/Dataflow
               (the structured model; Operation = isa.Instruction + an
               optional typed Result, opcode a u16 like Mnemonic)
  print.odin   token kinds + options + num-fmt (parallels isa.print)

Three honest concessions vs the ISA API, made explicit not inert: a
structured Module replaces the flat []Instruction; a first-class type
system; id-based entity refs replace labels. The encode/decode verbs take
a Module and drop label_defs/resolve/base_address. Dataflow hosts both the
WASM value stack and SSA; the codec is pluggable (table for WASM/SPIR-V,
bitstream for the LLVM family -- AIR/DXIL are LLVM dialects, not peers).

Package compiles; a hand-built SSA module round-trips through the types.
2026-06-18 19:03:27 -04:00

43 lines
1.6 KiB
Odin

// rexcode · Brendan Punsky (dotbmp@github), original author
package rexcode_ir
// =============================================================================
// ERROR / RESULT TYPES (shared by every IR codec)
// =============================================================================
//
// Parallels isa.status. The `Error` struct shape is intentionally identical to
// `isa.Error` (8 bytes: a u32 location + a 1-byte code) so a tool can surface
// ISA and IR diagnostics through one path. `Error_Code` keeps the encode/decode
// codes shared with the ISA side, then adds the codes only a *typed, structured*
// IR can produce. Per-IR codecs emit the subset that applies to them.
Error_Code :: enum u8 {
NONE = 0,
// Shared with the ISA side (encode/decode of the byte/word stream).
INVALID_OPCODE,
NO_MATCHING_ENCODING,
OPERAND_MISMATCH,
IMMEDIATE_OUT_OF_RANGE,
BUFFER_OVERFLOW,
BUFFER_TOO_SHORT,
// IR-specific (no ISA analog -- these need a type system / SSA / a module).
INVALID_TYPE, // malformed or out-of-range Type_Ref
TYPE_MISMATCH, // an operand/result type disagrees with the op signature
UNDEFINED_REF, // a Ref to an id/symbol that is never defined
DUPLICATE_DEFINITION, // an id/symbol defined twice
MALFORMED_MODULE, // structural violation (block without terminator, ...)
UNSUPPORTED_FEATURE, // a capability/extension the codec does not implement
}
// `location` is the operation index on encode, or the byte offset on decode --
// mirroring isa.Error.inst_idx.
Error :: struct #packed {
location: u32,
code: Error_Code,
_: [3]u8,
}
#assert(size_of(Error) == 8)