Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r4e24610 rafc1045  
    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 : Fri May 06 11:39:01 2016
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Mar  2 17:32:16 2016
    1313// Update Count     : 243
    1414//
     
    8484                output << genType( functionDecl->get_functionType(), mangleName( functionDecl ) );
    8585
    86                 // generalize this
    87                 switch ( functionDecl->get_attribute() ) {
    88                         case FunctionDecl::Constructor:
    89                                 output << " __attribute__ ((constructor))";
    90                                 break;
    91                         case FunctionDecl::Destructor:
    92                                 output << " __attribute__ ((destructor))";
    93                                 break;
    94                         default:
    95                                 break;
    96                 }
    97 
    9886                // how to get this to the Functype?
    9987                std::list< Declaration * > olds = functionDecl->get_oldDecls();
     
    11199                handleStorageClass( objectDecl );
    112100                output << genType( objectDecl->get_type(), mangleName( objectDecl ) );
    113 
     101       
    114102                if ( objectDecl->get_init() ) {
    115103                        output << " = ";
     
    125113                if ( aggDecl->get_name() != "" )
    126114                        output << aggDecl->get_name();
    127 
     115       
    128116                std::list< Declaration * > &memb = aggDecl->get_members();
    129117
     
    131119                        output << " {" << endl;
    132120
    133                         cur_indent += CodeGenerator::tabsize;
     121                        cur_indent += CodeGenerator::tabsize; 
    134122                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    135                                 output << indent;
     123                                output << indent; 
    136124                                (*i)->accept( *this );
    137125                                output << ";" << endl;
    138126                        }
    139127
    140                         cur_indent -= CodeGenerator::tabsize;
     128                        cur_indent -= CodeGenerator::tabsize; 
    141129
    142130                        output << indent << "}";
     
    153141                handleAggregate( aggregateDecl );
    154142        }
    155 
     143 
    156144        void CodeGenerator::visit( EnumDecl *aggDecl ) {
    157145                output << "enum ";
     
    159147                if ( aggDecl->get_name() != "" )
    160148                        output << aggDecl->get_name();
    161 
     149       
    162150                std::list< Declaration* > &memb = aggDecl->get_members();
    163151
     
    165153                        output << " {" << endl;
    166154
    167                         cur_indent += CodeGenerator::tabsize;
     155                        cur_indent += CodeGenerator::tabsize; 
    168156                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    169157                                ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
    170158                                assert( obj );
    171                                 output << indent << mangleName( obj );
     159                                output << indent << mangleName( obj ); 
    172160                                if ( obj->get_init() ) {
    173161                                        output << " = ";
     
    177165                        } // for
    178166
    179                         cur_indent -= CodeGenerator::tabsize;
     167                        cur_indent -= CodeGenerator::tabsize; 
    180168
    181169                        output << indent << "}";
    182170                } // if
    183171        }
    184 
     172 
    185173        void CodeGenerator::visit( TraitDecl *aggregateDecl ) {}
    186 
     174 
    187175        void CodeGenerator::visit( TypedefDecl *typeDecl ) {
    188176                output << "typedef ";
    189177                output << genType( typeDecl->get_base(), typeDecl->get_name() );
    190178        }
    191 
     179 
    192180        void CodeGenerator::visit( TypeDecl *typeDecl ) {
    193181                // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes,
     
    229217        }
    230218
    231         void CodeGenerator::visit( Constant *constant ) {
     219        void CodeGenerator::visit( Constant *constant ) { 
    232220                output << constant->get_value() ;
    233221        }
     
    246234                                                assert( arg != applicationExpr->get_args().end() );
    247235                                                if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
    248 
     236               
    249237                                                        *arg = addrExpr->get_arg();
    250238                                                } else {
     
    255243                                                break;
    256244                                        }
    257 
     245             
    258246                                  default:
    259247                                        // do nothing
    260248                                        ;
    261249                                }
    262 
     250           
    263251                                switch ( opInfo.type ) {
    264252                                  case OT_INDEX:
     
    269257                                        output << "]";
    270258                                        break;
    271 
     259             
    272260                                  case OT_CALL:
    273261                                        // there are no intrinsic definitions of the function call operator
    274262                                        assert( false );
    275263                                        break;
    276 
     264             
    277265                                  case OT_PREFIX:
    278266                                  case OT_PREFIXASSIGN:
     
    283271                                        output << ")";
    284272                                        break;
    285 
     273             
    286274                                  case OT_POSTFIX:
    287275                                  case OT_POSTFIXASSIGN:
     
    300288                                        output << ")";
    301289                                        break;
    302 
     290             
    303291                                  case OT_CONSTANT:
    304292                                  case OT_LABELADDRESS:
     
    319307                } // if
    320308        }
    321 
     309 
    322310        void CodeGenerator::visit( UntypedExpr *untypedExpr ) {
    323311                if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
     
    333321                                        output << "]";
    334322                                        break;
    335 
     323             
    336324                                  case OT_CALL:
    337325                                        assert( false );
    338326                                        break;
    339 
     327             
    340328                                  case OT_PREFIX:
    341329                                  case OT_PREFIXASSIGN:
     
    347335                                        output << ")";
    348336                                        break;
    349 
     337             
    350338                                  case OT_POSTFIX:
    351339                                  case OT_POSTFIXASSIGN:
     
    354342                                        output << opInfo.symbol;
    355343                                        break;
    356 
     344 
    357345                                  case OT_INFIX:
    358346                                  case OT_INFIXASSIGN:
     
    364352                                        output << ")";
    365353                                        break;
    366 
     354                                       
    367355                                  case OT_CONSTANT:
    368356                                        // there are no intrinsic definitions of 0 or 1 as functions
     
    382370                } // if
    383371        }
    384 
     372 
    385373        void CodeGenerator::visit( NameExpr *nameExpr ) {
    386374                OperatorInfo opInfo;
     
    392380                } // if
    393381        }
    394 
     382 
    395383        void CodeGenerator::visit( AddressExpr *addressExpr ) {
    396384                output << "(&";
     
    421409                output << ")";
    422410        }
    423 
     411 
    424412        void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) {
    425413                assert( false );
    426414        }
    427 
     415 
    428416        void CodeGenerator::visit( MemberExpr *memberExpr ) {
    429417                memberExpr->get_aggregate()->accept( *this );
    430418                output << "." << mangleName( memberExpr->get_member() );
    431419        }
    432 
     420 
    433421        void CodeGenerator::visit( VariableExpr *variableExpr ) {
    434422                OperatorInfo opInfo;
     
    439427                } // if
    440428        }
    441 
     429 
    442430        void CodeGenerator::visit( ConstantExpr *constantExpr ) {
    443431                assert( constantExpr->get_constant() );
    444432                constantExpr->get_constant()->accept( *this );
    445433        }
    446 
     434 
    447435        void CodeGenerator::visit( SizeofExpr *sizeofExpr ) {
    448436                output << "sizeof(";
     
    481469                assert( false && "OffsetPackExpr should not reach code generation" );
    482470        }
    483 
     471 
    484472        void CodeGenerator::visit( LogicalExpr *logicalExpr ) {
    485473                output << "(";
     
    493481                output << ")";
    494482        }
    495 
     483 
    496484        void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) {
    497485                output << "(";
     
    503491                output << ")";
    504492        }
    505 
     493 
    506494        void CodeGenerator::visit( CommaExpr *commaExpr ) {
    507495                output << "(";
     
    511499                output << ")";
    512500        }
    513 
     501 
    514502        void CodeGenerator::visit( TupleExpr *tupleExpr ) {}
    515 
     503 
    516504        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    517505
     
    544532                        }
    545533                }
    546                 cur_indent -= CodeGenerator::tabsize;
     534                cur_indent -= CodeGenerator::tabsize; 
    547535
    548536                output << indent << "}";
     
    550538
    551539        void CodeGenerator::visit( ExprStmt *exprStmt ) {
    552                 // I don't see why this check is necessary.
    553                 // If this starts to cause problems then put it back in,
     540                // I don't see why this check is necessary. 
     541                // If this starts to cause problems then put it back in, 
    554542                // with an explanation
    555543                assert( exprStmt );
     
    601589                switchStmt->get_condition()->accept( *this );
    602590                output << " ) ";
    603 
     591               
    604592                output << "{" << std::endl;
    605593                cur_indent += CodeGenerator::tabsize;
     
    621609                } // if
    622610                output << ":\n";
    623 
     611               
    624612                std::list<Statement *> sts = caseStmt->get_statements();
    625613
     
    638626                        if ( ! branchStmt->get_target().empty() )
    639627                                output << "goto " << branchStmt->get_target();
    640                         else {
     628                        else { 
    641629                                if ( branchStmt->get_computedTarget() != 0 ) {
    642630                                        output << "goto *";
     
    689677
    690678        void CodeGenerator::visit( ForStmt *forStmt ) {
    691                 // initialization is always hoisted, so don't
    692                 // bother doing anything with that
     679                // initialization is always hoisted, so don't 
     680                // bother doing anything with that 
    693681                output << "for (;";
    694682
     
    714702        void CodeGenerator::visit( DeclStmt *declStmt ) {
    715703                declStmt->get_decl()->accept( *this );
    716 
     704       
    717705                if ( doSemicolon( declStmt->get_decl() ) ) {
    718706                        output << ";";
Note: See TracChangeset for help on using the changeset viewer.