Files
Odin/core/rexcode/ir/spirv/reloc.odin
Brendan Punsky 7a8684f541 rexcode/ir/spirv: scaffold the SPIR-V IR package (foundation + generated tables)
Start the SPIR-V intermediate representation under core/rexcode/ir/spirv,
following the ir API (docs/ir_design.md) and the ISA package conventions. SPIR-V
is table-driven on encoding and SSA on dataflow, so it re-exports the shared ir
vocabulary and is laid out like an arch package.

  spirv.odin          package + ir re-exports + physical format (MAGIC, version,
                      Header, wordCount<<16|opcode framing)
  module.odin         Module :: struct { using base: ir.Module, ...sections... } --
                      capabilities, ext-imports, entry points, exec modes, constant
                      pool, decorations, debug; SPIR-V's module metadata has no
                      ir.Module slot, so it is carried alongside the core
  reloc.odin          Relocation (linkage import/export)
  opcodes.odin        GENERATED: the Opcode enum (873 opcodes)
  operand_kinds.odin  GENERATED: ValueEnum/BitEnum operand kinds + Spec_Kind
  tablegen/gen.odin   the generator (core:encoding/json)
  tablegen/spirv.core.grammar.json  vendored authoritative grammar (Khronos
                      SPIRV-Headers unified1) -- single source of truth

Generating from the authoritative grammar avoids hand-transcription errors
(hand-authoring had Quads/Aliased/... wrong). Package compiles. Codec
(encode/decode + flat<->structured lowering), printer, and tests are next.
2026-06-26 06:53:46 -04:00

30 lines
1.3 KiB
Odin

// rexcode · Brendan Punsky (dotbmp@github), original author
package rexcode_spirv
// =============================================================================
// SECTION: Relocation (SPIR-V linkage fixups -- the per-IR reloc.odin)
// =============================================================================
//
// SPIR-V is normally self-contained: operands reference entities by <id>,
// resolved structurally, with no cross-object fixups. The one exception is
// *linkage*: an <id> decorated `LinkageAttributes` with `Import` is defined in
// another module and `Export` is offered to one. A linker matching imports to
// exports by name is the SPIR-V analog of an object-file symbol fixup, so it is
// surfaced as a `Relocation` the way each arch surfaces its own (parallel to an
// arch's reloc.odin), produced by `encode` for EXTERNAL references.
//
// Not #packed (unlike the small ISA Relocation): the linkage name is a string.
Relocation_Type :: enum u8 {
NONE,
IMPORT, // the <id> is imported (LinkageType Import) -- undefined here
EXPORT, // the <id> is exported (LinkageType Export) -- visible to other modules
}
Relocation :: struct {
id: Id, // the <id> carrying the LinkageAttributes decoration
name: string, // the external linkage name to match across modules
type: Relocation_Type,
}