Changes in / [f678663e:093f1a0]
- Location:
- src
- Files:
-
- 5 edited
-
ControlStruct/LabelFixer.cc (modified) (6 diffs)
-
ControlStruct/LabelFixer.h (modified) (3 diffs)
-
GenPoly/Box.cc (modified) (7 diffs)
-
ResolvExpr/Cost.h (modified) (2 diffs)
-
main.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/LabelFixer.cc
rf678663e r093f1a0 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 28 13:32:43201513 // Update Count : 1 5612 // Last Modified On : Wed Jul 08 12:36:46 2015 13 // Update Count : 145 14 14 // 15 15 … … 27 27 28 28 namespace ControlStruct { 29 LabelFixer::Entry::Entry( Statement *to, Statement *from ) : definition ( to ) { 30 if ( from != 0 ) { 31 UsageLoc loc; loc.stmt = from; 32 usage.push_back( loc ); 33 } 34 } 35 36 LabelFixer::Entry::Entry( Statement *to, Expression *from ) : definition ( to ) { 37 if ( from != 0 ) { 38 UsageLoc loc; loc.expr = from; 39 usage.push_back( loc ); 40 } 41 } 42 43 29 44 bool LabelFixer::Entry::insideLoop() { 30 45 return ( dynamic_cast< ForStmt * > ( definition ) || 31 46 dynamic_cast< WhileStmt * > ( definition ) ); 47 } 48 49 void LabelFixer::Entry::UsageLoc::accept( Visitor & visitor ) { 50 if ( dynamic_cast< Statement * >( stmt ) ) { 51 stmt->accept( visitor ); 52 } else { 53 expr->accept( visitor ); 54 } 32 55 } 33 56 … … 54 77 // prune to at most one label definition for each statement 55 78 void LabelFixer::visit( Statement *stmt ) { 79 currentStatement = stmt; 56 80 std::list< Label > &labels = stmt->get_labels(); 57 81 … … 59 83 // only remember one label for each statement 60 84 Label current = setLabelsDef( labels, stmt ); 85 labels.clear(); 86 labels.push_front( current ); 61 87 } // if 62 88 } … … 104 130 } else { 105 131 // used previously, but undefined until now -> link with this entry 106 delete labelTable[ *i ]; 132 Entry * oldEntry = labelTable[ *i ]; 133 e->add_uses( *oldEntry ); 107 134 labelTable[ *i ] = e; 108 135 } // if … … 114 141 } 115 142 116 // A label was used, add it ot the table if it isn't already there143 // Remember all uses of a label. 117 144 template< typename UsageNode > 118 145 void LabelFixer::setLabelsUsg( Label orgValue, UsageNode *use ) { 119 146 assert( use != 0 ); 120 147 121 // add label with an unknown origin 122 if ( labelTable.find( orgValue ) == labelTable.end() ) { 123 labelTable[ orgValue ] = new Entry( 0 ); 124 } 125 } 126 127 // Builds a table that maps a label to its defining statement. 148 if ( labelTable.find( orgValue ) != labelTable.end() ) { 149 // the label has been defined or used before 150 labelTable[ orgValue ]->add_use( use ); 151 } else { 152 labelTable[ orgValue ] = new Entry( 0, use ); 153 } 154 } 155 156 class LabelGetter : public Visitor { 157 public: 158 LabelGetter( Label &label ) : label( label ) {} 159 160 virtual void visit( BranchStmt * branchStmt ) { 161 label = branchStmt->get_target(); 162 } 163 164 virtual void visit( UntypedExpr * untyped ) { 165 NameExpr * name = dynamic_cast< NameExpr * >( untyped->get_function() ); 166 assert( name ); 167 assert( name->get_name() == "&&" ); 168 NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() ); 169 assert( arg ); 170 label = arg->get_name(); 171 } 172 173 private: 174 Label &label; 175 }; 176 177 class LabelSetter : public Visitor { 178 public: 179 LabelSetter( Label label ) : label( label ) {} 180 181 virtual void visit( BranchStmt * branchStmt ) { 182 branchStmt->set_target( label ); 183 } 184 185 virtual void visit( UntypedExpr * untyped ) { 186 NameExpr * name = dynamic_cast< NameExpr * >( untyped->get_function() ); 187 assert( name ); 188 assert( name->get_name() == "&&" ); 189 NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() ); 190 assert( arg ); 191 arg->set_name( label ); 192 } 193 194 private: 195 Label label; 196 }; 197 198 // Ultimately builds a table that maps a label to its defining statement. 199 // In the process, 128 200 std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) { 201 std::map< Statement *, Entry * > def_us; 202 203 // combine the entries for all labels that target the same location 204 for ( std::map< Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); ++i ) { 205 Entry *e = i->second; 206 207 if ( def_us.find ( e->get_definition() ) == def_us.end() ) { 208 def_us[ e->get_definition() ] = e; 209 } else if ( e->used() ) { 210 def_us[ e->get_definition() ]->add_uses( *e ); 211 } 212 } 213 214 // create a unique label for each target location. 215 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); ++i ) { 216 Statement *to = (*i).first; 217 Entry * entry = (*i).second; 218 std::list< Entry::UsageLoc > &from = entry->get_uses(); 219 220 // no label definition found 221 if ( to == 0 ) { 222 Label undef; 223 LabelGetter getLabel( undef ); 224 from.back().accept( getLabel ); 225 // Label undef = getLabel( from.back()->get_target() ); 226 throw SemanticError ( "'" + undef + "' label not defined"); 227 } // if 228 229 // generate a new label, and attach it to its defining statement as the only label on that statement 230 Label finalLabel = generator->newLabel( to->get_labels().back() ); 231 entry->set_label( finalLabel ); 232 233 to->get_labels().clear(); 234 to->get_labels().push_back( finalLabel ); 235 236 // redirect each of the source branch statements to the new target label 237 for ( std::list< Entry::UsageLoc >::iterator j = from.begin(); j != from.end(); ++j ) { 238 LabelSetter setLabel( finalLabel ); 239 (*j).accept( setLabel ); 240 // setLabel( *j, finalLabel ); 241 242 // BranchStmt *jump = *j; 243 // assert( jump != 0 ); 244 // jump->set_target( finalLabel ); 245 } // for 246 } // for 247 248 // create a table where each label maps to its defining statement 129 249 std::map< Label, Statement * > *ret = new std::map< Label, Statement * >(); 130 for ( std::map< Label, Entry * >::iterator i = labelTable.begin(); i != labelTable.end(); ++i ) { 131 if ( ! i->second->defined() ) { 132 throw SemanticError( "Use of undefined label: " + i->first ); 133 } 134 (*ret)[ i->first ] = i->second->get_definition(); 250 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); ++i ) { 251 (*ret)[ (*i).second->get_label() ] = (*i).first; 135 252 } 136 253 -
src/ControlStruct/LabelFixer.h
rf678663e r093f1a0 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Jul 28 13:09:02201513 // Update Count : 3111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 29 17:24:39 2015 13 // Update Count : 29 14 14 // 15 15 … … 63 63 class Entry { 64 64 public: 65 union UsageLoc { 66 Statement * stmt; 67 Expression * expr; 68 69 void accept( Visitor &visitor ); 70 }; 71 65 72 Entry( Statement *to ) : definition( to ) {} 73 Entry( Statement *to, Statement *from ); 74 Entry( Statement *to, Expression *from ); 75 bool used() { return ( usage.empty() ); } 66 76 bool defined() { return ( definition != 0 ); } 67 77 bool insideLoop(); … … 73 83 void set_definition( Statement *def ) { definition = def; } 74 84 85 std::list< UsageLoc > &get_uses() { return usage; } 86 void add_use( Statement *use ) { 87 UsageLoc loc; 88 loc.stmt = use; 89 usage.push_back( loc ); 90 } 91 void add_use( Expression *use ) { 92 UsageLoc loc; 93 loc.expr = use; 94 usage.push_back( loc ); 95 } 96 97 void add_uses ( Entry &other ) { usage.insert( usage.end(), other.usage.begin(), other.usage.end() ); } 75 98 private: 76 99 Label label; 77 100 Statement *definition; 101 std::list<UsageLoc> usage; 78 102 }; 79 103 80 104 std::map < Label, Entry *> labelTable; 81 105 LabelGenerator *generator; 106 Statement * currentStatement; 82 107 }; 83 108 } // namespace ControlStruct -
src/GenPoly/Box.cc
rf678663e r093f1a0 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jul 30 14:35:40201513 // Update Count : 5412 // Last Modified On : Wed Jun 24 16:19:07 2015 13 // Update Count : 10 14 14 // 15 15 … … 527 527 528 528 void Pass1::passAdapters( ApplicationExpr *appExpr, FunctionType *functionType, const TyVarMap &exprTyVars ) { 529 // collect a list of function types passed as parameters or implicit parameters (assertions)530 529 std::list< DeclarationWithType *> ¶mList = functionType->get_parameters(); 531 530 std::list< FunctionType *> functions; … … 538 537 findFunction( (*arg)->get_type(), functions, exprTyVars, needsAdapter ); 539 538 } // for 540 541 // parameter function types for which an appropriate adapter has been generated.542 // we cannot use the types after applying substitutions, since two different543 // parameter types may be unified to the same type544 539 std::set< std::string > adaptersDone; 545 546 540 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) { 547 541 FunctionType *realFunction = (*funType)->clone(); 542 assert( env ); 543 env->apply( realFunction ); 544 548 545 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 549 550 // only attempt to create an adapter or pass one as a parameter if we haven't551 // already done so for this pre-substitution parameter function type.552 546 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 553 std::string mangleName = SymTab::Mangler::mangle( realFunction );554 adaptersDone.insert( adaptersDone.begin(), mangleName );555 556 // apply substitution to type variables to figure out what the557 // adapter's type should look like558 assert( env );559 env->apply( realFunction );560 mangleName = SymTab::Mangler::mangle( realFunction );561 547 AdapterMap & adapters = Pass1::adapters.top(); 562 548 AdapterMap::iterator adapter = adapters.find( mangleName ); … … 569 555 continue; 570 556 } else if ( adapter == adapters.end() ) { 571 // adapter has not been created yet in the current scope, so define it572 557 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars ); 573 558 adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) ); … … 575 560 } // if 576 561 assert( adapter != adapters.end() ); 577 578 // add the appropriate adapter as a parameter579 562 appExpr->get_args().push_front( new VariableExpr( adapter->second ) ); 563 // appExpr->get_args().push_front( new NameExpr( makeAdapterName ( mangleName ) ) ); 564 adaptersDone.insert( adaptersDone.begin(), mangleName ); 580 565 } // if 581 566 } // for … … 895 880 896 881 void Pass1::doBeginScope() { 897 // actually, maybe this could (should?) push898 // a copy of the current map899 882 adapters.push(AdapterMap()); 900 883 } … … 1068 1051 if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) { 1069 1052 if ( isPolyVal( objectDecl->get_type(), scopeTyVars ) ) { 1070 // change initialization of a polymorphic value object1071 // to allocate storage with alloca1072 1053 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( objectDecl->get_type() ); 1073 1054 assert( typeInst ); 1074 1055 UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) ); 1075 1056 alloc->get_args().push_back( new NameExpr( typeInst->get_name() ) ); 1076 1077 delete objectDecl->get_init(); 1078 1079 std::list<Expression*> designators; 1080 objectDecl->set_init( new SingleInit( alloc, designators ) ); 1057 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 1058 assign->get_args().push_back( new VariableExpr( objectDecl ) ); 1059 assign->get_args().push_back( alloc ); 1060 stmtsToAddAfter.push_back( new ExprStmt( noLabels, assign ) ); 1081 1061 } 1082 1062 } -
src/ResolvExpr/Cost.h
rf678663e r093f1a0 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 09:39:50 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Jul 22 16:43:10201513 // Update Count : 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 09:42:04 2015 13 // Update Count : 3 14 14 // 15 15 … … 56 56 57 57 inline void Cost::incPoly( int inc ) { 58 poly+= inc;58 unsafe += inc; 59 59 } 60 60 61 61 inline void Cost::incSafe( int inc ) { 62 safe += inc;62 unsafe += inc; 63 63 } 64 64 -
src/main.cc
rf678663e r093f1a0 9 9 // Author : Richard C. Bilson 10 10 // Created On : Fri May 15 23:12:02 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Jul 30 1 6:08:18201513 // Update Count : 1 6711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 30 15:36:41 2015 13 // Update Count : 146 14 14 // 15 15 … … 228 228 // add the assignment statement after the 229 229 // initialization of a type parameter 230 OPTPRINT( "tweak" ) 231 InitTweak::tweak( translationUnit ); 230 232 OPTPRINT( "validate" ) 231 233 SymTab::validate( translationUnit, symtabp ); … … 249 251 OPTPRINT( "fixNames" ) 250 252 CodeGen::fixNames( translationUnit ); 251 OPTPRINT( "tweak" )252 InitTweak::tweak( translationUnit );253 253 254 254 if ( libcfap ) {
Note:
See TracChangeset
for help on using the changeset viewer.