Changeset 5f08961d for src/CodeGen


Ignore:
Timestamp:
Apr 16, 2018, 4:48:43 PM (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, with_gc
Children:
a3323db1
Parents:
e93f1d2
Message:

Add debug codegen for types in postfix comments for expressions

Location:
src/CodeGen
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    re93f1d2 r5f08961d  
    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
  • src/CodeGen/CodeGenerator.h

    re93f1d2 r5f08961d  
    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
     
    140143                bool genC = false;    // true if output has to be C code
    141144                bool lineMarks = false;
     145                bool printExprTypes = false;
    142146        public:
    143147                LineEnder endl;
  • src/CodeGen/Generate.cc

    re93f1d2 r5f08961d  
    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

    re93f1d2 r5f08961d  
    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.