Changes in / [2f8d351:4dc3b8c]
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cpp
r2f8d351 r4dc3b8c 40 40 namespace { 41 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 }52 53 42 // -------------------------------------------------------------------------- 54 43 /// Adds layout-generation functions to polymorphic types. … … 71 60 } 72 61 return sizedParams; 62 } 63 64 ast::BasicType * makeSizeAlignType() { 65 return new ast::BasicType( ast::BasicType::LongUnsignedInt ); 73 66 } 74 67 … … 83 76 sizedParam->location, 84 77 sizeofName( paramName ), 85 make LayoutCType()78 makeSizeAlignType() 86 79 ) ); 87 80 params.emplace_back( new ast::ObjectDecl( 88 81 sizedParam->location, 89 82 alignofName( paramName ), 90 make LayoutCType()83 makeSizeAlignType() 91 84 ) ); 92 85 } 93 86 } 94 87 95 ast::Type * make LayoutOutType() {96 return new ast::PointerType( make LayoutType() );88 ast::Type * makeSizeAlignOutType() { 89 return new ast::PointerType( makeSizeAlignType() ); 97 90 } 98 91 … … 111 104 location, 112 105 sizeofName( aggr->name ), 113 make LayoutOutType()106 makeSizeAlignOutType() 114 107 ); 115 108 ast::ObjectDecl * alignParam = new ast::ObjectDecl( 116 109 location, 117 110 alignofName( aggr->name ), 118 make LayoutOutType()111 makeSizeAlignOutType() 119 112 ); 120 113 ast::ObjectDecl * offsetParam = nullptr; … … 124 117 location, 125 118 offsetofName( aggr->name ), 126 make LayoutOutType()119 makeSizeAlignOutType() 127 120 ); 128 121 params.push_back( offsetParam ); … … 1379 1372 }; 1380 1373 1374 // size/align/offset parameters may not be used, so add the unused attribute. 1381 1375 ast::ObjectDecl * makeObj( 1382 1376 CodeLocation const & location, std::string const & name ) { 1383 // The size/align parameters may be unused, so add the unused attribute.1384 1377 return new ast::ObjectDecl( location, name, 1385 make LayoutCType(),1378 makeSizeAlignType(), 1386 1379 nullptr, ast::Storage::Classes(), ast::Linkage::C, nullptr, 1387 1380 { 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;1397 1381 } 1398 1382 … … 1434 1418 } 1435 1419 for ( ast::ptr<ast::DeclWithType> & assert : mutDecl->assertions ) { 1436 ast::DeclWithType * mutAssert = ast::mutate( assert.get() );1437 1420 // Assertion parameters may not be used in body, 1438 1421 // pass along with unused attribute. 1439 mutAssert->attributes.push_back( new ast::Attribute( "unused" ) );1440 mutAssert->set_type( addConst( mutAssert->get_type()) );1441 inferredParams. emplace_back( mutAssert );1422 assert.get_and_mutate()->attributes.push_back( 1423 new ast::Attribute( "unused" ) ); 1424 inferredParams.push_back( assert ); 1442 1425 } 1443 1426 mutDecl->assertions.clear(); … … 1626 1609 1627 1610 /// Converts polymorphic type into a suitable monomorphic representation. 1628 /// Currently: __attribute__(( 1611 /// Currently: __attribute__((aligned(8) )) char[size_T]; 1629 1612 ast::Type * polyToMonoType( CodeLocation const & location, 1630 1613 ast::Type const * declType ) { … … 1632 1615 auto size = new ast::NameExpr( location, 1633 1616 sizeofName( Mangle::mangleType( declType ) ) ); 1617 auto aligned = new ast::Attribute( "aligned", 1618 { ast::ConstantExpr::from_int( location, 8 ) } ); 1634 1619 auto ret = new ast::ArrayType( charType, size, 1635 1620 ast::VariableLen, ast::DynamicDim, ast::CV::Qualifiers() ); 1636 ret->attributes.emplace_back( new ast::Attribute( "aligned", 1637 { ast::ConstantExpr::from_int( location, 8 ) } ) ); 1621 ret->attributes.push_back( aligned ); 1638 1622 return ret; 1639 1623 } … … 1661 1645 ast::TypeInstType inst( decl->name, decl ); 1662 1646 std::string typeName = Mangle::mangleType( &inst ); 1647 ast::Type * layoutType = new ast::BasicType( 1648 ast::BasicType::LongUnsignedInt ); 1663 1649 1664 1650 ast::ObjectDecl * sizeDecl = new ast::ObjectDecl( decl->location, 1665 sizeofName( typeName ), makeLayoutCType(),1651 sizeofName( typeName ), layoutType, 1666 1652 new ast::SingleInit( decl->location, 1667 1653 new ast::SizeofExpr( decl->location, deepCopy( base ) ) … … 1669 1655 ); 1670 1656 ast::ObjectDecl * alignDecl = new ast::ObjectDecl( decl->location, 1671 alignofName( typeName ), makeLayoutCType(),1657 alignofName( typeName ), layoutType, 1672 1658 new ast::SingleInit( decl->location, 1673 1659 new ast::AlignofExpr( decl->location, deepCopy( base ) ) … … 1766 1752 long findMember( ast::DeclWithType const * memberDecl, 1767 1753 const ast::vector<ast::Decl> & baseDecls ) { 1768 for ( auto const & [index, value]: enumerate( baseDecls ) ) {1769 if ( isMember( memberDecl, value.get() ) ) {1770 return index;1754 for ( auto pair : enumerate( baseDecls ) ) { 1755 if ( isMember( memberDecl, pair.val.get() ) ) { 1756 return pair.idx; 1771 1757 } 1772 1758 } … … 1926 1912 knownOffsets.insert( offsetName ); 1927 1913 1914 auto baseMembers = type->base->members; 1915 ast::Type const * offsetType = new ast::BasicType( 1916 ast::BasicType::LongUnsignedInt ); 1917 1928 1918 // Build initializer list for offset array. 1929 1919 ast::vector<ast::Init> inits; 1930 for ( ast::ptr<ast::Decl> const & member : type->base->members ) {1920 for ( ast::ptr<ast::Decl> & member : baseMembers ) { 1931 1921 auto memberDecl = member.as<ast::DeclWithType>(); 1932 1922 assertf( memberDecl, "Requesting offset of non-DWT member: %s", … … 1942 1932 auto offsetArray = makeVar( expr->location, offsetName, 1943 1933 new ast::ArrayType( 1944 makeLayoutType(),1945 ast::ConstantExpr::from_ulong( expr->location, inits.size() ),1934 offsetType, 1935 ast::ConstantExpr::from_ulong( expr->location, baseMembers.size() ), 1946 1936 ast::FixedLen, 1947 1937 ast::DynamicDim … … 2022 2012 // parameters to the layout call. 2023 2013 knownLayouts.insert( typeName ); 2014 ast::Type const * layoutType = makeSizeAlignType(); 2024 2015 2025 2016 int memberCount = inst->base->members.size(); … … 2027 2018 // All empty structures have the same layout (size 1, align 1). 2028 2019 makeVar( location, 2029 sizeofName( typeName ), makeLayoutType(),2020 sizeofName( typeName ), layoutType, 2030 2021 new ast::SingleInit( location, 2031 2022 ast::ConstantExpr::from_ulong( location, 1 ) ) ); 2032 2023 makeVar( location, 2033 alignofName( typeName ), makeLayoutType(),2024 alignofName( typeName ), ast::deepCopy( layoutType ), 2034 2025 new ast::SingleInit( location, 2035 2026 ast::ConstantExpr::from_ulong( location, 1 ) ) ); … … 2037 2028 } else { 2038 2029 ast::ObjectDecl const * sizeofVar = makeVar( location, 2039 sizeofName( typeName ), makeLayoutType(), nullptr );2030 sizeofName( typeName ), deepCopy( layoutType ), nullptr ); 2040 2031 ast::ObjectDecl const * alignofVar = makeVar( location, 2041 alignofName( typeName ), makeLayoutType(), nullptr );2032 alignofName( typeName ), deepCopy( layoutType ), nullptr ); 2042 2033 ast::ObjectDecl const * offsetofVar = makeVar( location, 2043 2034 offsetofName( typeName ), 2044 2035 new ast::ArrayType( 2045 makeLayoutType(),2036 layoutType, 2046 2037 ast::ConstantExpr::from_int( location, memberCount ), 2047 2038 ast::FixedLen, … … 2087 2078 // parameters to the layout call. 2088 2079 knownLayouts.insert( typeName ); 2080 ast::Type const * layoutType = makeSizeAlignType(); 2089 2081 2090 2082 ast::ObjectDecl * sizeofVar = makeVar( location, 2091 sizeofName( typeName ), makeLayoutType());2083 sizeofName( typeName ), layoutType ); 2092 2084 ast::ObjectDecl * alignofVar = makeVar( location, 2093 alignofName( typeName ), makeLayoutType() );2085 alignofName( typeName ), ast::deepCopy( layoutType ) ); 2094 2086 2095 2087 ast::UntypedExpr * layoutCall = new ast::UntypedExpr( location, -
tests/.expect/functions.arm64.txt
r2f8d351 r4dc3b8c 105 105 struct _tuple2_ { 106 106 }; 107 static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, const unsigned long int _sizeof_Y15tuple_param_2_0, const unsigned long int _alignof_Y15tuple_param_2_0, const unsigned long int _sizeof_Y15tuple_param_2_1, constunsigned long int _alignof_Y15tuple_param_2_1){107 static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, unsigned long int _sizeof_Y15tuple_param_2_0, unsigned long int _alignof_Y15tuple_param_2_0, unsigned long int _sizeof_Y15tuple_param_2_1, unsigned long int _alignof_Y15tuple_param_2_1){ 108 108 ((void)((*_sizeof__tuple2_)=0)); 109 109 ((void)((*_alignof__tuple2_)=1)); … … 136 136 struct _tuple3_ { 137 137 }; 138 static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, const unsigned long int _sizeof_Y15tuple_param_3_0, const unsigned long int _alignof_Y15tuple_param_3_0, const unsigned long int _sizeof_Y15tuple_param_3_1, const unsigned long int _alignof_Y15tuple_param_3_1, const unsigned long int _sizeof_Y15tuple_param_3_2, constunsigned long int _alignof_Y15tuple_param_3_2){138 static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, unsigned long int _sizeof_Y15tuple_param_3_0, unsigned long int _alignof_Y15tuple_param_3_0, unsigned long int _sizeof_Y15tuple_param_3_1, unsigned long int _alignof_Y15tuple_param_3_1, unsigned long int _sizeof_Y15tuple_param_3_2, unsigned long int _alignof_Y15tuple_param_3_2){ 139 139 ((void)((*_sizeof__tuple3_)=0)); 140 140 ((void)((*_alignof__tuple3_)=1)); -
tests/.expect/functions.x64.txt
r2f8d351 r4dc3b8c 105 105 struct _tuple2_ { 106 106 }; 107 static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, const unsigned long int _sizeof_Y15tuple_param_2_0, const unsigned long int _alignof_Y15tuple_param_2_0, const unsigned long int _sizeof_Y15tuple_param_2_1, constunsigned long int _alignof_Y15tuple_param_2_1){107 static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, unsigned long int _sizeof_Y15tuple_param_2_0, unsigned long int _alignof_Y15tuple_param_2_0, unsigned long int _sizeof_Y15tuple_param_2_1, unsigned long int _alignof_Y15tuple_param_2_1){ 108 108 ((void)((*_sizeof__tuple2_)=0)); 109 109 ((void)((*_alignof__tuple2_)=1)); … … 136 136 struct _tuple3_ { 137 137 }; 138 static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, const unsigned long int _sizeof_Y15tuple_param_3_0, const unsigned long int _alignof_Y15tuple_param_3_0, const unsigned long int _sizeof_Y15tuple_param_3_1, const unsigned long int _alignof_Y15tuple_param_3_1, const unsigned long int _sizeof_Y15tuple_param_3_2, constunsigned long int _alignof_Y15tuple_param_3_2){138 static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, unsigned long int _sizeof_Y15tuple_param_3_0, unsigned long int _alignof_Y15tuple_param_3_0, unsigned long int _sizeof_Y15tuple_param_3_1, unsigned long int _alignof_Y15tuple_param_3_1, unsigned long int _sizeof_Y15tuple_param_3_2, unsigned long int _alignof_Y15tuple_param_3_2){ 139 139 ((void)((*_sizeof__tuple3_)=0)); 140 140 ((void)((*_alignof__tuple3_)=1)); -
tests/.expect/functions.x86.txt
r2f8d351 r4dc3b8c 105 105 struct _tuple2_ { 106 106 }; 107 static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, const unsigned long int _sizeof_Y15tuple_param_2_0, const unsigned long int _alignof_Y15tuple_param_2_0, const unsigned long int _sizeof_Y15tuple_param_2_1, constunsigned long int _alignof_Y15tuple_param_2_1){107 static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, unsigned long int _sizeof_Y15tuple_param_2_0, unsigned long int _alignof_Y15tuple_param_2_0, unsigned long int _sizeof_Y15tuple_param_2_1, unsigned long int _alignof_Y15tuple_param_2_1){ 108 108 ((void)((*_sizeof__tuple2_)=0)); 109 109 ((void)((*_alignof__tuple2_)=1)); … … 136 136 struct _tuple3_ { 137 137 }; 138 static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, const unsigned long int _sizeof_Y15tuple_param_3_0, const unsigned long int _alignof_Y15tuple_param_3_0, const unsigned long int _sizeof_Y15tuple_param_3_1, const unsigned long int _alignof_Y15tuple_param_3_1, const unsigned long int _sizeof_Y15tuple_param_3_2, constunsigned long int _alignof_Y15tuple_param_3_2){138 static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, unsigned long int _sizeof_Y15tuple_param_3_0, unsigned long int _alignof_Y15tuple_param_3_0, unsigned long int _sizeof_Y15tuple_param_3_1, unsigned long int _alignof_Y15tuple_param_3_1, unsigned long int _sizeof_Y15tuple_param_3_2, unsigned long int _alignof_Y15tuple_param_3_2){ 139 139 ((void)((*_sizeof__tuple3_)=0)); 140 140 ((void)((*_alignof__tuple3_)=1));
Note: See TracChangeset
for help on using the changeset viewer.