Commit 4f7811db authored by Christoph Mallon's avatar Christoph Mallon
Browse files

template: Add a function prologue like all other backends do.

parent 154081ef
......@@ -167,20 +167,6 @@ static void emit_be_IncSP(const ir_node *node)
TEMPLATE_emitf(node, "%s %S0, %d, %D0", op, offset);
}
static void emit_Start(const ir_node *node)
{
ir_graph *irg = get_irn_irg(node);
ir_type *frame_type = get_irg_frame_type(irg);
unsigned size = get_type_size_bytes(frame_type);
/* emit function prolog */
/* allocate stackframe */
if (size > 0) {
TEMPLATE_emitf(node, "sub %%sp, %u, %%sp", size);
}
}
static void emit_Return(const ir_node *node)
{
ir_graph *irg = get_irn_irg(node);
......@@ -217,7 +203,6 @@ static void TEMPLATE_register_emitters(void)
/* custom emitters not provided by the spec */
be_set_emitter(op_TEMPLATE_Jmp, emit_TEMPLATE_Jmp);
be_set_emitter(op_TEMPLATE_Return, emit_Return);
be_set_emitter(op_TEMPLATE_Start, emit_Start);
be_set_emitter(op_be_IncSP, emit_be_IncSP);
}
......
......@@ -172,6 +172,7 @@ Start => {
out_reqs => [ "sp:I", "r0", "r1", "r2", "r3", "mem" ],
outs => [ "stack", "arg0", "arg1", "arg2", "arg3", "M" ],
ins => [],
emit => "",
},
Return => {
......
......@@ -15,6 +15,7 @@
#include "bemodule.h"
#include "benode.h"
#include "bera.h"
#include "besched.h"
#include "bestack.h"
#include "debug.h"
#include "gen_TEMPLATE_regalloc_if.h"
......@@ -58,6 +59,19 @@ static const regalloc_if_t TEMPLATE_regalloc_if = {
.new_reload = TEMPLATE_new_reload,
};
static void introduce_prologue(ir_graph *const irg)
{
arch_register_t const *const sp = &TEMPLATE_registers[REG_SP];
ir_node *const start = get_irg_start(irg);
ir_node *const block = get_nodes_block(start);
ir_node *const initial_sp = be_get_initial_reg_value(irg, sp);
ir_type *const frame_type = get_irg_frame_type(irg);
unsigned const frame_size = get_type_size_bytes(frame_type);
ir_node *const incsp = be_new_IncSP(sp, block, initial_sp, frame_size, 0);
edges_reroute_except(initial_sp, incsp, incsp);
sched_add_after(start, incsp);
}
static void TEMPLATE_generate_code(FILE *output, const char *cup_name)
{
be_begin(output, cup_name);
......@@ -75,6 +89,8 @@ static void TEMPLATE_generate_code(FILE *output, const char *cup_name)
be_step_regalloc(irg, &TEMPLATE_regalloc_if);
introduce_prologue(irg);
be_fix_stack_nodes(irg, &TEMPLATE_registers[REG_SP]);
be_birg_from_irg(irg)->non_ssa_regs = NULL;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment