Changeset 6949c45 for src


Ignore:
Timestamp:
Jun 10, 2019, 1:51:24 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2773ab8, 558d13b
Parents:
891b827 (diff), f9a7cf0 (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:
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r891b827 r6949c45  
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu May 06 19:51:00 2019
    13 // Update Count     : 10
     12// Last Modified On : Man Jun 10 11:51:00 2019
     13// Update Count     : 11
    1414//
    1515
     
    9292
    9393        Label makeLabel(Statement * labelled, const ast::Label& label) {
     94                // This probably will leak memory, but only until we get rid of the old tree.
     95                if ( nullptr == labelled && label.location.isSet() ) {
     96                        labelled = new NullStmt();
     97                        labelled->location = label.location;
     98                }
    9499                return Label(
    95100                        label.name,
     
    154159                auto&& attr = get<Attribute>().acceptL( node->attributes );
    155160                if ( inCache( node ) ) {
    156                         if(node->name == "tmp") {
    157                                 std::cerr << (void*)node << "(new) in cache " << (void*)this->node << "(old)" << std::endl;
    158                         }
    159161                        return nullptr;
    160162                }
     
    169171                        Type::FuncSpecifiers( node->funcSpec.val )
    170172                );
    171                 if(node->name == "tmp") {
    172                         std::cerr << (void*)node << "(new) created " << (void*)decl << "(old)" << std::endl;
    173                 }
    174173                return declWithTypePostamble( decl, node );
    175174        }
     
    13901389        // Local Utilities:
    13911390
    1392         #define construct(T, key, ...) ({ \
    1393                 void * data = ::operator new(sizeof(T)); \
    1394                 cache.emplace( key, (T*)data ); \
    1395                 new (data) T( __VA_ARGS__ ); \
    1396         })
    1397 
    13981391        template<typename NewT, typename OldT>
    13991392        NewT * getAccept1( OldT old ) {
     
    14091402
    14101403        template<typename NewT, typename OldC>
    1411         std::vector< ast::ptr<NewT> > getAcceptV( OldC& old ) {
     1404        std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) {
    14121405                std::vector< ast::ptr<NewT> > ret;
    14131406                ret.reserve( old.size() );
     
    14221415#       define GET_ACCEPT_V(child, type) \
    14231416                getAcceptV< ast::type, decltype( old->child ) >( old->child )
    1424        
     1417
    14251418        template<typename NewT, typename OldC>
    1426         std::deque< ast::ptr<NewT> > getAcceptD( OldC& old ) {
     1419        std::deque< ast::ptr<NewT> > getAcceptD( const OldC& old ) {
    14271420                std::deque< ast::ptr<NewT> > ret;
    14281421                for ( auto a : old ) {
     
    14371430                getAcceptD< ast::type, decltype( old->child ) >( old->child )
    14381431
    1439         ast::Label make_label(Label* old) {
     1432        ast::Label make_label(const Label* old) {
     1433                CodeLocation const & location =
     1434                    ( old->labelled ) ? old->labelled->location : CodeLocation();
    14401435                return ast::Label(
    1441                         old->labelled->location,
     1436                        location,
    14421437                        old->name,
    14431438                        GET_ACCEPT_V(attributes, Attribute)
     
    14701465
    14711466        virtual void visit( ObjectDecl * old ) override final {
    1472                 if( old->name == "tmp" ) {
    1473                         std::cerr << "building parameters for" << (void*)old << std::endl;
    1474                 }
    14751467                auto&& type = GET_ACCEPT_1(type, Type);
    14761468                auto&& init = GET_ACCEPT_1(init, Init);
    14771469                auto&& bfwd = GET_ACCEPT_1(bitfieldWidth, Expr);
    14781470                auto&& attr = GET_ACCEPT_V(attributes, Attribute);
    1479                 if( old->name == "tmp" ) {
    1480                         std::cerr << "checking cache for " << (void*)old << std::endl;
    1481                 }
    14821471                if ( inCache( old ) ) {
    1483                         if( old->name == "tmp" ) {
    1484                                 std::cerr << (void*)old << "(old) in cache " << (void*)this->node << "(new)" << std::endl;
    1485                         }
    14861472                        return;
    14871473                }
     
    14981484                );
    14991485                cache.emplace(old, decl);
    1500                 if( old->name == "tmp" ) {
    1501                         std::cerr << (void*)old << "(old) added to cache with " << (void*)decl << "(new)" << std::endl;
    1502                 }
    15031486                assert(cache.find( old ) != cache.end());
    15041487                decl->scopeLevel = old->scopeLevel;
     
    15091492
    15101493                this->node = decl;
    1511 
    1512                 if( old->name == "tmp" ) {
    1513                         std::cerr << (void*)old << "(old) created " << (void*)this->node << "(new)" << std::endl;
    1514                 }
    15151494        }
    15161495
     
    18271806                        }
    18281807
    1829                         Label label = old->originalTarget;
    18301808                        auto stmt = new ast::BranchStmt(
    18311809                                old->location,
    18321810                                kind,
    1833                                 make_label(&label),
     1811                                make_label(&old->originalTarget),
    18341812                                GET_LABELS_V(old->labels)
    18351813                        );
  • src/AST/Node.hpp

    r891b827 r6949c45  
    9999
    100100/// Mutate a node field (only clones if not equal to existing value)
    101 template<typename node_t, typename field_t>
    102 const node_t * mutate_field(
    103         const node_t * node,
    104         typename std::remove_const<typename std::remove_reference<field_t>::type>::type node_t::* field,
    105         field_t&& val
    106 ) {
     101template<typename node_t, typename field_t, typename assn_t>
     102const node_t * mutate_field( const node_t * node, field_t node_t::* field, assn_t && val ) {
     103        // skip mutate if equivalent
    107104        if ( node->*field == val ) return node;
    108105       
     106        // mutate and return
    109107        node_t * ret = mutate( node );
    110         ret->*field = std::forward< field_t >( val );
     108        ret->*field = std::forward< assn_t >( val );
     109        return ret;
     110}
     111
     112/// Mutate a single index of a node field (only clones if not equal to existing value)
     113template<typename node_t, typename coll_t, typename ind_t, typename field_t>
     114const node_t * mutate_field_index(
     115        const node_t * node, coll_t node_t::* field, ind_t i, field_t && val
     116) {
     117        // skip mutate if equivalent
     118        if  ( (node->*field)[i] == val ) return node;
     119
     120        // mutate and return
     121        node_t * ret = mutate( node );
     122        (ret->*field)[i] = std::forward< field_t >( val );
    111123        return ret;
    112124}
  • src/AST/Pass.hpp

    r891b827 r6949c45  
    262262/// Used to restore values/functions/etc. when the Pass finishes visiting this node
    263263class WithGuards {
    264         __pass::at_cleanup_t at_cleanup;
    265 
     264        __pass::at_cleanup_t at_cleanup = [](__pass::cleanup_func_t, void*) {
     265                std::cerr << "No cleanup function was set" << std::endl;
     266                abort();
     267        };
     268
     269        template< typename pass_t>
     270        friend auto __pass::at_cleanup( pass_t & pass, int ) -> decltype( &pass.at_cleanup );
    266271public:
     272
    267273        /// When this node is finished being visited, restore the value of a variable
    268274        template< typename T >
  • src/InitTweak/InitTweak.cc

    r891b827 r6949c45  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// InitTweak.cc --
     8//
     9// Author           : Rob Schluntz
     10// Created On       : Fri May 13 11:26:36 2016
     11// Last Modified By : Aaron B. Moss
     12// Last Modified On : Mon Jun 10 13:30:00 2019
     13// Update Count     : 5
     14//
     15
    116#include <algorithm>               // for find, all_of
    217#include <cassert>                 // for assertf, assert, strict_dynamic_cast
     
    419#include <iterator>                // for back_insert_iterator, back_inserter
    520#include <memory>                  // for __shared_ptr
     21#include <vector>
    622
    723#include "AST/Expr.hpp"
     
    307323        }
    308324
    309         struct CallFinder {
    310                 CallFinder( const std::list< std::string > & names ) : names( names ) {}
     325        struct CallFinder_old {
     326                CallFinder_old( const std::list< std::string > & names ) : names( names ) {}
    311327
    312328                void postvisit( ApplicationExpr * appExpr ) {
     
    331347        };
    332348
     349        struct CallFinder_new final {
     350                std::vector< ast::ptr< ast::Expr > > matches;
     351                const std::vector< std::string > names;
     352
     353                CallFinder_new( std::vector< std::string > && ns ) : matches(), names( std::move(ns) ) {}
     354
     355                void handleCallExpr( const ast::Expr * expr ) {
     356                        std::string fname = getFunctionName( expr );
     357                        if ( std::find( names.begin(), names.end(), fname ) != names.end() ) {
     358                                matches.emplace_back( expr );
     359                        }
     360                }
     361
     362                void postvisit( const ast::ApplicationExpr * expr ) { handleCallExpr( expr ); }
     363                void postvisit( const ast::UntypedExpr *     expr ) { handleCallExpr( expr ); }
     364        };
     365
    333366        void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ) {
    334                 static PassVisitor<CallFinder> finder( std::list< std::string >{ "?{}", "^?{}" } );
     367                static PassVisitor<CallFinder_old> finder( std::list< std::string >{ "?{}", "^?{}" } );
    335368                finder.pass.matches = &matches;
    336369                maybeAccept( stmt, finder );
     370        }
     371
     372        std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt ) {
     373                ast::Pass< CallFinder_new > finder{ std::vector< std::string >{ "?{}", "^?{}" } };
     374                maybe_accept( stmt, finder );
     375                return std::move( finder.pass.matches );
    337376        }
    338377
     
    436475        }
    437476
     477        const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr ) {
     478                auto appExpr = dynamic_cast< const ast::ApplicationExpr * >( expr );
     479                if ( ! appExpr ) return nullptr;
     480
     481                const ast::DeclWithType * func = getCalledFunction( appExpr->func );
     482                assertf( func,
     483                        "getCalledFunction returned nullptr: %s", toString( appExpr->func ).c_str() );
     484               
     485                // check for Intrinsic only -- don't want to remove all overridable ctor/dtor because
     486                // autogenerated ctor/dtor will call all member dtors, and some members may have a
     487                // user-defined dtor
     488                return func->linkage == ast::Linkage::Intrinsic ? appExpr : nullptr;
     489        }
     490
    438491        namespace {
    439492                template <typename Predicate>
     
    444497                        return std::all_of( callExprs.begin(), callExprs.end(), pred);
    445498                }
     499
     500                template <typename Predicate>
     501                bool allofCtorDtor( const ast::Stmt * stmt, const Predicate & pred ) {
     502                        std::vector< ast::ptr< ast::Expr > > callExprs = collectCtorDtorCalls( stmt );
     503                        return std::all_of( callExprs.begin(), callExprs.end(), pred );
     504                }
    446505        }
    447506
     
    452511                                assert( funcType );
    453512                                return funcType->get_parameters().size() == 1;
     513                        }
     514                        return false;
     515                });
     516        }
     517
     518        bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt ) {
     519                return allofCtorDtor( stmt, []( const ast::Expr * callExpr ){
     520                        if ( const ast::ApplicationExpr * appExpr = isIntrinsicCallExpr( callExpr ) ) {
     521                                const ast::FunctionType * funcType =
     522                                        GenPoly::getFunctionType( appExpr->func->result );
     523                                assert( funcType );
     524                                return funcType->params.size() == 1;
    454525                        }
    455526                        return false;
  • src/InitTweak/InitTweak.h

    r891b827 r6949c45  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // RemoveInit.h --
     7// InitTweak.h --
    88//
    99// Author           : Rob Schluntz
    1010// Created On       : Fri May 13 11:26:36 2016
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:30:33 2017
    13 // Update Count     : 4
     11// Last Modified By : Aaron B. Moss
     12// Last Modified On : Mon Jun 10 13:30:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    1919#include <memory>             // for shared_ptr
    2020#include <string>             // for string, allocator
     21#include <vector>
    2122
    2223#include "AST/Fwd.hpp"        // for AST nodes
     
    6364        /// Non-Null if expr is a call expression whose target function is intrinsic
    6465        ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
     66        const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr);
    6567
    6668        /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
     
    6870        /// Currently has assertions that make it less than fully general.
    6971        bool isIntrinsicSingleArgCallStmt( Statement * stmt );
     72        bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt );
    7073
    7174        /// True if stmt is a call statement where the function called is intrinsic.
     
    7477        /// get all Ctor/Dtor call expressions from a Statement
    7578        void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches );
     79        std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt );
    7680
    7781        /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
  • src/ResolvExpr/CurrentObject.cc

    r891b827 r6949c45  
    946946        }
    947947
    948         void CurrentObject::setNext( const ast::Designation * designation ) {
     948        const Designation * CurrentObject::findNext( const Designation * designation ) {
     949                using DesignatorChain = std::deque< ptr< Expr > >;
     950                PRINT( std::cerr << "___findNext" << std::endl; )
     951               
     952                // find all the d's
     953                std::vector< DesignatorChain > desigAlts{ {} }, newDesigAlts;
     954                std::deque< const Type * > curTypes{ objStack.back()->getType() }, newTypes;
     955                for ( const Expr * expr : designation->designators ) {
     956                        PRINT( std::cerr << "____untyped: " << expr << std::endl; )
     957                        auto dit = desigAlts.begin();
     958                        if ( auto nexpr = dynamic_cast< const NameExpr * >( expr ) ) {
     959                                for ( const Type * t : curTypes ) {
     960                                        assert( dit != desigAlts.end() );
     961
     962                                        DesignatorChain & d = *dit;
     963                                        PRINT( std::cerr << "____actual: " << t << std::endl; )
     964                                        if ( auto refType = dynamic_cast< const ReferenceToType * >( t ) ) {
     965                                                // concatenate identical field names
     966                                                for ( const Decl * mem : refType->lookup( nexpr->name ) ) {
     967                                                        if ( auto field = dynamic_cast< const ObjectDecl * >( mem ) ) {
     968                                                                PRINT( std::cerr << "____alt: " << field->type << std::endl; )
     969                                                                DesignatorChain d2 = d;
     970                                                                d2.emplace_back( new VariableExpr{ expr->location, field } );
     971                                                                newDesigAlts.emplace_back( std::move( d2 ) );
     972                                                                newTypes.emplace_back( field->type );
     973                                                        }
     974                                                }
     975                                        }
     976
     977                                        ++dit;
     978                                }
     979                        } else {
     980                                for ( const Type * t : curTypes ) {
     981                                        assert( dit != desigAlts.end() );
     982
     983                                        DesignatorChain & d = *dit;
     984                                        if ( auto at = dynamic_cast< const ArrayType * >( t ) ) {
     985                                                PRINT( std::cerr << "____alt: " << at->get_base() << std::endl; )
     986                                                d.emplace_back( expr );
     987                                                newDesigAlts.emplace_back( d );
     988                                                newTypes.emplace_back( at->base );
     989                                        }
     990                                }
     991                        }
     992
     993                        // reset queue
     994                        desigAlts = std::move( newDesigAlts );
     995                        newDesigAlts.clear();
     996                        curTypes = std::move( newTypes );
     997                        newTypes.clear();
     998                        assertf( desigAlts.size() == curTypes.size(), "Designator alternatives (%zu) and current types (%zu) out of sync", desigAlts.size(), curTypes.size() );
     999                }
     1000
     1001                if ( desigAlts.size() > 1 ) {
     1002                        SemanticError( designation, toString("Too many alternatives (", desigAlts.size(), ") for designation: ") );
     1003                } else if ( desigAlts.empty() ) {
     1004                        SemanticError( designation, "No reasonable alternatives for designation: " );
     1005                }
     1006
     1007                DesignatorChain & d = desigAlts.back();
     1008                PRINT( for ( Expression * expr : d ) {
     1009                        std::cerr << "____desig: " << expr << std::endl;
     1010                } ) // for
     1011                assertf( ! curTypes.empty(), "empty designator chosen");
     1012
     1013                // set new designators
     1014                assertf( ! objStack.empty(), "empty object stack when setting designation" );
     1015                Designation * actualDesignation =
     1016                        new Designation{ designation->location, DesignatorChain{d} };
     1017                objStack.back()->setPosition( d ); // destroys d
     1018                return actualDesignation;
     1019        }
     1020
     1021        void CurrentObject::setNext( const Designation * designation ) {
    9491022                PRINT( std::cerr << "____setNext" << designation << std::endl; )
    9501023                assertf( ! objStack.empty(), "obj stack empty in setNext" );
  • src/ResolvExpr/CurrentObject.h

    r891b827 r6949c45  
    111111                CurrentObject( const CodeLocation & loc, const Type * type );
    112112
     113                /// resolves unresolved designation
     114                const Designation * findNext( const Designation * designation );
    113115                /// sets current position using the resolved designation
    114116                void setNext( const ast::Designation * designation );
  • src/ResolvExpr/Resolver.cc

    r891b827 r6949c45  
    12271227                void previsit( const ast::WaitForStmt * );
    12281228
    1229                 const ast::SingleInit * previsit( const ast::SingleInit * );
    1230                 const ast::ListInit * previsit( const ast::ListInit * );
    1231                 void previsit( const ast::ConstructorInit * );
     1229                const ast::SingleInit *      previsit( const ast::SingleInit * );
     1230                const ast::ListInit *        previsit( const ast::ListInit * );
     1231                const ast::ConstructorInit * previsit( const ast::ConstructorInit * );
    12321232        };
    12331233
     
    15101510                        // iterate designations and initializers in pairs, moving the cursor to the current
    15111511                        // designated object and resolving the initializer against that object
    1512                         #warning unimplemented; Resolver port in progress
    1513                         assert(false);
    1514                 }
     1512                        listInit = ast::mutate_field_index(
     1513                                listInit, &ast::ListInit::designations, i,
     1514                                currentObject.findNext( listInit->designations[i] ) );
     1515                        listInit = ast::mutate_field_index(
     1516                                listInit, &ast::ListInit::initializers, i,
     1517                                listInit->initializers[i]->accept( *visitor ) );
     1518                }
     1519
     1520                // move cursor out of brace-enclosed initializer-list
     1521                currentObject.exitListInit();
    15151522
    15161523                visit_children = false;
     
    15181525        }
    15191526
    1520         void Resolver_new::previsit( const ast::ConstructorInit * ctorInit ) {
    1521                 #warning unimplemented; Resolver port in progress
    1522                 (void)ctorInit;
    1523                 assert(false);
     1527        const ast::ConstructorInit * Resolver_new::previsit( const ast::ConstructorInit * ctorInit ) {
     1528                visitor->maybe_accept( ctorInit, &ast::ConstructorInit::ctor );
     1529                visitor->maybe_accept( ctorInit, &ast::ConstructorInit::dtor );
     1530
     1531                // found a constructor - can get rid of C-style initializer
     1532                // xxx - Rob suggests this field is dead code
     1533                ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::init, nullptr );
     1534
     1535                // intrinsic single-parameter constructors and destructors do nothing. Since this was
     1536                // implicitly generated, there's no way for it to have side effects, so get rid of it to
     1537                // clean up generated code
     1538                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) {
     1539                        ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::ctor, nullptr );
     1540                }
     1541                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) {
     1542                        ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::dtor, nullptr );
     1543                }
     1544
     1545                return ctorInit;
    15241546        }
    15251547
Note: See TracChangeset for help on using the changeset viewer.