Changeset 28e58fd for src/CodeGen


Ignore:
Timestamp:
Aug 25, 2017, 10:38:34 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
800d275
Parents:
af08051 (diff), 3eab308c (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

Location:
src/CodeGen
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    raf08051 r28e58fd  
    192192                        genCommaList( aggDecl->get_parameters().begin(), aggDecl->get_parameters().end() );
    193193                        output << ")" << endl;
     194                        output << indent;
    194195                }
    195196
     
    205206                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    206207                                updateLocation( *i );
     208                                output << indent;
    207209                                (*i)->accept( *this );
    208210                                output << ";" << endl;
     
    244246                                assert( obj );
    245247                                updateLocation( obj );
    246                                 output << mangleName( obj );
     248                                output << indent << mangleName( obj );
    247249                                if ( obj->get_init() ) {
    248250                                        output << " = ";
     
    332334        void CodeGenerator::visit( __attribute__((unused)) ConstructorInit * init ){
    333335                assertf( ! genC, "ConstructorInit nodes should not reach code generation." );
    334                 // xxx - generate something reasonable for constructor/destructor pairs
    335                 output << "<ctorinit>";
     336                // pseudo-output for constructor/destructor pairs
     337                output << "<ctorinit>{" << std::endl << ++indent << "ctor: ";
     338                maybeAccept( init->get_ctor(), *this );
     339                output << ", " << std::endl << indent << "dtor: ";
     340                maybeAccept( init->get_dtor(), *this );
     341                output << std::endl << --indent << "}";
    336342        }
    337343
     
    347353                        if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) {
    348354                                std::list< Expression* >::iterator arg = applicationExpr->get_args().begin();
    349                                 switch ( opInfo.type ) {
    350                                   case OT_PREFIXASSIGN:
    351                                   case OT_POSTFIXASSIGN:
    352                                   case OT_INFIXASSIGN:
    353                                   case OT_CTOR:
    354                                   case OT_DTOR:
    355                                         {
    356                                                 assert( arg != applicationExpr->get_args().end() );
    357                                                 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
    358                                                         // remove & from first assignment/ctor argument
    359                                                         *arg = addrExpr->get_arg();
    360                                                 } else {
    361                                                         // no address-of operator, so must be a pointer - add dereference
    362                                                         // NOTE: if the assertion starts to trigger, check that the application expr isn't being shared.
    363                                                         // Since its arguments are modified here, this assertion most commonly triggers when the application
    364                                                         // is visited multiple times.
    365                                                         UntypedExpr * newExpr = new UntypedExpr( new NameExpr( "*?" ) );
    366                                                         newExpr->get_args().push_back( *arg );
    367                                                         Type * type = InitTweak::getPointerBase( (*arg)->get_result() );
    368                                                         assertf( type, "First argument to a derefence must be a pointer. Ensure that expressions are not being shared." );
    369                                                         newExpr->set_result( type->clone() );
    370                                                         *arg = newExpr;
    371                                                 } // if
    372                                                 break;
    373                                         }
    374 
    375                                   default:
    376                                         // do nothing
    377                                         ;
    378                                 } // switch
    379 
    380355                                switch ( opInfo.type ) {
    381356                                  case OT_INDEX:
     
    584559                if ( castExpr->get_result()->isVoid() ) {
    585560                        output << "(void)" ;
    586                 } else if ( ! castExpr->get_result()->get_lvalue() ) {
    587                         // at least one result type of cast, but not an lvalue
     561                } else {
     562                        // at least one result type of cast.
     563                        // Note: previously, lvalue casts were skipped. Since it's now impossible for the user to write
     564                        // an lvalue cast, this has been taken out.
    588565                        output << "(";
    589566                        output << genType( castExpr->get_result(), "", pretty, genC );
    590567                        output << ")";
    591                 } else {
    592                         // otherwise, the cast is to an lvalue type, so the cast should be dropped, since the result of a cast is
    593                         // never an lvalue in C
    594568                } // if
    595569                castExpr->get_arg()->accept( *this );
     
    706680                extension( commaExpr );
    707681                output << "(";
     682                if ( genC ) {
     683                        // arg1 of a CommaExpr is never used, so it can be safely cast to void to reduce gcc warnings.
     684                        commaExpr->set_arg1( new CastExpr( commaExpr->get_arg1() ) );
     685                }
    708686                commaExpr->get_arg1()->accept( *this );
    709687                output << " , ";
    710688                commaExpr->get_arg2()->accept( *this );
    711689                output << ")";
     690        }
     691
     692        void CodeGenerator::visit( TupleAssignExpr * tupleExpr ) {
     693                assertf( ! genC, "TupleAssignExpr should not reach code generation." );
     694                tupleExpr->stmtExpr->accept( *this );
    712695        }
    713696
     
    759742                output << "(" << genType( compLitExpr->get_result(), "", pretty, genC ) << ")";
    760743                compLitExpr->get_initializer()->accept( *this );
     744        }
     745
     746        void CodeGenerator::visit( UniqueExpr * unqExpr ) {
     747                assertf( ! genC, "Unique expressions should not reach code generation." );
     748                output << "unq<" << unqExpr->get_id() << ">{ ";
     749                unqExpr->get_expr()->accept( *this );
     750                output << " }";
    761751        }
    762752
     
    770760                for ( Statement * stmt : stmts ) {
    771761                        updateLocation( stmt );
    772             output << printLabels( stmt->get_labels() );
     762                        output << printLabels( stmt->get_labels() );
    773763                        if ( i+1 == numStmts ) {
    774764                                // last statement in a statement expression needs to be handled specially -
     
    815805        void CodeGenerator::visit( ExprStmt * exprStmt ) {
    816806                assert( exprStmt );
    817                 Expression * expr = exprStmt->get_expr();
    818807                if ( genC ) {
    819808                        // cast the top-level expression to void to reduce gcc warnings.
    820                         expr = new CastExpr( expr );
    821                 }
    822                 expr->accept( *this );
     809                        exprStmt->set_expr( new CastExpr( exprStmt->get_expr() ) );
     810                }
     811                exprStmt->get_expr()->accept( *this );
    823812                output << ";";
    824813        }
  • src/CodeGen/CodeGenerator.h

    raf08051 r28e58fd  
    7474                virtual void visit( CommaExpr *commaExpr );
    7575                virtual void visit( CompoundLiteralExpr *compLitExpr );
     76                virtual void visit( UniqueExpr * );
     77                virtual void visit( TupleAssignExpr * tupleExpr );
    7678                virtual void visit( UntypedTupleExpr *tupleExpr );
    7779                virtual void visit( TupleExpr *tupleExpr );
  • src/CodeGen/GenType.cc

    raf08051 r28e58fd  
    3737                virtual void visit( PointerType *pointerType );
    3838                virtual void visit( ArrayType *arrayType );
     39                virtual void visit( ReferenceType *refType );
    3940                virtual void visit( StructInstType *structInst );
    4041                virtual void visit( UnionInstType *unionInst );
     
    145146        void GenType::visit( ArrayType *arrayType ) {
    146147                genArray( arrayType->get_qualifiers(), arrayType->get_base(), arrayType->get_dimension(), arrayType->get_isVarLen(), arrayType->get_isStatic() );
     148        }
     149
     150        void GenType::visit( ReferenceType *refType ) {
     151                assert( refType->get_base() != 0);
     152                assertf( ! genC, "Reference types should not reach code generation." );
     153                handleQualifiers( refType );
     154                typeString = "&" + typeString;
     155                refType->get_base()->accept( *this );
    147156        }
    148157
     
    278287                        typeString = "_Atomic " + typeString;
    279288                } // if
     289                if ( type->get_lvalue() && ! genC ) {
     290                        // when not generating C code, print lvalue for debugging.
     291                        typeString = "lvalue " + typeString;
     292                }
    280293        }
    281294} // namespace CodeGen
  • src/CodeGen/OperatorTable.cc

    raf08051 r28e58fd  
    1414//
    1515
    16 #include <map>      // for map, _Rb_tree_const_iterator, map<>::const_iterator
    17 #include <utility>  // for pair
     16#include <algorithm>  // for any_of
     17#include <map>        // for map, _Rb_tree_const_iterator, map<>::const_iterator
     18#include <utility>    // for pair
    1819
    1920#include "OperatorTable.h"
     
    9394                } // if
    9495        }
     96
     97        /// determines if a given function name is one of the operator types between [begin, end)
     98        template<typename Iterator>
     99        bool isOperatorType( const std::string & funcName, Iterator begin, Iterator end ) {
     100                OperatorInfo info;
     101                if ( operatorLookup( funcName, info ) ) {
     102                        return std::find( begin, end, info.type ) != end;
     103                }
     104                return false;
     105        }
     106
     107        bool isConstructor( const std::string & funcName ) {
     108                static OperatorType types[] = { OT_CTOR };
     109                return isOperatorType( funcName, std::begin(types), std::end(types) );
     110        }
     111
     112        bool isDestructor( const std::string & funcName ) {
     113                static OperatorType types[] = { OT_DTOR };
     114                return isOperatorType( funcName, std::begin(types), std::end(types) );
     115        }
     116
     117        bool isAssignment( const std::string & funcName ) {
     118                static OperatorType types[] = { OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN };
     119                return isOperatorType( funcName, std::begin(types), std::end(types) );
     120        }
     121
     122        bool isCtorDtor( const std::string & funcName ) {
     123                static OperatorType types[] = { OT_CTOR, OT_DTOR };
     124                return isOperatorType( funcName, std::begin(types), std::end(types) );
     125        }
     126
     127        bool isCtorDtorAssign( const std::string & funcName ) {
     128                static OperatorType types[] = { OT_CTOR, OT_DTOR, OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN };
     129                return isOperatorType( funcName, std::begin(types), std::end(types) );
     130        }
    95131} // namespace CodeGen
    96132
  • src/CodeGen/OperatorTable.h

    raf08051 r28e58fd  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // OperatorTable.h -- 
     7// OperatorTable.h --
    88//
    99// Author           : Richard C. Bilson
     
    4242
    4343        bool operatorLookup( std::string funcName, OperatorInfo &info );
     44
     45        bool isConstructor( const std::string & );
     46        bool isDestructor( const std::string & );
     47        bool isAssignment( const std::string & );
     48        bool isCtorDtor( const std::string & );
     49        bool isCtorDtorAssign( const std::string & );
    4450} // namespace CodeGen
    4551
Note: See TracChangeset for help on using the changeset viewer.