From f96df358c926039fbde5426d7c8364e1f697ae84 Mon Sep 17 00:00:00 2001 From: Fredrik Robertsen Date: Sat, 28 Mar 2026 21:39:03 +0100 Subject: [PATCH] ps5: map generate_function in generate_program --- ps5/src/generator.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ps5/src/generator.c b/ps5/src/generator.c index 22ece16..60c69d4 100644 --- a/ps5/src/generator.c +++ b/ps5/src/generator.c @@ -29,6 +29,18 @@ void generate_program(void) // TODO (Task 3): // For each function in global_symbols, generate it using generate_function () + bool found = false; + symbol_t *entry; + for (int i = 0; i < global_symbols->n_children; i++) { + symbol_t *sym = global_symbols->children[i]; + if (sym->type == SYMBOL_FUNCTION) { + if (!found) { + entry = sym; + found = true; + } + generate_function(sym); + } + } // In VSL, the topmost function in a program is its entry point. // We want to be able to take parameters from the command line, @@ -38,6 +50,7 @@ void generate_program(void) // and passed as the (argc, argv)-pair, we need to make a wrapper for our entry function. // This wrapper handles string -> int64_t conversion, and is already implemented. // call generate_main ( ); + generate_main(entry); } // Prints one .asciz entry for each string in the global string_list