Changes in / [d67a9a1:00ede9e]


Ignore:
Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rd67a9a1 r00ede9e  
    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
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Sep 17 15:24:08 2015
    13 // Update Count     : 231
     12// Last Modified On : Wed Jan 20 12:54:50 2016
     13// Update Count     : 241
    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:
    260260                                        // there are no intrinsic definitions of the function call operator
    261261                                        assert( false );
    262262                                        break;
    263              
     263
    264264                                  case OT_PREFIX:
    265265                                  case OT_PREFIXASSIGN:
     
    270270                                        output << ")";
    271271                                        break;
    272              
     272
    273273                                  case OT_POSTFIX:
    274274                                  case OT_POSTFIXASSIGN:
     
    287287                                        output << ")";
    288288                                        break;
    289              
     289
    290290                                  case OT_CONSTANT:
    291291                                  case OT_LABELADDRESS:
     
    306306                } // if
    307307        }
    308  
     308
    309309        void CodeGenerator::visit( UntypedExpr *untypedExpr ) {
    310310                if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
     
    320320                                        output << "]";
    321321                                        break;
    322              
     322
    323323                                  case OT_CALL:
    324324                                        assert( false );
    325325                                        break;
    326              
     326
    327327                                  case OT_PREFIX:
    328328                                  case OT_PREFIXASSIGN:
     
    334334                                        output << ")";
    335335                                        break;
    336              
     336
    337337                                  case OT_POSTFIX:
    338338                                  case OT_POSTFIXASSIGN:
     
    341341                                        output << opInfo.symbol;
    342342                                        break;
    343  
     343
    344344                                  case OT_INFIX:
    345345                                  case OT_INFIXASSIGN:
     
    351351                                        output << ")";
    352352                                        break;
    353                                        
     353
    354354                                  case OT_CONSTANT:
    355355                                        // there are no intrinsic definitions of 0 or 1 as functions
     
    369369                } // if
    370370        }
    371  
     371
    372372        void CodeGenerator::visit( NameExpr *nameExpr ) {
    373373                OperatorInfo opInfo;
     
    379379                } // if
    380380        }
    381  
     381
    382382        void CodeGenerator::visit( AddressExpr *addressExpr ) {
    383383                output << "(&";
     
    392392
    393393        void CodeGenerator::visit( CastExpr *castExpr ) {
    394                 // if the cast is to an lvalue type, then the cast
    395                 // should be dropped, since the result of a cast is
    396                 // never an lvalue in C
    397                 if ( castExpr->get_results().front()->get_isLvalue() ) {
    398                         castExpr->get_arg()->accept( *this );
    399                 } else {
    400                         output << "((";
    401                         if ( castExpr->get_results().empty() ) {
    402                                 output << "void" ;
    403                         } else {
    404                                 output << genType( castExpr->get_results().front(), "" );
    405                         } // if
     394                output << "(";
     395                if ( castExpr->get_results().empty() ) {
     396                        output << "(void)" ;
     397                } else if ( ! castExpr->get_results().front()->get_isLvalue() ) {
     398                        // at least one result type of cast, but not an lvalue
     399                        output << "(";
     400                        output << genType( castExpr->get_results().front(), "" );
    406401                        output << ")";
    407                         castExpr->get_arg()->accept( *this );
    408                         output << ")";                 
     402                } else {
     403                        // otherwise, the cast is to an lvalue type, so the cast
     404                        // should be dropped, since the result of a cast is
     405                        // never an lvalue in C
    409406                }
    410         }
    411  
     407                castExpr->get_arg()->accept( *this );
     408                output << ")";
     409        }
     410
    412411        void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) {
    413412                assert( false );
    414413        }
    415  
     414
    416415        void CodeGenerator::visit( MemberExpr *memberExpr ) {
    417416                memberExpr->get_aggregate()->accept( *this );
    418417                output << "." << mangleName( memberExpr->get_member() );
    419418        }
    420  
     419
    421420        void CodeGenerator::visit( VariableExpr *variableExpr ) {
    422421                OperatorInfo opInfo;
     
    427426                } // if
    428427        }
    429  
     428
    430429        void CodeGenerator::visit( ConstantExpr *constantExpr ) {
    431430                assert( constantExpr->get_constant() );
    432431                constantExpr->get_constant()->accept( *this );
    433432        }
    434  
     433
    435434        void CodeGenerator::visit( SizeofExpr *sizeofExpr ) {
    436435                output << "sizeof(";
     
    453452                output << ")";
    454453        }
    455  
     454
    456455        void CodeGenerator::visit( LogicalExpr *logicalExpr ) {
    457456                output << "(";
     
    465464                output << ")";
    466465        }
    467  
     466
    468467        void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) {
    469468                output << "(";
     
    475474                output << ")";
    476475        }
    477  
     476
    478477        void CodeGenerator::visit( CommaExpr *commaExpr ) {
    479478                output << "(";
     
    483482                output << ")";
    484483        }
    485  
     484
    486485        void CodeGenerator::visit( TupleExpr *tupleExpr ) {}
    487  
     486
    488487        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    489488
     
    516515                        }
    517516                }
    518                 cur_indent -= CodeGenerator::tabsize; 
     517                cur_indent -= CodeGenerator::tabsize;
    519518
    520519                output << indent << "}";
     
    522521
    523522        void CodeGenerator::visit( ExprStmt *exprStmt ) {
    524                 // I don't see why this check is necessary. 
    525                 // If this starts to cause problems then put it back in, 
     523                // I don't see why this check is necessary.
     524                // If this starts to cause problems then put it back in,
    526525                // with an explanation
    527526                assert( exprStmt );
     
    573572                switchStmt->get_condition()->accept( *this );
    574573                output << " ) ";
    575                
     574
    576575                output << "{" << std::endl;
    577576                cur_indent += CodeGenerator::tabsize;
     
    593592                } // if
    594593                output << ":\n";
    595                
     594
    596595                std::list<Statement *> sts = caseStmt->get_statements();
    597596
     
    610609                        if ( ! branchStmt->get_target().empty() )
    611610                                output << "goto " << branchStmt->get_target();
    612                         else { 
     611                        else {
    613612                                if ( branchStmt->get_computedTarget() != 0 ) {
    614613                                        output << "goto *";
     
    661660
    662661        void CodeGenerator::visit( ForStmt *forStmt ) {
    663                 // initialization is always hoisted, so don't 
    664                 // bother doing anything with that 
     662                // initialization is always hoisted, so don't
     663                // bother doing anything with that
    665664                output << "for (;";
    666665
     
    686685        void CodeGenerator::visit( DeclStmt *declStmt ) {
    687686                declStmt->get_decl()->accept( *this );
    688        
     687
    689688                if ( doSemicolon( declStmt->get_decl() ) ) {
    690689                        output << ";";
  • src/GenPoly/Specialize.cc

    rd67a9a1 r00ede9e  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Specialize.cc -- 
     7// Specialize.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Sep 22 14:04:13 2015
    13 // Update Count     : 15
     12// Last Modified On : Wed Jan 20 12:40:33 2016
     13// Update Count     : 18
    1414//
    1515
     
    140140                return new AddressExpr( new VariableExpr( thunkFunc ) );
    141141        }
    142        
     142
    143143        Expression * Specialize::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) {
     144                assert( ! actual->get_results().empty() );
    144145                if ( needsSpecialization( formalType, actual->get_results().front(), env ) ) {
    145146                        FunctionType *funType;
     
    198199        Expression * Specialize::mutate( CastExpr *castExpr ) {
    199200                castExpr->get_arg()->acceptMutator( *this );
     201                if ( castExpr->get_results().empty() ) {
     202                        // can't specialize if we don't have a return value
     203                        return castExpr;
     204                }
    200205                Expression *specialized = doSpecialization( castExpr->get_results().front(), castExpr->get_arg() );
    201206                if ( specialized != castExpr->get_arg() ) {
Note: See TracChangeset for help on using the changeset viewer.