Changeset db4062d


Ignore:
Timestamp:
Jun 20, 2018, 8:42:37 AM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, 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, with_gc
Children:
4439008
Parents:
e04aec4 (diff), 270fdcf (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

Files:
7 added
32 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    re04aec4 rdb4062d  
    133133                output << "__attribute__ ((";
    134134                for ( list< Attribute * >::iterator attr( attributes.begin() );; ) {
    135                         output << (*attr)->get_name();
    136                         if ( ! (*attr)->get_parameters().empty() ) {
     135                        output << (*attr)->name;
     136                        if ( ! (*attr)->parameters.empty() ) {
    137137                                output << "(";
    138                                 genCommaList( (*attr)->get_parameters().begin(), (*attr)->get_parameters().end() );
     138                                genCommaList( (*attr)->parameters.begin(), (*attr)->parameters.end() );
    139139                                output << ")";
    140140                        } // if
     
    836836                assertf( ! genC, "Deleted expressions should not reach code generation." );
    837837                expr->expr->accept( *visitor );
     838        }
     839
     840        void CodeGenerator::postvisit( DefaultArgExpr * arg ) {
     841                assertf( ! genC, "Default argument expressions should not reach code generation." );
     842                arg->expr->accept( *visitor );
    838843        }
    839844
  • src/CodeGen/CodeGenerator.h

    re04aec4 rdb4062d  
    9494                void postvisit( ConstructorExpr * );
    9595                void postvisit( DeletedExpr * );
     96                void postvisit( DefaultArgExpr * );
    9697                void postvisit( GenericExpr * );
    9798
  • src/Common/Debug.h

    re04aec4 rdb4062d  
    2828namespace Debug {
    2929        /// debug codegen a translation unit
    30         static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) {
     30        static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec::Builtin ) {
    3131        #ifdef DEBUG
    3232                std::list< Declaration * > decls;
  • src/Common/PassVisitor.h

    re04aec4 rdb4062d  
    125125        virtual void visit( InitExpr *  initExpr ) override final;
    126126        virtual void visit( DeletedExpr *  delExpr ) override final;
     127        virtual void visit( DefaultArgExpr * argExpr ) override final;
    127128        virtual void visit( GenericExpr * genExpr ) override final;
    128129
     
    224225        virtual Expression * mutate( InitExpr *  initExpr ) override final;
    225226        virtual Expression * mutate( DeletedExpr *  delExpr ) override final;
     227        virtual Expression * mutate( DefaultArgExpr * argExpr ) override final;
    226228        virtual Expression * mutate( GenericExpr * genExpr ) override final;
    227229
     
    258260
    259261private:
     262        bool inFunction = false;
     263
    260264        template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
    261265        template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
  • src/Common/PassVisitor.impl.h

    re04aec4 rdb4062d  
    404404                        indexerAddId( &func );
    405405                        maybeAccept_impl( node->type, *this );
     406                        // function body needs to have the same scope as parameters - CompoundStmt will not enter
     407                        // a new scope if inFunction is true
     408                        ValueGuard< bool > oldInFunction( inFunction );
     409                        inFunction = true;
    406410                        maybeAccept_impl( node->statements, *this );
    407411                        maybeAccept_impl( node->attributes, *this );
     
    434438                        indexerAddId( &func );
    435439                        maybeMutate_impl( node->type, *this );
     440                        // function body needs to have the same scope as parameters - CompoundStmt will not enter
     441                        // a new scope if inFunction is true
     442                        ValueGuard< bool > oldInFunction( inFunction );
     443                        inFunction = true;
    436444                        maybeMutate_impl( node->statements, *this );
    437445                        maybeMutate_impl( node->attributes, *this );
     
    712720        VISIT_START( node );
    713721        {
    714                 auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     722                // do not enter a new scope if inFunction is true - needs to check old state before the assignment
     723                ValueGuard< bool > oldInFunction( inFunction );
     724                auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
    715725                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
     726                inFunction = false;
    716727                visitStatementList( node->kids );
    717728        }
     
    723734        MUTATE_START( node );
    724735        {
    725                 auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     736                // do not enter a new scope if inFunction is true - needs to check old state before the assignment
     737                ValueGuard< bool > oldInFunction( inFunction );
     738                auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
    726739                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
     740                inFunction = false;
    727741                mutateStatementList( node->kids );
    728742        }
     
    20842098
    20852099//--------------------------------------------------------------------------
     2100// DefaultArgExpr
     2101template< typename pass_type >
     2102void PassVisitor< pass_type >::visit( DefaultArgExpr * node ) {
     2103        VISIT_START( node );
     2104
     2105        indexerScopedAccept( node->result, *this );
     2106        maybeAccept_impl( node->expr, *this );
     2107
     2108        VISIT_END( node );
     2109}
     2110
     2111template< typename pass_type >
     2112Expression * PassVisitor< pass_type >::mutate( DefaultArgExpr * node ) {
     2113        MUTATE_START( node );
     2114
     2115        indexerScopedMutate( node->env, *this );
     2116        indexerScopedMutate( node->result, *this );
     2117        maybeMutate_impl( node->expr, *this );
     2118
     2119        MUTATE_END( Expression, node );
     2120}
     2121
     2122//--------------------------------------------------------------------------
    20862123// GenericExpr
    20872124template< typename pass_type >
  • src/GenPoly/Lvalue.cc

    re04aec4 rdb4062d  
    146146
    147147        namespace {
    148                 // true for intrinsic function calls that return a reference
     148                // true for intrinsic function calls that return an lvalue in C
    149149                bool isIntrinsicReference( Expression * expr ) {
     150                        // known intrinsic-reference prelude functions
     151                        static std::set<std::string> lvalueFunctions = { "*?", "?[?]" };
    150152                        if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * >( expr ) ) {
    151153                                std::string fname = InitTweak::getFunctionName( untyped );
    152                                 // known intrinsic-reference prelude functions
    153                                 return fname == "*?" || fname == "?[?]";
     154                                return lvalueFunctions.count(fname);
    154155                        } else if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( expr ) ) {
    155156                                if ( DeclarationWithType * func = InitTweak::getFunction( appExpr ) ) {
    156                                         // use type of return variable rather than expr result type, since it may have been changed to a pointer type
    157                                         FunctionType * ftype = GenPoly::getFunctionType( func->get_type() );
    158                                         Type * ret = ftype->returnVals.empty() ? nullptr : ftype->returnVals.front()->get_type();
    159                                         return func->linkage == LinkageSpec::Intrinsic && dynamic_cast<ReferenceType *>( ret );
     157                                        return func->linkage == LinkageSpec::Intrinsic && lvalueFunctions.count(func->name);
    160158                                }
    161159                        }
     
    212210                                                // TODO: it's likely that the second condition should be ... && ! isIntrinsicReference( arg ), but this requires investigation.
    213211
    214                                                 if ( function->get_linkage() != LinkageSpec::Intrinsic && isIntrinsicReference( arg ) ) {
     212                                                if ( function->linkage != LinkageSpec::Intrinsic && isIntrinsicReference( arg ) ) {
    215213                                                        // needed for definition of prelude functions, etc.
    216214                                                        // if argument is dereference or array subscript, the result isn't REALLY a reference, but non-intrinsic functions expect a reference: take address
     
    228226                                                        arg = new AddressExpr( arg );
    229227                                                // } else if ( function->get_linkage() == LinkageSpec::Intrinsic && InitTweak::getPointerBase( arg->result ) ) {
    230                                                 } else if ( function->get_linkage() == LinkageSpec::Intrinsic && arg->result->referenceDepth() != 0 ) {
     228                                                } else if ( function->linkage == LinkageSpec::Intrinsic && arg->result->referenceDepth() != 0 ) {
    231229                                                        // argument is a 'real' reference, but function expects a C lvalue: add a dereference to the reference-typed argument
    232230                                                        PRINT(
  • src/ResolvExpr/AlternativeFinder.cc

    re04aec4 rdb4062d  
    176176                                                selected[ mangleName ] = current;
    177177                                        } else if ( candidate->cost == mapPlace->second.candidate->cost ) {
    178                                                 PRINT(
    179                                                         std::cerr << "marking ambiguous" << std::endl;
    180                                                 )
    181                                                 mapPlace->second.isAmbiguous = true;
     178                                                // if one of the candidates contains a deleted identifier, can pick the other, since
     179                                                // deleted expressions should not be ambiguous if there is another option that is at least as good
     180                                                if ( findDeletedExpr( candidate->expr ) ) {
     181                                                        // do nothing
     182                                                        PRINT( std::cerr << "candidate is deleted" << std::endl; )
     183                                                } else if ( findDeletedExpr( mapPlace->second.candidate->expr ) ) {
     184                                                        PRINT( std::cerr << "current is deleted" << std::endl; )
     185                                                        selected[ mangleName ] = current;
     186                                                } else {
     187                                                        PRINT(
     188                                                                std::cerr << "marking ambiguous" << std::endl;
     189                                                        )
     190                                                        mapPlace->second.isAmbiguous = true;
     191                                                }
    182192                                        } else {
    183193                                                PRINT(
     
    335345                if ( ConstantExpr * constantExpr = dynamic_cast< ConstantExpr * >( member ) ) {
    336346                        // get the value of the constant expression as an int, must be between 0 and the length of the tuple type to have meaning
    337                         // xxx - this should be improved by memoizing the value of constant exprs
    338                         // during parsing and reusing that information here.
    339                         std::stringstream ss( constantExpr->get_constant()->get_value() );
    340                         int val = 0;
     347                        auto val = constantExpr->intValue();
    341348                        std::string tmp;
    342                         if ( ss >> val && ! (ss >> tmp) ) {
    343                                 if ( val >= 0 && (unsigned int)val < tupleType->size() ) {
    344                                         alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
    345                                 } // if
     349                        if ( val >= 0 && (unsigned long long)val < tupleType->size() ) {
     350                                alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
    346351                        } // if
    347                 } else if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( member ) ) {
    348                         // xxx - temporary hack until 0/1 are int constants
    349                         if ( nameExpr->get_name() == "0" || nameExpr->get_name() == "1" ) {
    350                                 std::stringstream ss( nameExpr->get_name() );
    351                                 int val;
    352                                 ss >> val;
    353                                 alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
    354                         }
    355352                } // if
    356353        }
     
    439436                                        return Cost::infinity;
    440437                                }
     438                        }
     439                        if ( DefaultArgExpr * def = dynamic_cast< DefaultArgExpr * >( *actualExpr ) ) {
     440                                // default arguments should be free - don't include conversion cost.
     441                                // Unwrap them here because they are not relevant to the rest of the system.
     442                                *actualExpr = def->expr;
     443                                ++formal;
     444                                continue;
    441445                        }
    442446                        Type * formalType = (*formal)->get_type();
     
    611615        ConstantExpr* getDefaultValue( Initializer* init ) {
    612616                if ( SingleInit* si = dynamic_cast<SingleInit*>( init ) ) {
    613                         if ( CastExpr* ce = dynamic_cast<CastExpr*>( si->get_value() ) ) {
    614                                 return dynamic_cast<ConstantExpr*>( ce->get_arg() );
     617                        if ( CastExpr* ce = dynamic_cast<CastExpr*>( si->value ) ) {
     618                                return dynamic_cast<ConstantExpr*>( ce->arg );
     619                        } else {
     620                                return dynamic_cast<ConstantExpr*>( si->value );
    615621                        }
    616622                }
     
    873879                                                                indexer ) ) {
    874880                                                        results.emplace_back(
    875                                                                 i, cnstExpr, move(env), move(need), move(have),
     881                                                                i, new DefaultArgExpr( cnstExpr ), move(env), move(need), move(have),
    876882                                                                move(openVars), nextArg, nTuples );
    877883                                                }
     
    10651071                funcFinder.findWithAdjustment( untypedExpr->function );
    10661072                // if there are no function alternatives, then proceeding is a waste of time.
     1073                // xxx - findWithAdjustment throws, so this check and others like it shouldn't be necessary.
    10671074                if ( funcFinder.alternatives.empty() ) return;
    10681075
  • src/ResolvExpr/Resolver.h

    re04aec4 rdb4062d  
    3636        void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer );
    3737        void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer );
     38        /// Searches expr and returns the first DeletedExpr found, otherwise nullptr
     39        DeletedExpr * findDeletedExpr( Expression * expr );
    3840} // namespace ResolvExpr
    3941
  • src/SymTab/Indexer.cc

    re04aec4 rdb4062d  
    126126                                decls.push_back( DeclBall{ data, isUserDefinedFunc, isCopyFunc } );
    127127                                existsUserDefinedCopyFunc = existsUserDefinedCopyFunc || (isUserDefinedFunc && isCopyFunc);
    128                                 if ( isUserDefinedFunc && ! data.deleteStmt ) {
     128                                if ( isUserDefinedFunc && ! deleteStmt ) {
    129129                                        // any user-defined function can act as an implicit delete statement for generated constructors.
    130130                                        // a delete stmt should not act as an implicit delete statement.
     
    166166                                bool isCopyFunc = ball.isCopyFunc;
    167167                                bool existsUserDefinedCopyFunc = val.existsUserDefinedCopyFunc;
    168                                 // only implicitly delete non-user defined functions that are  not intrinsic, and are
    169                                 // not copy functions (assignment or copy constructor), unless a user-defined copy function exists.
    170                                 // deleteStmt will be non-null only if a user-defined function is found.
    171                                 if (isNotUserDefinedFunc && (! isCopyFunc || existsUserDefinedCopyFunc)) {
    172                                         ball.decl.deleteStmt = val.deleteStmt;
     168
     169                                // only implicitly delete non-user defined functions that are not intrinsic, and are
     170                                // not copy functions (assignment or copy constructor). If a  user-defined copy function exists,
     171                                // do not pass along the non-user-defined copy functions since signatures do not have to match,
     172                                // and the generated functions will often be cheaper.
     173                                if ( isNotUserDefinedFunc ) {
     174                                        if ( isCopyFunc ) {
     175                                                // Skip over non-user-defined copy functions when there is a user-defined copy function.
     176                                                // Since their signatures do not have to be exact, deleting them is the wrong choice.
     177                                                if ( existsUserDefinedCopyFunc ) continue;
     178                                        } else {
     179                                                // delete non-user-defined non-copy functions if applicable.
     180                                                // deleteStmt will be non-null only if a user-defined function is found.
     181                                                ball.decl.deleteStmt = val.deleteStmt;
     182                                        }
    173183                                }
    174184                                out.push_back( ball.decl );
  • src/SynTree/Expression.cc

    re04aec4 rdb4062d  
    746746        os << std::endl << indent+1 << "... deleted by: ";
    747747        deleteStmt->print( os, indent+1 );
     748}
     749
     750
     751DefaultArgExpr::DefaultArgExpr( Expression * expr ) : expr( expr ) {
     752        assert( expr->result );
     753        result = expr->result->clone();
     754}
     755DefaultArgExpr::DefaultArgExpr( const DefaultArgExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ) {}
     756DefaultArgExpr::~DefaultArgExpr() {
     757        delete expr;
     758}
     759
     760void DefaultArgExpr::print( std::ostream & os, Indenter indent ) const {
     761        os << "Default Argument Expression" << std::endl << indent+1;
     762        expr->print( os, indent+1 );
    748763}
    749764
  • src/SynTree/Expression.h

    re04aec4 rdb4062d  
    865865};
    866866
     867/// expression wrapping the use of a default argument - should never make it past the resolver.
     868class DefaultArgExpr : public Expression {
     869public:
     870        Expression * expr;
     871
     872        DefaultArgExpr( Expression * expr );
     873        DefaultArgExpr( const DefaultArgExpr & other );
     874        ~DefaultArgExpr();
     875
     876        virtual DefaultArgExpr * clone() const { return new DefaultArgExpr( * this ); }
     877        virtual void accept( Visitor & v ) { v.visit( this ); }
     878        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
     879        virtual void print( std::ostream & os, Indenter indent = {} ) const;
     880};
     881
    867882/// C11 _Generic expression
    868883class GenericExpr : public Expression {
  • src/SynTree/Mutator.h

    re04aec4 rdb4062d  
    9393        virtual Expression * mutate( InitExpr  * initExpr ) = 0;
    9494        virtual Expression * mutate( DeletedExpr * delExpr ) = 0;
     95        virtual Expression * mutate( DefaultArgExpr * argExpr ) = 0;
    9596        virtual Expression * mutate( GenericExpr * genExpr ) = 0;
    9697
  • src/SynTree/SynTree.h

    re04aec4 rdb4062d  
    101101class InitExpr;
    102102class DeletedExpr;
     103class DefaultArgExpr;
    103104class GenericExpr;
    104105
  • src/SynTree/Visitor.h

    re04aec4 rdb4062d  
    9595        virtual void visit( InitExpr *  initExpr ) = 0;
    9696        virtual void visit( DeletedExpr * delExpr ) = 0;
     97        virtual void visit( DefaultArgExpr * argExpr ) = 0;
    9798        virtual void visit( GenericExpr * genExpr ) = 0;
    9899
  • src/tests/.gitignore

    re04aec4 rdb4062d  
    11.out/
    22.err/
     3.type
  • src/tests/Makefile.am

    re04aec4 rdb4062d  
    2828DEBUG_FLAGS =
    2929
    30 BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@
     30BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ -I.
    3131if !BUILD_DEBUG
    3232BUILD_FLAGS += -nodebug
  • src/tests/Makefile.in

    re04aec4 rdb4062d  
    309309# applies to both programs
    310310DEBUG_FLAGS =
    311 BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ \
     311BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ -I. \
    312312        $(am__append_1) $(am__append_2) $(am__append_3)
    313313TEST_FLAGS = $(if $(test), 2> $(test), )
  • src/tests/concurrent/coroutineYield.c

    re04aec4 rdb4062d  
    44#include <thread>
    55#include <time>
     6
     7#define __kick_rate 150000ul
     8#include "long_tests.h"
    69
    710#ifndef PREEMPTION_RATE
     
    1316}
    1417
    15 #ifdef LONG_TEST
     18#ifdef TEST_LONG
    1619static const unsigned long N = 600_000ul;
    1720#else
     
    2326void main(Coroutine& this) {
    2427        while(true) {
    25                 sout | "Coroutine 1" | endl;
     28                #if !defined(TEST_FOREVER)
     29                        sout | "Coroutine 1" | endl;
     30                #endif
    2631                yield();
    27                 sout | "Coroutine 2" | endl;
     32                #if !defined(TEST_FOREVER)
     33                        sout | "Coroutine 2" | endl;
     34                #endif
    2835                suspend();
    2936        }
     
    3340int main(int argc, char* argv[]) {
    3441        Coroutine c;
    35         for(int i = 0; i < N; i++) {
    36                 sout | "Thread 1" | endl;
     42        for(int i = 0; TEST(i < N); i++) {
     43                #if !defined(TEST_FOREVER)
     44                        sout | "Thread 1" | endl;
     45                #endif
    3746                resume(c);
    38                 sout | "Thread 2" | endl;
     47                #if !defined(TEST_FOREVER)
     48                        sout | "Thread 2" | endl;
     49                #endif
    3950                yield();
     51                KICK_WATCHDOG;
    4052        }
    4153}
  • src/tests/concurrent/preempt.c

    re04aec4 rdb4062d  
    22#include <thread>
    33#include <time>
     4
     5#include "long_tests.h"
    46
    57#ifndef PREEMPTION_RATE
     
    1113}
    1214
    13 #ifdef LONG_TEST
     15#ifdef TEST_LONG
    1416static const unsigned long N = 30_000ul;
    1517#else
     
    3032
    3133void main(worker_t & this) {
    32         while(counter < N) {
     34        while(TEST(counter < N)) {
    3335                __cfaabi_check_preemption();
    3436                if( (counter % 7) == this.value ) {
     
    4042                }
    4143                __cfaabi_check_preemption();
     44                KICK_WATCHDOG;
    4245        }
    4346}
  • src/tests/concurrent/signal/block.c

    re04aec4 rdb4062d  
    1414#include <time>
    1515
     16#include "long_tests.h"
     17
    1618#ifndef PREEMPTION_RATE
    1719#define PREEMPTION_RATE 10`ms
     
    2224}
    2325
    24 #ifdef LONG_TEST
     26#ifdef TEST_LONG
    2527static const unsigned long N = 150_000ul;
    2628#else
     
    6668thread Waiter {};
    6769void main( Waiter & this ) {
    68         for( int i = 0; i < N; i++ ) {
     70        for( int i = 0; TEST(i < N); i++ ) {
    6971                wait_op( globalA, globalB, i );
     72                KICK_WATCHDOG;
    7073        }
    7174}
  • src/tests/concurrent/signal/disjoint.c

    re04aec4 rdb4062d  
    44#include <thread>
    55#include <time>
     6
     7#include "long_tests.h"
    68
    79#ifndef PREEMPTION_RATE
     
    1315}
    1416
    15 #ifdef LONG_TEST
     17#ifdef TEST_LONG
    1618static const unsigned long N = 300_000ul;
    1719#else
     
    6769        }
    6870
    69         d.counter++;
     71        #if !defined(TEST_FOREVER)
     72                d.counter++;
     73                if( (d.counter % 1000) == 0 ) sout | d.counter | endl;
     74        #endif
    7075
    71         if( (d.counter % 1000) == 0 ) sout | d.counter | endl;
    72 
    73         return d.counter < N;
     76        return TEST(d.counter < N);
    7477}
    7578
     
    7780
    7881void main( Waiter & this ) {
    79         while( wait( mut, data ) ) { yield(); }
     82        while( wait( mut, data ) ) { KICK_WATCHDOG; yield(); }
    8083}
    8184
     
    9497
    9598        //This is technically a mutual exclusion violation but the mutex monitor protects us
    96         bool running = data.counter < N && data.counter > 0;
     99        bool running = TEST(data.counter < N) && data.counter > 0;
    97100        if( data.state != SIGNAL && running ) {
    98101                sout | "ERROR Eager signal" | data.state | endl;
  • src/tests/concurrent/signal/wait.c

    re04aec4 rdb4062d  
    1212#include <time>
    1313
     14#define __kick_rate 12000ul
     15#include "long_tests.h"
     16
    1417#ifndef PREEMPTION_RATE
    1518#define PREEMPTION_RATE 10`ms
     
    2023}
    2124
    22 #ifdef LONG_TEST
     25#ifdef TEST_LONG
    2326static const unsigned long N = 375_000ul;
    2427#else
     
    9093// Waiter ABC
    9194void main( WaiterABC & this ) {
    92         for( int i = 0; i < N; i++ ) {
     95        for( int i = 0; TEST(i < N); i++ ) {
    9396                wait( condABC, globalA, globalB, globalC );
     97                KICK_WATCHDOG;
    9498        }
    9599
     
    100104// Waiter AB
    101105void main( WaiterAB & this ) {
    102         for( int i = 0; i < N; i++ ) {
     106        for( int i = 0; TEST(i < N); i++ ) {
    103107                wait( condAB , globalA, globalB );
     108                KICK_WATCHDOG;
    104109        }
    105110
     
    110115// Waiter AC
    111116void main( WaiterAC & this ) {
    112         for( int i = 0; i < N; i++ ) {
     117        for( int i = 0; TEST(i < N); i++ ) {
    113118                wait( condAC , globalA, globalC );
     119                KICK_WATCHDOG;
    114120        }
    115121
     
    120126// Waiter BC
    121127void main( WaiterBC & this ) {
    122         for( int i = 0; i < N; i++ ) {
     128        for( int i = 0; TEST(i < N); i++ ) {
    123129                wait( condBC , globalB, globalC );
     130                KICK_WATCHDOG;
    124131        }
    125132
  • src/tests/preempt_longrun/Makefile.am

    re04aec4 rdb4062d  
    1919preempt=10ul\`ms
    2020debug=-debug
     21type=LONG
    2122
    2223REPEAT = ${abs_top_srcdir}/tools/repeat
     24WATCHDOG = ${abs_top_srcdir}/tools/watchdog
    2325TIME = /usr/bin/time -f "%E"
    2426
    25 BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ -O2 -DPREEMPTION_RATE=${preempt} -DLONG_TEST
     27# $(shell ./update-type $(type))
     28# ./update-type $(type)
     29
     30UPDATED_TYPE = $(shell ./update-type $(type))
     31
     32BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ -O2 -DPREEMPTION_RATE=${preempt} -I.. -I. -DTEST_$(shell cat .type | tr a-z A-Z)
    2633CFLAGS = ${BUILD_FLAGS}
    2734CC = @CFA_BINDIR@/@CFA_NAME@
     
    2936TESTS = block coroutine create disjoint enter enter3 processor stack wait yield
    3037
    31 .INTERMEDIATE: ${TESTS}
     38# .INTERMEDIATE: ${TESTS}
    3239
    3340all-local: ${TESTS:=.run}
    3441
     42runall : ${TESTS:=.run}
     43        @ echo "All programs terminated normally"
     44
     45watchall : ${TESTS:=.watch}
     46        @ echo "All programs terminated normally"
     47
     48compileall : ${TESTS}
     49        @ echo "Compiled"
     50
    3551clean-local:
    36         rm -f ${TESTS} core* out.log
     52        rm -f ${TESTS} core* out.log .type
    3753
    38 % : %.c ${CC}
     54% : %.c ${CC} ${UPDATED_TYPE}
    3955        ${AM_V_GEN}${CC} ${CFLAGS} ${<} $(debug) -o ${@}
    4056
    4157%.run : % ${REPEAT}
    4258        @ time ${REPEAT} -r out.log -i -s $(repeats) timeout ${max_time} ./${<}
     59        @ rm ${<}
     60        @ echo -e "${<}: SUCCESS\n"
     61
     62%.watch : % ${WATCHDOG}
     63        @ time ${WATCHDOG} ./${<}
    4364        @ rm ${<}
    4465        @ echo -e "${<}: SUCCESS\n"
     
    4970        @ echo -e "${<}: SUCCESS\n"
    5071
    51 ${REPEAT}:
     72${REPEAT}: ${abs_top_srcdir}/tools/Makefile
    5273        @+make -C ${abs_top_srcdir}/tools/
     74
     75${WATCHDOG}: ${abs_top_srcdir}/tools/Makefile
     76        @+make -C ${abs_top_srcdir}/tools/
  • src/tests/preempt_longrun/Makefile.in

    re04aec4 rdb4062d  
    452452preempt = 10ul\`ms
    453453debug = -debug
     454type = LONG
    454455REPEAT = ${abs_top_srcdir}/tools/repeat
     456WATCHDOG = ${abs_top_srcdir}/tools/watchdog
    455457TIME = /usr/bin/time -f "%E"
    456 BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ -O2 -DPREEMPTION_RATE=${preempt} -DLONG_TEST
     458
     459# $(shell ./update-type $(type))
     460# ./update-type $(type)
     461UPDATED_TYPE = $(shell ./update-type $(type))
     462BUILD_FLAGS = -g -Wall -Wno-unused-function -quiet @CFA_FLAGS@ -O2 -DPREEMPTION_RATE=${preempt} -I.. -I. -DTEST_$(shell cat .type | tr a-z A-Z)
    457463TESTS = block coroutine create disjoint enter enter3 processor stack wait yield
    458464all: all-am
     
    873879
    874880
    875 .INTERMEDIATE: ${TESTS}
     881# .INTERMEDIATE: ${TESTS}
    876882
    877883all-local: ${TESTS:=.run}
    878884
     885runall : ${TESTS:=.run}
     886        @ echo "All programs terminated normally"
     887
     888watchall : ${TESTS:=.watch}
     889        @ echo "All programs terminated normally"
     890
     891compileall : ${TESTS}
     892        @ echo "Compiled"
     893
    879894clean-local:
    880         rm -f ${TESTS} core* out.log
    881 
    882 % : %.c ${CC}
     895        rm -f ${TESTS} core* out.log .type
     896
     897% : %.c ${CC} ${UPDATED_TYPE}
    883898        ${AM_V_GEN}${CC} ${CFLAGS} ${<} $(debug) -o ${@}
    884899
     
    888903        @ echo -e "${<}: SUCCESS\n"
    889904
     905%.watch : % ${WATCHDOG}
     906        @ time ${WATCHDOG} ./${<}
     907        @ rm ${<}
     908        @ echo -e "${<}: SUCCESS\n"
     909
    890910%.time : % ${REPEAT}
    891911        @ ${REPEAT} -i -s -- $(repeats) $(TIME) -a -o times.log ./${<}
     
    893913        @ echo -e "${<}: SUCCESS\n"
    894914
    895 ${REPEAT}:
     915${REPEAT}: ${abs_top_srcdir}/tools/Makefile
     916        @+make -C ${abs_top_srcdir}/tools/
     917
     918${WATCHDOG}: ${abs_top_srcdir}/tools/Makefile
    896919        @+make -C ${abs_top_srcdir}/tools/
    897920
  • src/tests/preempt_longrun/create.c

    re04aec4 rdb4062d  
    22#include <thread>
    33#include <time>
     4
     5#include "long_tests.h"
    46
    57#ifndef PREEMPTION_RATE
     
    1921int main(int argc, char* argv[]) {
    2022        processor p;
    21         for(int i = 0; i < N; i++) {
     23        for(int i = 0; TEST(i < N); i++) {
    2224                worker_t w[7];
     25                KICK_WATCHDOG;
    2326        }
    2427}
  • src/tests/preempt_longrun/enter.c

    re04aec4 rdb4062d  
    33#include <thread>
    44#include <time>
     5
     6#define __kick_rate 75000ul
     7#include "long_tests.h"
    58
    69#ifndef PREEMPTION_RATE
     
    1518
    1619monitor mon_t {};
    17 void foo( mon_t & mutex this ) {}
     20void foo( mon_t & mutex this ) {
     21        KICK_WATCHDOG;
     22}
    1823
    1924mon_t mon;
    2025thread worker_t {};
    2126void main( worker_t & this ) {
    22         for( unsigned long i = 0; i < N; i++ ) {
     27        for( unsigned long i = 0; TEST(i < N); i++ ) {
    2328                foo( mon );
    2429        }
  • src/tests/preempt_longrun/enter3.c

    re04aec4 rdb4062d  
    33#include <thread>
    44#include <time>
     5
     6#define __kick_rate 75000ul
     7#include "long_tests.h"
    58
    69#ifndef PREEMPTION_RATE
     
    1821mon_t mon1, mon2, mon3;
    1922
    20 void foo( mon_t & mutex a, mon_t & mutex b, mon_t & mutex c ) {}
     23void foo( mon_t & mutex a, mon_t & mutex b, mon_t & mutex c ) {
     24        KICK_WATCHDOG;
     25}
    2126
    2227thread worker_t {};
    2328
    2429void main( worker_t & this ) {
    25         for( unsigned long i = 0; i < N; i++ ) {
     30        for( unsigned long i = 0; TEST(i < N); i++ ) {
    2631                foo( mon1, mon2, mon3 );
    2732        }
  • src/tests/preempt_longrun/processor.c

    re04aec4 rdb4062d  
    44
    55#include <unistd.h>
     6
     7#include "long_tests.h"
    68
    79#ifndef PREEMPTION_RATE
     
    1719int main(int argc, char* argv[]) {
    1820        processor * p[15];
    19         write(STDOUT_FILENO, "Preparing\n", sizeof("Preparing\n"));
    2021        for ( int pi = 0; pi < 15; pi++ ) {
    2122                p[pi] = new();
    2223        }
    23         write(STDOUT_FILENO, "Starting\n", sizeof("Starting\n"));
    24         for ( int i = 0; i < N; i++) {
     24        for ( int i = 0; TEST(i < N); i++) {
    2525                int pi = i % 15;
    2626                delete( p[pi] );
    2727                p[pi] = new();
     28                KICK_WATCHDOG;
    2829        }
    29         write(STDOUT_FILENO, "Stopping\n", sizeof("Stopping\n"));
    3030        for ( int pi = 0; pi < 15; pi++ ) {
    3131                delete( p[pi] );
    3232        }
    33         write(STDOUT_FILENO, "Done\n", sizeof("Done\n"));
    3433}
  • src/tests/preempt_longrun/stack.c

    re04aec4 rdb4062d  
    33#include <thread>
    44#include <time>
     5
     6#define __kick_rate 5000000ul
     7#include "long_tests.h"
    58
    69#ifndef PREEMPTION_RATE
     
    1518
    1619void main(worker_t & this) {
    17         volatile long long p = 5_021_609ul;
    18         volatile long long a = 326_417ul;
    19         volatile long long n = 1l;
    20         for (volatile long long i = 0; i < p; i++) {
    21                 n *= a;
    22                 n %= p;
    23         }
     20        while(TEST(0)) {
     21                volatile long long p = 5_021_609ul;
     22                volatile long long a = 326_417ul;
     23                volatile long long n = 1l;
     24                for (volatile long long i = 0; i < p; i++) {
     25                        n *= a;
     26                        n %= p;
     27                        KICK_WATCHDOG;
     28                }
    2429
    25         if( n != a ) {
    26                 abort();
     30                if( !TEST(n == a) ) {
     31                        abort();
     32                }
    2733        }
    2834}
  • src/tests/preempt_longrun/yield.c

    re04aec4 rdb4062d  
    22#include <thread>
    33#include <time>
     4
     5#define __kick_rate 550000ul
     6#include "long_tests.h"
    47
    58#ifndef PREEMPTION_RATE
     
    1114}
    1215
    13 #ifdef LONG_TEST
     16#ifdef TEST_LONG
    1417static const unsigned long N = 9_750_000ul;
    1518#else
     
    2023
    2124void main(worker_t & this) {
    22         for(int i = 0; i < N; i++) {
     25        for(int i = 0; TEST(i < N); i++) {
    2326                yield();
     27                KICK_WATCHDOG;
    2428        }
    2529}
  • tools/Makefile.am

    re04aec4 rdb4062d  
    1818CFLAGS = -Wall -Wextra -O2 -g
    1919
    20 noinst_PROGRAMS = busy catchsig repeat
     20noinst_PROGRAMS = busy catchsig repeat watchdog
    2121
    2222busy_SOURCES     = busy.c
     
    2424catchsig_SOURCES = catchsig.c
    2525repeat_SOURCES   = repeat.c
     26watchdog_SOURCES = watchdog.c
  • tools/Makefile.in

    re04aec4 rdb4062d  
    9292build_triplet = @build@
    9393host_triplet = @host@
    94 noinst_PROGRAMS = busy$(EXEEXT) catchsig$(EXEEXT) repeat$(EXEEXT)
     94noinst_PROGRAMS = busy$(EXEEXT) catchsig$(EXEEXT) repeat$(EXEEXT) \
     95        watchdog$(EXEEXT)
    9596subdir = tools
    9697ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
     
    115116repeat_OBJECTS = $(am_repeat_OBJECTS)
    116117repeat_LDADD = $(LDADD)
     118am_watchdog_OBJECTS = watchdog.$(OBJEXT)
     119watchdog_OBJECTS = $(am_watchdog_OBJECTS)
     120watchdog_LDADD = $(LDADD)
    117121AM_V_P = $(am__v_P_@AM_V@)
    118122am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
     
    143147am__v_CCLD_0 = @echo "  CCLD    " $@;
    144148am__v_CCLD_1 =
    145 SOURCES = $(busy_SOURCES) $(catchsig_SOURCES) $(repeat_SOURCES)
    146 DIST_SOURCES = $(busy_SOURCES) $(catchsig_SOURCES) $(repeat_SOURCES)
     149SOURCES = $(busy_SOURCES) $(catchsig_SOURCES) $(repeat_SOURCES) \
     150        $(watchdog_SOURCES)
     151DIST_SOURCES = $(busy_SOURCES) $(catchsig_SOURCES) $(repeat_SOURCES) \
     152        $(watchdog_SOURCES)
    147153am__can_run_installinfo = \
    148154  case $$AM_UPDATE_INFO_DIR in \
     
    295301catchsig_SOURCES = catchsig.c
    296302repeat_SOURCES = repeat.c
     303watchdog_SOURCES = watchdog.c
    297304all: all-am
    298305
     
    344351        $(AM_V_CCLD)$(LINK) $(repeat_OBJECTS) $(repeat_LDADD) $(LIBS)
    345352
     353watchdog$(EXEEXT): $(watchdog_OBJECTS) $(watchdog_DEPENDENCIES) $(EXTRA_watchdog_DEPENDENCIES)
     354        @rm -f watchdog$(EXEEXT)
     355        $(AM_V_CCLD)$(LINK) $(watchdog_OBJECTS) $(watchdog_LDADD) $(LIBS)
     356
    346357mostlyclean-compile:
    347358        -rm -f *.$(OBJEXT)
     
    353364@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/catchsig.Po@am__quote@
    354365@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/repeat.Po@am__quote@
     366@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/watchdog.Po@am__quote@
    355367
    356368.c.o:
Note: See TracChangeset for help on using the changeset viewer.