Changeset 1cdfa82 for src/CodeGen
- Timestamp:
- Apr 25, 2018, 4:55:53 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- 42107b4
- Parents:
- 2efe4b8 (diff), 9d5fb67 (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:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r2efe4b8 r1cdfa82 116 116 } 117 117 118 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( CodeGenerator::tabsize ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ), endl( *this ) {}118 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks, bool printExprTypes ) : indent( CodeGenerator::tabsize ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ), printExprTypes( printExprTypes ), endl( *this ) {} 119 119 120 120 string CodeGenerator::mangleName( DeclarationWithType * decl ) { … … 159 159 } 160 160 161 // *** Expression 162 void CodeGenerator::previsit( Expression * node ) { 163 previsit( (BaseSyntaxNode *)node ); 164 GuardAction( [this, node](){ 165 if ( printExprTypes ) { 166 output << " /* " << genType( node->result, "", pretty, genC ) << " */ "; 167 } 168 } ); 169 } 170 161 171 // *** Declarations 162 172 void CodeGenerator::postvisit( FunctionDecl * functionDecl ) { … … 203 213 204 214 void CodeGenerator::handleAggregate( AggregateDecl * aggDecl, const std::string & kind ) { 205 genAttributes( aggDecl->get_attributes() );206 207 215 if( ! aggDecl->get_parameters().empty() && ! genC ) { 208 216 // assertf( ! genC, "Aggregate type parameters should not reach code generation." ); … … 213 221 } 214 222 215 output << kind << aggDecl->get_name(); 223 output << kind; 224 genAttributes( aggDecl->get_attributes() ); 225 output << aggDecl->get_name(); 216 226 217 227 if ( aggDecl->has_body() ) { … … 298 308 output << " }"; 299 309 } 310 } 311 312 void CodeGenerator::postvisit( StaticAssertDecl * assertDecl ) { 313 output << "_Static_assert("; 314 assertDecl->condition->accept( *visitor ); 315 output << ", "; 316 assertDecl->message->accept( *visitor ); 317 output << ")"; 300 318 } 301 319 … … 578 596 output << ")"; 579 597 } // if 580 castExpr->get_arg()->accept( *visitor ); 598 castExpr->arg->accept( *visitor ); 599 output << ")"; 600 } 601 602 void CodeGenerator::postvisit( KeywordCastExpr * castExpr ) { 603 assertf( ! genC, "KeywordCast should not reach code generation." ); 604 extension( castExpr ); 605 output << "((" << castExpr->targetString() << " &)"; 606 castExpr->arg->accept( *visitor ); 581 607 output << ")"; 582 608 } … … 928 954 output << "continue"; 929 955 break; 956 case BranchStmt::FallThrough: 957 case BranchStmt::FallThroughDefault: 958 assertf( ! genC, "fallthru should not reach code generation." ); 959 output << "fallthru"; 960 break; 930 961 } // switch 962 // print branch target for labelled break/continue/fallthru in debug mode 963 if ( ! genC && branchStmt->get_type() != BranchStmt::Goto ) { 964 if ( ! branchStmt->get_target().empty() ) { 965 output << " " << branchStmt->get_target(); 966 } else if ( branchStmt->get_type() == BranchStmt::FallThrough ) { 967 output << " default"; 968 } 969 } 931 970 output << ";"; 932 971 } -
src/CodeGen/CodeGenerator.h
r2efe4b8 r1cdfa82 27 27 28 28 namespace CodeGen { 29 struct CodeGenerator : public WithShortCircuiting, public With VisitorRef<CodeGenerator> {29 struct CodeGenerator : public WithShortCircuiting, public WithGuards, public WithVisitorRef<CodeGenerator> { 30 30 static int tabsize; 31 31 32 CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false );32 CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false, bool printExprTypes = false ); 33 33 34 34 //*** Turn off visit_children for all nodes … … 38 38 void postvisit( BaseSyntaxNode * ); 39 39 40 //*** print type for all expressions 41 void previsit( Expression * node ); 42 40 43 //*** Declaration 41 44 void postvisit( StructDecl * ); 42 45 void postvisit( FunctionDecl * ); 43 46 void postvisit( ObjectDecl * ); 44 void postvisit( UnionDecl *aggregateDecl ); 45 void postvisit( EnumDecl *aggregateDecl ); 46 void postvisit( TraitDecl *aggregateDecl ); 47 void postvisit( TypedefDecl *typeDecl ); 48 void postvisit( TypeDecl *typeDecl ); 47 void postvisit( UnionDecl * aggregateDecl ); 48 void postvisit( EnumDecl * aggregateDecl ); 49 void postvisit( TraitDecl * aggregateDecl ); 50 void postvisit( TypedefDecl * typeDecl ); 51 void postvisit( TypeDecl * typeDecl ); 52 void postvisit( StaticAssertDecl * assertDecl ); 49 53 50 54 //*** Initializer … … 65 69 void postvisit( LabelAddressExpr *addressExpr ); 66 70 void postvisit( CastExpr *castExpr ); 71 void postvisit( KeywordCastExpr * castExpr ); 67 72 void postvisit( VirtualCastExpr *castExpr ); 68 73 void postvisit( UntypedMemberExpr *memberExpr ); … … 139 144 bool genC = false; // true if output has to be C code 140 145 bool lineMarks = false; 146 bool printExprTypes = false; 141 147 public: 142 148 LineEnder endl; -
src/CodeGen/GenType.cc
r2efe4b8 r1cdfa82 48 48 void postvisit( ZeroType * zeroType ); 49 49 void postvisit( OneType * oneType ); 50 void postvisit( TraitInstType * inst ); 51 void postvisit( TypeofType * typeof ); 50 52 51 53 private: … … 289 291 } 290 292 293 void GenType::postvisit( TraitInstType * inst ) { 294 assertf( ! genC, "Trait types should not reach code generation." ); 295 typeString = inst->name + " " + typeString; 296 handleQualifiers( inst ); 297 } 298 299 void GenType::postvisit( TypeofType * typeof ) { 300 std::ostringstream os; 301 PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks ); 302 os << "typeof("; 303 typeof->expr->accept( cg ); 304 os << ") " << typeString; 305 typeString = os.str(); 306 handleQualifiers( typeof ); 307 } 308 291 309 void GenType::handleQualifiers( Type * type ) { 292 310 if ( type->get_const() ) { -
src/CodeGen/Generate.cc
r2efe4b8 r1cdfa82 46 46 } // namespace 47 47 48 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC, bool lineMarks ) {48 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC, bool lineMarks, bool printExprTypes ) { 49 49 cleanTree( translationUnit ); 50 50 51 PassVisitor<CodeGenerator> cgv( os, pretty, generateC, lineMarks );51 PassVisitor<CodeGenerator> cgv( os, pretty, generateC, lineMarks, printExprTypes ); 52 52 for ( auto & dcl : translationUnit ) { 53 53 if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) { … … 66 66 os << CodeGen::genPrettyType( type, "" ); 67 67 } else { 68 PassVisitor<CodeGenerator> cgv( os, true, false, false );68 PassVisitor<CodeGenerator> cgv( os, true, false, false, false ); 69 69 node->accept( cgv ); 70 70 } -
src/CodeGen/Generate.h
r2efe4b8 r1cdfa82 24 24 namespace CodeGen { 25 25 /// Generates code. doIntrinsics determines if intrinsic functions are printed, pretty formats output nicely (e.g., uses unmangled names, etc.), generateC is true when the output must consist only of C code (allows some assertions, etc.) 26 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC = false , bool lineMarks = false );26 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC = false , bool lineMarks = false, bool printTypeExpr = false ); 27 27 28 28 /// Generate code for a single node -- helpful for debugging in gdb -
src/CodeGen/OperatorTable.cc
r2efe4b8 r1cdfa82 79 79 } // namespace 80 80 81 bool operatorLookup( std::string funcName, OperatorInfo &info ) {81 bool operatorLookup( const std::string & funcName, OperatorInfo & info ) { 82 82 static bool init = false; 83 83 if ( ! init ) { … … 100 100 return true; 101 101 } // if 102 } 103 104 bool isOperator( const std::string & funcName ) { 105 OperatorInfo info; 106 return operatorLookup( funcName, info ); 102 107 } 103 108 -
src/CodeGen/OperatorTable.h
r2efe4b8 r1cdfa82 41 41 }; 42 42 43 bool operatorLookup( std::string funcName, OperatorInfo &info ); 43 bool isOperator( const std::string & funcName ); 44 bool operatorLookup( const std::string & funcName, OperatorInfo & info ); 44 45 45 46 bool isConstructor( const std::string & );
Note: See TracChangeset
for help on using the changeset viewer.