Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r2a7b3ca r7b2c0a99  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 21 15:49:59 2017
    13 // Update Count     : 346
     12// Last Modified On : Sat May 13 09:26:38 2017
     13// Update Count     : 341
    1414//
    1515
     
    6262namespace GenPoly {
    6363        namespace {
     64                const std::list<Label> noLabels;
     65
    6466                FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars );
    6567
     
    101103                        void passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars );
    102104                        /// wraps a function application with a new temporary for the out-parameter return value
    103                         Expression *addRetParam( ApplicationExpr *appExpr, Type *retType, std::list< Expression *>::iterator &arg );
     105                        Expression *addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg );
    104106                        /// Replaces all the type parameters of a generic type with their concrete equivalents under the current environment
    105107                        void replaceParametersWithConcrete( ApplicationExpr *appExpr, std::list< Expression* >& params );
     
    108110                        Type *replaceWithConcrete( ApplicationExpr *appExpr, Type *type, bool doClone = true );
    109111                        /// wraps a function application returning a polymorphic type with a new temporary for the out-parameter return value
    110                         Expression *addDynRetParam( ApplicationExpr *appExpr, Type *polyType, std::list< Expression *>::iterator &arg );
     112                        Expression *addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *polyType, std::list< Expression *>::iterator &arg );
    111113                        Expression *applyAdapter( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars );
    112114                        void boxParam( Type *formal, Expression *&arg, const TyVarMap &exprTyVars );
     
    134136                  public:
    135137                        template< typename DeclClass >
    136                         DeclClass *handleDecl( DeclClass *decl );
     138                        DeclClass *handleDecl( DeclClass *decl, Type *type );
    137139                        template< typename AggDecl >
    138140                        AggDecl * handleAggDecl( AggDecl * aggDecl );
     
    341343        Statement *makeAlignTo( Expression *lhs, Expression *rhs ) {
    342344                // check that the lhs is zeroed out to the level of rhs
    343                 Expression *ifCond = makeOp( "?&?", lhs, makeOp( "?-?", rhs, new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
     345                Expression *ifCond = makeOp( "?&?", lhs, makeOp( "?-?", rhs, new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), "1" ) ) ) );
    344346                // if not aligned, increment to alignment
    345347                Expression *ifExpr = makeOp( "?+=?", lhs->clone(), makeOp( "?-?", rhs->clone(), ifCond->clone() ) );
     
    384386
    385387                // initialize size and alignment to 0 and 1 (will have at least one member to re-edit size)
    386                 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant::from_ulong( 0 ) ) ) );
    387                 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
     388                addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant( sizeAlignType->clone(), "0" ) ) ) );
     389                addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant( sizeAlignType->clone(), "1" ) ) ) );
    388390                unsigned long n_members = 0;
    389391                bool firstMember = true;
     
    441443
    442444                // calculate union layout in function body
    443                 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
    444                 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
     445                addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant( sizeAlignType->clone(), "1" ) ) ) );
     446                addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant( sizeAlignType->clone(), "1" ) ) ) );
    445447                for ( std::list< Declaration* >::const_iterator member = unionDecl->get_members().begin(); member != unionDecl->get_members().end(); ++member ) {
    446448                        DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member );
     
    504506                DeclarationWithType *Pass1::mutate( FunctionDecl *functionDecl ) {
    505507                        if ( functionDecl->get_statements() ) {         // empty routine body ?
    506                                 // std::cerr << "mutating function: " << functionDecl->get_mangleName() << std::endl;
    507508                                doBeginScope();
    508509                                scopeTyVars.beginScope();
     
    549550                                retval = oldRetval;
    550551                                doEndScope();
    551                                 // std::cerr << "end function: " << functionDecl->get_mangleName() << std::endl;
    552552                        } // if
    553553                        return functionDecl;
     
    665665                }
    666666
    667                 Expression *Pass1::addRetParam( ApplicationExpr *appExpr, Type *retType, std::list< Expression *>::iterator &arg ) {
     667                Expression *Pass1::addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg ) {
    668668                        // Create temporary to hold return value of polymorphic function and produce that temporary as a result
    669669                        // using a comma expression.
     
    728728                }
    729729
    730                 Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, Type *dynType, std::list< Expression *>::iterator &arg ) {
     730                Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *dynType, std::list< Expression *>::iterator &arg ) {
    731731                        assert( env );
    732732                        Type *concrete = replaceWithConcrete( appExpr, dynType );
    733733                        // add out-parameter for return value
    734                         return addRetParam( appExpr, concrete, arg );
     734                        return addRetParam( appExpr, function, concrete, arg );
    735735                }
    736736
     
    739739//                      if ( ! function->get_returnVals().empty() && isPolyType( function->get_returnVals().front()->get_type(), tyVars ) ) {
    740740                        if ( isDynRet( function, tyVars ) ) {
    741                                 ret = addRetParam( appExpr, function->get_returnVals().front()->get_type(), arg );
     741                                ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg );
    742742                        } // if
    743743                        std::string mangleName = mangleAdapterName( function, tyVars );
     
    11181118
    11191119                Expression *Pass1::mutate( ApplicationExpr *appExpr ) {
    1120                         // std::cerr << "mutate appExpr: " << InitTweak::getFunctionName( appExpr ) << std::endl;
     1120                        // std::cerr << "mutate appExpr: ";
    11211121                        // for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {
    11221122                        //      std::cerr << i->first << " ";
     
    11431143                        ReferenceToType *dynRetType = isDynRet( function, exprTyVars );
    11441144
    1145                         // std::cerr << function << std::endl;
    1146                         // std::cerr << "scopeTyVars: ";
    1147                         // printTyVarMap( std::cerr, scopeTyVars );
    1148                         // std::cerr << "exprTyVars: ";
    1149                         // printTyVarMap( std::cerr, exprTyVars );
    1150                         // std::cerr << "env: " << *env << std::endl;
    1151                         // std::cerr << needsAdapter( function, scopeTyVars ) << ! needsAdapter( function, exprTyVars) << std::endl;
    1152 
    11531145                        // NOTE: addDynRetParam needs to know the actual (generated) return type so it can make a temp variable, so pass the result type from the appExpr
    11541146                        // passTypeVars needs to know the program-text return type (i.e. the distinction between _conc_T30 and T3(int))
    11551147                        // concRetType may not be a good name in one or both of these places. A more appropriate name change is welcome.
    11561148                        if ( dynRetType ) {
    1157                                 // std::cerr << "dynRetType: " << dynRetType << std::endl;
    11581149                                Type *concRetType = appExpr->get_result()->isVoid() ? nullptr : appExpr->get_result();
    1159                                 ret = addDynRetParam( appExpr, concRetType, arg ); // xxx - used to use dynRetType instead of concRetType
     1150                                ret = addDynRetParam( appExpr, function, concRetType, arg ); // xxx - used to use dynRetType instead of concRetType
    11601151                        } else if ( needsAdapter( function, scopeTyVars ) && ! needsAdapter( function, exprTyVars) ) { // xxx - exprTyVars is used above...?
    11611152                                // xxx - the ! needsAdapter check may be incorrect. It seems there is some situation where an adapter is applied where it shouldn't be, and this fixes it for some cases. More investigation is needed.
     
    12911282
    12921283                template< typename DeclClass >
    1293                 DeclClass * Pass2::handleDecl( DeclClass *decl ) {
     1284                DeclClass * Pass2::handleDecl( DeclClass *decl, Type *type ) {
    12941285                        DeclClass *ret = static_cast< DeclClass *>( Parent::mutate( decl ) );
    12951286
     
    13051296
    13061297                DeclarationWithType * Pass2::mutate( FunctionDecl *functionDecl ) {
    1307                         functionDecl = safe_dynamic_cast< FunctionDecl * > ( handleDecl( functionDecl ) );
     1298                        functionDecl = safe_dynamic_cast< FunctionDecl * > ( handleDecl( functionDecl, functionDecl->get_functionType() ) );
    13081299                        FunctionType * ftype = functionDecl->get_functionType();
    13091300                        if ( ! ftype->get_returnVals().empty() && functionDecl->get_statements() ) {
     
    13301321
    13311322                ObjectDecl * Pass2::mutate( ObjectDecl *objectDecl ) {
    1332                         return handleDecl( objectDecl );
     1323                        return handleDecl( objectDecl, objectDecl->get_type() );
    13331324                }
    13341325
     
    13531344                        addToTyVarMap( typeDecl, scopeTyVars );
    13541345                        if ( typeDecl->get_base() ) {
    1355                                 return handleDecl( typeDecl );
     1346                                return handleDecl( typeDecl, typeDecl->get_base() );
    13561347                        } else {
    13571348                                return Parent::mutate( typeDecl );
     
    13601351
    13611352                TypedefDecl * Pass2::mutate( TypedefDecl *typedefDecl ) {
    1362                         return handleDecl( typedefDecl );
     1353                        return handleDecl( typedefDecl, typedefDecl->get_base() );
    13631354                }
    13641355
     
    15751566                /// Returns an index expression into the offset array for a type
    15761567                Expression *makeOffsetIndex( Type *objectType, long i ) {
    1577                         ConstantExpr *fieldIndex = new ConstantExpr( Constant::from_ulong( i ) );
     1568                        std::stringstream offset_namer;
     1569                        offset_namer << i;
     1570                        ConstantExpr *fieldIndex = new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), offset_namer.str() ) );
    15781571                        UntypedExpr *fieldOffset = new UntypedExpr( new NameExpr( "?[?]" ) );
    15791572                        fieldOffset->get_args().push_back( new NameExpr( offsetofName( mangleType( objectType ) ) ) );
     
    17881781                                // all union members are at offset zero
    17891782                                delete offsetofExpr;
    1790                                 return new ConstantExpr( Constant::from_ulong( 0 ) );
     1783                                return new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), "0" ) );
    17911784                        } else return offsetofExpr;
    17921785                }
     
    18131806                                        std::list< Initializer* > inits;
    18141807                                        for ( std::list< Declaration* >::const_iterator member = baseMembers.begin(); member != baseMembers.end(); ++member ) {
    1815                                                 if ( DeclarationWithType *memberDecl = dynamic_cast< DeclarationWithType* >( *member ) ) {
    1816                                                         inits.push_back( new SingleInit( new OffsetofExpr( ty->clone(), memberDecl ) ) );
     1808                                                DeclarationWithType *memberDecl;
     1809                                                if ( DeclarationWithType *origMember = dynamic_cast< DeclarationWithType* >( *member ) ) {
     1810                                                        memberDecl = origMember->clone();
    18171811                                                } else {
    1818                                                         assertf( false, "Requesting offset of Non-DWT member: %s", toString( *member ).c_str() );
     1812                                                        memberDecl = new ObjectDecl( (*member)->get_name(), Type::StorageClasses(), LinkageSpec::Cforall, 0, offsetType->clone(), 0 );
    18191813                                                }
     1814                                                inits.push_back( new SingleInit( new OffsetofExpr( ty->clone(), memberDecl ) ) );
    18201815                                        }
    18211816
Note: See TracChangeset for help on using the changeset viewer.