Changes in src/CodeGen/CodeGenerator.cc [afc1045:03e5d14]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rafc1045 r03e5d14 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 : Wed Mar 2 17:32:16201611 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri May 06 15:40:35 2016 13 13 // Update Count : 243 14 14 // … … 75 75 //*** Declarations 76 76 void CodeGenerator::visit( FunctionDecl *functionDecl ) { 77 // generalize this 78 FunctionDecl::Attribute attr = functionDecl->get_attribute(); 79 switch ( attr.type ) { 80 case FunctionDecl::Attribute::Constructor: 81 output << "__attribute__ ((constructor"; 82 if ( attr.priority != FunctionDecl::Attribute::Default ) { 83 output << "(" << attr.priority << ")"; 84 } 85 output << ")) "; 86 break; 87 case FunctionDecl::Attribute::Destructor: 88 output << "__attribute__ ((destructor"; 89 if ( attr.priority != FunctionDecl::Attribute::Default ) { 90 output << "(" << attr.priority << ")"; 91 } 92 output << ")) "; 93 break; 94 default: 95 break; 96 } 77 97 handleStorageClass( functionDecl ); 78 98 if ( functionDecl->get_isInline() ) { … … 99 119 handleStorageClass( objectDecl ); 100 120 output << genType( objectDecl->get_type(), mangleName( objectDecl ) ); 101 121 102 122 if ( objectDecl->get_init() ) { 103 123 output << " = "; … … 113 133 if ( aggDecl->get_name() != "" ) 114 134 output << aggDecl->get_name(); 115 135 116 136 std::list< Declaration * > &memb = aggDecl->get_members(); 117 137 … … 119 139 output << " {" << endl; 120 140 121 cur_indent += CodeGenerator::tabsize; 141 cur_indent += CodeGenerator::tabsize; 122 142 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 123 output << indent; 143 output << indent; 124 144 (*i)->accept( *this ); 125 145 output << ";" << endl; 126 146 } 127 147 128 cur_indent -= CodeGenerator::tabsize; 148 cur_indent -= CodeGenerator::tabsize; 129 149 130 150 output << indent << "}"; … … 141 161 handleAggregate( aggregateDecl ); 142 162 } 143 163 144 164 void CodeGenerator::visit( EnumDecl *aggDecl ) { 145 165 output << "enum "; … … 147 167 if ( aggDecl->get_name() != "" ) 148 168 output << aggDecl->get_name(); 149 169 150 170 std::list< Declaration* > &memb = aggDecl->get_members(); 151 171 … … 153 173 output << " {" << endl; 154 174 155 cur_indent += CodeGenerator::tabsize; 175 cur_indent += CodeGenerator::tabsize; 156 176 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 157 177 ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i ); 158 178 assert( obj ); 159 output << indent << mangleName( obj ); 179 output << indent << mangleName( obj ); 160 180 if ( obj->get_init() ) { 161 181 output << " = "; … … 165 185 } // for 166 186 167 cur_indent -= CodeGenerator::tabsize; 187 cur_indent -= CodeGenerator::tabsize; 168 188 169 189 output << indent << "}"; 170 190 } // if 171 191 } 172 192 173 193 void CodeGenerator::visit( TraitDecl *aggregateDecl ) {} 174 194 175 195 void CodeGenerator::visit( TypedefDecl *typeDecl ) { 176 196 output << "typedef "; 177 197 output << genType( typeDecl->get_base(), typeDecl->get_name() ); 178 198 } 179 199 180 200 void CodeGenerator::visit( TypeDecl *typeDecl ) { 181 201 // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes, … … 217 237 } 218 238 219 void CodeGenerator::visit( Constant *constant ) { 239 void CodeGenerator::visit( Constant *constant ) { 220 240 output << constant->get_value() ; 221 241 } … … 234 254 assert( arg != applicationExpr->get_args().end() ); 235 255 if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) { 236 256 237 257 *arg = addrExpr->get_arg(); 238 258 } else { … … 243 263 break; 244 264 } 245 265 246 266 default: 247 267 // do nothing 248 268 ; 249 269 } 250 270 251 271 switch ( opInfo.type ) { 252 272 case OT_INDEX: … … 257 277 output << "]"; 258 278 break; 259 279 260 280 case OT_CALL: 261 281 // there are no intrinsic definitions of the function call operator 262 282 assert( false ); 263 283 break; 264 284 265 285 case OT_PREFIX: 266 286 case OT_PREFIXASSIGN: … … 271 291 output << ")"; 272 292 break; 273 293 274 294 case OT_POSTFIX: 275 295 case OT_POSTFIXASSIGN: … … 288 308 output << ")"; 289 309 break; 290 310 291 311 case OT_CONSTANT: 292 312 case OT_LABELADDRESS: … … 307 327 } // if 308 328 } 309 329 310 330 void CodeGenerator::visit( UntypedExpr *untypedExpr ) { 311 331 if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) { … … 321 341 output << "]"; 322 342 break; 323 343 324 344 case OT_CALL: 325 345 assert( false ); 326 346 break; 327 347 328 348 case OT_PREFIX: 329 349 case OT_PREFIXASSIGN: … … 335 355 output << ")"; 336 356 break; 337 357 338 358 case OT_POSTFIX: 339 359 case OT_POSTFIXASSIGN: … … 342 362 output << opInfo.symbol; 343 363 break; 344 364 345 365 case OT_INFIX: 346 366 case OT_INFIXASSIGN: … … 352 372 output << ")"; 353 373 break; 354 374 355 375 case OT_CONSTANT: 356 376 // there are no intrinsic definitions of 0 or 1 as functions … … 370 390 } // if 371 391 } 372 392 373 393 void CodeGenerator::visit( NameExpr *nameExpr ) { 374 394 OperatorInfo opInfo; … … 380 400 } // if 381 401 } 382 402 383 403 void CodeGenerator::visit( AddressExpr *addressExpr ) { 384 404 output << "(&"; … … 409 429 output << ")"; 410 430 } 411 431 412 432 void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) { 413 433 assert( false ); 414 434 } 415 435 416 436 void CodeGenerator::visit( MemberExpr *memberExpr ) { 417 437 memberExpr->get_aggregate()->accept( *this ); 418 438 output << "." << mangleName( memberExpr->get_member() ); 419 439 } 420 440 421 441 void CodeGenerator::visit( VariableExpr *variableExpr ) { 422 442 OperatorInfo opInfo; … … 427 447 } // if 428 448 } 429 449 430 450 void CodeGenerator::visit( ConstantExpr *constantExpr ) { 431 451 assert( constantExpr->get_constant() ); 432 452 constantExpr->get_constant()->accept( *this ); 433 453 } 434 454 435 455 void CodeGenerator::visit( SizeofExpr *sizeofExpr ) { 436 456 output << "sizeof("; … … 469 489 assert( false && "OffsetPackExpr should not reach code generation" ); 470 490 } 471 491 472 492 void CodeGenerator::visit( LogicalExpr *logicalExpr ) { 473 493 output << "("; … … 481 501 output << ")"; 482 502 } 483 503 484 504 void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) { 485 505 output << "("; … … 491 511 output << ")"; 492 512 } 493 513 494 514 void CodeGenerator::visit( CommaExpr *commaExpr ) { 495 515 output << "("; … … 499 519 output << ")"; 500 520 } 501 521 502 522 void CodeGenerator::visit( TupleExpr *tupleExpr ) {} 503 523 504 524 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 505 525 … … 532 552 } 533 553 } 534 cur_indent -= CodeGenerator::tabsize; 554 cur_indent -= CodeGenerator::tabsize; 535 555 536 556 output << indent << "}"; … … 538 558 539 559 void CodeGenerator::visit( ExprStmt *exprStmt ) { 540 // I don't see why this check is necessary. 541 // If this starts to cause problems then put it back in, 560 // I don't see why this check is necessary. 561 // If this starts to cause problems then put it back in, 542 562 // with an explanation 543 563 assert( exprStmt ); … … 589 609 switchStmt->get_condition()->accept( *this ); 590 610 output << " ) "; 591 611 592 612 output << "{" << std::endl; 593 613 cur_indent += CodeGenerator::tabsize; … … 609 629 } // if 610 630 output << ":\n"; 611 631 612 632 std::list<Statement *> sts = caseStmt->get_statements(); 613 633 … … 626 646 if ( ! branchStmt->get_target().empty() ) 627 647 output << "goto " << branchStmt->get_target(); 628 else { 648 else { 629 649 if ( branchStmt->get_computedTarget() != 0 ) { 630 650 output << "goto *"; … … 677 697 678 698 void CodeGenerator::visit( ForStmt *forStmt ) { 679 // initialization is always hoisted, so don't 680 // bother doing anything with that 699 // initialization is always hoisted, so don't 700 // bother doing anything with that 681 701 output << "for (;"; 682 702 … … 702 722 void CodeGenerator::visit( DeclStmt *declStmt ) { 703 723 declStmt->get_decl()->accept( *this ); 704 724 705 725 if ( doSemicolon( declStmt->get_decl() ) ) { 706 726 output << ";";
Note:
See TracChangeset
for help on using the changeset viewer.