Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r2e3a379 raa19ccf  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue May 03 16:44:47 2016
    13 // Update Count     : 295
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Feb  5 16:45:07 2016
     13// Update Count     : 286
    1414//
    1515
     
    133133                        Value *lookup( Key *key, const std::list< TypeExpr* >& params ) const {
    134134                                TypeList typeList( params );
    135 
     135                               
    136136                                // scan scopes for matches to the key
    137137                                for ( typename InnerMap::const_iterator insts = instantiations.find( key ); insts != instantiations.end(); insts = instantiations.findNext( insts, key ) ) {
     
    160160                        virtual Declaration *mutate( UnionDecl *unionDecl );
    161161                };
    162 
     162               
    163163                /// Replaces polymorphic return types with out-parameters, replaces calls to polymorphic functions with adapter calls as needed, and adds appropriate type variables to the function call
    164164                class Pass1 : public PolyMutator {
     
    208208                        ResolvExpr::TypeMap< DeclarationWithType > scopedAssignOps;  ///< Currently known assignment operators
    209209                        ScopedMap< std::string, DeclarationWithType* > adapters;     ///< Set of adapter functions in the current scope
    210 
     210                       
    211211                        DeclarationWithType *retval;
    212212                        bool useRetval;
     
    226226                        virtual Type *mutate( PointerType *pointerType );
    227227                        virtual Type *mutate( FunctionType *funcType );
    228 
     228                       
    229229                  private:
    230230                        void addAdapters( FunctionType *functionType );
     
    297297                        /// Exits the type-variable scope
    298298                        void endTypeScope();
    299 
     299                       
    300300                        ScopedSet< std::string > knownLayouts;          ///< Set of generic type layouts known in the current scope, indexed by sizeofName
    301301                        ScopedSet< std::string > knownOffsets;          ///< Set of non-generic types for which the offset array exists in the current scope, indexed by offsetofName
     
    351351                PolyGenericCalculator polyCalculator;
    352352                Pass3 pass3;
    353 
     353               
    354354                layoutBuilder.mutateDeclarationList( translationUnit );
    355355                mutateTranslationUnit/*All*/( translationUnit, pass1 );
     
    370370                return functionDecl;
    371371        }
    372 
     372       
    373373        /// Get a list of type declarations that will affect a layout function
    374374        std::list< TypeDecl* > takeOtypeOnly( std::list< TypeDecl* > &decls ) {
     
    380380                        }
    381381                }
    382 
     382               
    383383                return otypeDecls;
    384384        }
     
    387387        void addOtypeParams( FunctionType *layoutFnType, std::list< TypeDecl* > &otypeParams ) {
    388388                BasicType sizeAlignType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    389 
     389               
    390390                for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) {
    391391                        TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param );
     
    444444                return makeCond( ifCond, ifExpr );
    445445        }
    446 
     446       
    447447        /// adds an expression to a compound statement
    448448        void addExpr( CompoundStmt *stmts, Expression *expr ) {
     
    454454                stmts->get_kids().push_back( stmt );
    455455        }
    456 
     456       
    457457        Declaration *LayoutFunctionBuilder::mutate( StructDecl *structDecl ) {
    458458                // do not generate layout function for "empty" tag structs
     
    467467                BasicType *sizeAlignType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    468468                PointerType *sizeAlignOutType = new PointerType( Type::Qualifiers(), sizeAlignType );
    469 
     469               
    470470                ObjectDecl *sizeParam = new ObjectDecl( sizeofName( structDecl->get_name() ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 );
    471471                layoutFnType->get_parameters().push_back( sizeParam );
     
    497497                                addStmt( layoutDecl->get_statements(), makeAlignTo( derefVar( sizeParam ), new AlignofExpr( memberType->clone() ) ) );
    498498                        }
    499 
     499                       
    500500                        // place current size in the current offset index
    501501                        addExpr( layoutDecl->get_statements(), makeOp( "?=?", makeOp( "?[?]", new VariableExpr( offsetParam ), new ConstantExpr( Constant::from( n_members ) ) ),
     
    505505                        // add member size to current size
    506506                        addExpr( layoutDecl->get_statements(), makeOp( "?+=?", derefVar( sizeParam ), new SizeofExpr( memberType->clone() ) ) );
    507 
     507                       
    508508                        // take max of member alignment and global alignment
    509509                        addStmt( layoutDecl->get_statements(), makeAssignMax( derefVar( alignParam ), new AlignofExpr( memberType->clone() ) ) );
     
    515515                return structDecl;
    516516        }
    517 
     517       
    518518        Declaration *LayoutFunctionBuilder::mutate( UnionDecl *unionDecl ) {
    519519                // do not generate layout function for "empty" tag unions
    520520                if ( unionDecl->get_members().empty() ) return unionDecl;
    521 
     521               
    522522                // get parameters that can change layout, exiting early if none
    523523                std::list< TypeDecl* > otypeParams = takeOtypeOnly( unionDecl->get_parameters() );
     
    528528                BasicType *sizeAlignType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    529529                PointerType *sizeAlignOutType = new PointerType( Type::Qualifiers(), sizeAlignType );
    530 
     530               
    531531                ObjectDecl *sizeParam = new ObjectDecl( sizeofName( unionDecl->get_name() ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 );
    532532                layoutFnType->get_parameters().push_back( sizeParam );
     
    545545                        assert( dwt );
    546546                        Type *memberType = dwt->get_type();
    547 
     547                       
    548548                        // take max member size and global size
    549549                        addStmt( layoutDecl->get_statements(), makeAssignMax( derefVar( sizeParam ), new SizeofExpr( memberType->clone() ) ) );
    550 
     550                       
    551551                        // take max of member alignment and global alignment
    552552                        addStmt( layoutDecl->get_statements(), makeAssignMax( derefVar( alignParam ), new AlignofExpr( memberType->clone() ) ) );
     
    558558                return unionDecl;
    559559        }
    560 
     560       
    561561        ////////////////////////////////////////// Pass1 ////////////////////////////////////////////////////
    562562
     
    619619                        return 0;
    620620                }
    621 
     621               
    622622                /// returns T if the given declaration is: (*?=?)(T *, T) for some type T (return not checked, but maybe should be), NULL otherwise
    623623                /// Only picks assignments where neither parameter is cv-qualified
     
    631631                                                Type *paramType2 = funType->get_parameters().back()->get_type();
    632632                                                if ( paramType2->get_qualifiers() != defaultQualifiers ) return 0;
    633 
     633                                               
    634634                                                if ( PointerType *pointerType = dynamic_cast< PointerType* >( paramType1 ) ) {
    635635                                                        Type *baseType1 = pointerType->get_base();
     
    784784                                                arg++;
    785785                                        } else {
    786                                                 /// xxx - should this be an assertion?
    787                                                 throw SemanticError( "unbound type variable: " + tyParm->first + " in application ", appExpr );
     786                                                throw SemanticError( "unbound type variable in application ", appExpr );
    788787                                        } // if
    789788                                } // if
     
    804803                                passArgTypeVars( appExpr, polyRetType, concRetType, arg, exprTyVars, seenTypes );
    805804                        }
    806 
     805                       
    807806                        // add type information args for presently unseen types in parameter list
    808807                        for ( ; fnParm != funcType->get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) {
     
    883882                        assert( env );
    884883                        Type *concrete = replaceWithConcrete( appExpr, polyType );
    885                         // add out-parameter for return value
     884                        // add out-parameter for return value   
    886885                        return addRetParam( appExpr, function, concrete, arg );
    887886                }
     
    911910                                } else if ( arg->get_results().front()->get_isLvalue() ) {
    912911                                        // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue)
    913                                         // xxx - need to test that this code is still reachable
    914912                                        if ( CommaExpr *commaArg = dynamic_cast< CommaExpr* >( arg ) ) {
    915913                                                commaArg->set_arg2( new AddressExpr( commaArg->get_arg2() ) );
     
    12931291                        } else if ( needsAdapter( function, scopeTyVars ) ) {
    12941292                                // std::cerr << "needs adapter: ";
    1295                                 // printTyVarMap( std::cerr, scopeTyVars );
    1296                                 // std::cerr << *env << std::endl;
     1293                                // for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {
     1294                                //      std::cerr << i->first << " ";
     1295                                // }
     1296                                // std::cerr << "\n";
    12971297                                // change the application so it calls the adapter rather than the passed function
    12981298                                ret = applyAdapter( appExpr, function, arg, scopeTyVars );
     
    13451345                                } // if
    13461346                        } // if
    1347                         // isPolyType check needs to happen before mutating addrExpr arg, so pull it forward
    1348                         // out of the if condition.
    1349                         bool polytype = isPolyType( addrExpr->get_arg()->get_results().front(), scopeTyVars, env );
    13501347                        addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) );
    1351                         if ( polytype || needs ) {
     1348                        if ( isPolyType( addrExpr->get_arg()->get_results().front(), scopeTyVars, env ) || needs ) {
    13521349                                Expression *ret = addrExpr->get_arg();
    13531350                                delete ret->get_results().front();
     
    13691366                        return new VariableExpr( functionObj );
    13701367                }
    1371 
     1368               
    13721369                Statement * Pass1::mutate( ReturnStmt *returnStmt ) {
    13731370                        if ( retval && returnStmt->get_expr() ) {
     
    18891886                                }
    18901887                        }
    1891 
     1888                       
    18921889                        Type *ret = Mutator::mutate( funcType );
    18931890
     
    19081905
    19091906                                        std::list<Expression*> designators;
    1910                                         objectDecl->set_init( new SingleInit( alloc, designators, false ) ); // not constructed
     1907                                        objectDecl->set_init( new SingleInit( alloc, designators ) );
    19111908                                }
    19121909                        }
     
    19491946                        return derefdVar;
    19501947                }
    1951 
     1948               
    19521949                Expression *PolyGenericCalculator::mutate( MemberExpr *memberExpr ) {
    19531950                        // mutate, exiting early if no longer MemberExpr
     
    21472144                        Type *ty = offsetofExpr->get_type();
    21482145                        if ( ! findGeneric( ty ) ) return offsetofExpr;
    2149 
     2146                       
    21502147                        if ( StructInstType *structType = dynamic_cast< StructInstType* >( ty ) ) {
    21512148                                // replace offsetof expression by index into offset array
Note: See TracChangeset for help on using the changeset viewer.