authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-20 23:03:28-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-15 15:11:36-08:00
logf1e167c1d8706a777acd9b4f12fa8d281430796d
tree88292bf764509619c13afdb89b9e55a292c574ca
parent2174d205409c17588f22cf60f8bba1fc1aa5c8d5

use fixed writer in more places


1 files changed, 8 insertions(+), 8 deletions(-)

src/arch/wasm/CodeGen.zig+8-8
......@@ -1193,9 +1193,9 @@ pub const Function = extern struct {
11931193 const locals = wasm.all_zcu_locals.items[f.locals_off..][0..f.locals_len];
11941194 try code.ensureUnusedCapacity(gpa, 5 + locals.len * 6 + 38);
11951195
1196 std.leb.writeUleb128(code.writer(gpa), @as(u32, @intCast(locals.len))) catch unreachable;
1196 std.leb.writeUleb128(code.fixedWriter(), @as(u32, @intCast(locals.len))) catch unreachable;
11971197 for (locals) |local| {
1198 std.leb.writeUleb128(code.writer(gpa), @as(u32, 1)) catch unreachable;
1198 std.leb.writeUleb128(code.fixedWriter(), @as(u32, 1)) catch unreachable;
11991199 code.appendAssumeCapacity(local);
12001200 }
12011201
......@@ -1205,30 +1205,30 @@ pub const Function = extern struct {
12051205 const sp_global: Wasm.GlobalIndex = .stack_pointer;
12061206 // load stack pointer
12071207 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.global_get));
1208 std.leb.writeULEB128(code.writer(gpa), @intFromEnum(sp_global)) catch unreachable;
1208 std.leb.writeULEB128(code.fixedWriter(), @intFromEnum(sp_global)) catch unreachable;
12091209 // store stack pointer so we can restore it when we return from the function
12101210 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.local_tee));
1211 leb.writeUleb128(code.writer(gpa), f.prologue.sp_local) catch unreachable;
1211 leb.writeUleb128(code.fixedWriter(), f.prologue.sp_local) catch unreachable;
12121212 // get the total stack size
12131213 const aligned_stack: i32 = @intCast(stack_alignment.forward(f.prologue.stack_size));
12141214 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_const));
1215 leb.writeIleb128(code.writer(gpa), aligned_stack) catch unreachable;
1215 leb.writeIleb128(code.fixedWriter(), aligned_stack) catch unreachable;
12161216 // subtract it from the current stack pointer
12171217 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_sub));
12181218 // Get negative stack alignment
12191219 const neg_stack_align = @as(i32, @intCast(align_bytes)) * -1;
12201220 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_const));
1221 leb.writeIleb128(code.writer(gpa), neg_stack_align) catch unreachable;
1221 leb.writeIleb128(code.fixedWriter(), neg_stack_align) catch unreachable;
12221222 // Bitwise-and the value to get the new stack pointer to ensure the
12231223 // pointers are aligned with the abi alignment.
12241224 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_and));
12251225 // The bottom will be used to calculate all stack pointer offsets.
12261226 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.local_tee));
1227 leb.writeUleb128(code.writer(gpa), f.prologue.bottom_stack_local) catch unreachable;
1227 leb.writeUleb128(code.fixedWriter(), f.prologue.bottom_stack_local) catch unreachable;
12281228 // Store the current stack pointer value into the global stack pointer so other function calls will
12291229 // start from this value instead and not overwrite the current stack.
12301230 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.global_set));
1231 std.leb.writeULEB128(code.writer(gpa), @intFromEnum(sp_global)) catch unreachable;
1231 std.leb.writeULEB128(code.fixedWriter(), @intFromEnum(sp_global)) catch unreachable;
12321232 }
12331233
12341234 var emit: Emit = .{