Changeset 6c3744e for translator/ControlStruct
- Timestamp:
- Jan 19, 2015, 6:29:10 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- f7f6785
- Parents:
- 0b8cd722
- Location:
- translator/ControlStruct
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/ControlStruct/LabelFixer.cc
r0b8cd722 r6c3744e 24 24 } 25 25 26 void LabelFixer::visit( FunctionDecl *functionDecl) {26 void LabelFixer::visit( FunctionDecl *functionDecl ) { 27 27 if ( functionDecl->get_statements() != 0 ) 28 28 functionDecl->get_statements()->accept( *this ); … … 32 32 } 33 33 34 void LabelFixer::visit( Statement *stmt ) {34 void LabelFixer::visit( Statement *stmt ) { 35 35 std::list< Label > &labels = stmt->get_labels(); 36 36 … … 42 42 } 43 43 44 void LabelFixer::visit( BranchStmt *branchStmt) {44 void LabelFixer::visit( BranchStmt *branchStmt ) { 45 45 visit ( ( Statement * )branchStmt ); // the labels this statement might have 46 46 … … 50 50 } //else /* computed goto or normal exit-loop statements */ 51 51 } 52 53 52 54 53 Label LabelFixer::setLabelsDef( std::list< Label > &llabel, Statement *definition ) { … … 61 60 { used = true; labelTable[ *i ] = entry; } // undefined and unused 62 61 else 63 if ( labelTable[ *i ]->defined() )64 throw SemanticError( "Duplicate definition of label: " + *i );62 if ( labelTable[ *i ]->defined() ) 63 throw SemanticError( "Duplicate definition of label: " + *i ); 65 64 else 66 65 labelTable[ *i ]->set_definition( definition ); … … 82 81 } 83 82 84 std::map <Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) {85 std::map 83 std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) { 84 std::map< Statement *, Entry * > def_us; 86 85 87 for ( std::map 86 for ( std::map< Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); i++ ) { 88 87 Entry *e = i->second; 89 88 … … 91 90 def_us[ e->get_definition() ] = e; 92 91 else 93 if (e->used())92 if ( e->used() ) 94 93 def_us[ e->get_definition() ]->add_uses( e->get_uses() ); 95 94 } 96 95 97 96 // get rid of labelTable 98 for ( std::map 97 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ ) { 99 98 Statement *to = (*i).first; 100 std::list 99 std::list< Statement *> &from = (*i).second->get_uses(); 101 100 Label finalLabel = generator->newLabel(); 102 101 (*i).second->set_label( finalLabel ); … … 114 113 115 114 for ( std::list< Statement *>::iterator j = from.begin(); j != from.end(); j++ ) { 116 BranchStmt *jumpTo = dynamic_cast 115 BranchStmt *jumpTo = dynamic_cast< BranchStmt * > ( *j ); 117 116 assert( jumpTo != 0 ); 118 117 jumpTo->set_target( finalLabel ); … … 121 120 122 121 // reverse table 123 std::map < Label, Statement * > *ret = new std::map< Label, Statement * >();124 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ )122 std::map< Label, Statement * > *ret = new std::map< Label, Statement * >(); 123 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ ) 125 124 (*ret)[ (*i).second->get_label() ] = (*i).first; 126 125 -
translator/ControlStruct/MLEMutator.cc
r0b8cd722 r6c3744e 12 12 } 13 13 14 CompoundStmt* MLEMutator::mutate( CompoundStmt *cmpndStmt) {14 CompoundStmt* MLEMutator::mutate( CompoundStmt *cmpndStmt ) { 15 15 bool labeledBlock = false; 16 16 if ( !((cmpndStmt->get_labels()).empty()) ) { … … 27 27 if ( next == kids.end() ) { 28 28 std::list<Label> ls; ls.push_back( get_breakLabel() ); 29 kids.push_back( new NullStmt( ls) );29 kids.push_back( new NullStmt( ls ) ); 30 30 } else 31 31 (*next)->get_labels().push_back( get_breakLabel() ); … … 88 88 std::list< Entry >::iterator check; 89 89 if ( ( check = std::find( enclosingLoops.begin(), enclosingLoops.end(), (*targetTable)[branchStmt->get_target()] ) ) == enclosingLoops.end() ) 90 // not in loop, checking if in switch/choose90 // not in loop, checking if in block 91 91 if ( (check = std::find( enclosingBlocks.begin(), enclosingBlocks.end(), (*targetTable)[branchStmt->get_target()] )) == enclosingBlocks.end() ) 92 92 // neither in loop nor in block, checking if in switch/choose … … 95 95 96 96 if ( enclosingLoops.back() == (*check) ) 97 return branchStmt; // exit the innermost loop (labels notnecessary)97 return branchStmt; // exit the innermost loop (labels unnecessary) 98 98 99 99 Label newLabel; … … 102 102 if ( check->get_breakExit() != "" ) 103 103 newLabel = check->get_breakExit(); 104 else { newLabel = generator->newLabel(); check->set_breakExit( newLabel ); } 104 else { 105 newLabel = generator->newLabel(); 106 check->set_breakExit( newLabel ); 107 } // if 105 108 break; 106 109 case BranchStmt::Continue: 107 110 if ( check->get_contExit() != "" ) 108 111 newLabel = check->get_contExit(); 109 else { newLabel = generator->newLabel(); check->set_contExit( newLabel ); } 112 else { 113 newLabel = generator->newLabel(); 114 check->set_contExit( newLabel ); 115 } // if 110 116 break; 111 117 default: 112 // shouldn't be here 113 return 0; 118 return 0; // shouldn't be here 114 119 } // switch 115 120 116 return new BranchStmt( std::list<Label>(), newLabel, BranchStmt::Goto );121 return new BranchStmt( std::list<Label>(), newLabel, BranchStmt::Goto ); 117 122 } 118 123 119 124 120 Statement *MLEMutator::mutate( SwitchStmt *switchStmt) {125 Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) { 121 126 Label brkLabel = generator->newLabel(); 122 127 enclosingSwitches.push_back( Entry(switchStmt, "", brkLabel) ); … … 131 136 } 132 137 133 Statement *MLEMutator::mutate( ChooseStmt *switchStmt) {138 Statement *MLEMutator::mutate( ChooseStmt *switchStmt ) { 134 139 Label brkLabel = generator->newLabel(); 135 140 enclosingSwitches.push_back( Entry(switchStmt,"", brkLabel) ); -
translator/ControlStruct/MLEMutator.h
r0b8cd722 r6c3744e 15 15 class Entry; 16 16 public: 17 MLEMutator( std::map 17 MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {} 18 18 ~MLEMutator(); 19 19 … … 56 56 }; 57 57 58 std::map <Label, Statement *> *targetTable;59 std::list < Entry > enclosingBlocks,enclosingLoops,enclosingSwitches;58 std::map< Label, Statement * > *targetTable; 59 std::list< Entry > enclosingBlocks, enclosingLoops, enclosingSwitches; 60 60 Label breakLabel; 61 61 LabelGenerator *generator;
Note: See TracChangeset
for help on using the changeset viewer.