Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    ra9a259c r2a4b088  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // CodeGenerator.cc --
     7// CodeGenerator.cc -- 
    88//
    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 : Tue Feb 09 13:24:40 2016
    13 // Update Count     : 255
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Jan 25 21:22:00 2016
     13// Update Count     : 242
    1414//
    1515
     
    9898                handleStorageClass( objectDecl );
    9999                output << genType( objectDecl->get_type(), mangleName( objectDecl ) );
    100 
     100       
    101101                if ( objectDecl->get_init() ) {
    102102                        output << " = ";
     
    112112                if ( aggDecl->get_name() != "" )
    113113                        output << aggDecl->get_name();
    114 
     114       
    115115                std::list< Declaration * > &memb = aggDecl->get_members();
    116116
     
    118118                        output << " {" << endl;
    119119
    120                         cur_indent += CodeGenerator::tabsize;
     120                        cur_indent += CodeGenerator::tabsize; 
    121121                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    122                                 output << indent;
     122                                output << indent; 
    123123                                (*i)->accept( *this );
    124124                                output << ";" << endl;
    125125                        }
    126126
    127                         cur_indent -= CodeGenerator::tabsize;
     127                        cur_indent -= CodeGenerator::tabsize; 
    128128
    129129                        output << indent << "}";
     
    140140                handleAggregate( aggregateDecl );
    141141        }
    142 
     142 
    143143        void CodeGenerator::visit( EnumDecl *aggDecl ) {
    144144                output << "enum ";
     
    146146                if ( aggDecl->get_name() != "" )
    147147                        output << aggDecl->get_name();
    148 
     148       
    149149                std::list< Declaration* > &memb = aggDecl->get_members();
    150150
     
    152152                        output << " {" << endl;
    153153
    154                         cur_indent += CodeGenerator::tabsize;
     154                        cur_indent += CodeGenerator::tabsize; 
    155155                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    156156                                ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
    157157                                assert( obj );
    158                                 output << indent << mangleName( obj );
     158                                output << indent << mangleName( obj ); 
    159159                                if ( obj->get_init() ) {
    160160                                        output << " = ";
     
    164164                        } // for
    165165
    166                         cur_indent -= CodeGenerator::tabsize;
     166                        cur_indent -= CodeGenerator::tabsize; 
    167167
    168168                        output << indent << "}";
    169169                } // if
    170170        }
    171 
     171 
    172172        void CodeGenerator::visit( ContextDecl *aggregateDecl ) {}
    173 
     173 
    174174        void CodeGenerator::visit( TypedefDecl *typeDecl ) {
    175175                output << "typedef ";
    176176                output << genType( typeDecl->get_base(), typeDecl->get_name() );
    177177        }
    178 
     178 
    179179        void CodeGenerator::visit( TypeDecl *typeDecl ) {
    180180                // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes,
     
    216216        }
    217217
    218         void CodeGenerator::visit( Constant *constant ) {
     218        void CodeGenerator::visit( Constant *constant ) { 
    219219                output << constant->get_value() ;
    220220        }
     
    233233                                                assert( arg != applicationExpr->get_args().end() );
    234234                                                if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
    235 
     235               
    236236                                                        *arg = addrExpr->get_arg();
    237237                                                } else {
     
    242242                                                break;
    243243                                        }
    244 
     244             
    245245                                  default:
    246246                                        // do nothing
    247247                                        ;
    248248                                }
    249 
     249           
    250250                                switch ( opInfo.type ) {
    251251                                  case OT_INDEX:
     
    256256                                        output << "]";
    257257                                        break;
    258 
     258             
    259259                                  case OT_CALL:
    260                                         // there are no intrinsic definitions of the function call operator or constructors or destructors
     260                                        // there are no intrinsic definitions of the function call operator
    261261                                        assert( false );
    262262                                        break;
    263 
    264                                   case OT_CTOR:
    265                                   // it's just an optimization to disallow this, so for now let it through
    266                                   // since it makes autogenerating constructors a lot easier
    267                                 varExpr->accept( *this );
    268                                         output << "(";
    269                                         genCommaList( applicationExpr->get_args().begin(), applicationExpr->get_args().end() );
    270                                         output << ")";
    271 
    272                                   // intrinsic constructors should never be called directly - they should be transformed back into Initializer nodes
    273                                   // assert(false);
    274                                   break;
    275 
    276                                   case OT_DTOR:
    277                                   // intrinsic destructors do nothing - don't generate any code
    278                                   output << " // " << dynamic_cast<VariableExpr*>(applicationExpr->get_function())->get_var()->get_name() << endl;
    279                                   break;
    280 
     263             
    281264                                  case OT_PREFIX:
    282265                                  case OT_PREFIXASSIGN:
     
    287270                                        output << ")";
    288271                                        break;
    289 
     272             
    290273                                  case OT_POSTFIX:
    291274                                  case OT_POSTFIXASSIGN:
     
    294277                                        output << opInfo.symbol;
    295278                                        break;
    296 
    297279
    298280                                  case OT_INFIX:
     
    305287                                        output << ")";
    306288                                        break;
    307 
     289             
    308290                                  case OT_CONSTANT:
    309291                                  case OT_LABELADDRESS:
     
    324306                } // if
    325307        }
    326 
     308 
    327309        void CodeGenerator::visit( UntypedExpr *untypedExpr ) {
    328310                if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
     
    338320                                        output << "]";
    339321                                        break;
    340 
     322             
    341323                                  case OT_CALL:
    342324                                        assert( false );
    343 
    344                                         case OT_CTOR:
    345                                         case OT_DTOR:
    346                                         // intrinsic constructors should never be called
    347                                         // intrinsic destructors do nothing
    348                                         break;
    349 
     325                                        break;
     326             
    350327                                  case OT_PREFIX:
    351328                                  case OT_PREFIXASSIGN:
     
    357334                                        output << ")";
    358335                                        break;
    359 
     336             
    360337                                  case OT_POSTFIX:
    361338                                  case OT_POSTFIXASSIGN:
     
    364341                                        output << opInfo.symbol;
    365342                                        break;
    366 
     343 
    367344                                  case OT_INFIX:
    368345                                  case OT_INFIXASSIGN:
     
    374351                                        output << ")";
    375352                                        break;
    376 
     353                                       
    377354                                  case OT_CONSTANT:
    378355                                        // there are no intrinsic definitions of 0 or 1 as functions
     
    392369                } // if
    393370        }
    394 
     371 
    395372        void CodeGenerator::visit( NameExpr *nameExpr ) {
    396373                OperatorInfo opInfo;
     
    402379                } // if
    403380        }
    404 
     381 
    405382        void CodeGenerator::visit( AddressExpr *addressExpr ) {
    406383                output << "(&";
     
    431408                output << ")";
    432409        }
    433 
     410 
    434411        void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) {
    435412                assert( false );
    436413        }
    437 
     414 
    438415        void CodeGenerator::visit( MemberExpr *memberExpr ) {
    439416                memberExpr->get_aggregate()->accept( *this );
    440417                output << "." << mangleName( memberExpr->get_member() );
    441418        }
    442 
     419 
    443420        void CodeGenerator::visit( VariableExpr *variableExpr ) {
    444421                OperatorInfo opInfo;
     
    449426                } // if
    450427        }
    451 
     428 
    452429        void CodeGenerator::visit( ConstantExpr *constantExpr ) {
    453430                assert( constantExpr->get_constant() );
    454431                constantExpr->get_constant()->accept( *this );
    455432        }
    456 
     433 
    457434        void CodeGenerator::visit( SizeofExpr *sizeofExpr ) {
    458435                output << "sizeof(";
     
    487464                output << ")";
    488465        }
    489 
     466 
    490467        void CodeGenerator::visit( LogicalExpr *logicalExpr ) {
    491468                output << "(";
     
    499476                output << ")";
    500477        }
    501 
     478 
    502479        void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) {
    503480                output << "(";
     
    509486                output << ")";
    510487        }
    511 
     488 
    512489        void CodeGenerator::visit( CommaExpr *commaExpr ) {
    513490                output << "(";
     
    517494                output << ")";
    518495        }
    519 
     496 
    520497        void CodeGenerator::visit( TupleExpr *tupleExpr ) {}
    521 
     498 
    522499        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    523500
     
    550527                        }
    551528                }
    552                 cur_indent -= CodeGenerator::tabsize;
     529                cur_indent -= CodeGenerator::tabsize; 
    553530
    554531                output << indent << "}";
     
    556533
    557534        void CodeGenerator::visit( ExprStmt *exprStmt ) {
    558                 // I don't see why this check is necessary.
    559                 // If this starts to cause problems then put it back in,
     535                // I don't see why this check is necessary. 
     536                // If this starts to cause problems then put it back in, 
    560537                // with an explanation
    561538                assert( exprStmt );
     
    607584                switchStmt->get_condition()->accept( *this );
    608585                output << " ) ";
    609 
     586               
    610587                output << "{" << std::endl;
    611588                cur_indent += CodeGenerator::tabsize;
     
    627604                } // if
    628605                output << ":\n";
    629 
     606               
    630607                std::list<Statement *> sts = caseStmt->get_statements();
    631608
     
    644621                        if ( ! branchStmt->get_target().empty() )
    645622                                output << "goto " << branchStmt->get_target();
    646                         else {
     623                        else { 
    647624                                if ( branchStmt->get_computedTarget() != 0 ) {
    648625                                        output << "goto *";
     
    695672
    696673        void CodeGenerator::visit( ForStmt *forStmt ) {
    697                 // initialization is always hoisted, so don't
    698                 // bother doing anything with that
     674                // initialization is always hoisted, so don't 
     675                // bother doing anything with that 
    699676                output << "for (;";
    700677
     
    720697        void CodeGenerator::visit( DeclStmt *declStmt ) {
    721698                declStmt->get_decl()->accept( *this );
    722 
     699       
    723700                if ( doSemicolon( declStmt->get_decl() ) ) {
    724701                        output << ";";
Note: See TracChangeset for help on using the changeset viewer.