Changeset be5aa1b for src/ControlStruct
- Timestamp:
- May 27, 2015, 4:40:05 PM (9 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:
- 46cbfe1, 52ac3b4
- Parents:
- 6aa5ec0f
- Location:
- src/ControlStruct
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/LabelFixer.cc
r6aa5ec0f rbe5aa1b 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue May 19 15:25:59201513 // Update Count : 111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed May 27 16:16:14 2015 13 // Update Count : 4 14 14 // 15 15 … … 40 40 41 41 void LabelFixer::visit( FunctionDecl *functionDecl ) { 42 if ( functionDecl->get_statements() != 0 ) 43 functionDecl->get_statements()->accept( *this ); 42 maybeAccept( functionDecl->get_statements(), *this ); 44 43 45 44 MLEMutator mlemut( resolveJumps(), generator ); … … 102 101 Entry *e = i->second; 103 102 104 if ( def_us.find ( e->get_definition() ) == def_us.end() ) 105 def_us[ e->get_definition() ] = e; 106 else103 if ( def_us.find ( e->get_definition() ) == def_us.end() ) { 104 def_us[ e->get_definition() ] = e; 105 } else { 107 106 if ( e->used() ) 108 107 def_us[ e->get_definition() ]->add_uses( e->get_uses() ); 108 } 109 109 } 110 110 -
src/ControlStruct/LabelFixer.h
r6aa5ec0f rbe5aa1b 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue May 19 15:31:55201513 // Update Count : 311 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue May 26 12:55:10 2015 13 // Update Count : 4 14 14 // 15 15 … … 66 66 67 67 Label get_label() const { return label; } 68 void set_label( Label lab ) { label = lab; } 69 68 70 Statement *get_definition() const { return definition; } 71 void set_definition( Statement *def ) { definition = def; } 72 69 73 std::list< Statement *> &get_uses() { return usage; } 70 71 74 void add_use ( Statement *use ) { usage.push_back( use ); } 72 75 void add_uses ( std::list<Statement *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); } 73 void set_definition( Statement *def ) { definition = def; }74 75 void set_label( Label lab ) { label = lab; }76 Label gset_label() const { return label; }77 76 private: 78 77 Label label; -
src/ControlStruct/MLEMutator.cc
r6aa5ec0f rbe5aa1b 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue May 19 15:32:26201513 // Update Count : 211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed May 27 16:19:32 2015 13 // Update Count : 44 14 14 // 15 15 … … 28 28 CompoundStmt* MLEMutator::mutate( CompoundStmt *cmpndStmt ) { 29 29 bool labeledBlock = false; 30 if ( !( (cmpndStmt->get_labels()).empty()) ) {30 if ( !(cmpndStmt->get_labels().empty()) ) { 31 31 labeledBlock = true; 32 32 enclosingBlocks.push_back( Entry( cmpndStmt ) ); … … 42 42 std::list<Label> ls; ls.push_back( get_breakLabel() ); 43 43 kids.push_back( new NullStmt( ls ) ); 44 } else 44 } else { 45 45 (*next)->get_labels().push_back( get_breakLabel() ); 46 } 46 47 47 48 set_breakLabel(""); … … 51 52 if ( labeledBlock ) { 52 53 assert( ! enclosingBlocks.empty() ); 53 if ( ! enclosingBlocks.back().get_breakExit().empty() ) 54 if ( ! enclosingBlocks.back().get_breakExit().empty() ) { 54 55 set_breakLabel( enclosingBlocks.back().get_breakExit() ); 56 } 55 57 enclosingBlocks.pop_back(); 56 58 } // if … … 85 87 86 88 Statement *MLEMutator::mutate( BranchStmt *branchStmt ) throw ( SemanticError ) { 89 std::string originalTarget = branchStmt->get_originalTarget(); 90 87 91 if ( branchStmt->get_type() == BranchStmt::Goto ) 88 92 return branchStmt; 89 93 90 94 // test if continue target is a loop 91 if ( branchStmt->get_type() == BranchStmt::Continue && enclosingLoops.empty() ) 92 throw SemanticError( "'continue' outside a loop" ); 95 if ( branchStmt->get_type() == BranchStmt::Continue) { 96 if ( enclosingLoops.empty() ) { 97 throw SemanticError( "'continue' outside a loop" ); 98 } else if ( std::find( enclosingLoops.begin(), enclosingLoops.end(), (*targetTable)[branchStmt->get_target()] ) == enclosingLoops.end() ) { 99 throw SemanticError( "'continue' target label must be an enclosing loop: " + originalTarget ); 100 } 101 } 93 102 94 103 if ( branchStmt->get_type() == BranchStmt::Break && (enclosingLoops.empty() && enclosingSwitches.empty() && enclosingBlocks.empty() ) ) … … 98 107 99 108 if ( targetTable->find( branchStmt->get_target() ) == targetTable->end() ) 100 throw SemanticError("The label defined in the exit loop statement does not exist ."); // shouldn't happen (since that's already checked)109 throw SemanticError("The label defined in the exit loop statement does not exist: " + originalTarget ); // shouldn't happen (since that's already checked) 101 110 102 111 std::list< Entry >::iterator check; … … 106 115 // neither in loop nor in block, checking if in switch/choose 107 116 if ( (check = std::find( enclosingSwitches.begin(), enclosingSwitches.end(), (*targetTable)[branchStmt->get_target()] )) == enclosingSwitches.end() ) 108 throw SemanticError("The target specified in the exit loop statement does not correspond to an enclosing loop.");117 throw SemanticError("The target specified in the exit loop statement does not correspond to an enclosing control structure: " + originalTarget ); 109 118 110 119 if ( enclosingLoops.back() == (*check) ) … … 114 123 switch ( branchStmt->get_type() ) { 115 124 case BranchStmt::Break: 116 if ( check->get_breakExit() != "" )117 newLabel = check->get_breakExit();118 else {119 newLabel = generator->newLabel();120 check->set_breakExit( newLabel );121 } // if122 break;125 if ( check->get_breakExit() != "" ) { 126 newLabel = check->get_breakExit(); 127 } else { 128 newLabel = generator->newLabel(); 129 check->set_breakExit( newLabel ); 130 } // if 131 break; 123 132 case BranchStmt::Continue: 124 if ( check->get_contExit() != "" )125 newLabel = check->get_contExit();126 else {127 newLabel = generator->newLabel();128 check->set_contExit( newLabel );129 } // if130 break;133 if ( check->get_contExit() != "" ) { 134 newLabel = check->get_contExit(); 135 } else { 136 newLabel = generator->newLabel(); 137 check->set_contExit( newLabel ); 138 } // if 139 break; 131 140 default: 132 return 0; // shouldn't be here141 return 0; // shouldn't be here 133 142 } // switch 134 143 … … 136 145 } 137 146 138 139 Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) { 147 template< typename SwitchClass > 148 Statement *handleSwitchStmt( SwitchClass *switchStmt, MLEMutator &mutator ) { 149 // set up some aliases so that the rest of the code isn't messy 150 typedef MLEMutator::Entry Entry; 151 LabelGenerator *generator = mutator.generator; 152 std::list< Entry > &enclosingSwitches = mutator.enclosingSwitches; 153 140 154 Label brkLabel = generator->newLabel(); 141 155 enclosingSwitches.push_back( Entry(switchStmt, "", brkLabel) ); 142 mutateAll( switchStmt->get_branches(), *this); {156 mutateAll( switchStmt->get_branches(), mutator ); { 143 157 // check if this is necessary (if there is a break to this point, otherwise do not generate 144 158 std::list<Label> temp; temp.push_back( brkLabel ); … … 150 164 } 151 165 166 Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) { 167 return handleSwitchStmt( switchStmt, *this ); 168 } 169 152 170 Statement *MLEMutator::mutate( ChooseStmt *switchStmt ) { 153 Label brkLabel = generator->newLabel(); 154 enclosingSwitches.push_back( Entry(switchStmt,"", brkLabel) ); 155 mutateAll( switchStmt->get_branches(), *this ); { 156 // check if this is necessary (if there is a break to this point, otherwise do not generate 157 std::list<Label> temp; temp.push_back( brkLabel ); 158 switchStmt->get_branches().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) ); 159 } 160 assert ( enclosingSwitches.back() == switchStmt ); 161 enclosingSwitches.pop_back(); 162 return switchStmt; 171 return handleSwitchStmt( switchStmt, *this ); 163 172 } 164 173 -
src/ControlStruct/MLEMutator.h
r6aa5ec0f rbe5aa1b 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue May 19 15:32:39201513 // Update Count : 311 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue May 26 15:04:21 2015 13 // Update Count : 7 14 14 // 15 15 … … 75 75 Label breakLabel; 76 76 LabelGenerator *generator; 77 78 template< typename SwitchClass > 79 friend Statement *handleSwitchStmt( SwitchClass *switchStmt, MLEMutator &mutator ); 77 80 }; 78 81 } // namespace ControlStruct
Note: See TracChangeset
for help on using the changeset viewer.