Changes in src/CodeGen/CodeGenerator.cc [5f642e38:fbcde64]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r5f642e38 rfbcde64 89 89 } 90 90 91 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty , bool genC ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC) {}91 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ) {} 92 92 93 93 CodeGenerator::CodeGenerator( std::ostream & os, std::string init, int indentation, bool infunp ) … … 136 136 functionDecl->get_funcSpec().print( output ); 137 137 138 output << genType( functionDecl->get_functionType(), mangleName( functionDecl ), pretty , genC);138 output << genType( functionDecl->get_functionType(), mangleName( functionDecl ), pretty ); 139 139 140 140 asmName( functionDecl ); … … 147 147 148 148 void CodeGenerator::visit( ObjectDecl * objectDecl ) { 149 if (objectDecl->get_name().empty() && genC ) { 150 // only generate an anonymous name when generating C code, otherwise it clutters the output too much 149 if (objectDecl->get_name().empty()) { 151 150 static UniqueName name = { "__anonymous_object" }; 152 151 objectDecl->set_name( name.newName() ); … … 157 156 158 157 handleStorageClass( objectDecl ); 159 output << genType( objectDecl->get_type(), mangleName( objectDecl ), pretty , genC);158 output << genType( objectDecl->get_type(), mangleName( objectDecl ), pretty ); 160 159 161 160 asmName( objectDecl ); … … 172 171 } 173 172 174 void CodeGenerator::handleAggregate( AggregateDecl * aggDecl , const std::string & kind) {173 void CodeGenerator::handleAggregate( AggregateDecl * aggDecl ) { 175 174 genAttributes( aggDecl->get_attributes() ); 176 175 177 if( ! aggDecl->get_parameters().empty() && ! genC ) {178 // assertf( ! genC, "Aggregate type parameters should not reach code generation." );179 output << "forall(";180 genCommaList( aggDecl->get_parameters().begin(), aggDecl->get_parameters().end() );181 output << ")" << endl;182 }183 184 output << kind;185 176 if ( aggDecl->get_name() != "" ) 186 177 output << aggDecl->get_name(); 187 178 179 // std::list< Declaration * > & memb = aggDecl->get_members(); 180 // if ( ! memb.empty() ) { 188 181 if ( aggDecl->has_body() ) { 189 182 std::list< Declaration * > & memb = aggDecl->get_members(); … … 205 198 void CodeGenerator::visit( StructDecl * structDecl ) { 206 199 extension( structDecl ); 207 handleAggregate( structDecl, "struct " ); 200 output << "struct "; 201 handleAggregate( structDecl ); 208 202 } 209 203 210 204 void CodeGenerator::visit( UnionDecl * unionDecl ) { 211 205 extension( unionDecl ); 212 handleAggregate( unionDecl, "union " ); 206 output << "union "; 207 handleAggregate( unionDecl ); 213 208 } 214 209 … … 247 242 248 243 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 249 assert f( ! genC,"Typedefs are removed and substituted in earlier passes." );250 output << "typedef ";251 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl;244 assert( false && "Typedefs are removed and substituted in earlier passes." ); 245 //output << "typedef "; 246 //output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty ); 252 247 } 253 248 254 249 void CodeGenerator::visit( TypeDecl * typeDecl ) { 255 if ( genC ) { 256 // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes, 257 // still to be done 258 extension( typeDecl ); 259 output << "extern unsigned long " << typeDecl->get_name(); 260 if ( typeDecl->get_base() ) { 261 output << " = sizeof( " << genType( typeDecl->get_base(), "", pretty, genC ) << " )"; 262 } // if 263 } else { 264 output << typeDecl->typeString() << " " << typeDecl->get_name(); 265 if ( ! typeDecl->get_assertions().empty() ) { 266 output << " | { "; 267 genCommaList( typeDecl->get_assertions().begin(), typeDecl->get_assertions().end() ); 268 output << " }"; 269 } 270 } 250 // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes, 251 // still to be done 252 extension( typeDecl ); 253 output << "extern unsigned long " << typeDecl->get_name(); 254 if ( typeDecl->get_base() ) { 255 output << " = sizeof( " << genType( typeDecl->get_base(), "", pretty ) << " )"; 256 } // if 271 257 } 272 258 … … 307 293 308 294 void CodeGenerator::visit( ConstructorInit * init ){ 309 assertf( ! genC, "ConstructorInit nodes should not reach code generation." ); 310 // xxx - generate something reasonable for constructor/destructor pairs 311 output << "<ctorinit>"; 295 assertf( false, "ConstructorInit nodes should not make it to CodeGen." ); 312 296 } 313 297 … … 563 547 // at least one result type of cast, but not an lvalue 564 548 output << "("; 565 output << genType( castExpr->get_result(), "", pretty , genC);549 output << genType( castExpr->get_result(), "", pretty ); 566 550 output << ")"; 567 551 } else { … … 574 558 575 559 void CodeGenerator::visit( UntypedMemberExpr * memberExpr ) { 576 assertf( ! genC, "UntypedMemberExpr should not reach code generation." ); 577 extension( memberExpr ); 578 memberExpr->get_aggregate()->accept( *this ); 579 output << "."; 580 memberExpr->get_member()->accept( *this ); 560 assert( false ); 581 561 } 582 562 … … 607 587 output << "sizeof("; 608 588 if ( sizeofExpr->get_isType() ) { 609 output << genType( sizeofExpr->get_type(), "", pretty , genC);589 output << genType( sizeofExpr->get_type(), "", pretty ); 610 590 } else { 611 591 sizeofExpr->get_expr()->accept( *this ); … … 619 599 output << "__alignof__("; 620 600 if ( alignofExpr->get_isType() ) { 621 output << genType( alignofExpr->get_type(), "", pretty , genC);601 output << genType( alignofExpr->get_type(), "", pretty ); 622 602 } else { 623 603 alignofExpr->get_expr()->accept( *this ); … … 627 607 628 608 void CodeGenerator::visit( UntypedOffsetofExpr * offsetofExpr ) { 629 assertf( ! genC, "UntypedOffsetofExpr should not reach code generation." ); 630 output << "offsetof("; 631 output << genType( offsetofExpr->get_type(), "", pretty, genC ); 632 output << ", " << offsetofExpr->get_member(); 633 output << ")"; 609 assert( false && "UntypedOffsetofExpr should not reach code generation." ); 634 610 } 635 611 … … 637 613 // use GCC builtin 638 614 output << "__builtin_offsetof("; 639 output << genType( offsetofExpr->get_type(), "", pretty , genC);615 output << genType( offsetofExpr->get_type(), "", pretty ); 640 616 output << ", " << mangleName( offsetofExpr->get_member() ); 641 617 output << ")"; … … 643 619 644 620 void CodeGenerator::visit( OffsetPackExpr * offsetPackExpr ) { 645 assertf( ! genC, "OffsetPackExpr should not reach code generation." ); 646 output << "__CFA_offsetpack(" << genType( offsetPackExpr->get_type(), "", pretty, genC ) << ")"; 621 assert( false && "OffsetPackExpr should not reach code generation." ); 647 622 } 648 623 … … 680 655 } 681 656 682 void CodeGenerator::visit( UntypedTupleExpr * tupleExpr ) { 683 assertf( ! genC, "UntypedTupleExpr should not reach code generation." ); 684 output << "["; 685 genCommaList( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end() ); 686 output << "]"; 687 } 688 689 void CodeGenerator::visit( TupleExpr * tupleExpr ) { 690 assertf( ! genC, "TupleExpr should not reach code generation." ); 691 output << "["; 692 genCommaList( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end() ); 693 output << "]"; 694 } 695 696 void CodeGenerator::visit( TypeExpr * typeExpr ) { 697 assertf( ! genC, "TypeExpr should not reach code generation." ); 698 output<< genType( typeExpr->get_type(), "", pretty, genC ); 699 } 657 void CodeGenerator::visit( UntypedTupleExpr * tupleExpr ) { assertf( false, "UntypedTupleExpr should not make it to Code Gen" ); } 658 659 void CodeGenerator::visit( TupleExpr * tupleExpr ) { assertf( false, "TupleExpr should not make it to Code Gen" ); } 660 661 void CodeGenerator::visit( TypeExpr * typeExpr ) {} 700 662 701 663 void CodeGenerator::visit( AsmExpr * asmExpr ) { … … 713 675 void CodeGenerator::visit( CompoundLiteralExpr *compLitExpr ) { 714 676 assert( compLitExpr->get_result() && dynamic_cast< ListInit * > ( compLitExpr->get_initializer() ) ); 715 output << "(" << genType( compLitExpr->get_result(), "", pretty , genC) << ")";677 output << "(" << genType( compLitExpr->get_result(), "", pretty ) << ")"; 716 678 compLitExpr->get_initializer()->accept( *this ); 717 679 }
Note:
See TracChangeset
for help on using the changeset viewer.