Changeset b1e63ac5 for src/CodeGen
- Timestamp:
- Jul 4, 2017, 9:40:16 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 208e5be
- Parents:
- 9c951e3 (diff), f7cb0bc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/CodeGen
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r9c951e3 rb1e63ac5 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 10 14:45:00 201713 // Update Count : 48 412 // Last Modified On : Thu Jun 8 16:00:00 2017 13 // Update Count : 485 14 14 // 15 15 … … 65 65 } // if 66 66 } // extension 67 68 ostream & CodeGenerator::Indenter::operator()( ostream & output ) const {69 return output << string( cg.cur_indent, ' ' );70 }71 72 ostream & operator<<( ostream & output, const CodeGenerator::Indenter &indent ) {73 return indent( output );74 }75 67 76 68 CodeGenerator::LabelPrinter & CodeGenerator::LabelPrinter::operator()( std::list< Label > & l ) { … … 111 103 } 112 104 113 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {} 114 115 CodeGenerator::CodeGenerator( std::ostream & os, std::string init, int indentation, bool infunp ) 116 : indent( *this), cur_indent( indentation ), insideFunction( infunp ), output( os ), printLabels( *this ) { 117 //output << std::string( init ); 118 } 119 120 CodeGenerator::CodeGenerator( std::ostream & os, char * init, int indentation, bool infunp ) 121 : indent( *this ), cur_indent( indentation ), insideFunction( infunp ), output( os ), printLabels( *this ) { 122 //output << std::string( init ); 123 } 105 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( CodeGenerator::tabsize ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {} 124 106 125 107 string CodeGenerator::mangleName( DeclarationWithType * decl ) { … … 212 194 output << " {" << endl; 213 195 214 cur_indent += CodeGenerator::tabsize;196 ++indent; 215 197 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 216 198 output << lineDirective( *i ) << indent; … … 219 201 } // for 220 202 221 cur_indent -= CodeGenerator::tabsize;203 --indent; 222 204 223 205 output << indent << "}"; … … 249 231 output << " {" << endl; 250 232 251 cur_indent += CodeGenerator::tabsize;233 ++indent; 252 234 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 253 235 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); … … 261 243 } // for 262 244 263 cur_indent -= CodeGenerator::tabsize;245 --indent; 264 246 265 247 output << indent << "}"; … … 267 249 } 268 250 269 void CodeGenerator::visit( TraitDecl * traitDecl ) {}251 void CodeGenerator::visit( __attribute__((unused)) TraitDecl * traitDecl ) {} 270 252 271 253 void CodeGenerator::visit( TypedefDecl * typeDecl ) { … … 298 280 } 299 281 300 void CodeGenerator:: printDesignators( std::list< Expression * > & designators) {301 typedef std::list< Expression * > DesignatorList;282 void CodeGenerator::visit( Designation * designation ) { 283 std::list< Expression * > designators = designation->get_designators(); 302 284 if ( designators.size() == 0 ) return; 303 for ( DesignatorList::iterator iter = designators.begin(); iter != designators.end(); ++iter) {304 if ( dynamic_cast< NameExpr * >( *iter) ) {305 // if expression is a name, then initializing aggregate member285 for ( Expression * des : designators ) { 286 if ( dynamic_cast< NameExpr * >( des ) || dynamic_cast< VariableExpr * >( des ) ) { 287 // if expression is a NameExpr or VariableExpr, then initializing aggregate member 306 288 output << "."; 307 (*iter)->accept( *this );289 des->accept( *this ); 308 290 } else { 309 // if not a simple name, it has to be a constant expression, i.e. an array designator291 // otherwise, it has to be a ConstantExpr or CastExpr, initializing array eleemnt 310 292 output << "["; 311 (*iter)->accept( *this );293 des->accept( *this ); 312 294 output << "]"; 313 295 } // if … … 317 299 318 300 void CodeGenerator::visit( SingleInit * init ) { 319 printDesignators( init->get_designators() );320 301 init->get_value()->accept( *this ); 321 302 } 322 303 323 304 void CodeGenerator::visit( ListInit * init ) { 324 printDesignators( init->get_designators() ); 305 auto initBegin = init->begin(); 306 auto initEnd = init->end(); 307 auto desigBegin = init->get_designations().begin(); 308 auto desigEnd = init->get_designations().end(); 309 325 310 output << "{ "; 326 if ( init->begin() == init->end() ) { 327 // illegal to leave initializer list empty for scalar initializers, but always legal to have 0 328 output << "0"; 329 } else { 330 genCommaList( init->begin(), init->end() ); 331 } // if 311 for ( ; initBegin != initEnd && desigBegin != desigEnd; ) { 312 (*desigBegin)->accept( *this ); 313 (*initBegin)->accept( *this ); 314 ++initBegin, ++desigBegin; 315 if ( initBegin != initEnd ) { 316 output << ", "; 317 } 318 } 332 319 output << " }"; 333 } 334 335 void CodeGenerator::visit( ConstructorInit * init ){ 320 assertf( initBegin == initEnd && desigBegin == desigEnd, "Initializers and designators not the same length. %s", toString( init ).c_str() ); 321 } 322 323 void CodeGenerator::visit( __attribute__((unused)) ConstructorInit * init ){ 336 324 assertf( ! genC, "ConstructorInit nodes should not reach code generation." ); 337 325 // xxx - generate something reasonable for constructor/destructor pairs … … 731 719 732 720 void CodeGenerator::visit( TypeExpr * typeExpr ) { 733 assertf( ! genC, "TypeExpr should not reach code generation." ); 734 output<< genType( typeExpr->get_type(), "", pretty, genC ); 721 // if ( genC ) std::cerr << "typeexpr still exists: " << typeExpr << std::endl; 722 // assertf( ! genC, "TypeExpr should not reach code generation." ); 723 if ( ! genC ) { 724 output<< genType( typeExpr->get_type(), "", pretty, genC ); 725 } 735 726 } 736 727 … … 756 747 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 757 748 output << lineDirective( stmtExpr) << "({" << std::endl; 758 cur_indent += CodeGenerator::tabsize;749 ++indent; 759 750 unsigned int numStmts = stmts.size(); 760 751 unsigned int i = 0; … … 779 770 ++i; 780 771 } 781 cur_indent -= CodeGenerator::tabsize;772 --indent; 782 773 output << indent << "})"; 783 774 } … … 788 779 output << "{" << endl; 789 780 790 cur_indent += CodeGenerator::tabsize;781 ++indent; 791 782 792 783 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++ ) { … … 799 790 } // if 800 791 } // for 801 cur_indent -= CodeGenerator::tabsize;792 --indent; 802 793 803 794 output << indent << "}"; … … 867 858 868 859 output << "{" << std::endl; 869 cur_indent += CodeGenerator::tabsize;860 ++indent; 870 861 acceptAll( switchStmt->get_statements(), *this ); 871 cur_indent -= CodeGenerator::tabsize;862 --indent; 872 863 output << indent << "}"; 873 864 } … … 886 877 std::list<Statement *> sts = caseStmt->get_statements(); 887 878 888 cur_indent += CodeGenerator::tabsize;879 ++indent; 889 880 for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end(); i++) { 890 881 output << indent << printLabels( (*i)->get_labels() ) ; … … 892 883 output << endl; 893 884 } // for 894 cur_indent -= CodeGenerator::tabsize;885 --indent; 895 886 } 896 887 … … 923 914 } 924 915 916 void CodeGenerator::visit( ThrowStmt * throwStmt ) { 917 assertf( ! genC, "Throw statements should not reach code generation." ); 918 919 output << ((throwStmt->get_kind() == ThrowStmt::Terminate) ? 920 "throw" : "throwResume"); 921 if (throwStmt->get_expr()) { 922 output << " "; 923 throwStmt->get_expr()->accept( *this ); 924 } 925 if (throwStmt->get_target()) { 926 output << " _At "; 927 throwStmt->get_target()->accept( *this ); 928 } 929 output << ";"; 930 } 931 925 932 void CodeGenerator::visit( WhileStmt * whileStmt ) { 926 933 if ( whileStmt->get_isDoWhile() ) { … … 967 974 } 968 975 969 void CodeGenerator::visit( NullStmt * nullStmt ) {976 void CodeGenerator::visit( __attribute__((unused)) NullStmt * nullStmt ) { 970 977 //output << indent << CodeGenerator::printLabels( nullStmt->get_labels() ); 971 978 output << "/* null statement */ ;"; -
src/CodeGen/CodeGenerator.h
r9c951e3 rb1e63ac5 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 10 10:57:00 201713 // Update Count : 5 112 // Last Modified On : Thu Jun 8 15:48:00 2017 13 // Update Count : 52 14 14 // 15 15 … … 25 25 #include "SymTab/Indexer.h" 26 26 27 #include "Common/Indenter.h" 27 28 #include "Common/utility.h" 28 29 … … 47 48 48 49 //*** Initializer 50 virtual void visit( Designation * ); 49 51 virtual void visit( SingleInit * ); 50 52 virtual void visit( ListInit * ); … … 91 93 virtual void visit( BranchStmt * ); 92 94 virtual void visit( ReturnStmt * ); 95 virtual void visit( ThrowStmt * ); 93 96 virtual void visit( WhileStmt * ); 94 97 virtual void visit( ForStmt * ); … … 99 102 100 103 template< class Iterator > void genCommaList( Iterator begin, Iterator end ); 101 102 struct Indenter {103 Indenter(CodeGenerator &cg) : cg(cg) {}104 CodeGenerator & cg;105 std::ostream& operator()(std::ostream & os) const;106 };107 104 108 105 struct LabelPrinter { … … 128 125 private: 129 126 Indenter indent; 130 int cur_indent;131 127 bool insideFunction; 132 128 std::ostream &output; … … 136 132 bool lineMarks = false; 137 133 138 void printDesignators( std::list< Expression * > & );139 134 void handleStorageClass( DeclarationWithType *decl ); 140 135 void handleAggregate( AggregateDecl *aggDecl, const std::string & kind ); -
src/CodeGen/FixNames.cc
r9c951e3 rb1e63ac5 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Mar 16 07:50:30 201713 // Update Count : 1611 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jun 28 15:26:00 2017 13 // Update Count : 20 14 14 // 15 15 … … 93 93 void FixNames::fixDWT( DeclarationWithType *dwt ) { 94 94 if ( dwt->get_name() != "" ) { 95 if ( LinkageSpec::is Decoratable( dwt->get_linkage() ) ) {95 if ( LinkageSpec::isMangled( dwt->get_linkage() ) ) { 96 96 dwt->set_mangleName( SymTab::Mangler::mangle( dwt ) ); 97 97 dwt->set_scopeLevel( scopeLevel ); … … 114 114 throw SemanticError("Main expected to have 0, 2 or 3 arguments\n", functionDecl); 115 115 } 116 functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new ConstantExpr( Constant ( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), "0") ) ) );116 functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new ConstantExpr( Constant::from_int( 0 ) ) ) ); 117 117 CodeGen::FixMain::registerMain( functionDecl ); 118 118 }
Note:
See TracChangeset
for help on using the changeset viewer.