diff options
author | Ting-Wei Lan <lantw44@gmail.com> | 2015-12-30 15:33:33 +0800 |
---|---|---|
committer | Ting-Wei Lan <lantw44@gmail.com> | 2015-12-30 15:33:33 +0800 |
commit | 463be4aa241f9c9b8453ba46a89ce5d67995c55b (patch) | |
tree | 8575ce34c28d0cc10a4b3a98ced553a504e7c7d4 | |
parent | 0c0c7ab0850b6803c377ad7150305870d75bf3c0 (diff) | |
download | compiler2015-463be4aa241f9c9b8453ba46a89ce5d67995c55b.tar compiler2015-463be4aa241f9c9b8453ba46a89ce5d67995c55b.tar.gz compiler2015-463be4aa241f9c9b8453ba46a89ce5d67995c55b.tar.bz2 compiler2015-463be4aa241f9c9b8453ba46a89ce5d67995c55b.tar.lz compiler2015-463be4aa241f9c9b8453ba46a89ce5d67995c55b.tar.xz compiler2015-463be4aa241f9c9b8453ba46a89ce5d67995c55b.tar.zst compiler2015-463be4aa241f9c9b8453ba46a89ce5d67995c55b.zip |
Drop any_error from state and add asm_output to state
-rw-r--r-- | src/code-generation.c | 2 | ||||
-rw-r--r-- | src/code-generation.h | 7 | ||||
-rw-r--r-- | src/main.c | 7 | ||||
-rw-r--r-- | src/state.c | 5 | ||||
-rw-r--r-- | src/state.h | 3 |
5 files changed, 12 insertions, 12 deletions
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 <stdio.h> #include <stdlib.h> -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 <stdio.h> -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: @@ -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 <stdbool.h> #include <stddef.h> +#include <stdio.h> // 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); |