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 {...@@ -1193,9 +1193,9 @@ pub const Function = extern struct {
1193 const locals = wasm.all_zcu_locals.items[f.locals_off..][0..f.locals_len];1193 const locals = wasm.all_zcu_locals.items[f.locals_off..][0..f.locals_len];
1194 try code.ensureUnusedCapacity(gpa, 5 + locals.len * 6 + 38);1194 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;
1197 for (locals) |local| {1197 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;
1199 code.appendAssumeCapacity(local);1199 code.appendAssumeCapacity(local);
1200 }1200 }
12011201
...@@ -1205,30 +1205,30 @@ pub const Function = extern struct {...@@ -1205,30 +1205,30 @@ pub const Function = extern struct {
1205 const sp_global: Wasm.GlobalIndex = .stack_pointer;1205 const sp_global: Wasm.GlobalIndex = .stack_pointer;
1206 // load stack pointer1206 // load stack pointer
1207 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.global_get));1207 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;
1209 // store stack pointer so we can restore it when we return from the function1209 // store stack pointer so we can restore it when we return from the function
1210 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.local_tee));1210 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;
1212 // get the total stack size1212 // get the total stack size
1213 const aligned_stack: i32 = @intCast(stack_alignment.forward(f.prologue.stack_size));1213 const aligned_stack: i32 = @intCast(stack_alignment.forward(f.prologue.stack_size));
1214 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_const));1214 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;
1216 // subtract it from the current stack pointer1216 // subtract it from the current stack pointer
1217 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_sub));1217 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_sub));
1218 // Get negative stack alignment1218 // Get negative stack alignment
1219 const neg_stack_align = @as(i32, @intCast(align_bytes)) * -1;1219 const neg_stack_align = @as(i32, @intCast(align_bytes)) * -1;
1220 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_const));1220 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;
1222 // Bitwise-and the value to get the new stack pointer to ensure the1222 // Bitwise-and the value to get the new stack pointer to ensure the
1223 // pointers are aligned with the abi alignment.1223 // pointers are aligned with the abi alignment.
1224 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_and));1224 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.i32_and));
1225 // The bottom will be used to calculate all stack pointer offsets.1225 // The bottom will be used to calculate all stack pointer offsets.
1226 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.local_tee));1226 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;
1228 // Store the current stack pointer value into the global stack pointer so other function calls will1228 // Store the current stack pointer value into the global stack pointer so other function calls will
1229 // start from this value instead and not overwrite the current stack.1229 // start from this value instead and not overwrite the current stack.
1230 code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.global_set));1230 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;
1232 }1232 }
12331233
1234 var emit: Emit = .{1234 var emit: Emit = .{