| ... | @@ -536,11 +536,18 @@ fn lowerMir(emit: *Emit) !void { | ... | @@ -536,11 +536,18 @@ fn lowerMir(emit: *Emit) !void { |
| 536 | const data = mir_datas[inst].i_type; | 536 | const data = mir_datas[inst].i_type; |
| 537 | // TODO: probably create a psuedo instruction for s0 loads/stores instead of this. | 537 | // TODO: probably create a psuedo instruction for s0 loads/stores instead of this. |
| 538 | if (data.rs1 == .s0) { | 538 | if (data.rs1 == .s0) { |
| 539 | const casted_size = math.cast(i12, emit.stack_size) orelse { | | |
| 540 | return emit.fail("TODO: support bigger stack sizes lowerMir", .{}); | | |
| 541 | }; | | |
| 542 | const offset = mir_datas[inst].i_type.imm12; | 539 | const offset = mir_datas[inst].i_type.imm12; |
| 543 | mir_datas[inst].i_type.imm12 = -(casted_size - 12 - offset); | 540 | |
| | 541 | // sp + 32 (aka s0) |
| | 542 | // ra -- previous ra spilled |
| | 543 | // s0 -- previous s0 spilled |
| | 544 | // --- this is -16(s0) |
| | 545 | |
| | 546 | // TODO: this "+ 8" is completely arbiratary as the largest possible store |
| | 547 | // we don't want to actually use it. instead we need to calculate the difference |
| | 548 | // between the first and second stack store and use it instead. |
| | 549 | |
| | 550 | mir_datas[inst].i_type.imm12 = -(16 + offset + 8); |
| 544 | } | 551 | } |
| 545 | } | 552 | } |
| 546 | | 553 | |