Ignore:
Timestamp:
May 6, 2016, 1:56:08 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, with_gc
Children:
d029162
Parents:
711eee5
Message:

Add constructor attribute to global initializer function, don't try to fix const globals, add Constructor/Destructor? attributes to FunctionDecl?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r711eee5 r4e24610  
    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 : Wed Mar  2 17:32:16 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Fri May 06 11:39:01 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
    8698                // how to get this to the Functype?
    8799                std::list< Declaration * > olds = functionDecl->get_oldDecls();
     
    99111                handleStorageClass( objectDecl );
    100112                output << genType( objectDecl->get_type(), mangleName( objectDecl ) );
    101        
     113
    102114                if ( objectDecl->get_init() ) {
    103115                        output << " = ";
     
    113125                if ( aggDecl->get_name() != "" )
    114126                        output << aggDecl->get_name();
    115        
     127
    116128                std::list< Declaration * > &memb = aggDecl->get_members();
    117129
     
    119131                        output << " {" << endl;
    120132
    121                         cur_indent += CodeGenerator::tabsize; 
     133                        cur_indent += CodeGenerator::tabsize;
    122134                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    123                                 output << indent; 
     135                                output << indent;
    124136                                (*i)->accept( *this );
    125137                                output << ";" << endl;
    126138                        }
    127139
    128                         cur_indent -= CodeGenerator::tabsize; 
     140                        cur_indent -= CodeGenerator::tabsize;
    129141
    130142                        output << indent << "}";
     
    141153                handleAggregate( aggregateDecl );
    142154        }
    143  
     155
    144156        void CodeGenerator::visit( EnumDecl *aggDecl ) {
    145157                output << "enum ";
     
    147159                if ( aggDecl->get_name() != "" )
    148160                        output << aggDecl->get_name();
    149        
     161
    150162                std::list< Declaration* > &memb = aggDecl->get_members();
    151163
     
    153165                        output << " {" << endl;
    154166
    155                         cur_indent += CodeGenerator::tabsize; 
     167                        cur_indent += CodeGenerator::tabsize;
    156168                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    157169                                ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
    158170                                assert( obj );
    159                                 output << indent << mangleName( obj ); 
     171                                output << indent << mangleName( obj );
    160172                                if ( obj->get_init() ) {
    161173                                        output << " = ";
     
    165177                        } // for
    166178
    167                         cur_indent -= CodeGenerator::tabsize; 
     179                        cur_indent -= CodeGenerator::tabsize;
    168180
    169181                        output << indent << "}";
    170182                } // if
    171183        }
    172  
     184
    173185        void CodeGenerator::visit( TraitDecl *aggregateDecl ) {}
    174  
     186
    175187        void CodeGenerator::visit( TypedefDecl *typeDecl ) {
    176188                output << "typedef ";
    177189                output << genType( typeDecl->get_base(), typeDecl->get_name() );
    178190        }
    179  
     191
    180192        void CodeGenerator::visit( TypeDecl *typeDecl ) {
    181193                // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes,
     
    217229        }
    218230
    219         void CodeGenerator::visit( Constant *constant ) { 
     231        void CodeGenerator::visit( Constant *constant ) {
    220232                output << constant->get_value() ;
    221233        }
     
    234246                                                assert( arg != applicationExpr->get_args().end() );
    235247                                                if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
    236                
     248
    237249                                                        *arg = addrExpr->get_arg();
    238250                                                } else {
     
    243255                                                break;
    244256                                        }
    245              
     257
    246258                                  default:
    247259                                        // do nothing
    248260                                        ;
    249261                                }
    250            
     262
    251263                                switch ( opInfo.type ) {
    252264                                  case OT_INDEX:
     
    257269                                        output << "]";
    258270                                        break;
    259              
     271
    260272                                  case OT_CALL:
    261273                                        // there are no intrinsic definitions of the function call operator
    262274                                        assert( false );
    263275                                        break;
    264              
     276
    265277                                  case OT_PREFIX:
    266278                                  case OT_PREFIXASSIGN:
     
    271283                                        output << ")";
    272284                                        break;
    273              
     285
    274286                                  case OT_POSTFIX:
    275287                                  case OT_POSTFIXASSIGN:
     
    288300                                        output << ")";
    289301                                        break;
    290              
     302
    291303                                  case OT_CONSTANT:
    292304                                  case OT_LABELADDRESS:
     
    307319                } // if
    308320        }
    309  
     321
    310322        void CodeGenerator::visit( UntypedExpr *untypedExpr ) {
    311323                if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
     
    321333                                        output << "]";
    322334                                        break;
    323              
     335
    324336                                  case OT_CALL:
    325337                                        assert( false );
    326338                                        break;
    327              
     339
    328340                                  case OT_PREFIX:
    329341                                  case OT_PREFIXASSIGN:
     
    335347                                        output << ")";
    336348                                        break;
    337              
     349
    338350                                  case OT_POSTFIX:
    339351                                  case OT_POSTFIXASSIGN:
     
    342354                                        output << opInfo.symbol;
    343355                                        break;
    344  
     356
    345357                                  case OT_INFIX:
    346358                                  case OT_INFIXASSIGN:
     
    352364                                        output << ")";
    353365                                        break;
    354                                        
     366
    355367                                  case OT_CONSTANT:
    356368                                        // there are no intrinsic definitions of 0 or 1 as functions
     
    370382                } // if
    371383        }
    372  
     384
    373385        void CodeGenerator::visit( NameExpr *nameExpr ) {
    374386                OperatorInfo opInfo;
     
    380392                } // if
    381393        }
    382  
     394
    383395        void CodeGenerator::visit( AddressExpr *addressExpr ) {
    384396                output << "(&";
     
    409421                output << ")";
    410422        }
    411  
     423
    412424        void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) {
    413425                assert( false );
    414426        }
    415  
     427
    416428        void CodeGenerator::visit( MemberExpr *memberExpr ) {
    417429                memberExpr->get_aggregate()->accept( *this );
    418430                output << "." << mangleName( memberExpr->get_member() );
    419431        }
    420  
     432
    421433        void CodeGenerator::visit( VariableExpr *variableExpr ) {
    422434                OperatorInfo opInfo;
     
    427439                } // if
    428440        }
    429  
     441
    430442        void CodeGenerator::visit( ConstantExpr *constantExpr ) {
    431443                assert( constantExpr->get_constant() );
    432444                constantExpr->get_constant()->accept( *this );
    433445        }
    434  
     446
    435447        void CodeGenerator::visit( SizeofExpr *sizeofExpr ) {
    436448                output << "sizeof(";
     
    469481                assert( false && "OffsetPackExpr should not reach code generation" );
    470482        }
    471  
     483
    472484        void CodeGenerator::visit( LogicalExpr *logicalExpr ) {
    473485                output << "(";
     
    481493                output << ")";
    482494        }
    483  
     495
    484496        void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) {
    485497                output << "(";
     
    491503                output << ")";
    492504        }
    493  
     505
    494506        void CodeGenerator::visit( CommaExpr *commaExpr ) {
    495507                output << "(";
     
    499511                output << ")";
    500512        }
    501  
     513
    502514        void CodeGenerator::visit( TupleExpr *tupleExpr ) {}
    503  
     515
    504516        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    505517
     
    532544                        }
    533545                }
    534                 cur_indent -= CodeGenerator::tabsize; 
     546                cur_indent -= CodeGenerator::tabsize;
    535547
    536548                output << indent << "}";
     
    538550
    539551        void CodeGenerator::visit( ExprStmt *exprStmt ) {
    540                 // I don't see why this check is necessary. 
    541                 // If this starts to cause problems then put it back in, 
     552                // I don't see why this check is necessary.
     553                // If this starts to cause problems then put it back in,
    542554                // with an explanation
    543555                assert( exprStmt );
     
    589601                switchStmt->get_condition()->accept( *this );
    590602                output << " ) ";
    591                
     603
    592604                output << "{" << std::endl;
    593605                cur_indent += CodeGenerator::tabsize;
     
    609621                } // if
    610622                output << ":\n";
    611                
     623
    612624                std::list<Statement *> sts = caseStmt->get_statements();
    613625
     
    626638                        if ( ! branchStmt->get_target().empty() )
    627639                                output << "goto " << branchStmt->get_target();
    628                         else { 
     640                        else {
    629641                                if ( branchStmt->get_computedTarget() != 0 ) {
    630642                                        output << "goto *";
     
    677689
    678690        void CodeGenerator::visit( ForStmt *forStmt ) {
    679                 // initialization is always hoisted, so don't 
    680                 // bother doing anything with that 
     691                // initialization is always hoisted, so don't
     692                // bother doing anything with that
    681693                output << "for (;";
    682694
     
    702714        void CodeGenerator::visit( DeclStmt *declStmt ) {
    703715                declStmt->get_decl()->accept( *this );
    704        
     716
    705717                if ( doSemicolon( declStmt->get_decl() ) ) {
    706718                        output << ";";
Note: See TracChangeset for help on using the changeset viewer.