Changeset c8c03683 for src/CodeGen
- Timestamp:
- Jun 14, 2016, 12:53:26 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:
- 7ff30d07
- Parents:
- e04ef3a (diff), d14d96a (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:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
re04ef3a rc8c03683 26 26 #include "SynTree/Statement.h" 27 27 #include "SynTree/Type.h" 28 #include "SynTree/Attribute.h" 28 29 29 30 #include "Common/utility.h" … … 33 34 #include "OperatorTable.h" 34 35 #include "GenType.h" 36 37 #include "InitTweak/InitTweak.h" 35 38 36 39 using namespace std; … … 74 77 } 75 78 79 void CodeGenerator::genAttributes( std::list< Attribute * > & attributes ) { 80 if ( ! attributes.empty() ) { 81 output << "__attribute__ (("; 82 for ( Attribute *& attr : attributes ) { 83 if ( ! attr->empty() ) { 84 output << attr->get_name() << "("; 85 genCommaList( attr->get_parameters().begin(), attr->get_parameters().end() ); 86 output << ")"; 87 } 88 output << ","; 89 } 90 output << ")) "; 91 } 92 } 93 94 76 95 //*** Declarations 77 96 void CodeGenerator::visit( FunctionDecl *functionDecl ) { 78 // generalize this 79 FunctionDecl::Attribute attr = functionDecl->get_attribute(); 80 switch ( attr.type ) { 81 case FunctionDecl::Attribute::Constructor: 82 output << "__attribute__ ((constructor"; 83 if ( attr.priority != FunctionDecl::Attribute::Default ) { 84 output << "(" << attr.priority << ")"; 85 } 86 output << ")) "; 87 break; 88 case FunctionDecl::Attribute::Destructor: 89 output << "__attribute__ ((destructor"; 90 if ( attr.priority != FunctionDecl::Attribute::Default ) { 91 output << "(" << attr.priority << ")"; 92 } 93 output << ")) "; 94 break; 95 default: 96 break; 97 } 97 genAttributes( functionDecl->get_attributes() ); 98 98 99 handleStorageClass( functionDecl ); 99 100 if ( functionDecl->get_isInline() ) { … … 270 271 UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) ); 271 272 newExpr->get_args().push_back( *arg ); 273 assert( (*arg)->get_results().size() == 1 ); 274 Type * type = InitTweak::getPointerBase( (*arg)->get_results().front() ); 275 assert( type ); 276 newExpr->get_results().push_back( type ); 272 277 *arg = newExpr; 273 278 } // if … … 298 303 if ( applicationExpr->get_args().size() == 1 ) { 299 304 // the expression fed into a single parameter constructor or destructor 300 // may contain side effects - output as a voidexpression301 output << "( (void)(";305 // may contain side effects, so must still output this expression 306 output << "("; 302 307 (*arg++)->accept( *this ); 303 output << ") )/* " << opInfo.inputName << " */";308 output << ") /* " << opInfo.inputName << " */"; 304 309 } else if ( applicationExpr->get_args().size() == 2 ) { 305 310 // intrinsic two parameter constructors are essentially bitwise assignment … … 384 389 if ( untypedExpr->get_args().size() == 1 ) { 385 390 // the expression fed into a single parameter constructor or destructor 386 // may contain side effects - output as a voidexpression387 output << "( (void)(";391 // may contain side effects, so must still output this expression 392 output << "("; 388 393 (*arg++)->accept( *this ); 389 output << ") )/* " << opInfo.inputName << " */";394 output << ") /* " << opInfo.inputName << " */"; 390 395 } else if ( untypedExpr->get_args().size() == 2 ) { 391 396 // intrinsic two parameter constructors are essentially bitwise assignment … … 626 631 627 632 void CodeGenerator::visit( ExprStmt *exprStmt ) { 628 // I don't see why this check is necessary.629 // If this starts to cause problems then put it back in,630 // with an explanation631 633 assert( exprStmt ); 632 633 // if ( exprStmt != 0 ) { 634 exprStmt->get_expr()->accept( *this ); 635 output << ";" ; 636 // } // if 634 // cast the top-level expression to void to reduce gcc warnings. 635 Expression * expr = new CastExpr( exprStmt->get_expr() ); 636 expr->accept( *this ); 637 output << ";"; 637 638 } 638 639 … … 743 744 744 745 void CodeGenerator::visit( WhileStmt *whileStmt ) { 745 if ( whileStmt->get_isDoWhile() ) 746 if ( whileStmt->get_isDoWhile() ) { 746 747 output << "do" ; 747 else {748 } else { 748 749 output << "while (" ; 749 750 whileStmt->get_condition()->accept( *this ); … … 769 770 output << "for (;"; 770 771 771 if ( forStmt->get_condition() != 0 ) 772 if ( forStmt->get_condition() != 0 ) { 772 773 forStmt->get_condition()->accept( *this ); 774 } 773 775 output << ";"; 774 776 775 if ( forStmt->get_increment() != 0 ) 776 forStmt->get_increment()->accept( *this ); 777 if ( forStmt->get_increment() != 0 ) { 778 // cast the top-level expression to void to reduce gcc warnings. 779 Expression * expr = new CastExpr( forStmt->get_increment() ); 780 expr->accept( *this ); 781 } 777 782 output << ") "; 778 783 -
src/CodeGen/CodeGenerator.h
re04ef3a rc8c03683 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // CodeGenerator.h -- 7 // CodeGenerator.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 60 60 virtual void visit( MemberExpr *memberExpr ); 61 61 virtual void visit( VariableExpr *variableExpr ); 62 virtual void visit( ConstantExpr *constantExpr ); 62 virtual void visit( ConstantExpr *constantExpr ); 63 63 virtual void visit( SizeofExpr *sizeofExpr ); 64 64 virtual void visit( AlignofExpr *alignofExpr ); … … 85 85 virtual void visit( ForStmt * ); 86 86 virtual void visit( NullStmt * ); 87 virtual void visit( DeclStmt * ); 87 virtual void visit( DeclStmt * ); 88 89 void genAttributes( std::list< Attribute * > & attributes ); 88 90 89 91 template< class Iterator > void genCommaList( Iterator begin, Iterator end ); … … 114 116 115 117 }; 116 118 117 119 template< class Iterator > 118 120 void CodeGenerator::genCommaList( Iterator begin, Iterator end ) { … … 125 127 } // for 126 128 } 127 129 128 130 inline bool doSemicolon( Declaration* decl ) { 129 131 if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) {
Note: See TracChangeset
for help on using the changeset viewer.