Changeset e6d39fe for src/CodeGen


Ignore:
Timestamp:
Apr 20, 2018, 9:04:41 AM (7 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, with_gc
Children:
22bdc34
Parents:
9181f1d (diff), 88f15ae (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:
5 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r9181f1d re6d39fe  
    116116        }
    117117
    118         CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( CodeGenerator::tabsize ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ), endl( *this ) {}
     118        CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks, bool printExprTypes ) : indent( CodeGenerator::tabsize ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ), printExprTypes( printExprTypes ), endl( *this ) {}
    119119
    120120        string CodeGenerator::mangleName( DeclarationWithType * decl ) {
     
    157157                node->print( ss );
    158158                assertf( false, "Unhandled node reached in CodeGenerator: %s", ss.str().c_str() );
     159        }
     160
     161        // *** Expression
     162        void CodeGenerator::previsit( Expression * node ) {
     163                previsit( (BaseSyntaxNode *)node );
     164                GuardAction( [this, node](){
     165                        if ( printExprTypes ) {
     166                                output << " /* " << genType( node->result, "", pretty, genC ) << " */ ";
     167                        }
     168                } );
    159169        }
    160170
     
    586596                        output << ")";
    587597                } // if
    588                 castExpr->get_arg()->accept( *visitor );
     598                castExpr->arg->accept( *visitor );
     599                output << ")";
     600        }
     601
     602        void CodeGenerator::postvisit( KeywordCastExpr * castExpr ) {
     603                assertf( ! genC, "KeywordCast should not reach code generation." );
     604                extension( castExpr );
     605                output << "((" << castExpr->targetString() << " &)";
     606                castExpr->arg->accept( *visitor );
    589607                output << ")";
    590608        }
  • src/CodeGen/CodeGenerator.h

    r9181f1d re6d39fe  
    2727
    2828namespace CodeGen {
    29         struct CodeGenerator : public WithShortCircuiting, public WithVisitorRef<CodeGenerator> {
     29        struct CodeGenerator : public WithShortCircuiting, public WithGuards, public WithVisitorRef<CodeGenerator> {
    3030          static int tabsize;
    3131
    32                 CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false );
     32                CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false, bool printExprTypes = false );
    3333
    3434                //*** Turn off visit_children for all nodes
     
    3737                //*** Error for unhandled node types
    3838                void postvisit( BaseSyntaxNode * );
     39
     40                //*** print type for all expressions
     41                void previsit( Expression * node );
    3942
    4043                //*** Declaration
     
    6669                void postvisit( LabelAddressExpr *addressExpr );
    6770                void postvisit( CastExpr *castExpr );
     71                void postvisit( KeywordCastExpr * castExpr );
    6872                void postvisit( VirtualCastExpr *castExpr );
    6973                void postvisit( UntypedMemberExpr *memberExpr );
     
    140144                bool genC = false;    // true if output has to be C code
    141145                bool lineMarks = false;
     146                bool printExprTypes = false;
    142147        public:
    143148                LineEnder endl;
  • src/CodeGen/GenType.cc

    r9181f1d re6d39fe  
    4848                void postvisit( ZeroType * zeroType );
    4949                void postvisit( OneType * oneType );
     50                void postvisit( TraitInstType * inst );
     51                void postvisit( TypeofType * typeof );
    5052
    5153          private:
     
    289291        }
    290292
     293        void GenType::postvisit( TraitInstType * inst ) {
     294                assertf( ! genC, "Trait types should not reach code generation." );
     295                typeString = inst->name + " " + typeString;
     296                handleQualifiers( inst );
     297        }
     298
     299        void GenType::postvisit( TypeofType * typeof ) {
     300                std::ostringstream os;
     301                PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks );
     302                os << "typeof(";
     303                typeof->expr->accept( cg );
     304                os << ") " << typeString;
     305                typeString = os.str();
     306                handleQualifiers( typeof );
     307        }
     308
    291309        void GenType::handleQualifiers( Type * type ) {
    292310                if ( type->get_const() ) {
  • src/CodeGen/Generate.cc

    r9181f1d re6d39fe  
    4646        } // namespace
    4747
    48         void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC, bool lineMarks ) {
     48        void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC, bool lineMarks, bool printExprTypes ) {
    4949                cleanTree( translationUnit );
    5050
    51                 PassVisitor<CodeGenerator> cgv( os, pretty, generateC, lineMarks );
     51                PassVisitor<CodeGenerator> cgv( os, pretty, generateC, lineMarks, printExprTypes );
    5252                for ( auto & dcl : translationUnit ) {
    5353                        if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) {
     
    6666                        os << CodeGen::genPrettyType( type, "" );
    6767                } else {
    68                         PassVisitor<CodeGenerator> cgv( os, true, false, false );
     68                        PassVisitor<CodeGenerator> cgv( os, true, false, false, false );
    6969                        node->accept( cgv );
    7070                }
  • src/CodeGen/Generate.h

    r9181f1d re6d39fe  
    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 , bool lineMarks = false );
     26        void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC = false , bool lineMarks = false, bool printTypeExpr = false );
    2727
    2828        /// Generate code for a single node -- helpful for debugging in gdb
Note: See TracChangeset for help on using the changeset viewer.