Changes in src/CodeGen/CodeGenerator.cc [2a4b088:a9a259c]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r2a4b088 ra9a259c 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // CodeGenerator.cc -- 7 // CodeGenerator.cc -- 8 8 // 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 : Mon Jan 25 21:22:00 201613 // Update Count : 2 4211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Feb 09 13:24:40 2016 13 // Update Count : 255 14 14 // 15 15 … … 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 // there are no intrinsic definitions of the function call operator 260 // there are no intrinsic definitions of the function call operator or constructors or destructors 261 261 assert( false ); 262 262 break; 263 263 264 case OT_CTOR: 265 // it's just an optimization to disallow this, so for now let it through 266 // since it makes autogenerating constructors a lot easier 267 varExpr->accept( *this ); 268 output << "("; 269 genCommaList( applicationExpr->get_args().begin(), applicationExpr->get_args().end() ); 270 output << ")"; 271 272 // intrinsic constructors should never be called directly - they should be transformed back into Initializer nodes 273 // assert(false); 274 break; 275 276 case OT_DTOR: 277 // intrinsic destructors do nothing - don't generate any code 278 output << " // " << dynamic_cast<VariableExpr*>(applicationExpr->get_function())->get_var()->get_name() << endl; 279 break; 280 264 281 case OT_PREFIX: 265 282 case OT_PREFIXASSIGN: … … 270 287 output << ")"; 271 288 break; 272 289 273 290 case OT_POSTFIX: 274 291 case OT_POSTFIXASSIGN: … … 277 294 output << opInfo.symbol; 278 295 break; 296 279 297 280 298 case OT_INFIX: … … 287 305 output << ")"; 288 306 break; 289 307 290 308 case OT_CONSTANT: 291 309 case OT_LABELADDRESS: … … 306 324 } // if 307 325 } 308 326 309 327 void CodeGenerator::visit( UntypedExpr *untypedExpr ) { 310 328 if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) { … … 320 338 output << "]"; 321 339 break; 322 340 323 341 case OT_CALL: 324 342 assert( false ); 325 break; 326 343 344 case OT_CTOR: 345 case OT_DTOR: 346 // intrinsic constructors should never be called 347 // intrinsic destructors do nothing 348 break; 349 327 350 case OT_PREFIX: 328 351 case OT_PREFIXASSIGN: … … 334 357 output << ")"; 335 358 break; 336 359 337 360 case OT_POSTFIX: 338 361 case OT_POSTFIXASSIGN: … … 341 364 output << opInfo.symbol; 342 365 break; 343 366 344 367 case OT_INFIX: 345 368 case OT_INFIXASSIGN: … … 351 374 output << ")"; 352 375 break; 353 376 354 377 case OT_CONSTANT: 355 378 // there are no intrinsic definitions of 0 or 1 as functions … … 369 392 } // if 370 393 } 371 394 372 395 void CodeGenerator::visit( NameExpr *nameExpr ) { 373 396 OperatorInfo opInfo; … … 379 402 } // if 380 403 } 381 404 382 405 void CodeGenerator::visit( AddressExpr *addressExpr ) { 383 406 output << "(&"; … … 408 431 output << ")"; 409 432 } 410 433 411 434 void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) { 412 435 assert( false ); 413 436 } 414 437 415 438 void CodeGenerator::visit( MemberExpr *memberExpr ) { 416 439 memberExpr->get_aggregate()->accept( *this ); 417 440 output << "." << mangleName( memberExpr->get_member() ); 418 441 } 419 442 420 443 void CodeGenerator::visit( VariableExpr *variableExpr ) { 421 444 OperatorInfo opInfo; … … 426 449 } // if 427 450 } 428 451 429 452 void CodeGenerator::visit( ConstantExpr *constantExpr ) { 430 453 assert( constantExpr->get_constant() ); 431 454 constantExpr->get_constant()->accept( *this ); 432 455 } 433 456 434 457 void CodeGenerator::visit( SizeofExpr *sizeofExpr ) { 435 458 output << "sizeof("; … … 464 487 output << ")"; 465 488 } 466 489 467 490 void CodeGenerator::visit( LogicalExpr *logicalExpr ) { 468 491 output << "("; … … 476 499 output << ")"; 477 500 } 478 501 479 502 void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) { 480 503 output << "("; … … 486 509 output << ")"; 487 510 } 488 511 489 512 void CodeGenerator::visit( CommaExpr *commaExpr ) { 490 513 output << "("; … … 494 517 output << ")"; 495 518 } 496 519 497 520 void CodeGenerator::visit( TupleExpr *tupleExpr ) {} 498 521 499 522 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 500 523 … … 527 550 } 528 551 } 529 cur_indent -= CodeGenerator::tabsize; 552 cur_indent -= CodeGenerator::tabsize; 530 553 531 554 output << indent << "}"; … … 533 556 534 557 void CodeGenerator::visit( ExprStmt *exprStmt ) { 535 // I don't see why this check is necessary. 536 // If this starts to cause problems then put it back in, 558 // I don't see why this check is necessary. 559 // If this starts to cause problems then put it back in, 537 560 // with an explanation 538 561 assert( exprStmt ); … … 584 607 switchStmt->get_condition()->accept( *this ); 585 608 output << " ) "; 586 609 587 610 output << "{" << std::endl; 588 611 cur_indent += CodeGenerator::tabsize; … … 604 627 } // if 605 628 output << ":\n"; 606 629 607 630 std::list<Statement *> sts = caseStmt->get_statements(); 608 631 … … 621 644 if ( ! branchStmt->get_target().empty() ) 622 645 output << "goto " << branchStmt->get_target(); 623 else { 646 else { 624 647 if ( branchStmt->get_computedTarget() != 0 ) { 625 648 output << "goto *"; … … 672 695 673 696 void CodeGenerator::visit( ForStmt *forStmt ) { 674 // initialization is always hoisted, so don't 675 // bother doing anything with that 697 // initialization is always hoisted, so don't 698 // bother doing anything with that 676 699 output << "for (;"; 677 700 … … 697 720 void CodeGenerator::visit( DeclStmt *declStmt ) { 698 721 declStmt->get_decl()->accept( *this ); 699 722 700 723 if ( doSemicolon( declStmt->get_decl() ) ) { 701 724 output << ";";
Note:
See TracChangeset
for help on using the changeset viewer.