From eab637f2491ceb5fa2cb42155006f4b8998a1b9c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 16 Jun 2026 14:21:09 +0100 Subject: [PATCH] Improve formatting --- core/rexcode/wasm/decoder.odin | 4 +-- core/rexcode/wasm/encoding_types.odin | 20 ++++++++--- core/rexcode/wasm/operands.odin | 24 +++++-------- core/rexcode/wasm/printer.odin | 36 +++++++------------ core/rexcode/wasm/tests/pipeline_smoke.odin | 8 +---- .../rexcode/wasm/tools/dump_verify_input.odin | 36 +++++++------------ 6 files changed, 52 insertions(+), 76 deletions(-) diff --git a/core/rexcode/wasm/decoder.odin b/core/rexcode/wasm/decoder.odin index d7ca165a4..ee98bf6e6 100644 --- a/core/rexcode/wasm/decoder.odin +++ b/core/rexcode/wasm/decoder.odin @@ -185,9 +185,9 @@ decode_one :: proc( case .BR_TABLE: count := read_uleb(data, &off) or_return targets := make([]u32, int(count), targets_allocator) - for i in 0.. u32 { b := u8(v & 0x7F) v >>= 7 n += 1 - if (v == 0 && (b & 0x40) == 0) || (v == -1 && (b & 0x40) != 0) { break } + if (v == 0 && (b & 0x40) == 0) || (v == -1 && (b & 0x40) != 0) { + break + } } return n } @@ -138,7 +144,9 @@ read_uleb :: #force_inline proc "contextless" (data: []u8, offset: ^u32) -> (val b := data[offset^] offset^ += 1 value |= u64(b & 0x7F) << shift - if b & 0x80 == 0 { return value, true } + if b & 0x80 == 0 { + return value, true + } shift += 7 } return 0, false @@ -153,7 +161,9 @@ read_sleb :: #force_inline proc "contextless" (data: []u8, offset: ^u32) -> (val offset^ += 1 value |= i64(b & 0x7F) << shift shift += 7 - if b & 0x80 == 0 { break } + if b & 0x80 == 0 { + break + } } if shift < 64 && (b & 0x40) != 0 { value |= -(i64(1) << shift) diff --git a/core/rexcode/wasm/operands.odin b/core/rexcode/wasm/operands.odin index 90215b0ad..a1ea49db1 100644 --- a/core/rexcode/wasm/operands.odin +++ b/core/rexcode/wasm/operands.odin @@ -32,9 +32,8 @@ package rexcode_wasm Operand_Kind :: enum u8 { NONE, - REGISTER, // vestigial -- WASM is register-less (never produced) IMMEDIATE, // i32/i64/f32/f64 constant (floats stored as raw bits) - INDEX, // LEB128 unsigned index into one of the index spaces + INDEX, // LEB128 unsigned index into one of the index spaces MEMARG, // load/store alignment + offset pair BLOCK_TYPE, // block / loop / if signature } @@ -98,11 +97,6 @@ Operand :: struct #packed { // Generic constructors (contract surface) // ----------------------------------------------------------------------------- -@(require_results) -op_reg :: #force_inline proc "contextless" (r: Register) -> Operand { - return Operand{reg = r, kind = .REGISTER} -} - @(require_results) op_imm :: #force_inline proc "contextless" (v: i64, size: u8) -> Operand { return Operand{immediate = v, kind = .IMMEDIATE, size = size} @@ -171,14 +165,14 @@ op_index :: #force_inline proc "contextless" (kind: Index_Kind, value: u32) -> O return Operand{index = value, kind = .INDEX, idx_kind = kind} } -@(require_results) op_local :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.LOCAL, n) } -@(require_results) op_global :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.GLOBAL, n) } -@(require_results) op_func :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.FUNC, n) } -@(require_results) op_type :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.TYPE, n) } -@(require_results) op_table :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.TABLE, n) } -@(require_results) op_memory :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.MEMORY, n) } -@(require_results) op_data :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.DATA, n) } -@(require_results) op_elem :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.ELEM, n) } +@(require_results) op_local :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.LOCAL, n) } +@(require_results) op_global :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.GLOBAL, n) } +@(require_results) op_func :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.FUNC, n) } +@(require_results) op_type :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.TYPE, n) } +@(require_results) op_table :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.TABLE, n) } +@(require_results) op_memory :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.MEMORY, n) } +@(require_results) op_data :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.DATA, n) } +@(require_results) op_elem :: #force_inline proc "contextless" (n: u32) -> Operand { return op_index(.ELEM, n) } // Branch label depth (number of enclosing blocks to break out of). @(require_results) op_labelidx :: #force_inline proc "contextless" (depth: u32) -> Operand { return op_index(.LABEL, depth) } diff --git a/core/rexcode/wasm/printer.odin b/core/rexcode/wasm/printer.odin index cf7b5f176..a6e382b2c 100644 --- a/core/rexcode/wasm/printer.odin +++ b/core/rexcode/wasm/printer.odin @@ -47,13 +47,6 @@ mnemonic_to_string :: proc(m: Mnemonic, lowercase: bool = true, allocator := con return strings.to_string(sb) } -// Vestigial -- WASM is register-less; provided for contract parity only. -register_name :: proc(r: Register, lowercase: bool = true, allocator := context.temp_allocator) -> string { - _ = r - _ = lowercase - return "" -} - // ============================================================================= // Core sbprint // ============================================================================= @@ -73,13 +66,8 @@ sbprint :: proc( opts = &defaults } - running: u32 = 0 - for i in 0.. 0 { + case: for slot in 0.."); return } if uppercase { for i in 0..= 'a' && c <= 'z' { strings.write_byte(sb, c - 32) } else { strings.write_byte(sb, c) } + c := name[i] // to force ASCII + if 'a' <= c && c <= 'z' { + strings.write_byte(sb, c - 32) + } else { + strings.write_byte(sb, c) + } } } else { strings.write_string(sb, name) @@ -283,9 +276,6 @@ write_operand :: proc( switch op.kind { case .NONE: - case .REGISTER: - strings.write_string(sb, "") // vestigial - case .IMMEDIATE: if mnemonic == .REF_NULL { write_heap_type(sb, u8(op.immediate)) diff --git a/core/rexcode/wasm/tests/pipeline_smoke.odin b/core/rexcode/wasm/tests/pipeline_smoke.odin index 3333bfef3..ee68a9355 100644 --- a/core/rexcode/wasm/tests/pipeline_smoke.odin +++ b/core/rexcode/wasm/tests/pipeline_smoke.odin @@ -33,13 +33,7 @@ ok :: proc(name: string, cond: bool) { @(private="file") eq_bytes :: proc(name: string, got, want: []u8) { - same := len(got) == len(want) - if same { - for i in 0.. 0 { strings.write_byte(&hex_buf, ',') } @@ -82,28 +81,17 @@ synth :: proc(mn: w.Mnemonic, form: w.Encoding) -> w.Instruction { switch k { case .NONE, .ZERO_BYTE: // no operand - case .BLOCKTYPE: - inst.ops[slot] = w.op_blocktype(.EMPTY); slot += 1 - case .I32: - inst.ops[slot] = w.op_i32(1); slot += 1 - case .I64: - inst.ops[slot] = w.op_i64(1); slot += 1 - case .F32: - inst.ops[slot] = w.op_f32(1); slot += 1 - case .F64: - inst.ops[slot] = w.op_f64(1); slot += 1 - case .IDX: - inst.ops[slot] = w.op_func(0); slot += 1 - case .MEMARG: - inst.ops[slot] = w.op_memarg(0, 0); slot += 1 - case .REFTYPE: - inst.ops[slot] = w.op_reftype(.FUNCREF); slot += 1 - case .LANE: - inst.ops[slot] = w.op_lane(0); slot += 1 - case .LANES16: - // 16-byte value lives in inst.bytes (left zero), no operand - case .BR_TABLE: - // handled above + case .BLOCKTYPE: inst.ops[slot] = w.op_blocktype(.EMPTY); slot += 1 + case .I32: inst.ops[slot] = w.op_i32(1); slot += 1 + case .I64: inst.ops[slot] = w.op_i64(1); slot += 1 + case .F32: inst.ops[slot] = w.op_f32(1); slot += 1 + case .F64: inst.ops[slot] = w.op_f64(1); slot += 1 + case .IDX: inst.ops[slot] = w.op_func(0); slot += 1 + case .MEMARG: inst.ops[slot] = w.op_memarg(0, 0); slot += 1 + case .REFTYPE: inst.ops[slot] = w.op_reftype(.FUNCREF); slot += 1 + case .LANE: inst.ops[slot] = w.op_lane(0); slot += 1 + case .LANES16: // 16-byte value lives in inst.bytes (left zero), no operand + case .BR_TABLE: // handled above } } inst.operand_count = u8(slot)