Commit f1e167c1d8

Andrew Kelley <andrew@ziglang.org>
2024-12-21 08:03:28
use fixed writer in more places
1 parent 2174d20
Changed files (1)
src
arch
src/arch/wasm/CodeGen.zig
@@ -1193,9 +1193,9 @@ pub const Function = extern struct {
         const locals = wasm.all_zcu_locals.items[f.locals_off..][0..f.locals_len];
         try code.ensureUnusedCapacity(gpa, 5 + locals.len * 6 + 38);
 
-        std.leb.writeUleb128(code.writer(gpa), @as(u32, @intCast(locals.len))) catch unreachable;
+        std.leb.writeUleb128(code.fixedWriter(), @as(u32, @intCast(locals.len))) catch unreachable;
         for (locals) |local| {
-            std.leb.writeUleb128(code.writer(gpa), @as(u32, 1)) catch unreachable;
+            std.leb.writeUleb128(code.fixedWriter(), @as(u32, 1)) catch unreachable;
             code.appendAssumeCapacity(local);
         }
 
@@ -1205,30 +1205,30 @@ pub const Function = extern struct {
             const sp_global: Wasm.GlobalIndex = .stack_pointer;
             // load stack pointer
             code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.global_get));
-            std.leb.writeULEB128(code.writer(gpa), @intFromEnum(sp_global)) catch unreachable;
+            std.leb.writeULEB128(code.fixedWriter(), @intFromEnum(sp_global)) catch unreachable;
             // store stack pointer so we can restore it when we return from the function
             code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.local_tee));
-            leb.writeUleb128(code.writer(gpa), f.prologue.sp_local) catch unreachable;
+            leb.writeUleb128(code.fixedWriter(), f.prologue.sp_local) catch unreachable;
             // get the total stack size
             const aligned_stack: i32 = @intCast(stack_alignment.forward(f.prologue.stack_size));
             code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_const));
-            leb.writeIleb128(code.writer(gpa), aligned_stack) catch unreachable;
+            leb.writeIleb128(code.fixedWriter(), aligned_stack) catch unreachable;
             // subtract it from the current stack pointer
             code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_sub));
             // Get negative stack alignment
             const neg_stack_align = @as(i32, @intCast(align_bytes)) * -1;
             code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_const));
-            leb.writeIleb128(code.writer(gpa), neg_stack_align) catch unreachable;
+            leb.writeIleb128(code.fixedWriter(), neg_stack_align) catch unreachable;
             // Bitwise-and the value to get the new stack pointer to ensure the
             // pointers are aligned with the abi alignment.
             code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_and));
             // The bottom will be used to calculate all stack pointer offsets.
             code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.local_tee));
-            leb.writeUleb128(code.writer(gpa), f.prologue.bottom_stack_local) catch unreachable;
+            leb.writeUleb128(code.fixedWriter(), f.prologue.bottom_stack_local) catch unreachable;
             // Store the current stack pointer value into the global stack pointer so other function calls will
             // start from this value instead and not overwrite the current stack.
             code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.global_set));
-            std.leb.writeULEB128(code.writer(gpa), @intFromEnum(sp_global)) catch unreachable;
+            std.leb.writeULEB128(code.fixedWriter(), @intFromEnum(sp_global)) catch unreachable;
         }
 
         var emit: Emit = .{