diff --git a/main.c b/main.c index 78a943c0..066559ef 100644 --- a/main.c +++ b/main.c @@ -271,9 +271,19 @@ static void cc1(void) { Obj *prog = parse(tok); + // Open a temporary output buffer. + char *buf; + size_t buflen; + FILE *output_buf = open_memstream(&buf, &buflen); + // Traverse the AST to emit assembly. + codegen(prog, output_buf); + fclose(output_buf); + + // Write the asembly text to a file. FILE *out = open_file(output_file); - codegen(prog, out); + fwrite(buf, buflen, 1, out); + fclose(out); } static void assemble(char *input, char *output) {