Changeset 1ed33fed for src/CodeGen
- Timestamp:
- May 11, 2017, 2:49:34 PM (9 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:
- 3476a0d
- Parents:
- 6ac2ada (diff), 6a4f3d4 (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 deleted
- 6 edited
-
CodeGenerator.cc (modified) (6 diffs)
-
CodeGenerator.h (modified) (7 diffs)
-
GenType.cc (modified) (8 diffs)
-
GenType.h (modified) (1 diff)
-
Generate.cc (modified) (3 diffs)
-
Generate.h (modified) (1 diff)
-
LineStream.cc (deleted)
-
LineStream.h (deleted)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r6ac2ada r1ed33fed 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus May 9 14:32:00 201713 // Update Count : 48 312 // Last Modified On : Wed May 10 14:45:00 2017 13 // Update Count : 484 14 14 // 15 15 … … 41 41 namespace CodeGen { 42 42 int CodeGenerator::tabsize = 4; 43 44 // Pseudo Function: output << lineDirective(*currentNode);45 struct lineDirective {46 CodeLocation const & loc;47 lineDirective(CodeLocation const & location) : loc(location) {}48 lineDirective(BaseSyntaxNode const * node) : loc(node->location) {}49 };50 std::ostream & operator<<(std::ostream & out, lineDirective const & ld) {51 if (ld.loc.isSet())52 return out << "\n# " << ld.loc.linenumber << " \""53 << ld.loc.filename << "\"\n";54 return out << "\n// Unset Location\n";55 }56 43 57 44 // the kinds of statements that would ideally be followed by whitespace … … 102 89 } 103 90 104 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ) {} 91 CodeGenerator::LineMarker::LineMarker( 92 CodeLocation const & loc, bool toPrint) : 93 loc(loc), toPrint(toPrint) 94 {} 95 96 CodeGenerator::LineMarker CodeGenerator::lineDirective( 97 BaseSyntaxNode const * node) { 98 return LineMarker(node->location, lineMarks); 99 } 100 101 std::ostream & operator<<(std::ostream & out, 102 CodeGenerator::LineMarker const & marker) { 103 if (marker.toPrint && marker.loc.isSet()) { 104 return out << "\n# " << marker.loc.linenumber << " \"" 105 << marker.loc.filename << "\"\n"; 106 } else if (marker.toPrint) { 107 return out << "\n/* Missing CodeLocation */\n"; 108 } else { 109 return out; 110 } 111 } 112 113 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {} 105 114 106 115 CodeGenerator::CodeGenerator( std::ostream & os, std::string init, int indentation, bool infunp ) … … 195 204 } 196 205 197 output << lineDirective( aggDecl ) <<kind;206 output << kind; 198 207 if ( aggDecl->get_name() != "" ) 199 208 output << aggDecl->get_name(); … … 700 709 void CodeGenerator::visit( UntypedTupleExpr * tupleExpr ) { 701 710 assertf( ! genC, "UntypedTupleExpr should not reach code generation." ); 711 extension( tupleExpr ); 702 712 output << "["; 703 713 genCommaList( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end() ); … … 707 717 void CodeGenerator::visit( TupleExpr * tupleExpr ) { 708 718 assertf( ! genC, "TupleExpr should not reach code generation." ); 719 extension( tupleExpr ); 709 720 output << "["; 710 721 genCommaList( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end() ); 711 722 output << "]"; 723 } 724 725 void CodeGenerator::visit( TupleIndexExpr * tupleExpr ) { 726 assertf( ! genC, "TupleIndexExpr should not reach code generation." ); 727 extension( tupleExpr ); 728 tupleExpr->get_tuple()->accept( *this ); 729 output << "." << tupleExpr->get_index(); 712 730 } 713 731 -
src/CodeGen/CodeGenerator.h
r6ac2ada r1ed33fed 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Ma r 1 16:20:04201713 // Update Count : 5 011 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 10 10:57:00 2017 13 // Update Count : 51 14 14 // 15 15 … … 25 25 #include "SymTab/Indexer.h" 26 26 27 #include "Common/utility.h" 28 27 29 namespace CodeGen { 28 30 class CodeGenerator : public Visitor { … … 30 32 static int tabsize; 31 33 32 CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false );34 CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false ); 33 35 CodeGenerator( std::ostream &os, std::string, int indent = 0, bool infun = false ); 34 36 CodeGenerator( std::ostream &os, char *, int indent = 0, bool infun = false ); … … 74 76 virtual void visit( UntypedTupleExpr *tupleExpr ); 75 77 virtual void visit( TupleExpr *tupleExpr ); 78 virtual void visit( TupleIndexExpr * tupleExpr ); 76 79 virtual void visit( TypeExpr *typeExpr ); 77 80 virtual void visit( AsmExpr * ); … … 110 113 }; 111 114 115 struct LineMarker { 116 CodeLocation const & loc; 117 bool toPrint; 118 119 LineMarker(CodeLocation const & loc, bool toPrint); 120 }; 121 122 LineMarker lineDirective(BaseSyntaxNode const * node); 123 112 124 void asmName( DeclarationWithType *decl ); 113 125 … … 122 134 bool pretty = false; // pretty print 123 135 bool genC = false; // true if output has to be C code 136 bool lineMarks = false; 124 137 125 138 void printDesignators( std::list< Expression * > & ); … … 149 162 /// returns C-compatible name of declaration 150 163 std::string genName( DeclarationWithType * decl ); 164 165 std::ostream & operator<<(std::ostream &, 166 CodeGenerator::LineMarker const &); 151 167 } // namespace CodeGen 152 168 -
src/CodeGen/GenType.cc
r6ac2ada r1ed33fed 28 28 class GenType : public Visitor { 29 29 public: 30 GenType( const std::string &typeString, bool pretty = false, bool genC = false );30 GenType( const std::string &typeString, bool pretty = false, bool genC = false, bool lineMarks = false ); 31 31 std::string get_typeString() const { return typeString; } 32 32 void set_typeString( const std::string &newValue ) { typeString = newValue; } … … 54 54 bool pretty = false; // pretty print 55 55 bool genC = false; // generating C code? 56 bool lineMarks = false; 56 57 }; 57 58 58 std::string genType( Type *type, const std::string &baseString, bool pretty, bool genC ) {59 GenType gt( baseString, pretty, genC );59 std::string genType( Type *type, const std::string &baseString, bool pretty, bool genC , bool lineMarks ) { 60 GenType gt( baseString, pretty, genC, lineMarks ); 60 61 std::ostringstream os; 61 62 62 63 if ( ! type->get_attributes().empty() ) { 63 CodeGenerator cg( os, pretty, genC );64 CodeGenerator cg( os, pretty, genC, lineMarks ); 64 65 cg.genAttributes( type->get_attributes() ); 65 66 } // if … … 73 74 } 74 75 75 GenType::GenType( const std::string &typeString, bool pretty, bool genC ) : typeString( typeString ), pretty( pretty ), genC( genC) {}76 GenType::GenType( const std::string &typeString, bool pretty, bool genC, bool lineMarks ) : typeString( typeString ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {} 76 77 77 78 void GenType::visit( VoidType *voidType ) { … … 114 115 } // if 115 116 if ( dimension != 0 ) { 116 CodeGenerator cg( os, pretty, genC );117 CodeGenerator cg( os, pretty, genC, lineMarks ); 117 118 dimension->accept( cg ); 118 119 } else if ( isVarLen ) { … … 168 169 } // if 169 170 } else { 170 CodeGenerator cg( os, pretty, genC );171 CodeGenerator cg( os, pretty, genC, lineMarks ); 171 172 os << "(" ; 172 173 … … 191 192 // assertf( ! genC, "Aggregate type parameters should not reach code generation." ); 192 193 std::ostringstream os; 193 CodeGenerator cg( os, pretty, genC );194 CodeGenerator cg( os, pretty, genC, lineMarks ); 194 195 os << "forall("; 195 196 cg.genCommaList( funcType->get_forall().begin(), funcType->get_forall().end() ); … … 202 203 if ( ! refType->get_parameters().empty() ) { 203 204 std::ostringstream os; 204 CodeGenerator cg( os, pretty, genC );205 CodeGenerator cg( os, pretty, genC, lineMarks ); 205 206 os << "("; 206 207 cg.genCommaList( refType->get_parameters().begin(), refType->get_parameters().end() ); … … 242 243 for ( Type * t : *tupleType ) { 243 244 i++; 244 os << genType( t, "", pretty, genC ) << (i == tupleType->size() ? "" : ", ");245 os << genType( t, "", pretty, genC, lineMarks ) << (i == tupleType->size() ? "" : ", "); 245 246 } 246 247 os << "]"; -
src/CodeGen/GenType.h
r6ac2ada r1ed33fed 21 21 22 22 namespace CodeGen { 23 std::string genType( Type *type, const std::string &baseString, bool pretty = false, bool genC = false );23 std::string genType( Type *type, const std::string &baseString, bool pretty = false, bool genC = false, bool lineMarks = false ); 24 24 std::string genPrettyType( Type * type, const std::string & baseString ); 25 25 } // namespace CodeGen -
src/CodeGen/Generate.cc
r6ac2ada r1ed33fed 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Jun 4 14:04:25 201513 // Update Count : 511 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 19 13:05:00 2017 13 // Update Count : 6 14 14 // 15 15 … … 31 31 32 32 namespace CodeGen { 33 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC ) {34 CodeGen::CodeGenerator cgv( os, pretty, generateC );33 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC, bool lineMarks ) { 34 CodeGen::CodeGenerator cgv( os, pretty, generateC, lineMarks ); 35 35 for ( auto & dcl : translationUnit ) { 36 36 if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) { 37 os << cgv.lineDirective(dcl); 37 38 dcl->accept(cgv); 38 39 if ( doSemicolon( dcl ) ) { … … 48 49 os << CodeGen::genPrettyType( type, "" ); 49 50 } else { 50 CodeGen::CodeGenerator cgv( os, true, false );51 CodeGen::CodeGenerator cgv( os, true, false, false ); 51 52 node->accept( cgv ); 52 53 } -
src/CodeGen/Generate.h
r6ac2ada r1ed33fed 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 );26 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC = false , bool lineMarks = 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.