Changeset 1869adf
- Timestamp:
- Jun 24, 2015, 4:33:13 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 721f17a, 937e51d
- Parents:
- 94e0864d
- Location:
- src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/LabelFixer.cc
r94e0864d r1869adf 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Jun 23 12:42:23201513 // Update Count : 9611 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 24 16:24:34 2015 13 // Update Count : 141 14 14 // 15 15 … … 19 19 #include "LabelFixer.h" 20 20 #include "MLEMutator.h" 21 #include "SynTree/Expression.h" 21 22 #include "SynTree/Statement.h" 22 23 #include "SynTree/Declaration.h" … … 26 27 27 28 namespace ControlStruct { 28 LabelFixer::Entry::Entry( Statement *to, BranchStmt *from ) : definition ( to ) { 29 if ( from != 0 ) 30 usage.push_back( from ); 31 } 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 32 43 33 44 bool LabelFixer::Entry::insideLoop() { … … 36 47 } 37 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 } 56 38 57 LabelFixer::LabelFixer( LabelGenerator *gen ) : generator ( gen ) { 39 58 if ( generator == 0 ) … … 50 69 // prune to at most one label definition for each statement 51 70 void LabelFixer::visit( Statement *stmt ) { 71 currentStatement = stmt; 52 72 std::list< Label > &labels = stmt->get_labels(); 53 73 … … 69 89 } 70 90 } 91 92 void LabelFixer::visit( UntypedExpr *untyped ) { 93 if ( NameExpr * func = dynamic_cast< NameExpr * >( untyped->get_function() ) ) { 94 if ( func->get_name() == "&&" ) { 95 NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() ); 96 Label target = arg->get_name(); 97 assert( target != "" ); 98 setLabelsUsg( target, untyped ); 99 } else { 100 Visitor::visit( untyped ); 101 } 102 } 103 } 104 71 105 72 106 // sets the definition of the labelTable entry to be the provided … … 89 123 // used previously, but undefined until now -> link with this entry 90 124 Entry * oldEntry = labelTable[ *i ]; 91 e->add_uses( oldEntry->get_uses());125 e->add_uses( *oldEntry ); 92 126 labelTable[ *i ] = e; 93 127 } // if … … 100 134 101 135 // Remember all uses of a label. 102 void LabelFixer::setLabelsUsg( Label orgValue, BranchStmt *use ) { 136 template< typename UsageNode > 137 void LabelFixer::setLabelsUsg( Label orgValue, UsageNode *use ) { 103 138 assert( use != 0 ); 104 139 … … 111 146 } 112 147 148 class LabelGetter : public Visitor { 149 public: 150 LabelGetter( Label &label ) : label( label ) {} 151 152 virtual void visit( BranchStmt * branchStmt ) { 153 label = branchStmt->get_target(); 154 } 155 156 virtual void visit( UntypedExpr * untyped ) { 157 NameExpr * name = dynamic_cast< NameExpr * >( untyped->get_function() ); 158 assert( name ); 159 assert( name->get_name() == "&&" ); 160 NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() ); 161 assert( arg ); 162 label = arg->get_name(); 163 } 164 165 private: 166 Label &label; 167 }; 168 169 class LabelSetter : public Visitor { 170 public: 171 LabelSetter( Label label ) : label( label ) {} 172 173 virtual void visit( BranchStmt * branchStmt ) { 174 branchStmt->set_target( label ); 175 } 176 177 virtual void visit( UntypedExpr * untyped ) { 178 NameExpr * name = dynamic_cast< NameExpr * >( untyped->get_function() ); 179 assert( name ); 180 assert( name->get_name() == "&&" ); 181 NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() ); 182 assert( arg ); 183 arg->set_name( label ); 184 } 185 186 private: 187 Label label; 188 }; 189 113 190 // Ultimately builds a table that maps a label to its defining statement. 114 191 // In the process, … … 121 198 122 199 if ( def_us.find ( e->get_definition() ) == def_us.end() ) { 123 def_us[ e->get_definition() ] = e; 200 def_us[ e->get_definition() ] = e; 124 201 } else if ( e->used() ) { 125 def_us[ e->get_definition() ]->add_uses( e->get_uses());202 def_us[ e->get_definition() ]->add_uses( *e ); 126 203 } 127 204 } … … 131 208 Statement *to = (*i).first; 132 209 Entry * entry = (*i).second; 133 std::list< BranchStmt *> &from = entry->get_uses();210 std::list< Entry::UsageLoc > &from = entry->get_uses(); 134 211 135 212 // no label definition found 136 213 if ( to == 0 ) { 137 Label undef = from.back()->get_target(); 214 Label undef; 215 LabelGetter getLabel( undef ); 216 from.back().accept( getLabel ); 217 // Label undef = getLabel( from.back()->get_target() ); 138 218 throw SemanticError ( "'" + undef + "' label not defined"); 139 219 } // if … … 147 227 148 228 // redirect each of the source branch statements to the new target label 149 for ( std::list< BranchStmt *>::iterator j = from.begin(); j != from.end(); ++j ) { 150 BranchStmt *jump = *j; 151 assert( jump != 0 ); 152 jump->set_target( finalLabel ); 229 for ( std::list< Entry::UsageLoc >::iterator j = from.begin(); j != from.end(); ++j ) { 230 LabelSetter setLabel( finalLabel ); 231 (*j).accept( setLabel ); 232 // setLabel( *j, finalLabel ); 233 234 // BranchStmt *jump = *j; 235 // assert( jump != 0 ); 236 // jump->set_target( finalLabel ); 153 237 } // for 154 238 } // for -
src/ControlStruct/LabelFixer.h
r94e0864d r1869adf 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri May 29 15:25:55 201513 // Update Count : 1112 // Last Modified On : Tue Jun 23 15:47:25 2015 13 // Update Count : 28 14 14 // 15 15 … … 53 53 virtual void visit( DeclStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } 54 54 virtual void visit( BranchStmt *branchStmt ); 55 virtual void visit( UntypedExpr *untyped ); 55 56 56 57 Label setLabelsDef( std::list< Label > &, Statement *definition ); 57 void setLabelsUsg( Label, BranchStmt *usage = 0 ); 58 template< typename UsageNode > 59 void setLabelsUsg( Label, UsageNode *usage = 0 ); 58 60 59 61 private: 60 62 class Entry { 61 public: 62 Entry( Statement *to = 0, BranchStmt *from = 0 ); 63 public: 64 union UsageLoc { 65 Statement * stmt; 66 Expression * expr; 67 68 void accept( Visitor &visitor ); 69 }; 70 71 Entry( Statement *to ) : definition( to ) {} 72 Entry( Statement *to, Statement *from ); 73 Entry( Statement *to, Expression *from ); 63 74 bool used() { return ( usage.empty() ); } 64 75 bool defined() { return ( definition != 0 ); } … … 71 82 void set_definition( Statement *def ) { definition = def; } 72 83 73 std::list< BranchStmt *> &get_uses() { return usage; } 74 void add_use ( BranchStmt *use ) { usage.push_back( use ); } 75 void add_uses ( std::list<BranchStmt *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); } 84 std::list< UsageLoc > &get_uses() { return usage; } 85 void add_use( Statement *use ) { 86 UsageLoc loc; 87 loc.stmt = use; 88 usage.push_back( loc ); 89 } 90 void add_use( Expression *use ) { 91 UsageLoc loc; 92 loc.expr = use; 93 usage.push_back( loc ); 94 } 95 96 void add_uses ( Entry &other ) { usage.insert( usage.end(), other.usage.begin(), usage.end() ); } 76 97 private: 77 98 Label label; 78 99 Statement *definition; 79 std::list< BranchStmt *> usage;100 std::list<UsageLoc> usage; 80 101 }; 81 102 82 103 std::map < Label, Entry *> labelTable; 83 104 LabelGenerator *generator; 105 Statement * currentStatement; 84 106 }; 85 107 } // namespace ControlStruct -
src/ControlStruct/LabelTypeChecker.cc
r94e0864d r1869adf 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue May 19 15:32:15201513 // Update Count : 211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 24 16:24:48 2015 13 // Update Count : 3 14 14 // 15 15 … … 29 29 NameExpr *fname; 30 30 if ( ((fname = dynamic_cast<NameExpr *>(untypedExpr->get_function())) != 0) 31 && fname->get_name() == std::string(" LabAddress") )31 && fname->get_name() == std::string("&&") ) 32 32 std::cerr << "Taking the label of an address." << std::endl; 33 33 else { -
src/Parser/ExpressionNode.cc
r94e0864d r1869adf 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 24 16: 10:47201513 // Update Count : 15 412 // Last Modified On : Wed Jun 24 16:20:00 2015 13 // Update Count : 158 14 14 // 15 15 -
src/ResolvExpr/Resolver.cc
r94e0864d r1869adf 10 10 // Created On : Sun May 17 12:17:01 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 24 16: 08:49201513 // Update Count : 15 512 // Last Modified On : Wed Jun 24 16:20:35 2015 13 // Update Count : 156 14 14 // 15 15 … … 363 363 resolveAggrInit( uit->get_baseUnion(), init, initEnd ); 364 364 } else { 365 // member is not an aggregate type, so can't go any deeper 366 365 367 // might need to rethink what is being thrown 366 368 throw; -
src/SymTab/Validate.cc
r94e0864d r1869adf 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jun 13 17:10:29201513 // Update Count : 2911 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 24 16:20:50 2015 13 // Update Count : 30 14 14 // 15 15 … … 176 176 acceptAll( translationUnit, pass1 ); 177 177 acceptAll( translationUnit, pass2 ); 178 // need to collect all of the assignment operators prior to 179 // this point and only generate assignment operators if one doesn't exist 178 180 AddStructAssignment::addStructAssignment( translationUnit ); 179 181 acceptAll( translationUnit, pass3 );
Note: See TracChangeset
for help on using the changeset viewer.