2016-10-15 16:38:46 +00:00
|
|
|
#include "mcg.h"
|
|
|
|
|
2016-10-15 20:53:56 +00:00
|
|
|
/* mcg stack frames are laid out as:
|
|
|
|
*
|
|
|
|
* | ...params...
|
2016-10-15 21:33:30 +00:00
|
|
|
* | --------------- <- ab
|
2016-10-15 20:53:56 +00:00
|
|
|
* | saved regs
|
2016-10-15 21:33:30 +00:00
|
|
|
* | ---------------
|
2016-10-15 20:53:56 +00:00
|
|
|
* | spills
|
2016-10-15 21:33:30 +00:00
|
|
|
* | --------------- <- st, fp (a.k.a. lb)
|
2016-10-15 20:53:56 +00:00
|
|
|
* | locals
|
|
|
|
* | --------------- <- sp
|
|
|
|
* V ...user area...
|
|
|
|
*
|
2016-10-15 21:33:30 +00:00
|
|
|
* st indexes up; lb indexes down.
|
2016-10-15 20:53:56 +00:00
|
|
|
*/
|
|
|
|
|
2016-10-15 21:19:44 +00:00
|
|
|
void platform_calculate_offsets(void)
|
2016-10-15 16:38:46 +00:00
|
|
|
{
|
2016-10-15 21:33:30 +00:00
|
|
|
current_proc->fp_to_st = 0;
|
|
|
|
current_proc->fp_to_ab = current_proc->spills_size + current_proc->saved_size + 8;
|
2016-10-15 21:19:44 +00:00
|
|
|
current_proc->fp_to_lb = 0;
|
2016-10-15 20:53:56 +00:00
|
|
|
}
|
2016-10-15 16:38:46 +00:00
|
|
|
|
2016-10-15 21:19:44 +00:00
|
|
|
struct hop* platform_prologue(void)
|
2016-10-15 20:53:56 +00:00
|
|
|
{
|
2016-10-15 21:19:44 +00:00
|
|
|
struct hop* hop = new_hop(current_proc->entry, NULL);
|
2016-10-15 16:38:46 +00:00
|
|
|
|
2016-10-15 21:33:30 +00:00
|
|
|
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));
|
2016-10-15 21:39:38 +00:00
|
|
|
hop_add_insel(hop, "mfspr r0, lr");
|
2016-10-15 21:19:44 +00:00
|
|
|
hop_add_insel(hop, "stw fp, %d(sp)", current_proc->fp_to_st + current_proc->locals_size);
|
2016-10-15 21:39:38 +00:00
|
|
|
hop_add_insel(hop, "stw r0, %d(sp)", current_proc->fp_to_st + current_proc->locals_size + 4);
|
2016-10-15 21:19:44 +00:00
|
|
|
hop_add_insel(hop, "addi fp, sp, %d", current_proc->locals_size);
|
2016-10-15 16:38:46 +00:00
|
|
|
|
|
|
|
return hop;
|
|
|
|
}
|
|
|
|
|
2016-10-15 21:19:44 +00:00
|
|
|
struct hop* platform_epilogue(void)
|
2016-10-15 16:38:46 +00:00
|
|
|
{
|
2016-10-15 21:19:44 +00:00
|
|
|
struct hop* hop = new_hop(current_proc->exit, NULL);
|
2016-10-15 16:38:46 +00:00
|
|
|
|
|
|
|
hop_add_insel(hop, "b .ret");
|
|
|
|
|
|
|
|
return hop;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hop* platform_move(struct basicblock* bb, struct hreg* src, struct hreg* dest)
|
|
|
|
{
|
|
|
|
struct hop* hop = new_hop(bb, NULL);
|
|
|
|
|
|
|
|
if ((src->type & burm_int_ATTR) && (dest->type & burm_int_ATTR))
|
2016-10-15 20:53:56 +00:00
|
|
|
{
|
|
|
|
if (src->is_stacked)
|
|
|
|
hop_add_insel(hop, "lwz %H, %S(fp) ! %H", dest, src, src);
|
|
|
|
else if (dest->is_stacked)
|
|
|
|
hop_add_insel(hop, "stw %H, %S(fp) ! %H", src, dest, dest);
|
|
|
|
else
|
|
|
|
hop_add_insel(hop, "mr %H, %H", dest, src);
|
|
|
|
}
|
2016-10-15 16:38:46 +00:00
|
|
|
else
|
|
|
|
fatal("cannot generate move from %s to %s", src->name, dest->name);
|
|
|
|
|
|
|
|
return hop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set sw=4 ts=4 expandtab : */
|
|
|
|
|