Changeset 16c95e3


Ignore:
Timestamp:
Jun 27, 2017, 10:35:11 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
fa4805f
Parents:
fda8168 (diff), 6385d62 (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 plg2:software/cfa/cfa-cc

Files:
8 added
26 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    rfda8168 r16c95e3  
    3131
    3232src/prelude/builtins.cf
    33 src/prelude/builtins.c
     33src/prelude/gcc-builtins.cf
     34src/prelude/gcc-builtins.c
    3435src/prelude/extras.cf
    3536src/prelude/bootloader.c
  • doc/proposals/tagged-struct.txt

    rfda8168 r16c95e3  
    1414say which of the possible values is currently stored in the union. The idea
    1515here is similar, however the possibilities are more open ended.
     16
     17Alternate names include virtual structure and abstract structure.
    1618
    1719
     
    3638their parent's fields to their field list so they can be upcast.
    3739
     40The type field may be public, if it is then it can be accessed through a
     41simple field access "instance.type". The type field would then be able to be
     42used to access the type object, which contains the information for the type.
     43It may just be a pointer to the type object "*instance.type", although a
     44lookup function could also be used.
     45
     46
     47Usage:
     48
     49The central feature for tagged structs is a checked cast between pointer types
     50to the structures. A cast is successful if the true type of the pointed object
     51is of the type being cast to or any of its children, otherwise the cast
     52returns null.
     53
     54The type field should also allow for equality comparison of types.
     55
     56Currently, with only these operations (and similar features) the type field
     57could be hidden and the operations given through helper functions. However
     58if the type object has more complex (or even open ended) information in it
     59than providing direct access becomes very valuable.
     60
    3861
    3962Implemenation:
    4063
    41 Adding to the field list is a simple matter, should be doable during
    42 translation. The type field is just a pointer to a type object. With proper
    43 linking we can create a single unique instance of the type object for each
    44 declared tagged struct. The instance's address is used as an id for the type.
    45 It also holds data about the type, such as its parent's id/a pointer to the
    46 parent type object.
     64Adding to the field list would have to be handled during translation. The
     65simple act of adding declarations should not be difficult, althought it might
     66take a bit of work to find the parent's declarations.
    4767
    48 The type field could be hidden (as best as C can hide it) or it could be
    49 visible to the user with easy access to allow the user to examine the type
    50 object directly.
    51 
    52 Direct access is more useful if the data on the type-objects can change, other
    53 wise the build in function could handle all cases. Perhaps each root object
    54 can specify a type object to use or the type objects are themselves tagged,
    55 although there may not be a base case with the latter.
    56 
    57 In the simplest case the type object is a pointer to the parent type object.
    58 Additional data could be added, such as a name, or a function pointer to the
    59 destructor.
     68Type objects are also simple in to generate, they should just be global
     69(program lifetime) structures. Getting there to be exactly one instance of
     70each allows the pointer to the structure to be used as the type id, and that
     71should be possible to do during linking.
    6072
    6173
     
    94106If unions are declared tagged instead of creating a new tagged type, all
    95107possible values of the union must be of that tagged type or a child type.
     108
     109
     110Custom Type Objects (Extention):
     111
     112Some method to define type objects used within a tree of types. One option is
     113to allow the tree's type object to be specified by the tree root. It would
     114then have to be filled in for each type in the tree, including the root.
     115
     116The only required field is the parent field, a pointer to the type object's
     117type. (This is also the only required field on the tagged structure itself.)
     118
     119A further extention could allow expanding type objects, so child types could
     120append fields to their parent's feild list. They might need their own type
     121objects at that point, or maybe static checks will be enough to see the
     122minimum field list.
  • doc/working/exception/translate.c

    rfda8168 r16c95e3  
    11/* Translation rules for exception handling code, from Cforall to C.
    22 *
    3  * Note that these are not final. Names, syntax and the exact translation
    4  * will be updated. The first section is the shared definitions, not generated
    5  * by the local translations but used by the translated code.
     3 * Reminder: This is not final. Besides names and things it is also going very
     4 * much for correctness and simplisity over efficiency.
     5 *
     6 * The first section is the shared definitions, not generated by the local
     7 * translations but used by the translated code.
    68 *
    79 * Most of these exist only after translation (in C code). The first (the
     
    1618typedef int exception;
    1719
     20// Will have to be availibe to user. Consider new name. Requires tagged types.
     21forall(dtype parent | tagged(parent), dtype child | tagged(child))
     22parent *dynamic_cast(child *);
     23
    1824void __throw_terminate(exception except) __attribute__((noreturn));
    1925void __rethrow_terminate() __attribute__((noreturn));
     
    116122                }
    117123                int match1(exception except) {
    118                         OtherException inner_except;
    119                         if (dynamic_cast__SomeException(except)) {
    120                                 return 1;
    121                         }
    122                         else if ( (inner_except = dynamic_cast__OtherException(except)) &&
    123                                         inner_except.priority > 3) {
    124                                 return 2;
    125                         }
    126                         else return 0;
     124                        {
     125                                if (dynamic_cast__SomeException(except)) {
     126                                        return 1;
     127                                }
     128                        }
     129                        {
     130                                OtherException err;
     131                                if ( (err = dynamic_cast__OtherException(except)) &&
     132                                                err.priority > 3) {
     133                                        return 2;
     134                                }
     135                        }
     136                        return 0;
    127137                }
    128138                __try_terminate(try1, catch1, match1);
     
    151161        {
    152162                bool handle1(exception except) {
    153                         OtherException inner_except;
    154                         if (dynamic_cast__SomeException(except)) {
    155                                 fiddleThing();
    156                                 return true;
    157                         } else if (dynamic_cast__OtherException(except) &&
    158                                         inner_except.priority > 3) {
    159                                 twiddleWidget();
    160                                 return true;
    161                         } else {
    162                                 return false;
    163                         }
     163                        {
     164                                if (dynamic_cast__SomeException(except)) {
     165                                        fiddleThing();
     166                                        return true;
     167                                }
     168                        }
     169                        {
     170                                OtherException err;
     171                                if ( ( err = dynamic_cast__OtherException(except) ) &&
     172                                                err.priority > 3) {
     173                                        twiddleWidget();
     174                                        return true;
     175                                }
     176                        }
     177                        return false;
    164178                }
    165179                struct __try_resume_node data =
     
    230244                }
    231245                bool handle1(exception except) {
    232                         if (dynamic_cast__SomeException(except)) {
    233                                 fiddleThing();
    234                                 return true;
    235                         } else {
    236                                 return false;
    237                         }
     246                        {
     247                                if (dynamic_cast__SomeException(except)) {
     248                                        fiddleThing();
     249                                        return true;
     250                                }
     251                        }
     252                        return false;
    238253                }
    239254                struct __cleanup_hook generated_name
     
    273288        {
    274289                bool handle1() {
    275                         if (dynamic_cast__OtherException(except)) {
    276                                 twiddleWidget();
    277                                 return true;
     290                        {
     291                                if (dynamic_cast__OtherException(except)) {
     292                                        twiddleWidget();
     293                                        return true;
     294                                }
    278295                        }
    279296                        return false;
     
    297314                }
    298315                int match1(exception except) {
    299                         if (dynamic_cast__SomeException(except)) {
    300                                 return 1;
     316                        {
     317                                if (dynamic_cast__SomeException(except)) {
     318                                        return 1;
     319                                }
    301320                        }
    302321                        return 0;
  • src/Common/PassVisitor.h

    rfda8168 r16c95e3  
    2525// | WithStmtsToAdd       - provides the ability to insert statements before or after the current statement by adding new statements into
    2626//                          stmtsToAddBefore or stmtsToAddAfter respectively.
    27 // | WithShortCircuiting  - provides the ability to skip visiting child nodes; set skip_children to true if pre{visit,mutate} to skip visiting children
     27// | WithShortCircuiting  - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children
    2828// | WithScopes           - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable
    2929//                          will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates.
     
    3737        PassVisitor(Args &&... args)
    3838                : pass( std::forward<Args>( args )... )
    39         {}
     39        {
     40                typedef PassVisitor<pass_type> this_t;
     41                this_t * const * visitor = visitor_impl(pass, 0);
     42                if(visitor) {
     43                        *const_cast<this_t **>( visitor ) = this;
     44                }
     45        }
    4046
    4147        virtual ~PassVisitor() = default;
     
    214220
    215221private:
     222        template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
     223        template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
     224
    216225        template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); }
    217226        template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); }
     
    225234        void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); }
    226235
    227         void visitStatementList( std::list< Statement* > &statements );
     236        template< typename func_t >
     237        void handleStatementList( std::list< Statement * > & statements, func_t func );
     238        void visitStatementList ( std::list< Statement* > &statements );
    228239        void mutateStatementList( std::list< Statement* > &statements );
    229240
    230         Statement * visitStatement( Statement * stmt );
     241        template< typename func_t >
     242        Statement * handleStatement( Statement * stmt, func_t func );
     243        Statement * visitStatement ( Statement * stmt );
    231244        Statement * mutateStatement( Statement * stmt );
    232245
    233         void visitExpression( Expression * expr );
     246        template< typename func_t >
     247        Expression * handleExpression( Expression * expr, func_t func );
     248        Expression * visitExpression ( Expression * expr );
    234249        Expression * mutateExpression( Expression * expr );
    235250
     
    238253        std::list< Statement* > *       get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); }
    239254        std::list< Statement* > *       get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); }
    240         bool visit_children() { bool* skip = skip_children_impl(pass, 0); return ! (skip && *skip); }
    241         void reset_visit() { bool* skip = skip_children_impl(pass, 0); if(skip) *skip = false; }
     255        std::list< Declaration* > *     get_beforeDecls() { return declsToAddBefore_impl( pass, 0); }
     256        std::list< Declaration* > *     get_afterDecls () { return declsToAddAfter_impl ( pass, 0); }
     257
     258        void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); }
    242259
    243260        guard_value_impl init_guard() {
     
    278295        std::list< Statement* > stmtsToAddAfter;
    279296};
    280 
    281297class WithShortCircuiting {
    282298protected:
     
    285301
    286302public:
    287         bool skip_children;
     303        bool_ref visit_children;
    288304};
    289305
     
    304320};
    305321
     322template<typename pass_type>
     323class WithVisitorRef {
     324protected:
     325        WithVisitorRef() = default;
     326        ~WithVisitorRef() = default;
     327
     328public:
     329        PassVisitor<pass_type> * const visitor;
     330};
    306331
    307332#include "PassVisitor.impl.h"
  • src/Common/PassVisitor.impl.h

    rfda8168 r16c95e3  
    44        __attribute__((unused))                   \
    55        const auto & guard = init_guard();        \
     6        bool visit_children = true;               \
     7        set_visit_children( visit_children );   \
    68        call_previsit( node );                    \
    7         if( visit_children() ) {                  \
     9        if( visit_children ) {                    \
    810
    911#define VISIT_END( node )                       \
    1012        }                                         \
    11         reset_visit();                            \
    1213        call_postvisit( node );                   \
    1314
     
    1516        __attribute__((unused))                   \
    1617        const auto & guard = init_guard();        \
     18        bool visit_children = true;               \
     19        set_visit_children( visit_children );   \
    1720        call_premutate( node );                   \
    18         if( visit_children() ) {                  \
     21        if( visit_children ) {                    \
    1922
    2023#define MUTATE_END( type, node )                \
    2124        }                                         \
    22         reset_visit();                            \
    2325        return call_postmutate< type * >( node ); \
    2426
     
    4244}
    4345
    44 typedef std::list< Statement * > StmtList_t;
    45 
    46 template< typename pass_type >
    47 void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) {
     46typedef std::list< Statement   * > StmtList_t;
     47typedef std::list< Declaration * > DeclList_t;
     48
     49template<typename iterator_t>
     50static inline void splice( iterator_t it, DeclList_t * decls ) {
     51        std::transform(
     52                decls->begin(),
     53                decls->end(),
     54                it,
     55                [](Declaration * decl) -> auto {
     56                        return new DeclStmt( noLabels, decl );
     57                }
     58        );
     59        decls->clear();
     60}
     61
     62template< typename pass_type >
     63static inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) {
     64
     65        DeclList_t* beforeDecls = visitor.get_beforeDecls();
     66        DeclList_t* afterDecls  = visitor.get_afterDecls();
     67
     68        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     69                // splice in new declarations after previous decl
     70                if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
     71
     72                if ( i == decls.end() ) break;
     73
     74                // run mutator on declaration
     75                maybeAccept( *i, visitor );
     76
     77                // splice in new declarations before current decl
     78                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
     79        }
     80}
     81
     82template< typename pass_type >
     83static inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) {
     84
     85        DeclList_t* beforeDecls = mutator.get_beforeDecls();
     86        DeclList_t* afterDecls  = mutator.get_afterDecls();
     87
     88        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     89                // splice in new declarations after previous decl
     90                if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
     91
     92                if ( i == decls.end() ) break;
     93
     94                // run mutator on declaration
     95                *i = maybeMutate( *i, mutator );
     96
     97                // splice in new declarations before current decl
     98                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
     99        }
     100}
     101
     102template< typename pass_type >
     103template< typename func_t >
     104void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) {
    48105        SemanticError errors;
    49106
    50107        StmtList_t* beforeStmts = get_beforeStmts();
    51108        StmtList_t* afterStmts  = get_afterStmts();
     109        DeclList_t* beforeDecls = get_beforeDecls();
     110        DeclList_t* afterDecls  = get_afterDecls();
    52111
    53112        for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
     113
     114                if ( !empty( afterDecls ) ) { splice( std::inserter( statements, i ), afterDecls ); }
    54115                if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
     116
    55117                try {
    56                         (*i)->accept( *this );
     118                        func( *i );
     119                        assert(( empty( beforeStmts ) && empty( afterStmts ))
     120                            || ( empty( beforeDecls ) && empty( afterDecls )) );
     121
    57122                } catch ( SemanticError &e ) {
    58123                        errors.append( e );
    59124                }
     125
     126                if ( !empty( beforeDecls ) ) { splice( std::inserter( statements, i ), beforeDecls ); }
    60127                if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); }
    61128        }
    62129
     130        if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); }
    63131        if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); }
    64132        if ( !errors.isEmpty() ) { throw errors; }
     
    66134
    67135template< typename pass_type >
     136void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) {
     137        handleStatementList( statements, [this]( Statement * stmt) {
     138                stmt->accept( *this );
     139        });
     140}
     141
     142template< typename pass_type >
    68143void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) {
    69         SemanticError errors;
     144        handleStatementList( statements, [this]( Statement *& stmt) {
     145                stmt = stmt->acceptMutator( *this );
     146        });
     147}
     148
     149
     150template< typename pass_type >
     151template< typename func_t >
     152Statement * PassVisitor< pass_type >::handleStatement( Statement * stmt, func_t func ) {
     153        // don't want statements from outer CompoundStmts to be added to this CompoundStmt
     154        ValueGuardPtr< TypeSubstitution * >  oldEnv        ( get_env_ptr    () );
     155        ValueGuardPtr< DeclList_t >          oldBeforeDecls( get_beforeDecls() );
     156        ValueGuardPtr< DeclList_t >          oldAfterDecls ( get_afterDecls () );
     157        ValueGuardPtr< StmtList_t >          oldBeforeStmts( get_beforeStmts() );
     158        ValueGuardPtr< StmtList_t >          oldAfterStmts ( get_afterStmts () );
     159
     160        Statement *newStmt = func( stmt );
    70161
    71162        StmtList_t* beforeStmts = get_beforeStmts();
    72163        StmtList_t* afterStmts  = get_afterStmts();
    73 
    74         for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
    75                 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
    76                 try {
    77                         *i = (*i)->acceptMutator( *this );
    78                 } catch ( SemanticError &e ) {
    79                         errors.append( e );
    80                 }
    81                 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); }
    82         }
    83 
    84         if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); }
    85         if ( !errors.isEmpty() ) { throw errors; }
    86 }
    87 
    88 template< typename pass_type >
    89 Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) {
    90         // don't want statements from outer CompoundStmts to be added to this CompoundStmt
    91         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
    92         ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    93         ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    94 
    95         maybeAccept( stmt, *this );
    96 
    97         StmtList_t* beforeStmts = get_beforeStmts();
    98         StmtList_t* afterStmts  = get_afterStmts();
    99 
    100         if( empty(beforeStmts) && empty(afterStmts) ) { return stmt; }
     164        DeclList_t* beforeDecls = get_beforeDecls();
     165        DeclList_t* afterDecls  = get_afterDecls();
     166
     167        if( empty(beforeStmts) && empty(afterStmts) && empty(beforeDecls) && empty(afterDecls) ) { return newStmt; }
     168        assert(( empty( beforeStmts ) && empty( afterStmts ))
     169            || ( empty( beforeDecls ) && empty( afterDecls )) );
    101170
    102171        CompoundStmt *compound = new CompoundStmt( noLabels );
     172        if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); }
    103173        if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
    104         compound->get_kids().push_back( stmt );
     174        compound->get_kids().push_back( newStmt );
     175        if( !empty(afterDecls) ) { splice( std::back_inserter( compound->get_kids() ), afterDecls ); }
    105176        if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
    106177        return compound;
     
    108179
    109180template< typename pass_type >
     181Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) {
     182        return handleStatement( stmt, [this]( Statement * stmt ) {
     183                maybeAccept( stmt, *this );
     184                return stmt;
     185        });
     186}
     187
     188template< typename pass_type >
    110189Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) {
    111         // don't want statements from outer CompoundStmts to be added to this CompoundStmt
    112         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
    113         ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    114         ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    115 
    116         Statement *newStmt = maybeMutate( stmt, *this );
    117 
    118         StmtList_t* beforeStmts = get_beforeStmts();
    119         StmtList_t* afterStmts  = get_afterStmts();
    120 
    121         if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; }
    122 
    123         CompoundStmt *compound = new CompoundStmt( noLabels );
    124         if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
    125         compound->get_kids().push_back( newStmt );
    126         if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
    127         return compound;
    128 }
    129 
    130 
    131 
    132 template< typename pass_type >
    133 void PassVisitor< pass_type >::visitExpression( Expression * expr ) {
    134         if( !expr ) return;
     190        return handleStatement( stmt, [this]( Statement * stmt ) {
     191                return maybeMutate( stmt, *this );
     192        });
     193}
     194
     195template< typename pass_type >
     196template< typename func_t >
     197Expression * PassVisitor< pass_type >::handleExpression( Expression * expr, func_t func ) {
     198        if( !expr ) return nullptr;
    135199
    136200        auto env_ptr = get_env_ptr();
     
    138202                *env_ptr = expr->get_env();
    139203        }
    140         // xxx - should env be cloned (or moved) onto the result of the mutate?
    141         expr->accept( *this );
     204
     205        // should env be cloned (or moved) onto the result of the mutate?
     206        return func( expr );
     207}
     208
     209template< typename pass_type >
     210Expression * PassVisitor< pass_type >::visitExpression( Expression * expr ) {
     211        return handleExpression(expr, [this]( Expression * expr ) {
     212                expr->accept( *this );
     213                return expr;
     214        });             
    142215}
    143216
    144217template< typename pass_type >
    145218Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) {
    146         if( !expr ) return nullptr;
    147 
    148         auto env_ptr = get_env_ptr();
    149         if ( env_ptr && expr->get_env() ) {
    150                 *env_ptr = expr->get_env();
    151         }
    152         // xxx - should env be cloned (or moved) onto the result of the mutate?
    153         return expr->acceptMutator( *this );
    154 }
    155 
     219        return handleExpression(expr, [this]( Expression * expr ) {
     220                return expr->acceptMutator( *this );
     221        });
     222}
    156223
    157224//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    231298void PassVisitor< pass_type >::visit( ExprStmt * node ) {
    232299        VISIT_START( node );
    233         call_beginScope();
    234300
    235301        visitExpression( node->get_expr() );
    236302
    237         call_endScope();
    238303        VISIT_END( node );
    239304}
     
    248313}
    249314
     315//--------------------------------------------------------------------------
     316// AsmStmt
    250317template< typename pass_type >
    251318void PassVisitor< pass_type >::visit( AsmStmt * node ) {
    252319        VISIT_BODY( node );
     320}
     321
     322template< typename pass_type >
     323Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
     324        MUTATE_BODY( Statement, node );
    253325}
    254326
     
    300372
    301373//--------------------------------------------------------------------------
    302 // WhileStmt
     374// ForStmt
    303375template< typename pass_type >
    304376void PassVisitor< pass_type >::visit( ForStmt * node ) {
     
    348420
    349421//--------------------------------------------------------------------------
    350 // SwitchStmt
     422// CaseStmt
    351423template< typename pass_type >
    352424void PassVisitor< pass_type >::visit( CaseStmt * node ) {
     
    369441}
    370442
     443//--------------------------------------------------------------------------
     444// BranchStmt
    371445template< typename pass_type >
    372446void PassVisitor< pass_type >::visit( BranchStmt * node ) {
    373447        VISIT_BODY( node );
     448}
     449
     450template< typename pass_type >
     451Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
     452        MUTATE_BODY( Statement, node );
    374453}
    375454
     
    415494        maybeAccept( node->get_block(), *this );
    416495        acceptAll( node->get_catchers(), *this );
     496        maybeAccept( node->get_finally(), *this );
    417497
    418498        VISIT_END( node );
     
    425505        node->set_block(  maybeMutate( node->get_block(), *this ) );
    426506        mutateAll( node->get_catchers(), *this );
     507        node->set_finally( maybeMutate( node->get_finally(), *this ) );
    427508
    428509        MUTATE_END( Statement, node );
     
    435516        VISIT_START( node );
    436517
     518        maybeAccept( node->get_decl(), *this );
     519        node->set_cond( visitExpression( node->get_cond() ) );
    437520        node->set_body( visitStatement( node->get_body() ) );
    438         maybeAccept( node->get_decl(), *this );
    439521
    440522        VISIT_END( node );
     
    445527        MUTATE_START( node );
    446528
    447         node->set_body(  mutateStatement( node->get_body() ) );
    448         node->set_decl(  maybeMutate( node->get_decl(), *this ) );
     529        node->set_decl( maybeMutate( node->get_decl(), *this ) );
     530        node->set_cond( mutateExpression( node->get_cond() ) );
     531        node->set_body( mutateStatement( node->get_body() ) );
    449532
    450533        MUTATE_END( Statement, node );
     
    838921
    839922template< typename pass_type >
    840 Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
    841         MUTATE_BODY( Statement, node );
    842 }
    843 
    844 template< typename pass_type >
    845 Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
    846         MUTATE_BODY( Statement, node );
    847 }
    848 
    849 template< typename pass_type >
    850923Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
    851924        MUTATE_BODY( Statement, node );
  • src/Common/PassVisitor.proto.h

    rfda8168 r16c95e3  
    11#pragma once
     2
     3template<typename pass_type>
     4class PassVisitor;
    25
    36typedef std::function<void( void * )> cleanup_func_t;
     
    3134
    3235typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t;
     36
     37class bool_ref {
     38public:
     39        bool_ref() = default;
     40        ~bool_ref() = default;
     41
     42        operator bool() { return *m_ref; }
     43        bool operator=( bool val ) { return *m_ref = val; }
     44
     45private:
     46
     47        template<typename pass>
     48        friend class PassVisitor;
     49
     50        void set( bool & val ) { m_ref = &val; };
     51
     52        bool * m_ref;
     53};
    3354
    3455//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    112133FIELD_PTR( std::list< Statement* >, stmtsToAddBefore )
    113134FIELD_PTR( std::list< Statement* >, stmtsToAddAfter  )
    114 FIELD_PTR( bool, skip_children )
     135FIELD_PTR( std::list< Declaration* >, declsToAddBefore )
     136FIELD_PTR( std::list< Declaration* >, declsToAddAfter  )
     137FIELD_PTR( bool_ref, visit_children )
    115138FIELD_PTR( at_cleanup_t, at_cleanup )
     139FIELD_PTR( PassVisitor<pass_type> * const, visitor )
  • src/GenPoly/DeclMutator.cc

    rfda8168 r16c95e3  
    99// Author           : Aaron B. Moss
    1010// Created On       : Fri Nov 27 14:44:00 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug  4 11:16:43 2016
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Jun 22 13:49:00 2017
     13// Update Count     : 4
    1414//
    1515
     
    178178        Statement* DeclMutator::mutate(CatchStmt *catchStmt) {
    179179                catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) );
     180                catchStmt->set_cond( maybeMutate( catchStmt->get_cond(), *this ) );
    180181                catchStmt->set_body( mutateStatement( catchStmt->get_body() ) );
    181182                return catchStmt;
  • src/GenPoly/PolyMutator.cc

    rfda8168 r16c95e3  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug  4 11:26:22 2016
    13 // Update Count     : 16
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Jun 22 13:47:00 2017
     13// Update Count     : 17
    1414//
    1515
     
    123123
    124124        Statement * PolyMutator::mutate(TryStmt *tryStmt) {
    125                 tryStmt->set_block(  maybeMutate( tryStmt->get_block(), *this ) );
     125                tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
    126126                mutateAll( tryStmt->get_catchers(), *this );
     127                tryStmt->set_finally( maybeMutate( tryStmt->get_finally(), *this ) );
    127128                return tryStmt;
    128129        }
    129130
    130131        Statement * PolyMutator::mutate(CatchStmt *cathStmt) {
    131                 cathStmt->set_body(  mutateStatement( cathStmt->get_body() ) );
    132                 cathStmt->set_decl(  maybeMutate( cathStmt->get_decl(), *this ) );
     132                cathStmt->set_body( mutateStatement( cathStmt->get_body() ) );
     133                cathStmt->set_cond( maybeMutate( cathStmt->get_cond(), *this ) );
     134                cathStmt->set_decl( maybeMutate( cathStmt->get_decl(), *this ) );
    133135                return cathStmt;
    134136        }
  • src/GenPoly/Specialize.cc

    rfda8168 r16c95e3  
    9999                if ( FunctionType * fftype = getFunctionType( formalType ) ) {
    100100                        if ( fftype->isTtype() ) return true;
     101                        // conversion of 0 (null) to function type does not require tuple specialization
     102                        if ( dynamic_cast< ZeroType * >( actualType ) ) return false;
    101103                        FunctionType * aftype = getFunctionType( actualType );
    102104                        assertf( aftype, "formal type is a function type, but actual type is not." );
  • src/InitTweak/InitTweak.cc

    rfda8168 r16c95e3  
    474474        public:
    475475                ConstExprChecker() : isConstExpr( true ) {}
     476
     477                using Visitor::visit;
    476478
    477479                virtual void visit( __attribute((unused)) ApplicationExpr *applicationExpr ) { isConstExpr = false; }
  • src/Parser/StatementNode.cc

    rfda8168 r16c95e3  
    168168
    169169Statement *build_resume_at( ExpressionNode *ctl, ExpressionNode *target ) {
    170         std::list< Expression * > exps;
    171         buildMoveList( ctl, exps );
    172         assertf( exps.size() < 2, "This means we are leaking memory");
    173         return new ThrowStmt( noLabels, ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr );
     170        (void)ctl;
     171        (void)target;
     172        assertf( false, "resume at (non-local throw) is not yet supported," );
    174173}
    175174
  • src/SynTree/Constant.cc

    rfda8168 r16c95e3  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 21 16:44:48 2017
    13 // Update Count     : 27
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Jun 22 10:11:00 2017
     13// Update Count     : 28
    1414//
    1515
     
    2929
    3030Constant::~Constant() { delete type; }
     31
     32Constant Constant::from_bool( bool b ) {
     33        return Constant( new BasicType( Type::Qualifiers(), BasicType::Bool ), b ? "1" : "0" , (unsigned long long int)b );
     34}
    3135
    3236Constant Constant::from_int( int i ) {
  • src/SynTree/Constant.h

    rfda8168 r16c95e3  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 21 16:44:48 2017
    13 // Update Count     : 14
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Jun 22 10:13:00 2017
     13// Update Count     : 15
    1414//
    1515
     
    3333        void set_value( std::string newValue ) { rep = newValue; }
    3434
     35        /// generates a boolean constant of the given bool
     36        static Constant from_bool( bool b );
    3537        /// generates an integer constant of the given int
    3638        static Constant from_int( int i );
  • src/SynTree/Mutator.cc

    rfda8168 r16c95e3  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Mar  8 16:36:00 2017
    13 // Update Count     : 23
     12// Last Modified On : Thu Jun 22 13:43:00 2017
     13// Update Count     : 24
    1414//
    1515
     
    162162        tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
    163163        mutateAll( tryStmt->get_catchers(), *this );
     164        tryStmt->set_finally( maybeMutate( tryStmt->get_finally(), *this ) );
    164165        return tryStmt;
    165166}
     
    167168Statement *Mutator::mutate( CatchStmt *catchStmt ) {
    168169        catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) );
     170        catchStmt->set_cond( maybeMutate( catchStmt->get_cond(), *this ) );
    169171        catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) );
    170172        return catchStmt;
  • src/SynTree/Visitor.cc

    rfda8168 r16c95e3  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Jun  8 16:31:00 2017
    13 // Update Count     : 25
     12// Last Modified On : Thu Jun 22 13:41:00 2017
     13// Update Count     : 26
    1414//
    1515
     
    137137        maybeAccept( tryStmt->get_block(), *this );
    138138        acceptAll( tryStmt->get_catchers(), *this );
     139        maybeAccept( tryStmt->get_finally(), *this );
    139140}
    140141
    141142void Visitor::visit( CatchStmt *catchStmt ) {
    142143        maybeAccept( catchStmt->get_decl(), *this );
     144        maybeAccept( catchStmt->get_cond(), *this );
    143145        maybeAccept( catchStmt->get_body(), *this );
    144146}
  • src/libcfa/Makefile.am

    rfda8168 r16c95e3  
    7272libcfa_a_CFLAGS = -nodebug -O2
    7373libcfa_d_a_SOURCES = ${libsrc}
    74 libcfa_d_a_CFLAGS = -debug -O0
     74libcfa_d_a_CFLAGS = -debug -O0 #No need for __CFA_DEBUG__ since we pass -debug
    7575
    7676stdhdr = ${shell echo stdhdr/*}
  • src/libcfa/Makefile.in

    rfda8168 r16c95e3  
    332332libcfa_a_CFLAGS = -nodebug -O2
    333333libcfa_d_a_SOURCES = ${libsrc}
    334 libcfa_d_a_CFLAGS = -debug -O0
     334libcfa_d_a_CFLAGS = -debug -O0 #No need for __CFA_DEBUG__ since we pass -debug
    335335stdhdr = ${shell echo stdhdr/*}
    336336cfa_includedir = $(CFA_INCDIR)
  • src/main.cc

    rfda8168 r16c95e3  
    186186                if ( ! nopreludep ) {                                                   // include gcc builtins
    187187                        // -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here.
     188                        // Read to cfa builtins, if not generating the cfa library
    188189                        FILE * builtins = fopen( libcfap | treep ? "../prelude/builtins.cf" : CFA_LIBDIR "/builtins.cf", "r" );
    189190                        assertf( builtins, "cannot open builtins.cf\n" );
    190191                        parse( builtins, LinkageSpec::Compiler );
     192
     193                        // Read to gcc builtins, if not generating the cfa library
     194                        FILE * gcc_builtins = fopen( libcfap | treep ? "../prelude/gcc-builtins.cf" : CFA_LIBDIR "/gcc-builtins.cf", "r" );
     195                        assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" );
     196                        parse( gcc_builtins, LinkageSpec::Compiler );
    191197
    192198                        // read the extra prelude in, if not generating the cfa library
  • src/prelude/Makefile.am

    rfda8168 r16c95e3  
    2020# put into lib for now
    2121cfalibdir = ${CFA_LIBDIR}
    22 cfalib_DATA = builtins.cf extras.cf prelude.cf bootloader.c
     22cfalib_DATA = gcc-builtins.cf builtins.cf extras.cf prelude.cf bootloader.c
    2323noinst_DATA = ../libcfa/libcfa-prelude.c
    2424
     
    2828
    2929# create forward declarations for gcc builtins
    30 builtins.cf : builtins.c prototypes.sed
     30gcc-builtins.cf : gcc-builtins.c prototypes.sed
    3131        ${AM_V_GEN}@BACKEND_CC@ -E -P $< | sed -f prototypes.sed > $@
    3232
    33 builtins.c : builtins.def prototypes.awk
     33gcc-builtins.c : builtins.def prototypes.awk
    3434        ${AM_V_GEN}@BACKEND_CC@ -E prototypes.c | awk -f prototypes.awk > $@
    3535
     
    3838prototypes.awk :
    3939
    40 ../libcfa/libcfa-prelude.c : prelude.cf extras.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
     40# create forward declarations for cfa builtins
     41builtins.cf : builtins.c
     42        ${AM_V_GEN}@BACKEND_CC@ -E -P ${<} -o ${@}
     43
     44../libcfa/libcfa-prelude.c : prelude.cf extras.cf gcc-builtins.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
    4145        ${AM_V_GEN}${abs_top_srcdir}/src/driver/cfa-cpp -l prelude.cf $@  # use src/cfa-cpp as not in lib until after install
    4246
    43 bootloader.c : bootloader.cf prelude.cf extras.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
     47bootloader.c : bootloader.cf prelude.cf extras.cf gcc-builtins.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
    4448        ${AM_V_GEN}${abs_top_srcdir}/src/driver/cfa-cpp -tpmL bootloader.cf $@  # use src/cfa-cpp as not in lib until after install
    4549
    46 MAINTAINERCLEANFILES = builtins.c builtins.cf extras.cf bootloader.c ${addprefix ${libdir}/,${cfalib_DATA}} ${addprefix ${libdir}/,${lib_LIBRARIES}}
     50MAINTAINERCLEANFILES = gcc-builtins.c gcc-builtins.cf builtins.cf extras.cf bootloader.c ${addprefix ${libdir}/,${cfalib_DATA}} ${addprefix ${libdir}/,${lib_LIBRARIES}}
  • src/prelude/Makefile.in

    rfda8168 r16c95e3  
    211211# put into lib for now
    212212cfalibdir = ${CFA_LIBDIR}
    213 cfalib_DATA = builtins.cf extras.cf prelude.cf bootloader.c
     213cfalib_DATA = gcc-builtins.cf builtins.cf extras.cf prelude.cf bootloader.c
    214214noinst_DATA = ../libcfa/libcfa-prelude.c
    215 MAINTAINERCLEANFILES = builtins.c builtins.cf extras.cf bootloader.c ${addprefix ${libdir}/,${cfalib_DATA}} ${addprefix ${libdir}/,${lib_LIBRARIES}}
     215MAINTAINERCLEANFILES = gcc-builtins.c gcc-builtins.cf builtins.cf extras.cf bootloader.c ${addprefix ${libdir}/,${cfalib_DATA}} ${addprefix ${libdir}/,${lib_LIBRARIES}}
    216216all: all-am
    217217
     
    425425
    426426# create forward declarations for gcc builtins
    427 builtins.cf : builtins.c prototypes.sed
     427gcc-builtins.cf : gcc-builtins.c prototypes.sed
    428428        ${AM_V_GEN}@BACKEND_CC@ -E -P $< | sed -f prototypes.sed > $@
    429429
    430 builtins.c : builtins.def prototypes.awk
     430gcc-builtins.c : builtins.def prototypes.awk
    431431        ${AM_V_GEN}@BACKEND_CC@ -E prototypes.c | awk -f prototypes.awk > $@
    432432
     
    435435prototypes.awk :
    436436
    437 ../libcfa/libcfa-prelude.c : prelude.cf extras.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
     437# create forward declarations for cfa builtins
     438builtins.cf : builtins.c
     439        ${AM_V_GEN}@BACKEND_CC@ -E -P ${<} -o ${@}
     440
     441../libcfa/libcfa-prelude.c : prelude.cf extras.cf gcc-builtins.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
    438442        ${AM_V_GEN}${abs_top_srcdir}/src/driver/cfa-cpp -l prelude.cf $@  # use src/cfa-cpp as not in lib until after install
    439443
    440 bootloader.c : bootloader.cf prelude.cf extras.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
     444bootloader.c : bootloader.cf prelude.cf extras.cf gcc-builtins.cf builtins.cf ${abs_top_srcdir}/src/driver/cfa-cpp
    441445        ${AM_V_GEN}${abs_top_srcdir}/src/driver/cfa-cpp -tpmL bootloader.cf $@  # use src/cfa-cpp as not in lib until after install
    442446
  • src/tests/preempt_longrun/Makefile.am

    rfda8168 r16c95e3  
    2626CC = @CFA_BINDIR@/@CFA_NAME@
    2727
    28 TESTS = create stack yield
     28TESTS = barge block create disjoint processor stack wait yield
    2929
    3030.INTERMEDIATE: ${TESTS}
  • src/tests/preempt_longrun/Makefile.in

    rfda8168 r16c95e3  
    183183REPEAT = ${abs_top_srcdir}/tools/repeat -s
    184184BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ -debug -O2 -DN=${N} -DPREEMPTION_RATE=${preempt}
    185 TESTS = create stack yield
     185TESTS = barge block create disjoint processor stack wait yield
    186186all: all-am
    187187
  • src/tests/sched-int-block.c

    rfda8168 r16c95e3  
    55#include <thread>
    66
    7 static const unsigned N = 100_000;
     7#ifndef N
     8#define N 100_000
     9#endif
    810
    911enum state_t { WAITED, SIGNAL, BARGE };
  • src/tests/sched-int-disjoint.c

    rfda8168 r16c95e3  
    44#include <thread>
    55
     6#ifndef N
    67#define N 100_000
     8#endif
    79
    810enum state_t { WAIT, SIGNAL, BARGE };
  • src/tests/sched-int-wait.c

    rfda8168 r16c95e3  
    55#include <thread>
    66
    7 static const int N = 10_000;
     7#ifndef N
     8#define N 10_000
     9#endif
    810
    911monitor global_t {};
  • tools/repeat

    rfda8168 r16c95e3  
    2020for (( i = 0; i < ITERATION; i ++ )); do
    2121        echo -ne "\r$i / $ITERATION"
    22         $@ &
     22        $@ > /dev/null &
    2323        child=$!
    2424        wait "$child"
Note: See TracChangeset for help on using the changeset viewer.