From 463be4aa241f9c9b8453ba46a89ce5d67995c55b Mon Sep 17 00:00:00 2001 From: Ting-Wei Lan Date: Wed, 30 Dec 2015 15:33:33 +0800 Subject: Drop any_error from state and add asm_output to state --- src/code-generation.c | 2 +- src/code-generation.h | 7 ++----- src/main.c | 7 +++---- src/state.c | 5 ++++- src/state.h | 3 ++- 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/code-generation.c b/src/code-generation.c index c0c5874..294389f 100644 --- a/src/code-generation.c +++ b/src/code-generation.c @@ -8,6 +8,6 @@ #include #include -void ccmmc_code_generation(CcmmcAst *root, CcmmcSymbolTable *table, FILE *asm_output) +void ccmmc_code_generation(CcmmcState *state) { } diff --git a/src/code-generation.h b/src/code-generation.h index 8250695..ce12490 100644 --- a/src/code-generation.h +++ b/src/code-generation.h @@ -1,14 +1,11 @@ #ifndef CCMMC_HEADER_CODE_GENERATION_H #define CCMMC_HEADER_CODE_GENERATION_H -#include "ast.h" -#include "symbol-table.h" +#include "state.h" #include -void ccmmc_code_generation (CcmmcAst *root, - CcmmcSymbolTable *table, - FILE *asm_output); +void ccmmc_code_generation (CcmmcState *state); #endif // vim: set sw=4 ts=4 sts=4 et: diff --git a/src/main.c b/src/main.c index 5f6c169..0ae48e4 100644 --- a/src/main.c +++ b/src/main.c @@ -96,13 +96,12 @@ int main (int argc, char **argv) else exit(1); - FILE *asm_output = fopen("output.s", "w"); - if (asm_output == NULL) { + state->asm_output = fopen("output.s", "w"); + if (state->asm_output == NULL) { fprintf(stderr, "%s: output.s: %s\n", prog_name, ERR_MSG); exit(1); } - ccmmc_code_generation(state->ast, state->table, asm_output); - fclose(asm_output); + ccmmc_code_generation(state); ccmmc_state_fini(state); fclose(source_handle); diff --git a/src/state.c b/src/state.c index 8d1a2f3..0c643f6 100644 --- a/src/state.c +++ b/src/state.c @@ -10,7 +10,7 @@ void ccmmc_state_init (CcmmcState *state) state->ast = NULL; state->table = NULL; state->line_number = 1; - state->any_error = false; + state->asm_output = NULL; } void ccmmc_state_fini (CcmmcState *state) @@ -21,6 +21,9 @@ void ccmmc_state_fini (CcmmcState *state) if (state->table != NULL) { // TODO: Free the symbol table } + if (state->asm_output != NULL) { + fclose(state->asm_output); + } } // vim: set sw=4 ts=4 sts=4 et: diff --git a/src/state.h b/src/state.h index 8e268d3..516b7fc 100644 --- a/src/state.h +++ b/src/state.h @@ -6,13 +6,14 @@ #include #include +#include // All states of the compiler instance typedef struct CcmmcState_struct { CcmmcAst *ast; CcmmcSymbolTable *table; size_t line_number; - bool any_error; + FILE *asm_output; } CcmmcState; void ccmmc_state_init (CcmmcState *state); -- cgit