| ... | @@ -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); |
| 1195 | | 1195 | |
| 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 | } |
| 1201 | | 1201 | |
| ... | @@ -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 pointer | 1206 | // 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 function | 1209 | // 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 size | 1212 | // 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 pointer | 1216 | // 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 alignment | 1218 | // 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 the | 1222 | // 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 will | 1228 | // 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 | } |
| 1233 | | 1233 | |
| 1234 | var emit: Emit = .{ | 1234 | var emit: Emit = .{ |