Ignore:
Timestamp:
Jul 5, 2016, 11:10:14 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, 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:
9bb81bb8
Parents:
a43e1d7 (diff), d32c4e2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    ra43e1d7 r39f04ec  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  9 13:21:00 2016
    13 // Update Count     : 256
     12// Last Modified On : Mon Jul  4 20:38:32 2016
     13// Update Count     : 300
    1414//
    1515
     
    4747                        dynamic_cast< WhileStmt * >( stmt ) || dynamic_cast< ForStmt * > ( stmt ) || dynamic_cast< SwitchStmt *>( stmt );
    4848        }
     49
     50        void CodeGenerator::extension( Expression *expr ) {
     51                if ( expr->get_extension() ) {
     52                        output << "__extension__ ";
     53                } // if
     54        } // extension
     55
     56        void CodeGenerator::extension( Declaration *decl ) {
     57                if ( decl->get_extension() ) {
     58                        output << "__extension__ ";
     59                } // if
     60        } // extension
    4961
    5062        ostream & CodeGenerator::Indenter::operator()( ostream & output ) const {
     
    110122        //*** Declarations
    111123        void CodeGenerator::visit( FunctionDecl *functionDecl ) {
     124                extension( functionDecl );
    112125                genAttributes( functionDecl->get_attributes() );
    113126
     
    134147
    135148        void CodeGenerator::visit( ObjectDecl *objectDecl ) {
     149                extension( objectDecl );
    136150                handleStorageClass( objectDecl );
    137151                output << genType( objectDecl->get_type(), mangleName( objectDecl ) );
     
    170184
    171185        void CodeGenerator::visit( StructDecl *structDecl ) {
     186                extension( structDecl );
    172187                output << "struct ";
    173188                handleAggregate( structDecl );
    174189        }
    175190
    176         void CodeGenerator::visit( UnionDecl *aggregateDecl ) {
     191        void CodeGenerator::visit( UnionDecl *unionDecl ) {
     192                extension( unionDecl );
    177193                output << "union ";
    178                 handleAggregate( aggregateDecl );
    179         }
    180 
    181         void CodeGenerator::visit( EnumDecl *aggDecl ) {
     194                handleAggregate( unionDecl );
     195        }
     196
     197        void CodeGenerator::visit( EnumDecl *enumDecl ) {
     198                extension( enumDecl );
    182199                output << "enum ";
    183200
    184                 if ( aggDecl->get_name() != "" )
    185                         output << aggDecl->get_name();
    186 
    187                 std::list< Declaration* > &memb = aggDecl->get_members();
     201                if ( enumDecl->get_name() != "" )
     202                        output << enumDecl->get_name();
     203
     204                std::list< Declaration* > &memb = enumDecl->get_members();
    188205
    189206                if ( ! memb.empty() ) {
     
    208225        }
    209226
    210         void CodeGenerator::visit( TraitDecl *aggregateDecl ) {}
     227        void CodeGenerator::visit( TraitDecl *traitDecl ) {}
    211228
    212229        void CodeGenerator::visit( TypedefDecl *typeDecl ) {
    213                 output << "typedef ";
    214                 output << genType( typeDecl->get_base(), typeDecl->get_name() );
     230                assert( false && "Typedefs are removed and substituted in earlier passes." );
     231                //output << "typedef ";
     232                //output << genType( typeDecl->get_base(), typeDecl->get_name() );
    215233        }
    216234
     
    218236                // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes,
    219237                // still to be done
     238                extension( typeDecl );
    220239                output << "extern unsigned long " << typeDecl->get_name();
    221240                if ( typeDecl->get_base() ) {
     
    251270                output << "{ ";
    252271                if ( init->begin_initializers() == init->end_initializers() ) {
    253                         // illegal to leave initializer list empty for scalar initializers,
    254                         // but always legal to have 0
     272                        // illegal to leave initializer list empty for scalar initializers, but always legal to have 0
    255273                        output << "0";
    256274                } else {
     
    317335                                  case OT_DTOR:
    318336                                        if ( applicationExpr->get_args().size() == 1 ) {
    319                                                 // the expression fed into a single parameter constructor or destructor
    320                                                 // may contain side effects, so must still output this expression
     337                                                // the expression fed into a single parameter constructor or destructor may contain side
     338                                                // effects, so must still output this expression
    321339                                                output << "(";
    322340                                                (*arg++)->accept( *this );
     
    403421                                  case OT_DTOR:
    404422                                        if ( untypedExpr->get_args().size() == 1 ) {
    405                                                 // the expression fed into a single parameter constructor or destructor
    406                                                 // may contain side effects, so must still output this expression
     423                                                // the expression fed into a single parameter constructor or destructor may contain side
     424                                                // effects, so must still output this expression
    407425                                                output << "(";
    408426                                                (*arg++)->accept( *this );
     
    500518                        output << ")";
    501519                } else {
    502                         // otherwise, the cast is to an lvalue type, so the cast
    503                         // should be dropped, since the result of a cast is
     520                        // otherwise, the cast is to an lvalue type, so the cast should be dropped, since the result of a cast is
    504521                        // never an lvalue in C
    505522                }
     
    546563
    547564        void CodeGenerator::visit( AlignofExpr *alignofExpr ) {
     565                // use GCC extension to avoid bumping std to C11
    548566                extension( alignofExpr );
    549                 // use GCC extension to avoid bumping std to C11
    550567                output << "__alignof__(";
    551568                if ( alignofExpr->get_isType() ) {
     
    558575
    559576        void CodeGenerator::visit( UntypedOffsetofExpr *offsetofExpr ) {
    560                 assert( false && "UntypedOffsetofExpr should not reach code generation" );
     577                assert( false && "UntypedOffsetofExpr should not reach code generation." );
    561578        }
    562579
    563580        void CodeGenerator::visit( OffsetofExpr *offsetofExpr ) {
    564                 extension( offsetofExpr );
    565581                // use GCC builtin
    566582                output << "__builtin_offsetof(";
     
    571587
    572588        void CodeGenerator::visit( OffsetPackExpr *offsetPackExpr ) {
    573                 assert( false && "OffsetPackExpr should not reach code generation" );
     589                assert( false && "OffsetPackExpr should not reach code generation." );
    574590        }
    575591
     
    612628
    613629        void CodeGenerator::visit( AsmExpr *asmExpr ) {
    614                 extension( asmExpr );
    615630                if ( asmExpr->get_inout() ) {
    616631                        output << "[ ";
     
    777792
    778793        void CodeGenerator::visit( ForStmt *forStmt ) {
    779                 // initialization is always hoisted, so don't
    780                 // bother doing anything with that
     794                // initialization is always hoisted, so don't bother doing anything with that
    781795                output << "for (;";
    782796
Note: See TracChangeset for help on using the changeset viewer.