Changeset 28e58fd for src/CodeGen
- Timestamp:
- Aug 25, 2017, 10:38:34 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 800d275
- Parents:
- af08051 (diff), 3eab308c (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/CodeGen
- Files:
-
- 5 edited
-
CodeGenerator.cc (modified) (10 diffs)
-
CodeGenerator.h (modified) (1 diff)
-
GenType.cc (modified) (3 diffs)
-
OperatorTable.cc (modified) (2 diffs)
-
OperatorTable.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
raf08051 r28e58fd 192 192 genCommaList( aggDecl->get_parameters().begin(), aggDecl->get_parameters().end() ); 193 193 output << ")" << endl; 194 output << indent; 194 195 } 195 196 … … 205 206 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 206 207 updateLocation( *i ); 208 output << indent; 207 209 (*i)->accept( *this ); 208 210 output << ";" << endl; … … 244 246 assert( obj ); 245 247 updateLocation( obj ); 246 output << mangleName( obj );248 output << indent << mangleName( obj ); 247 249 if ( obj->get_init() ) { 248 250 output << " = "; … … 332 334 void CodeGenerator::visit( __attribute__((unused)) ConstructorInit * init ){ 333 335 assertf( ! genC, "ConstructorInit nodes should not reach code generation." ); 334 // xxx - generate something reasonable for constructor/destructor pairs 335 output << "<ctorinit>"; 336 // pseudo-output for constructor/destructor pairs 337 output << "<ctorinit>{" << std::endl << ++indent << "ctor: "; 338 maybeAccept( init->get_ctor(), *this ); 339 output << ", " << std::endl << indent << "dtor: "; 340 maybeAccept( init->get_dtor(), *this ); 341 output << std::endl << --indent << "}"; 336 342 } 337 343 … … 347 353 if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) { 348 354 std::list< Expression* >::iterator arg = applicationExpr->get_args().begin(); 349 switch ( opInfo.type ) {350 case OT_PREFIXASSIGN:351 case OT_POSTFIXASSIGN:352 case OT_INFIXASSIGN:353 case OT_CTOR:354 case OT_DTOR:355 {356 assert( arg != applicationExpr->get_args().end() );357 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {358 // remove & from first assignment/ctor argument359 *arg = addrExpr->get_arg();360 } else {361 // no address-of operator, so must be a pointer - add dereference362 // NOTE: if the assertion starts to trigger, check that the application expr isn't being shared.363 // Since its arguments are modified here, this assertion most commonly triggers when the application364 // is visited multiple times.365 UntypedExpr * newExpr = new UntypedExpr( new NameExpr( "*?" ) );366 newExpr->get_args().push_back( *arg );367 Type * type = InitTweak::getPointerBase( (*arg)->get_result() );368 assertf( type, "First argument to a derefence must be a pointer. Ensure that expressions are not being shared." );369 newExpr->set_result( type->clone() );370 *arg = newExpr;371 } // if372 break;373 }374 375 default:376 // do nothing377 ;378 } // switch379 380 355 switch ( opInfo.type ) { 381 356 case OT_INDEX: … … 584 559 if ( castExpr->get_result()->isVoid() ) { 585 560 output << "(void)" ; 586 } else if ( ! castExpr->get_result()->get_lvalue() ) { 587 // at least one result type of cast, but not an lvalue 561 } else { 562 // at least one result type of cast. 563 // Note: previously, lvalue casts were skipped. Since it's now impossible for the user to write 564 // an lvalue cast, this has been taken out. 588 565 output << "("; 589 566 output << genType( castExpr->get_result(), "", pretty, genC ); 590 567 output << ")"; 591 } else {592 // otherwise, the cast is to an lvalue type, so the cast should be dropped, since the result of a cast is593 // never an lvalue in C594 568 } // if 595 569 castExpr->get_arg()->accept( *this ); … … 706 680 extension( commaExpr ); 707 681 output << "("; 682 if ( genC ) { 683 // arg1 of a CommaExpr is never used, so it can be safely cast to void to reduce gcc warnings. 684 commaExpr->set_arg1( new CastExpr( commaExpr->get_arg1() ) ); 685 } 708 686 commaExpr->get_arg1()->accept( *this ); 709 687 output << " , "; 710 688 commaExpr->get_arg2()->accept( *this ); 711 689 output << ")"; 690 } 691 692 void CodeGenerator::visit( TupleAssignExpr * tupleExpr ) { 693 assertf( ! genC, "TupleAssignExpr should not reach code generation." ); 694 tupleExpr->stmtExpr->accept( *this ); 712 695 } 713 696 … … 759 742 output << "(" << genType( compLitExpr->get_result(), "", pretty, genC ) << ")"; 760 743 compLitExpr->get_initializer()->accept( *this ); 744 } 745 746 void CodeGenerator::visit( UniqueExpr * unqExpr ) { 747 assertf( ! genC, "Unique expressions should not reach code generation." ); 748 output << "unq<" << unqExpr->get_id() << ">{ "; 749 unqExpr->get_expr()->accept( *this ); 750 output << " }"; 761 751 } 762 752 … … 770 760 for ( Statement * stmt : stmts ) { 771 761 updateLocation( stmt ); 772 output << printLabels( stmt->get_labels() );762 output << printLabels( stmt->get_labels() ); 773 763 if ( i+1 == numStmts ) { 774 764 // last statement in a statement expression needs to be handled specially - … … 815 805 void CodeGenerator::visit( ExprStmt * exprStmt ) { 816 806 assert( exprStmt ); 817 Expression * expr = exprStmt->get_expr();818 807 if ( genC ) { 819 808 // cast the top-level expression to void to reduce gcc warnings. 820 expr = new CastExpr( expr);821 } 822 expr ->accept( *this );809 exprStmt->set_expr( new CastExpr( exprStmt->get_expr() ) ); 810 } 811 exprStmt->get_expr()->accept( *this ); 823 812 output << ";"; 824 813 } -
src/CodeGen/CodeGenerator.h
raf08051 r28e58fd 74 74 virtual void visit( CommaExpr *commaExpr ); 75 75 virtual void visit( CompoundLiteralExpr *compLitExpr ); 76 virtual void visit( UniqueExpr * ); 77 virtual void visit( TupleAssignExpr * tupleExpr ); 76 78 virtual void visit( UntypedTupleExpr *tupleExpr ); 77 79 virtual void visit( TupleExpr *tupleExpr ); -
src/CodeGen/GenType.cc
raf08051 r28e58fd 37 37 virtual void visit( PointerType *pointerType ); 38 38 virtual void visit( ArrayType *arrayType ); 39 virtual void visit( ReferenceType *refType ); 39 40 virtual void visit( StructInstType *structInst ); 40 41 virtual void visit( UnionInstType *unionInst ); … … 145 146 void GenType::visit( ArrayType *arrayType ) { 146 147 genArray( arrayType->get_qualifiers(), arrayType->get_base(), arrayType->get_dimension(), arrayType->get_isVarLen(), arrayType->get_isStatic() ); 148 } 149 150 void GenType::visit( ReferenceType *refType ) { 151 assert( refType->get_base() != 0); 152 assertf( ! genC, "Reference types should not reach code generation." ); 153 handleQualifiers( refType ); 154 typeString = "&" + typeString; 155 refType->get_base()->accept( *this ); 147 156 } 148 157 … … 278 287 typeString = "_Atomic " + typeString; 279 288 } // if 289 if ( type->get_lvalue() && ! genC ) { 290 // when not generating C code, print lvalue for debugging. 291 typeString = "lvalue " + typeString; 292 } 280 293 } 281 294 } // namespace CodeGen -
src/CodeGen/OperatorTable.cc
raf08051 r28e58fd 14 14 // 15 15 16 #include <map> // for map, _Rb_tree_const_iterator, map<>::const_iterator 17 #include <utility> // for pair 16 #include <algorithm> // for any_of 17 #include <map> // for map, _Rb_tree_const_iterator, map<>::const_iterator 18 #include <utility> // for pair 18 19 19 20 #include "OperatorTable.h" … … 93 94 } // if 94 95 } 96 97 /// determines if a given function name is one of the operator types between [begin, end) 98 template<typename Iterator> 99 bool isOperatorType( const std::string & funcName, Iterator begin, Iterator end ) { 100 OperatorInfo info; 101 if ( operatorLookup( funcName, info ) ) { 102 return std::find( begin, end, info.type ) != end; 103 } 104 return false; 105 } 106 107 bool isConstructor( const std::string & funcName ) { 108 static OperatorType types[] = { OT_CTOR }; 109 return isOperatorType( funcName, std::begin(types), std::end(types) ); 110 } 111 112 bool isDestructor( const std::string & funcName ) { 113 static OperatorType types[] = { OT_DTOR }; 114 return isOperatorType( funcName, std::begin(types), std::end(types) ); 115 } 116 117 bool isAssignment( const std::string & funcName ) { 118 static OperatorType types[] = { OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN }; 119 return isOperatorType( funcName, std::begin(types), std::end(types) ); 120 } 121 122 bool isCtorDtor( const std::string & funcName ) { 123 static OperatorType types[] = { OT_CTOR, OT_DTOR }; 124 return isOperatorType( funcName, std::begin(types), std::end(types) ); 125 } 126 127 bool isCtorDtorAssign( const std::string & funcName ) { 128 static OperatorType types[] = { OT_CTOR, OT_DTOR, OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN }; 129 return isOperatorType( funcName, std::begin(types), std::end(types) ); 130 } 95 131 } // namespace CodeGen 96 132 -
src/CodeGen/OperatorTable.h
raf08051 r28e58fd 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // OperatorTable.h -- 7 // OperatorTable.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 42 42 43 43 bool operatorLookup( std::string funcName, OperatorInfo &info ); 44 45 bool isConstructor( const std::string & ); 46 bool isDestructor( const std::string & ); 47 bool isAssignment( const std::string & ); 48 bool isCtorDtor( const std::string & ); 49 bool isCtorDtorAssign( const std::string & ); 44 50 } // namespace CodeGen 45 51
Note:
See TracChangeset
for help on using the changeset viewer.