Changeset 35b1bf4 for src/CodeGen
- Timestamp:
- Feb 8, 2017, 9:09:39 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:
- 52c14b3
- Parents:
- fe26fbf
- Location:
- src/CodeGen
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/CodeGen/CodeGenerator.cc ¶
rfe26fbf r35b1bf4 89 89 } 90 90 91 CodeGenerator::CodeGenerator( std::ostream & os, bool mangle ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), mangle( mangle) {}91 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ) {} 92 92 93 93 CodeGenerator::CodeGenerator( std::ostream & os, std::string init, int indentation, bool infunp ) … … 102 102 103 103 string CodeGenerator::mangleName( DeclarationWithType * decl ) { 104 if ( ! mangle) return decl->get_name();104 if ( pretty ) return decl->get_name(); 105 105 if ( decl->get_mangleName() != "" ) { 106 106 // need to incorporate scope level in order to differentiate names for destructors … … 140 140 output << "_Noreturn "; 141 141 } // if 142 output << genType( functionDecl->get_functionType(), mangleName( functionDecl ) );142 output << genType( functionDecl->get_functionType(), mangleName( functionDecl ), pretty ); 143 143 144 144 // how to get this to the Functype? … … 161 161 162 162 handleStorageClass( objectDecl ); 163 output << genType( objectDecl->get_type(), mangleName( objectDecl ) );163 output << genType( objectDecl->get_type(), mangleName( objectDecl ), pretty ); 164 164 165 165 asmName( objectDecl ); … … 178 178 void CodeGenerator::handleAggregate( AggregateDecl * aggDecl ) { 179 179 genAttributes( aggDecl->get_attributes() ); 180 180 181 181 if ( aggDecl->get_name() != "" ) 182 182 output << aggDecl->get_name(); … … 249 249 assert( false && "Typedefs are removed and substituted in earlier passes." ); 250 250 //output << "typedef "; 251 //output << genType( typeDecl->get_base(), typeDecl->get_name() );251 //output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty ); 252 252 } 253 253 … … 258 258 output << "extern unsigned long " << typeDecl->get_name(); 259 259 if ( typeDecl->get_base() ) { 260 output << " = sizeof( " << genType( typeDecl->get_base(), "" ) << " )";260 output << " = sizeof( " << genType( typeDecl->get_base(), "", pretty ) << " )"; 261 261 } // if 262 262 } … … 552 552 // at least one result type of cast, but not an lvalue 553 553 output << "("; 554 output << genType( castExpr->get_result(), "" );554 output << genType( castExpr->get_result(), "", pretty ); 555 555 output << ")"; 556 556 } else { … … 592 592 output << "sizeof("; 593 593 if ( sizeofExpr->get_isType() ) { 594 output << genType( sizeofExpr->get_type(), "" );594 output << genType( sizeofExpr->get_type(), "", pretty ); 595 595 } else { 596 596 sizeofExpr->get_expr()->accept( *this ); … … 604 604 output << "__alignof__("; 605 605 if ( alignofExpr->get_isType() ) { 606 output << genType( alignofExpr->get_type(), "" );606 output << genType( alignofExpr->get_type(), "", pretty ); 607 607 } else { 608 608 alignofExpr->get_expr()->accept( *this ); … … 618 618 // use GCC builtin 619 619 output << "__builtin_offsetof("; 620 output << genType( offsetofExpr->get_type(), "" );620 output << genType( offsetofExpr->get_type(), "", pretty ); 621 621 output << ", " << mangleName( offsetofExpr->get_member() ); 622 622 output << ")"; … … 680 680 void CodeGenerator::visit( CompoundLiteralExpr *compLitExpr ) { 681 681 assert( compLitExpr->get_type() && dynamic_cast< ListInit * > ( compLitExpr->get_initializer() ) ); 682 output << "(" << genType( compLitExpr->get_type(), "" ) << ")";682 output << "(" << genType( compLitExpr->get_type(), "", pretty ) << ")"; 683 683 compLitExpr->get_initializer()->accept( *this ); 684 684 } -
TabularUnified src/CodeGen/CodeGenerator.h ¶
rfe26fbf r35b1bf4 30 30 static int tabsize; 31 31 32 CodeGenerator( std::ostream &os, bool mangle = true );32 CodeGenerator( std::ostream &os, bool pretty = false ); 33 33 CodeGenerator( std::ostream &os, std::string, int indent = 0, bool infun = false ); 34 34 CodeGenerator( std::ostream &os, char *, int indent = 0, bool infun = false ); … … 119 119 std::ostream &output; 120 120 LabelPrinter printLabels; 121 bool mangle = true;121 bool pretty = false; // pretty print 122 122 123 123 void printDesignators( std::list< Expression * > & ); -
TabularUnified src/CodeGen/GenType.cc ¶
rfe26fbf r35b1bf4 28 28 class GenType : public Visitor { 29 29 public: 30 GenType( const std::string &typeString, bool mangle = true );30 GenType( const std::string &typeString, bool pretty = false ); 31 31 std::string get_typeString() const { return typeString; } 32 32 void set_typeString( const std::string &newValue ) { typeString = newValue; } … … 51 51 52 52 std::string typeString; 53 bool mangle = true;53 bool pretty = false; // pretty print 54 54 }; 55 55 56 std::string genType( Type *type, const std::string &baseString, bool mangle) {57 GenType gt( baseString, mangle);58 std::ostringstream os; 59 56 std::string genType( Type *type, const std::string &baseString, bool pretty ) { 57 GenType gt( baseString, pretty ); 58 std::ostringstream os; 59 60 60 if ( ! type->get_attributes().empty() ) { 61 CodeGenerator cg( os, mangle);61 CodeGenerator cg( os, pretty ); 62 62 cg.genAttributes( type->get_attributes() ); 63 63 } // if … … 67 67 } 68 68 69 GenType::GenType( const std::string &typeString, bool mangle ) : typeString( typeString ), mangle( mangle ) {} 69 std::string genPrettyType( Type * type, const std::string & baseString ) { 70 return genType( type, baseString, true ); 71 } 72 73 GenType::GenType( const std::string &typeString, bool pretty ) : typeString( typeString ), pretty( pretty ) {} 70 74 71 75 void GenType::visit( VoidType *voidType ) { … … 108 112 } // if 109 113 if ( dimension != 0 ) { 110 CodeGenerator cg( os, mangle);114 CodeGenerator cg( os, pretty ); 111 115 dimension->accept( cg ); 112 116 } else if ( isVarLen ) { … … 162 166 } // if 163 167 } else { 164 CodeGenerator cg( os, mangle);168 CodeGenerator cg( os, pretty ); 165 169 os << "(" ; 166 170 … … 203 207 204 208 void GenType::visit( TupleType * tupleType ) { 205 assertf( ! mangle, "Tuple types should not make it to Code Gen." );209 assertf( pretty, "Tuple types should not make it to Code Gen." ); 206 210 Visitor::visit( tupleType ); 211 unsigned int i = 0; 212 std::ostringstream os; 213 os << "["; 214 for ( Type * t : *tupleType ) { 215 i++; 216 os << genType( t, "", pretty ) << (i == tupleType->size() ? "" : ", "); 217 } 218 os << "]"; 219 typeString = os.str() + typeString; 207 220 } 208 221 … … 214 227 void GenType::visit( ZeroType *zeroType ) { 215 228 // ideally these wouldn't hit codegen at all, but should be safe to make them ints 216 typeString = "long int "+ typeString;229 typeString = (pretty ? "zero_t " : "long int ") + typeString; 217 230 handleQualifiers( zeroType ); 218 231 } … … 220 233 void GenType::visit( OneType *oneType ) { 221 234 // ideally these wouldn't hit codegen at all, but should be safe to make them ints 222 typeString = "long int "+ typeString;235 typeString = (pretty ? "one_t " : "long int ") + typeString; 223 236 handleQualifiers( oneType ); 224 237 } -
TabularUnified src/CodeGen/GenType.h ¶
rfe26fbf r35b1bf4 21 21 22 22 namespace CodeGen { 23 std::string genType( Type *type, const std::string &baseString, bool mangle = true ); 23 std::string genType( Type *type, const std::string &baseString, bool pretty = false ); 24 std::string genPrettyType( Type * type, const std::string & baseString ); 24 25 } // namespace CodeGen 25 26 -
TabularUnified src/CodeGen/Generate.cc ¶
rfe26fbf r35b1bf4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Generate.cc -- 7 // Generate.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 26 26 27 27 namespace CodeGen { 28 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics ) {29 CodeGen::CodeGenerator cgv( os );28 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty ) { 29 CodeGen::CodeGenerator cgv( os, pretty ); 30 30 31 31 for ( std::list<Declaration *>::iterator i = translationUnit.begin(); i != translationUnit.end(); i++ ) { -
TabularUnified src/CodeGen/Generate.h ¶
rfe26fbf r35b1bf4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Generate.h -- 7 // Generate.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 24 24 namespace CodeGen { 25 25 /// Generates code 26 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics );26 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty ); 27 27 } // namespace CodeGen 28 28
Note: See TracChangeset
for help on using the changeset viewer.