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