Changes in / [093f1a0:f678663e]
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/LabelFixer.cc
r093f1a0 rf678663e 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jul 08 12:36:46201513 // Update Count : 1 4512 // Last Modified On : Tue Jul 28 13:32:43 2015 13 // Update Count : 156 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 44 29 bool LabelFixer::Entry::insideLoop() { 45 30 return ( dynamic_cast< ForStmt * > ( definition ) || 46 31 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 }55 32 } 56 33 … … 77 54 // prune to at most one label definition for each statement 78 55 void LabelFixer::visit( Statement *stmt ) { 79 currentStatement = stmt;80 56 std::list< Label > &labels = stmt->get_labels(); 81 57 … … 83 59 // only remember one label for each statement 84 60 Label current = setLabelsDef( labels, stmt ); 85 labels.clear();86 labels.push_front( current );87 61 } // if 88 62 } … … 130 104 } else { 131 105 // used previously, but undefined until now -> link with this entry 132 Entry * oldEntry = labelTable[ *i ]; 133 e->add_uses( *oldEntry ); 106 delete labelTable[ *i ]; 134 107 labelTable[ *i ] = e; 135 108 } // if … … 141 114 } 142 115 143 // Remember all uses of a label.116 // A label was used, add it ot the table if it isn't already there 144 117 template< typename UsageNode > 145 118 void LabelFixer::setLabelsUsg( Label orgValue, UsageNode *use ) { 146 119 assert( use != 0 ); 147 120 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 ); 121 // add label with an unknown origin 122 if ( labelTable.find( orgValue ) == labelTable.end() ) { 123 labelTable[ orgValue ] = new Entry( 0 ); 153 124 } 154 125 } 155 126 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, 127 // Builds a table that maps a label to its defining statement. 200 128 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 ); 129 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 ); 211 133 } 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 249 std::map< Label, Statement * > *ret = new std::map< Label, Statement * >(); 250 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); ++i ) { 251 (*ret)[ (*i).second->get_label() ] = (*i).first; 134 (*ret)[ i->first ] = i->second->get_definition(); 252 135 } 253 136 -
src/ControlStruct/LabelFixer.h
r093f1a0 rf678663e 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 : Mon Jun 29 17:24:39201513 // Update Count : 2911 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 28 13:09:02 2015 13 // Update Count : 31 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 72 65 Entry( Statement *to ) : definition( to ) {} 73 Entry( Statement *to, Statement *from );74 Entry( Statement *to, Expression *from );75 bool used() { return ( usage.empty() ); }76 66 bool defined() { return ( definition != 0 ); } 77 67 bool insideLoop(); … … 83 73 void set_definition( Statement *def ) { definition = def; } 84 74 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() ); }98 75 private: 99 76 Label label; 100 77 Statement *definition; 101 std::list<UsageLoc> usage;102 78 }; 103 79 104 80 std::map < Label, Entry *> labelTable; 105 81 LabelGenerator *generator; 106 Statement * currentStatement;107 82 }; 108 83 } // namespace ControlStruct -
src/GenPoly/Box.cc
r093f1a0 rf678663e 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 24 16:19:07201513 // Update Count : 1012 // Last Modified On : Thu Jul 30 14:35:40 2015 13 // Update Count : 54 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) 529 530 std::list< DeclarationWithType *> ¶mList = functionType->get_parameters(); 530 531 std::list< FunctionType *> functions; … … 537 538 findFunction( (*arg)->get_type(), functions, exprTyVars, needsAdapter ); 538 539 } // 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 different 543 // parameter types may be unified to the same type 539 544 std::set< std::string > adaptersDone; 545 540 546 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) { 541 547 FunctionType *realFunction = (*funType)->clone(); 542 assert( env );543 env->apply( realFunction );544 545 548 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 549 550 // only attempt to create an adapter or pass one as a parameter if we haven't 551 // already done so for this pre-substitution parameter function type. 546 552 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 the 557 // adapter's type should look like 558 assert( env ); 559 env->apply( realFunction ); 560 mangleName = SymTab::Mangler::mangle( realFunction ); 547 561 AdapterMap & adapters = Pass1::adapters.top(); 548 562 AdapterMap::iterator adapter = adapters.find( mangleName ); … … 555 569 continue; 556 570 } else if ( adapter == adapters.end() ) { 571 // adapter has not been created yet in the current scope, so define it 557 572 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars ); 558 573 adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) ); … … 560 575 } // if 561 576 assert( adapter != adapters.end() ); 577 578 // add the appropriate adapter as a parameter 562 579 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 );565 580 } // if 566 581 } // for … … 880 895 881 896 void Pass1::doBeginScope() { 897 // actually, maybe this could (should?) push 898 // a copy of the current map 882 899 adapters.push(AdapterMap()); 883 900 } … … 1051 1068 if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) { 1052 1069 if ( isPolyVal( objectDecl->get_type(), scopeTyVars ) ) { 1070 // change initialization of a polymorphic value object 1071 // to allocate storage with alloca 1053 1072 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( objectDecl->get_type() ); 1054 1073 assert( typeInst ); 1055 1074 UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) ); 1056 1075 alloc->get_args().push_back( new NameExpr( typeInst->get_name() ) ); 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 ) ); 1076 1077 delete objectDecl->get_init(); 1078 1079 std::list<Expression*> designators; 1080 objectDecl->set_init( new SingleInit( alloc, designators ) ); 1061 1081 } 1062 1082 } -
src/ResolvExpr/Cost.h
r093f1a0 rf678663e 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 09:39:50 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun May 17 09:42:04201513 // Update Count : 311 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jul 22 16:43:10 2015 13 // Update Count : 4 14 14 // 15 15 … … 56 56 57 57 inline void Cost::incPoly( int inc ) { 58 unsafe+= inc;58 poly += inc; 59 59 } 60 60 61 61 inline void Cost::incSafe( int inc ) { 62 unsafe += inc;62 safe += inc; 63 63 } 64 64 -
src/main.cc
r093f1a0 rf678663e 9 9 // Author : Richard C. Bilson 10 10 // Created On : Fri May 15 23:12:02 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Jul 30 1 5:36:41201513 // Update Count : 1 4611 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jul 30 16:08:18 2015 13 // Update Count : 167 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 );232 230 OPTPRINT( "validate" ) 233 231 SymTab::validate( translationUnit, symtabp ); … … 251 249 OPTPRINT( "fixNames" ) 252 250 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.