Ignore:
Timestamp:
Feb 25, 2020, 1:17:33 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7dc2e015
Parents:
9fb8f01 (diff), dd9e1ca (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:

resolve conflict

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r9fb8f01 r3d5701e  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr May  2 10:47:00 2019
    13 // Update Count     : 497
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Feb 16 08:32:48 2020
     13// Update Count     : 532
    1414//
    1515#include "CodeGenerator.h"
     
    2323#include "InitTweak/InitTweak.h"     // for getPointerBase
    2424#include "OperatorTable.h"           // for OperatorInfo, operatorLookup
    25 #include "Parser/LinkageSpec.h"      // for Spec, Intrinsic
     25#include "SynTree/LinkageSpec.h"     // for Spec, Intrinsic
    2626#include "SynTree/Attribute.h"       // for Attribute
    2727#include "SynTree/BaseSyntaxNode.h"  // for BaseSyntaxNode
     
    3939        int CodeGenerator::tabsize = 4;
    4040
    41         // the kinds of statements that would ideally be followed by whitespace
     41        // The kinds of statements that would ideally be followed by whitespace.
    4242        bool wantSpacing( Statement * stmt) {
    4343                return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) ||
     
    7878        }
    7979
    80         /* Using updateLocation at the beginning of a node and endl
    81          * within a node should become the method of formating.
    82          */
     80        // Using updateLocation at the beginning of a node and endl within a node should become the method of formating.
    8381        void CodeGenerator::updateLocation( CodeLocation const & to ) {
    8482                // skip if linemarks shouldn't appear or if codelocation is unset
     
    9593                } else {
    9694                        output << "\n# " << to.first_line << " \"" << to.filename
    97                                << "\"\n" << indent;
     95                                   << "\"\n" << indent;
    9896                        currentLocation = to;
    9997                }
     
    131129
    132130        void CodeGenerator::genAttributes( list< Attribute * > & attributes ) {
    133           if ( attributes.empty() ) return;
     131                if ( attributes.empty() ) return;
    134132                output << "__attribute__ ((";
    135133                for ( list< Attribute * >::iterator attr( attributes.begin() );; ) {
     
    140138                                output << ")";
    141139                        } // if
    142                   if ( ++attr == attributes.end() ) break;
     140                        if ( ++attr == attributes.end() ) break;
    143141                        output << ",";                                                          // separator
    144142                } // for
     
    165163                previsit( (BaseSyntaxNode *)node );
    166164                GuardAction( [this, node](){
    167                         if ( options.printExprTypes && node->result ) {
    168                                 output << " /* " << genType( node->result, "", options ) << " */ ";
    169                         }
    170                 } );
     165                                if ( options.printExprTypes && node->result ) {
     166                                        output << " /* " << genType( node->result, "", options ) << " */ ";
     167                                }
     168                        } );
    171169        }
    172170
     
    198196                // deleted decls should never be used, so don't print them
    199197                if ( objectDecl->isDeleted && options.genC ) return;
    200                 if (objectDecl->get_name().empty() && options.genC ) {
     198
     199                // gcc allows an empty declarator (no name) for bit-fields and C states: 6.7.2.1 Structure and union specifiers,
     200                // point 4, page 113: If the (bit field) value is zero, the declaration shall have no declarator.  For anything
     201                // else, the anonymous name refers to the anonymous object for plan9 inheritance.
     202                if ( objectDecl->get_name().empty() && options.genC && ! objectDecl->get_bitfieldWidth() ) {
    201203                        // only generate an anonymous name when generating C code, otherwise it clutters the output too much
    202204                        static UniqueName name = { "__anonymous_object" };
    203205                        objectDecl->set_name( name.newName() );
    204             // Stops unused parameter warnings.
    205             if ( options.anonymousUnused ) {
    206                 objectDecl->attributes.push_back( new Attribute( "unused" ) );
    207             }
     206                        // Stops unused parameter warnings.
     207                        if ( options.anonymousUnused ) {
     208                                objectDecl->attributes.push_back( new Attribute( "unused" ) );
     209                        }
    208210                }
    209211
     
    395397                extension( applicationExpr );
    396398                if ( VariableExpr * varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) {
    397                         OperatorInfo opInfo;
    398                         if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) {
     399                        const OperatorInfo * opInfo;
     400                        if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && ( opInfo = operatorLookup( varExpr->get_var()->get_name() ) ) ) {
    399401                                std::list< Expression* >::iterator arg = applicationExpr->get_args().begin();
    400                                 switch ( opInfo.type ) {
     402                                switch ( opInfo->type ) {
    401403                                  case OT_INDEX:
    402404                                        assert( applicationExpr->get_args().size() == 2 );
     
    419421                                                output << "(";
    420422                                                (*arg++)->accept( *visitor );
    421                                                 output << ") /* " << opInfo.inputName << " */";
     423                                                output << ") /* " << opInfo->inputName << " */";
    422424                                        } else if ( applicationExpr->get_args().size() == 2 ) {
    423425                                                // intrinsic two parameter constructors are essentially bitwise assignment
    424426                                                output << "(";
    425427                                                (*arg++)->accept( *visitor );
    426                                                 output << opInfo.symbol;
     428                                                output << opInfo->symbol;
    427429                                                (*arg)->accept( *visitor );
    428                                                 output << ") /* " << opInfo.inputName << " */";
     430                                                output << ") /* " << opInfo->inputName << " */";
    429431                                        } else {
    430432                                                // no constructors with 0 or more than 2 parameters
     
    437439                                        assert( applicationExpr->get_args().size() == 1 );
    438440                                        output << "(";
    439                                         output << opInfo.symbol;
     441                                        output << opInfo->symbol;
    440442                                        (*arg)->accept( *visitor );
    441443                                        output << ")";
     
    446448                                        assert( applicationExpr->get_args().size() == 1 );
    447449                                        (*arg)->accept( *visitor );
    448                                         output << opInfo.symbol;
     450                                        output << opInfo->symbol;
    449451                                        break;
    450452
     
    455457                                        output << "(";
    456458                                        (*arg++)->accept( *visitor );
    457                                         output << opInfo.symbol;
     459                                        output << opInfo->symbol;
    458460                                        (*arg)->accept( *visitor );
    459461                                        output << ")";
     
    482484                extension( untypedExpr );
    483485                if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr->function ) ) {
    484                         OperatorInfo opInfo;
    485                         if ( operatorLookup( nameExpr->name, opInfo ) ) {
     486                        const OperatorInfo * opInfo = operatorLookup( nameExpr->name );
     487                        if ( opInfo ) {
    486488                                std::list< Expression* >::iterator arg = untypedExpr->args.begin();
    487                                 switch ( opInfo.type ) {
     489                                switch ( opInfo->type ) {
    488490                                  case OT_INDEX:
    489491                                        assert( untypedExpr->args.size() == 2 );
     
    504506                                                output << "(";
    505507                                                (*arg++)->accept( *visitor );
    506                                                 output << ") /* " << opInfo.inputName << " */";
     508                                                output << ") /* " << opInfo->inputName << " */";
    507509                                        } else if ( untypedExpr->get_args().size() == 2 ) {
    508510                                                // intrinsic two parameter constructors are essentially bitwise assignment
    509511                                                output << "(";
    510512                                                (*arg++)->accept( *visitor );
    511                                                 output << opInfo.symbol;
     513                                                output << opInfo->symbol;
    512514                                                (*arg)->accept( *visitor );
    513                                                 output << ") /* " << opInfo.inputName << " */";
     515                                                output << ") /* " << opInfo->inputName << " */";
    514516                                        } else {
    515517                                                // no constructors with 0 or more than 2 parameters
     
    517519                                                output << "(";
    518520                                                (*arg++)->accept( *visitor );
    519                                                 output << opInfo.symbol << "{ ";
     521                                                output << opInfo->symbol << "{ ";
    520522                                                genCommaList( arg, untypedExpr->args.end() );
    521                                                 output << "}) /* " << opInfo.inputName << " */";
     523                                                output << "}) /* " << opInfo->inputName << " */";
    522524                                        } // if
    523525                                        break;
     
    528530                                        assert( untypedExpr->args.size() == 1 );
    529531                                        output << "(";
    530                                         output << opInfo.symbol;
     532                                        output << opInfo->symbol;
    531533                                        (*arg)->accept( *visitor );
    532534                                        output << ")";
     
    537539                                        assert( untypedExpr->args.size() == 1 );
    538540                                        (*arg)->accept( *visitor );
    539                                         output << opInfo.symbol;
     541                                        output << opInfo->symbol;
    540542                                        break;
    541543
     
    545547                                        output << "(";
    546548                                        (*arg++)->accept( *visitor );
    547                                         output << opInfo.symbol;
     549                                        output << opInfo->symbol;
    548550                                        (*arg)->accept( *visitor );
    549551                                        output << ")";
     
    577579        void CodeGenerator::postvisit( NameExpr * nameExpr ) {
    578580                extension( nameExpr );
    579                 OperatorInfo opInfo;
    580                 if ( operatorLookup( nameExpr->name, opInfo ) ) {
    581                         if ( opInfo.type == OT_CONSTANT ) {
    582                                 output << opInfo.symbol;
     581                const OperatorInfo * opInfo = operatorLookup( nameExpr->name );
     582                if ( opInfo ) {
     583                        if ( opInfo->type == OT_CONSTANT ) {
     584                                output << opInfo->symbol;
    583585                        } else {
    584                                 output << opInfo.outputName;
     586                                output << opInfo->outputName;
    585587                        }
    586588                } else {
     
    650652        void CodeGenerator::postvisit( VariableExpr * variableExpr ) {
    651653                extension( variableExpr );
    652                 OperatorInfo opInfo;
    653                 if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( variableExpr->get_var()->get_name(), opInfo ) && opInfo.type == OT_CONSTANT ) {
    654                         output << opInfo.symbol;
     654                const OperatorInfo * opInfo;
     655                if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && (opInfo = operatorLookup( variableExpr->get_var()->get_name() )) && opInfo->type == OT_CONSTANT ) {
     656                        output << opInfo->symbol;
    655657                } else {
    656658                        output << mangleName( variableExpr->get_var() );
     
    782784
    783785        void CodeGenerator::postvisit( AsmExpr * asmExpr ) {
    784                 if ( asmExpr->get_inout() ) {
     786                if ( !asmExpr->inout.empty() ) {
    785787                        output << "[ ";
    786                         asmExpr->get_inout()->accept( *visitor );
     788                        output << asmExpr->inout;
    787789                        output << " ] ";
    788790                } // if
    789                 asmExpr->get_constraint()->accept( *visitor );
     791                asmExpr->constraint->accept( *visitor );
    790792                output << " ( ";
    791                 asmExpr->get_operand()->accept( *visitor );
     793                asmExpr->operand->accept( *visitor );
    792794                output << " )";
    793795        }
     
    10071009                  case BranchStmt::FallThroughDefault:
    10081010                        assertf( ! options.genC, "fallthru should not reach code generation." );
    1009                   output << "fallthru";
     1011                        output << "fallthru";
    10101012                        break;
    10111013                } // switch
     
    10311033
    10321034                output << ((throwStmt->get_kind() == ThrowStmt::Terminate) ?
    1033                            "throw" : "throwResume");
     1035                                   "throw" : "throwResume");
    10341036                if (throwStmt->get_expr()) {
    10351037                        output << " ";
     
    10461048
    10471049                output << ((stmt->get_kind() == CatchStmt::Terminate) ?
    1048                 "catch" : "catchResume");
     1050                                   "catch" : "catchResume");
    10491051                output << "( ";
    10501052                stmt->decl->accept( *visitor );
     
    11831185
    11841186        std::string genName( DeclarationWithType * decl ) {
    1185                 CodeGen::OperatorInfo opInfo;
    1186                 if ( operatorLookup( decl->get_name(), opInfo ) ) {
    1187                         return opInfo.outputName;
     1187                const OperatorInfo * opInfo = operatorLookup( decl->get_name() );
     1188                if ( opInfo ) {
     1189                        return opInfo->outputName;
    11881190                } else {
    11891191                        return decl->get_name();
Note: See TracChangeset for help on using the changeset viewer.