Ignore:
Timestamp:
Oct 16, 2023, 8:09:51 AM (14 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
2bf46a5, 54e59dd, 61e5d99
Parents:
946a6e4 (diff), 8cbe732 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/BoxNew.cpp

    r946a6e4 ra97b9ed  
    9494
    9595/// Adds parameters for otype size and alignment to a function type.
    96 void addOTypeParams(
    97                 ast::FunctionDecl * decl,
     96void addSTypeParams(
     97                ast::vector<ast::DeclWithType> & params,
    9898                ast::vector<ast::TypeDecl> const & sizedParams ) {
    99         // TODO: Can we fold this into buildLayoutFunction to avoid rebuilding?
    100         ast::FunctionType * type = ast::mutate( decl->type.get() );
    10199        for ( ast::ptr<ast::TypeDecl> const & sizedParam : sizedParams ) {
    102100                ast::TypeInstType inst( sizedParam );
    103101                std::string paramName = Mangle::mangleType( &inst );
    104                 decl->params.emplace_back( new ast::ObjectDecl(
     102                params.emplace_back( new ast::ObjectDecl(
    105103                        sizedParam->location,
    106104                        sizeofName( paramName ),
    107105                        makeSizeAlignType()
    108106                ) );
    109                 type->params.emplace_back( makeSizeAlignType() );
    110                 decl->params.emplace_back( new ast::ObjectDecl(
     107                params.emplace_back( new ast::ObjectDecl(
    111108                        sizedParam->location,
    112109                        alignofName( paramName ),
    113110                        makeSizeAlignType()
    114111                ) );
    115                 type->params.emplace_back( makeSizeAlignType() );
    116         }
    117         decl->type = type;
     112        }
    118113}
    119114
     
    129124};
    130125
    131 // TODO: Is there a better way to handle the different besides a flag?
    132126LayoutData buildLayoutFunction(
    133127                CodeLocation const & location, ast::AggregateDecl const * aggr,
     128                ast::vector<ast::TypeDecl> const & sizedParams,
    134129                bool isInFunction, bool isStruct ) {
    135130        ast::ObjectDecl * sizeParam = new ast::ObjectDecl(
     
    153148                params.push_back( offsetParam );
    154149        }
     150        addSTypeParams( params, sizedParams );
    155151
    156152        // Routines at global scope marked "static" to prevent multiple
     
    238234
    239235        // Build layout function signature.
    240         LayoutData layout =
    241                 buildLayoutFunction( location, decl, isInFunction(), true );
     236        LayoutData layout = buildLayoutFunction(
     237                location, decl, sizedParams, isInFunction(), true );
    242238        ast::FunctionDecl * layoutDecl = layout.function;
    243239        // Also return these or extract them from the parameter list?
     
    246242        ast::ObjectDecl const * offsetofParam = layout.offsetofParam;
    247243        assert( nullptr != layout.offsetofParam );
    248         addOTypeParams( layoutDecl, sizedParams );
    249244
    250245        // Calculate structure layout in function body.
     
    313308
    314309        // Build layout function signature.
    315         LayoutData layout =
    316                 buildLayoutFunction( location, decl, isInFunction(), false );
     310        LayoutData layout = buildLayoutFunction(
     311                location, decl, sizedParams, isInFunction(), false );
    317312        ast::FunctionDecl * layoutDecl = layout.function;
    318313        // Also return these or extract them from the parameter list?
     
    320315        ast::ObjectDecl const * alignofParam = layout.alignofParam;
    321316        assert( nullptr == layout.offsetofParam );
    322         addOTypeParams( layoutDecl, sizedParams );
    323317
    324318        // Calculate union layout in function body.
     
    641635        // the variable can be reused as a parameter to the call rather than
    642636        // creating a new temporary variable. Previously this step was an
    643         // optimization, but
    644         // ...
    645         // with the introduction of tuples and UniqueExprs, it is necessary to
    646         // ensure that they use the same variable.
     637        // optimization, but with the introduction of tuples and UniqueExprs,
     638        // it is necessary to ensure that they use the same variable.
    647639        // Essentially, looking for pattern:
    648640        // (x=f(...), x)
     
    689681        // the distinction between _conc_T30 and T3(int)) concRetType may not be
    690682        // a good name in one or both of these places.
    691         // TODO A more appropriate name change is welcome.
    692683        if ( dynRetType ) {
    693684                ast::Type const * result = mutExpr->result;
     
    698689        } else if ( needsAdapter( function, scopeTypeVars )
    699690                        && !needsAdapter( function, exprTypeVars ) ) {
    700                 // TODO:
    701                 // The !needsAdapter check may be incorrect. It seems there is some
    702                 // situation where an adapter is applied where it shouldn't be,
    703                 // and this fixes it for some case. More investigation is needed.
    704 
    705691                // Change the application so it calls the adapter rather than the
    706692                // passed function.
     
    17741760        /// Adds type parameters to the layout call; will generate the
    17751761        /// appropriate parameters if needed.
    1776         void addOTypeParamsToLayoutCall(
     1762        void addSTypeParamsToLayoutCall(
    17771763                ast::UntypedExpr * layoutCall,
    17781764                const ast::vector<ast::Type> & otypeParams );
     
    20142000                ast::MemberExpr const * expr ) {
    20152001        // Only mutate member expressions for polymorphic types.
    2016         int typeDepth;
    20172002        ast::Type const * objectType = hasPolyBase(
    2018                 expr->aggregate->result, scopeTypeVars, &typeDepth
     2003                expr->aggregate->result, scopeTypeVars
    20192004        );
    20202005        if ( !objectType ) return expr;
     
    20942079        }
    20952080        // MemberExpr was converted to pointer + offset; and it is not valid C to
    2096         // take the address of an addition, so stript the address-of.
     2081        // take the address of an addition, so strip away the address-of.
    20972082        // It also preserves the env value.
    20982083        return ast::mutate_field( expr->arg.get(), &ast::Expr::env, expr->env );
     
    22952280                                } );
    22962281
    2297                         addOTypeParamsToLayoutCall( layoutCall, sizedParams );
     2282                        addSTypeParamsToLayoutCall( layoutCall, sizedParams );
    22982283
    22992284                        stmtsToAddBefore.emplace_back(
     
    23362321                        } );
    23372322
    2338                 addOTypeParamsToLayoutCall( layoutCall, sizedParams );
     2323                addSTypeParamsToLayoutCall( layoutCall, sizedParams );
    23392324
    23402325                stmtsToAddBefore.emplace_back(
     
    23462331}
    23472332
    2348 void PolyGenericCalculator::addOTypeParamsToLayoutCall(
     2333void PolyGenericCalculator::addSTypeParamsToLayoutCall(
    23492334                ast::UntypedExpr * layoutCall,
    23502335                const ast::vector<ast::Type> & otypeParams ) {
Note: See TracChangeset for help on using the changeset viewer.