Changes in src/CodeGen/CodeGenerator.cc [60a8062:4e5e6cc]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r60a8062 r4e5e6cc 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 : Sun Feb 16 08:32:48 202013 // Update Count : 53211 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr May 2 10:47:00 2019 13 // Update Count : 497 14 14 // 15 15 #include "CodeGenerator.h" … … 23 23 #include "InitTweak/InitTweak.h" // for getPointerBase 24 24 #include "OperatorTable.h" // for OperatorInfo, operatorLookup 25 #include " SynTree/LinkageSpec.h"// for Spec, Intrinsic25 #include "Parser/LinkageSpec.h" // for Spec, Intrinsic 26 26 #include "SynTree/Attribute.h" // for Attribute 27 27 #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode … … 39 39 int CodeGenerator::tabsize = 4; 40 40 41 // The kinds of statements that would ideally be followed by whitespace.41 // the kinds of statements that would ideally be followed by whitespace 42 42 bool wantSpacing( Statement * stmt) { 43 43 return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) || … … 78 78 } 79 79 80 // Using updateLocation at the beginning of a node and endl within a node should become the method of formating. 80 /* Using updateLocation at the beginning of a node and endl 81 * within a node should become the method of formating. 82 */ 81 83 void CodeGenerator::updateLocation( CodeLocation const & to ) { 82 84 // skip if linemarks shouldn't appear or if codelocation is unset … … 93 95 } else { 94 96 output << "\n# " << to.first_line << " \"" << to.filename 95 << "\"\n" << indent;97 << "\"\n" << indent; 96 98 currentLocation = to; 97 99 } … … 129 131 130 132 void CodeGenerator::genAttributes( list< Attribute * > & attributes ) { 131 if ( attributes.empty() ) return;133 if ( attributes.empty() ) return; 132 134 output << "__attribute__ (("; 133 135 for ( list< Attribute * >::iterator attr( attributes.begin() );; ) { … … 138 140 output << ")"; 139 141 } // if 140 if ( ++attr == attributes.end() ) break;142 if ( ++attr == attributes.end() ) break; 141 143 output << ","; // separator 142 144 } // for … … 163 165 previsit( (BaseSyntaxNode *)node ); 164 166 GuardAction( [this, node](){ 165 if ( options.printExprTypes && node->result ) {166 output << " /* " << genType( node->result, "", options ) << " */ ";167 }168 } );167 if ( options.printExprTypes && node->result ) { 168 output << " /* " << genType( node->result, "", options ) << " */ "; 169 } 170 } ); 169 171 } 170 172 … … 196 198 // deleted decls should never be used, so don't print them 197 199 if ( objectDecl->isDeleted && options.genC ) return; 198 199 // gcc allows an empty declarator (no name) for bit-fields and C states: 6.7.2.1 Structure and union specifiers, 200 // point 4, page 113: If the (bit field) value is zero, the declaration shall have no declarator. For anything 201 // else, the anonymous name refers to the anonymous object for plan9 inheritance. 202 if ( objectDecl->get_name().empty() && options.genC && ! objectDecl->get_bitfieldWidth() ) { 200 if (objectDecl->get_name().empty() && options.genC ) { 203 201 // only generate an anonymous name when generating C code, otherwise it clutters the output too much 204 202 static UniqueName name = { "__anonymous_object" }; 205 203 objectDecl->set_name( name.newName() ); 206 // Stops unused parameter warnings.207 if ( options.anonymousUnused ) {208 objectDecl->attributes.push_back( new Attribute( "unused" ) );209 }204 // Stops unused parameter warnings. 205 if ( options.anonymousUnused ) { 206 objectDecl->attributes.push_back( new Attribute( "unused" ) ); 207 } 210 208 } 211 209 … … 397 395 extension( applicationExpr ); 398 396 if ( VariableExpr * varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) { 399 const OperatorInfo *opInfo;400 if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && ( opInfo = operatorLookup( varExpr->get_var()->get_name() )) ) {397 OperatorInfo opInfo; 398 if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) { 401 399 std::list< Expression* >::iterator arg = applicationExpr->get_args().begin(); 402 switch ( opInfo ->type ) {400 switch ( opInfo.type ) { 403 401 case OT_INDEX: 404 402 assert( applicationExpr->get_args().size() == 2 ); … … 421 419 output << "("; 422 420 (*arg++)->accept( *visitor ); 423 output << ") /* " << opInfo ->inputName << " */";421 output << ") /* " << opInfo.inputName << " */"; 424 422 } else if ( applicationExpr->get_args().size() == 2 ) { 425 423 // intrinsic two parameter constructors are essentially bitwise assignment 426 424 output << "("; 427 425 (*arg++)->accept( *visitor ); 428 output << opInfo ->symbol;426 output << opInfo.symbol; 429 427 (*arg)->accept( *visitor ); 430 output << ") /* " << opInfo ->inputName << " */";428 output << ") /* " << opInfo.inputName << " */"; 431 429 } else { 432 430 // no constructors with 0 or more than 2 parameters … … 439 437 assert( applicationExpr->get_args().size() == 1 ); 440 438 output << "("; 441 output << opInfo ->symbol;439 output << opInfo.symbol; 442 440 (*arg)->accept( *visitor ); 443 441 output << ")"; … … 448 446 assert( applicationExpr->get_args().size() == 1 ); 449 447 (*arg)->accept( *visitor ); 450 output << opInfo ->symbol;448 output << opInfo.symbol; 451 449 break; 452 450 … … 457 455 output << "("; 458 456 (*arg++)->accept( *visitor ); 459 output << opInfo ->symbol;457 output << opInfo.symbol; 460 458 (*arg)->accept( *visitor ); 461 459 output << ")"; … … 484 482 extension( untypedExpr ); 485 483 if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr->function ) ) { 486 const OperatorInfo * opInfo = operatorLookup( nameExpr->name );487 if ( op Info) {484 OperatorInfo opInfo; 485 if ( operatorLookup( nameExpr->name, opInfo ) ) { 488 486 std::list< Expression* >::iterator arg = untypedExpr->args.begin(); 489 switch ( opInfo ->type ) {487 switch ( opInfo.type ) { 490 488 case OT_INDEX: 491 489 assert( untypedExpr->args.size() == 2 ); … … 506 504 output << "("; 507 505 (*arg++)->accept( *visitor ); 508 output << ") /* " << opInfo ->inputName << " */";506 output << ") /* " << opInfo.inputName << " */"; 509 507 } else if ( untypedExpr->get_args().size() == 2 ) { 510 508 // intrinsic two parameter constructors are essentially bitwise assignment 511 509 output << "("; 512 510 (*arg++)->accept( *visitor ); 513 output << opInfo ->symbol;511 output << opInfo.symbol; 514 512 (*arg)->accept( *visitor ); 515 output << ") /* " << opInfo ->inputName << " */";513 output << ") /* " << opInfo.inputName << " */"; 516 514 } else { 517 515 // no constructors with 0 or more than 2 parameters … … 519 517 output << "("; 520 518 (*arg++)->accept( *visitor ); 521 output << opInfo ->symbol << "{ ";519 output << opInfo.symbol << "{ "; 522 520 genCommaList( arg, untypedExpr->args.end() ); 523 output << "}) /* " << opInfo ->inputName << " */";521 output << "}) /* " << opInfo.inputName << " */"; 524 522 } // if 525 523 break; … … 530 528 assert( untypedExpr->args.size() == 1 ); 531 529 output << "("; 532 output << opInfo ->symbol;530 output << opInfo.symbol; 533 531 (*arg)->accept( *visitor ); 534 532 output << ")"; … … 539 537 assert( untypedExpr->args.size() == 1 ); 540 538 (*arg)->accept( *visitor ); 541 output << opInfo ->symbol;539 output << opInfo.symbol; 542 540 break; 543 541 … … 547 545 output << "("; 548 546 (*arg++)->accept( *visitor ); 549 output << opInfo ->symbol;547 output << opInfo.symbol; 550 548 (*arg)->accept( *visitor ); 551 549 output << ")"; … … 579 577 void CodeGenerator::postvisit( NameExpr * nameExpr ) { 580 578 extension( nameExpr ); 581 const OperatorInfo * opInfo = operatorLookup( nameExpr->name );582 if ( op Info) {583 if ( opInfo ->type == OT_CONSTANT ) {584 output << opInfo ->symbol;579 OperatorInfo opInfo; 580 if ( operatorLookup( nameExpr->name, opInfo ) ) { 581 if ( opInfo.type == OT_CONSTANT ) { 582 output << opInfo.symbol; 585 583 } else { 586 output << opInfo ->outputName;584 output << opInfo.outputName; 587 585 } 588 586 } else { … … 652 650 void CodeGenerator::postvisit( VariableExpr * variableExpr ) { 653 651 extension( variableExpr ); 654 const OperatorInfo *opInfo;655 if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && (opInfo = operatorLookup( variableExpr->get_var()->get_name() )) && opInfo->type == OT_CONSTANT ) {656 output << opInfo ->symbol;652 OperatorInfo opInfo; 653 if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( variableExpr->get_var()->get_name(), opInfo ) && opInfo.type == OT_CONSTANT ) { 654 output << opInfo.symbol; 657 655 } else { 658 656 output << mangleName( variableExpr->get_var() ); … … 784 782 785 783 void CodeGenerator::postvisit( AsmExpr * asmExpr ) { 786 if ( !asmExpr->inout.empty() ) {784 if ( asmExpr->get_inout() ) { 787 785 output << "[ "; 788 output << asmExpr->inout;786 asmExpr->get_inout()->accept( *visitor ); 789 787 output << " ] "; 790 788 } // if 791 asmExpr-> constraint->accept( *visitor );789 asmExpr->get_constraint()->accept( *visitor ); 792 790 output << " ( "; 793 asmExpr-> operand->accept( *visitor );791 asmExpr->get_operand()->accept( *visitor ); 794 792 output << " )"; 795 793 } … … 1009 1007 case BranchStmt::FallThroughDefault: 1010 1008 assertf( ! options.genC, "fallthru should not reach code generation." ); 1011 output << "fallthru";1009 output << "fallthru"; 1012 1010 break; 1013 1011 } // switch … … 1033 1031 1034 1032 output << ((throwStmt->get_kind() == ThrowStmt::Terminate) ? 1035 "throw" : "throwResume");1033 "throw" : "throwResume"); 1036 1034 if (throwStmt->get_expr()) { 1037 1035 output << " "; … … 1048 1046 1049 1047 output << ((stmt->get_kind() == CatchStmt::Terminate) ? 1050 "catch" : "catchResume");1048 "catch" : "catchResume"); 1051 1049 output << "( "; 1052 1050 stmt->decl->accept( *visitor ); … … 1185 1183 1186 1184 std::string genName( DeclarationWithType * decl ) { 1187 const OperatorInfo * opInfo = operatorLookup( decl->get_name() );1188 if ( op Info) {1189 return opInfo ->outputName;1185 CodeGen::OperatorInfo opInfo; 1186 if ( operatorLookup( decl->get_name(), opInfo ) ) { 1187 return opInfo.outputName; 1190 1188 } else { 1191 1189 return decl->get_name();
Note:
See TracChangeset
for help on using the changeset viewer.