diff options
author | Adrian Thurston <thurston@colm.net> | 2018-12-12 12:19:06 +0200 |
---|---|---|
committer | Adrian Thurston <thurston@colm.net> | 2018-12-12 12:19:06 +0200 |
commit | 46afc4c66c0075d01646df65d0939571c91e9050 (patch) | |
tree | 57013b98ea88e158672d1ecd009cdbbd4fa7ee2d /src | |
parent | 779a96e143c9aaccebd24f5de48dee04e46aeab6 (diff) | |
download | colm-46afc4c66c0075d01646df65d0939571c91e9050.tar.gz |
make it optional to clean trees as we reduce
Was always freeing trees after each reduction action. Can now turn this off and
have the trees underneath what we have reduced available.
Diffstat (limited to 'src')
-rw-r--r-- | src/colm.h | 1 | ||||
-rw-r--r-- | src/program.c | 6 | ||||
-rw-r--r-- | src/program.h | 1 | ||||
-rw-r--r-- | src/reduce.cc | 10 |
4 files changed, 14 insertions, 4 deletions
@@ -131,6 +131,7 @@ int colm_delete_program( struct colm_program *prg ); /* Set the pointer to the reduce struct used. */ void *colm_get_reduce_ctx( struct colm_program *prg ); void colm_set_reduce_ctx( struct colm_program *prg, void *ctx ); +void colm_set_reduce_clean( struct colm_program *prg, unsigned char reduce_clean ); const char *colm_error( struct colm_program *prg, int *length ); diff --git a/src/program.c b/src/program.c index 5555207a..0675c239 100644 --- a/src/program.c +++ b/src/program.c @@ -170,6 +170,11 @@ void colm_set_debug( program_t *prg, long active_realm ) prg->active_realm = active_realm; } +void colm_set_reduce_clean( struct colm_program *prg, unsigned char reduce_clean ) +{ + prg->reduce_clean = reduce_clean; +} + program_t *colm_new_program( struct colm_sections *rtd ) { program_t *prg = malloc(sizeof(program_t)); @@ -180,6 +185,7 @@ program_t *colm_new_program( struct colm_sections *rtd ) prg->rtd = rtd; prg->ctx_dep_parsing = 1; + prg->reduce_clean = 1; init_pool_alloc( &prg->kid_pool, sizeof(kid_t) ); init_pool_alloc( &prg->tree_pool, sizeof(tree_t) ); diff --git a/src/program.h b/src/program.h index 21e21d36..8ba716d4 100644 --- a/src/program.h +++ b/src/program.h @@ -136,6 +136,7 @@ struct colm_program const int *argl; unsigned char ctx_dep_parsing; + unsigned char reduce_clean; struct colm_sections *rtd; struct colm_struct *global; int induce_exit; diff --git a/src/reduce.cc b/src/reduce.cc index 98622326..a2db97f0 100644 --- a/src/reduce.cc +++ b/src/reduce.cc @@ -435,7 +435,7 @@ void Compiler::writeNeeds() "extern \"C\" int " << objectName << "_reducer_need_tok( program_t *prg, " "struct pda_run *pda_run, int id )\n" "{\n" - " if ( pda_run->reducer > 0 ) {\n" + " if ( prg->reduce_clean && pda_run->reducer > 0 ) {\n" /* Note we are forcing the reducer need for data. Enabling requires finding * a solution for backtracking push. */ " return COLM_RN_DATA | ri[pda_run->reducer].need_data[id] | \n" @@ -700,9 +700,11 @@ void Compiler::writeParseReduce( Reduction *reduction ) " }\n" "\n" " commit_clear_parse_tree( prg, sp, pda_run, lel->child );\n" - " commit_clear_kid_list( prg, sp, kid->tree->child );\n" - " kid->tree->child = 0;\n" - " kid->tree->flags &= ~( AF_LEFT_IGNORE | AF_RIGHT_IGNORE );\n" + " if ( prg->reduce_clean ) {\n" + " commit_clear_kid_list( prg, sp, kid->tree->child );\n" + " kid->tree->child = 0;\n" + " kid->tree->flags &= ~( AF_LEFT_IGNORE | AF_RIGHT_IGNORE );\n" + " }\n" " lel->child = 0;\n" "\n" " if ( sp != root )\n" |