Changeset 7754cde


Ignore:
Timestamp:
Dec 16, 2015, 4:59:58 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
69911c11
Parents:
0f889a77
Message:

First draft of passing generic size/align

Location:
src/GenPoly
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r0f889a77 r7754cde  
    306306
    307307                void Pass1::passTypeVars( ApplicationExpr *appExpr, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
     308                        // pass size/align for type variables
    308309                        for ( TyVarMap::const_iterator tyParm = exprTyVars.begin(); tyParm != exprTyVars.end(); ++tyParm ) {
    309310                                ResolvExpr::EqvClass eqvClass;
     
    321322                                } // if
    322323                        } // for
     324
     325                        // add size/align for generic types to parameter list
     326                        //assert( ! appExpr->get_function()->get_results().empty() );
     327                        if ( appExpr->get_function()->get_results().empty() ) return;
     328                        FunctionType *funcType = getFunctionType( appExpr->get_function()->get_results().front() );
     329                        assert( funcType );
     330                       
     331                        std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin();
     332                        std::list< Expression* >::const_iterator fnArg = arg;
     333                        std::set< std::string > seenTypes; //< sizeofName for generic types we've seen
     334                        for ( ; fnParm != funcType->get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) {
     335                                Type *parmType = (*fnParm)->get_type();
     336                                if ( ! dynamic_cast< TypeInstType* >( parmType ) && isPolyType( parmType, exprTyVars ) ) {
     337                                        std::string sizeName = sizeofName( parmType );
     338                                        if ( seenTypes.count( sizeName ) ) continue;
     339
     340                                        assert( ! (*fnArg)->get_results().empty() );
     341                                        Type *argType = (*fnArg)->get_results().front();
     342                                        arg = appExpr->get_args().insert( arg, new SizeofExpr( argType->clone() ) );
     343                                        arg++;
     344                                        arg = appExpr->get_args().insert( arg, new AlignofExpr( argType->clone() ) );
     345                                        arg++;
     346
     347                                        seenTypes.insert( sizeName );
     348                                }
     349                        }
    323350                }
    324351
     
    971998                        TyVarMap oldtyVars = scopeTyVars;
    972999                        makeTyVarMap( funcType, scopeTyVars );
    973  
     1000
     1001                        // move polymorphic return type to parameter list
    9741002                        std::string typeName;
    9751003                        if ( isPolyRet( funcType, typeName ) ) {
     
    9791007                                funcType->get_returnVals().pop_front();
    9801008                        }
    981  
     1009
     1010                        // add size/align and assertions for type parameters to parameter list
    9821011                        std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin();
    9831012                        std::list< DeclarationWithType *> inferredParams;
     
    10071036                                (*tyParm)->get_assertions().clear();
    10081037                        }
     1038
     1039                        // add size/align for generic types to parameter list
     1040                        std::set< std::string > seenTypes; //< sizeofName for generic types we've seen
     1041                        for ( std::list< DeclarationWithType* >::const_iterator fnParm = last; fnParm != funcType->get_parameters().end(); ++fnParm ) {
     1042                                Type *parmType = (*fnParm)->get_type();
     1043                                if ( ! dynamic_cast< TypeInstType* >( parmType ) && isPolyType( parmType, scopeTyVars ) ) {
     1044                                        std::string sizeName = sizeofName( parmType );
     1045                                        if ( seenTypes.count( sizeName ) ) continue;
     1046                                       
     1047                                        ObjectDecl *sizeParm, *alignParm;
     1048                                        sizeParm = newObj.clone();
     1049                                        sizeParm->set_name( sizeName );
     1050                                        last = funcType->get_parameters().insert( last, sizeParm );
     1051                                        ++last;
     1052
     1053                                        alignParm = newObj.clone();
     1054                                        alignParm->set_name( alignofName( parmType ) );
     1055                                        last = funcType->get_parameters().insert( last, alignParm );
     1056                                        ++last;
     1057
     1058                                        seenTypes.insert( sizeName );
     1059                                }
     1060                        }
     1061
     1062                        // splice assertion parameters into parameter list
    10091063                        funcType->get_parameters().splice( last, inferredParams );
    10101064                        addAdapters( funcType );
  • src/GenPoly/GenPoly.cc

    r0f889a77 r7754cde  
    149149        }
    150150
     151        FunctionType * getFunctionType( Type *ty ) {
     152                PointerType *ptrType;
     153                if ( ( ptrType = dynamic_cast< PointerType* >( ty ) ) ) {
     154                        return dynamic_cast< FunctionType* >( ptrType->get_base() ); // pointer if FunctionType, NULL otherwise
     155                } else {
     156                        return dynamic_cast< FunctionType* >( ty ); // pointer if FunctionType, NULL otherwise
     157                }
     158        }
     159
    151160        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) {
    152161                for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) {
  • src/GenPoly/GenPoly.h

    r0f889a77 r7754cde  
    4848        Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
    4949
     50        /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
     51        FunctionType * getFunctionType( Type *ty );
     52
    5053        /// Prints type variable map
    5154        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
  • src/GenPoly/ScrubTyVars.cc

    r0f889a77 r7754cde  
    4646        Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
    4747                // sizeof( T ) => _sizeof_T parameter, which is the size of T
    48                 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) {
    49                         Expression *expr = new NameExpr( sizeofName( typeInst ) );
     48                if ( Type *polyType = isPolyType( szeof->get_type() ) ) {
     49                        Expression *expr = new NameExpr( sizeofName( polyType ) );
    5050                        return expr;
    5151                } else {
     
    5656        Expression * ScrubTyVars::mutate( AlignofExpr *algnof ) {
    5757                // alignof( T ) => _alignof_T parameter, which is the alignment of T
    58                 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( algnof->get_type() ) ) {
    59                         Expression *expr = new NameExpr( alignofName( typeInst ) );
     58                if ( Type *polyType = isPolyType( algnof->get_type() ) ) {
     59                        Expression *expr = new NameExpr( alignofName( polyType ) );
    6060                        return expr;
    6161                } else {
  • src/GenPoly/Specialize.cc

    r0f889a77 r7754cde  
    1717
    1818#include "Specialize.h"
     19#include "GenPoly.h"
    1920#include "PolyMutator.h"
    2021
     
    8788        }
    8889
    89         /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
    90         FunctionType * getFunctionType( Type *ty ) {
    91                 PointerType *ptrType;
    92                 if ( ( ptrType = dynamic_cast< PointerType* >( ty ) ) ) {
    93                         return dynamic_cast< FunctionType* >( ptrType->get_base() ); // pointer if FunctionType, NULL otherwise
    94                 } else {
    95                         return dynamic_cast< FunctionType* >( ty ); // pointer if FunctionType, NULL otherwise
    96                 }
    97         }
    98 
    9990        /// Generates a thunk that calls `actual` with type `funType` and returns its address
    10091        Expression * Specialize::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) {
Note: See TracChangeset for help on using the changeset viewer.