ps5: function prologue
This commit is contained in:
@@ -120,6 +120,30 @@ static void generate_function(symbol_t* function)
|
||||
|
||||
// TODO (Task 3.1): Do the prologue, including call frame building and parameter pushing
|
||||
// Tip: use the definitions REGISTER_PARAMS and NUM_REGISTER_PARAMS at the top of this file
|
||||
LABEL(".%s", function->name);
|
||||
|
||||
PUSHQ(RBP);
|
||||
MOVQ(RSP, RBP);
|
||||
|
||||
symbol_table_t *symtable = function->function_symtable;
|
||||
for (int i = 0; i < symtable->n_symbols; i++) {
|
||||
symbol_t *sym = symtable->children[i];
|
||||
switch (sym->type) {
|
||||
case SYMBOL_PARAMETER:
|
||||
if (i < NUM_REGISTER_PARAMS) {
|
||||
PUSHQ(REGISTER_PARAMS[i]);
|
||||
} else {
|
||||
/* these params are already on the stack */;
|
||||
}
|
||||
break;
|
||||
case SYMBOL_LOCAL_VAR:
|
||||
PUSHQ("$0");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unexpected symbol in symtable");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO (Task 4): the function body can be sent to generate_statement()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user