Changeset 00ede9e
- Timestamp:
- Jan 20, 2016, 2:03:17 PM (9 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:
- d41280e
- Parents:
- d67a9a1 (diff), 803deb1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rd67a9a1 r00ede9e 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:24:08 201513 // Update Count : 2 3112 // Last Modified On : Wed Jan 20 12:54:50 2016 13 // Update Count : 241 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 // there are no intrinsic definitions of the function call operator 261 261 assert( false ); 262 262 break; 263 263 264 264 case OT_PREFIX: 265 265 case OT_PREFIXASSIGN: … … 270 270 output << ")"; 271 271 break; 272 272 273 273 case OT_POSTFIX: 274 274 case OT_POSTFIXASSIGN: … … 287 287 output << ")"; 288 288 break; 289 289 290 290 case OT_CONSTANT: 291 291 case OT_LABELADDRESS: … … 306 306 } // if 307 307 } 308 308 309 309 void CodeGenerator::visit( UntypedExpr *untypedExpr ) { 310 310 if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) { … … 320 320 output << "]"; 321 321 break; 322 322 323 323 case OT_CALL: 324 324 assert( false ); 325 325 break; 326 326 327 327 case OT_PREFIX: 328 328 case OT_PREFIXASSIGN: … … 334 334 output << ")"; 335 335 break; 336 336 337 337 case OT_POSTFIX: 338 338 case OT_POSTFIXASSIGN: … … 341 341 output << opInfo.symbol; 342 342 break; 343 343 344 344 case OT_INFIX: 345 345 case OT_INFIXASSIGN: … … 351 351 output << ")"; 352 352 break; 353 353 354 354 case OT_CONSTANT: 355 355 // there are no intrinsic definitions of 0 or 1 as functions … … 369 369 } // if 370 370 } 371 371 372 372 void CodeGenerator::visit( NameExpr *nameExpr ) { 373 373 OperatorInfo opInfo; … … 379 379 } // if 380 380 } 381 381 382 382 void CodeGenerator::visit( AddressExpr *addressExpr ) { 383 383 output << "(&"; … … 392 392 393 393 void CodeGenerator::visit( CastExpr *castExpr ) { 394 // if the cast is to an lvalue type, then the cast 395 // should be dropped, since the result of a cast is 396 // never an lvalue in C 397 if ( castExpr->get_results().front()->get_isLvalue() ) { 398 castExpr->get_arg()->accept( *this ); 399 } else { 400 output << "(("; 401 if ( castExpr->get_results().empty() ) { 402 output << "void" ; 403 } else { 404 output << genType( castExpr->get_results().front(), "" ); 405 } // if 394 output << "("; 395 if ( castExpr->get_results().empty() ) { 396 output << "(void)" ; 397 } else if ( ! castExpr->get_results().front()->get_isLvalue() ) { 398 // at least one result type of cast, but not an lvalue 399 output << "("; 400 output << genType( castExpr->get_results().front(), "" ); 406 401 output << ")"; 407 castExpr->get_arg()->accept( *this ); 408 output << ")"; 402 } else { 403 // otherwise, the cast is to an lvalue type, so the cast 404 // should be dropped, since the result of a cast is 405 // never an lvalue in C 409 406 } 410 } 411 407 castExpr->get_arg()->accept( *this ); 408 output << ")"; 409 } 410 412 411 void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) { 413 412 assert( false ); 414 413 } 415 414 416 415 void CodeGenerator::visit( MemberExpr *memberExpr ) { 417 416 memberExpr->get_aggregate()->accept( *this ); 418 417 output << "." << mangleName( memberExpr->get_member() ); 419 418 } 420 419 421 420 void CodeGenerator::visit( VariableExpr *variableExpr ) { 422 421 OperatorInfo opInfo; … … 427 426 } // if 428 427 } 429 428 430 429 void CodeGenerator::visit( ConstantExpr *constantExpr ) { 431 430 assert( constantExpr->get_constant() ); 432 431 constantExpr->get_constant()->accept( *this ); 433 432 } 434 433 435 434 void CodeGenerator::visit( SizeofExpr *sizeofExpr ) { 436 435 output << "sizeof("; … … 453 452 output << ")"; 454 453 } 455 454 456 455 void CodeGenerator::visit( LogicalExpr *logicalExpr ) { 457 456 output << "("; … … 465 464 output << ")"; 466 465 } 467 466 468 467 void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) { 469 468 output << "("; … … 475 474 output << ")"; 476 475 } 477 476 478 477 void CodeGenerator::visit( CommaExpr *commaExpr ) { 479 478 output << "("; … … 483 482 output << ")"; 484 483 } 485 484 486 485 void CodeGenerator::visit( TupleExpr *tupleExpr ) {} 487 486 488 487 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 489 488 … … 516 515 } 517 516 } 518 cur_indent -= CodeGenerator::tabsize; 517 cur_indent -= CodeGenerator::tabsize; 519 518 520 519 output << indent << "}"; … … 522 521 523 522 void CodeGenerator::visit( ExprStmt *exprStmt ) { 524 // I don't see why this check is necessary. 525 // If this starts to cause problems then put it back in, 523 // I don't see why this check is necessary. 524 // If this starts to cause problems then put it back in, 526 525 // with an explanation 527 526 assert( exprStmt ); … … 573 572 switchStmt->get_condition()->accept( *this ); 574 573 output << " ) "; 575 574 576 575 output << "{" << std::endl; 577 576 cur_indent += CodeGenerator::tabsize; … … 593 592 } // if 594 593 output << ":\n"; 595 594 596 595 std::list<Statement *> sts = caseStmt->get_statements(); 597 596 … … 610 609 if ( ! branchStmt->get_target().empty() ) 611 610 output << "goto " << branchStmt->get_target(); 612 else { 611 else { 613 612 if ( branchStmt->get_computedTarget() != 0 ) { 614 613 output << "goto *"; … … 661 660 662 661 void CodeGenerator::visit( ForStmt *forStmt ) { 663 // initialization is always hoisted, so don't 664 // bother doing anything with that 662 // initialization is always hoisted, so don't 663 // bother doing anything with that 665 664 output << "for (;"; 666 665 … … 686 685 void CodeGenerator::visit( DeclStmt *declStmt ) { 687 686 declStmt->get_decl()->accept( *this ); 688 687 689 688 if ( doSemicolon( declStmt->get_decl() ) ) { 690 689 output << ";"; -
src/GenPoly/Specialize.cc
rd67a9a1 r00ede9e 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Specialize.cc -- 7 // Specialize.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 : Tue Sep 22 14:04:13 201513 // Update Count : 1 512 // Last Modified On : Wed Jan 20 12:40:33 2016 13 // Update Count : 18 14 14 // 15 15 … … 140 140 return new AddressExpr( new VariableExpr( thunkFunc ) ); 141 141 } 142 142 143 143 Expression * Specialize::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) { 144 assert( ! actual->get_results().empty() ); 144 145 if ( needsSpecialization( formalType, actual->get_results().front(), env ) ) { 145 146 FunctionType *funType; … … 198 199 Expression * Specialize::mutate( CastExpr *castExpr ) { 199 200 castExpr->get_arg()->acceptMutator( *this ); 201 if ( castExpr->get_results().empty() ) { 202 // can't specialize if we don't have a return value 203 return castExpr; 204 } 200 205 Expression *specialized = doSpecialization( castExpr->get_results().front(), castExpr->get_arg() ); 201 206 if ( specialized != castExpr->get_arg() ) {
Note: See TracChangeset
for help on using the changeset viewer.