From a03710697c78027d5d70c2a27becac41bf1dfea6 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 20 Dec 2024 23:03:28 -0800 Subject: [PATCH] use fixed writer in more places --- src/arch/wasm/CodeGen.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 416a12b42443..e1a967e84095 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/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 = .{