break;
case INSEL_ST_OFFSET:
- appendf("(st+%d)", insel->u.hreg->offset);
+ appendf("%d", current_proc->fp_to_st + insel->u.hreg->offset);
break;
case INSEL_AB_OFFSET:
- appendf("(ab+%d)", insel->u.offset);
+ appendf("%d", current_proc->fp_to_ab + insel->u.offset);
break;
case INSEL_LB_OFFSET:
- appendf("(lb+%d)", insel->u.offset);
+ appendf("%d", current_proc->fp_to_lb + insel->u.offset);
break;
case INSEL_VALUE:
break;
case IR_LOCAL:
+ if (ir->u.ivalue >= 0)
+ appendf("%d", current_proc->fp_to_ab + ir->u.ivalue);
+ else
+ appendf("%d", current_proc->fp_to_lb + ir->u.ivalue);
+ break;
+
case IR_CONST:
appendf("%d", ir->u.ivalue);
break;
/* mcg stack frames are laid out as:
*
* | ...params...
- * | --------------- <- ap
+ * | --------------- <- ab
* | saved regs
- * | --------------- <- st
+ * | ---------------
* | spills
- * | --------------- <- fp (a.k.a. lb)
+ * | --------------- <- st, fp (a.k.a. lb)
* | locals
* | --------------- <- sp
* V ...user area...
*
+ * st indexes up; lb indexes down.
*/
void platform_calculate_offsets(void)
{
- current_proc->fp_to_st = current_proc->spills_size;
- current_proc->fp_to_ap = current_proc->fp_to_st + current_proc->saved_size + 8;
+ current_proc->fp_to_st = 0;
+ current_proc->fp_to_ab = current_proc->spills_size + current_proc->saved_size + 8;
current_proc->fp_to_lb = 0;
}
{
struct hop* hop = new_hop(current_proc->entry, NULL);
- hop_add_insel(hop, "addi sp, sp, %d", current_proc->fp_to_ap + current_proc->locals_size);
+ hop_add_insel(hop, "! saved_size = %d+8 bytes", current_proc->saved_size);
+ hop_add_insel(hop, "! spills_size = %d bytes", current_proc->spills_size);
+ hop_add_insel(hop, "! locals_size = %d bytes", current_proc->locals_size);
+ hop_add_insel(hop, "addi sp, sp, %d", -(current_proc->fp_to_ab + current_proc->locals_size));
hop_add_insel(hop, "mfspr 0, lr");
hop_add_insel(hop, "stw fp, %d(sp)", current_proc->fp_to_st + current_proc->locals_size);
hop_add_insel(hop, "stw 0, %d(sp)", current_proc->fp_to_st + current_proc->locals_size + 4);