Changeset a08ba92 for translator/ControlStruct
- Timestamp:
- May 19, 2015, 4:58:14 PM (11 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:
- 843054c2
- Parents:
- 01aeade
- Location:
- translator/ControlStruct
- Files:
-
- 16 edited
-
CaseRangeMutator.cc (modified) (2 diffs)
-
CaseRangeMutator.h (modified) (2 diffs)
-
ChooseMutator.cc (modified) (2 diffs)
-
ChooseMutator.h (modified) (2 diffs)
-
ForExprMutator.cc (modified) (2 diffs)
-
ForExprMutator.h (modified) (1 diff)
-
LabelFixer.cc (modified) (2 diffs)
-
LabelFixer.h (modified) (2 diffs)
-
LabelGenerator.cc (modified) (2 diffs)
-
LabelGenerator.h (modified) (2 diffs)
-
LabelTypeChecker.cc (modified) (2 diffs)
-
LabelTypeChecker.h (modified) (2 diffs)
-
MLEMutator.cc (modified) (2 diffs)
-
MLEMutator.h (modified) (2 diffs)
-
Mutate.cc (modified) (2 diffs)
-
Mutate.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
translator/ControlStruct/CaseRangeMutator.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // CaseRangeMutator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 0 14 // 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 13:00:28 2015 13 // Update Count : 3 14 // 15 15 16 #include <list> 16 17 #include <cassert> … … 27 28 28 29 namespace ControlStruct { 29 Statement *CaseRangeMutator::mutate(ChooseStmt *chooseStmt) { 30 /* There shouldn't be any `choose' statements by now, throw an exception or something. */ 31 throw( 0 ) ; /* FIXME */ 32 } 33 34 Statement *CaseRangeMutator::mutate(SwitchStmt *switchStmt) { 35 std::list< Statement * > &cases = switchStmt->get_branches(); 36 37 // a `for' would be more natural... all this contortions are because `replace' invalidates the iterator 38 std::list< Statement * >::iterator i = cases.begin(); 39 while ( i != cases.end() ) { 40 (*i)->acceptMutator( *this ); 41 42 if ( ! newCaseLabels.empty() ) { 43 std::list< Statement * > newCases; 44 45 // transform( newCaseLabels.begin(), newCaseLabels.end(), bnd1st( ptr_fun( ctor< CaseStmt, Label, Expression * > ) ) ); 46 47 for ( std::list< Expression * >::iterator j = newCaseLabels.begin(); 48 j != newCaseLabels.end(); j++ ) { 49 std::list<Label> emptyLabels; 50 std::list< Statement *> emptyStmts; 51 newCases.push_back( new CaseStmt( emptyLabels, *j, emptyStmts ) ); 52 } 53 54 if ( CaseStmt *currentCase = dynamic_cast< CaseStmt * > ( *i ) ) 55 if ( ! currentCase->get_statements().empty() ) { 56 CaseStmt *lastCase = dynamic_cast< CaseStmt * > ( newCases.back() ); 57 if ( lastCase == 0 ) { throw ( 0 ); /* FIXME */ } // something is very wrong, as I just made these, and they were all cases 58 // transfer the statement block (if any) to the new list: 59 lastCase->set_statements( currentCase->get_statements() ); 60 } 61 std::list< Statement * >::iterator j = i; advance( j, 1 ); 62 replace ( cases, i, newCases ); 63 i = j; 64 newCaseLabels.clear(); 65 } else 66 i++; 67 } // while 68 69 return switchStmt; 70 } 71 72 Statement *CaseRangeMutator::mutate(FallthruStmt *fallthruStmt) { 73 //delete fallthruStmt; 74 return new NullStmt(); 75 } 76 77 Statement *CaseRangeMutator::mutate(CaseStmt *caseStmt) { 78 UntypedExpr *cond; 79 if ( (cond = dynamic_cast< UntypedExpr * >( caseStmt->get_condition() )) != 0 ) { 80 NameExpr *nmfunc; 81 if ( (nmfunc = dynamic_cast< NameExpr *>( cond->get_function() )) != 0 ) { 82 if ( nmfunc->get_name() == std::string("Range") ) { 83 assert( cond->get_args().size() == 2 ); 84 std::list<Expression *>::iterator i = cond->get_args().begin(); 85 Expression *lo = *i, *hi = *(++i); // "unnecessary" temporaries 86 fillRange( lo, hi); 87 } 88 } 89 } else if ( TupleExpr *tcond = dynamic_cast< TupleExpr * >( caseStmt->get_condition() ) ) { 90 // case list 91 assert( ! tcond->get_exprs().empty() ); 92 for ( std::list< Expression * >::iterator i = tcond->get_exprs().begin(); i != tcond->get_exprs().end(); i++ ) 93 newCaseLabels.push_back( *i ); // do I need to clone them? 94 } // if 95 96 std::list< Statement * > &stmts = caseStmt->get_statements(); 97 mutateAll ( stmts, *this ); 98 99 return caseStmt; 100 } 101 102 void CaseRangeMutator::fillRange(Expression *lo, Expression *hi) { 103 // generate the actual range (and check for consistency) 104 Constant *c_lo, *c_hi; 105 ConstantExpr *ce_lo, *ce_hi; 106 ce_lo = dynamic_cast< ConstantExpr * >( lo ); 107 ce_hi = dynamic_cast< ConstantExpr * >( hi ); 108 109 if ( ce_lo && ce_hi ) { 110 c_lo = ce_lo->get_constant(); c_hi = ce_hi->get_constant(); 111 } /* else { 112 if ( ! ce_lo ) ; 113 if ( ! ce_hi ) ; 114 } */ 115 BasicType *ty_lo = dynamic_cast< BasicType * >( c_lo->get_type() ), 116 *ty_hi = dynamic_cast< BasicType * >( c_hi->get_type() ); 117 118 if ( ! ty_lo || ! ty_hi ) 119 return; // one of them is not a constant 120 121 switch ( ty_lo->get_kind() ) { 122 case BasicType::Char: 123 case BasicType::UnsignedChar: 124 switch ( ty_hi->get_kind() ){ 30 Statement *CaseRangeMutator::mutate( ChooseStmt *chooseStmt ) { 31 // There shouldn't be any `choose' statements by now, throw an exception or something. 32 throw( 0 ) ; /* FIXME */ 33 } 34 35 Statement *CaseRangeMutator::mutate( SwitchStmt *switchStmt ) { 36 std::list< Statement * > &cases = switchStmt->get_branches(); 37 38 // a `for' would be more natural... all this contortions are because `replace' invalidates the iterator 39 std::list< Statement * >::iterator i = cases.begin(); 40 while ( i != cases.end() ) { 41 (*i )->acceptMutator( *this ); 42 43 if ( ! newCaseLabels.empty() ) { 44 std::list< Statement * > newCases; 45 46 // transform( newCaseLabels.begin(), newCaseLabels.end(), bnd1st( ptr_fun( ctor< CaseStmt, Label, Expression * > ) ) ); 47 48 for ( std::list< Expression * >::iterator j = newCaseLabels.begin(); 49 j != newCaseLabels.end(); j++ ) { 50 std::list<Label> emptyLabels; 51 std::list< Statement *> emptyStmts; 52 newCases.push_back( new CaseStmt( emptyLabels, *j, emptyStmts ) ); 53 } // for 54 55 if ( CaseStmt *currentCase = dynamic_cast< CaseStmt * > ( *i ) ) 56 if ( ! currentCase->get_statements().empty() ) { 57 CaseStmt *lastCase = dynamic_cast< CaseStmt * > ( newCases.back() ); 58 if ( lastCase == 0 ) { throw ( 0 ); /* FIXME */ } // something is very wrong, as I just made these, and they were all cases 59 // transfer the statement block ( if any ) to the new list: 60 lastCase->set_statements( currentCase->get_statements() ); 61 } // if 62 std::list< Statement * >::iterator j = i; advance( j, 1 ); 63 replace ( cases, i, newCases ); 64 i = j; 65 newCaseLabels.clear(); 66 } else 67 i++; 68 } // while 69 70 return switchStmt; 71 } 72 73 Statement *CaseRangeMutator::mutate( FallthruStmt *fallthruStmt ) { 74 //delete fallthruStmt; 75 return new NullStmt(); 76 } 77 78 Statement *CaseRangeMutator::mutate( CaseStmt *caseStmt ) { 79 UntypedExpr *cond; 80 if ( ( cond = dynamic_cast< UntypedExpr * >( caseStmt->get_condition() )) != 0 ) { 81 NameExpr *nmfunc; 82 if ( ( nmfunc = dynamic_cast< NameExpr *>( cond->get_function() )) != 0 ) { 83 if ( nmfunc->get_name() == std::string("Range") ) { 84 assert( cond->get_args().size() == 2 ); 85 std::list<Expression *>::iterator i = cond->get_args().begin(); 86 Expression *lo = *i, *hi = *(++i ); // "unnecessary" temporaries 87 fillRange( lo, hi ); 88 } // if 89 } // if 90 } else if ( TupleExpr *tcond = dynamic_cast< TupleExpr * >( caseStmt->get_condition() ) ) { 91 // case list 92 assert( ! tcond->get_exprs().empty() ); 93 for ( std::list< Expression * >::iterator i = tcond->get_exprs().begin(); i != tcond->get_exprs().end(); i++ ) 94 newCaseLabels.push_back( *i ); // do I need to clone them? 95 } // if 96 97 std::list< Statement * > &stmts = caseStmt->get_statements(); 98 mutateAll ( stmts, *this ); 99 100 return caseStmt; 101 } 102 103 void CaseRangeMutator::fillRange( Expression *lo, Expression *hi ) { 104 // generate the actual range ( and check for consistency ) 105 Constant *c_lo, *c_hi; 106 ConstantExpr *ce_lo, *ce_hi; 107 ce_lo = dynamic_cast< ConstantExpr * >( lo ); 108 ce_hi = dynamic_cast< ConstantExpr * >( hi ); 109 110 if ( ce_lo && ce_hi ) { 111 c_lo = ce_lo->get_constant(); c_hi = ce_hi->get_constant(); 112 } /* else { 113 if ( ! ce_lo ) ; 114 if ( ! ce_hi ) ; 115 } */ 116 BasicType *ty_lo = dynamic_cast< BasicType * >( c_lo->get_type() ), 117 *ty_hi = dynamic_cast< BasicType * >( c_hi->get_type() ); 118 119 if ( ! ty_lo || ! ty_hi ) 120 return; // one of them is not a constant 121 122 switch ( ty_lo->get_kind() ) { 125 123 case BasicType::Char: 126 124 case BasicType::UnsignedChar: 127 // first case, they are both printable ASCII characters represented as 'x' 128 if ( c_lo->get_value().size() == 3 && c_hi->get_value().size() == 3 ) { 129 char ch_lo = (c_lo->get_value())[1], ch_hi = (c_hi->get_value())[1]; 130 131 if ( ch_lo > ch_hi ) { char t=ch_lo; ch_lo=ch_hi; ch_hi=t; } 132 133 for ( char c = ch_lo; c <= ch_hi; c++ ){ 134 Type::Qualifiers q; 135 Constant cnst( new BasicType(q, BasicType::Char), 136 std::string("'") + c + std::string("'") ); 137 newCaseLabels.push_back( new ConstantExpr( cnst ) ); 125 switch ( ty_hi->get_kind() ) { 126 case BasicType::Char: 127 case BasicType::UnsignedChar: 128 // first case, they are both printable ASCII characters represented as 'x' 129 if ( c_lo->get_value().size() == 3 && c_hi->get_value().size() == 3 ) { 130 char ch_lo = ( c_lo->get_value())[1], ch_hi = ( c_hi->get_value())[1]; 131 132 if ( ch_lo > ch_hi ) { char t=ch_lo; ch_lo=ch_hi; ch_hi=t; } 133 134 for ( char c = ch_lo; c <= ch_hi; c++ ) { 135 Type::Qualifiers q; 136 Constant cnst( new BasicType( q, BasicType::Char ), 137 std::string("'") + c + std::string("'") ); 138 newCaseLabels.push_back( new ConstantExpr( cnst ) ); 139 } // for 140 141 return; 142 } // if 143 break; 144 default: 145 // error: incompatible constants 146 break; 147 } // switch 148 break; 149 case BasicType::ShortSignedInt: 150 case BasicType::ShortUnsignedInt: 151 case BasicType::SignedInt: 152 case BasicType::UnsignedInt: 153 case BasicType::LongSignedInt: 154 case BasicType::LongUnsignedInt: 155 case BasicType::LongLongSignedInt: 156 case BasicType::LongLongUnsignedInt: 157 switch ( ty_hi->get_kind() ) { 158 case BasicType::ShortSignedInt: 159 case BasicType::ShortUnsignedInt: 160 case BasicType::SignedInt: 161 case BasicType::UnsignedInt: 162 case BasicType::LongSignedInt: 163 case BasicType::LongUnsignedInt: 164 case BasicType::LongLongSignedInt: 165 case BasicType::LongLongUnsignedInt: { 166 int i_lo = atoi( c_lo->get_value().c_str()), 167 i_hi = atoi( c_hi->get_value().c_str()); 168 169 if ( i_lo > i_hi ) { int t=i_lo; i_lo=i_hi; i_hi=t; } 170 171 for ( int c = i_lo; c <= i_hi; c++ ) { 172 Type::Qualifiers q; 173 Constant cnst( new BasicType( q, ty_hi->get_kind()), // figure can't hurt (used to think in positives) 174 toString< int >( c ) ); 175 newCaseLabels.push_back( new ConstantExpr( cnst ) ); 176 } 177 178 return; 179 } 180 default: 181 // error: incompatible constants 182 break; 138 183 } 139 184 break; 185 default: 186 break; 187 } // switch 188 189 /* End: */{ 190 // invalid range, signal a warning (it still generates the two case labels) 191 newCaseLabels.push_back( lo ); 192 newCaseLabels.push_back( hi ); 140 193 return; 141 }142 break;143 default:144 // error: incompatible constants145 break;146 194 } 147 break; 148 case BasicType::ShortSignedInt: 149 case BasicType::ShortUnsignedInt: 150 case BasicType::SignedInt: 151 case BasicType::UnsignedInt: 152 case BasicType::LongSignedInt: 153 case BasicType::LongUnsignedInt: 154 case BasicType::LongLongSignedInt: 155 case BasicType::LongLongUnsignedInt: 156 switch ( ty_hi->get_kind() ) { 157 case BasicType::ShortSignedInt: 158 case BasicType::ShortUnsignedInt: 159 case BasicType::SignedInt: 160 case BasicType::UnsignedInt: 161 case BasicType::LongSignedInt: 162 case BasicType::LongUnsignedInt: 163 case BasicType::LongLongSignedInt: 164 case BasicType::LongLongUnsignedInt: { 165 int i_lo = atoi(c_lo->get_value().c_str()), 166 i_hi = atoi(c_hi->get_value().c_str()); 167 168 if ( i_lo > i_hi ) { int t=i_lo; i_lo=i_hi; i_hi=t; } 169 170 for ( int c = i_lo; c <= i_hi; c++ ){ 171 Type::Qualifiers q; 172 Constant cnst( new BasicType(q, ty_hi->get_kind()), // figure can't hurt (used to think in positives) 173 toString< int >( c ) ); 174 newCaseLabels.push_back( new ConstantExpr( cnst ) ); 175 } 176 177 return; 178 } 179 default: 180 // error: incompatible constants 181 break; 182 } 183 break; 184 default: 185 break; 186 } // switch 187 188 /* End: */{ 189 // invalid range, signal a warning (it still generates the two case labels) 190 newCaseLabels.push_back( lo ); 191 newCaseLabels.push_back( hi ); 192 return; 193 } 194 } 195 } 195 196 } // namespace ControlStruct 197 196 198 // Local Variables: // 197 199 // tab-width: 4 // -
translator/ControlStruct/CaseRangeMutator.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // CaseRangeMutator.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:22:51 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef CASERNG_MUTATOR_H 16 17 #define CASERNG_MUTATOR_H … … 21 22 22 23 namespace ControlStruct { 23 class CaseRangeMutator : public Mutator {24 public:25 CaseRangeMutator() {}24 class CaseRangeMutator : public Mutator { 25 public: 26 CaseRangeMutator() {} 26 27 27 virtual Statement *mutate( ChooseStmt * );28 virtual Statement *mutate( SwitchStmt * );29 virtual Statement *mutate( FallthruStmt * );30 virtual Statement *mutate( CaseStmt * );31 private:32 void fillRange( Expression *lo, Expression *hi );28 virtual Statement *mutate( ChooseStmt * ); 29 virtual Statement *mutate( SwitchStmt * ); 30 virtual Statement *mutate( FallthruStmt * ); 31 virtual Statement *mutate( CaseStmt * ); 32 private: 33 void fillRange( Expression *lo, Expression *hi ); 33 34 34 Expression *currentCondition; 35 std::list< Expression * > newCaseLabels; 36 }; 37 35 Expression *currentCondition; 36 std::list< Expression * > newCaseLabels; 37 }; 38 38 } // namespace ControlStruct 39 39 40 40 #endif // CASERNG_MUTATOR_H 41 41 42 /*43 Local Variables:44 mode: c++45 End:46 */47 42 // Local Variables: // 48 43 // tab-width: 4 // -
translator/ControlStruct/ChooseMutator.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // ChooseMutator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:31:39 2015 13 // Update Count : 2 14 14 // 15 15 16 #include <list> 16 17 … … 19 20 20 21 namespace ControlStruct { 21 Statement *ChooseMutator::mutate( ChooseStmt *chooseStmt) {22 bool enclosingChoose = insideChoose;23 insideChoose = true;24 mutateAll( chooseStmt->get_branches(), *this );25 insideChoose = enclosingChoose;26 return new SwitchStmt( chooseStmt->get_labels(), chooseStmt->get_condition(), chooseStmt->get_branches() );27 }22 Statement *ChooseMutator::mutate( ChooseStmt *chooseStmt ) { 23 bool enclosingChoose = insideChoose; 24 insideChoose = true; 25 mutateAll( chooseStmt->get_branches(), *this ); 26 insideChoose = enclosingChoose; 27 return new SwitchStmt( chooseStmt->get_labels(), chooseStmt->get_condition(), chooseStmt->get_branches() ); 28 } 28 29 29 Statement *ChooseMutator::mutate( SwitchStmt *switchStmt ) {30 bool enclosingChoose = insideChoose;31 insideChoose = false;32 mutateAll( switchStmt->get_branches(), *this );33 insideChoose = enclosingChoose;34 return switchStmt;35 }30 Statement *ChooseMutator::mutate( SwitchStmt *switchStmt ) { 31 bool enclosingChoose = insideChoose; 32 insideChoose = false; 33 mutateAll( switchStmt->get_branches(), *this ); 34 insideChoose = enclosingChoose; 35 return switchStmt; 36 } 36 37 37 Statement *ChooseMutator::mutate( FallthruStmt *fallthruStmt ) {38 delete fallthruStmt;39 return new NullStmt();40 }38 Statement *ChooseMutator::mutate( FallthruStmt *fallthruStmt ) { 39 delete fallthruStmt; 40 return new NullStmt(); 41 } 41 42 42 Statement* ChooseMutator::mutate(CaseStmt *caseStmt) {43 std::list< Statement * > &stmts = caseStmt->get_statements();43 Statement* ChooseMutator::mutate( CaseStmt *caseStmt ) { 44 std::list< Statement * > &stmts = caseStmt->get_statements(); 44 45 45 if ( insideChoose ) {46 BranchStmt *posBrk;47 if ( (( posBrk = dynamic_cast< BranchStmt * > ( stmts.back() ) ) &&48 ( posBrk->get_type() == BranchStmt::Break )) // last statement in the list is a (superfluous) 'break'49 || dynamic_cast< FallthruStmt * > ( stmts.back() ) )50 ;51 else {52 stmts.push_back( new BranchStmt( std::list< Label >(), "", BranchStmt::Break ) );53 } // if54 } // if46 if ( insideChoose ) { 47 BranchStmt *posBrk; 48 if ( (( posBrk = dynamic_cast< BranchStmt * > ( stmts.back() ) ) && 49 ( posBrk->get_type() == BranchStmt::Break )) // last statement in the list is a (superfluous) 'break' 50 || dynamic_cast< FallthruStmt * > ( stmts.back() ) ) 51 ; 52 else { 53 stmts.push_back( new BranchStmt( std::list< Label >(), "", BranchStmt::Break ) ); 54 } // if 55 } // if 55 56 56 mutateAll ( stmts, *this );57 return caseStmt;58 }57 mutateAll ( stmts, *this ); 58 return caseStmt; 59 } 59 60 } // namespace ControlStruct 61 60 62 // Local Variables: // 61 63 // tab-width: 4 // -
translator/ControlStruct/ChooseMutator.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // ChooseMutator.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:33:11 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef CHOOSE_MUTATOR_H 16 17 #define CHOOSE_MUTATOR_H … … 21 22 22 23 namespace ControlStruct { 24 class ChooseMutator : public Mutator { 25 public: 26 ChooseMutator() : insideChoose( false ) {} 23 27 24 class ChooseMutator : public Mutator { 25 public: 26 ChooseMutator() : insideChoose( false ) {} 27 28 virtual Statement *mutate( ChooseStmt * ); 29 virtual Statement *mutate( SwitchStmt * ); 30 virtual Statement *mutate( FallthruStmt * ); 31 virtual Statement *mutate( CaseStmt * ); 32 private: 33 bool insideChoose; 34 }; 28 virtual Statement *mutate( ChooseStmt * ); 29 virtual Statement *mutate( SwitchStmt * ); 30 virtual Statement *mutate( FallthruStmt * ); 31 virtual Statement *mutate( CaseStmt * ); 32 private: 33 bool insideChoose; 34 }; 35 35 } // namespace ControlStruct 36 36 37 37 #endif // CHOOSE_MUTATOR_H 38 38 39 /*40 Local Variables:41 mode: c++42 End:43 */44 39 // Local Variables: // 45 40 // tab-width: 4 // -
translator/ControlStruct/ForExprMutator.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // ForExprMutator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:31:47 2015 13 // Update Count : 2 14 14 // 15 15 16 #include "SynTree/Mutator.h" 16 17 #include "SynTree/Statement.h" … … 18 19 19 20 namespace ControlStruct { 20 Statement *ForExprMutator::mutate( ForStmt *forStmt ) {21 // recurse down all nest for loops to hoist any initializer declarations to make them C89 (rather than C99)22 forStmt->set_body( forStmt->get_body()->acceptMutator( *this ) );23 if ( DeclStmt *decl = dynamic_cast< DeclStmt * > ( forStmt->get_initialization() ) ) {24 // create compound statement, move initializer declaration outside, leave _for_ as-is25 CompoundStmt *block = new CompoundStmt( std::list< Label >() );26 std::list<Statement *> &stmts = block->get_kids();21 Statement *ForExprMutator::mutate( ForStmt *forStmt ) { 22 // recurse down all nest for loops to hoist any initializer declarations to make them C89 (rather than C99) 23 forStmt->set_body( forStmt->get_body()->acceptMutator( *this ) ); 24 if ( DeclStmt *decl = dynamic_cast< DeclStmt * > ( forStmt->get_initialization() ) ) { 25 // create compound statement, move initializer declaration outside, leave _for_ as-is 26 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 27 std::list<Statement *> &stmts = block->get_kids(); 27 28 28 stmts.push_back( decl );29 forStmt->set_initialization( 0 );30 stmts.push_back( forStmt );29 stmts.push_back( decl ); 30 forStmt->set_initialization( 0 ); 31 stmts.push_back( forStmt ); 31 32 32 return block;33 } // if33 return block; 34 } // if 34 35 35 return forStmt;36 }36 return forStmt; 37 } 37 38 } // namespace ControlStruct 39 38 40 // Local Variables: // 39 41 // tab-width: 4 // -
translator/ControlStruct/ForExprMutator.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // ForExprMutator.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:25:19 2015 13 // Update Count : 2 14 14 // 15 15 16 #ifndef FOR_MUTATOR_H 16 17 #define FOR_MUTATOR_H 17 18 18 19 #include "SynTree/Mutator.h" 19 20 20 #include "utility.h" 21 21 22 22 namespace ControlStruct { 23 class ForExprMutator : public Mutator {24 public:25 virtual Statement *mutate( ForStmt * );26 };23 class ForExprMutator : public Mutator { 24 public: 25 virtual Statement *mutate( ForStmt * ); 26 }; 27 27 } // namespace ControlStruct 28 28 29 29 #endif // CHOOSE_MUTATOR_H 30 30 31 /*32 Local Variables:33 mode: c++34 End:35 */36 31 // Local Variables: // 37 32 // tab-width: 4 // -
translator/ControlStruct/LabelFixer.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // LabelFixer.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:25:59 2015 13 // Update Count : 1 14 14 // 15 15 16 #include <list> 16 17 #include <cassert> … … 23 24 24 25 namespace ControlStruct { 25 LabelFixer::Entry::Entry( Statement *to, Statement *from ) : definition ( to ) { 26 if ( from != 0 ) 27 usage.push_back( from ); 28 } 29 30 bool LabelFixer::Entry::insideLoop() { 31 return ( dynamic_cast< ForStmt * > ( definition ) || 32 dynamic_cast< WhileStmt * > ( definition ) ); 33 } 34 35 LabelFixer::LabelFixer( LabelGenerator *gen ) : generator ( gen ) { 36 if ( generator == 0 ) 37 generator = LabelGenerator::getGenerator(); 38 } 39 40 void LabelFixer::visit( FunctionDecl *functionDecl ) { 41 if ( functionDecl->get_statements() != 0 ) 42 functionDecl->get_statements()->accept( *this ); 43 44 MLEMutator mlemut( resolveJumps(), generator ); 45 functionDecl->acceptMutator( mlemut ); 46 } 47 48 void LabelFixer::visit( Statement *stmt ) { 49 std::list< Label > &labels = stmt->get_labels(); 50 51 if ( ! labels.empty() ) { 52 Label current = setLabelsDef( labels, stmt ); 53 labels.clear(); 54 labels.push_front( current ); 55 } // if 56 } 57 58 void LabelFixer::visit( BranchStmt *branchStmt ) { 59 visit ( ( Statement * )branchStmt ); // the labels this statement might have 60 61 Label target; 62 if ( (target = branchStmt->get_target()) != "" ) { 63 setLabelsUsg( target, branchStmt ); 64 } //else /* computed goto or normal exit-loop statements */ 65 } 66 67 Label LabelFixer::setLabelsDef( std::list< Label > &llabel, Statement *definition ) { 68 assert( definition != 0 ); 69 Entry *entry = new Entry( definition ); 70 bool used = false; 71 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 ); 80 81 if (! used ) delete entry; 82 83 return labelTable[ llabel.front() ]->get_label(); // this *must* exist 84 } 85 86 Label LabelFixer::setLabelsUsg( Label orgValue, Statement *use ) { 87 assert( use != 0 ); 88 89 if ( labelTable.find( orgValue ) != labelTable.end() ) 90 labelTable[ orgValue ]->add_use( use ); // the label has been defined or used before 91 else 92 labelTable[ orgValue ] = new Entry( 0, use ); 93 94 return labelTable[ orgValue ]->get_label(); 95 } 96 97 std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) { 98 std::map< Statement *, Entry * > def_us; 99 100 for ( std::map< Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); i++ ) { 101 Entry *e = i->second; 102 103 if ( def_us.find ( e->get_definition() ) == def_us.end() ) 104 def_us[ e->get_definition() ] = e; 105 else 106 if ( e->used() ) 107 def_us[ e->get_definition() ]->add_uses( e->get_uses() ); 26 LabelFixer::Entry::Entry( Statement *to, Statement *from ) : definition ( to ) { 27 if ( from != 0 ) 28 usage.push_back( from ); 108 29 } 109 30 110 // get rid of labelTable 111 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ ) { 112 Statement *to = (*i).first; 113 std::list< Statement *> &from = (*i).second->get_uses(); 114 Label finalLabel = generator->newLabel(); 115 (*i).second->set_label( finalLabel ); 31 bool LabelFixer::Entry::insideLoop() { 32 return ( dynamic_cast< ForStmt * > ( definition ) || 33 dynamic_cast< WhileStmt * > ( definition ) ); 34 } 116 35 117 if ( to == 0 ) { 118 BranchStmt *first_use = dynamic_cast<BranchStmt *>(from.back()); 119 Label undef(""); 120 if ( first_use != 0 ) 121 undef = first_use->get_target(); 122 throw SemanticError ( "'" + undef + "' label not defined"); 123 } 36 LabelFixer::LabelFixer( LabelGenerator *gen ) : generator ( gen ) { 37 if ( generator == 0 ) 38 generator = LabelGenerator::getGenerator(); 39 } 124 40 125 to->get_labels().clear(); 126 to->get_labels().push_back( finalLabel ); 41 void LabelFixer::visit( FunctionDecl *functionDecl ) { 42 if ( functionDecl->get_statements() != 0 ) 43 functionDecl->get_statements()->accept( *this ); 127 44 128 for ( std::list< Statement *>::iterator j = from.begin(); j != from.end(); j++ ) { 129 BranchStmt *jumpTo = dynamic_cast< BranchStmt * > ( *j ); 130 assert( jumpTo != 0 ); 131 jumpTo->set_target( finalLabel ); 132 } // for 133 } // for 45 MLEMutator mlemut( resolveJumps(), generator ); 46 functionDecl->acceptMutator( mlemut ); 47 } 134 48 135 // reverse table 136 std::map< Label, Statement * > *ret = new std::map< Label, Statement * >(); 137 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ ) 138 (*ret)[ (*i).second->get_label() ] = (*i).first; 49 void LabelFixer::visit( Statement *stmt ) { 50 std::list< Label > &labels = stmt->get_labels(); 139 51 140 return ret; 141 } 52 if ( ! labels.empty() ) { 53 Label current = setLabelsDef( labels, stmt ); 54 labels.clear(); 55 labels.push_front( current ); 56 } // if 57 } 58 59 void LabelFixer::visit( BranchStmt *branchStmt ) { 60 visit ( ( Statement * )branchStmt ); // the labels this statement might have 61 62 Label target; 63 if ( (target = branchStmt->get_target()) != "" ) { 64 setLabelsUsg( target, branchStmt ); 65 } //else /* computed goto or normal exit-loop statements */ 66 } 67 68 Label LabelFixer::setLabelsDef( std::list< Label > &llabel, Statement *definition ) { 69 assert( definition != 0 ); 70 Entry *entry = new Entry( definition ); 71 bool used = false; 72 73 for ( std::list< Label >::iterator i = llabel.begin(); i != llabel.end(); i++ ) 74 if ( labelTable.find( *i ) == labelTable.end() ) 75 { used = true; labelTable[ *i ] = entry; } // undefined and unused 76 else 77 if ( labelTable[ *i ]->defined() ) 78 throw SemanticError( "Duplicate definition of label: " + *i ); 79 else 80 labelTable[ *i ]->set_definition( definition ); 81 82 if ( ! used ) delete entry; 83 84 return labelTable[ llabel.front() ]->get_label(); // this *must* exist 85 } 86 87 Label LabelFixer::setLabelsUsg( Label orgValue, Statement *use ) { 88 assert( use != 0 ); 89 90 if ( labelTable.find( orgValue ) != labelTable.end() ) 91 labelTable[ orgValue ]->add_use( use ); // the label has been defined or used before 92 else 93 labelTable[ orgValue ] = new Entry( 0, use ); 94 95 return labelTable[ orgValue ]->get_label(); 96 } 97 98 std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) { 99 std::map< Statement *, Entry * > def_us; 100 101 for ( std::map< Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); i++ ) { 102 Entry *e = i->second; 103 104 if ( def_us.find ( e->get_definition() ) == def_us.end() ) 105 def_us[ e->get_definition() ] = e; 106 else 107 if ( e->used() ) 108 def_us[ e->get_definition() ]->add_uses( e->get_uses() ); 109 } 110 111 // get rid of labelTable 112 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ ) { 113 Statement *to = (*i).first; 114 std::list< Statement *> &from = (*i).second->get_uses(); 115 Label finalLabel = generator->newLabel(); 116 (*i).second->set_label( finalLabel ); 117 118 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(); 123 throw SemanticError ( "'" + undef + "' label not defined"); 124 } 125 126 to->get_labels().clear(); 127 to->get_labels().push_back( finalLabel ); 128 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 ); 133 } // for 134 } // for 135 136 // reverse table 137 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++ ) 139 (*ret)[ (*i).second->get_label() ] = (*i).first; 140 141 return ret; 142 } 142 143 } // namespace ControlStruct 144 143 145 // Local Variables: // 144 146 // tab-width: 4 // -
translator/ControlStruct/LabelFixer.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // LabelFixer.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:31:55 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef LABEL_FIXER_H 16 17 #define LABEL_FIXER_H 17 18 18 19 #include "utility.h" 19 20 20 #include "SynTree/SynTree.h" 21 21 #include "SynTree/Visitor.h" 22 23 22 #include "LabelGenerator.h" 24 23 … … 26 25 27 26 namespace ControlStruct { 28 class LabelFixer : public Visitor {29 typedef Visitor Parent;30 public:31 LabelFixer( LabelGenerator *gen = 0 );27 class LabelFixer : public Visitor { 28 typedef Visitor Parent; 29 public: 30 LabelFixer( LabelGenerator *gen = 0 ); 32 31 33 std::map < Label, Statement * > *resolveJumps() throw ( SemanticError );32 std::map < Label, Statement * > *resolveJumps() throw ( SemanticError ); 34 33 35 // Declarations36 virtual void visit( FunctionDecl *functionDecl );34 // Declarations 35 virtual void visit( FunctionDecl *functionDecl ); 37 36 38 // Statements39 void visit( Statement *stmt );37 // Statements 38 void visit( Statement *stmt ); 40 39 41 virtual void visit( CompoundStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }42 virtual void visit( NullStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }43 virtual void visit( ExprStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }44 virtual void visit( IfStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }45 virtual void visit( WhileStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }46 virtual void visit( ForStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }47 virtual void visit( SwitchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }48 virtual void visit( ChooseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }49 virtual void visit( FallthruStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }50 virtual void visit( CaseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }51 virtual void visit( ReturnStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }52 virtual void visit( TryStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }53 virtual void visit( CatchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }54 virtual void visit( DeclStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); }55 virtual void visit( BranchStmt *branchStmt );40 virtual void visit( CompoundStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 41 virtual void visit( NullStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 42 virtual void visit( ExprStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 43 virtual void visit( IfStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 44 virtual void visit( WhileStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 45 virtual void visit( ForStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 46 virtual void visit( SwitchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 47 virtual void visit( ChooseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 48 virtual void visit( FallthruStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 49 virtual void visit( CaseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 50 virtual void visit( ReturnStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 51 virtual void visit( TryStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 52 virtual void visit( CatchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 53 virtual void visit( DeclStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 54 virtual void visit( BranchStmt *branchStmt ); 56 55 57 Label setLabelsDef( std::list< Label > &, Statement *definition );58 Label setLabelsUsg( Label, Statement *usage = 0 );56 Label setLabelsDef( std::list< Label > &, Statement *definition ); 57 Label setLabelsUsg( Label, Statement *usage = 0 ); 59 58 60 private:61 class Entry {62 public:63 Entry( Statement *to = 0, Statement *from = 0 );64 bool used() { return ( usage.empty() ); }65 bool defined() { return ( definition != 0 ); }66 bool insideLoop();59 private: 60 class Entry { 61 public: 62 Entry( Statement *to = 0, Statement *from = 0 ); 63 bool used() { return ( usage.empty() ); } 64 bool defined() { return ( definition != 0 ); } 65 bool insideLoop(); 67 66 68 Label get_label() const { return label; }69 Statement *get_definition() const { return definition; }70 std::list< Statement *> &get_uses() { return usage; }67 Label get_label() const { return label; } 68 Statement *get_definition() const { return definition; } 69 std::list< Statement *> &get_uses() { return usage; } 71 70 72 void add_use ( Statement *use ) { usage.push_back( use ); }73 void add_uses ( std::list<Statement *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); }74 void set_definition( Statement *def ) { definition = def; }71 void add_use ( Statement *use ) { usage.push_back( use ); } 72 void add_uses ( std::list<Statement *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); } 73 void set_definition( Statement *def ) { definition = def; } 75 74 76 void set_label( Label lab ) { label = lab; } 77 Label gset_label() const { return label; } 78 private: 79 Label label; 80 Statement *definition; 81 std::list<Statement *> usage; 75 void set_label( Label lab ) { label = lab; } 76 Label gset_label() const { return label; } 77 private: 78 Label label; 79 Statement *definition; 80 std::list<Statement *> usage; 81 }; 82 83 std::map < Label, Entry *> labelTable; 84 LabelGenerator *generator; 82 85 }; 83 84 std::map < Label, Entry *> labelTable;85 LabelGenerator *generator;86 };87 86 } // namespace ControlStruct 88 87 89 88 #endif // LABEL_FIXER_H 90 89 91 /*92 Local Variables:93 mode: c++94 End:95 */96 90 // Local Variables: // 97 91 // tab-width: 4 // -
translator/ControlStruct/LabelGenerator.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // LabelGenerator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:32:04 2015 13 // Update Count : 2 14 14 // 15 15 16 #include <iostream> 16 17 #include <strstream> … … 19 20 20 21 namespace ControlStruct { 21 LabelGenerator *LabelGenerator::labelGenerator = 0;22 LabelGenerator *LabelGenerator::labelGenerator = 0; 22 23 23 LabelGenerator *LabelGenerator::getGenerator() {24 if ( LabelGenerator::labelGenerator == 0 )25 LabelGenerator::labelGenerator = new LabelGenerator();24 LabelGenerator *LabelGenerator::getGenerator() { 25 if ( LabelGenerator::labelGenerator == 0 ) 26 LabelGenerator::labelGenerator = new LabelGenerator(); 26 27 27 return labelGenerator;28 }28 return labelGenerator; 29 } 29 30 30 Label LabelGenerator::newLabel() {31 std::ostrstream os;32 os << "__L" << current++ << "__";// << std::ends;33 os.freeze( false );34 std::string ret = std::string (os.str(), os.pcount());35 return Label( ret );36 }31 Label LabelGenerator::newLabel() { 32 std::ostrstream os; 33 os << "__L" << current++ << "__";// << std::ends; 34 os.freeze( false ); 35 std::string ret = std::string (os.str(), os.pcount()); 36 return Label( ret ); 37 } 37 38 } // namespace ControlStruct 39 38 40 // Local Variables: // 39 41 // tab-width: 4 // -
translator/ControlStruct/LabelGenerator.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // LabelGenerator.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:33:20 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef LABEL_GENERATOR_H 16 17 #define LABEL_GENERATOR_H … … 19 20 20 21 namespace ControlStruct { 21 class LabelGenerator {22 public:23 static LabelGenerator *getGenerator();24 Label newLabel();25 void reset() { current = 0; }26 void rewind() { current--; }27 protected:28 LabelGenerator(): current(0) {}29 private:30 int current;31 static LabelGenerator *labelGenerator;32 };22 class LabelGenerator { 23 public: 24 static LabelGenerator *getGenerator(); 25 Label newLabel(); 26 void reset() { current = 0; } 27 void rewind() { current--; } 28 protected: 29 LabelGenerator(): current(0) {} 30 private: 31 int current; 32 static LabelGenerator *labelGenerator; 33 }; 33 34 } // namespace ControlStruct 34 35 35 36 #endif // LABEL_GENERATOR_H 36 37 37 /*38 Local Variables:39 mode: c++40 End:41 */42 38 // Local Variables: // 43 39 // tab-width: 4 // -
translator/ControlStruct/LabelTypeChecker.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // LabelTypeChecker.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:32:15 2015 13 // Update Count : 2 14 14 // 15 15 16 #include <list> 16 17 #include <cassert> … … 23 24 #include "LabelTypeChecker.h" 24 25 26 namespace ControlStruct { 27 void LabelTypeChecker::visit(UntypedExpr *untypedExpr) { 28 assert( untypedExpr != 0 ); 29 NameExpr *fname; 30 if ( ((fname = dynamic_cast<NameExpr *>(untypedExpr->get_function())) != 0) 31 && fname->get_name() == std::string("LabAddress") ) 32 std::cerr << "Taking the label of an address." << std::endl; 33 else { 34 acceptAll( untypedExpr->get_results(), *this ); 35 acceptAll( untypedExpr->get_args(), *this ); 36 } // if 37 return; 38 } 25 39 26 namespace ControlStruct { 27 void LabelTypeChecker::visit(UntypedExpr *untypedExpr){ 28 assert( untypedExpr != 0 ); 29 NameExpr *fname; 30 if ( ((fname = dynamic_cast<NameExpr *>(untypedExpr->get_function())) != 0) 31 && fname->get_name() == std::string("LabAddress") ) 32 std::cerr << "Taking the label of an address." << std::endl; 33 else { 34 acceptAll( untypedExpr->get_results(), *this ); 35 acceptAll( untypedExpr->get_args(), *this ); 36 } // if 37 return; 38 } 40 void LabelTypeChecker::visit(CompoundStmt *compoundStmt) { 41 index.enterScope(); 42 acceptAll( compoundStmt->get_kids(), *this ); 43 index.leaveScope(); 44 } 39 45 40 void LabelTypeChecker::visit(CompoundStmt *compoundStmt) { 41 index.enterScope(); 42 acceptAll( compoundStmt->get_kids(), *this ); 43 index.leaveScope(); 44 } 46 void LabelTypeChecker::visit(DeclStmt *declStmt) { 47 declStmt->accept( index ); 45 48 46 void LabelTypeChecker::visit(DeclStmt *declStmt){ 47 declStmt->accept( index ); 49 //ObjectDecl *odecl = 0; 50 // if ( ( odecl = dynamic_cast<ObjectDecl *>(declStmt->get_decl()) ) != 0 ) { 51 return; 52 } 48 53 49 //ObjectDecl *odecl = 0;50 // if ( ( odecl = dynamic_cast<ObjectDecl *>(declStmt->get_decl()) ) != 0 ){51 return;52 } 54 void LabelTypeChecker::visit(BranchStmt *branchStmt) { 55 if ( branchStmt->get_type() != BranchStmt::Goto ) return; 56 Expression *target; 57 if ( (target = branchStmt->get_computedTarget()) == 0 ) return; 53 58 54 void LabelTypeChecker::visit(BranchStmt *branchStmt) { 55 if ( branchStmt->get_type() != BranchStmt::Goto ) return; 56 Expression *target; 57 if ( (target = branchStmt->get_computedTarget()) == 0 ) return; 59 NameExpr *name; 60 if ( ((name = dynamic_cast<NameExpr *>(target)) == 0) ) 61 return; // Not a name expression 62 63 std::list< DeclarationWithType * > interps; 64 index.lookupId(name->get_name(), interps); 65 if ( interps.size() != 1) 66 // in case of multiple declarations 67 throw SemanticError("Illegal label expression: " + name->get_name() ); 58 68 59 NameExpr *name; 60 if ( ((name = dynamic_cast<NameExpr *>(target)) == 0) ) 61 return; // Not a name expression 62 63 std::list< DeclarationWithType * > interps; 64 index.lookupId(name->get_name(), interps); 65 if ( interps.size() != 1) 66 // in case of multiple declarations 67 throw SemanticError("Illegal label expression: " + name->get_name() ); 69 PointerType *ptr; 70 if ( (ptr = dynamic_cast<PointerType *>(interps.front()->get_type())) != 0 ) 71 if ( dynamic_cast<VoidType *>(ptr->get_base()) != 0 ) 72 return; 73 else 74 throw SemanticError("Wrong type of parameter for computed goto"); 75 else 76 throw SemanticError("Wrong type of parameter for computed goto"); 68 77 69 PointerType *ptr;70 if ( (ptr = dynamic_cast<PointerType *>(interps.front()->get_type())) != 0 )71 if ( dynamic_cast<VoidType *>(ptr->get_base()) != 0 )72 78 return; 73 else 74 throw SemanticError("Wrong type of parameter for computed goto"); 75 else 76 throw SemanticError("Wrong type of parameter for computed goto"); 79 } 80 } // namespace ControlStruct 77 81 78 return;79 }80 } // namespace ControlStruct81 82 // Local Variables: // 82 83 // tab-width: 4 // -
translator/ControlStruct/LabelTypeChecker.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // LabelTypeChecker.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:33:47 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef LABEL_TYPE_H 16 17 #define LABEL_TYPE_H … … 23 24 24 25 namespace ControlStruct { 25 class LabelTypeChecker : public Visitor {26 public:27 //LabelTypeChecker() {26 class LabelTypeChecker : public Visitor { 27 public: 28 //LabelTypeChecker() { 28 29 29 virtual void visit( CompoundStmt *compoundStmt );30 virtual void visit( DeclStmt *declStmt );31 virtual void visit( BranchStmt *branchStmt );32 virtual void visit( UntypedExpr *untypedExpr );33 private:34 SymTab::Indexer index;35 };30 virtual void visit( CompoundStmt *compoundStmt ); 31 virtual void visit( DeclStmt *declStmt ); 32 virtual void visit( BranchStmt *branchStmt ); 33 virtual void visit( UntypedExpr *untypedExpr ); 34 private: 35 SymTab::Indexer index; 36 }; 36 37 } // namespace ControlStruct 37 38 38 39 #endif // LABEL_TYPE_H 39 40 /*41 Local Variables:42 mode: c++43 End:44 */45 46 47 40 48 41 // Local Variables: // -
translator/ControlStruct/MLEMutator.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // MLEMutator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 0 14 // 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:32:26 2015 13 // Update Count : 2 14 // 15 15 16 #include <cassert> 16 17 #include <algorithm> … … 19 20 #include "SynTree/Statement.h" 20 21 21 22 22 namespace ControlStruct { 23 MLEMutator::~MLEMutator() {24 delete targetTable;25 targetTable = 0;26 }27 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 }34 35 std::list< Statement * > &kids = cmpndStmt->get_kids();36 for ( std::list< Statement * >::iterator k = kids.begin(); k != kids.end(); k++ ) {37 *k = (*k)->acceptMutator(*this);38 39 if ( ! get_breakLabel().empty() ) {40 std::list< Statement * >::iterator next = k; next++;41 if ( next == kids.end() ) {42 std::list<Label> ls; ls.push_back( get_breakLabel() );43 kids.push_back( new NullStmt( ls ) );44 } else45 (*next)->get_labels().push_back( get_breakLabel() );46 47 set_breakLabel("");48 } // if49 } // for50 51 if ( labeledBlock ) {52 assert( ! enclosingBlocks.empty() );53 if ( ! enclosingBlocks.back().get_breakExit().empty() )54 set_breakLabel( enclosingBlocks.back().get_breakExit() );55 enclosingBlocks.pop_back();56 } // if57 58 //mutateAll( cmpndStmt->get_kids(), *this );59 return cmpndStmt;60 }61 62 Statement *MLEMutator::mutate( WhileStmt *whileStmt ) {63 enclosingLoops.push_back( Entry( whileStmt ) );64 whileStmt->set_body ( whileStmt->get_body()->acceptMutator( *this ) );65 66 Entry &e = enclosingLoops.back();67 assert ( e == whileStmt );68 whileStmt->set_body( mutateLoop( whileStmt->get_body(), e ) );69 enclosingLoops.pop_back();70 71 return whileStmt;72 }73 74 Statement *MLEMutator::mutate( ForStmt *forStmt ) {75 enclosingLoops.push_back( Entry( forStmt ) );76 maybeMutate( forStmt->get_body(), *this );77 78 Entry &e = enclosingLoops.back();79 assert ( e == forStmt );80 forStmt->set_body( mutateLoop( forStmt->get_body(), e ) );81 enclosingLoops.pop_back();82 83 return forStmt;84 }85 86 Statement *MLEMutator::mutate( BranchStmt *branchStmt ) throw ( SemanticError ) {87 if ( branchStmt->get_type() == BranchStmt::Goto )88 return branchStmt;89 90 // test if continue target is a loop91 if ( branchStmt->get_type() == BranchStmt::Continue && enclosingLoops.empty() )92 throw SemanticError( "'continue' outside a loop" );93 94 if ( branchStmt->get_type() == BranchStmt::Break && (enclosingLoops.empty() && enclosingSwitches.empty() && enclosingBlocks.empty() ) )95 throw SemanticError( "'break' outside a loop or switch" );96 97 if ( branchStmt->get_target() == "" ) return branchStmt;98 99 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)101 102 std::list< Entry >::iterator check;103 if ( ( check = std::find( enclosingLoops.begin(), enclosingLoops.end(), (*targetTable)[branchStmt->get_target()] ) ) == enclosingLoops.end() )104 // not in loop, checking if in block105 if ( (check = std::find( enclosingBlocks.begin(), enclosingBlocks.end(), (*targetTable)[branchStmt->get_target()] )) == enclosingBlocks.end() )106 // neither in loop nor in block, checking if in switch/choose107 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.");109 110 if ( enclosingLoops.back() == (*check) )111 return branchStmt; // exit the innermost loop (labels unnecessary)112 113 Label newLabel;114 switch ( branchStmt->get_type() ) {115 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;123 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;131 default:132 return 0; // shouldn't be here133 } // switch134 135 return new BranchStmt( std::list<Label>(), newLabel, BranchStmt::Goto );136 }137 138 139 Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) {140 Label brkLabel = generator->newLabel();141 enclosingSwitches.push_back( Entry(switchStmt, "", brkLabel) );142 mutateAll( switchStmt->get_branches(), *this ); {143 // check if this is necessary (if there is a break to this point, otherwise do not generate144 std::list<Label> temp; temp.push_back( brkLabel );145 switchStmt->get_branches().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) );146 }147 assert ( enclosingSwitches.back() == switchStmt );148 enclosingSwitches.pop_back();149 return switchStmt;150 }151 152 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 generate157 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;163 }164 165 Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {166 CompoundStmt *newBody;167 if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) {168 newBody = new CompoundStmt( std::list< Label >() );169 newBody->get_kids().push_back( bodyLoop );170 } // if171 172 Label endLabel = e.get_contExit();173 174 if ( e.get_breakExit() != "" ) {175 if ( endLabel == "" ) endLabel = generator->newLabel();176 // check for whether this label is used or not, so as to not generate extraneous gotos177 if (e.breakExitUsed)178 newBody->get_kids().push_back( new BranchStmt( std::list< Label >(), endLabel, BranchStmt::Goto ) );179 // xxx180 //std::list< Label > ls; ls.push_back( e.get_breakExit() );181 set_breakLabel( e.get_breakExit() );182 //newBody->get_kids().push_back( new BranchStmt( ls, "", BranchStmt::Break ) );183 } // if184 185 if ( e.get_breakExit() != "" || e.get_contExit() != "" ){186 if (dynamic_cast< NullStmt *>( newBody->get_kids().back() ))187 newBody->get_kids().back()->get_labels().push_back( endLabel );188 else {189 std::list < Label > ls; ls.push_back( endLabel );190 newBody->get_kids().push_back( new NullStmt( ls ) );191 } // if192 } // if193 194 return newBody;195 }196 197 //*** Entry's methods198 void MLEMutator::Entry::set_contExit( Label l ) {199 assert ( contExit == "" || contExit == l );200 contExit = l;201 }202 203 void MLEMutator::Entry::set_breakExit( Label l ) {204 assert ( breakExit == "" || breakExit == l );205 breakExit = l;206 }23 MLEMutator::~MLEMutator() { 24 delete targetTable; 25 targetTable = 0; 26 } 27 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(); 36 for ( std::list< Statement * >::iterator k = kids.begin(); k != kids.end(); k++ ) { 37 *k = (*k)->acceptMutator(*this); 38 39 if ( ! get_breakLabel().empty() ) { 40 std::list< Statement * >::iterator next = k; next++; 41 if ( next == kids.end() ) { 42 std::list<Label> ls; ls.push_back( get_breakLabel() ); 43 kids.push_back( new NullStmt( ls ) ); 44 } else 45 (*next)->get_labels().push_back( get_breakLabel() ); 46 47 set_breakLabel(""); 48 } // if 49 } // for 50 51 if ( labeledBlock ) { 52 assert( ! enclosingBlocks.empty() ); 53 if ( ! enclosingBlocks.back().get_breakExit().empty() ) 54 set_breakLabel( enclosingBlocks.back().get_breakExit() ); 55 enclosingBlocks.pop_back(); 56 } // if 57 58 //mutateAll( cmpndStmt->get_kids(), *this ); 59 return cmpndStmt; 60 } 61 62 Statement *MLEMutator::mutate( WhileStmt *whileStmt ) { 63 enclosingLoops.push_back( Entry( whileStmt ) ); 64 whileStmt->set_body ( whileStmt->get_body()->acceptMutator( *this ) ); 65 66 Entry &e = enclosingLoops.back(); 67 assert ( e == whileStmt ); 68 whileStmt->set_body( mutateLoop( whileStmt->get_body(), e ) ); 69 enclosingLoops.pop_back(); 70 71 return whileStmt; 72 } 73 74 Statement *MLEMutator::mutate( ForStmt *forStmt ) { 75 enclosingLoops.push_back( Entry( forStmt ) ); 76 maybeMutate( forStmt->get_body(), *this ); 77 78 Entry &e = enclosingLoops.back(); 79 assert ( e == forStmt ); 80 forStmt->set_body( mutateLoop( forStmt->get_body(), e ) ); 81 enclosingLoops.pop_back(); 82 83 return forStmt; 84 } 85 86 Statement *MLEMutator::mutate( BranchStmt *branchStmt ) throw ( SemanticError ) { 87 if ( branchStmt->get_type() == BranchStmt::Goto ) 88 return branchStmt; 89 90 // test if continue target is a loop 91 if ( branchStmt->get_type() == BranchStmt::Continue && enclosingLoops.empty() ) 92 throw SemanticError( "'continue' outside a loop" ); 93 94 if ( branchStmt->get_type() == BranchStmt::Break && (enclosingLoops.empty() && enclosingSwitches.empty() && enclosingBlocks.empty() ) ) 95 throw SemanticError( "'break' outside a loop or switch" ); 96 97 if ( branchStmt->get_target() == "" ) return branchStmt; 98 99 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) 101 102 std::list< Entry >::iterator check; 103 if ( ( check = std::find( enclosingLoops.begin(), enclosingLoops.end(), (*targetTable)[branchStmt->get_target()] ) ) == enclosingLoops.end() ) 104 // not in loop, checking if in block 105 if ( (check = std::find( enclosingBlocks.begin(), enclosingBlocks.end(), (*targetTable)[branchStmt->get_target()] )) == enclosingBlocks.end() ) 106 // neither in loop nor in block, checking if in switch/choose 107 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."); 109 110 if ( enclosingLoops.back() == (*check) ) 111 return branchStmt; // exit the innermost loop (labels unnecessary) 112 113 Label newLabel; 114 switch ( branchStmt->get_type() ) { 115 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 } // if 122 break; 123 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 } // if 130 break; 131 default: 132 return 0; // shouldn't be here 133 } // switch 134 135 return new BranchStmt( std::list<Label>(), newLabel, BranchStmt::Goto ); 136 } 137 138 139 Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) { 140 Label brkLabel = generator->newLabel(); 141 enclosingSwitches.push_back( Entry(switchStmt, "", brkLabel) ); 142 mutateAll( switchStmt->get_branches(), *this ); { 143 // check if this is necessary (if there is a break to this point, otherwise do not generate 144 std::list<Label> temp; temp.push_back( brkLabel ); 145 switchStmt->get_branches().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) ); 146 } 147 assert ( enclosingSwitches.back() == switchStmt ); 148 enclosingSwitches.pop_back(); 149 return switchStmt; 150 } 151 152 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; 163 } 164 165 Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) { 166 CompoundStmt *newBody; 167 if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) { 168 newBody = new CompoundStmt( std::list< Label >() ); 169 newBody->get_kids().push_back( bodyLoop ); 170 } // if 171 172 Label endLabel = e.get_contExit(); 173 174 if ( e.get_breakExit() != "" ) { 175 if ( endLabel == "" ) endLabel = generator->newLabel(); 176 // check for whether this label is used or not, so as to not generate extraneous gotos 177 if (e.breakExitUsed) 178 newBody->get_kids().push_back( new BranchStmt( std::list< Label >(), endLabel, BranchStmt::Goto ) ); 179 // xxx 180 //std::list< Label > ls; ls.push_back( e.get_breakExit() ); 181 set_breakLabel( e.get_breakExit() ); 182 //newBody->get_kids().push_back( new BranchStmt( ls, "", BranchStmt::Break ) ); 183 } // if 184 185 if ( e.get_breakExit() != "" || e.get_contExit() != "" ) { 186 if (dynamic_cast< NullStmt *>( newBody->get_kids().back() )) 187 newBody->get_kids().back()->get_labels().push_back( endLabel ); 188 else { 189 std::list < Label > ls; ls.push_back( endLabel ); 190 newBody->get_kids().push_back( new NullStmt( ls ) ); 191 } // if 192 } // if 193 194 return newBody; 195 } 196 197 //*** Entry's methods 198 void MLEMutator::Entry::set_contExit( Label l ) { 199 assert ( contExit == "" || contExit == l ); 200 contExit = l; 201 } 202 203 void MLEMutator::Entry::set_breakExit( Label l ) { 204 assert ( breakExit == "" || breakExit == l ); 205 breakExit = l; 206 } 207 207 } // namespace ControlStruct 208 208 209 // Local Variables: // 209 210 // tab-width: 4 // -
translator/ControlStruct/MLEMutator.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // MLEMutator.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:32:39 2015 13 // Update Count : 3 14 14 // 15 15 16 #ifndef MLE_MUTATOR_H 16 17 #define MLE_MUTATOR_H … … 26 27 27 28 namespace ControlStruct { 28 class MLEMutator : public Mutator {29 class Entry;30 public:31 MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}32 ~MLEMutator();29 class MLEMutator : public Mutator { 30 class Entry; 31 public: 32 MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {} 33 ~MLEMutator(); 33 34 34 CompoundStmt *mutate( CompoundStmt *cmpndStmt );35 Statement *mutate( WhileStmt *whileStmt );36 Statement *mutate( ForStmt *forStmt );37 Statement *mutate( BranchStmt *branchStmt ) throw ( SemanticError );35 CompoundStmt *mutate( CompoundStmt *cmpndStmt ); 36 Statement *mutate( WhileStmt *whileStmt ); 37 Statement *mutate( ForStmt *forStmt ); 38 Statement *mutate( BranchStmt *branchStmt ) throw ( SemanticError ); 38 39 39 Statement *mutate( SwitchStmt *switchStmt );40 Statement *mutate( ChooseStmt *switchStmt );40 Statement *mutate( SwitchStmt *switchStmt ); 41 Statement *mutate( ChooseStmt *switchStmt ); 41 42 42 Statement *mutateLoop( Statement *bodyLoop, Entry &e );43 Statement *mutateLoop( Statement *bodyLoop, Entry &e ); 43 44 44 Label &get_breakLabel() { return breakLabel; }45 void set_breakLabel( Label newValue ) { breakLabel = newValue; }46 private:47 class Entry {48 public:49 explicit Entry( Statement *_loop = 0, Label _contExit = Label(""), Label _breakExit = Label("") ) :50 loop( _loop ), contExit( _contExit ), breakExit( _breakExit ), contExitUsed( false ), breakExitUsed( false ) {}45 Label &get_breakLabel() { return breakLabel; } 46 void set_breakLabel( Label newValue ) { breakLabel = newValue; } 47 private: 48 class Entry { 49 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 52 52 bool operator==( const Statement *stmt ) { return ( loop == stmt ); }53 bool operator!=( const Statement *stmt ) { return ( loop != stmt ); }53 bool operator==( const Statement *stmt ) { return ( loop == stmt ); } 54 bool operator!=( const Statement *stmt ) { return ( loop != stmt ); } 54 55 55 bool operator==( const Entry &other ) { return ( loop == other.get_loop() ); }56 bool operator==( const Entry &other ) { return ( loop == other.get_loop() ); } 56 57 57 Statement *get_loop() const { return loop; }58 Statement *get_loop() const { return loop; } 58 59 59 Label get_contExit() const { return contExit; }60 void set_contExit( Label );60 Label get_contExit() const { return contExit; } 61 void set_contExit( Label ); 61 62 62 Label get_breakExit() const { return breakExit; }63 void set_breakExit( Label );63 Label get_breakExit() const { return breakExit; } 64 void set_breakExit( Label ); 64 65 65 private: 66 Statement *loop; 67 Label contExit, breakExit; 68 public: // hack, provide proper [sg]etters 69 bool contExitUsed, breakExitUsed; 66 private: 67 Statement *loop; 68 Label contExit, breakExit; 69 public: // hack, provide proper [sg]etters 70 bool contExitUsed, breakExitUsed; 71 }; 72 73 std::map< Label, Statement * > *targetTable; 74 std::list< Entry > enclosingBlocks, enclosingLoops, enclosingSwitches; 75 Label breakLabel; 76 LabelGenerator *generator; 70 77 }; 71 72 std::map< Label, Statement * > *targetTable;73 std::list< Entry > enclosingBlocks, enclosingLoops, enclosingSwitches;74 Label breakLabel;75 LabelGenerator *generator;76 };77 78 78 } // namespace ControlStruct 79 79 80 #endif 80 #endif // MLE_MUTATOR_H 81 81 82 /*83 Local Variables:84 mode: c++85 End:86 */87 82 // Local Variables: // 88 83 // tab-width: 4 // -
translator/ControlStruct/Mutate.cc
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // Mutate.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:32:52 2015 13 // Update Count : 2 14 14 // 15 15 16 #include <algorithm> 16 17 #include <iostream> … … 34 35 35 36 namespace ControlStruct { 36 void mutate( std::list< Declaration * > translationUnit ) {37 // ForExprMutator formut;38 LabelFixer lfix;39 ChooseMutator chmut;40 CaseRangeMutator ranges; // has to run after ChooseMutator41 //ExceptMutator exc;42 // LabelTypeChecker lbl;37 void mutate( std::list< Declaration * > translationUnit ) { 38 // ForExprMutator formut; 39 LabelFixer lfix; 40 ChooseMutator chmut; 41 CaseRangeMutator ranges; // has to run after ChooseMutator 42 //ExceptMutator exc; 43 // LabelTypeChecker lbl; 43 44 44 // mutateAll( translationUnit, formut );45 acceptAll( translationUnit, lfix );46 mutateAll( translationUnit, chmut );47 mutateAll( translationUnit, ranges );48 //mutateAll( translationUnit, exc );49 //acceptAll( translationUnit, lbl );50 }45 // mutateAll( translationUnit, formut ); 46 acceptAll( translationUnit, lfix ); 47 mutateAll( translationUnit, chmut ); 48 mutateAll( translationUnit, ranges ); 49 //mutateAll( translationUnit, exc ); 50 //acceptAll( translationUnit, lbl ); 51 } 51 52 } // namespace CodeGen 53 52 54 // Local Variables: // 53 55 // tab-width: 4 // -
translator/ControlStruct/Mutate.h
r01aeade ra08ba92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // Mutate.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 15:31:20 2015 13 // Update Count : 2 14 14 // 15 15 16 #ifndef CTRLS_MUTATE_H 16 17 #define CTRLS_MUTATE_H … … 22 23 23 24 namespace ControlStruct { 24 void mutate( std::list< Declaration* > translationUnit );25 void mutate( std::list< Declaration* > translationUnit ); 25 26 } // namespace ControlStruct 26 27 27 28 #endif // CTRLS_MUTATE_H 28 29 29 /*30 Local Variables:31 mode: c++32 End:33 */34 30 // Local Variables: // 35 31 // tab-width: 4 //
Note:
See TracChangeset
for help on using the changeset viewer.