Changeset 23b6f4d7
- Timestamp:
- Jun 23, 2016, 12:16:45 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, with_gc
- Children:
- 71a145de
- Parents:
- 0caaa6a
- git-author:
- Rob Schluntz <rschlunt@…> (06/23/16 11:34:11)
- git-committer:
- Rob Schluntz <rschlunt@…> (06/23/16 12:16:45)
- Location:
- src
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/LabelFixer.cc
r0caaa6a r23b6f4d7 95 95 96 96 for ( std::list< Label >::iterator i = llabel.begin(); i != llabel.end(); i++ ) { 97 if ( labelTable.find( *i ) == labelTable.end() ) { 97 Label & l = *i; 98 l.set_statement( definition ); // attach statement to the label to be used later 99 if ( labelTable.find( l ) == labelTable.end() ) { 98 100 // all labels on this statement need to use the same entry, so this should only be created once 99 101 // undefined and unused until now, add an entry 100 labelTable[ *i] = e;101 } else if ( labelTable[ *i]->defined() ) {102 labelTable[ l ] = e; 103 } else if ( labelTable[ l ]->defined() ) { 102 104 // defined twice, error 103 throw SemanticError( "Duplicate definition of label: " + (*i).get_name() );105 throw SemanticError( "Duplicate definition of label: " + l.get_name() ); 104 106 } else { 105 107 // used previously, but undefined until now -> link with this entry 106 delete labelTable[ *i];107 labelTable[ *i] = e;108 delete labelTable[ l ]; 109 labelTable[ l ] = e; 108 110 } // if 109 111 } // for … … 114 116 } 115 117 116 // A label was used, add it otthe table if it isn't already there118 // A label was used, add it to the table if it isn't already there 117 119 template< typename UsageNode > 118 120 void LabelFixer::setLabelsUsg( Label orgValue, UsageNode *use ) { -
src/ControlStruct/MLEMutator.cc
r0caaa6a r23b6f4d7 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // MLEMutator.cc -- 7 // MLEMutator.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves … … 14 14 // 15 15 16 // NOTE: There are two known subtle differences from the code that uC++ 16 // NOTE: There are two known subtle differences from the code that uC++ 17 17 // generates for the same input 18 18 // -CFA puts the break label inside at the end of a switch, uC++ puts it after … … 34 34 } 35 35 36 // break labels have to come after the statement they break out of, 36 // break labels have to come after the statement they break out of, 37 37 // so mutate a statement, then if they inform us through the breakLabel field 38 // tha they need a place to jump to on a break statement, add the break label 38 // tha they need a place to jump to on a break statement, add the break label 39 39 // to the body of statements 40 40 void MLEMutator::fixBlock( std::list< Statement * > &kids ) { … … 44 44 if ( ! get_breakLabel().empty() ) { 45 45 std::list< Statement * >::iterator next = k+1; 46 Statement * stmt = 0; 46 47 if ( next == kids.end() ) { 47 48 std::list<Label> ls; ls.push_back( get_breakLabel() ); 48 kids.push_back( new NullStmt( ls ) );49 kids.push_back( stmt = new NullStmt( ls ) ); 49 50 } else { 50 ( *next)->get_labels().push_back( get_breakLabel() );51 (stmt = *next)->get_labels().push_back( get_breakLabel() ); 51 52 } 53 stmt->get_labels().front().set_statement( stmt ); 52 54 53 55 set_breakLabel(""); … … 81 83 template< typename LoopClass > 82 84 Statement *MLEMutator::handleLoopStmt( LoopClass *loopStmt ) { 83 // remember this as the most recent enclosing loop, then mutate 85 // remember this as the most recent enclosing loop, then mutate 84 86 // the body of the loop -- this will determine whether brkLabel 85 87 // and contLabel are used with branch statements … … 111 113 template< typename SwitchClass > 112 114 Statement *MLEMutator::handleSwitchStmt( SwitchClass *switchStmt ) { 113 // generate a label for breaking out of a labeled switch 115 // generate a label for breaking out of a labeled switch 114 116 Label brkLabel = generator->newLabel("switchBreak"); 115 117 enclosingSwitches.push_back( Entry(switchStmt, brkLabel) ); 116 mutateAll( switchStmt->get_branches(), *this ); 118 mutateAll( switchStmt->get_branches(), *this ); 117 119 118 120 Entry &e = enclosingSwitches.back(); … … 121 123 // only generate break label if labeled break is used 122 124 if (e.isBreakUsed()) { 123 // for the purposes of keeping switch statements uniform (i.e. all statements that are 124 // direct children of a switch should be CastStmts), append the exit label + break to the 125 // for the purposes of keeping switch statements uniform (i.e. all statements that are 126 // direct children of a switch should be CastStmts), append the exit label + break to the 125 127 // last case statement; create a default case if there are no cases 126 128 std::list< Statement * > &branches = switchStmt->get_branches(); … … 131 133 if ( CaseStmt * c = dynamic_cast< CaseStmt * >( branches.back() ) ) { 132 134 std::list<Label> temp; temp.push_back( brkLabel ); 133 c->get_statements().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) ); 135 Statement * stmt = new BranchStmt( temp, Label(""), BranchStmt::Break ); 136 stmt->get_labels().front().set_statement( stmt ); 137 c->get_statements().push_back( stmt ); 134 138 } else assert(0); // as of this point, all branches of a switch are still CaseStmts 135 139 } … … 206 210 // continue label goes in the body as the last statement 207 211 std::list< Label > labels; labels.push_back( e.useContExit() ); 208 newBody->get_kids().push_back( new NullStmt( labels ) ); 212 Statement * stmt = new NullStmt( labels ); 213 stmt->get_labels().front().set_statement( stmt ); 214 newBody->get_kids().push_back( stmt ); 209 215 } 210 216 211 217 if ( e.isBreakUsed() ) { 212 // break label goes after the loop -- it'll get set by the 218 // break label goes after the loop -- it'll get set by the 213 219 // outer mutator if we do this 214 set_breakLabel( e.useBreakExit() ); 220 set_breakLabel( e.useBreakExit() ); 215 221 } 216 222 … … 231 237 232 238 Statement *MLEMutator::mutate( ChooseStmt *switchStmt ) { 233 return handleSwitchStmt( switchStmt ); 239 return handleSwitchStmt( switchStmt ); 234 240 } 235 241
Note: See TracChangeset
for help on using the changeset viewer.