Changeset c850687 for src/CodeGen
- Timestamp:
- May 11, 2017, 11:07:58 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:
- 8514fe19
- Parents:
- 29cf9c8
- Location:
- src/CodeGen
- Files:
-
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r29cf9c8 rc850687 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 16:50:00 201712 // Last Modified On : Wed May 10 14:45:00 2017 13 13 // Update Count : 484 14 14 // … … 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 ) … … 143 152 // *** Declarations 144 153 void CodeGenerator::visit( FunctionDecl * functionDecl ) { 145 output << lineDirective( functionDecl );146 147 154 extension( functionDecl ); 148 155 genAttributes( functionDecl->get_attributes() ); … … 168 175 } 169 176 170 output << lineDirective( objectDecl );171 172 177 extension( objectDecl ); 173 178 genAttributes( objectDecl->get_attributes() ); … … 221 226 222 227 void CodeGenerator::visit( StructDecl * structDecl ) { 223 output << lineDirective( structDecl );224 225 228 extension( structDecl ); 226 229 handleAggregate( structDecl, "struct " ); … … 228 231 229 232 void CodeGenerator::visit( UnionDecl * unionDecl ) { 230 output << lineDirective( unionDecl );231 232 233 extension( unionDecl ); 233 234 handleAggregate( unionDecl, "union " ); -
src/CodeGen/CodeGenerator.h
r29cf9c8 rc850687 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 ); … … 110 112 }; 111 113 114 struct LineMarker { 115 CodeLocation const & loc; 116 bool toPrint; 117 118 LineMarker(CodeLocation const & loc, bool toPrint); 119 }; 120 121 LineMarker lineDirective(BaseSyntaxNode const * node); 122 112 123 void asmName( DeclarationWithType *decl ); 113 124 … … 122 133 bool pretty = false; // pretty print 123 134 bool genC = false; // true if output has to be C code 135 bool lineMarks = false; 124 136 125 137 void printDesignators( std::list< Expression * > & ); … … 149 161 /// returns C-compatible name of declaration 150 162 std::string genName( DeclarationWithType * decl ); 163 164 std::ostream & operator<<(std::ostream &, 165 CodeGenerator::LineMarker const &); 151 166 } // namespace CodeGen 152 167 -
src/CodeGen/GenType.cc
r29cf9c8 rc850687 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
r29cf9c8 rc850687 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
r29cf9c8 rc850687 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
r29cf9c8 rc850687 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.