Changeset 35b1bf4 for src/CodeGen


Ignore:
Timestamp:
Feb 8, 2017, 9:09:39 AM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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
Message:

added pretty print flag, which currently just turns off name mangling in code gen

Location:
src/CodeGen
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rfe26fbf r35b1bf4  
    8989        }
    9090
    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 ) {}
    9292
    9393        CodeGenerator::CodeGenerator( std::ostream & os, std::string init, int indentation, bool infunp )
     
    102102
    103103        string CodeGenerator::mangleName( DeclarationWithType * decl ) {
    104                 if ( ! mangle ) return decl->get_name();
     104                if ( pretty ) return decl->get_name();
    105105                if ( decl->get_mangleName() != "" ) {
    106106                        // need to incorporate scope level in order to differentiate names for destructors
     
    140140                        output << "_Noreturn ";
    141141                } // if
    142                 output << genType( functionDecl->get_functionType(), mangleName( functionDecl ) );
     142                output << genType( functionDecl->get_functionType(), mangleName( functionDecl ), pretty );
    143143
    144144                // how to get this to the Functype?
     
    161161
    162162                handleStorageClass( objectDecl );
    163                 output << genType( objectDecl->get_type(), mangleName( objectDecl ) );
     163                output << genType( objectDecl->get_type(), mangleName( objectDecl ), pretty );
    164164
    165165                asmName( objectDecl );
     
    178178        void CodeGenerator::handleAggregate( AggregateDecl * aggDecl ) {
    179179                genAttributes( aggDecl->get_attributes() );
    180                
     180
    181181                if ( aggDecl->get_name() != "" )
    182182                        output << aggDecl->get_name();
     
    249249                assert( false && "Typedefs are removed and substituted in earlier passes." );
    250250                //output << "typedef ";
    251                 //output << genType( typeDecl->get_base(), typeDecl->get_name() );
     251                //output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty );
    252252        }
    253253
     
    258258                output << "extern unsigned long " << typeDecl->get_name();
    259259                if ( typeDecl->get_base() ) {
    260                         output << " = sizeof( " << genType( typeDecl->get_base(), "" ) << " )";
     260                        output << " = sizeof( " << genType( typeDecl->get_base(), "", pretty ) << " )";
    261261                } // if
    262262        }
     
    552552                        // at least one result type of cast, but not an lvalue
    553553                        output << "(";
    554                         output << genType( castExpr->get_result(), "" );
     554                        output << genType( castExpr->get_result(), "", pretty );
    555555                        output << ")";
    556556                } else {
     
    592592                output << "sizeof(";
    593593                if ( sizeofExpr->get_isType() ) {
    594                         output << genType( sizeofExpr->get_type(), "" );
     594                        output << genType( sizeofExpr->get_type(), "", pretty );
    595595                } else {
    596596                        sizeofExpr->get_expr()->accept( *this );
     
    604604                output << "__alignof__(";
    605605                if ( alignofExpr->get_isType() ) {
    606                         output << genType( alignofExpr->get_type(), "" );
     606                        output << genType( alignofExpr->get_type(), "", pretty );
    607607                } else {
    608608                        alignofExpr->get_expr()->accept( *this );
     
    618618                // use GCC builtin
    619619                output << "__builtin_offsetof(";
    620                 output << genType( offsetofExpr->get_type(), "" );
     620                output << genType( offsetofExpr->get_type(), "", pretty );
    621621                output << ", " << mangleName( offsetofExpr->get_member() );
    622622                output << ")";
     
    680680        void CodeGenerator::visit( CompoundLiteralExpr *compLitExpr ) {
    681681                assert( compLitExpr->get_type() && dynamic_cast< ListInit * > ( compLitExpr->get_initializer() ) );
    682                 output << "(" << genType( compLitExpr->get_type(), "" ) << ")";
     682                output << "(" << genType( compLitExpr->get_type(), "", pretty ) << ")";
    683683                compLitExpr->get_initializer()->accept( *this );
    684684        }
  • src/CodeGen/CodeGenerator.h

    rfe26fbf r35b1bf4  
    3030                static int tabsize;
    3131
    32                 CodeGenerator( std::ostream &os, bool mangle = true );
     32                CodeGenerator( std::ostream &os, bool pretty = false );
    3333                CodeGenerator( std::ostream &os, std::string, int indent = 0, bool infun = false );
    3434                CodeGenerator( std::ostream &os, char *, int indent = 0, bool infun = false );
     
    119119                std::ostream &output;
    120120                LabelPrinter printLabels;
    121                 bool mangle = true;
     121                bool pretty = false;  // pretty print
    122122
    123123                void printDesignators( std::list< Expression * > & );
  • src/CodeGen/GenType.cc

    rfe26fbf r35b1bf4  
    2828        class GenType : public Visitor {
    2929          public:
    30                 GenType( const std::string &typeString, bool mangle = true );
     30                GenType( const std::string &typeString, bool pretty = false );
    3131                std::string get_typeString() const { return typeString; }
    3232                void set_typeString( const std::string &newValue ) { typeString = newValue; }
     
    5151
    5252                std::string typeString;
    53                 bool mangle = true;
     53                bool pretty = false; // pretty print
    5454        };
    5555
    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
    6060                if ( ! type->get_attributes().empty() ) {
    61                         CodeGenerator cg( os, mangle );
     61                        CodeGenerator cg( os, pretty );
    6262                        cg.genAttributes( type->get_attributes() );
    6363                } // if
     
    6767        }
    6868
    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 ) {}
    7074
    7175        void GenType::visit( VoidType *voidType ) {
     
    108112                } // if
    109113                if ( dimension != 0 ) {
    110                         CodeGenerator cg( os, mangle );
     114                        CodeGenerator cg( os, pretty );
    111115                        dimension->accept( cg );
    112116                } else if ( isVarLen ) {
     
    162166                        } // if
    163167                } else {
    164                         CodeGenerator cg( os, mangle );
     168                        CodeGenerator cg( os, pretty );
    165169                        os << "(" ;
    166170
     
    203207
    204208        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." );
    206210                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;
    207220        }
    208221
     
    214227        void GenType::visit( ZeroType *zeroType ) {
    215228                // 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;
    217230                handleQualifiers( zeroType );
    218231        }
     
    220233        void GenType::visit( OneType *oneType ) {
    221234                // 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;
    223236                handleQualifiers( oneType );
    224237        }
  • src/CodeGen/GenType.h

    rfe26fbf r35b1bf4  
    2121
    2222namespace 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 );
    2425} // namespace CodeGen
    2526
  • src/CodeGen/Generate.cc

    rfe26fbf r35b1bf4  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Generate.cc -- 
     7// Generate.cc --
    88//
    99// Author           : Richard C. Bilson
     
    2626
    2727namespace 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 );
    3030
    3131                for ( std::list<Declaration *>::iterator i = translationUnit.begin(); i != translationUnit.end();  i++ ) {
  • src/CodeGen/Generate.h

    rfe26fbf r35b1bf4  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Generate.h -- 
     7// Generate.h --
    88//
    99// Author           : Richard C. Bilson
     
    2424namespace CodeGen {
    2525        /// 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 );
    2727} // namespace CodeGen
    2828
Note: See TracChangeset for help on using the changeset viewer.