Changeset dd900b5
- Timestamp:
- Dec 1, 2023, 2:37:02 PM (13 months ago)
- Branches:
- master
- Children:
- c4b9fa9
- Parents:
- c4570af3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cpp
rc4570af3 rdd900b5 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 42 53 // -------------------------------------------------------------------------- 43 54 /// Adds layout-generation functions to polymorphic types. … … 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(); … … 1645 1662 ast::TypeInstType inst( decl->name, decl ); 1646 1663 std::string typeName = Mangle::mangleType( &inst ); 1647 ast::Type * layoutType = new ast::BasicType(1648 ast::BasicType::LongUnsignedInt );1649 1664 1650 1665 ast::ObjectDecl * sizeDecl = new ast::ObjectDecl( decl->location, 1651 sizeofName( typeName ), layoutType,1666 sizeofName( typeName ), makeLayoutCType(), 1652 1667 new ast::SingleInit( decl->location, 1653 1668 new ast::SizeofExpr( decl->location, deepCopy( base ) ) … … 1655 1670 ); 1656 1671 ast::ObjectDecl * alignDecl = new ast::ObjectDecl( decl->location, 1657 alignofName( typeName ), layoutType,1672 alignofName( typeName ), makeLayoutCType(), 1658 1673 new ast::SingleInit( decl->location, 1659 1674 new ast::AlignofExpr( decl->location, deepCopy( base ) ) … … 1912 1927 knownOffsets.insert( offsetName ); 1913 1928 1914 auto baseMembers = type->base->members;1915 ast::Type const * offsetType = new ast::BasicType(1916 ast::BasicType::LongUnsignedInt );1917 1918 1929 // Build initializer list for offset array. 1919 1930 ast::vector<ast::Init> inits; 1920 for ( ast::ptr<ast::Decl> & member : baseMembers ) {1931 for ( ast::ptr<ast::Decl> const & member : type->base->members ) { 1921 1932 auto memberDecl = member.as<ast::DeclWithType>(); 1922 1933 assertf( memberDecl, "Requesting offset of non-DWT member: %s", … … 1932 1943 auto offsetArray = makeVar( expr->location, offsetName, 1933 1944 new ast::ArrayType( 1934 offsetType,1935 ast::ConstantExpr::from_ulong( expr->location, baseMembers.size() ),1945 makeLayoutType(), 1946 ast::ConstantExpr::from_ulong( expr->location, inits.size() ), 1936 1947 ast::FixedLen, 1937 1948 ast::DynamicDim … … 2012 2023 // parameters to the layout call. 2013 2024 knownLayouts.insert( typeName ); 2014 ast::Type const * layoutType = makeSizeAlignType();2015 2025 2016 2026 int memberCount = inst->base->members.size(); … … 2018 2028 // All empty structures have the same layout (size 1, align 1). 2019 2029 makeVar( location, 2020 sizeofName( typeName ), layoutType,2030 sizeofName( typeName ), makeLayoutType(), 2021 2031 new ast::SingleInit( location, 2022 2032 ast::ConstantExpr::from_ulong( location, 1 ) ) ); 2023 2033 makeVar( location, 2024 alignofName( typeName ), ast::deepCopy( layoutType),2034 alignofName( typeName ), makeLayoutType(), 2025 2035 new ast::SingleInit( location, 2026 2036 ast::ConstantExpr::from_ulong( location, 1 ) ) ); … … 2028 2038 } else { 2029 2039 ast::ObjectDecl const * sizeofVar = makeVar( location, 2030 sizeofName( typeName ), deepCopy( layoutType), nullptr );2040 sizeofName( typeName ), makeLayoutType(), nullptr ); 2031 2041 ast::ObjectDecl const * alignofVar = makeVar( location, 2032 alignofName( typeName ), deepCopy( layoutType), nullptr );2042 alignofName( typeName ), makeLayoutType(), nullptr ); 2033 2043 ast::ObjectDecl const * offsetofVar = makeVar( location, 2034 2044 offsetofName( typeName ), 2035 2045 new ast::ArrayType( 2036 layoutType,2046 makeLayoutType(), 2037 2047 ast::ConstantExpr::from_int( location, memberCount ), 2038 2048 ast::FixedLen, … … 2078 2088 // parameters to the layout call. 2079 2089 knownLayouts.insert( typeName ); 2080 ast::Type const * layoutType = makeSizeAlignType();2081 2090 2082 2091 ast::ObjectDecl * sizeofVar = makeVar( location, 2083 sizeofName( typeName ), layoutType);2092 sizeofName( typeName ), makeLayoutType() ); 2084 2093 ast::ObjectDecl * alignofVar = makeVar( location, 2085 alignofName( typeName ), ast::deepCopy( layoutType) );2094 alignofName( typeName ), makeLayoutType() ); 2086 2095 2087 2096 ast::UntypedExpr * layoutCall = new ast::UntypedExpr( location, -
tests/.expect/functions.arm64.txt
rc4570af3 rdd900b5 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_, 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){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, const 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_, 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){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, const 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
rc4570af3 rdd900b5 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_, 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){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, const 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_, 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){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, const 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
rc4570af3 rdd900b5 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_, 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){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, const 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_, 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){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, const 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.