Changes in src/CodeGen/CodeGenerator.cc [4e24610:afc1045]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r4e24610 rafc1045 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 : Fri May 06 11:39:01201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:32:16 2016 13 13 // Update Count : 243 14 14 // … … 84 84 output << genType( functionDecl->get_functionType(), mangleName( functionDecl ) ); 85 85 86 // generalize this87 switch ( functionDecl->get_attribute() ) {88 case FunctionDecl::Constructor:89 output << " __attribute__ ((constructor))";90 break;91 case FunctionDecl::Destructor:92 output << " __attribute__ ((destructor))";93 break;94 default:95 break;96 }97 98 86 // how to get this to the Functype? 99 87 std::list< Declaration * > olds = functionDecl->get_oldDecls(); … … 111 99 handleStorageClass( objectDecl ); 112 100 output << genType( objectDecl->get_type(), mangleName( objectDecl ) ); 113 101 114 102 if ( objectDecl->get_init() ) { 115 103 output << " = "; … … 125 113 if ( aggDecl->get_name() != "" ) 126 114 output << aggDecl->get_name(); 127 115 128 116 std::list< Declaration * > &memb = aggDecl->get_members(); 129 117 … … 131 119 output << " {" << endl; 132 120 133 cur_indent += CodeGenerator::tabsize; 121 cur_indent += CodeGenerator::tabsize; 134 122 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 135 output << indent; 123 output << indent; 136 124 (*i)->accept( *this ); 137 125 output << ";" << endl; 138 126 } 139 127 140 cur_indent -= CodeGenerator::tabsize; 128 cur_indent -= CodeGenerator::tabsize; 141 129 142 130 output << indent << "}"; … … 153 141 handleAggregate( aggregateDecl ); 154 142 } 155 143 156 144 void CodeGenerator::visit( EnumDecl *aggDecl ) { 157 145 output << "enum "; … … 159 147 if ( aggDecl->get_name() != "" ) 160 148 output << aggDecl->get_name(); 161 149 162 150 std::list< Declaration* > &memb = aggDecl->get_members(); 163 151 … … 165 153 output << " {" << endl; 166 154 167 cur_indent += CodeGenerator::tabsize; 155 cur_indent += CodeGenerator::tabsize; 168 156 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 169 157 ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i ); 170 158 assert( obj ); 171 output << indent << mangleName( obj ); 159 output << indent << mangleName( obj ); 172 160 if ( obj->get_init() ) { 173 161 output << " = "; … … 177 165 } // for 178 166 179 cur_indent -= CodeGenerator::tabsize; 167 cur_indent -= CodeGenerator::tabsize; 180 168 181 169 output << indent << "}"; 182 170 } // if 183 171 } 184 172 185 173 void CodeGenerator::visit( TraitDecl *aggregateDecl ) {} 186 174 187 175 void CodeGenerator::visit( TypedefDecl *typeDecl ) { 188 176 output << "typedef "; 189 177 output << genType( typeDecl->get_base(), typeDecl->get_name() ); 190 178 } 191 179 192 180 void CodeGenerator::visit( TypeDecl *typeDecl ) { 193 181 // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes, … … 229 217 } 230 218 231 void CodeGenerator::visit( Constant *constant ) { 219 void CodeGenerator::visit( Constant *constant ) { 232 220 output << constant->get_value() ; 233 221 } … … 246 234 assert( arg != applicationExpr->get_args().end() ); 247 235 if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) { 248 236 249 237 *arg = addrExpr->get_arg(); 250 238 } else { … … 255 243 break; 256 244 } 257 245 258 246 default: 259 247 // do nothing 260 248 ; 261 249 } 262 250 263 251 switch ( opInfo.type ) { 264 252 case OT_INDEX: … … 269 257 output << "]"; 270 258 break; 271 259 272 260 case OT_CALL: 273 261 // there are no intrinsic definitions of the function call operator 274 262 assert( false ); 275 263 break; 276 264 277 265 case OT_PREFIX: 278 266 case OT_PREFIXASSIGN: … … 283 271 output << ")"; 284 272 break; 285 273 286 274 case OT_POSTFIX: 287 275 case OT_POSTFIXASSIGN: … … 300 288 output << ")"; 301 289 break; 302 290 303 291 case OT_CONSTANT: 304 292 case OT_LABELADDRESS: … … 319 307 } // if 320 308 } 321 309 322 310 void CodeGenerator::visit( UntypedExpr *untypedExpr ) { 323 311 if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) { … … 333 321 output << "]"; 334 322 break; 335 323 336 324 case OT_CALL: 337 325 assert( false ); 338 326 break; 339 327 340 328 case OT_PREFIX: 341 329 case OT_PREFIXASSIGN: … … 347 335 output << ")"; 348 336 break; 349 337 350 338 case OT_POSTFIX: 351 339 case OT_POSTFIXASSIGN: … … 354 342 output << opInfo.symbol; 355 343 break; 356 344 357 345 case OT_INFIX: 358 346 case OT_INFIXASSIGN: … … 364 352 output << ")"; 365 353 break; 366 354 367 355 case OT_CONSTANT: 368 356 // there are no intrinsic definitions of 0 or 1 as functions … … 382 370 } // if 383 371 } 384 372 385 373 void CodeGenerator::visit( NameExpr *nameExpr ) { 386 374 OperatorInfo opInfo; … … 392 380 } // if 393 381 } 394 382 395 383 void CodeGenerator::visit( AddressExpr *addressExpr ) { 396 384 output << "(&"; … … 421 409 output << ")"; 422 410 } 423 411 424 412 void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) { 425 413 assert( false ); 426 414 } 427 415 428 416 void CodeGenerator::visit( MemberExpr *memberExpr ) { 429 417 memberExpr->get_aggregate()->accept( *this ); 430 418 output << "." << mangleName( memberExpr->get_member() ); 431 419 } 432 420 433 421 void CodeGenerator::visit( VariableExpr *variableExpr ) { 434 422 OperatorInfo opInfo; … … 439 427 } // if 440 428 } 441 429 442 430 void CodeGenerator::visit( ConstantExpr *constantExpr ) { 443 431 assert( constantExpr->get_constant() ); 444 432 constantExpr->get_constant()->accept( *this ); 445 433 } 446 434 447 435 void CodeGenerator::visit( SizeofExpr *sizeofExpr ) { 448 436 output << "sizeof("; … … 481 469 assert( false && "OffsetPackExpr should not reach code generation" ); 482 470 } 483 471 484 472 void CodeGenerator::visit( LogicalExpr *logicalExpr ) { 485 473 output << "("; … … 493 481 output << ")"; 494 482 } 495 483 496 484 void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) { 497 485 output << "("; … … 503 491 output << ")"; 504 492 } 505 493 506 494 void CodeGenerator::visit( CommaExpr *commaExpr ) { 507 495 output << "("; … … 511 499 output << ")"; 512 500 } 513 501 514 502 void CodeGenerator::visit( TupleExpr *tupleExpr ) {} 515 503 516 504 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 517 505 … … 544 532 } 545 533 } 546 cur_indent -= CodeGenerator::tabsize; 534 cur_indent -= CodeGenerator::tabsize; 547 535 548 536 output << indent << "}"; … … 550 538 551 539 void CodeGenerator::visit( ExprStmt *exprStmt ) { 552 // I don't see why this check is necessary. 553 // If this starts to cause problems then put it back in, 540 // I don't see why this check is necessary. 541 // If this starts to cause problems then put it back in, 554 542 // with an explanation 555 543 assert( exprStmt ); … … 601 589 switchStmt->get_condition()->accept( *this ); 602 590 output << " ) "; 603 591 604 592 output << "{" << std::endl; 605 593 cur_indent += CodeGenerator::tabsize; … … 621 609 } // if 622 610 output << ":\n"; 623 611 624 612 std::list<Statement *> sts = caseStmt->get_statements(); 625 613 … … 638 626 if ( ! branchStmt->get_target().empty() ) 639 627 output << "goto " << branchStmt->get_target(); 640 else { 628 else { 641 629 if ( branchStmt->get_computedTarget() != 0 ) { 642 630 output << "goto *"; … … 689 677 690 678 void CodeGenerator::visit( ForStmt *forStmt ) { 691 // initialization is always hoisted, so don't 692 // bother doing anything with that 679 // initialization is always hoisted, so don't 680 // bother doing anything with that 693 681 output << "for (;"; 694 682 … … 714 702 void CodeGenerator::visit( DeclStmt *declStmt ) { 715 703 declStmt->get_decl()->accept( *this ); 716 704 717 705 if ( doSemicolon( declStmt->get_decl() ) ) { 718 706 output << ";";
Note:
See TracChangeset
for help on using the changeset viewer.