Changes in src/CodeGen/CodeGenerator.cc [fbcde64:5f642e38]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rfbcde64 r5f642e38 89 89 } 90 90 91 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty) {}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 ) {} 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 );138 output << genType( functionDecl->get_functionType(), mangleName( functionDecl ), pretty, genC ); 139 139 140 140 asmName( functionDecl ); … … 147 147 148 148 void CodeGenerator::visit( ObjectDecl * objectDecl ) { 149 if (objectDecl->get_name().empty()) { 149 if (objectDecl->get_name().empty() && genC ) { 150 // only generate an anonymous name when generating C code, otherwise it clutters the output too much 150 151 static UniqueName name = { "__anonymous_object" }; 151 152 objectDecl->set_name( name.newName() ); … … 156 157 157 158 handleStorageClass( objectDecl ); 158 output << genType( objectDecl->get_type(), mangleName( objectDecl ), pretty );159 output << genType( objectDecl->get_type(), mangleName( objectDecl ), pretty, genC ); 159 160 160 161 asmName( objectDecl ); … … 171 172 } 172 173 173 void CodeGenerator::handleAggregate( AggregateDecl * aggDecl ) {174 void CodeGenerator::handleAggregate( AggregateDecl * aggDecl, const std::string & kind ) { 174 175 genAttributes( aggDecl->get_attributes() ); 175 176 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; 176 185 if ( aggDecl->get_name() != "" ) 177 186 output << aggDecl->get_name(); 178 187 179 // std::list< Declaration * > & memb = aggDecl->get_members();180 // if ( ! memb.empty() ) {181 188 if ( aggDecl->has_body() ) { 182 189 std::list< Declaration * > & memb = aggDecl->get_members(); … … 198 205 void CodeGenerator::visit( StructDecl * structDecl ) { 199 206 extension( structDecl ); 200 output << "struct "; 201 handleAggregate( structDecl ); 207 handleAggregate( structDecl, "struct " ); 202 208 } 203 209 204 210 void CodeGenerator::visit( UnionDecl * unionDecl ) { 205 211 extension( unionDecl ); 206 output << "union "; 207 handleAggregate( unionDecl ); 212 handleAggregate( unionDecl, "union " ); 208 213 } 209 214 … … 242 247 243 248 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 244 assert ( false &&"Typedefs are removed and substituted in earlier passes." );245 //output << "typedef ";246 //output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty );249 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 250 output << "typedef "; 251 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; 247 252 } 248 253 249 254 void CodeGenerator::visit( TypeDecl * typeDecl ) { 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 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 } 257 271 } 258 272 … … 293 307 294 308 void CodeGenerator::visit( ConstructorInit * init ){ 295 assertf( false, "ConstructorInit nodes should not make it to CodeGen." ); 309 assertf( ! genC, "ConstructorInit nodes should not reach code generation." ); 310 // xxx - generate something reasonable for constructor/destructor pairs 311 output << "<ctorinit>"; 296 312 } 297 313 … … 547 563 // at least one result type of cast, but not an lvalue 548 564 output << "("; 549 output << genType( castExpr->get_result(), "", pretty );565 output << genType( castExpr->get_result(), "", pretty, genC ); 550 566 output << ")"; 551 567 } else { … … 558 574 559 575 void CodeGenerator::visit( UntypedMemberExpr * memberExpr ) { 560 assert( false ); 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 ); 561 581 } 562 582 … … 587 607 output << "sizeof("; 588 608 if ( sizeofExpr->get_isType() ) { 589 output << genType( sizeofExpr->get_type(), "", pretty );609 output << genType( sizeofExpr->get_type(), "", pretty, genC ); 590 610 } else { 591 611 sizeofExpr->get_expr()->accept( *this ); … … 599 619 output << "__alignof__("; 600 620 if ( alignofExpr->get_isType() ) { 601 output << genType( alignofExpr->get_type(), "", pretty );621 output << genType( alignofExpr->get_type(), "", pretty, genC ); 602 622 } else { 603 623 alignofExpr->get_expr()->accept( *this ); … … 607 627 608 628 void CodeGenerator::visit( UntypedOffsetofExpr * offsetofExpr ) { 609 assert( false && "UntypedOffsetofExpr should not reach code generation." ); 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 << ")"; 610 634 } 611 635 … … 613 637 // use GCC builtin 614 638 output << "__builtin_offsetof("; 615 output << genType( offsetofExpr->get_type(), "", pretty );639 output << genType( offsetofExpr->get_type(), "", pretty, genC ); 616 640 output << ", " << mangleName( offsetofExpr->get_member() ); 617 641 output << ")"; … … 619 643 620 644 void CodeGenerator::visit( OffsetPackExpr * offsetPackExpr ) { 621 assert( false && "OffsetPackExpr should not reach code generation." ); 645 assertf( ! genC, "OffsetPackExpr should not reach code generation." ); 646 output << "__CFA_offsetpack(" << genType( offsetPackExpr->get_type(), "", pretty, genC ) << ")"; 622 647 } 623 648 … … 655 680 } 656 681 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 ) {} 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 } 662 700 663 701 void CodeGenerator::visit( AsmExpr * asmExpr ) { … … 675 713 void CodeGenerator::visit( CompoundLiteralExpr *compLitExpr ) { 676 714 assert( compLitExpr->get_result() && dynamic_cast< ListInit * > ( compLitExpr->get_initializer() ) ); 677 output << "(" << genType( compLitExpr->get_result(), "", pretty ) << ")";715 output << "(" << genType( compLitExpr->get_result(), "", pretty, genC ) << ")"; 678 716 compLitExpr->get_initializer()->accept( *this ); 679 717 }
Note:
See TracChangeset
for help on using the changeset viewer.