Changeset 71f4e4f for src/CodeGen
- Timestamp:
- Jan 13, 2016, 5:19:47 PM (10 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, with_gc
- Children:
- f1e012b
- Parents:
- 02c7d04
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r02c7d04 r71f4e4f 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 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Sep 17 15:25:58 201513 // Update Count : 23 312 // Last Modified On : Wed Jan 13 16:26:59 2016 13 // Update Count : 234 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 260 case OT_CTOR: … … 263 263 assert( false ); 264 264 break; 265 265 266 266 case OT_PREFIX: 267 267 case OT_PREFIXASSIGN: … … 272 272 output << ")"; 273 273 break; 274 274 275 275 case OT_POSTFIX: 276 276 case OT_POSTFIXASSIGN: … … 289 289 output << ")"; 290 290 break; 291 291 292 292 case OT_CONSTANT: 293 293 case OT_LABELADDRESS: … … 308 308 } // if 309 309 } 310 310 311 311 void CodeGenerator::visit( UntypedExpr *untypedExpr ) { 312 312 if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) { … … 322 322 output << "]"; 323 323 break; 324 324 325 325 case OT_CALL: 326 326 case OT_CTOR: … … 328 328 assert( false ); 329 329 break; 330 330 331 331 case OT_PREFIX: 332 332 case OT_PREFIXASSIGN: … … 338 338 output << ")"; 339 339 break; 340 340 341 341 case OT_POSTFIX: 342 342 case OT_POSTFIXASSIGN: … … 345 345 output << opInfo.symbol; 346 346 break; 347 347 348 348 case OT_INFIX: 349 349 case OT_INFIXASSIGN: … … 355 355 output << ")"; 356 356 break; 357 357 358 358 case OT_CONSTANT: 359 359 // there are no intrinsic definitions of 0 or 1 as functions … … 373 373 } // if 374 374 } 375 375 376 376 void CodeGenerator::visit( NameExpr *nameExpr ) { 377 377 OperatorInfo opInfo; … … 383 383 } // if 384 384 } 385 385 386 386 void CodeGenerator::visit( AddressExpr *addressExpr ) { 387 387 output << "(&"; … … 410 410 output << ")"; 411 411 castExpr->get_arg()->accept( *this ); 412 output << ")"; 412 output << ")"; 413 413 } 414 414 } 415 415 416 416 void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) { 417 417 assert( false ); 418 418 } 419 419 420 420 void CodeGenerator::visit( MemberExpr *memberExpr ) { 421 421 memberExpr->get_aggregate()->accept( *this ); 422 422 output << "." << mangleName( memberExpr->get_member() ); 423 423 } 424 424 425 425 void CodeGenerator::visit( VariableExpr *variableExpr ) { 426 426 OperatorInfo opInfo; … … 431 431 } // if 432 432 } 433 433 434 434 void CodeGenerator::visit( ConstantExpr *constantExpr ) { 435 435 assert( constantExpr->get_constant() ); 436 436 constantExpr->get_constant()->accept( *this ); 437 437 } 438 438 439 439 void CodeGenerator::visit( SizeofExpr *sizeofExpr ) { 440 440 output << "sizeof("; … … 457 457 output << ")"; 458 458 } 459 459 460 460 void CodeGenerator::visit( LogicalExpr *logicalExpr ) { 461 461 output << "("; … … 469 469 output << ")"; 470 470 } 471 471 472 472 void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) { 473 473 output << "("; … … 479 479 output << ")"; 480 480 } 481 481 482 482 void CodeGenerator::visit( CommaExpr *commaExpr ) { 483 483 output << "("; … … 487 487 output << ")"; 488 488 } 489 489 490 490 void CodeGenerator::visit( TupleExpr *tupleExpr ) {} 491 491 492 492 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 493 493 … … 520 520 } 521 521 } 522 cur_indent -= CodeGenerator::tabsize; 522 cur_indent -= CodeGenerator::tabsize; 523 523 524 524 output << indent << "}"; … … 526 526 527 527 void CodeGenerator::visit( ExprStmt *exprStmt ) { 528 // I don't see why this check is necessary. 529 // If this starts to cause problems then put it back in, 528 // I don't see why this check is necessary. 529 // If this starts to cause problems then put it back in, 530 530 // with an explanation 531 531 assert( exprStmt ); … … 577 577 switchStmt->get_condition()->accept( *this ); 578 578 output << " ) "; 579 579 580 580 output << "{" << std::endl; 581 581 cur_indent += CodeGenerator::tabsize; … … 597 597 } // if 598 598 output << ":\n"; 599 599 600 600 std::list<Statement *> sts = caseStmt->get_statements(); 601 601 … … 614 614 if ( ! branchStmt->get_target().empty() ) 615 615 output << "goto " << branchStmt->get_target(); 616 else { 616 else { 617 617 if ( branchStmt->get_computedTarget() != 0 ) { 618 618 output << "goto *"; … … 665 665 666 666 void CodeGenerator::visit( ForStmt *forStmt ) { 667 // initialization is always hoisted, so don't 668 // bother doing anything with that 667 // initialization is always hoisted, so don't 668 // bother doing anything with that 669 669 output << "for (;"; 670 670 … … 690 690 void CodeGenerator::visit( DeclStmt *declStmt ) { 691 691 declStmt->get_decl()->accept( *this ); 692 692 693 693 if ( doSemicolon( declStmt->get_decl() ) ) { 694 694 output << ";";
Note:
See TracChangeset
for help on using the changeset viewer.