package core:rexcode/isa
Overview
rexcode · Brendan Punsky (dotbmp@github), original author
rexcode · Brendan Punsky (dotbmp@github), original author
rexcode · Brendan Punsky (dotbmp@github), original author
rexcode · Brendan Punsky (dotbmp@github), original author
Index
Constants (2)
Variables (0)
This section is empty.
Procedure Groups (0)
This section is empty.
Types
Branch_Target ¶
Branch_Target :: struct { inst_idx: u32, // which decoded instruction has the branch op_idx: u8, // which operand of that instruction is the target target: u32, }
Branch target discovered while decoding. Each branch operand a per-arch decoder produces (RELATIVE-kind operand with a known target offset) becomes one of these for pass 2.
Error ¶
Error :: struct #packed { inst_idx: u32, // Which instruction failed (or byte offset for decode) code: Error_Code, _: [3]u8, }
Error_Code ¶
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, }
Label_Definition ¶
Label_Definition :: distinct u32
----------------------------------------------------------------------------- Array-index model (used by every arch's encode/decode hot path) -----------------------------------------------------------------------------
Label_Definition maps a label ID to: - the instruction index where it's defined (input to encode), then - the byte offset of that instruction (rewritten in place by encode).
Related Constants
Label_Map ¶
Label_Map :: struct { labels: [dynamic]Label_Definition, names: map[string]u32, }
Label_Map: named labels.
Related Procedures With Parameters
Print_Options ¶
Print_Options :: struct { uppercase: bool, // uppercase mnemonics/registers hex_prefix: string, // hex prefix (default "0x") hex_lowercase: bool, label_prefix: string, // default ".L" show_offsets: bool, // show byte offsets before each instruction indent: string, // default " " separator: string, // default "\n" space_after_comma: bool, }
Related Procedures With Parameters
Related Constants
Token ¶
Token :: struct { offset: u32, // byte offset in output string length: u16, // length in bytes kind: Token_Kind, instruction_index: u16, }
Token_Kind ¶
Token_Kind :: enum u8 { WHITESPACE, // spaces, tabs, indentation NEWLINE, // line breaks LABEL_DEF, // label definition (e.g., ".L1:") LABEL_REF, // label reference in operand OFFSET, // byte offset prefix (e.g., "0x10:") MNEMONIC, // instruction mnemonic REGISTER, // register name IMMEDIATE, // immediate value MEMORY_BRACKET, // '[' or ']' MEMORY_OPERATOR, // '+', '-', '*' in memory operands MEMORY_DISP, // displacement in memory operand MEMORY_SCALE, // scale factor in memory operand PUNCTUATION, // comma separator, colon COMMENT, }
Related Procedures With Parameters
Constants
DEFAULT_PRINT_OPTIONS ¶
DEFAULT_PRINT_OPTIONS :: Print_Options{uppercase = false, hex_prefix = "0x", hex_lowercase = true, label_prefix = ".L", show_offsets = false, indent = " ", separator = "\n", space_after_comma = true}
LABEL_UNDEFINED ¶
LABEL_UNDEFINED :: Label_Definition(0xFFFFFFFF)
Variables
This section is empty.
Procedures
infer_labels_from_branches ¶
infer_labels_from_branches :: proc(branches: []Branch_Target, decoded_end: u32, label_defs: ^[dynamic]Label_Definition, relocs: []$R) {…}
Resolve branch targets into label definitions.
For each branch target inside the decoded region (target < decoded_end):
- if a label is already defined at that offset, do nothing;
- else if relocs provides a label_id for that offset (named label
carried over from the encode side), use that ID;
- else create a fresh label ID and append it.
label_defs may grow.
Parametric over the caller's relocation type $R: the body only reads
.offset and .label_id, so any per-arch Relocation struct with
those fields works. Monomorphizes at the call site with no overhead.
label ¶
label :: proc(labels: ^[dynamic]Label_Definition, instructions: ^[dynamic]$T) -> u32 {…}
Define a label at the current instruction position. Parametric on $T so any arch's Instruction type works.
label_forward ¶
label_forward :: proc(labels: ^[dynamic]Label_Definition) -> u32 {…}
Reserve a label slot for forward references.
label_map_destroy ¶
label_map_destroy :: proc(lm: ^Label_Map) {…}
label_map_init ¶
label_map_init :: proc(lm: ^Label_Map, allocator := context.allocator) {…}
label_named ¶
Define a named label at the current instruction position.
label_reserve ¶
Reserve a named label for forward reference.
label_set ¶
Define a previously reserved named label's position.
label_set_at ¶
label_set_at :: proc(labels: ^[dynamic]Label_Definition, id: u32, instructions: ^[dynamic]$T) {…}
Define a previously reserved (anonymous) label's position. Pairs with
label_forward to support 1: ... jlt <1 / ... jlt 1> ... 1: style
forward and backward local labels:
fwd := label_forward(&labels) ... encode body that references fwd ... label_set_at(&labels, fwd, &instructions)
print_decimal ¶
Print a decimal number (used for label IDs, scale factors, etc).
print_hex ¶
print_hex :: proc(sb: ^strings.Builder, value: u64, options: ^Print_Options) {…}
print_hex_digits ¶
print_hex_digits :: proc(sb: ^strings.Builder, value: u64, options: ^Print_Options) {…}
rewrite_label_defs_to_offsets ¶
rewrite_label_defs_to_offsets :: proc(label_defs: []Label_Definition, inst_offsets: []u32) {…}
token_kind_to_string ¶
token_kind_to_string :: proc(k: Token_Kind) -> string {…}
Procedure Groups
This section is empty.
Source Files
Generation Information
Generated with odin version dev-2026-07 (vendor "odin") Windows_amd64 @ 2026-07-20 21:55:30.829790500 +0000 UTC