From b2348e1de06ecbc6298c7caae7ac0deaa444dffb Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Sun, 2 Jun 2013 12:35:53 +0200 Subject: [PATCH] remove the ast tree earlier - saves over 3% peak memory usage --- parser.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/parser.c b/parser.c index bedef2b..cf69136 100644 --- a/parser.c +++ b/parser.c @@ -39,6 +39,8 @@ typedef struct parser_s { lex_file *lex; int tok; + bool ast_cleaned; + ast_expression **globals; ast_expression **fields; ast_function **functions; @@ -6189,9 +6191,12 @@ bool parser_compile_string(parser_t *parser, const char *name, const char *str, return parser_compile(parser); } -void parser_cleanup(parser_t *parser) +static void parser_remove_ast(parser_t *parser) { size_t i; + if (parser->ast_cleaned) + return; + parser->ast_cleaned = true; for (i = 0; i < vec_size(parser->accessors); ++i) { ast_delete(parser->accessors[i]->constval.vfunc); parser->accessors[i]->constval.vfunc = NULL; @@ -6260,9 +6265,12 @@ void parser_cleanup(parser_t *parser) ast_value_delete(parser->const_vec[2]); util_htdel(parser->aliases); - intrin_intrinsics_destroy(parser); +} +void parser_cleanup(parser_t *parser) +{ + parser_remove_ast(parser); code_cleanup(parser->code); mem_d(parser); @@ -6421,6 +6429,8 @@ bool parser_finish(parser_t *parser, const char *output) return false; } } + + generate_checksum(parser); if (OPTS_OPTION_BOOL(OPTION_DUMP)) ir_builder_dump(ir, con_out); for (i = 0; i < vec_size(parser->functions); ++i) { @@ -6430,6 +6440,7 @@ bool parser_finish(parser_t *parser, const char *output) return false; } } + parser_remove_ast(parser); if (compile_Werrors) { con_out("*** there were warnings treated as errors\n"); @@ -6441,15 +6452,12 @@ bool parser_finish(parser_t *parser, const char *output) if (OPTS_OPTION_BOOL(OPTION_DUMPFIN)) ir_builder_dump(ir, con_out); - generate_checksum(parser); - if (!ir_builder_generate(parser->code, ir, output)) { con_out("*** failed to generate output file\n"); ir_builder_delete(ir); return false; } } - ir_builder_delete(ir); return retval; } -- 2.39.2