Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r2a4b088 ra9a259c  
    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 : Peter A. Buhr
    12 // Last Modified On : Mon Jan 25 21:22:00 2016
    13 // Update Count     : 242
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Feb 09 13:24:40 2016
     13// Update Count     : 255
    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
     260                                        // there are no intrinsic definitions of the function call operator or constructors or destructors
    261261                                        assert( false );
    262262                                        break;
    263              
     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
    264281                                  case OT_PREFIX:
    265282                                  case OT_PREFIXASSIGN:
     
    270287                                        output << ")";
    271288                                        break;
    272              
     289
    273290                                  case OT_POSTFIX:
    274291                                  case OT_POSTFIXASSIGN:
     
    277294                                        output << opInfo.symbol;
    278295                                        break;
     296
    279297
    280298                                  case OT_INFIX:
     
    287305                                        output << ")";
    288306                                        break;
    289              
     307
    290308                                  case OT_CONSTANT:
    291309                                  case OT_LABELADDRESS:
     
    306324                } // if
    307325        }
    308  
     326
    309327        void CodeGenerator::visit( UntypedExpr *untypedExpr ) {
    310328                if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
     
    320338                                        output << "]";
    321339                                        break;
    322              
     340
    323341                                  case OT_CALL:
    324342                                        assert( false );
    325                                         break;
    326              
     343
     344                                        case OT_CTOR:
     345                                        case OT_DTOR:
     346                                        // intrinsic constructors should never be called
     347                                        // intrinsic destructors do nothing
     348                                        break;
     349
    327350                                  case OT_PREFIX:
    328351                                  case OT_PREFIXASSIGN:
     
    334357                                        output << ")";
    335358                                        break;
    336              
     359
    337360                                  case OT_POSTFIX:
    338361                                  case OT_POSTFIXASSIGN:
     
    341364                                        output << opInfo.symbol;
    342365                                        break;
    343  
     366
    344367                                  case OT_INFIX:
    345368                                  case OT_INFIXASSIGN:
     
    351374                                        output << ")";
    352375                                        break;
    353                                        
     376
    354377                                  case OT_CONSTANT:
    355378                                        // there are no intrinsic definitions of 0 or 1 as functions
     
    369392                } // if
    370393        }
    371  
     394
    372395        void CodeGenerator::visit( NameExpr *nameExpr ) {
    373396                OperatorInfo opInfo;
     
    379402                } // if
    380403        }
    381  
     404
    382405        void CodeGenerator::visit( AddressExpr *addressExpr ) {
    383406                output << "(&";
     
    408431                output << ")";
    409432        }
    410  
     433
    411434        void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) {
    412435                assert( false );
    413436        }
    414  
     437
    415438        void CodeGenerator::visit( MemberExpr *memberExpr ) {
    416439                memberExpr->get_aggregate()->accept( *this );
    417440                output << "." << mangleName( memberExpr->get_member() );
    418441        }
    419  
     442
    420443        void CodeGenerator::visit( VariableExpr *variableExpr ) {
    421444                OperatorInfo opInfo;
     
    426449                } // if
    427450        }
    428  
     451
    429452        void CodeGenerator::visit( ConstantExpr *constantExpr ) {
    430453                assert( constantExpr->get_constant() );
    431454                constantExpr->get_constant()->accept( *this );
    432455        }
    433  
     456
    434457        void CodeGenerator::visit( SizeofExpr *sizeofExpr ) {
    435458                output << "sizeof(";
     
    464487                output << ")";
    465488        }
    466  
     489
    467490        void CodeGenerator::visit( LogicalExpr *logicalExpr ) {
    468491                output << "(";
     
    476499                output << ")";
    477500        }
    478  
     501
    479502        void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) {
    480503                output << "(";
     
    486509                output << ")";
    487510        }
    488  
     511
    489512        void CodeGenerator::visit( CommaExpr *commaExpr ) {
    490513                output << "(";
     
    494517                output << ")";
    495518        }
    496  
     519
    497520        void CodeGenerator::visit( TupleExpr *tupleExpr ) {}
    498  
     521
    499522        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    500523
     
    527550                        }
    528551                }
    529                 cur_indent -= CodeGenerator::tabsize; 
     552                cur_indent -= CodeGenerator::tabsize;
    530553
    531554                output << indent << "}";
     
    533556
    534557        void CodeGenerator::visit( ExprStmt *exprStmt ) {
    535                 // I don't see why this check is necessary. 
    536                 // If this starts to cause problems then put it back in, 
     558                // I don't see why this check is necessary.
     559                // If this starts to cause problems then put it back in,
    537560                // with an explanation
    538561                assert( exprStmt );
     
    584607                switchStmt->get_condition()->accept( *this );
    585608                output << " ) ";
    586                
     609
    587610                output << "{" << std::endl;
    588611                cur_indent += CodeGenerator::tabsize;
     
    604627                } // if
    605628                output << ":\n";
    606                
     629
    607630                std::list<Statement *> sts = caseStmt->get_statements();
    608631
     
    621644                        if ( ! branchStmt->get_target().empty() )
    622645                                output << "goto " << branchStmt->get_target();
    623                         else { 
     646                        else {
    624647                                if ( branchStmt->get_computedTarget() != 0 ) {
    625648                                        output << "goto *";
     
    672695
    673696        void CodeGenerator::visit( ForStmt *forStmt ) {
    674                 // initialization is always hoisted, so don't 
    675                 // bother doing anything with that 
     697                // initialization is always hoisted, so don't
     698                // bother doing anything with that
    676699                output << "for (;";
    677700
     
    697720        void CodeGenerator::visit( DeclStmt *declStmt ) {
    698721                declStmt->get_decl()->accept( *this );
    699        
     722
    700723                if ( doSemicolon( declStmt->get_decl() ) ) {
    701724                        output << ";";
Note: See TracChangeset for help on using the changeset viewer.