Changeset 9a8930f for src/ControlStruct
- Timestamp:
- Jun 4, 2015, 2:07:40 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:
- 0423f25, eb3261f
- Parents:
- a61fea9a (diff), 1136d96 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/ControlStruct
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ChooseMutator.cc
ra61fea9a r9a8930f 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:39201513 // Update Count : 211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 03 15:30:20 2015 13 // Update Count : 5 14 14 // 15 15 … … 44 44 std::list< Statement * > &stmts = caseStmt->get_statements(); 45 45 46 // the difference between switch and choose is that switch has an implicit fallthrough 47 // to the next case, whereas choose has an implicit break at the end of the current case. 48 // thus to transform a choose statement into a switch, we only need to insert breaks at the 49 // end of any case that doesn't already end in a break and that doesn't end in a fallthru 50 46 51 if ( insideChoose ) { 47 52 BranchStmt *posBrk; -
src/ControlStruct/LabelFixer.cc
ra61fea9a r9a8930f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed May 27 16:16:14201513 // Update Count : 412 // Last Modified On : Tue Jun 02 15:30:32 2015 13 // Update Count : 93 14 14 // 15 15 … … 23 23 #include "utility.h" 24 24 25 #include <iostream> 26 25 27 namespace ControlStruct { 26 LabelFixer::Entry::Entry( Statement *to, Statement *from ) : definition ( to ) {28 LabelFixer::Entry::Entry( Statement *to, BranchStmt *from ) : definition ( to ) { 27 29 if ( from != 0 ) 28 30 usage.push_back( from ); … … 31 33 bool LabelFixer::Entry::insideLoop() { 32 34 return ( dynamic_cast< ForStmt * > ( definition ) || 33 35 dynamic_cast< WhileStmt * > ( definition ) ); 34 36 } 35 37 … … 46 48 } 47 49 50 // prune to at most one label definition for each statement 48 51 void LabelFixer::visit( Statement *stmt ) { 49 52 std::list< Label > &labels = stmt->get_labels(); 50 53 51 54 if ( ! labels.empty() ) { 55 // only remember one label for each statement 52 56 Label current = setLabelsDef( labels, stmt ); 53 57 labels.clear(); … … 57 61 58 62 void LabelFixer::visit( BranchStmt *branchStmt ) { 59 visit ( ( Statement * )branchStmt ); // the labels this statement might have63 visit ( ( Statement * )branchStmt ); 60 64 61 Label target; 62 if ( (target = branchStmt->get_target()) != "" ) { 65 // for labeled branches, add an entry to the label table 66 Label target = branchStmt->get_target(); 67 if ( target != "" ) { 63 68 setLabelsUsg( target, branchStmt ); 64 } //else /* computed goto or normal exit-loop statements */69 } 65 70 } 66 71 72 // sets the definition of the labelTable entry to be the provided 73 // statement for every label in the list parameter. Happens for every kind of statement 67 74 Label LabelFixer::setLabelsDef( std::list< Label > &llabel, Statement *definition ) { 68 75 assert( definition != 0 ); 69 Entry *entry = new Entry( definition ); 70 bool used = false; 76 assert( llabel.size() > 0 ); 71 77 72 for ( std::list< Label >::iterator i = llabel.begin(); i != llabel.end(); i++ ) 73 if ( labelTable.find( *i ) == labelTable.end() ) 74 { used = true; labelTable[ *i ] = entry; } // undefined and unused 75 else 76 if ( labelTable[ *i ]->defined() ) 77 throw SemanticError( "Duplicate definition of label: " + *i ); 78 else 79 labelTable[ *i ]->set_definition( definition ); 78 Entry * e = new Entry( definition ); 80 79 81 if ( ! used ) delete entry; 80 for ( std::list< Label >::iterator i = llabel.begin(); i != llabel.end(); i++ ) { 81 if ( labelTable.find( *i ) == labelTable.end() ) { 82 // all labels on this statement need to use the same entry, so this should only be created once 83 // undefined and unused until now, add an entry 84 labelTable[ *i ] = e; 85 } else if ( labelTable[ *i ]->defined() ) { 86 // defined twice, error 87 throw SemanticError( "Duplicate definition of label: " + *i ); 88 } else { 89 // used previously, but undefined until now -> link with this entry 90 Entry * oldEntry = labelTable[ *i ]; 91 e->add_uses( oldEntry->get_uses() ); 92 labelTable[ *i ] = e; 93 } // if 94 } // for 82 95 83 return labelTable[ llabel.front() ]->get_label(); // this *must* exist 96 // produce one of the labels attached to this statement to be 97 // temporarily used as the canonical label 98 return labelTable[ llabel.front() ]->get_label(); 84 99 } 85 100 86 Label LabelFixer::setLabelsUsg( Label orgValue, Statement *use ) { 101 // Remember all uses of a label. 102 void LabelFixer::setLabelsUsg( Label orgValue, BranchStmt *use ) { 87 103 assert( use != 0 ); 88 104 89 if ( labelTable.find( orgValue ) != labelTable.end() ) 90 labelTable[ orgValue ]->add_use( use ); // the label has been defined or used before 91 else 105 if ( labelTable.find( orgValue ) != labelTable.end() ) { 106 // the label has been defined or used before 107 labelTable[ orgValue ]->add_use( use ); 108 } else { 92 109 labelTable[ orgValue ] = new Entry( 0, use ); 93 94 return labelTable[ orgValue ]->get_label(); 110 } 95 111 } 96 112 113 // Ultimately builds a table that maps a label to its defining statement. 114 // In the process, 97 115 std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) { 98 116 std::map< Statement *, Entry * > def_us; 99 117 100 for ( std::map< Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); i++ ) { 118 // combine the entries for all labels that target the same location 119 for ( std::map< Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); ++i ) { 101 120 Entry *e = i->second; 102 121 103 122 if ( def_us.find ( e->get_definition() ) == def_us.end() ) { 104 123 def_us[ e->get_definition() ] = e; 105 } else { 106 if ( e->used() ) 107 def_us[ e->get_definition() ]->add_uses( e->get_uses() ); 124 } else if ( e->used() ) { 125 def_us[ e->get_definition() ]->add_uses( e->get_uses() ); 108 126 } 109 127 } 110 128 111 // get rid of labelTable112 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++) {129 // create a unique label for each target location. 130 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); ++i ) { 113 131 Statement *to = (*i).first; 114 std::list< Statement *> &from = (*i).second->get_uses(); 115 Label finalLabel = generator->newLabel(); 116 (*i).second->set_label( finalLabel ); 132 Entry * entry = (*i).second; 133 std::list< BranchStmt *> &from = entry->get_uses(); 117 134 135 // no label definition found 118 136 if ( to == 0 ) { 119 BranchStmt *first_use = dynamic_cast<BranchStmt *>(from.back()); 120 Label undef(""); 121 if ( first_use != 0 ) 122 undef = first_use->get_target(); 137 Label undef = from.back()->get_target(); 123 138 throw SemanticError ( "'" + undef + "' label not defined"); 124 139 } 140 141 // generate a new label, and attach it to its defining statement 142 // as the only label on that statement 143 Label finalLabel = generator->newLabel(); 144 entry->set_label( finalLabel ); 125 145 126 146 to->get_labels().clear(); 127 147 to->get_labels().push_back( finalLabel ); 128 148 129 for ( std::list< Statement *>::iterator j = from.begin(); j != from.end(); j++ ) { 130 BranchStmt *jumpTo = dynamic_cast< BranchStmt * > ( *j ); 131 assert( jumpTo != 0 ); 132 jumpTo->set_target( finalLabel ); 149 // redirect each of the source branch statements to the new target label 150 for ( std::list< BranchStmt *>::iterator j = from.begin(); j != from.end(); ++j ) { 151 BranchStmt *jump = *j; 152 assert( jump != 0 ); 153 jump->set_target( finalLabel ); 133 154 } // for 134 155 } // for 135 156 136 // reverse table157 // create a table where each label maps to its defining statement 137 158 std::map< Label, Statement * > *ret = new std::map< Label, Statement * >(); 138 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ )159 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); ++i ) { 139 160 (*ret)[ (*i).second->get_label() ] = (*i).first; 161 } 140 162 141 163 return ret; -
src/ControlStruct/LabelFixer.h
ra61fea9a r9a8930f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue May 26 12:55:10201513 // Update Count : 412 // Last Modified On : Fri May 29 15:25:55 2015 13 // Update Count : 11 14 14 // 15 15 … … 55 55 56 56 Label setLabelsDef( std::list< Label > &, Statement *definition ); 57 Label setLabelsUsg( Label, Statement *usage = 0 );57 void setLabelsUsg( Label, BranchStmt *usage = 0 ); 58 58 59 59 private: 60 60 class Entry { 61 61 public: 62 Entry( Statement *to = 0, Statement *from = 0 );62 Entry( Statement *to = 0, BranchStmt *from = 0 ); 63 63 bool used() { return ( usage.empty() ); } 64 64 bool defined() { return ( definition != 0 ); } … … 71 71 void set_definition( Statement *def ) { definition = def; } 72 72 73 std::list< Statement *> &get_uses() { return usage; }74 void add_use ( Statement *use ) { usage.push_back( use ); }75 void add_uses ( std::list< Statement *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); }73 std::list< BranchStmt *> &get_uses() { return usage; } 74 void add_use ( BranchStmt *use ) { usage.push_back( use ); } 75 void add_uses ( std::list<BranchStmt *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); } 76 76 private: 77 77 Label label; 78 78 Statement *definition; 79 std::list< Statement *> usage;79 std::list<BranchStmt *> usage; 80 80 }; 81 81 -
src/ControlStruct/LabelGenerator.cc
ra61fea9a r9a8930f 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:04201513 // Update Count : 211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 03 14:23:26 2015 13 // Update Count : 9 14 14 // 15 15 … … 29 29 } 30 30 31 Label LabelGenerator::newLabel( ) {31 Label LabelGenerator::newLabel(std::string suffix) { 32 32 std::ostrstream os; 33 os << "__L" << current++ << "__" ;// << std::ends;33 os << "__L" << current++ << "__" << suffix; 34 34 os.freeze( false ); 35 35 std::string ret = std::string (os.str(), os.pcount()); -
src/ControlStruct/LabelGenerator.h
ra61fea9a r9a8930f 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:33:20201513 // Update Count : 311 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 03 14:16:26 2015 13 // Update Count : 5 14 14 // 15 15 … … 18 18 19 19 #include "SynTree/SynTree.h" 20 #include <string> 20 21 21 22 namespace ControlStruct { … … 23 24 public: 24 25 static LabelGenerator *getGenerator(); 25 Label newLabel( );26 Label newLabel(std::string suffix = ""); 26 27 void reset() { current = 0; } 27 28 void rewind() { current--; } -
src/ControlStruct/MLEMutator.cc
ra61fea9a r9a8930f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed May 27 16:19:32201513 // Update Count : 4412 // Last Modified On : Wed Jun 03 15:09:27 2015 13 // Update Count : 170 14 14 // 15 15 … … 19 19 #include "MLEMutator.h" 20 20 #include "SynTree/Statement.h" 21 #include "SynTree/Expression.h" 21 22 22 23 namespace ControlStruct { … … 26 27 } 27 28 28 CompoundStmt* MLEMutator::mutate( CompoundStmt *cmpndStmt ) { 29 bool labeledBlock = false; 30 if ( !(cmpndStmt->get_labels().empty()) ) { 31 labeledBlock = true; 32 enclosingBlocks.push_back( Entry( cmpndStmt ) ); 33 } // if 34 35 std::list< Statement * > &kids = cmpndStmt->get_kids(); 29 // break labels have to come after the statement they break out of, 30 // so mutate a statement, then if they inform us through the breakLabel field 31 // tha they need a place to jump to on a break statement, add the break label 32 // to the body of statements 33 void MLEMutator::fixBlock( std::list< Statement * > &kids ) { 36 34 for ( std::list< Statement * >::iterator k = kids.begin(); k != kids.end(); k++ ) { 37 35 *k = (*k)->acceptMutator(*this); 38 36 39 37 if ( ! get_breakLabel().empty() ) { 40 std::list< Statement * >::iterator next = k ; next++;38 std::list< Statement * >::iterator next = k+1; 41 39 if ( next == kids.end() ) { 42 40 std::list<Label> ls; ls.push_back( get_breakLabel() ); … … 49 47 } // if 50 48 } // for 49 } 50 51 CompoundStmt* MLEMutator::mutate( CompoundStmt *cmpndStmt ) { 52 bool labeledBlock = !(cmpndStmt->get_labels().empty()); 53 if ( labeledBlock ) { 54 Label brkLabel = generator->newLabel(); 55 enclosingBlocks.push_back( Entry( cmpndStmt, brkLabel ) ); 56 } // if 57 58 // a child statement may set the break label 59 // - if they do, attach it to the next statement 60 std::list< Statement * > &kids = cmpndStmt->get_kids(); 61 fixBlock( kids ); 51 62 52 63 if ( labeledBlock ) { 53 64 assert( ! enclosingBlocks.empty() ); 54 if ( ! enclosingBlocks.back(). get_breakExit().empty() ) {55 set_breakLabel( enclosingBlocks.back(). get_breakExit() );65 if ( ! enclosingBlocks.back().useBreakExit().empty() ) { 66 set_breakLabel( enclosingBlocks.back().useBreakExit() ); 56 67 } 57 68 enclosingBlocks.pop_back(); 58 69 } // if 59 70 60 //mutateAll( cmpndStmt->get_kids(), *this );61 71 return cmpndStmt; 62 72 } 63 73 64 Statement *MLEMutator::mutate( WhileStmt *whileStmt ) { 65 enclosingLoops.push_back( Entry( whileStmt ) ); 66 whileStmt->set_body ( whileStmt->get_body()->acceptMutator( *this ) ); 67 74 template< typename LoopClass > 75 Statement *MLEMutator::handleLoopStmt( LoopClass *loopStmt ) { 76 // remember this as the most recent enclosing loop, then mutate 77 // the body of the loop -- this will do SOMETHING with branch statements 78 // and will recursively do the same to nested loops 79 Label brkLabel = generator->newLabel("loopBreak"); 80 Label contLabel = generator->newLabel("loopContinue"); 81 enclosingLoops.push_back( Entry( loopStmt, brkLabel, contLabel ) ); 82 loopStmt->set_body ( loopStmt->get_body()->acceptMutator( *this ) ); 83 84 // sanity check that the enclosing loops have been popped correctly 68 85 Entry &e = enclosingLoops.back(); 69 assert ( e == whileStmt ); 70 whileStmt->set_body( mutateLoop( whileStmt->get_body(), e ) ); 86 assert ( e == loopStmt ); 87 88 // generate labels as needed 89 loopStmt->set_body( mutateLoop( loopStmt->get_body(), e ) ); 71 90 enclosingLoops.pop_back(); 72 91 73 return whileStmt; 74 } 75 76 Statement *MLEMutator::mutate( ForStmt *forStmt ) { 77 enclosingLoops.push_back( Entry( forStmt ) ); 78 maybeMutate( forStmt->get_body(), *this ); 79 80 Entry &e = enclosingLoops.back(); 81 assert ( e == forStmt ); 82 forStmt->set_body( mutateLoop( forStmt->get_body(), e ) ); 83 enclosingLoops.pop_back(); 84 85 return forStmt; 92 return loopStmt; 93 } 94 95 Statement *MLEMutator::mutate( CaseStmt *caseStmt ) { 96 caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) ); 97 fixBlock( caseStmt->get_statements() ); 98 99 return caseStmt; 100 } 101 102 template< typename SwitchClass > 103 Statement *MLEMutator::handleSwitchStmt( SwitchClass *switchStmt ) { 104 // generate a label for breaking out of a labeled switch 105 Label brkLabel = generator->newLabel("switchBreak"); 106 enclosingSwitches.push_back( Entry(switchStmt, brkLabel) ); 107 mutateAll( switchStmt->get_branches(), *this ); 108 109 Entry &e = enclosingSwitches.back(); 110 assert ( e == switchStmt ); 111 112 // only generate break label if labeled break is used 113 if (e.isBreakUsed()) { 114 // for the purposes of keeping switch statements uniform (i.e. all statements that are 115 // direct children of a switch should be CastStmts), append the exit label + break to the 116 // last case statement; create a default case if there are no cases 117 std::list< Statement * > &branches = switchStmt->get_branches(); 118 if ( branches.empty() ) { 119 branches.push_back( CaseStmt::makeDefault() ); 120 } 121 122 if ( CaseStmt * c = dynamic_cast< CaseStmt * >( branches.back() ) ) { 123 std::list<Label> temp; temp.push_back( brkLabel ); 124 c->get_statements().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) ); 125 } else assert(0); // as of this point, all branches of a switch are still CaseStmts 126 } 127 128 assert ( enclosingSwitches.back() == switchStmt ); 129 enclosingSwitches.pop_back(); 130 return switchStmt; 86 131 } 87 132 … … 117 162 throw SemanticError("The target specified in the exit loop statement does not correspond to an enclosing control structure: " + originalTarget ); 118 163 164 // what about exiting innermost block or switch??? 119 165 if ( enclosingLoops.back() == (*check) ) 120 166 return branchStmt; // exit the innermost loop (labels unnecessary) 121 167 122 Label newLabel; 168 // branch error checks, get the appropriate label name and create a goto 169 Label exitLabel; 123 170 switch ( branchStmt->get_type() ) { 124 171 case BranchStmt::Break: 125 if ( check->get_breakExit() != "" ) { 126 newLabel = check->get_breakExit(); 127 } else { 128 newLabel = generator->newLabel(); 129 check->set_breakExit( newLabel ); 130 } // if 172 assert( check->useBreakExit() != ""); 173 exitLabel = check->useBreakExit(); 131 174 break; 132 175 case BranchStmt::Continue: 133 if ( check->get_contExit() != "" ) { 134 newLabel = check->get_contExit(); 135 } else { 136 newLabel = generator->newLabel(); 137 check->set_contExit( newLabel ); 138 } // if 176 assert( check->useContExit() != ""); 177 exitLabel = check->useContExit(); 139 178 break; 140 179 default: 141 return 0; // shouldn't be here180 assert(0); // shouldn't be here 142 181 } // switch 143 182 144 return new BranchStmt( std::list<Label>(), newLabel, BranchStmt::Goto ); 145 } 146 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 154 Label brkLabel = generator->newLabel(); 155 enclosingSwitches.push_back( Entry(switchStmt, "", brkLabel) ); 156 mutateAll( switchStmt->get_branches(), mutator ); { 157 // check if this is necessary (if there is a break to this point, otherwise do not generate 158 std::list<Label> temp; temp.push_back( brkLabel ); 159 switchStmt->get_branches().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) ); 160 } 161 assert ( enclosingSwitches.back() == switchStmt ); 162 enclosingSwitches.pop_back(); 163 return switchStmt; 164 } 165 166 Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) { 167 return handleSwitchStmt( switchStmt, *this ); 168 } 169 170 Statement *MLEMutator::mutate( ChooseStmt *switchStmt ) { 171 return handleSwitchStmt( switchStmt, *this ); 183 return new BranchStmt( std::list<Label>(), exitLabel, BranchStmt::Goto ); 172 184 } 173 185 174 186 Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) { 187 // ensure loop body is a block 175 188 CompoundStmt *newBody; 176 189 if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) { … … 179 192 } // if 180 193 181 Label endLabel = e.get_contExit(); 182 183 if ( e.get_breakExit() != "" ) { 184 if ( endLabel == "" ) endLabel = generator->newLabel(); 185 // check for whether this label is used or not, so as to not generate extraneous gotos 186 if (e.breakExitUsed) 187 newBody->get_kids().push_back( new BranchStmt( std::list< Label >(), endLabel, BranchStmt::Goto ) ); 188 // xxx 189 //std::list< Label > ls; ls.push_back( e.get_breakExit() ); 190 set_breakLabel( e.get_breakExit() ); 191 //newBody->get_kids().push_back( new BranchStmt( ls, "", BranchStmt::Break ) ); 192 } // if 193 194 if ( e.get_breakExit() != "" || e.get_contExit() != "" ) { 195 if (dynamic_cast< NullStmt *>( newBody->get_kids().back() )) 196 newBody->get_kids().back()->get_labels().push_back( endLabel ); 197 else { 198 std::list < Label > ls; ls.push_back( endLabel ); 199 newBody->get_kids().push_back( new NullStmt( ls ) ); 200 } // if 201 } // if 194 // only generate these when needed 195 196 if ( e.isContUsed() ) { 197 // continue label goes in the body as the last statement 198 std::list< Label > labels; labels.push_back( e.useContExit() ); 199 newBody->get_kids().push_back( new NullStmt( labels ) ); 200 } 201 202 if ( e.isBreakUsed() ) { 203 // break label goes after the loop -- it'll get set by the 204 // outer mutator if we do this 205 set_breakLabel( e.useBreakExit() ); 206 } 202 207 203 208 return newBody; 204 209 } 205 210 206 //*** Entry's methods 207 void MLEMutator::Entry::set_contExit( Label l ) { 208 assert ( contExit == "" || contExit == l ); 209 contExit = l; 210 } 211 212 void MLEMutator::Entry::set_breakExit( Label l ) { 213 assert ( breakExit == "" || breakExit == l ); 214 breakExit = l; 215 } 211 Statement *MLEMutator::mutate( WhileStmt *whileStmt ) { 212 return handleLoopStmt( whileStmt ); 213 } 214 215 Statement *MLEMutator::mutate( ForStmt *forStmt ) { 216 return handleLoopStmt( forStmt ); 217 } 218 219 Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) { 220 return handleSwitchStmt( switchStmt ); 221 } 222 223 Statement *MLEMutator::mutate( ChooseStmt *switchStmt ) { 224 return handleSwitchStmt( switchStmt ); 225 } 226 216 227 } // namespace ControlStruct 217 228 -
src/ControlStruct/MLEMutator.h
ra61fea9a r9a8930f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue May 26 15:04:21201513 // Update Count : 712 // Last Modified On : Wed Jun 03 15:06:36 2015 13 // Update Count : 25 14 14 // 15 15 … … 38 38 Statement *mutate( BranchStmt *branchStmt ) throw ( SemanticError ); 39 39 40 Statement *mutate( CaseStmt *caseStmt ); 40 41 Statement *mutate( SwitchStmt *switchStmt ); 41 42 Statement *mutate( ChooseStmt *switchStmt ); … … 48 49 class Entry { 49 50 public: 50 explicit Entry( Statement *_loop = 0, Label _contExit = Label(""), Label _breakExit = Label("") ) :51 loop( _loop ), contExit( _contExit ), breakExit( _breakExit ), contExitUsed( false ), breakExitUsed( false) {}51 explicit Entry( Statement *_loop, Label _breakExit, Label _contExit = Label("") ) : 52 loop( _loop ), breakExit( _breakExit ), contExit( _contExit ), breakUsed(false), contUsed(false) {} 52 53 53 54 bool operator==( const Statement *stmt ) { return ( loop == stmt ); } … … 58 59 Statement *get_loop() const { return loop; } 59 60 60 Label get_contExit() const {return contExit; }61 void set_contExit( Label );61 Label useContExit() { contUsed = true; return contExit; } 62 Label useBreakExit() { breakUsed = true; return breakExit; } 62 63 63 Label get_breakExit() const { return breakExit; }64 void set_breakExit( Label );64 bool isContUsed() const { return contUsed; } 65 bool isBreakUsed() const { return breakUsed; } 65 66 66 67 private: 67 68 Statement *loop; 68 Label contExit, breakExit; 69 public: // hack, provide proper [sg]etters 70 bool contExitUsed, breakExitUsed; 69 Label breakExit, contExit; 70 bool breakUsed, contUsed; 71 71 }; 72 72 … … 76 76 LabelGenerator *generator; 77 77 78 template< typename LoopClass > 79 Statement *handleLoopStmt( LoopClass *loopStmt ); 80 78 81 template< typename SwitchClass > 79 friend Statement *handleSwitchStmt( SwitchClass *switchStmt, MLEMutator &mutator ); 82 Statement *handleSwitchStmt( SwitchClass *switchStmt ); 83 84 void fixBlock( std::list< Statement * > &kids ); 80 85 }; 81 86 } // namespace ControlStruct -
src/ControlStruct/Mutate.cc
ra61fea9a r9a8930f 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:52201513 // Update Count : 211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 03 23:08:43 2015 13 // Update Count : 5 14 14 // 15 15 … … 37 37 void mutate( std::list< Declaration * > translationUnit ) { 38 38 // ForExprMutator formut; 39 40 // normalizes label definitions and generates multi-level 41 // exit labels 39 42 LabelFixer lfix; 43 44 // transform choose statements into switch statements 40 45 ChooseMutator chmut; 46 47 // expand case ranges and turn fallthru into a null statement 41 48 CaseRangeMutator ranges; // has to run after ChooseMutator 49 42 50 //ExceptMutator exc; 43 51 // LabelTypeChecker lbl;
Note:
See TracChangeset
for help on using the changeset viewer.