Changeset 81da3da4 for src/GenPoly
- Timestamp:
- Dec 11, 2023, 4:18:13 AM (2 years ago)
- Branches:
- master
- Children:
- 21ce2c7, 2554f24
- Parents:
- 5ddb8bf (diff), 1c85ffc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/GenPoly
- Files:
-
- 2 edited
- 6 moved
-
Box.cpp (moved) (moved from src/GenPoly/BoxNew.cpp ) (20 diffs)
-
FindFunction.cc (modified) (1 diff)
-
InstantiateGeneric.cpp (moved) (moved from src/GenPoly/InstantiateGenericNew.cpp ) (2 diffs)
-
Lvalue.cpp (moved) (moved from src/GenPoly/LvalueNew.cpp ) (1 diff)
-
ScrubTypeVars.cpp (moved) (moved from src/GenPoly/ScrubTyVars.cc ) (3 diffs)
-
ScrubTypeVars.hpp (moved) (moved from src/GenPoly/ScrubTyVars.h ) (2 diffs)
-
Specialize.cpp (moved) (moved from src/GenPoly/SpecializeNew.cpp ) (1 diff)
-
module.mk (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cpp
r5ddb8bf r81da3da4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Box New.cpp -- Implement polymorphic function calls and types.7 // Box.cpp -- Implement polymorphic function calls and types. 8 8 // 9 9 // Author : Andrew Beach … … 32 32 #include "GenPoly/Lvalue.h" // for generalizedLvalue 33 33 #include "GenPoly/ScopedSet.h" // for ScopedSet 34 #include "GenPoly/ScrubTy Vars.h"// for scrubTypeVars, scrubAllTypeVars34 #include "GenPoly/ScrubTypeVars.hpp" // for scrubTypeVars, scrubAllTypeVars 35 35 #include "ResolvExpr/Unify.h" // for typesCompatible 36 36 #include "SymTab/Mangler.h" // for mangle, mangleType … … 39 39 40 40 namespace { 41 42 /// The layout type is used to represent sizes, alignments and offsets. 43 ast::BasicType * makeLayoutType() { 44 return new ast::BasicType( ast::BasicType::LongUnsignedInt ); 45 } 46 47 /// Fixed version of layout type (just adding a 'C' in C++ style). 48 ast::BasicType * makeLayoutCType() { 49 return new ast::BasicType( ast::BasicType::LongUnsignedInt, 50 ast::CV::Qualifiers( ast::CV::Const ) ); 51 } 41 52 42 53 // -------------------------------------------------------------------------- … … 60 71 } 61 72 return sizedParams; 62 }63 64 ast::BasicType * makeSizeAlignType() {65 return new ast::BasicType( ast::BasicType::LongUnsignedInt );66 73 } 67 74 … … 76 83 sizedParam->location, 77 84 sizeofName( paramName ), 78 make SizeAlignType()85 makeLayoutCType() 79 86 ) ); 80 87 params.emplace_back( new ast::ObjectDecl( 81 88 sizedParam->location, 82 89 alignofName( paramName ), 83 make SizeAlignType()90 makeLayoutCType() 84 91 ) ); 85 92 } 86 93 } 87 94 88 ast::Type * make SizeAlignOutType() {89 return new ast::PointerType( make SizeAlignType() );95 ast::Type * makeLayoutOutType() { 96 return new ast::PointerType( makeLayoutType() ); 90 97 } 91 98 … … 104 111 location, 105 112 sizeofName( aggr->name ), 106 make SizeAlignOutType()113 makeLayoutOutType() 107 114 ); 108 115 ast::ObjectDecl * alignParam = new ast::ObjectDecl( 109 116 location, 110 117 alignofName( aggr->name ), 111 make SizeAlignOutType()118 makeLayoutOutType() 112 119 ); 113 120 ast::ObjectDecl * offsetParam = nullptr; … … 117 124 location, 118 125 offsetofName( aggr->name ), 119 make SizeAlignOutType()126 makeLayoutOutType() 120 127 ); 121 128 params.push_back( offsetParam ); … … 1372 1379 }; 1373 1380 1374 // size/align/offset parameters may not be used, so add the unused attribute.1375 1381 ast::ObjectDecl * makeObj( 1376 1382 CodeLocation const & location, std::string const & name ) { 1383 // The size/align parameters may be unused, so add the unused attribute. 1377 1384 return new ast::ObjectDecl( location, name, 1378 make SizeAlignType(),1385 makeLayoutCType(), 1379 1386 nullptr, ast::Storage::Classes(), ast::Linkage::C, nullptr, 1380 1387 { new ast::Attribute( "unused" ) } ); 1388 } 1389 1390 /// A modified and specialized version of ast::add_qualifiers. 1391 ast::Type const * addConst( ast::Type const * type ) { 1392 ast::CV::Qualifiers cvq = { ast::CV::Const }; 1393 if ( ( type->qualifiers & cvq ) != 0 ) return type; 1394 auto mutType = ast::mutate( type ); 1395 mutType->qualifiers |= cvq; 1396 return mutType; 1381 1397 } 1382 1398 … … 1418 1434 } 1419 1435 for ( ast::ptr<ast::DeclWithType> & assert : mutDecl->assertions ) { 1436 ast::DeclWithType * mutAssert = ast::mutate( assert.get() ); 1420 1437 // Assertion parameters may not be used in body, 1421 1438 // pass along with unused attribute. 1422 assert.get_and_mutate()->attributes.push_back(1423 new ast::Attribute( "unused") );1424 inferredParams. push_back( assert );1439 mutAssert->attributes.push_back( new ast::Attribute( "unused" ) ); 1440 mutAssert->set_type( addConst( mutAssert->get_type() ) ); 1441 inferredParams.emplace_back( mutAssert ); 1425 1442 } 1426 1443 mutDecl->assertions.clear(); … … 1609 1626 1610 1627 /// Converts polymorphic type into a suitable monomorphic representation. 1611 /// Currently: __attribute__(( aligned(8) )) char[size_T];1628 /// Currently: __attribute__(( aligned(8) )) char[size_T]; 1612 1629 ast::Type * polyToMonoType( CodeLocation const & location, 1613 1630 ast::Type const * declType ) { … … 1615 1632 auto size = new ast::NameExpr( location, 1616 1633 sizeofName( Mangle::mangleType( declType ) ) ); 1617 auto aligned = new ast::Attribute( "aligned",1618 { ast::ConstantExpr::from_int( location, 8 ) } );1619 1634 auto ret = new ast::ArrayType( charType, size, 1620 1635 ast::VariableLen, ast::DynamicDim, ast::CV::Qualifiers() ); 1621 ret->attributes.push_back( aligned ); 1636 ret->attributes.emplace_back( new ast::Attribute( "aligned", 1637 { ast::ConstantExpr::from_int( location, 8 ) } ) ); 1622 1638 return ret; 1623 1639 } … … 1645 1661 ast::TypeInstType inst( decl->name, decl ); 1646 1662 std::string typeName = Mangle::mangleType( &inst ); 1647 ast::Type * layoutType = new ast::BasicType(1648 ast::BasicType::LongUnsignedInt );1649 1663 1650 1664 ast::ObjectDecl * sizeDecl = new ast::ObjectDecl( decl->location, 1651 sizeofName( typeName ), layoutType,1665 sizeofName( typeName ), makeLayoutCType(), 1652 1666 new ast::SingleInit( decl->location, 1653 1667 new ast::SizeofExpr( decl->location, deepCopy( base ) ) … … 1655 1669 ); 1656 1670 ast::ObjectDecl * alignDecl = new ast::ObjectDecl( decl->location, 1657 alignofName( typeName ), layoutType,1671 alignofName( typeName ), makeLayoutCType(), 1658 1672 new ast::SingleInit( decl->location, 1659 1673 new ast::AlignofExpr( decl->location, deepCopy( base ) ) … … 1752 1766 long findMember( ast::DeclWithType const * memberDecl, 1753 1767 const ast::vector<ast::Decl> & baseDecls ) { 1754 for ( auto pair: enumerate( baseDecls ) ) {1755 if ( isMember( memberDecl, pair.val.get() ) ) {1756 return pair.idx;1768 for ( auto const & [index, value] : enumerate( baseDecls ) ) { 1769 if ( isMember( memberDecl, value.get() ) ) { 1770 return index; 1757 1771 } 1758 1772 } … … 1912 1926 knownOffsets.insert( offsetName ); 1913 1927 1914 auto baseMembers = type->base->members;1915 ast::Type const * offsetType = new ast::BasicType(1916 ast::BasicType::LongUnsignedInt );1917 1918 1928 // Build initializer list for offset array. 1919 1929 ast::vector<ast::Init> inits; 1920 for ( ast::ptr<ast::Decl> & member : baseMembers ) {1930 for ( ast::ptr<ast::Decl> const & member : type->base->members ) { 1921 1931 auto memberDecl = member.as<ast::DeclWithType>(); 1922 1932 assertf( memberDecl, "Requesting offset of non-DWT member: %s", … … 1932 1942 auto offsetArray = makeVar( expr->location, offsetName, 1933 1943 new ast::ArrayType( 1934 offsetType,1935 ast::ConstantExpr::from_ulong( expr->location, baseMembers.size() ),1944 makeLayoutType(), 1945 ast::ConstantExpr::from_ulong( expr->location, inits.size() ), 1936 1946 ast::FixedLen, 1937 1947 ast::DynamicDim … … 2012 2022 // parameters to the layout call. 2013 2023 knownLayouts.insert( typeName ); 2014 ast::Type const * layoutType = makeSizeAlignType();2015 2024 2016 2025 int memberCount = inst->base->members.size(); … … 2018 2027 // All empty structures have the same layout (size 1, align 1). 2019 2028 makeVar( location, 2020 sizeofName( typeName ), layoutType,2029 sizeofName( typeName ), makeLayoutType(), 2021 2030 new ast::SingleInit( location, 2022 2031 ast::ConstantExpr::from_ulong( location, 1 ) ) ); 2023 2032 makeVar( location, 2024 alignofName( typeName ), ast::deepCopy( layoutType),2033 alignofName( typeName ), makeLayoutType(), 2025 2034 new ast::SingleInit( location, 2026 2035 ast::ConstantExpr::from_ulong( location, 1 ) ) ); … … 2028 2037 } else { 2029 2038 ast::ObjectDecl const * sizeofVar = makeVar( location, 2030 sizeofName( typeName ), deepCopy( layoutType), nullptr );2039 sizeofName( typeName ), makeLayoutType(), nullptr ); 2031 2040 ast::ObjectDecl const * alignofVar = makeVar( location, 2032 alignofName( typeName ), deepCopy( layoutType), nullptr );2041 alignofName( typeName ), makeLayoutType(), nullptr ); 2033 2042 ast::ObjectDecl const * offsetofVar = makeVar( location, 2034 2043 offsetofName( typeName ), 2035 2044 new ast::ArrayType( 2036 layoutType,2045 makeLayoutType(), 2037 2046 ast::ConstantExpr::from_int( location, memberCount ), 2038 2047 ast::FixedLen, … … 2078 2087 // parameters to the layout call. 2079 2088 knownLayouts.insert( typeName ); 2080 ast::Type const * layoutType = makeSizeAlignType();2081 2089 2082 2090 ast::ObjectDecl * sizeofVar = makeVar( location, 2083 sizeofName( typeName ), layoutType);2091 sizeofName( typeName ), makeLayoutType() ); 2084 2092 ast::ObjectDecl * alignofVar = makeVar( location, 2085 alignofName( typeName ), ast::deepCopy( layoutType) );2093 alignofName( typeName ), makeLayoutType() ); 2086 2094 2087 2095 ast::UntypedExpr * layoutCall = new ast::UntypedExpr( location, -
src/GenPoly/FindFunction.cc
r5ddb8bf r81da3da4 22 22 #include "GenPoly/ErasableScopedMap.h" // for ErasableScopedMap<>::iterator 23 23 #include "GenPoly/GenPoly.h" // for TyVarMap 24 #include "ScrubTy Vars.h" // for ScrubTyVars24 #include "ScrubTypeVars.hpp" // for scrubTypeVars 25 25 26 26 namespace GenPoly { -
src/GenPoly/InstantiateGeneric.cpp
r5ddb8bf r81da3da4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // InstantiateGeneric New.cpp -- Create concrete instances of generic types.7 // InstantiateGeneric.cpp -- Create concrete instances of generic types. 8 8 // 9 9 // Author : Andrew Beach … … 31 31 #include "Common/UniqueName.h" // for UniqueName 32 32 #include "GenPoly/GenPoly.h" // for isPolyType, typesPolyCompatible 33 #include "GenPoly/ScrubTy Vars.h" // for scrubAll33 #include "GenPoly/ScrubTypeVars.hpp" // for scrubAllTypeVars 34 34 #include "ResolvExpr/AdjustExprType.hpp" // for adjustExprType 35 35 #include "ResolvExpr/Unify.h" // for typesCompatible -
src/GenPoly/Lvalue.cpp
r5ddb8bf r81da3da4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Lvalue New.cpp -- Clean up lvalues and remove references.7 // Lvalue.cpp -- Clean up lvalues and remove references. 8 8 // 9 9 // Author : Andrew Beach -
src/GenPoly/ScrubTypeVars.cpp
r5ddb8bf r81da3da4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // ScrubTy Vars.cc-- Remove polymorphic types.7 // ScrubTypeVars.cpp -- Remove polymorphic types. 8 8 // 9 9 // Author : Richard C. Bilson … … 14 14 // 15 15 16 #include "ScrubTypeVars.hpp" 17 16 18 #include <utility> // for pair 17 19 … … 19 21 #include "GenPoly.h" // for mangleType, TyVarMap, alignof... 20 22 #include "GenPoly/ErasableScopedMap.h" // for ErasableScopedMap<>::const_it... 21 #include "ScrubTyVars.h"22 23 #include "SymTab/Mangler.h" // for mangleType 23 24 -
src/GenPoly/ScrubTypeVars.hpp
r5ddb8bf r81da3da4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // ScrubTy Vars.h-- Remove polymorphic types.7 // ScrubTypeVars.hpp -- Remove polymorphic types. 8 8 // 9 9 // Author : Richard C. Bilson … … 16 16 #pragma once 17 17 18 #include <cassert> // for assert18 #include <cassert> // for strict_dynamic_cast 19 19 20 20 #include "AST/Fwd.hpp" // for Node 21 #include "GenPoly.h" // for TypeVarMap , isPolyType, isDynType21 #include "GenPoly.h" // for TypeVarMap 22 22 23 23 namespace GenPoly { -
src/GenPoly/Specialize.cpp
r5ddb8bf r81da3da4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Specialize New.cpp -- Generate thunks to specialize polymorphic functions.7 // Specialize.cpp -- Generate thunks to specialize polymorphic functions. 8 8 // 9 9 // Author : Andrew Beach -
src/GenPoly/module.mk
r5ddb8bf r81da3da4 22 22 23 23 SRC += $(SRC_GENPOLY) \ 24 GenPoly/Box New.cpp \24 GenPoly/Box.cpp \ 25 25 GenPoly/Box.h \ 26 26 GenPoly/ErasableScopedMap.h \ 27 27 GenPoly/FindFunction.cc \ 28 28 GenPoly/FindFunction.h \ 29 GenPoly/InstantiateGeneric New.cpp \29 GenPoly/InstantiateGeneric.cpp \ 30 30 GenPoly/InstantiateGeneric.h \ 31 GenPoly/Lvalue New.cpp \31 GenPoly/Lvalue.cpp \ 32 32 GenPoly/ScopedSet.h \ 33 GenPoly/ScrubTy Vars.cc\34 GenPoly/ScrubTy Vars.h\35 GenPoly/Specialize New.cpp \33 GenPoly/ScrubTypeVars.cpp \ 34 GenPoly/ScrubTypeVars.hpp \ 35 GenPoly/Specialize.cpp \ 36 36 GenPoly/Specialize.h 37 37
Note:
See TracChangeset
for help on using the changeset viewer.