Changeset 353d168 for src/CodeGen


Ignore:
Timestamp:
Aug 19, 2015, 3:59:45 PM (10 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
830c21a
Parents:
18997b9 (diff), 4aa0858 (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 'override-autogen' into ctor

Conflicts:

src/Parser/ParseNode.h

Location:
src/CodeGen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r18997b9 r353d168  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jul 15 14:47:42 2015
    13 // Update Count     : 177
     12// Last Modified On : Wed Aug 12 14:33:52 2015
     13// Update Count     : 222
    1414//
    1515
     
    5252        }
    5353
    54         CodeGenerator::CodeGenerator( std::ostream &os ) : indent(*this), cur_indent( 0 ), insideFunction( false ), output( os ) { }
     54        CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ) { }
    5555
    5656        CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp )
    57                         : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) {
     57                        : indent( *this), cur_indent( indentation ), insideFunction( infunp ), output( os ) {
    5858                //output << std::string( init );
    5959        }
    6060
    6161        CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp )
    62                         : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) {
     62                        : indent( *this ), cur_indent( indentation ), insideFunction( infunp ), output( os ) {
    6363                //output << std::string( init );
    6464        }
     
    9191                // acceptAll( functionDecl->get_oldDecls(), *this );
    9292                if ( functionDecl->get_statements() ) {
    93                         functionDecl->get_statements()->accept(*this );
     93                        functionDecl->get_statements()->accept( *this );
    9494                } // if
    9595        }
     
    121121                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    122122                                output << indent;
    123                                 (*i)->accept(*this );
     123                                (*i)->accept( *this );
    124124                                output << ";" << endl;
    125125                        }
     
    159159                                if ( obj->get_init() ) {
    160160                                        output << " = ";
    161                                         obj->get_init()->accept(*this );
     161                                        obj->get_init()->accept( *this );
    162162                                } // if
    163163                                output << "," << endl;
     
    186186        }
    187187
     188        void CodeGenerator::printDesignators( std::list< Expression * > & designators ) {
     189                typedef std::list< Expression * > DesignatorList;
     190                if ( designators.size() == 0 ) return;
     191                for ( DesignatorList::iterator iter = designators.begin(); iter != designators.end(); ++iter ) {
     192                        if ( NameExpr * nm = dynamic_cast< NameExpr * >( *iter ) ) {
     193                                // if expression is a name, then initializing aggregate member
     194                                output << ".";
     195                                (*iter)->accept( *this );
     196                        } else {
     197                                // if not a simple name, it has to be a constant expression, i.e. an array designator
     198                                output << "[";
     199                                (*iter)->accept( *this );
     200                                output << "]";
     201                        }
     202                }
     203                output << " = ";
     204        }
     205
    188206        void CodeGenerator::visit( SingleInit *init ) {
     207                printDesignators( init->get_designators() );
    189208                init->get_value()->accept( *this );
    190209        }
    191210
    192211        void CodeGenerator::visit( ListInit *init ) {
     212                printDesignators( init->get_designators() );
    193213                output << "{ ";
    194214                genCommaList( init->begin_initializers(), init->end_initializers() );
     
    452472        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    453473
     474        void CodeGenerator::visit( AsmExpr *asmExpr ) {
     475                if ( asmExpr->get_inout() ) {
     476                        output << "[ ";
     477                        asmExpr->get_inout()->accept( *this );
     478                        output << " ] ";
     479                } // if
     480                asmExpr->get_constraint()->accept( *this );
     481                output << " ( ";
     482                asmExpr->get_operand()->accept( *this );
     483                output << " )";
     484        }
     485
    454486        //*** Statements
    455487        void CodeGenerator::visit( CompoundStmt *compoundStmt ) {
     
    459491                cur_indent += CodeGenerator::tabsize;
    460492
    461                 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++) {
     493                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++ ) {
    462494                        output << indent << printLabels( (*i)->get_labels() );
    463                         (*i)->accept(*this );
     495                        (*i)->accept( *this );
    464496
    465497                        output << endl;
     
    485517        }
    486518
     519        void CodeGenerator::visit( AsmStmt *asmStmt ) {
     520                output << "asm ";
     521                if ( asmStmt->get_voltile() ) output << "volatile ";
     522                if ( ! asmStmt->get_gotolabels().empty()  ) output << "goto ";
     523                output << "( ";
     524                if ( asmStmt->get_instruction() ) asmStmt->get_instruction()->accept( *this );
     525                output << " : ";
     526                genCommaList( asmStmt->get_output().begin(), asmStmt->get_output().end() );
     527                output << " : ";
     528                genCommaList( asmStmt->get_input().begin(), asmStmt->get_input().end() );
     529                output << " : ";
     530                genCommaList( asmStmt->get_clobber().begin(), asmStmt->get_clobber().end() );
     531                if ( ! asmStmt->get_gotolabels().empty() ) {
     532                        output << " : ";
     533                        for ( std::list<Label>::iterator begin = asmStmt->get_gotolabels().begin();; ) {
     534                                output << *begin++;
     535                                if ( begin == asmStmt->get_gotolabels().end() ) break;
     536                                output << ", ";
     537                        } // for
     538                } // if
     539                output << " );" ;
     540        }
     541
    487542        void CodeGenerator::visit( IfStmt *ifStmt ) {
    488                 output << "if (";
    489                 ifStmt->get_condition()->accept(*this );
    490                 output << ") ";
    491 
    492                 ifStmt->get_thenPart()->accept(*this );
     543                output << "if ( ";
     544                ifStmt->get_condition()->accept( *this );
     545                output << " ) ";
     546
     547                ifStmt->get_thenPart()->accept( *this );
    493548
    494549                if ( ifStmt->get_elsePart() != 0) {
    495550                        output << " else ";
    496                         ifStmt->get_elsePart()->accept(*this );
     551                        ifStmt->get_elsePart()->accept( *this );
    497552                } // if
    498553        }
    499554
    500555        void CodeGenerator::visit( SwitchStmt *switchStmt ) {
    501                 output << "switch (" ;
    502                 switchStmt->get_condition()->accept(*this );
    503                 output << ") ";
     556                output << "switch ( " ;
     557                switchStmt->get_condition()->accept( *this );
     558                output << " ) ";
    504559               
    505560                output << "{" << std::endl;
     
    519574                } else {
    520575                        output << "case ";
    521                         caseStmt->get_condition()->accept(*this );
     576                        caseStmt->get_condition()->accept( *this );
    522577                } // if
    523578                output << ":\n";
     
    528583                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
    529584                        output << indent << printLabels( (*i)->get_labels() )  ;
    530                         (*i)->accept(*this );
     585                        (*i)->accept( *this );
    531586                        output << endl;
    532587                }
     
    572627                else {
    573628                        output << "while (" ;
    574                         whileStmt->get_condition()->accept(*this );
     629                        whileStmt->get_condition()->accept( *this );
    575630                        output << ")";
    576631                } // if
     
    584639                if ( whileStmt->get_isDoWhile() ) {
    585640                        output << " while (" ;
    586                         whileStmt->get_condition()->accept(*this );
     641                        whileStmt->get_condition()->accept( *this );
    587642                        output << ");";
    588643                } // if
  • src/CodeGen/CodeGenerator.h

    r18997b9 r353d168  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jun 11 13:24:23 2015
    13 // Update Count     : 23
     12// Last Modified On : Wed Aug 12 14:27:14 2015
     13// Update Count     : 27
    1414//
    1515
     
    6565                virtual void visit( TupleExpr *tupleExpr );
    6666                virtual void visit( TypeExpr *typeExpr );
     67                virtual void visit( AsmExpr * );
    6768
    6869                //*** Statements
    6970                virtual void visit( CompoundStmt * );
    7071                virtual void visit( ExprStmt * );
     72                virtual void visit( AsmStmt * );
    7173                virtual void visit( IfStmt * );
    7274                virtual void visit( SwitchStmt * );
     
    9395                std::ostream &output;
    9496
     97                void printDesignators( std::list< Expression * > & );
    9598                static std::string printLabels ( std::list < Label > & );
    9699                void handleStorageClass( Declaration *decl );
Note: See TracChangeset for help on using the changeset viewer.