ps5: generate_statement
This commit is contained in:
@@ -146,6 +146,7 @@ static void generate_function(symbol_t* function)
|
||||
}
|
||||
|
||||
// TODO (Task 4): the function body can be sent to generate_statement()
|
||||
generate_statement(function->node);
|
||||
|
||||
// TODO (Task 3.2): Emit the epilogue, including a label and a default return value (0)
|
||||
LABEL(".%s.epilogue", function->name);
|
||||
@@ -197,6 +198,28 @@ static void generate_statement(node_t* node)
|
||||
// The statements you must handle are BLOCK, ASSIGNMENT_STATEMENT,
|
||||
// PRINT_STATEMENT, RETURN_STATEMENT and FUNCTION_CALL.
|
||||
// Statements of type LOCAL_VARIABLE should be ignored.
|
||||
for (int i = 0; i < node->n_children; i++) {
|
||||
node_t *child = node->children[i];
|
||||
switch (child->type) {
|
||||
case BLOCK:
|
||||
node_t list = child->children[0];
|
||||
for (int j = 0; j < list->n_children; j++)
|
||||
generate_statement(list->children[j]);
|
||||
break;
|
||||
case ASSIGNMENT_STATEMENT:
|
||||
generate_assignment_statement(child);
|
||||
break;
|
||||
case PRINT_STATEMENT:
|
||||
generate_print_statement(child);
|
||||
break;
|
||||
case RETURN_STATEMENT:
|
||||
generate_return_statement(child);
|
||||
break;
|
||||
case FUNCTION_CALL:
|
||||
generate_function_call(child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void generate_safe_printf(void)
|
||||
|
||||
Reference in New Issue
Block a user