Changes in / [df2be83:e55ca05]
- Location:
- src/GenPoly
- Files:
-
- 1 deleted
- 8 edited
-
Box.cc (modified) (43 diffs)
-
ErasableScopedMap.h (deleted)
-
FindFunction.cc (modified) (3 diffs)
-
GenPoly.cc (modified) (3 diffs)
-
GenPoly.h (modified) (3 diffs)
-
PolyMutator.cc (modified) (1 diff)
-
ScopedMap.h (modified) (7 diffs)
-
ScopedSet.h (modified) (7 diffs)
-
ScrubTyVars.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
rdf2be83 re55ca05 205 205 ObjectDecl *makeTemporary( Type *type ); 206 206 207 ScopedMap< std::string, DeclarationWithType *> assignOps;///< Currently known type variable assignment operators207 std::map< std::string, DeclarationWithType *> assignOps; ///< Currently known type variable assignment operators 208 208 ResolvExpr::TypeMap< DeclarationWithType > scopedAssignOps; ///< Currently known assignment operators 209 209 ScopedMap< std::string, DeclarationWithType* > adapters; ///< Set of adapter functions in the current scope … … 385 385 for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) { 386 386 TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param ); 387 std::string paramName = mangleType( ¶mType ); 388 layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 389 layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( paramName ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 387 layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( ¶mType ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 388 layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( ¶mType ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 390 389 } 391 390 } 392 391 393 392 /// Builds a layout function declaration 394 FunctionDecl *buildLayoutFunctionDecl( AggregateDecl *typeDecl, unsigned int functionNesting, FunctionType *layoutFnType ) {393 FunctionDecl *buildLayoutFunctionDecl( const std::string &typeName, unsigned int functionNesting, FunctionType *layoutFnType ) { 395 394 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units 396 395 // because each unit generates copies of the default routines for each aggregate. 397 396 FunctionDecl *layoutDecl = new FunctionDecl( 398 layoutofName( typeDecl ), functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, layoutFnType, new CompoundStmt( noLabels ), true, false );397 "__layoutof_" + typeName, functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, layoutFnType, new CompoundStmt( noLabels ), true, false ); 399 398 layoutDecl->fixUniqueId(); 400 399 return layoutDecl; … … 463 462 PointerType *sizeAlignOutType = new PointerType( Type::Qualifiers(), sizeAlignType ); 464 463 465 ObjectDecl *sizeParam = new ObjectDecl( sizeofName( structDecl->get_name()), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 );464 ObjectDecl *sizeParam = new ObjectDecl( "__sizeof_" + structDecl->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 ); 466 465 layoutFnType->get_parameters().push_back( sizeParam ); 467 ObjectDecl *alignParam = new ObjectDecl( alignofName( structDecl->get_name()), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );466 ObjectDecl *alignParam = new ObjectDecl( "__alignof_" + structDecl->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 ); 468 467 layoutFnType->get_parameters().push_back( alignParam ); 469 ObjectDecl *offsetParam = new ObjectDecl( offsetofName( structDecl->get_name()), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );468 ObjectDecl *offsetParam = new ObjectDecl( "__offsetof_" + structDecl->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 ); 470 469 layoutFnType->get_parameters().push_back( offsetParam ); 471 470 addOtypeParams( layoutFnType, otypeParams ); 472 471 473 472 // build function decl 474 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( structDecl , functionNesting, layoutFnType );473 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( structDecl->get_name(), functionNesting, layoutFnType ); 475 474 476 475 // calculate struct layout in function body … … 524 523 PointerType *sizeAlignOutType = new PointerType( Type::Qualifiers(), sizeAlignType ); 525 524 526 ObjectDecl *sizeParam = new ObjectDecl( sizeofName( unionDecl->get_name()), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 );525 ObjectDecl *sizeParam = new ObjectDecl( "__sizeof_" + unionDecl->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 ); 527 526 layoutFnType->get_parameters().push_back( sizeParam ); 528 ObjectDecl *alignParam = new ObjectDecl( alignofName( unionDecl->get_name()), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );527 ObjectDecl *alignParam = new ObjectDecl( "__alignof_" + unionDecl->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 ); 529 528 layoutFnType->get_parameters().push_back( alignParam ); 530 529 addOtypeParams( layoutFnType, otypeParams ); 531 530 532 531 // build function decl 533 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( unionDecl , functionNesting, layoutFnType );532 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( unionDecl->get_name(), functionNesting, layoutFnType ); 534 533 535 534 // calculate union layout in function body … … 664 663 if ( functionDecl->get_statements() ) { // empty routine body ? 665 664 doBeginScope(); 666 scopeTyVars.beginScope();;667 assignOps.beginScope();665 TyVarMap oldtyVars = scopeTyVars; 666 std::map< std::string, DeclarationWithType *> oldassignOps = assignOps; 668 667 DeclarationWithType *oldRetval = retval; 669 668 bool oldUseRetval = useRetval; … … 706 705 functionDecl->set_statements( functionDecl->get_statements()->acceptMutator( *this ) ); 707 706 708 scopeTyVars.endScope(); 709 assignOps.endScope(); 707 scopeTyVars = oldtyVars; 708 assignOps = oldassignOps; 709 // std::cerr << "end FunctionDecl: "; 710 // for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) { 711 // std::cerr << i->first << " "; 712 // } 713 // std::cerr << "\n"; 710 714 retval = oldRetval; 711 715 useRetval = oldUseRetval; … … 743 747 Type *polyBase = hasPolyBase( parmType, exprTyVars ); 744 748 if ( polyBase && ! dynamic_cast< TypeInstType* >( polyBase ) ) { 745 std::string typeName = mangleType( polyBase );746 if ( seenTypes.count( typeName ) ) return;749 std::string sizeName = sizeofName( polyBase ); 750 if ( seenTypes.count( sizeName ) ) return; 747 751 748 752 arg = appExpr->get_args().insert( arg, new SizeofExpr( argBaseType->clone() ) ); … … 762 766 } 763 767 764 seenTypes.insert( typeName );768 seenTypes.insert( sizeName ); 765 769 } 766 770 } … … 1120 1124 addAssign->get_args().push_back( appExpr->get_args().front() ); 1121 1125 } // if 1122 addAssign->get_args().push_back( new NameExpr( sizeofName( mangleType( polyType )) ) );1126 addAssign->get_args().push_back( new NameExpr( sizeofName( polyType ) ) ); 1123 1127 addAssign->get_results().front() = appExpr->get_results().front()->clone(); 1124 1128 if ( appExpr->get_env() ) { … … 1147 1151 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 1148 1152 multiply->get_args().push_back( appExpr->get_args().back() ); 1149 multiply->get_args().push_back( new SizeofExpr( baseType1->clone() ) );1153 multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) ); 1150 1154 ret->get_args().push_back( appExpr->get_args().front() ); 1151 1155 ret->get_args().push_back( multiply ); … … 1153 1157 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 1154 1158 multiply->get_args().push_back( appExpr->get_args().front() ); 1155 multiply->get_args().push_back( new SizeofExpr( baseType2->clone() ) );1159 multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) ); 1156 1160 ret->get_args().push_back( multiply ); 1157 1161 ret->get_args().push_back( appExpr->get_args().back() ); … … 1216 1220 UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) ); 1217 1221 divide->get_args().push_back( appExpr ); 1218 divide->get_args().push_back( new SizeofExpr( baseType1->clone() ) );1222 divide->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) ); 1219 1223 divide->get_results().push_front( appExpr->get_results().front()->clone() ); 1220 1224 if ( appExpr->get_env() ) { … … 1226 1230 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 1227 1231 multiply->get_args().push_back( appExpr->get_args().back() ); 1228 multiply->get_args().push_back( new SizeofExpr( baseType1->clone() ) );1232 multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) ); 1229 1233 appExpr->get_args().back() = multiply; 1230 1234 } else if ( baseType2 ) { 1231 1235 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 1232 1236 multiply->get_args().push_back( appExpr->get_args().front() ); 1233 multiply->get_args().push_back( new SizeofExpr( baseType2->clone() ) );1237 multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) ); 1234 1238 appExpr->get_args().front() = multiply; 1235 1239 } // if … … 1241 1245 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 1242 1246 multiply->get_args().push_back( appExpr->get_args().back() ); 1243 multiply->get_args().push_back( new SizeofExpr( baseType->clone() ) );1247 multiply->get_args().push_back( new NameExpr( sizeofName( baseType ) ) ); 1244 1248 appExpr->get_args().back() = multiply; 1245 1249 } // if … … 1278 1282 std::list< Expression *>::iterator paramBegin = appExpr->get_args().begin(); 1279 1283 1280 TyVarMap exprTyVars ( (TypeDecl::Kind)-1 );1284 TyVarMap exprTyVars; 1281 1285 makeTyVarMap( function, exprTyVars ); 1282 1286 ReferenceToType *polyRetType = isPolyRet( function ); … … 1381 1385 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() ) ) { 1382 1386 // find assignment operator for type variable 1383 ScopedMap< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() );1387 std::map< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() ); 1384 1388 if ( assignIter == assignOps.end() ) { 1385 1389 throw SemanticError( "Attempt to return dtype or ftype object in ", returnStmt->get_expr() ); … … 1415 1419 DeclarationWithType *assertAssign = 0; 1416 1420 if ( TypeInstType *formalTypeInstType = dynamic_cast< TypeInstType* >( formalType ) ) { 1417 ScopedMap< std::string, DeclarationWithType *>::const_iterator assertAssignIt = assignOps.find( formalTypeInstType->get_name() );1421 std::map< std::string, DeclarationWithType *>::const_iterator assertAssignIt = assignOps.find( formalTypeInstType->get_name() ); 1418 1422 if ( assertAssignIt == assignOps.end() ) { 1419 1423 throw SemanticError( "No assignment operation found for ", formalTypeInstType ); … … 1456 1460 1457 1461 Type * Pass1::mutate( PointerType *pointerType ) { 1458 scopeTyVars.beginScope();1462 TyVarMap oldtyVars = scopeTyVars; 1459 1463 makeTyVarMap( pointerType, scopeTyVars ); 1460 1464 1461 1465 Type *ret = Mutator::mutate( pointerType ); 1462 1466 1463 scopeTyVars .endScope();1467 scopeTyVars = oldtyVars; 1464 1468 return ret; 1465 1469 } 1466 1470 1467 1471 Type * Pass1::mutate( FunctionType *functionType ) { 1468 scopeTyVars.beginScope();1472 TyVarMap oldtyVars = scopeTyVars; 1469 1473 makeTyVarMap( functionType, scopeTyVars ); 1470 1474 1471 1475 Type *ret = Mutator::mutate( functionType ); 1472 1476 1473 scopeTyVars .endScope();1477 scopeTyVars = oldtyVars; 1474 1478 return ret; 1475 1479 } … … 1536 1540 1537 1541 Type * Pass2::mutate( PointerType *pointerType ) { 1538 scopeTyVars.beginScope();1542 TyVarMap oldtyVars = scopeTyVars; 1539 1543 makeTyVarMap( pointerType, scopeTyVars ); 1540 1544 1541 1545 Type *ret = Mutator::mutate( pointerType ); 1542 1546 1543 scopeTyVars .endScope();1547 scopeTyVars = oldtyVars; 1544 1548 return ret; 1545 1549 } 1546 1550 1547 1551 Type *Pass2::mutate( FunctionType *funcType ) { 1548 scopeTyVars.beginScope();1552 TyVarMap oldtyVars = scopeTyVars; 1549 1553 makeTyVarMap( funcType, scopeTyVars ); 1550 1554 … … 1568 1572 if ( (*tyParm)->get_kind() == TypeDecl::Any ) { 1569 1573 TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm ); 1570 std::string parmName = mangleType( &parmType );1571 1574 1572 1575 sizeParm = newObj.clone(); 1573 sizeParm->set_name( sizeofName( parmName ) );1576 sizeParm->set_name( sizeofName( &parmType ) ); 1574 1577 last = funcType->get_parameters().insert( last, sizeParm ); 1575 1578 ++last; 1576 1579 1577 1580 alignParm = newObj.clone(); 1578 alignParm->set_name( alignofName( parmName ) );1581 alignParm->set_name( alignofName( &parmType ) ); 1579 1582 last = funcType->get_parameters().insert( last, alignParm ); 1580 1583 ++last; … … 1593 1596 Type *polyBase = hasPolyBase( (*fnParm)->get_type(), scopeTyVars ); 1594 1597 if ( polyBase && ! dynamic_cast< TypeInstType* >( polyBase ) ) { 1595 std::string typeName = mangleType( polyBase );1596 if ( seenTypes.count( typeName ) ) continue;1598 std::string sizeName = sizeofName( polyBase ); 1599 if ( seenTypes.count( sizeName ) ) continue; 1597 1600 1598 1601 ObjectDecl *sizeParm, *alignParm, *offsetParm; 1599 1602 sizeParm = newObj.clone(); 1600 sizeParm->set_name( size ofName( typeName ));1603 sizeParm->set_name( sizeName ); 1601 1604 last = funcType->get_parameters().insert( last, sizeParm ); 1602 1605 ++last; 1603 1606 1604 1607 alignParm = newObj.clone(); 1605 alignParm->set_name( alignofName( typeName ) );1608 alignParm->set_name( alignofName( polyBase ) ); 1606 1609 last = funcType->get_parameters().insert( last, alignParm ); 1607 1610 ++last; … … 1611 1614 if ( ! polyBaseStruct->get_baseStruct()->get_members().empty() ) { 1612 1615 offsetParm = newPtr.clone(); 1613 offsetParm->set_name( offsetofName( typeName ) );1616 offsetParm->set_name( offsetofName( polyBase ) ); 1614 1617 last = funcType->get_parameters().insert( last, offsetParm ); 1615 1618 ++last; … … 1617 1620 } 1618 1621 1619 seenTypes.insert( typeName );1622 seenTypes.insert( sizeName ); 1620 1623 } 1621 1624 } … … 1627 1630 mutateAll( funcType->get_parameters(), *this ); 1628 1631 1629 scopeTyVars .endScope();1632 scopeTyVars = oldtyVars; 1630 1633 return funcType; 1631 1634 } … … 1824 1827 template< typename DeclClass > 1825 1828 DeclClass * PolyGenericCalculator::handleDecl( DeclClass *decl, Type *type ) { 1826 scopeTyVars.beginScope();1829 TyVarMap oldtyVars = scopeTyVars; 1827 1830 makeTyVarMap( type, scopeTyVars ); 1828 1831 1829 1832 DeclClass *ret = static_cast< DeclClass *>( Mutator::mutate( decl ) ); 1830 1833 1831 scopeTyVars .endScope();1834 scopeTyVars = oldtyVars; 1832 1835 return ret; 1833 1836 } … … 1851 1854 1852 1855 Type * PolyGenericCalculator::mutate( PointerType *pointerType ) { 1853 scopeTyVars.beginScope();1856 TyVarMap oldtyVars = scopeTyVars; 1854 1857 makeTyVarMap( pointerType, scopeTyVars ); 1855 1858 1856 1859 Type *ret = Mutator::mutate( pointerType ); 1857 1860 1858 scopeTyVars .endScope();1861 scopeTyVars = oldtyVars; 1859 1862 return ret; 1860 1863 } 1861 1864 1862 1865 Type * PolyGenericCalculator::mutate( FunctionType *funcType ) { 1863 scopeTyVars.beginScope();1866 TyVarMap oldtyVars = scopeTyVars; 1864 1867 makeTyVarMap( funcType, scopeTyVars ); 1865 1868 … … 1869 1872 Type *polyBase = hasPolyBase( (*fnParm)->get_type(), scopeTyVars ); 1870 1873 if ( polyBase && ! dynamic_cast< TypeInstType* >( polyBase ) ) { 1871 knownLayouts.insert( mangleType( polyBase ) );1874 knownLayouts.insert( sizeofName( polyBase ) ); 1872 1875 } 1873 1876 } … … 1875 1878 Type *ret = Mutator::mutate( funcType ); 1876 1879 1877 scopeTyVars .endScope();1880 scopeTyVars = oldtyVars; 1878 1881 return ret; 1879 1882 } … … 1886 1889 Type *declType = objectDecl->get_type(); 1887 1890 UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) ); 1888 alloc->get_args().push_back( new NameExpr( sizeofName( mangleType( declType )) ) );1891 alloc->get_args().push_back( new NameExpr( sizeofName( declType ) ) ); 1889 1892 1890 1893 delete objectDecl->get_init(); … … 1918 1921 ConstantExpr *fieldIndex = new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), offset_namer.str() ) ); 1919 1922 UntypedExpr *fieldOffset = new UntypedExpr( new NameExpr( "?[?]" ) ); 1920 fieldOffset->get_args().push_back( new NameExpr( offsetofName( mangleType( objectType )) ) );1923 fieldOffset->get_args().push_back( new NameExpr( offsetofName( objectType ) ) ); 1921 1924 fieldOffset->get_args().push_back( fieldIndex ); 1922 1925 return fieldOffset; … … 1992 1995 if ( findGeneric( *param ) ) { 1993 1996 // push size/align vars for a generic parameter back 1994 std::string paramName = mangleType( *param ); 1995 layoutCall->get_args().push_back( new NameExpr( sizeofName( paramName ) ) ); 1996 layoutCall->get_args().push_back( new NameExpr( alignofName( paramName ) ) ); 1997 layoutCall->get_args().push_back( new NameExpr( sizeofName( *param ) ) ); 1998 layoutCall->get_args().push_back( new NameExpr( alignofName( *param ) ) ); 1997 1999 } else { 1998 2000 layoutCall->get_args().push_back( new SizeofExpr( (*param)->clone() ) ); … … 2038 2040 } else if ( StructInstType *structTy = dynamic_cast< StructInstType* >( ty ) ) { 2039 2041 // check if this type already has a layout generated for it 2040 std::string typeName = mangleType( ty );2041 if ( knownLayouts.find( typeName ) != knownLayouts.end() ) return true;2042 std::string sizeName = sizeofName( ty ); 2043 if ( knownLayouts.find( sizeName ) != knownLayouts.end() ) return true; 2042 2044 2043 2045 // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized … … 2046 2048 2047 2049 // insert local variables for layout and generate call to layout function 2048 knownLayouts.insert( typeName ); // done early so as not to interfere with the later addition of parameters to the layout call2050 knownLayouts.insert( sizeName ); // done early so as not to interfere with the later addition of parameters to the layout call 2049 2051 Type *layoutType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 2050 2052 … … 2052 2054 if ( n_members == 0 ) { 2053 2055 // all empty structs have the same layout - size 1, align 1 2054 makeVar( size ofName( typeName ), layoutType, new SingleInit( new ConstantExpr( Constant::from( (unsigned long)1 ) ) ) );2055 makeVar( alignofName( ty peName), layoutType->clone(), new SingleInit( new ConstantExpr( Constant::from( (unsigned long)1 ) ) ) );2056 makeVar( sizeName, layoutType, new SingleInit( new ConstantExpr( Constant::from( (unsigned long)1 ) ) ) ); 2057 makeVar( alignofName( ty ), layoutType->clone(), new SingleInit( new ConstantExpr( Constant::from( (unsigned long)1 ) ) ) ); 2056 2058 // NOTE zero-length arrays are forbidden in C, so empty structs have no offsetof array 2057 2059 } else { 2058 ObjectDecl *sizeVar = makeVar( size ofName( typeName ), layoutType );2059 ObjectDecl *alignVar = makeVar( alignofName( ty peName), layoutType->clone() );2060 ObjectDecl *offsetVar = makeVar( offsetofName( ty peName), new ArrayType( Type::Qualifiers(), layoutType->clone(), new ConstantExpr( Constant::from( n_members ) ), false, false ) );2060 ObjectDecl *sizeVar = makeVar( sizeName, layoutType ); 2061 ObjectDecl *alignVar = makeVar( alignofName( ty ), layoutType->clone() ); 2062 ObjectDecl *offsetVar = makeVar( offsetofName( ty ), new ArrayType( Type::Qualifiers(), layoutType->clone(), new ConstantExpr( Constant::from( n_members ) ), false, false ) ); 2061 2063 2062 2064 // generate call to layout function 2063 UntypedExpr *layoutCall = new UntypedExpr( new NameExpr( layoutofName( structTy->get_baseStruct()) ) );2065 UntypedExpr *layoutCall = new UntypedExpr( new NameExpr( "__layoutof_" + structTy->get_baseStruct()->get_name() ) ); 2064 2066 layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( sizeVar ) ) ); 2065 2067 layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( alignVar ) ) ); … … 2073 2075 } else if ( UnionInstType *unionTy = dynamic_cast< UnionInstType* >( ty ) ) { 2074 2076 // check if this type already has a layout generated for it 2075 std::string typeName = mangleType( ty );2076 if ( knownLayouts.find( typeName ) != knownLayouts.end() ) return true;2077 std::string sizeName = sizeofName( ty ); 2078 if ( knownLayouts.find( sizeName ) != knownLayouts.end() ) return true; 2077 2079 2078 2080 // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized … … 2081 2083 2082 2084 // insert local variables for layout and generate call to layout function 2083 knownLayouts.insert( typeName ); // done early so as not to interfere with the later addition of parameters to the layout call2085 knownLayouts.insert( sizeName ); // done early so as not to interfere with the later addition of parameters to the layout call 2084 2086 Type *layoutType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 2085 2087 2086 ObjectDecl *sizeVar = makeVar( size ofName( typeName ), layoutType );2087 ObjectDecl *alignVar = makeVar( alignofName( ty peName), layoutType->clone() );2088 ObjectDecl *sizeVar = makeVar( sizeName, layoutType ); 2089 ObjectDecl *alignVar = makeVar( alignofName( ty ), layoutType->clone() ); 2088 2090 2089 2091 // generate call to layout function 2090 UntypedExpr *layoutCall = new UntypedExpr( new NameExpr( layoutofName( unionTy->get_baseUnion()) ) );2092 UntypedExpr *layoutCall = new UntypedExpr( new NameExpr( "__layoutof_" + unionTy->get_baseUnion()->get_name() ) ); 2091 2093 layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( sizeVar ) ) ); 2092 2094 layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( alignVar ) ) ); … … 2104 2106 Type *ty = sizeofExpr->get_type(); 2105 2107 if ( findGeneric( ty ) ) { 2106 Expression *ret = new NameExpr( sizeofName( mangleType( ty )) );2108 Expression *ret = new NameExpr( sizeofName( ty ) ); 2107 2109 delete sizeofExpr; 2108 2110 return ret; … … 2114 2116 Type *ty = alignofExpr->get_type(); 2115 2117 if ( findGeneric( ty ) ) { 2116 Expression *ret = new NameExpr( alignofName( mangleType( ty )) );2118 Expression *ret = new NameExpr( alignofName( ty ) ); 2117 2119 delete alignofExpr; 2118 2120 return ret; … … 2152 2154 if ( findGeneric( ty ) ) { 2153 2155 // pull offset back from generated type information 2154 ret = new NameExpr( offsetofName( mangleType( ty )) );2156 ret = new NameExpr( offsetofName( ty ) ); 2155 2157 } else { 2156 std::string offsetName = offsetofName( mangleType( ty ));2158 std::string offsetName = offsetofName( ty ); 2157 2159 if ( knownOffsets.find( offsetName ) != knownOffsets.end() ) { 2158 2160 // use the already-generated offsets for this type … … 2194 2196 void PolyGenericCalculator::doEndScope() { 2195 2197 knownLayouts.endScope(); 2196 knownOffsets. endScope();2198 knownOffsets.beginScope(); 2197 2199 } 2198 2200 … … 2201 2203 template< typename DeclClass > 2202 2204 DeclClass * Pass3::handleDecl( DeclClass *decl, Type *type ) { 2203 scopeTyVars.beginScope();2205 TyVarMap oldtyVars = scopeTyVars; 2204 2206 makeTyVarMap( type, scopeTyVars ); 2205 2207 … … 2207 2209 ScrubTyVars::scrub( decl, scopeTyVars ); 2208 2210 2209 scopeTyVars .endScope();2211 scopeTyVars = oldtyVars; 2210 2212 return ret; 2211 2213 } … … 2237 2239 2238 2240 Type * Pass3::mutate( PointerType *pointerType ) { 2239 scopeTyVars.beginScope();2241 TyVarMap oldtyVars = scopeTyVars; 2240 2242 makeTyVarMap( pointerType, scopeTyVars ); 2241 2243 2242 2244 Type *ret = Mutator::mutate( pointerType ); 2243 2245 2244 scopeTyVars .endScope();2246 scopeTyVars = oldtyVars; 2245 2247 return ret; 2246 2248 } 2247 2249 2248 2250 Type * Pass3::mutate( FunctionType *functionType ) { 2249 scopeTyVars.beginScope();2251 TyVarMap oldtyVars = scopeTyVars; 2250 2252 makeTyVarMap( functionType, scopeTyVars ); 2251 2253 2252 2254 Type *ret = Mutator::mutate( functionType ); 2253 2255 2254 scopeTyVars .endScope();2256 scopeTyVars = oldtyVars; 2255 2257 return ret; 2256 2258 } -
src/GenPoly/FindFunction.cc
rdf2be83 re55ca05 55 55 TyVarMap::iterator var = tyVars.find( (*i)->get_name() ); 56 56 if ( var != tyVars.end() ) { 57 tyVars.erase( var ->first);57 tyVars.erase( var ); 58 58 } // if 59 59 } // for … … 61 61 62 62 Type * FindFunction::mutate( FunctionType *functionType ) { 63 tyVars.beginScope();63 TyVarMap oldTyVars = tyVars; 64 64 handleForall( functionType->get_forall() ); 65 65 mutateAll( functionType->get_returnVals(), *this ); … … 72 72 } // if 73 73 } // if 74 tyVars .endScope();74 tyVars = oldTyVars; 75 75 return ret; 76 76 } 77 77 78 78 Type * FindFunction::mutate( PointerType *pointerType ) { 79 tyVars.beginScope();79 TyVarMap oldTyVars = tyVars; 80 80 handleForall( pointerType->get_forall() ); 81 81 Type *ret = Mutator::mutate( pointerType ); 82 tyVars .endScope();82 tyVars = oldTyVars; 83 83 return ret; 84 84 } -
src/GenPoly/GenPoly.cc
rdf2be83 re55ca05 16 16 #include "GenPoly.h" 17 17 18 #include "SymTab/Mangler.h" 18 19 #include "SynTree/Expression.h" 19 20 #include "SynTree/Type.h" … … 37 38 ReferenceToType *isPolyRet( FunctionType *function ) { 38 39 if ( ! function->get_returnVals().empty() ) { 39 TyVarMap forallTypes ( (TypeDecl::Kind)-1 );40 TyVarMap forallTypes; 40 41 makeTyVarMap( function, forallTypes ); 41 42 return (ReferenceToType*)isPolyType( function->get_returnVals().front()->get_type(), forallTypes ); … … 217 218 } 218 219 220 std::string sizeofName( Type *ty ) { 221 return std::string( "_sizeof_" ) + SymTab::Mangler::mangleType( ty ); 222 } 223 224 std::string alignofName( Type *ty ) { 225 return std::string( "_alignof_" ) + SymTab::Mangler::mangleType( ty ); 226 } 227 228 std::string offsetofName( Type* ty ) { 229 return std::string( "_offsetof_" ) + SymTab::Mangler::mangleType( ty ); 230 } 231 219 232 } // namespace GenPoly 220 233 -
src/GenPoly/GenPoly.h
rdf2be83 re55ca05 17 17 #define GENPOLY_H 18 18 19 #include <map> 19 20 #include <string> 20 21 #include <iostream> 21 22 #include <utility> 22 23 #include "ErasableScopedMap.h"24 25 #include "SymTab/Mangler.h"26 23 27 24 #include "SynTree/Declaration.h" … … 30 27 31 28 namespace GenPoly { 32 typedef ErasableScopedMap< std::string, TypeDecl::Kind > TyVarMap;29 typedef std::map< std::string, TypeDecl::Kind > TyVarMap; 33 30 34 31 /// A function needs an adapter if it returns a polymorphic value or if any of its … … 72 69 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ); 73 70 74 /// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType(). 75 inline std::string mangleType( Type *ty ) { return SymTab::Mangler::mangleType( ty ); } 76 77 /// Gets the name of the sizeof parameter for the type, given its mangled name 78 inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; } 71 /// Gets the name of the sizeof parameter for the type 72 std::string sizeofName( Type *ty ); 79 73 80 /// Gets the name of the alignof parameter for the type , given its mangled name81 inline std::string alignofName( const std::string &name ) { return std::string( "_alignof_" ) + name; }74 /// Gets the name of the alignof parameter for the type 75 std::string alignofName( Type *ty ); 82 76 83 /// Gets the name of the offsetof parameter for the type, given its mangled name 84 inline std::string offsetofName( const std::string &name ) { return std::string( "_offsetof_" ) + name; } 85 86 /// Gets the name of the layout function for a given aggregate type, given its declaration 87 inline std::string layoutofName( AggregateDecl *decl ) { return std::string( "_layoutof_" ) + decl->get_name(); } 88 77 /// Gets the name of the offsetof parameter for the type 78 std::string offsetofName( Type *ty ); 89 79 } // namespace GenPoly 90 80 -
src/GenPoly/PolyMutator.cc
rdf2be83 re55ca05 27 27 } 28 28 29 PolyMutator::PolyMutator() : scopeTyVars( (TypeDecl::Kind)-1 ), env( 0 ) {} 29 PolyMutator::PolyMutator() : env( 0 ) { 30 } 30 31 31 32 void PolyMutator::mutateStatementList( std::list< Statement* > &statements ) { -
src/GenPoly/ScopedMap.h
rdf2be83 re55ca05 51 51 typedef typename scope_list::size_type size_type; 52 52 53 /// Checks if this iterator points to a valid item54 bool is_valid() const {55 return it != (*scopes)[i].end();56 }57 58 /// Increments on invalid59 iterator& next_valid() {60 if ( ! is_valid() ) { ++(*this); }61 return *this;62 }63 64 /// Decrements on invalid65 iterator& prev_valid() {66 if ( ! is_valid() ) { --(*this); }67 return *this;68 }69 70 53 iterator(scope_list const &_scopes, const wrapped_iterator &_it, size_type _i) 71 54 : scopes(&_scopes), it(_it), i(_i) {} … … 85 68 --i; 86 69 it = (*scopes)[i].begin(); 87 } else {88 ++it;89 }90 return next_valid();70 return *this; 71 } 72 ++it; 73 return *this; 91 74 } 92 75 iterator& operator++ (int) { iterator tmp = *this; ++(*this); return tmp; } … … 99 82 } 100 83 --it; 101 return prev_valid();84 return *this; 102 85 } 103 86 iterator& operator-- (int) { iterator tmp = *this; --(*this); return tmp; } … … 122 105 typedef typename scope_list::size_type size_type; 123 106 124 /// Checks if this iterator points to a valid item125 bool is_valid() const {126 return it != (*scopes)[i].end();127 }128 129 /// Increments on invalid130 const_iterator& next_valid() {131 if ( ! is_valid() ) { ++(*this); }132 return *this;133 }134 135 /// Decrements on invalid136 const_iterator& prev_valid() {137 if ( ! is_valid() ) { --(*this); }138 return *this;139 }140 141 107 const_iterator(scope_list const &_scopes, const wrapped_const_iterator &_it, size_type _i) 142 108 : scopes(&_scopes), it(_it), i(_i) {} … … 161 127 --i; 162 128 it = (*scopes)[i].begin(); 163 } else {164 ++it;165 }166 return next_valid();129 return *this; 130 } 131 ++it; 132 return *this; 167 133 } 168 134 const_iterator& operator++ (int) { const_iterator tmp = *this; ++(*this); return tmp; } … … 175 141 } 176 142 --it; 177 return prev_valid();143 return *this; 178 144 } 179 145 const_iterator& operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; } … … 205 171 ScopedMap() { beginScope(); } 206 172 207 iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1) .next_valid(); }208 const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1) .next_valid(); }209 const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1) .next_valid(); }173 iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1); } 174 const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); } 175 const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); } 210 176 iterator end() { return iterator(scopes, scopes[0].end(), 0); } 211 177 const_iterator end() const { return const_iterator(scopes, scopes[0].end(), 0); } -
src/GenPoly/ScopedSet.h
rdf2be83 re55ca05 48 48 typedef typename scope_list::size_type size_type; 49 49 50 /// Checks if this iterator points to a valid item51 bool is_valid() const {52 return it != (*scopes)[i].end();53 }54 55 /// Increments on invalid56 iterator& next_valid() {57 if ( ! is_valid() ) { ++(*this); }58 return *this;59 }60 61 /// Decrements on invalid62 iterator& prev_valid() {63 if ( ! is_valid() ) { --(*this); }64 return *this;65 }66 67 50 iterator(scope_list const &_scopes, const wrapped_iterator &_it, size_type _i) 68 51 : scopes(&_scopes), it(_it), i(_i) {} … … 82 65 --i; 83 66 it = (*scopes)[i].begin(); 84 } else {85 ++it;86 }87 return next_valid();67 return *this; 68 } 69 ++it; 70 return *this; 88 71 } 89 72 iterator& operator++ (int) { iterator tmp = *this; ++(*this); return tmp; } … … 96 79 } 97 80 --it; 98 return prev_valid();81 return *this; 99 82 } 100 83 iterator& operator-- (int) { iterator tmp = *this; --(*this); return tmp; } … … 119 102 typedef typename scope_list::size_type size_type; 120 103 121 /// Checks if this iterator points to a valid item122 bool is_valid() const {123 return it != (*scopes)[i].end();124 }125 126 /// Increments on invalid127 const_iterator& next_valid() {128 if ( ! is_valid() ) { ++(*this); }129 return *this;130 }131 132 /// Decrements on invalid133 const_iterator& prev_valid() {134 if ( ! is_valid() ) { --(*this); }135 return *this;136 }137 138 104 const_iterator(scope_list const &_scopes, const wrapped_const_iterator &_it, size_type _i) 139 105 : scopes(&_scopes), it(_it), i(_i) {} … … 158 124 --i; 159 125 it = (*scopes)[i].begin(); 160 } else {161 ++it;162 }163 return next_valid();126 return *this; 127 } 128 ++it; 129 return *this; 164 130 } 165 131 const_iterator& operator++ (int) { const_iterator tmp = *this; ++(*this); return tmp; } … … 172 138 } 173 139 --it; 174 return prev_valid();140 return *this; 175 141 } 176 142 const_iterator& operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; } … … 201 167 ScopedSet() { beginScope(); } 202 168 203 iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1) .next_valid(); }204 const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1) .next_valid(); }205 const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1) .next_valid(); }169 iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1); } 170 const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); } 171 const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); } 206 172 iterator end() { return iterator(scopes, scopes[0].end(), 0); } 207 173 const_iterator end() const { return const_iterator(scopes, scopes[0].end(), 0); } -
src/GenPoly/ScrubTyVars.cc
rdf2be83 re55ca05 64 64 // sizeof( T ) => _sizeof_T parameter, which is the size of T 65 65 if ( Type *polyType = isPolyType( szeof->get_type() ) ) { 66 Expression *expr = new NameExpr( sizeofName( mangleType( polyType )) );66 Expression *expr = new NameExpr( sizeofName( polyType ) ); 67 67 return expr; 68 68 } else { … … 74 74 // alignof( T ) => _alignof_T parameter, which is the alignment of T 75 75 if ( Type *polyType = isPolyType( algnof->get_type() ) ) { 76 Expression *expr = new NameExpr( alignofName( mangleType( polyType )) );76 Expression *expr = new NameExpr( alignofName( polyType ) ); 77 77 return expr; 78 78 } else {
Note:
See TracChangeset
for help on using the changeset viewer.