Changes in / [2f8d351:4dc3b8c]


Ignore:
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cpp

    r2f8d351 r4dc3b8c  
    4040namespace {
    4141
    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 
    5342// --------------------------------------------------------------------------
    5443/// Adds layout-generation functions to polymorphic types.
     
    7160        }
    7261        return sizedParams;
     62}
     63
     64ast::BasicType * makeSizeAlignType() {
     65        return new ast::BasicType( ast::BasicType::LongUnsignedInt );
    7366}
    7467
     
    8376                        sizedParam->location,
    8477                        sizeofName( paramName ),
    85                         makeLayoutCType()
     78                        makeSizeAlignType()
    8679                ) );
    8780                params.emplace_back( new ast::ObjectDecl(
    8881                        sizedParam->location,
    8982                        alignofName( paramName ),
    90                         makeLayoutCType()
     83                        makeSizeAlignType()
    9184                ) );
    9285        }
    9386}
    9487
    95 ast::Type * makeLayoutOutType() {
    96         return new ast::PointerType( makeLayoutType() );
     88ast::Type * makeSizeAlignOutType() {
     89        return new ast::PointerType( makeSizeAlignType() );
    9790}
    9891
     
    111104                location,
    112105                sizeofName( aggr->name ),
    113                 makeLayoutOutType()
     106                makeSizeAlignOutType()
    114107        );
    115108        ast::ObjectDecl * alignParam = new ast::ObjectDecl(
    116109                location,
    117110                alignofName( aggr->name ),
    118                 makeLayoutOutType()
     111                makeSizeAlignOutType()
    119112        );
    120113        ast::ObjectDecl * offsetParam = nullptr;
     
    124117                        location,
    125118                        offsetofName( aggr->name ),
    126                         makeLayoutOutType()
     119                        makeSizeAlignOutType()
    127120                );
    128121                params.push_back( offsetParam );
     
    13791372};
    13801373
     1374// size/align/offset parameters may not be used, so add the unused attribute.
    13811375ast::ObjectDecl * makeObj(
    13821376                CodeLocation const & location, std::string const & name ) {
    1383         // The size/align parameters may be unused, so add the unused attribute.
    13841377        return new ast::ObjectDecl( location, name,
    1385                 makeLayoutCType(),
     1378                makeSizeAlignType(),
    13861379                nullptr, ast::Storage::Classes(), ast::Linkage::C, nullptr,
    13871380                { 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;
    13971381}
    13981382
     
    14341418        }
    14351419        for ( ast::ptr<ast::DeclWithType> & assert : mutDecl->assertions ) {
    1436                 ast::DeclWithType * mutAssert = ast::mutate( assert.get() );
    14371420                // Assertion parameters may not be used in body,
    14381421                // 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 );
    14421425        }
    14431426        mutDecl->assertions.clear();
     
    16261609
    16271610/// Converts polymorphic type into a suitable monomorphic representation.
    1628 /// Currently: __attribute__(( aligned(8) )) char[size_T];
     1611/// Currently: __attribute__((aligned(8) )) char[size_T];
    16291612ast::Type * polyToMonoType( CodeLocation const & location,
    16301613                ast::Type const * declType ) {
     
    16321615        auto size = new ast::NameExpr( location,
    16331616                sizeofName( Mangle::mangleType( declType ) ) );
     1617        auto aligned = new ast::Attribute( "aligned",
     1618                { ast::ConstantExpr::from_int( location, 8 ) } );
    16341619        auto ret = new ast::ArrayType( charType, size,
    16351620                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 );
    16381622        return ret;
    16391623}
     
    16611645        ast::TypeInstType inst( decl->name, decl );
    16621646        std::string typeName = Mangle::mangleType( &inst );
     1647        ast::Type * layoutType = new ast::BasicType(
     1648                ast::BasicType::LongUnsignedInt );
    16631649
    16641650        ast::ObjectDecl * sizeDecl = new ast::ObjectDecl( decl->location,
    1665                 sizeofName( typeName ), makeLayoutCType(),
     1651                sizeofName( typeName ), layoutType,
    16661652                new ast::SingleInit( decl->location,
    16671653                        new ast::SizeofExpr( decl->location, deepCopy( base ) )
     
    16691655        );
    16701656        ast::ObjectDecl * alignDecl = new ast::ObjectDecl( decl->location,
    1671                 alignofName( typeName ), makeLayoutCType(),
     1657                alignofName( typeName ), layoutType,
    16721658                new ast::SingleInit( decl->location,
    16731659                        new ast::AlignofExpr( decl->location, deepCopy( base ) )
     
    17661752long findMember( ast::DeclWithType const * memberDecl,
    17671753                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;
    17711757                }
    17721758        }
     
    19261912        knownOffsets.insert( offsetName );
    19271913
     1914        auto baseMembers = type->base->members;
     1915        ast::Type const * offsetType = new ast::BasicType(
     1916                ast::BasicType::LongUnsignedInt );
     1917
    19281918        // Build initializer list for offset array.
    19291919        ast::vector<ast::Init> inits;
    1930         for ( ast::ptr<ast::Decl> const & member : type->base->members ) {
     1920        for ( ast::ptr<ast::Decl> & member : baseMembers ) {
    19311921                auto memberDecl = member.as<ast::DeclWithType>();
    19321922                assertf( memberDecl, "Requesting offset of non-DWT member: %s",
     
    19421932        auto offsetArray = makeVar( expr->location, offsetName,
    19431933                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() ),
    19461936                        ast::FixedLen,
    19471937                        ast::DynamicDim
     
    20222012                // parameters to the layout call.
    20232013                knownLayouts.insert( typeName );
     2014                ast::Type const * layoutType = makeSizeAlignType();
    20242015
    20252016                int memberCount = inst->base->members.size();
     
    20272018                        // All empty structures have the same layout (size 1, align 1).
    20282019                        makeVar( location,
    2029                                 sizeofName( typeName ), makeLayoutType(),
     2020                                sizeofName( typeName ), layoutType,
    20302021                                new ast::SingleInit( location,
    20312022                                                ast::ConstantExpr::from_ulong( location, 1 ) ) );
    20322023                        makeVar( location,
    2033                                 alignofName( typeName ), makeLayoutType(),
     2024                                alignofName( typeName ), ast::deepCopy( layoutType ),
    20342025                                new ast::SingleInit( location,
    20352026                                                ast::ConstantExpr::from_ulong( location, 1 ) ) );
     
    20372028                } else {
    20382029                        ast::ObjectDecl const * sizeofVar = makeVar( location,
    2039                                 sizeofName( typeName ), makeLayoutType(), nullptr );
     2030                                sizeofName( typeName ), deepCopy( layoutType ), nullptr );
    20402031                        ast::ObjectDecl const * alignofVar = makeVar( location,
    2041                                 alignofName( typeName ), makeLayoutType(), nullptr );
     2032                                alignofName( typeName ), deepCopy( layoutType ), nullptr );
    20422033                        ast::ObjectDecl const * offsetofVar = makeVar( location,
    20432034                                offsetofName( typeName ),
    20442035                                new ast::ArrayType(
    2045                                         makeLayoutType(),
     2036                                        layoutType,
    20462037                                        ast::ConstantExpr::from_int( location, memberCount ),
    20472038                                        ast::FixedLen,
     
    20872078                // parameters to the layout call.
    20882079                knownLayouts.insert( typeName );
     2080                ast::Type const * layoutType = makeSizeAlignType();
    20892081
    20902082                ast::ObjectDecl * sizeofVar = makeVar( location,
    2091                         sizeofName( typeName ), makeLayoutType() );
     2083                        sizeofName( typeName ), layoutType );
    20922084                ast::ObjectDecl * alignofVar = makeVar( location,
    2093                         alignofName( typeName ), makeLayoutType() );
     2085                        alignofName( typeName ), ast::deepCopy( layoutType ) );
    20942086
    20952087                ast::UntypedExpr * layoutCall = new ast::UntypedExpr( location,
  • tests/.expect/functions.arm64.txt

    r2f8d351 r4dc3b8c  
    105105struct _tuple2_ {
    106106};
    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){
     107static 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){
    108108    ((void)((*_sizeof__tuple2_)=0));
    109109    ((void)((*_alignof__tuple2_)=1));
     
    136136struct _tuple3_ {
    137137};
    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){
     138static 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){
    139139    ((void)((*_sizeof__tuple3_)=0));
    140140    ((void)((*_alignof__tuple3_)=1));
  • tests/.expect/functions.x64.txt

    r2f8d351 r4dc3b8c  
    105105struct _tuple2_ {
    106106};
    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){
     107static 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){
    108108    ((void)((*_sizeof__tuple2_)=0));
    109109    ((void)((*_alignof__tuple2_)=1));
     
    136136struct _tuple3_ {
    137137};
    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){
     138static 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){
    139139    ((void)((*_sizeof__tuple3_)=0));
    140140    ((void)((*_alignof__tuple3_)=1));
  • tests/.expect/functions.x86.txt

    r2f8d351 r4dc3b8c  
    105105struct _tuple2_ {
    106106};
    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){
     107static 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){
    108108    ((void)((*_sizeof__tuple2_)=0));
    109109    ((void)((*_alignof__tuple2_)=1));
     
    136136struct _tuple3_ {
    137137};
    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){
     138static 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){
    139139    ((void)((*_sizeof__tuple3_)=0));
    140140    ((void)((*_alignof__tuple3_)=1));
Note: See TracChangeset for help on using the changeset viewer.