Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rf32c7f4 r2794fff  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Aug 12 14:33:52 2015
    13 // Update Count     : 222
     12// Last Modified On : Wed Jul 15 14:47:42 2015
     13// Update Count     : 177
    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 
    206188        void CodeGenerator::visit( SingleInit *init ) {
    207                 printDesignators( init->get_designators() );
    208189                init->get_value()->accept( *this );
    209190        }
    210191
    211192        void CodeGenerator::visit( ListInit *init ) {
    212                 printDesignators( init->get_designators() );
    213193                output << "{ ";
    214194                genCommaList( init->begin_initializers(), init->end_initializers() );
     
    258238             
    259239                                  case OT_CALL:
    260                                         // there are no intrinsic definitions of the function call operator
     240                                  case OT_CTOR:
     241                                  case OT_DTOR:
     242                                        // there are no intrinsic definitions of the function call operator or constructors or destructors
    261243                                        assert( false );
    262244                                        break;
     
    470452        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    471453
    472         void CodeGenerator::visit( AsmExpr *asmExpr ) {
    473                 if ( asmExpr->get_inout() ) {
    474                         output << "[ ";
    475                         asmExpr->get_inout()->accept( *this );
    476                         output << " ] ";
    477                 } // if
    478                 asmExpr->get_constraint()->accept( *this );
    479                 output << " ( ";
    480                 asmExpr->get_operand()->accept( *this );
    481                 output << " )";
    482         }
    483 
    484454        //*** Statements
    485455        void CodeGenerator::visit( CompoundStmt *compoundStmt ) {
     
    489459                cur_indent += CodeGenerator::tabsize;
    490460
    491                 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++ ) {
     461                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++) {
    492462                        output << indent << printLabels( (*i)->get_labels() );
    493                         (*i)->accept( *this );
     463                        (*i)->accept(*this );
    494464
    495465                        output << endl;
     
    515485        }
    516486
    517         void CodeGenerator::visit( AsmStmt *asmStmt ) {
    518                 output << "asm ";
    519                 if ( asmStmt->get_voltile() ) output << "volatile ";
    520                 if ( ! asmStmt->get_gotolabels().empty()  ) output << "goto ";
    521                 output << "( ";
    522                 if ( asmStmt->get_instruction() ) asmStmt->get_instruction()->accept( *this );
    523                 output << " : ";
    524                 genCommaList( asmStmt->get_output().begin(), asmStmt->get_output().end() );
    525                 output << " : ";
    526                 genCommaList( asmStmt->get_input().begin(), asmStmt->get_input().end() );
    527                 output << " : ";
    528                 genCommaList( asmStmt->get_clobber().begin(), asmStmt->get_clobber().end() );
    529                 if ( ! asmStmt->get_gotolabels().empty() ) {
    530                         output << " : ";
    531                         for ( std::list<Label>::iterator begin = asmStmt->get_gotolabels().begin();; ) {
    532                                 output << *begin++;
    533                                 if ( begin == asmStmt->get_gotolabels().end() ) break;
    534                                 output << ", ";
    535                         } // for
    536                 } // if
    537                 output << " );" ;
    538         }
    539 
    540487        void CodeGenerator::visit( IfStmt *ifStmt ) {
    541                 output << "if ( ";
    542                 ifStmt->get_condition()->accept( *this );
    543                 output << " ) ";
    544 
    545                 ifStmt->get_thenPart()->accept( *this );
     488                output << "if (";
     489                ifStmt->get_condition()->accept(*this );
     490                output << ") ";
     491
     492                ifStmt->get_thenPart()->accept(*this );
    546493
    547494                if ( ifStmt->get_elsePart() != 0) {
    548495                        output << " else ";
    549                         ifStmt->get_elsePart()->accept( *this );
     496                        ifStmt->get_elsePart()->accept(*this );
    550497                } // if
    551498        }
    552499
    553500        void CodeGenerator::visit( SwitchStmt *switchStmt ) {
    554                 output << "switch ( " ;
    555                 switchStmt->get_condition()->accept( *this );
    556                 output << " ) ";
     501                output << "switch (" ;
     502                switchStmt->get_condition()->accept(*this );
     503                output << ") ";
    557504               
    558505                output << "{" << std::endl;
     
    572519                } else {
    573520                        output << "case ";
    574                         caseStmt->get_condition()->accept( *this );
     521                        caseStmt->get_condition()->accept(*this );
    575522                } // if
    576523                output << ":\n";
     
    581528                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
    582529                        output << indent << printLabels( (*i)->get_labels() )  ;
    583                         (*i)->accept( *this );
     530                        (*i)->accept(*this );
    584531                        output << endl;
    585532                }
     
    625572                else {
    626573                        output << "while (" ;
    627                         whileStmt->get_condition()->accept( *this );
     574                        whileStmt->get_condition()->accept(*this );
    628575                        output << ")";
    629576                } // if
     
    637584                if ( whileStmt->get_isDoWhile() ) {
    638585                        output << " while (" ;
    639                         whileStmt->get_condition()->accept( *this );
     586                        whileStmt->get_condition()->accept(*this );
    640587                        output << ");";
    641588                } // if
Note: See TracChangeset for help on using the changeset viewer.