Changeset 2f42718 for src/GenPoly
- Timestamp:
- Feb 22, 2019, 10:43:29 AM (7 years ago)
- Branches:
- no_list
- Parents:
- 43e0949
- Location:
- src/GenPoly
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r43e0949 r2f42718 286 286 TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param ); 287 287 std::string paramName = mangleType( ¶mType ); 288 layoutFnType-> get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );289 layoutFnType-> get_parameters().push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );288 layoutFnType->parameters.push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 289 layoutFnType->parameters.push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 290 290 } 291 291 } … … 367 367 368 368 ObjectDecl *sizeParam = new ObjectDecl( sizeofName( structDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType, 0 ); 369 layoutFnType-> get_parameters().push_back( sizeParam );369 layoutFnType->parameters.push_back( sizeParam ); 370 370 ObjectDecl *alignParam = new ObjectDecl( alignofName( structDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 ); 371 layoutFnType-> get_parameters().push_back( alignParam );371 layoutFnType->parameters.push_back( alignParam ); 372 372 ObjectDecl *offsetParam = new ObjectDecl( offsetofName( structDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 ); 373 layoutFnType-> get_parameters().push_back( offsetParam );373 layoutFnType->parameters.push_back( offsetParam ); 374 374 addOtypeParams( layoutFnType, otypeParams ); 375 375 … … 428 428 429 429 ObjectDecl *sizeParam = new ObjectDecl( sizeofName( unionDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType, 0 ); 430 layoutFnType-> get_parameters().push_back( sizeParam );430 layoutFnType->parameters.push_back( sizeParam ); 431 431 ObjectDecl *alignParam = new ObjectDecl( alignofName( unionDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 ); 432 layoutFnType-> get_parameters().push_back( alignParam );432 layoutFnType->parameters.push_back( alignParam ); 433 433 addOtypeParams( layoutFnType, otypeParams ); 434 434 … … 468 468 // to take those polymorphic types as pointers. Therefore, there can be two different functions 469 469 // with the same mangled name, so we need to further mangle the names. 470 for ( std::list< DeclarationWithType *>::iterator retval = function->get_returnVals().begin(); retval != function->get_returnVals().end(); ++retval) {471 if ( isPolyType( (*retval)->get_type(), tyVars ) ) {470 for ( auto retval : function->returnVals ) { 471 if ( isPolyType( retval->get_type(), tyVars ) ) { 472 472 name << "P"; 473 473 } else { … … 476 476 } 477 477 name << "_"; 478 std::list< DeclarationWithType *> ¶mList = function->get_parameters();479 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg) {480 if ( isPolyType( (*arg)->get_type(), tyVars ) ) {478 auto & paramList = function->parameters; 479 for ( auto arg : paramList ) { 480 if ( isPolyType( arg->get_type(), tyVars ) ) { 481 481 name << "P"; 482 482 } else { … … 518 518 makeTyVarMap( functionType, scopeTyVars ); 519 519 520 std::list< DeclarationWithType *> ¶mList = functionType->parameters;521 std:: list< FunctionType *> functions;522 for ( Type::ForallList::iterator tyVar = functionType->forall.begin(); tyVar != functionType->forall.end(); ++tyVar) {523 for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->assertions.begin(); assert != (*tyVar)->assertions.end(); ++assert) {524 findFunction( (*assert)->get_type(), functions, scopeTyVars, needsAdapter );520 auto & paramList = functionType->parameters; 521 std::vector< FunctionType *> functions; 522 for ( auto tyVar : functionType->forall ) { 523 for ( auto assert : tyVar->assertions ) { 524 findFunction( assert->get_type(), functions, scopeTyVars, needsAdapter ); 525 525 } // for 526 526 } // for 527 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg) {528 findFunction( (*arg)->get_type(), functions, scopeTyVars, needsAdapter );527 for ( auto arg : paramList ) { 528 findFunction( arg->get_type(), functions, scopeTyVars, needsAdapter ); 529 529 } // for 530 530 531 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType) {532 std::string mangleName = mangleAdapterName( *funType, scopeTyVars );531 for ( auto funType : functions ) { 532 std::string mangleName = mangleAdapterName( funType, scopeTyVars ); 533 533 if ( adapters.find( mangleName ) == adapters.end() ) { 534 534 std::string adapterName = makeAdapterName( mangleName ); 535 adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), nullptr ) ) );535 adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), nullptr ) ) ); 536 536 } // if 537 537 } // for … … 612 612 assert( funcType ); 613 613 614 std:: list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin();614 std::vector< DeclarationWithType* >::const_iterator fnParm = funcType->parameters.begin(); 615 615 std::list< Expression* >::const_iterator fnArg = arg; 616 616 std::set< std::string > seenTypes; ///< names for generic types we've seen … … 624 624 625 625 // add type information args for presently unseen types in parameter list 626 for ( ; fnParm != funcType-> get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) {626 for ( ; fnParm != funcType->parameters.end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) { 627 627 if ( ! (*fnArg)->get_result() ) continue; 628 628 Type * argType = (*fnArg)->get_result(); … … 708 708 // if ( ! function->get_returnVals().empty() && isPolyType( function->get_returnVals().front()->get_type(), tyVars ) ) { 709 709 if ( isDynRet( function, tyVars ) ) { 710 ret = addRetParam( appExpr, function-> get_returnVals().front()->get_type(), arg );710 ret = addRetParam( appExpr, function->returnVals.front()->get_type(), arg ); 711 711 } // if 712 712 std::string mangleName = mangleAdapterName( function, tyVars ); … … 786 786 } 787 787 788 void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) { 789 for ( std::list< DeclarationWithType *>::const_iterator param = function->get_parameters().begin(); param != function->parameters.end(); ++param, ++arg ) { 790 assertf( arg != appExpr->args.end(), "boxParams: missing argument for param %s to %s in %s", toString( *param ).c_str(), toString( function ).c_str(), toString( appExpr ).c_str() ); 791 addCast( *arg, (*param)->get_type(), exprTyVars ); 792 boxParam( (*param)->get_type(), *arg, exprTyVars ); 788 void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator & arg, const TyVarMap &exprTyVars ) { 789 for ( auto param : function->parameters ) { 790 assertf( arg != appExpr->args.end(), "boxParams: missing argument for param %s to %s in %s", toString( param ).c_str(), toString( function ).c_str(), toString( appExpr ).c_str() ); 791 addCast( *arg, param->get_type(), exprTyVars ); 792 boxParam( param->get_type(), *arg, exprTyVars ); 793 ++arg; 793 794 } // for 794 795 } … … 796 797 void Pass1::addInferredParams( ApplicationExpr *appExpr, FunctionType *functionType, std::list< Expression *>::iterator &arg, const TyVarMap &tyVars ) { 797 798 std::list< Expression *>::iterator cur = arg; 798 for ( Type::ForallList::iterator tyVar = functionType->get_forall().begin(); tyVar != functionType->get_forall().end(); ++tyVar) {799 for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->assertions.begin(); assert != (*tyVar)->assertions.end(); ++assert) {800 InferredParams::const_iterator inferParam = appExpr->inferParams.find( (*assert)->get_uniqueId() );801 assertf( inferParam != appExpr->inferParams.end(), "addInferredParams missing inferred parameter: %s in: %s", toString( *assert ).c_str(), toString( appExpr ).c_str() );799 for ( auto tyVar : functionType->forall ) { 800 for ( auto assert : tyVar->assertions ) { 801 InferredParams::const_iterator inferParam = appExpr->inferParams.find( assert->get_uniqueId() ); 802 assertf( inferParam != appExpr->inferParams.end(), "addInferredParams missing inferred parameter: %s in: %s", toString( assert ).c_str(), toString( appExpr ).c_str() ); 802 803 Expression *newExpr = inferParam->second.expr->clone(); 803 addCast( newExpr, (*assert)->get_type(), tyVars );804 boxParam( (*assert)->get_type(), newExpr, tyVars );804 addCast( newExpr, assert->get_type(), tyVars ); 805 boxParam( assert->get_type(), newExpr, tyVars ); 805 806 appExpr->get_args().insert( cur, newExpr ); 806 807 } // for … … 813 814 // make a new parameter that is a pointer to the type of the old return value 814 815 retParm->set_type( new PointerType( Type::Qualifiers(), retParm->get_type() ) ); 815 funcType-> get_parameters().push_front(retParm );816 funcType->parameters.insert( funcType->parameters.begin(), retParm ); 816 817 817 818 // we don't need the return value any more 818 funcType-> get_returnVals().clear();819 funcType->returnVals.clear(); 819 820 } 820 821 … … 825 826 makeRetParm( adapter ); 826 827 } // if 827 adapter-> get_parameters().push_front(new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 ) );828 adapter->parameters.insert( adapter->parameters.begin(), new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 ) ); 828 829 return adapter; 829 830 } … … 844 845 } 845 846 846 void addAdapterParams( ApplicationExpr *adapteeApp, std:: list< DeclarationWithType *>::iterator arg, std::list< DeclarationWithType *>::iterator param, std::list< DeclarationWithType *>::iterator paramEnd, std::list< DeclarationWithType *>::iterator realParam, const TyVarMap &tyVars ) {847 void addAdapterParams( ApplicationExpr *adapteeApp, std::vector< DeclarationWithType *>::iterator arg, std::vector< DeclarationWithType *>::iterator param, std::vector< DeclarationWithType *>::iterator paramEnd, std::vector< DeclarationWithType *>::iterator realParam, const TyVarMap &tyVars ) { 847 848 UniqueName paramNamer( "_p" ); 848 849 for ( ; param != paramEnd; ++param, ++arg, ++realParam ) { … … 858 859 FunctionType *adapterType = makeAdapterType( adaptee, tyVars ); 859 860 adapterType = ScrubTyVars::scrub( adapterType, tyVars ); 860 DeclarationWithType *adapteeDecl = adapterType-> get_parameters().front();861 DeclarationWithType *adapteeDecl = adapterType->parameters.front(); 861 862 adapteeDecl->set_name( "_adaptee" ); 862 863 // do not carry over attributes to real type parameters/return values … … 877 878 for ( ; tyParam != adapterType->get_forall().end(); ++tyArg, ++tyParam, ++realTyParam ) { 878 879 assert( tyArg != realType->get_forall().end() ); 879 std:: list< DeclarationWithType *>::iterator assertArg = (*tyArg)->get_assertions().begin();880 std:: list< DeclarationWithType *>::iterator assertParam = (*tyParam)->get_assertions().begin();881 std:: list< DeclarationWithType *>::iterator realAssertParam = (*realTyParam)->get_assertions().begin();882 for ( ; assertParam != (*tyParam)-> get_assertions().end(); ++assertArg, ++assertParam, ++realAssertParam ) {883 assert( assertArg != (*tyArg)-> get_assertions().end() );880 std::vector< DeclarationWithType *>::iterator assertArg = (*tyArg)->assertions.begin(); 881 std::vector< DeclarationWithType *>::iterator assertParam = (*tyParam)->assertions.begin(); 882 std::vector< DeclarationWithType *>::iterator realAssertParam = (*realTyParam)->assertions.begin(); 883 for ( ; assertParam != (*tyParam)->assertions.end(); ++assertArg, ++assertParam, ++realAssertParam ) { 884 assert( assertArg != (*tyArg)->assertions.end() ); 884 885 adapteeApp->get_args().push_back( makeAdapterArg( *assertParam, *assertArg, *realAssertParam, tyVars ) ); 885 886 } // for 886 887 } // for 887 888 888 std:: list< DeclarationWithType *>::iterator arg = realType->get_parameters().begin();889 std:: list< DeclarationWithType *>::iterator param = adapterType->get_parameters().begin();890 std:: list< DeclarationWithType *>::iterator realParam = adaptee->get_parameters().begin();889 std::vector< DeclarationWithType *>::iterator arg = realType->parameters.begin(); 890 std::vector< DeclarationWithType *>::iterator param = adapterType->parameters.begin(); 891 std::vector< DeclarationWithType *>::iterator realParam = adaptee->parameters.begin(); 891 892 param++; // skip adaptee parameter in the adapter type 892 if ( realType-> get_returnVals().empty() ) {893 if ( realType->returnVals.empty() ) { 893 894 // void return 894 addAdapterParams( adapteeApp, arg, param, adapterType-> get_parameters().end(), realParam, tyVars );895 addAdapterParams( adapteeApp, arg, param, adapterType->parameters.end(), realParam, tyVars ); 895 896 bodyStmt = new ExprStmt( adapteeApp ); 896 } else if ( isDynType( adaptee-> get_returnVals().front()->get_type(), tyVars ) ) {897 } else if ( isDynType( adaptee->returnVals.front()->get_type(), tyVars ) ) { 897 898 // return type T 898 899 if ( (*param)->get_name() == "" ) { … … 901 902 } // if 902 903 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 903 UntypedExpr *deref = UntypedExpr::createDeref( new CastExpr( new VariableExpr( *param++ ), new PointerType( Type::Qualifiers(), realType-> get_returnVals().front()->get_type()->clone() ) ) );904 UntypedExpr *deref = UntypedExpr::createDeref( new CastExpr( new VariableExpr( *param++ ), new PointerType( Type::Qualifiers(), realType->returnVals.front()->get_type()->clone() ) ) ); 904 905 assign->get_args().push_back( deref ); 905 addAdapterParams( adapteeApp, arg, param, adapterType-> get_parameters().end(), realParam, tyVars );906 addAdapterParams( adapteeApp, arg, param, adapterType->parameters.end(), realParam, tyVars ); 906 907 assign->get_args().push_back( adapteeApp ); 907 908 bodyStmt = new ExprStmt( assign ); 908 909 } else { 909 910 // adapter for a function that returns a monomorphic value 910 addAdapterParams( adapteeApp, arg, param, adapterType-> get_parameters().end(), realParam, tyVars );911 addAdapterParams( adapteeApp, arg, param, adapterType->parameters.end(), realParam, tyVars ); 911 912 bodyStmt = new ReturnStmt( adapteeApp ); 912 913 } // if … … 919 920 void Pass1::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) { 920 921 // collect a list of function types passed as parameters or implicit parameters (assertions) 921 std::list< DeclarationWithType *> ¶mList = functionType->get_parameters();922 std:: list< FunctionType *> functions;923 for ( Type::ForallList::iterator tyVar = functionType->get_forall().begin(); tyVar != functionType->get_forall().end(); ++tyVar) {924 for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->get_assertions().begin(); assert != (*tyVar)->get_assertions().end(); ++assert) {925 findFunction( (*assert)->get_type(), functions, exprTyVars, needsAdapter );922 auto & paramList = functionType->parameters; 923 std::vector< FunctionType *> functions; 924 for ( auto tyVar : functionType->forall ) { 925 for ( auto assert : tyVar->assertions ) { 926 findFunction( assert->get_type(), functions, exprTyVars, needsAdapter ); 926 927 } // for 927 928 } // for 928 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg) {929 findFunction( (*arg)->get_type(), functions, exprTyVars, needsAdapter );929 for ( auto arg : paramList ) { 930 findFunction( arg->get_type(), functions, exprTyVars, needsAdapter ); 930 931 } // for 931 932 … … 934 935 std::set< std::string > adaptersDone; 935 936 936 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType) {937 FunctionType * originalFunction = (*funType)->clone();938 FunctionType * realFunction = (*funType)->clone();937 for ( auto funType : functions ) { 938 FunctionType * originalFunction = funType->clone(); 939 FunctionType * realFunction = funType->clone(); 939 940 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 940 941 … … 954 955 if ( adapter == adapters.end() ) { 955 956 // adapter has not been created yet in the current scope, so define it 956 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars );957 FunctionDecl *newAdapter = makeAdapter( funType, realFunction, mangleName, exprTyVars ); 957 958 std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) ); 958 959 adapter = answer.first; … … 1255 1256 1256 1257 void Pass2::addAdapters( FunctionType *functionType ) { 1257 std::list< DeclarationWithType *> ¶mList = functionType->parameters;1258 std:: list< FunctionType *> functions;1259 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg) {1260 Type *orig = (*arg)->get_type();1258 auto & paramList = functionType->parameters; 1259 std::vector< FunctionType *> functions; 1260 for ( auto arg : paramList ) { 1261 Type *orig = arg->get_type(); 1261 1262 findAndReplaceFunction( orig, functions, scopeTyVars, needsAdapter ); 1262 (*arg)->set_type( orig );1263 arg->set_type( orig ); 1263 1264 } 1264 1265 std::set< std::string > adaptersDone; 1265 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType) {1266 std::string mangleName = mangleAdapterName( *funType, scopeTyVars );1266 for ( auto funType : functions ) { 1267 std::string mangleName = mangleAdapterName( funType, scopeTyVars ); 1267 1268 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 1268 1269 std::string adapterName = makeAdapterName( mangleName ); 1269 1270 // adapter may not be used in body, pass along with unused attribute. 1270 paramList. push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) );1271 paramList.insert( paramList.begin(), new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) ); 1271 1272 adaptersDone.insert( adaptersDone.begin(), mangleName ); 1272 1273 } 1273 1274 } 1274 // deleteAll( functions );1275 1275 } 1276 1276 … … 1324 1324 1325 1325 void Pass2::premutate( FunctionType *funcType ) { 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1326 1345 GuardScope( scopeTyVars ); 1327 1346 makeTyVarMap( funcType, scopeTyVars ); … … 1329 1348 // move polymorphic return type to parameter list 1330 1349 if ( isDynRet( funcType ) ) { 1331 ObjectDecl *ret = strict_dynamic_cast< ObjectDecl* >( funcType-> get_returnVals().front() );1350 ObjectDecl *ret = strict_dynamic_cast< ObjectDecl* >( funcType->returnVals.front() ); 1332 1351 ret->set_type( new PointerType( Type::Qualifiers(), ret->get_type() ) ); 1333 funcType-> get_parameters().push_front(ret );1334 funcType-> get_returnVals().pop_front();1352 funcType->parameters.insert( funcType->parameters.begin(), ret ); 1353 funcType->returnVals.erase(funcType->returnVals.begin()); 1335 1354 ret->set_init( nullptr ); // xxx - memory leak? 1336 1355 } 1337 1356 1338 // add size/align and assertions for type parameters to parameter list 1339 std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin(); 1340 std::list< DeclarationWithType *> inferredParams; 1357 // create a list of parameters after adding new ones 1358 std::vector<DeclarationWithType *> newParams; 1359 std::vector<DeclarationWithType *> inferredParams; 1360 1361 // reserve some memory for these vectors 1362 // Number of elements needed should be somewhat linear with the number of parameters / forall 1363 // "somewhat linear" == 2X 1364 newParams.reserve(funcType->parameters.size() * 2 + funcType->forall.size() * 2); 1365 inferredParams.reserve(funcType->forall.size() * 2); 1366 1341 1367 // size/align/offset parameters may not be used in body, pass along with unused attribute. 1342 1368 ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, … … 1344 1370 ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0, 1345 1371 new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 ); 1346 for ( Type::ForallList::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) { 1347 ObjectDecl *sizeParm, *alignParm; 1372 1373 // We do this several time, create a functor for it 1374 auto pushObj = [&newObj, &newParams]( const std::string & name ) { 1375 auto parm = newObj.clone(); 1376 parm->set_name( name ); 1377 newParams.push_back( parm ); 1378 }; 1379 1380 // add size/align and assertions for type parameters to parameter list 1381 for ( auto tyParm : funcType->forall ) { 1348 1382 // add all size and alignment parameters to parameter list 1349 if ( (*tyParm)->isComplete() ) {1350 TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );1383 if ( tyParm->isComplete() ) { 1384 TypeInstType parmType( Type::Qualifiers(), tyParm->get_name(), tyParm ); 1351 1385 std::string parmName = mangleType( &parmType ); 1352 1353 sizeParm = newObj.clone(); 1354 sizeParm->set_name( sizeofName( parmName ) ); 1355 last = funcType->get_parameters().insert( last, sizeParm ); 1356 ++last; 1357 1358 alignParm = newObj.clone(); 1359 alignParm->set_name( alignofName( parmName ) ); 1360 last = funcType->get_parameters().insert( last, alignParm ); 1361 ++last; 1386 pushObj( sizeofName( parmName ) ); 1387 pushObj( alignofName( parmName ) ); 1362 1388 } 1363 1389 // move all assertions into parameter list 1364 for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) { 1390 // move all assertions into parameter list 1391 for ( auto assert : tyParm->assertions ) { 1365 1392 // assertion parameters may not be used in body, pass along with unused attribute. 1366 (*assert)->get_attributes().push_back( new Attribute( "unused" ) );1367 inferredParams.push_back( *assert );1368 } 1369 (*tyParm)->get_assertions().clear();1393 assert->attributes.push_back( new Attribute( "unused" ) ); 1394 inferredParams.push_back( assert ); 1395 } 1396 tyParm->assertions.clear(); 1370 1397 } 1371 1398 1372 1399 // add size/align for generic parameter types to parameter list 1373 1400 std::set< std::string > seenTypes; // sizeofName for generic types we've seen 1374 for ( std::list< DeclarationWithType* >::const_iterator fnParm = last; fnParm != funcType->get_parameters().end(); ++fnParm ) { 1375 Type *polyType = isPolyType( (*fnParm)->get_type(), scopeTyVars ); 1376 if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) { 1401 for ( DeclarationWithType * fnParm : funcType->parameters ) 1402 { 1403 Type *polyType = isPolyType( fnParm->get_type(), scopeTyVars ); 1404 if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) 1405 { 1377 1406 std::string typeName = mangleType( polyType ); 1378 1407 if ( seenTypes.count( typeName ) ) continue; 1379 1408 1380 ObjectDecl *sizeParm, *alignParm, *offsetParm; 1381 sizeParm = newObj.clone(); 1382 sizeParm->set_name( sizeofName( typeName ) ); 1383 last = funcType->get_parameters().insert( last, sizeParm ); 1384 ++last; 1385 1386 alignParm = newObj.clone(); 1387 alignParm->set_name( alignofName( typeName ) ); 1388 last = funcType->get_parameters().insert( last, alignParm ); 1389 ++last; 1409 pushObj( sizeofName ( typeName ) ); 1410 pushObj( alignofName( typeName ) ); 1390 1411 1391 1412 if ( StructInstType *polyBaseStruct = dynamic_cast< StructInstType* >( polyType ) ) { 1392 1413 // NOTE zero-length arrays are illegal in C, so empty structs have no offset array 1393 1414 if ( ! polyBaseStruct->get_baseStruct()->get_members().empty() ) { 1394 offsetParm = newPtr.clone(); 1395 offsetParm->set_name( offsetofName( typeName ) ); 1396 last = funcType->get_parameters().insert( last, offsetParm ); 1397 ++last; 1415 auto offset = newPtr.clone(); 1416 offset->set_name( offsetofName( typeName ) ); 1417 newParams.push_back( offset ); 1398 1418 } 1399 1419 } … … 1403 1423 1404 1424 // splice assertion parameters into parameter list 1405 funcType->get_parameters().splice( last, inferredParams ); 1425 std::copy( inferredParams , std::back_inserter(newParams) ); 1426 std::copy( funcType->parameters, std::back_inserter(newParams) ); 1427 1428 funcType->parameters.swap(newParams); 1429 1406 1430 addAdapters( funcType ); 1407 1431 } … … 1470 1494 1471 1495 // make sure that any type information passed into the function is accounted for 1472 for ( std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin(); fnParm != funcType->get_parameters().end(); ++fnParm) {1496 for ( auto fnParm : funcType->parameters ) { 1473 1497 // condition here duplicates that in Pass2::mutate( FunctionType* ) 1474 Type *polyType = isPolyType( (*fnParm)->get_type(), scopeTyVars );1498 Type *polyType = isPolyType( fnParm->get_type(), scopeTyVars ); 1475 1499 if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) { 1476 1500 knownLayouts.insert( mangleType( polyType ) ); -
src/GenPoly/FindFunction.cc
r43e0949 r2f42718 29 29 class FindFunction : public WithGuards, public WithVisitorRef<FindFunction>, public WithShortCircuiting { 30 30 public: 31 FindFunction( std:: list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate );31 FindFunction( std::vector< FunctionType* > & functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate ); 32 32 33 33 void premutate( FunctionType * functionType ); … … 37 37 void handleForall( const Type::ForallList &forall ); 38 38 39 std:: list< FunctionType* > &functions;39 std::vector< FunctionType* > &functions; 40 40 TyVarMap tyVars; 41 41 bool replaceMode; … … 43 43 }; 44 44 45 void findFunction( Type *type, std:: list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {45 void findFunction( Type *type, std::vector< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) { 46 46 PassVisitor<FindFunction> finder( functions, tyVars, false, predicate ); 47 47 type->acceptMutator( finder ); 48 48 } 49 49 50 void findAndReplaceFunction( Type *&type, std:: list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {50 void findAndReplaceFunction( Type *&type, std::vector< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) { 51 51 PassVisitor<FindFunction> finder( functions, tyVars, true, predicate ); 52 52 type = type->acceptMutator( finder ); 53 53 } 54 54 55 FindFunction::FindFunction( std:: list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate )55 FindFunction::FindFunction( std::vector< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate ) 56 56 : functions( functions ), tyVars( tyVars ), replaceMode( replaceMode ), predicate( predicate ) { 57 57 } … … 70 70 GuardScope( tyVars ); 71 71 handleForall( functionType->get_forall() ); 72 mutateAll( functionType-> get_returnVals(), *visitor );72 mutateAll( functionType->returnVals, *visitor ); 73 73 } 74 74 -
src/GenPoly/FindFunction.h
r43e0949 r2f42718 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FindFunction.h -- 7 // FindFunction.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 27 27 28 28 /// recursively walk `type`, placing all functions that match `predicate` under `tyVars` into `functions` 29 void findFunction( Type *type, std:: list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate );29 void findFunction( Type *type, std::vector< FunctionType* > & functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ); 30 30 /// like `findFunction`, but also replaces the function type with void ()(void) 31 void findAndReplaceFunction( Type *&type, std:: list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate );31 void findAndReplaceFunction( Type *&type, std::vector< FunctionType* > & functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ); 32 32 } // namespace GenPoly 33 33 -
src/GenPoly/GenPoly.cc
r43e0949 r2f42718 144 144 145 145 ReferenceToType *isDynRet( FunctionType *function, const TyVarMap &forallTypes ) { 146 if ( function-> get_returnVals().empty() ) return 0;147 148 return (ReferenceToType*)isDynType( function-> get_returnVals().front()->get_type(), forallTypes );146 if ( function->returnVals.empty() ) return 0; 147 148 return (ReferenceToType*)isDynType( function->returnVals.front()->get_type(), forallTypes ); 149 149 } 150 150 151 151 ReferenceToType *isDynRet( FunctionType *function ) { 152 if ( function-> get_returnVals().empty() ) return 0;152 if ( function->returnVals.empty() ) return 0; 153 153 154 154 TyVarMap forallTypes( TypeDecl::Data{} ); 155 155 makeTyVarMap( function, forallTypes ); 156 return (ReferenceToType*)isDynType( function-> get_returnVals().front()->get_type(), forallTypes );156 return (ReferenceToType*)isDynType( function->returnVals.front()->get_type(), forallTypes ); 157 157 } 158 158 159 159 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 160 // if ( ! adaptee->get_returnVals().empty() && isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {161 // return true;162 // } // if163 160 if ( isDynRet( adaptee, tyVars ) ) return true; 164 161 165 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); innerArg != adaptee->get_parameters().end(); ++innerArg ) { 166 // if ( isPolyType( (*innerArg)->get_type(), tyVars ) ) { 167 if ( isDynType( (*innerArg)->get_type(), tyVars ) ) { 162 for ( auto innerArg : adaptee->parameters ) { 163 if ( isDynType( innerArg->get_type(), tyVars ) ) { 168 164 return true; 169 165 } // if … … 315 311 /// Flattens a declaration list 316 312 template<typename Output> 317 void flattenList( list< DeclarationWithType* > src, Output out ) {313 void flattenList( vector< DeclarationWithType* > src, Output out ) { 318 314 for ( DeclarationWithType* decl : src ) { 319 315 ResolvExpr::flatten( decl->get_type(), out ); … … 323 319 /// Flattens a list of types 324 320 template<typename Output> 325 void flattenList( list< Type* > src, Output out ) {321 void flattenList( vector< Type* > src, Output out ) { 326 322 for ( Type* ty : src ) { 327 323 ResolvExpr::flatten( ty, out ); … … 395 391 396 392 vector<Type*> aparams, bparams; 397 flattenList( af-> get_parameters(), back_inserter( aparams ) );398 flattenList( bf-> get_parameters(), back_inserter( bparams ) );393 flattenList( af->parameters, back_inserter( aparams ) ); 394 flattenList( bf->parameters, back_inserter( bparams ) ); 399 395 if ( aparams.size() != bparams.size() ) return false; 400 396 401 397 vector<Type*> areturns, breturns; 402 flattenList( af-> get_returnVals(), back_inserter( areturns ) );403 flattenList( bf-> get_returnVals(), back_inserter( breturns ) );398 flattenList( af->returnVals, back_inserter( areturns ) ); 399 flattenList( bf->returnVals, back_inserter( breturns ) ); 404 400 if ( areturns.size() != breturns.size() ) return false; 405 401 … … 429 425 430 426 vector<Type*> atypes, btypes; 431 flattenList( at-> get_types(), back_inserter( atypes ) );432 flattenList( bt-> get_types(), back_inserter( btypes ) );427 flattenList( at->types, back_inserter( atypes ) ); 428 flattenList( bt->types, back_inserter( btypes ) ); 433 429 if ( atypes.size() != btypes.size() ) return false; 434 430 -
src/GenPoly/Specialize.cc
r43e0949 r2f42718 91 91 if ( tuple1 && tuple2 ) { 92 92 if ( tuple1->size() != tuple2->size() ) return false; 93 for ( auto types : group_iterate( tuple1-> get_types(), tuple2->get_types()) ) {93 for ( auto types : group_iterate( tuple1->types, tuple2->types ) ) { 94 94 if ( ! matchingTupleStructure( std::get<0>( types ), std::get<1>( types ) ) ) return false; 95 95 } … … 115 115 size_t functionParameterSize( FunctionType * ftype ) { 116 116 size_t sz = 0; 117 for ( DeclarationWithType * p : ftype-> get_parameters()) {117 for ( DeclarationWithType * p : ftype->parameters ) { 118 118 sz += singleParameterSize( p->get_type() ); 119 119 } … … 227 227 } 228 228 std::unique_ptr< FunctionType > actualTypeManager( actualType ); // for RAII 229 std::list< DeclarationWithType * >::iterator actualBegin = actualType->get_parameters().begin();230 std::list< DeclarationWithType * >::iterator actualEnd = actualType->get_parameters().end();229 auto actualBegin = actualType->parameters.begin(); 230 auto actualEnd = actualType->parameters.end(); 231 231 232 232 std::list< Expression * > args; 233 for ( DeclarationWithType* param : thunkFunc->get_functionType()-> get_parameters()) {233 for ( DeclarationWithType* param : thunkFunc->get_functionType()->parameters ) { 234 234 // name each thunk parameter and explode it - these are then threaded back into the actual function call. 235 235 param->set_name( paramNamer.newName() ); … … 281 281 FunctionType *function = getFunctionType( appExpr->function->result ); 282 282 assert( function ); 283 std:: list< DeclarationWithType* >::iterator formal;283 std::vector< DeclarationWithType* >::iterator formal; 284 284 std::list< Expression* >::iterator actual; 285 for ( formal = function-> get_parameters().begin(), actual = appExpr->get_args().begin(); formal != function->get_parameters().end() && actual != appExpr->get_args().end(); ++formal, ++actual ) {285 for ( formal = function->parameters.begin(), actual = appExpr->get_args().begin(); formal != function->parameters.end() && actual != appExpr->get_args().end(); ++formal, ++actual ) { 286 286 *actual = doSpecialization( (*formal)->get_type(), *actual, &appExpr->inferParams ); 287 287 }
Note:
See TracChangeset
for help on using the changeset viewer.