References to the stack frame are now rendered properly.
authorDavid Given <dg@cowlark.com>
Sat, 15 Oct 2016 21:33:30 +0000 (23:33 +0200)
committerDavid Given <dg@cowlark.com>
Sat, 15 Oct 2016 21:33:30 +0000 (23:33 +0200)
mach/proto/mcg/hop.c
mach/proto/mcg/powerpc.c
mach/proto/mcg/procedure.h

index b5eaa02..7bdb232 100644 (file)
@@ -227,15 +227,15 @@ char* hop_render(struct hop* hop)
                                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:
@@ -252,6 +252,12 @@ char* hop_render(struct hop* hop)
                                                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;
index a47d8a8..fbd669e 100644 (file)
@@ -3,21 +3,22 @@
 /* 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;
 }
 
@@ -25,7 +26,10 @@ struct hop* platform_prologue(void)
 {
        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);
index 0cec989..2c0baf8 100644 (file)
@@ -17,7 +17,7 @@ struct procedure
     int spills_size;
     int saved_size;
     int fp_to_st;
-    int fp_to_ap;
+    int fp_to_ab;
     int fp_to_lb;
     ARRAYOF(struct basicblock) blocks;
     IMAPOF(struct local) locals;