Changeset dd33c1f


Ignore:
Timestamp:
Jul 26, 2022, 2:17:49 PM (21 months ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
1b97cc87
Parents:
4c48be0 (diff), 3992098 (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

Location:
src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    r4c48be0 rdd33c1f  
    108108        ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type,
    109109                const Init * init = nullptr, Storage::Classes storage = {},
    110                 Linkage::Spec linkage = Linkage::C, const Expr * bitWd = nullptr,
     110                Linkage::Spec linkage = Linkage::Cforall, const Expr * bitWd = nullptr,
    111111                std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {} )
    112112        : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ),
     
    143143        FunctionDecl( const CodeLocation & loc, const std::string & name, std::vector<ptr<TypeDecl>>&& forall,
    144144                std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
    145                 CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
     145                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::Cforall,
    146146                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}, bool isVarArgs = false);
    147147
     
    149149                std::vector<ptr<TypeDecl>>&& forall, std::vector<ptr<DeclWithType>>&& assertions,
    150150                std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
    151                 CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
     151                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::Cforall,
    152152                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}, bool isVarArgs = false);
    153153
  • src/AST/Pass.impl.hpp

    r4c48be0 rdd33c1f  
    597597                        guard_symtab guard { *this };
    598598                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
     599                        // This is a C name and so has C linkage.
    599600                        static ast::ptr< ast::ObjectDecl > func{ new ast::ObjectDecl{
    600601                                CodeLocation{}, "__func__",
     
    602603                                        new ast::BasicType{ ast::BasicType::Char, ast::CV::Const },
    603604                                        nullptr, VariableLen, DynamicDim
    604                                 }
     605                                },
     606                                nullptr,
     607                                ast::Storage::Classes(),
     608                                ast::Linkage::C,
    605609                        } };
    606610                        __pass::symtab::addId( core, 0, func );
  • src/Concurrency/KeywordsNew.cpp

    r4c48be0 rdd33c1f  
    398398                        new ast::ReferenceType( vtable_object->type, ast::CV::Const ),
    399399                        new ast::SingleInit( location,
    400                                 new ast::VariableExpr( location, vtable_object ) ),
    401                         ast::Storage::Classes(),
    402                         ast::Linkage::Cforall
     400                                new ast::VariableExpr( location, vtable_object ) )
    403401                )
    404402        );
     
    471469                location,
    472470                "this",
    473                 new ast::ReferenceType( new ast::StructInstType( decl ) ),
    474                 nullptr,
    475                 ast::Storage::Classes(),
    476                 ast::Linkage::Cforall
     471                new ast::ReferenceType( new ast::StructInstType( decl ) )
    477472        );
    478473
     
    480475                location,
    481476                "ret",
    482                 new ast::PointerType( new ast::StructInstType( type_decl ) ),
    483                 nullptr,
    484                 ast::Storage::Classes(),
    485                 ast::Linkage::Cforall
     477                new ast::PointerType( new ast::StructInstType( type_decl ) )
    486478        );
    487479
     
    530522                location,
    531523                field_name,
    532                 new ast::StructInstType( type_decl ),
    533                 nullptr,
    534                 ast::Storage::Classes(),
    535                 ast::Linkage::Cforall
     524                new ast::StructInstType( type_decl )
    536525        );
    537526
     
    577566                location,
    578567                "this",
    579                 new ast::ReferenceType( new ast::StructInstType( decl ) ),
    580                 nullptr,
    581                 ast::Storage::Classes(),
    582                 ast::Linkage::Cforall
     568                new ast::ReferenceType( new ast::StructInstType( decl ) )
    583569        );
    584570
     
    10771063                                ) }
    10781064                        )
    1079                 ),
    1080                 ast::Storage::Classes(),
    1081                 ast::Linkage::Cforall
     1065                )
    10821066        );
    10831067
     
    11071091                                {},
    11081092                                ast::MaybeConstruct
    1109                         ),
    1110                         ast::Storage::Classes(),
    1111                         ast::Linkage::Cforall
     1093                        )
    11121094                ))
    11131095        );
     
    11611143                                }
    11621144                        )
    1163                 ),
    1164                 ast::Storage::Classes(),
    1165                 ast::Linkage::Cforall
     1145                )
    11661146        );
    11671147
     
    11901170                                {},
    11911171                                ast::MaybeConstruct
    1192                         ),
    1193                         ast::Storage::Classes(),
    1194                         ast::Linkage::Cforall
     1172                        )
    11951173                ))
    11961174        );
     
    12961274                                }
    12971275                        )
    1298                 ),
    1299                 ast::Storage::Classes(),
    1300                 ast::Linkage::Cforall
     1276                )
    13011277        );
    13021278
     
    13701346                                        {},
    13711347                                        ast::MaybeConstruct
    1372                                 ),
    1373                                 ast::Storage::Classes(),
    1374                                 ast::Linkage::Cforall
     1348                                )
    13751349                        )
    13761350                )
     
    15131487                                {},
    15141488                                ast::MaybeConstruct
    1515                         ),
    1516                         ast::Storage::Classes(),
    1517                         ast::Linkage::Cforall
     1489                        )
    15181490                )
    15191491        ));
  • src/ControlStruct/ExceptDeclNew.cpp

    r4c48be0 rdd33c1f  
    110110                "parent",
    111111                new ast::PointerType(
    112                         new ast::StructInstType( "__cfavir_type_info", ast::CV::Const ) ),
    113                 nullptr,
    114                 ast::Storage::Classes(),
    115                 ast::Linkage::Cforall
     112                        new ast::StructInstType( "__cfavir_type_info", ast::CV::Const ) )
    116113        ) );
    117114        decl->body = true;
     
    166163                location,
    167164                "__cfavir_typeid",
    168                 new ast::PointerType( typeIdType ),
    169                 nullptr,
    170                 ast::Storage::Classes(),
    171                 ast::Linkage::Cforall
     165                new ast::PointerType( typeIdType )
    172166        );
    173167        ast::ObjectDecl * size = new ast::ObjectDecl(
    174168                location,
    175169                "size",
    176                 new ast::TypeInstType( "size_t", ast::TypeDecl::Dtype ),
    177                 nullptr,
    178                 ast::Storage::Classes(),
    179                 ast::Linkage::Cforall
     170                new ast::TypeInstType( "size_t", ast::TypeDecl::Dtype )
    180171        );
    181172        ast::ObjectDecl * copy = new ast::ObjectDecl(
    182173                location,
    183174                "copy",
    184                 new ast::PointerType( createCopyFuncType( exceptionName, params ) ),
    185                 nullptr,
    186                 ast::Storage::Classes(),
    187                 ast::Linkage::Cforall
     175                new ast::PointerType( createCopyFuncType( exceptionName, params ) )
    188176        );
    189177        ast::ObjectDecl * dtor = new ast::ObjectDecl(
    190178                location,
    191179                "^?{}",
    192                 new ast::PointerType( createDtorFuncType( exceptionName, params ) ),
    193                 nullptr,
    194                 ast::Storage::Classes(),
    195                 ast::Linkage::Cforall
     180                new ast::PointerType( createDtorFuncType( exceptionName, params ) )
    196181        );
    197182        ast::ObjectDecl * msg = new ast::ObjectDecl(
    198183                location,
    199184                "msg",
    200                 new ast::PointerType( createMsgFuncType( exceptionName, params ) ),
    201                 nullptr,
    202                 ast::Storage::Classes(),
    203                 ast::Linkage::Cforall
     185                new ast::PointerType( createMsgFuncType( exceptionName, params ) )
    204186        );
    205187        ast::StructDecl * decl = new ast::StructDecl(
     
    229211                "virtual_table",
    230212                new ast::PointerType(
    231                         createVTableInstType( exceptionName, params ) ),
    232                 nullptr,
    233                 ast::Storage::Classes(),
    234                 ast::Linkage::Cforall
     213                        createVTableInstType( exceptionName, params ) )
    235214        ) );
    236215        for ( ast::ptr<ast::Decl> const & member : members ) {
     
    289268                                "this",
    290269                                new ast::PointerType(
    291                                         createExceptionInstType( exceptionName, params ) ),
    292                                 nullptr,
    293                                 ast::Storage::Classes(),
    294                                 ast::Linkage::Cforall
     270                                        createExceptionInstType( exceptionName, params ) )
    295271                        ),
    296272                        new ast::ObjectDecl(
     
    298274                                "that",
    299275                                new ast::PointerType(
    300                                         createExceptionInstType( exceptionName, params ) ),
    301                                 nullptr,
    302                                 ast::Storage::Classes(),
    303                                 ast::Linkage::Cforall
     276                                        createExceptionInstType( exceptionName, params ) )
    304277                        ),
    305278                },
    306279                {
    307                         new ast::ObjectDecl(
    308                                 location,
    309                                 "",
    310                                 new ast::VoidType(),
    311                                 nullptr,
    312                                 ast::Storage::Classes(),
    313                                 ast::Linkage::Cforall
    314                         ),
     280                        new ast::ObjectDecl( location, "", new ast::VoidType() ),
    315281                },
    316282                new ast::CompoundStmt( location, {
     
    366332                                "this",
    367333                                new ast::PointerType(
    368                                         createExceptionInstType( exceptionName, params ) ),
    369                                 nullptr,
    370                                 ast::Storage::Classes(),
    371                                 ast::Linkage::Cforall
     334                                        createExceptionInstType( exceptionName, params ) )
    372335                        ),
    373336                },
     
    377340                                "",
    378341                                new ast::PointerType(
    379                                         new ast::BasicType( ast::BasicType::Char, ast::CV::Const ) ),
    380                                 nullptr,
    381                                 ast::Storage::Classes(),
    382                                 ast::Linkage::Cforall
     342                                        new ast::BasicType( ast::BasicType::Char, ast::CV::Const ) )
    383343                        ),
    384344                },
     
    432392                tableName,
    433393                createVTableInstType( exceptionName, params ),
    434                 new ast::ListInit( location, std::move( inits ), std::move( dsigs ) ),
    435                 ast::Storage::Classes(),
    436                 ast::Linkage::Cforall
     394                new ast::ListInit( location, std::move( inits ), std::move( dsigs ) )
    437395        );
    438396}
  • src/ControlStruct/ExceptTranslateNew.cpp

    r4c48be0 rdd33c1f  
    190190                location,
    191191                "__handler_index",
    192                 new ast::BasicType(ast::BasicType::SignedInt),
    193                 nullptr, //init
    194                 ast::Storage::Classes{},
    195                 ast::Linkage::Cforall
     192                new ast::BasicType( ast::BasicType::SignedInt )
    196193                );
    197194}
     
    203200                location,
    204201                "__exception_inst",
    205                 new ast::PointerType(
    206                         new ast::StructInstType( except_decl )
    207                         ),
    208                 nullptr, //init
    209                 ast::Storage::Classes{},
    210                 ast::Linkage::Cforall
     202                new ast::PointerType( new ast::StructInstType( except_decl ) )
    211203                );
    212204}
  • src/GenPoly/Specialize.h

    r4c48be0 rdd33c1f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Specialize.h --
     7// Specialize.h -- Generate thunks to specialize polymorphic functions.
    88//
    99// Author           : Richard C. Bilson
     
    1717
    1818#include <list>  // for list
    19 #include "AST/TranslationUnit.hpp"
    2019
    2120class Declaration;
     21namespace ast {
     22        class TranslationUnit;
     23}
    2224
    2325namespace GenPoly {
  • src/GenPoly/SpecializeNew.cpp

    r4c48be0 rdd33c1f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // SpecializeNew.cpp --
     7// SpecializeNew.cpp -- Generate thunks to specialize polymorphic functions.
    88//
    99// Author           : Andrew Beach
     
    201201                        *formal, *actual, getInferredParams( expr ) );
    202202        }
    203         //for ( auto pair : group_iterate( formal->params, mut->args ) ) {
    204         //      const ast::ptr<ast::Type> & formal = std::get<0>( pair );
    205         //      ast::ptr<ast::Expr> & actual = std::get<1>( pair );
    206         //      *actual = doSpecialization( (*actual)->location, *formal, *actual, getInferredParams( expr ) );
    207         //}
    208203        return mut;
    209204}
     
    227222}
    228223
    229 // Restructures the arguments to match the structure of the formal parameters
    230 // of the actual function. [begin, end) are the exploded arguments.
    231 template<typename Iterator, typename OutIterator>
    232 void structureArg( const CodeLocation & location, const ast::Type * type,
    233                 Iterator & begin, Iterator end, OutIterator out ) {
    234         if ( auto tuple = dynamic_cast<const ast::TupleType *>( type ) ) {
    235                 std::vector<ast::ptr<ast::Expr>> exprs;
    236                 for ( const ast::Type * t : *tuple ) {
    237                         structureArg( location, t, begin, end, std::back_inserter( exprs ) );
    238                 }
    239                 *out++ = new ast::TupleExpr( location, std::move( exprs ) );
    240         } else {
    241                 assertf( begin != end, "reached the end of the arguments while structuring" );
    242                 *out++ = *begin++;
    243         }
    244 }
    245 
    246 #if 0
     224// Restructures arguments to match the structure of the formal parameters
     225// of the actual function. Returns the next structured argument.
    247226template<typename Iterator>
    248227const ast::Expr * structureArg(
    249228                const CodeLocation& location, const ast::ptr<ast::Type> & type,
    250229                Iterator & begin, const Iterator & end ) {
    251         if ( auto tuple = type->as<ast::TupleType>() ) {
     230        if ( auto tuple = type.as<ast::TupleType>() ) {
    252231                std::vector<ast::ptr<ast::Expr>> exprs;
    253232                for ( const ast::Type * t : *tuple ) {
     
    260239        }
    261240}
    262 #endif
    263241
    264242namespace {
     
    291269                // Must replace only occurrences of type variables
    292270                // that occure free in the thunk's type.
    293                 //ast::TypeSubstitution::ApplyResult<ast::FunctionType>
    294                 //      typeSubs->applyFree( newType );
    295271                auto result = typeSubs->applyFree( newType );
    296272                newType = result.node.release();
     
    300276        using DeclVector = std::vector<ast::ptr<ast::TypeDecl>>;
    301277
    302         //const std::string & thunkName = thunkNamer.newName();
    303         //UniqueName paramNamer(thunkName + "Param");
    304278        UniqueName paramNamer( paramPrefix );
    305279
    306         //auto toParamDecl = [&location, &paramNamer]( const ast::Type * type ) {
    307         //      return new ast::ObjectDecl(
    308         //              location, paramNamer.newName(), ast::deepCopy( type ) );
    309         //};
    310 
    311280        // Create new thunk with same signature as formal type.
    312 
    313         // std::map<const ast::TypeDecl *, std::pair<int, int>> typeMap;
    314281        ast::Pass<TypeInstFixer> fixer;
    315282        for (const auto & kv : newType->forall) {
    316283                if (fixer.core.typeMap.count(kv->base)) {
    317                         std::cerr << location << ' ' << kv->base->name << ' ' << kv->expr_id << '_' << kv->formal_usage << ','
    318                         << fixer.core.typeMap[kv->base].first << '_' << fixer.core.typeMap[kv->base].second << std::endl;
     284                        std::cerr << location << ' ' << kv->base->name
     285                                << ' ' << kv->expr_id << '_' << kv->formal_usage
     286                                << ',' << fixer.core.typeMap[kv->base].first
     287                                << '_' << fixer.core.typeMap[kv->base].second << std::endl;
    319288                        assertf(false, "multiple formals in specialize");
    320289                }
     
    322291                        fixer.core.typeMap[kv->base] = std::make_pair(kv->expr_id, kv->formal_usage);
    323292                }
    324         } 
     293        }
    325294
    326295        ast::CompoundStmt * thunkBody = new ast::CompoundStmt( location );
     
    345314                );
    346315
    347         // thunkFunc->accept(fixer);
    348316        thunkFunc->fixUniqueId();
    349 
    350 
    351317
    352318        // Thunks may be generated and not used, avoid them.
     
    375341                // Name each thunk parameter and explode it.
    376342                // These are then threaded back into the actual function call.
    377                 //param->name = paramNamer.newName();
    378343                ast::DeclWithType * mutParam = ast::mutate( param.get() );
    379                 // - Should be renamed earlier. -
    380                 //mutParam->name = paramNamer.newName();
    381344                explodeSimple( location, new ast::VariableExpr( location, mutParam ),
    382345                        std::back_inserter( args ) );
     
    388351                argBegin = args.begin(), argEnd = args.end();
    389352        for ( const auto & actualArg : actualType->params ) {
    390                 structureArg( location, actualArg.get(), argBegin, argEnd,
    391                         std::back_inserter( app->args ) );
     353                app->args.push_back(
     354                        structureArg( location, actualArg.get(), argBegin, argEnd ) );
    392355        }
    393356        assertf( argBegin == argEnd, "Did not structure all arguments." );
     
    469432        // Create thunks for the inferred parameters.
    470433        // This is not needed for intrinsic calls, because they aren't
    471         // actually passed
    472         //
    473         // need to handle explicit params before inferred params so that
    474         // explicit params do not recieve a changed set of inferParams (and
    475         // change them again) alternatively, if order starts to matter then
    476         // copy appExpr's inferParams and pass them to handleExplicitParams.
     434        // actually passed to the function. It needs to handle explicit params
     435        // before inferred params so that explicit params do not recieve a
     436        // changed set of inferParams (and change them again).
     437        // Alternatively, if order starts to matter then copy expr's inferParams
     438        // and pass them to handleExplicitParams.
    477439        ast::ApplicationExpr * mut = handleExplicitParams( expr );
    478440        if ( !mut->inferred.hasParams() ) {
  • src/InitTweak/FixInitNew.cpp

    r4c48be0 rdd33c1f  
    595595                if ( arg && isIntrinsicCallExpr( dtor ) ) {
    596596                        return new ast::CommaExpr(loc, arg, new ast::VariableExpr(loc, ret ) );
    597                         // return;
    598597                }
    599598
     
    654653                if ( ! result->isVoid() ) {
    655654                        static UniqueName retNamer("_tmp_cp_ret");
    656                         // result = result->clone();
    657655                        auto subResult = env->apply( result ).node;
    658656                        auto ret = new ast::ObjectDecl(loc, retNamer.newName(), subResult, nullptr );
     
    833831                        }
    834832
    835                         // stmtsToAddBefore.splice( stmtsToAddBefore.end(), fixer.pass.stmtsToAddBefore );
    836                         // stmtsToAddAfter.splice( stmtsToAddAfter.end(), fixer.pass.stmtsToAddAfter );
    837833                        unqMap[mutExpr->id] = mutExpr;
    838834                } else {
     
    13491345                auto tmp = new ast::ObjectDecl(loc, tempNamer.newName(), callExpr->args.front()->result );
    13501346                declsToAddBefore.push_back( tmp );
    1351                 // delete ctorExpr;
    13521347
    13531348                // build assignment and replace constructor's first argument with new temporary
  • src/ResolvExpr/Resolver.cc

    r4c48be0 rdd33c1f  
    15421542        }
    15431543
    1544 
    15451544        const ast::StaticAssertDecl * Resolver_new::previsit(
    15461545                const ast::StaticAssertDecl * assertDecl
     
    15541553        const PtrType * handlePtrType( const PtrType * type, const ResolveContext & context ) {
    15551554                if ( type->dimension ) {
    1556                         ast::ptr< ast::Type > sizeType = context.global.sizeType;
     1555                        const ast::Type * sizeType = context.global.sizeType.get();
    15571556                        ast::ptr< ast::Expr > dimension = findSingleExpression( type->dimension, sizeType, context );
    15581557                        assertf(dimension->env->empty(), "array dimension expr has nonempty env");
    15591558                        dimension.get_and_mutate()->env = nullptr;
    1560                         ast::mutate_field(
    1561                                 type, &PtrType::dimension,
    1562                                 dimension);
     1559                        ast::mutate_field( type, &PtrType::dimension, dimension );
    15631560                }
    15641561                return type;
  • src/SymTab/Autogen.cc

    r4c48be0 rdd33c1f  
    258258        }
    259259
    260         ///
     260        /// Given type T, generate type of default ctor/dtor, i.e. function type void (*) (T &).
    261261        ast::FunctionDecl * genDefaultFunc(const CodeLocation loc, const std::string fname, const ast::Type * paramType, bool maybePolymorphic) {
    262262                std::vector<ast::ptr<ast::TypeDecl>> typeParams;
    263263                if (maybePolymorphic) typeParams = getGenericParams(paramType);
    264264                auto dstParam = new ast::ObjectDecl(loc, "_dst", new ast::ReferenceType(paramType), nullptr, {}, ast::Linkage::Cforall);
    265                 return new ast::FunctionDecl(loc, fname, std::move(typeParams), {dstParam}, {}, new ast::CompoundStmt(loc));
     265                return new ast::FunctionDecl(loc, fname, std::move(typeParams), {dstParam}, {}, new ast::CompoundStmt(loc), {}, ast::Linkage::Cforall);
    266266        }
    267267
  • src/Validate/Autogen.cpp

    r4c48be0 rdd33c1f  
    370370ast::ObjectDecl * FuncGenerator::dstParam() const {
    371371        return new ast::ObjectDecl( getLocation(), "_dst",
    372                 new ast::ReferenceType( ast::deepCopy( type ) ),
    373                 nullptr, {}, ast::Linkage::Cforall );
     372                new ast::ReferenceType( ast::deepCopy( type ) ) );
    374373}
    375374
    376375ast::ObjectDecl * FuncGenerator::srcParam() const {
    377376        return new ast::ObjectDecl( getLocation(), "_src",
    378                 ast::deepCopy( type ),
    379                 nullptr, {}, ast::Linkage::Cforall );
     377                ast::deepCopy( type ) );
    380378}
    381379
     
    429427                ast::ObjectDecl * param = new ast::ObjectDecl(
    430428                        getLocation(), member->name, paramType );
    431                 param->linkage = ast::Linkage::Cforall;
    432429                for ( auto & attr : member->attributes ) {
    433430                        if ( attr->isValidOnFuncParam() ) {
  • src/main.cc

    r4c48be0 rdd33c1f  
    439439                        PASS( "Translate Tries", ControlStruct::translateTries( transUnit ) );
    440440                        PASS( "Gen Waitfor", Concurrency::generateWaitFor( transUnit ) );
    441                         PASS( "Convert Specializations",  GenPoly::convertSpecializations( transUnit ) ); // needs to happen before tuple types are expanded
    442 
     441
     442                        // Needs to happen before tuple types are expanded.
     443                        PASS( "Convert Specializations",  GenPoly::convertSpecializations( transUnit ) );
    443444
    444445                        translationUnit = convert( move( transUnit ) );
     
    516517                        PASS( "Gen Waitfor", Concurrency::generateWaitFor( translationUnit ) );
    517518                        PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
    518 
    519519                }
    520 
    521 
    522                 // PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
    523520
    524521                PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
Note: See TracChangeset for help on using the changeset viewer.