Changeset ae8b942 for src/CodeGen


Ignore:
Timestamp:
Jan 29, 2016, 4:36:46 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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, string, with_gc
Children:
5721a6d
Parents:
d3b7937 (diff), 73a28e2 (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 plg2:software/cfa/cfa-cc

Location:
src/CodeGen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rd3b7937 rae8b942  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // CodeGenerator.cc --
     7// CodeGenerator.cc -- 
    88//
    99// Author           : Richard C. Bilson
     
    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 << "(&";
     
    408408                output << ")";
    409409        }
    410 
     410 
    411411        void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) {
    412412                assert( false );
    413413        }
    414 
     414 
    415415        void CodeGenerator::visit( MemberExpr *memberExpr ) {
    416416                memberExpr->get_aggregate()->accept( *this );
    417417                output << "." << mangleName( memberExpr->get_member() );
    418418        }
    419 
     419 
    420420        void CodeGenerator::visit( VariableExpr *variableExpr ) {
    421421                OperatorInfo opInfo;
     
    426426                } // if
    427427        }
    428 
     428 
    429429        void CodeGenerator::visit( ConstantExpr *constantExpr ) {
    430430                assert( constantExpr->get_constant() );
    431431                constantExpr->get_constant()->accept( *this );
    432432        }
    433 
     433 
    434434        void CodeGenerator::visit( SizeofExpr *sizeofExpr ) {
    435435                output << "sizeof(";
     
    442442        }
    443443
    444         void CodeGenerator::visit( AlignofExpr *sizeofExpr ) {
     444        void CodeGenerator::visit( AlignofExpr *alignofExpr ) {
    445445                // use GCC extension to avoid bumping std to C11
    446446                output << "__alignof__(";
    447                 if ( sizeofExpr->get_isType() ) {
    448                         output << genType( sizeofExpr->get_type(), "" );
    449                 } else {
    450                         sizeofExpr->get_expr()->accept( *this );
     447                if ( alignofExpr->get_isType() ) {
     448                        output << genType( alignofExpr->get_type(), "" );
     449                } else {
     450                        alignofExpr->get_expr()->accept( *this );
    451451                } // if
    452452                output << ")";
    453453        }
    454454
     455        void CodeGenerator::visit( OffsetofExpr *offsetofExpr ) {
     456                // use GCC builtin
     457                output << "__builtin_offsetof(";
     458                output << genType( offsetofExpr->get_type(), "" );
     459                output << ", " << mangleName( offsetofExpr->get_member() );
     460                output << ")";
     461        }
     462 
    455463        void CodeGenerator::visit( LogicalExpr *logicalExpr ) {
    456464                output << "(";
     
    464472                output << ")";
    465473        }
    466 
     474 
    467475        void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) {
    468476                output << "(";
     
    474482                output << ")";
    475483        }
    476 
     484 
    477485        void CodeGenerator::visit( CommaExpr *commaExpr ) {
    478486                output << "(";
     
    482490                output << ")";
    483491        }
    484 
     492 
    485493        void CodeGenerator::visit( TupleExpr *tupleExpr ) {}
    486 
     494 
    487495        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    488496
     
    515523                        }
    516524                }
    517                 cur_indent -= CodeGenerator::tabsize;
     525                cur_indent -= CodeGenerator::tabsize; 
    518526
    519527                output << indent << "}";
     
    521529
    522530        void CodeGenerator::visit( ExprStmt *exprStmt ) {
    523                 // I don't see why this check is necessary.
    524                 // If this starts to cause problems then put it back in,
     531                // I don't see why this check is necessary. 
     532                // If this starts to cause problems then put it back in, 
    525533                // with an explanation
    526534                assert( exprStmt );
     
    572580                switchStmt->get_condition()->accept( *this );
    573581                output << " ) ";
    574 
     582               
    575583                output << "{" << std::endl;
    576584                cur_indent += CodeGenerator::tabsize;
     
    592600                } // if
    593601                output << ":\n";
    594 
     602               
    595603                std::list<Statement *> sts = caseStmt->get_statements();
    596604
     
    609617                        if ( ! branchStmt->get_target().empty() )
    610618                                output << "goto " << branchStmt->get_target();
    611                         else {
     619                        else { 
    612620                                if ( branchStmt->get_computedTarget() != 0 ) {
    613621                                        output << "goto *";
     
    660668
    661669        void CodeGenerator::visit( ForStmt *forStmt ) {
    662                 // initialization is always hoisted, so don't
    663                 // bother doing anything with that
     670                // initialization is always hoisted, so don't 
     671                // bother doing anything with that 
    664672                output << "for (;";
    665673
     
    685693        void CodeGenerator::visit( DeclStmt *declStmt ) {
    686694                declStmt->get_decl()->accept( *this );
    687 
     695       
    688696                if ( doSemicolon( declStmt->get_decl() ) ) {
    689697                        output << ";";
  • src/CodeGen/CodeGenerator.h

    rd3b7937 rae8b942  
    6161                virtual void visit( SizeofExpr *sizeofExpr );
    6262                virtual void visit( AlignofExpr *alignofExpr );
     63                virtual void visit( OffsetofExpr *offsetofExpr );
    6364                virtual void visit( LogicalExpr *logicalExpr );
    6465                virtual void visit( ConditionalExpr *conditionalExpr );
Note: See TracChangeset for help on using the changeset viewer.