Ignore:
Timestamp:
Feb 18, 2020, 8:48:49 PM (5 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:
6988dc6
Parents:
5ccee64
Message:

rewrite most of OperatorTable? and change caller modules to use new interface

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r5ccee64 r60a8062  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 23:13:28 2019
    13 // Update Count     : 508
     12// Last Modified On : Sun Feb 16 08:32:48 2020
     13// Update Count     : 532
    1414//
    1515#include "CodeGenerator.h"
     
    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
     
    399397                extension( applicationExpr );
    400398                if ( VariableExpr * varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) {
    401                         OperatorInfo opInfo;
    402                         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() ) ) ) {
    403401                                std::list< Expression* >::iterator arg = applicationExpr->get_args().begin();
    404                                 switch ( opInfo.type ) {
     402                                switch ( opInfo->type ) {
    405403                                  case OT_INDEX:
    406404                                        assert( applicationExpr->get_args().size() == 2 );
     
    423421                                                output << "(";
    424422                                                (*arg++)->accept( *visitor );
    425                                                 output << ") /* " << opInfo.inputName << " */";
     423                                                output << ") /* " << opInfo->inputName << " */";
    426424                                        } else if ( applicationExpr->get_args().size() == 2 ) {
    427425                                                // intrinsic two parameter constructors are essentially bitwise assignment
    428426                                                output << "(";
    429427                                                (*arg++)->accept( *visitor );
    430                                                 output << opInfo.symbol;
     428                                                output << opInfo->symbol;
    431429                                                (*arg)->accept( *visitor );
    432                                                 output << ") /* " << opInfo.inputName << " */";
     430                                                output << ") /* " << opInfo->inputName << " */";
    433431                                        } else {
    434432                                                // no constructors with 0 or more than 2 parameters
     
    441439                                        assert( applicationExpr->get_args().size() == 1 );
    442440                                        output << "(";
    443                                         output << opInfo.symbol;
     441                                        output << opInfo->symbol;
    444442                                        (*arg)->accept( *visitor );
    445443                                        output << ")";
     
    450448                                        assert( applicationExpr->get_args().size() == 1 );
    451449                                        (*arg)->accept( *visitor );
    452                                         output << opInfo.symbol;
     450                                        output << opInfo->symbol;
    453451                                        break;
    454452
     
    459457                                        output << "(";
    460458                                        (*arg++)->accept( *visitor );
    461                                         output << opInfo.symbol;
     459                                        output << opInfo->symbol;
    462460                                        (*arg)->accept( *visitor );
    463461                                        output << ")";
     
    486484                extension( untypedExpr );
    487485                if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr->function ) ) {
    488                         OperatorInfo opInfo;
    489                         if ( operatorLookup( nameExpr->name, opInfo ) ) {
     486                        const OperatorInfo * opInfo = operatorLookup( nameExpr->name );
     487                        if ( opInfo ) {
    490488                                std::list< Expression* >::iterator arg = untypedExpr->args.begin();
    491                                 switch ( opInfo.type ) {
     489                                switch ( opInfo->type ) {
    492490                                  case OT_INDEX:
    493491                                        assert( untypedExpr->args.size() == 2 );
     
    508506                                                output << "(";
    509507                                                (*arg++)->accept( *visitor );
    510                                                 output << ") /* " << opInfo.inputName << " */";
     508                                                output << ") /* " << opInfo->inputName << " */";
    511509                                        } else if ( untypedExpr->get_args().size() == 2 ) {
    512510                                                // intrinsic two parameter constructors are essentially bitwise assignment
    513511                                                output << "(";
    514512                                                (*arg++)->accept( *visitor );
    515                                                 output << opInfo.symbol;
     513                                                output << opInfo->symbol;
    516514                                                (*arg)->accept( *visitor );
    517                                                 output << ") /* " << opInfo.inputName << " */";
     515                                                output << ") /* " << opInfo->inputName << " */";
    518516                                        } else {
    519517                                                // no constructors with 0 or more than 2 parameters
     
    521519                                                output << "(";
    522520                                                (*arg++)->accept( *visitor );
    523                                                 output << opInfo.symbol << "{ ";
     521                                                output << opInfo->symbol << "{ ";
    524522                                                genCommaList( arg, untypedExpr->args.end() );
    525                                                 output << "}) /* " << opInfo.inputName << " */";
     523                                                output << "}) /* " << opInfo->inputName << " */";
    526524                                        } // if
    527525                                        break;
     
    532530                                        assert( untypedExpr->args.size() == 1 );
    533531                                        output << "(";
    534                                         output << opInfo.symbol;
     532                                        output << opInfo->symbol;
    535533                                        (*arg)->accept( *visitor );
    536534                                        output << ")";
     
    541539                                        assert( untypedExpr->args.size() == 1 );
    542540                                        (*arg)->accept( *visitor );
    543                                         output << opInfo.symbol;
     541                                        output << opInfo->symbol;
    544542                                        break;
    545543
     
    549547                                        output << "(";
    550548                                        (*arg++)->accept( *visitor );
    551                                         output << opInfo.symbol;
     549                                        output << opInfo->symbol;
    552550                                        (*arg)->accept( *visitor );
    553551                                        output << ")";
     
    581579        void CodeGenerator::postvisit( NameExpr * nameExpr ) {
    582580                extension( nameExpr );
    583                 OperatorInfo opInfo;
    584                 if ( operatorLookup( nameExpr->name, opInfo ) ) {
    585                         if ( opInfo.type == OT_CONSTANT ) {
    586                                 output << opInfo.symbol;
     581                const OperatorInfo * opInfo = operatorLookup( nameExpr->name );
     582                if ( opInfo ) {
     583                        if ( opInfo->type == OT_CONSTANT ) {
     584                                output << opInfo->symbol;
    587585                        } else {
    588                                 output << opInfo.outputName;
     586                                output << opInfo->outputName;
    589587                        }
    590588                } else {
     
    654652        void CodeGenerator::postvisit( VariableExpr * variableExpr ) {
    655653                extension( variableExpr );
    656                 OperatorInfo opInfo;
    657                 if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( variableExpr->get_var()->get_name(), opInfo ) && opInfo.type == OT_CONSTANT ) {
    658                         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;
    659657                } else {
    660658                        output << mangleName( variableExpr->get_var() );
     
    10111009                  case BranchStmt::FallThroughDefault:
    10121010                        assertf( ! options.genC, "fallthru should not reach code generation." );
    1013                   output << "fallthru";
     1011                        output << "fallthru";
    10141012                        break;
    10151013                } // switch
     
    10351033
    10361034                output << ((throwStmt->get_kind() == ThrowStmt::Terminate) ?
    1037                            "throw" : "throwResume");
     1035                                   "throw" : "throwResume");
    10381036                if (throwStmt->get_expr()) {
    10391037                        output << " ";
     
    10501048
    10511049                output << ((stmt->get_kind() == CatchStmt::Terminate) ?
    1052                 "catch" : "catchResume");
     1050                                   "catch" : "catchResume");
    10531051                output << "( ";
    10541052                stmt->decl->accept( *visitor );
     
    11871185
    11881186        std::string genName( DeclarationWithType * decl ) {
    1189                 CodeGen::OperatorInfo opInfo;
    1190                 if ( operatorLookup( decl->get_name(), opInfo ) ) {
    1191                         return opInfo.outputName;
     1187                const OperatorInfo * opInfo = operatorLookup( decl->get_name() );
     1188                if ( opInfo ) {
     1189                        return opInfo->outputName;
    11921190                } else {
    11931191                        return decl->get_name();
Note: See TracChangeset for help on using the changeset viewer.