mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-19 16:42:33 +00:00
Each ISA's hand-written ENCODING_TABLE (the single source of truth) now lives in a per-arch tablegen/ metaprogram that flattens it and serializes committed binary blobs; the library #loads those into @(rodata) at compile time rather than compiling a table body. No arch keeps encoding_table.odin or decoding_tables.odin -- only a generated tables.odin loader and tables/*.bin. * Two-stage, type-checked pipeline: tablegen Stage A emits human-readable generated Odin, which compiles and serializes the blobs in Stage B. * encode() goes through encoding_forms(m); decoders are unchanged apart from x86's flattened 2-D index. Decode tables are byte-identical to the old ones. * build.lua: a LuaJIT driver for the metaprograms, validations, and tests, with cross-platform gating and a clear report. * Docs refreshed; the obsolete forward-looking plan in cross_arch_design.md trimmed to what was actually built. * Attribution headers added to all rexcode source files; the generators emit them so generated files keep them.
50 lines
1.3 KiB
Odin
50 lines
1.3 KiB
Odin
// rexcode · Brendan Punsky (dotbmp@github), original author
|
|
|
|
package rexcode_isa
|
|
|
|
// =============================================================================
|
|
// ERROR / RESULT TYPES (shared by encoder and decoder, all architectures)
|
|
// =============================================================================
|
|
//
|
|
// The struct shapes are universal. Error_Code holds the full set of codes
|
|
// any architecture may produce; per-arch encoders/decoders only emit the
|
|
// subset that applies to them. When an arch needs a new code (e.g.
|
|
// RISC-V's MISALIGNED_IMMEDIATE), add it here.
|
|
|
|
Error_Code :: enum u8 {
|
|
NONE = 0,
|
|
|
|
// Shared encoding errors
|
|
INVALID_MNEMONIC,
|
|
NO_MATCHING_ENCODING,
|
|
OPERAND_MISMATCH,
|
|
IMMEDIATE_OUT_OF_RANGE,
|
|
BUFFER_OVERFLOW,
|
|
LABEL_OUT_OF_RANGE,
|
|
INVALID_OPERAND_COUNT, // operand_count > 4 or doesn't match operands
|
|
|
|
// Shared decoding errors
|
|
BUFFER_TOO_SHORT,
|
|
INVALID_OPCODE,
|
|
|
|
// x86-specific decoding errors
|
|
INVALID_MODRM,
|
|
INVALID_SIB,
|
|
INVALID_PREFIX,
|
|
INVALID_VEX,
|
|
INVALID_EVEX,
|
|
TOO_MANY_PREFIXES,
|
|
}
|
|
|
|
Error :: struct #packed {
|
|
inst_idx: u32, // Which instruction failed (or byte offset for decode)
|
|
code: Error_Code,
|
|
_: [3]u8,
|
|
}
|
|
#assert(size_of(Error) == 8)
|
|
|
|
Result :: struct {
|
|
byte_count: u32, // Bytes written/read
|
|
success: bool, // True if no errors
|
|
}
|