ps5: errata for simple-print to work

This commit is contained in:
2026-04-01 21:16:11 +02:00
parent 47b4c646e1
commit e01baf43c6

View File

@@ -73,7 +73,7 @@ static void generate_stringtable(void)
// TODO (Task 1): Print all strings in the program here, with labels you can refer to later
// You have access to the global variables string_list and string_list_len from symbols.c
for (long int i = 0; i < string_list_len; i++) {
DIRECTIVE("string%ld:\t.asciz \"%s\"", i, string_list[i]);
DIRECTIVE("string%ld:\t.asciz %s", i, string_list[i]);
}
}
@@ -151,7 +151,7 @@ static void generate_function(symbol_t* function)
}
// TODO (Task 4): the function body can be sent to generate_statement()
generate_statement(function->node);
generate_statement(function->node->children[2]);
// TODO (Task 3.2): Emit the epilogue, including a label and a default return value (0)
CLEAR(RAX);
@@ -354,27 +354,24 @@ 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;
}
switch (node->type) {
case BLOCK:
node_t *list = node->children[0];
for (int j = 0; j < list->n_children; j++)
generate_statement(list->children[j]);
break;
case ASSIGNMENT_STATEMENT:
generate_assignment_statement(node);
break;
case PRINT_STATEMENT:
generate_print_statement(node);
break;
case RETURN_STATEMENT:
generate_return_statement(node);
break;
case FUNCTION_CALL:
generate_function_call(node);
break;
}
}