Changeset e6d39fe for src/CodeGen
- Timestamp:
- Apr 20, 2018, 9:04:41 AM (7 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, with_gc
- Children:
- 22bdc34
- Parents:
- 9181f1d (diff), 88f15ae (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
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r9181f1d re6d39fe 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 ) { … … 157 157 node->print( ss ); 158 158 assertf( false, "Unhandled node reached in CodeGenerator: %s", ss.str().c_str() ); 159 } 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 } ); 159 169 } 160 170 … … 586 596 output << ")"; 587 597 } // if 588 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 ); 589 607 output << ")"; 590 608 } -
src/CodeGen/CodeGenerator.h
r9181f1d re6d39fe 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 … … 37 37 //*** Error for unhandled node types 38 38 void postvisit( BaseSyntaxNode * ); 39 40 //*** print type for all expressions 41 void previsit( Expression * node ); 39 42 40 43 //*** Declaration … … 66 69 void postvisit( LabelAddressExpr *addressExpr ); 67 70 void postvisit( CastExpr *castExpr ); 71 void postvisit( KeywordCastExpr * castExpr ); 68 72 void postvisit( VirtualCastExpr *castExpr ); 69 73 void postvisit( UntypedMemberExpr *memberExpr ); … … 140 144 bool genC = false; // true if output has to be C code 141 145 bool lineMarks = false; 146 bool printExprTypes = false; 142 147 public: 143 148 LineEnder endl; -
src/CodeGen/GenType.cc
r9181f1d re6d39fe 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
r9181f1d re6d39fe 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
r9181f1d re6d39fe 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
Note:
See TracChangeset
for help on using the changeset viewer.