diff options
author | Adrian Thurston <thurston@complang.org> | 2015-11-22 15:28:37 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-11-22 15:28:37 -0500 |
commit | 255a339bf052fbc2a2412fd88b89936c95c7db33 (patch) | |
tree | cafddc28c9a6bf86ca5dec8bd52410b88cd3bf1f /src/reduce.cc | |
parent | 68be429ede12bfa28b96c713ff27ff4e45f9336c (diff) | |
download | colm-255a339bf052fbc2a2412fd88b89936c95c7db33.tar.gz |
reducer: cursor through rhs elements instead of starting from zero
Diffstat (limited to 'src/reduce.cc')
-rw-r--r-- | src/reduce.cc | 110 |
1 files changed, 90 insertions, 20 deletions
diff --git a/src/reduce.cc b/src/reduce.cc index 9ab6a9c1..fc6ef4b4 100644 --- a/src/reduce.cc +++ b/src/reduce.cc @@ -106,36 +106,106 @@ void Compiler::loadRefs( Production *production, const ReduceTextItemList &list production->prodName->fullName << ";\n"; } + /* + * In the first pass we + */ + bool useCursor = false; for ( Vector<ProdEl*>::Iter rhs = rhsUsed; rhs.lte(); rhs++ ) { - if ( *rhs != 0 ) { + if ( *rhs != 0 && (*rhs)->production == production && + (*rhs)->langEl->type != LangEl::Term ) + { + useCursor = true; + break; + } + } + + if ( useCursor ) { + int cursorPos = 0; + + *outStream << + " struct colm_parse_tree *_pt_cursor = lel->child;\n"; + + /* Same length, can concurrently walk with one test. */ + Vector<ProdEl*>::Iter rhs = rhsUsed; + Vector<ProdEl*>::Iter loc = locUsed; + + for ( ; rhs.lte(); rhs++, loc++ ) { ProdEl *prodEl = *rhs; - if ( prodEl->production == production ) { - if ( prodEl->langEl->type == LangEl::Term ) { + if ( prodEl != 0 ) { + while ( cursorPos < rhs.pos() ) { *outStream << - " colm_data *_rhs" << rhs.pos() << " = " - "get_rhs_el_kid( prg, kid->tree, " - << prodEl->pos << " )->tree->tokdata;\n"; + " _pt_cursor = _pt_cursor->next;\n"; + cursorPos += 1; } - else { - *outStream << - "lel_" << prodEl->langEl->fullName << " *" - "_rhs" << rhs.pos() << " = &((commit_reduce_union*)" - "(get_rhs_parse_tree( prg, lel, " << - prodEl->pos << " )+1))->" << - prodEl->langEl->fullName << ";\n"; + + + if ( prodEl->production == production ) { + if ( prodEl->langEl->type != LangEl::Term ) { + *outStream << + "lel_" << prodEl->langEl->fullName << " *" + "_rhs" << rhs.pos() << " = &((commit_reduce_union*)" + "(_pt_cursor+1))->" << + prodEl->langEl->fullName << ";\n"; + } } + } + } + } + useCursor = false; + for ( Vector<ProdEl*>::Iter rhs = rhsUsed; rhs.lte(); rhs++ ) { + if ( *rhs != 0 && (*rhs)->production == production && + (*rhs)->langEl->type == LangEl::Term ) + { + useCursor = true; + break; } } for ( Vector<ProdEl*>::Iter loc = locUsed; loc.lte(); loc++ ) { - ProdEl *prodEl = *loc; - if ( prodEl != 0 ) { - if ( prodEl->production == production ) { - *outStream << - " colm_location *_loc" << loc.pos() << " = " - "colm_find_location( prg, get_rhs_el_kid( prg, kid->tree, " << - prodEl->pos << " )->tree );\n"; + if ( *loc != 0 ) { + useCursor = true; + break; + } + } + + if ( useCursor ) { + int cursorPos = 0; + + *outStream << + " kid_t *_tree_cursor = kid->tree->child;\n"; + + /* Same length, can concurrently walk with one test. */ + Vector<ProdEl*>::Iter rhs = rhsUsed; + Vector<ProdEl*>::Iter loc = locUsed; + + for ( ; rhs.lte(); rhs++, loc++ ) { + ProdEl *prodEl = *rhs; + if ( prodEl != 0 ) { + while ( cursorPos < rhs.pos() ) { + *outStream << + " _tree_cursor = _tree_cursor->next;\n"; + cursorPos += 1; + } + + + if ( prodEl->production == production ) { + if ( prodEl->langEl->type == LangEl::Term ) { + *outStream << + " colm_data *_rhs" << rhs.pos() << " = " + "_tree_cursor->tree->tokdata;\n"; + } + } + + } + + ProdEl *locEl = *loc; + if ( locEl != 0 ) { + if ( locEl->production == production ) { + *outStream << + " colm_location *_loc" << loc.pos() << " = " + "colm_find_location( prg, _tree_cursor->tree );\n"; + } } } } |