| ... | ... | @@ -77,6 +77,7 @@ mir_instructions: *std.MultiArrayList(Mir.Inst), |
| 77 | 77 | /// Contains extra data for MIR |
| 78 | 78 | mir_extra: *std.ArrayListUnmanaged(u32), |
| 79 | 79 | start_mir_extra_off: u32, |
| 80 | start_locals_off: u32, |
| 80 | 81 | /// List of all locals' types generated throughout this declaration |
| 81 | 82 | /// used to emit locals count at start of 'code' section. |
| 82 | 83 | locals: *std.ArrayListUnmanaged(u8), |
| ... | ... | @@ -209,7 +210,7 @@ const WValue = union(enum) { |
| 209 | 210 | if (local_value < reserved + 2) return; // reserved locals may never be re-used. Also accounts for 2 stack locals. |
| 210 | 211 | |
| 211 | 212 | const index = local_value - reserved; |
| 212 | | const valtype: std.wasm.Valtype = @enumFromInt(gen.locals.items[index]); |
| 213 | const valtype: std.wasm.Valtype = @enumFromInt(gen.locals.items[gen.start_locals_off + index]); |
| 213 | 214 | switch (valtype) { |
| 214 | 215 | .i32 => gen.free_locals_i32.append(gen.gpa, local_value) catch return, // It's ok to fail any of those, a new local can be allocated instead |
| 215 | 216 | .i64 => gen.free_locals_i64.append(gen.gpa, local_value) catch return, |
| ... | ... | @@ -1295,6 +1296,7 @@ pub fn function( |
| 1295 | 1296 | .mir_extra = &wasm.mir_extra, |
| 1296 | 1297 | .locals = &wasm.all_zcu_locals, |
| 1297 | 1298 | .start_mir_extra_off = @intCast(wasm.mir_extra.items.len), |
| 1299 | .start_locals_off = @intCast(wasm.all_zcu_locals.items.len), |
| 1298 | 1300 | }; |
| 1299 | 1301 | defer code_gen.deinit(); |
| 1300 | 1302 | |
| ... | ... | @@ -1309,7 +1311,6 @@ fn functionInner(cg: *CodeGen, any_returns: bool) InnerError!Function { |
| 1309 | 1311 | const zcu = cg.pt.zcu; |
| 1310 | 1312 | |
| 1311 | 1313 | const start_mir_off: u32 = @intCast(wasm.mir_instructions.len); |
| 1312 | | const start_locals_off: u32 = @intCast(wasm.all_zcu_locals.items.len); |
| 1313 | 1314 | |
| 1314 | 1315 | try cg.branches.append(cg.gpa, .{}); |
| 1315 | 1316 | // clean up outer branch |
| ... | ... | @@ -1339,8 +1340,8 @@ fn functionInner(cg: *CodeGen, any_returns: bool) InnerError!Function { |
| 1339 | 1340 | .mir_len = @intCast(wasm.mir_instructions.len - start_mir_off), |
| 1340 | 1341 | .mir_extra_off = cg.start_mir_extra_off, |
| 1341 | 1342 | .mir_extra_len = cg.extraLen(), |
| 1342 | | .locals_off = start_locals_off, |
| 1343 | | .locals_len = @intCast(wasm.all_zcu_locals.items.len - start_locals_off), |
| 1343 | .locals_off = cg.start_locals_off, |
| 1344 | .locals_len = @intCast(wasm.all_zcu_locals.items.len - cg.start_locals_off), |
| 1344 | 1345 | .prologue = if (cg.initial_stack_value == .none) .none else .{ |
| 1345 | 1346 | .sp_local = cg.initial_stack_value.local.value, |
| 1346 | 1347 | .flags = .{ .stack_alignment = cg.stack_alignment }, |