Changeset 3bd1eb4 for src/CodeGen


Ignore:
Timestamp:
May 15, 2017, 3:27:47 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
db0fa7c
Parents:
dbfb35d (diff), 9ff8310 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/CodeGen
Files:
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rdbfb35d r3bd1eb4  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus May  9 16:50:00 2017
     12// Last Modified On : Wed May 10 14:45:00 2017
    1313// Update Count     : 484
    1414//
     
    4141namespace CodeGen {
    4242        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         }
    5643
    5744        // the kinds of statements that would ideally be followed by whitespace
     
    10289        }
    10390
    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 ) {}
    105114
    106115        CodeGenerator::CodeGenerator( std::ostream & os, std::string init, int indentation, bool infunp )
     
    143152        // *** Declarations
    144153        void CodeGenerator::visit( FunctionDecl * functionDecl ) {
    145                 output << lineDirective( functionDecl );
    146 
    147154                extension( functionDecl );
    148155                genAttributes( functionDecl->get_attributes() );
     
    168175                }
    169176
    170                 output << lineDirective( objectDecl );
    171 
    172177                extension( objectDecl );
    173178                genAttributes( objectDecl->get_attributes() );
     
    221226
    222227        void CodeGenerator::visit( StructDecl * structDecl ) {
    223                 output << lineDirective( structDecl );
    224 
    225228                extension( structDecl );
    226229                handleAggregate( structDecl, "struct " );
     
    228231
    229232        void CodeGenerator::visit( UnionDecl * unionDecl ) {
    230                 output << lineDirective( unionDecl );
    231 
    232233                extension( unionDecl );
    233234                handleAggregate( unionDecl, "union " );
     
    708709        void CodeGenerator::visit( UntypedTupleExpr * tupleExpr ) {
    709710                assertf( ! genC, "UntypedTupleExpr should not reach code generation." );
     711                extension( tupleExpr );
    710712                output << "[";
    711713                genCommaList( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end() );
     
    715717        void CodeGenerator::visit( TupleExpr * tupleExpr ) {
    716718                assertf( ! genC, "TupleExpr should not reach code generation." );
     719                extension( tupleExpr );
    717720                output << "[";
    718721                genCommaList( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end() );
    719722                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();
    720730        }
    721731
  • src/CodeGen/CodeGenerator.h

    rdbfb35d r3bd1eb4  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  1 16:20:04 2017
    13 // Update Count     : 50
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed May 10 10:57:00 2017
     13// Update Count     : 51
    1414//
    1515
     
    2525#include "SymTab/Indexer.h"
    2626
     27#include "Common/utility.h"
     28
    2729namespace CodeGen {
    2830        class CodeGenerator : public Visitor {
     
    3032                static int tabsize;
    3133
    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 );
    3335                CodeGenerator( std::ostream &os, std::string, int indent = 0, bool infun = false );
    3436                CodeGenerator( std::ostream &os, char *, int indent = 0, bool infun = false );
     
    7476                virtual void visit( UntypedTupleExpr *tupleExpr );
    7577                virtual void visit( TupleExpr *tupleExpr );
     78                virtual void visit( TupleIndexExpr * tupleExpr );
    7679                virtual void visit( TypeExpr *typeExpr );
    7780                virtual void visit( AsmExpr * );
     
    110113                };
    111114
     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
    112124                void asmName( DeclarationWithType *decl );
    113125
     
    122134                bool pretty = false;  // pretty print
    123135                bool genC = false;    // true if output has to be C code
     136                bool lineMarks = false;
    124137
    125138                void printDesignators( std::list< Expression * > & );
     
    149162        /// returns C-compatible name of declaration
    150163        std::string genName( DeclarationWithType * decl );
     164
     165        std::ostream & operator<<(std::ostream &,
     166                CodeGenerator::LineMarker const &);
    151167} // namespace CodeGen
    152168
  • src/CodeGen/GenType.cc

    rdbfb35d r3bd1eb4  
    2828        class GenType : public Visitor {
    2929          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 );
    3131                std::string get_typeString() const { return typeString; }
    3232                void set_typeString( const std::string &newValue ) { typeString = newValue; }
     
    5454                bool pretty = false; // pretty print
    5555                bool genC = false;   // generating C code?
     56                bool lineMarks = false;
    5657        };
    5758
    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 );
    6061                std::ostringstream os;
    6162
    6263                if ( ! type->get_attributes().empty() ) {
    63                         CodeGenerator cg( os, pretty, genC );
     64                        CodeGenerator cg( os, pretty, genC, lineMarks );
    6465                        cg.genAttributes( type->get_attributes() );
    6566                } // if
     
    7374  }
    7475
    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 ) {}
    7677
    7778        void GenType::visit( VoidType *voidType ) {
     
    114115                } // if
    115116                if ( dimension != 0 ) {
    116                         CodeGenerator cg( os, pretty, genC );
     117                        CodeGenerator cg( os, pretty, genC, lineMarks );
    117118                        dimension->accept( cg );
    118119                } else if ( isVarLen ) {
     
    168169                        } // if
    169170                } else {
    170                         CodeGenerator cg( os, pretty, genC );
     171                        CodeGenerator cg( os, pretty, genC, lineMarks );
    171172                        os << "(" ;
    172173
     
    191192                        // assertf( ! genC, "Aggregate type parameters should not reach code generation." );
    192193                        std::ostringstream os;
    193                         CodeGenerator cg( os, pretty, genC );
     194                        CodeGenerator cg( os, pretty, genC, lineMarks );
    194195                        os << "forall(";
    195196                        cg.genCommaList( funcType->get_forall().begin(), funcType->get_forall().end() );
     
    202203                if ( ! refType->get_parameters().empty() ) {
    203204                        std::ostringstream os;
    204                         CodeGenerator cg( os, pretty, genC );
     205                        CodeGenerator cg( os, pretty, genC, lineMarks );
    205206                        os << "(";
    206207                        cg.genCommaList( refType->get_parameters().begin(), refType->get_parameters().end() );
     
    242243                for ( Type * t : *tupleType ) {
    243244                        i++;
    244                         os << genType( t, "", pretty, genC ) << (i == tupleType->size() ? "" : ", ");
     245                        os << genType( t, "", pretty, genC, lineMarks ) << (i == tupleType->size() ? "" : ", ");
    245246                }
    246247                os << "]";
  • src/CodeGen/GenType.h

    rdbfb35d r3bd1eb4  
    2121
    2222namespace 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 );
    2424  std::string genPrettyType( Type * type, const std::string & baseString );
    2525} // namespace CodeGen
  • src/CodeGen/Generate.cc

    rdbfb35d r3bd1eb4  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  4 14:04:25 2015
    13 // Update Count     : 5
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed May 19 13:05:00 2017
     13// Update Count     : 6
    1414//
    1515
     
    3131
    3232namespace 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 );
    3535                for ( auto & dcl : translationUnit ) {
    3636                        if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) {
     37                                os << cgv.lineDirective(dcl);
    3738                                dcl->accept(cgv);
    3839                                if ( doSemicolon( dcl ) ) {
     
    4849                        os << CodeGen::genPrettyType( type, "" );
    4950                } else {
    50                         CodeGen::CodeGenerator cgv( os, true, false );
     51                        CodeGen::CodeGenerator cgv( os, true, false, false );
    5152                        node->accept( cgv );
    5253                }
  • src/CodeGen/Generate.h

    rdbfb35d r3bd1eb4  
    2424namespace CodeGen {
    2525        /// 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 );
    2727
    2828        /// Generate code for a single node -- helpful for debugging in gdb
Note: See TracChangeset for help on using the changeset viewer.