Changeset ae8b942 for src/CodeGen
- Timestamp:
- Jan 29, 2016, 4:36:46 PM (8 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:
- 5721a6d
- Parents:
- d3b7937 (diff), 73a28e2 (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:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rd3b7937 rae8b942 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // CodeGenerator.cc -- 7 // CodeGenerator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 98 98 handleStorageClass( objectDecl ); 99 99 output << genType( objectDecl->get_type(), mangleName( objectDecl ) ); 100 100 101 101 if ( objectDecl->get_init() ) { 102 102 output << " = "; … … 112 112 if ( aggDecl->get_name() != "" ) 113 113 output << aggDecl->get_name(); 114 114 115 115 std::list< Declaration * > &memb = aggDecl->get_members(); 116 116 … … 118 118 output << " {" << endl; 119 119 120 cur_indent += CodeGenerator::tabsize; 120 cur_indent += CodeGenerator::tabsize; 121 121 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 122 output << indent; 122 output << indent; 123 123 (*i)->accept( *this ); 124 124 output << ";" << endl; 125 125 } 126 126 127 cur_indent -= CodeGenerator::tabsize; 127 cur_indent -= CodeGenerator::tabsize; 128 128 129 129 output << indent << "}"; … … 140 140 handleAggregate( aggregateDecl ); 141 141 } 142 142 143 143 void CodeGenerator::visit( EnumDecl *aggDecl ) { 144 144 output << "enum "; … … 146 146 if ( aggDecl->get_name() != "" ) 147 147 output << aggDecl->get_name(); 148 148 149 149 std::list< Declaration* > &memb = aggDecl->get_members(); 150 150 … … 152 152 output << " {" << endl; 153 153 154 cur_indent += CodeGenerator::tabsize; 154 cur_indent += CodeGenerator::tabsize; 155 155 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 156 156 ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i ); 157 157 assert( obj ); 158 output << indent << mangleName( obj ); 158 output << indent << mangleName( obj ); 159 159 if ( obj->get_init() ) { 160 160 output << " = "; … … 164 164 } // for 165 165 166 cur_indent -= CodeGenerator::tabsize; 166 cur_indent -= CodeGenerator::tabsize; 167 167 168 168 output << indent << "}"; 169 169 } // if 170 170 } 171 171 172 172 void CodeGenerator::visit( ContextDecl *aggregateDecl ) {} 173 173 174 174 void CodeGenerator::visit( TypedefDecl *typeDecl ) { 175 175 output << "typedef "; 176 176 output << genType( typeDecl->get_base(), typeDecl->get_name() ); 177 177 } 178 178 179 179 void CodeGenerator::visit( TypeDecl *typeDecl ) { 180 180 // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes, … … 216 216 } 217 217 218 void CodeGenerator::visit( Constant *constant ) { 218 void CodeGenerator::visit( Constant *constant ) { 219 219 output << constant->get_value() ; 220 220 } … … 233 233 assert( arg != applicationExpr->get_args().end() ); 234 234 if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) { 235 235 236 236 *arg = addrExpr->get_arg(); 237 237 } else { … … 242 242 break; 243 243 } 244 244 245 245 default: 246 246 // do nothing 247 247 ; 248 248 } 249 249 250 250 switch ( opInfo.type ) { 251 251 case OT_INDEX: … … 256 256 output << "]"; 257 257 break; 258 258 259 259 case OT_CALL: 260 260 // there are no intrinsic definitions of the function call operator 261 261 assert( false ); 262 262 break; 263 263 264 264 case OT_PREFIX: 265 265 case OT_PREFIXASSIGN: … … 270 270 output << ")"; 271 271 break; 272 272 273 273 case OT_POSTFIX: 274 274 case OT_POSTFIXASSIGN: … … 287 287 output << ")"; 288 288 break; 289 289 290 290 case OT_CONSTANT: 291 291 case OT_LABELADDRESS: … … 306 306 } // if 307 307 } 308 308 309 309 void CodeGenerator::visit( UntypedExpr *untypedExpr ) { 310 310 if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) { … … 320 320 output << "]"; 321 321 break; 322 322 323 323 case OT_CALL: 324 324 assert( false ); 325 325 break; 326 326 327 327 case OT_PREFIX: 328 328 case OT_PREFIXASSIGN: … … 334 334 output << ")"; 335 335 break; 336 336 337 337 case OT_POSTFIX: 338 338 case OT_POSTFIXASSIGN: … … 341 341 output << opInfo.symbol; 342 342 break; 343 343 344 344 case OT_INFIX: 345 345 case OT_INFIXASSIGN: … … 351 351 output << ")"; 352 352 break; 353 353 354 354 case OT_CONSTANT: 355 355 // there are no intrinsic definitions of 0 or 1 as functions … … 369 369 } // if 370 370 } 371 371 372 372 void CodeGenerator::visit( NameExpr *nameExpr ) { 373 373 OperatorInfo opInfo; … … 379 379 } // if 380 380 } 381 381 382 382 void CodeGenerator::visit( AddressExpr *addressExpr ) { 383 383 output << "(&"; … … 408 408 output << ")"; 409 409 } 410 410 411 411 void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) { 412 412 assert( false ); 413 413 } 414 414 415 415 void CodeGenerator::visit( MemberExpr *memberExpr ) { 416 416 memberExpr->get_aggregate()->accept( *this ); 417 417 output << "." << mangleName( memberExpr->get_member() ); 418 418 } 419 419 420 420 void CodeGenerator::visit( VariableExpr *variableExpr ) { 421 421 OperatorInfo opInfo; … … 426 426 } // if 427 427 } 428 428 429 429 void CodeGenerator::visit( ConstantExpr *constantExpr ) { 430 430 assert( constantExpr->get_constant() ); 431 431 constantExpr->get_constant()->accept( *this ); 432 432 } 433 433 434 434 void CodeGenerator::visit( SizeofExpr *sizeofExpr ) { 435 435 output << "sizeof("; … … 442 442 } 443 443 444 void CodeGenerator::visit( AlignofExpr * sizeofExpr ) {444 void CodeGenerator::visit( AlignofExpr *alignofExpr ) { 445 445 // use GCC extension to avoid bumping std to C11 446 446 output << "__alignof__("; 447 if ( sizeofExpr->get_isType() ) {448 output << genType( sizeofExpr->get_type(), "" );449 } else { 450 sizeofExpr->get_expr()->accept( *this );447 if ( alignofExpr->get_isType() ) { 448 output << genType( alignofExpr->get_type(), "" ); 449 } else { 450 alignofExpr->get_expr()->accept( *this ); 451 451 } // if 452 452 output << ")"; 453 453 } 454 454 455 void CodeGenerator::visit( OffsetofExpr *offsetofExpr ) { 456 // use GCC builtin 457 output << "__builtin_offsetof("; 458 output << genType( offsetofExpr->get_type(), "" ); 459 output << ", " << mangleName( offsetofExpr->get_member() ); 460 output << ")"; 461 } 462 455 463 void CodeGenerator::visit( LogicalExpr *logicalExpr ) { 456 464 output << "("; … … 464 472 output << ")"; 465 473 } 466 474 467 475 void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) { 468 476 output << "("; … … 474 482 output << ")"; 475 483 } 476 484 477 485 void CodeGenerator::visit( CommaExpr *commaExpr ) { 478 486 output << "("; … … 482 490 output << ")"; 483 491 } 484 492 485 493 void CodeGenerator::visit( TupleExpr *tupleExpr ) {} 486 494 487 495 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 488 496 … … 515 523 } 516 524 } 517 cur_indent -= CodeGenerator::tabsize; 525 cur_indent -= CodeGenerator::tabsize; 518 526 519 527 output << indent << "}"; … … 521 529 522 530 void CodeGenerator::visit( ExprStmt *exprStmt ) { 523 // I don't see why this check is necessary. 524 // If this starts to cause problems then put it back in, 531 // I don't see why this check is necessary. 532 // If this starts to cause problems then put it back in, 525 533 // with an explanation 526 534 assert( exprStmt ); … … 572 580 switchStmt->get_condition()->accept( *this ); 573 581 output << " ) "; 574 582 575 583 output << "{" << std::endl; 576 584 cur_indent += CodeGenerator::tabsize; … … 592 600 } // if 593 601 output << ":\n"; 594 602 595 603 std::list<Statement *> sts = caseStmt->get_statements(); 596 604 … … 609 617 if ( ! branchStmt->get_target().empty() ) 610 618 output << "goto " << branchStmt->get_target(); 611 else { 619 else { 612 620 if ( branchStmt->get_computedTarget() != 0 ) { 613 621 output << "goto *"; … … 660 668 661 669 void CodeGenerator::visit( ForStmt *forStmt ) { 662 // initialization is always hoisted, so don't 663 // bother doing anything with that 670 // initialization is always hoisted, so don't 671 // bother doing anything with that 664 672 output << "for (;"; 665 673 … … 685 693 void CodeGenerator::visit( DeclStmt *declStmt ) { 686 694 declStmt->get_decl()->accept( *this ); 687 695 688 696 if ( doSemicolon( declStmt->get_decl() ) ) { 689 697 output << ";"; -
src/CodeGen/CodeGenerator.h
rd3b7937 rae8b942 61 61 virtual void visit( SizeofExpr *sizeofExpr ); 62 62 virtual void visit( AlignofExpr *alignofExpr ); 63 virtual void visit( OffsetofExpr *offsetofExpr ); 63 64 virtual void visit( LogicalExpr *logicalExpr ); 64 65 virtual void visit( ConditionalExpr *conditionalExpr );
Note: See TracChangeset
for help on using the changeset viewer.