Ignore:
Timestamp:
Jul 30, 2015, 3:56:18 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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, string, with_gc
Children:
093f1a0
Parents:
51b986f
Message:

asm statement, memory leaks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r51b986f r7f5566b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jul 15 14:47:42 2015
    13 // Update Count     : 177
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Jul 27 14:40:06 2015
     13// Update Count     : 218
    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;
     
    450450        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    451451
     452        void CodeGenerator::visit( AsmExpr *asmExpr ) {
     453                if ( asmExpr->get_inout() ) {
     454                        output << "[ ";
     455                        asmExpr->get_inout()->accept( *this );
     456                        output << " ] ";
     457                } // if
     458                asmExpr->get_constraint()->accept( *this );
     459                output << " ( ";
     460                asmExpr->get_operand()->accept( *this );
     461                output << " )";
     462        }
     463
    452464        //*** Statements
    453465        void CodeGenerator::visit( CompoundStmt *compoundStmt ) {
     
    457469                cur_indent += CodeGenerator::tabsize;
    458470
    459                 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++) {
     471                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++ ) {
    460472                        output << indent << printLabels( (*i)->get_labels() );
    461                         (*i)->accept(*this );
     473                        (*i)->accept( *this );
    462474
    463475                        output << endl;
     
    483495        }
    484496
     497        void CodeGenerator::visit( AsmStmt *asmStmt ) {
     498                output << "asm ";
     499                if ( asmStmt->get_voltile() ) output << "volatile ";
     500                if ( ! asmStmt->get_gotolabels().empty()  ) output << "goto ";
     501                output << "( ";
     502                if ( asmStmt->get_instruction() ) asmStmt->get_instruction()->accept( *this );
     503                output << " : ";
     504                genCommaList( asmStmt->get_output().begin(), asmStmt->get_output().end() );
     505                output << " : ";
     506                genCommaList( asmStmt->get_input().begin(), asmStmt->get_input().end() );
     507                output << " : ";
     508                genCommaList( asmStmt->get_clobber().begin(), asmStmt->get_clobber().end() );
     509                if ( ! asmStmt->get_gotolabels().empty() ) {
     510                        output << " : ";
     511                        for ( std::list<Label>::iterator begin = asmStmt->get_gotolabels().begin();; ) {
     512                                output << *begin++;
     513                                if ( begin == asmStmt->get_gotolabels().end() ) break;
     514                                output << ", ";
     515                        } // for
     516                } // if
     517                output << " );" ;
     518        }
     519
    485520        void CodeGenerator::visit( IfStmt *ifStmt ) {
    486                 output << "if (";
    487                 ifStmt->get_condition()->accept(*this );
    488                 output << ") ";
    489 
    490                 ifStmt->get_thenPart()->accept(*this );
     521                output << "if ( ";
     522                ifStmt->get_condition()->accept( *this );
     523                output << " ) ";
     524
     525                ifStmt->get_thenPart()->accept( *this );
    491526
    492527                if ( ifStmt->get_elsePart() != 0) {
    493528                        output << " else ";
    494                         ifStmt->get_elsePart()->accept(*this );
     529                        ifStmt->get_elsePart()->accept( *this );
    495530                } // if
    496531        }
    497532
    498533        void CodeGenerator::visit( SwitchStmt *switchStmt ) {
    499                 output << "switch (" ;
    500                 switchStmt->get_condition()->accept(*this );
    501                 output << ") ";
     534                output << "switch ( " ;
     535                switchStmt->get_condition()->accept( *this );
     536                output << " ) ";
    502537               
    503538                output << "{" << std::endl;
     
    517552                } else {
    518553                        output << "case ";
    519                         caseStmt->get_condition()->accept(*this );
     554                        caseStmt->get_condition()->accept( *this );
    520555                } // if
    521556                output << ":\n";
     
    526561                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
    527562                        output << indent << printLabels( (*i)->get_labels() )  ;
    528                         (*i)->accept(*this );
     563                        (*i)->accept( *this );
    529564                        output << endl;
    530565                }
     
    570605                else {
    571606                        output << "while (" ;
    572                         whileStmt->get_condition()->accept(*this );
     607                        whileStmt->get_condition()->accept( *this );
    573608                        output << ")";
    574609                } // if
     
    582617                if ( whileStmt->get_isDoWhile() ) {
    583618                        output << " while (" ;
    584                         whileStmt->get_condition()->accept(*this );
     619                        whileStmt->get_condition()->accept( *this );
    585620                        output << ");";
    586621                } // if
Note: See TracChangeset for help on using the changeset viewer.