Changeset 7951100 for src


Ignore:
Timestamp:
Jun 7, 2018, 4:40:05 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b067d9b
Parents:
b4e1876 (diff), 08b5a7e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

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

Location:
src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • src/Common/SemanticError.cc

    rb4e1876 r7951100  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 16 15:01:20 2018
    13 // Update Count     : 9
     12// Last Modified On : Thu Jun  7 08:05:26 2018
     13// Update Count     : 10
    1414//
    1515
     
    9797void SemanticError( CodeLocation location, std::string error ) {
    9898        SemanticErrorThrow = true;
    99         throw SemanticErrorException(location, error);
     99        throw SemanticErrorException( location, error );
    100100}
    101101
  • src/Parser/DeclarationNode.cc

    rb4e1876 r7951100  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun  6 15:57:50 2018
    13 // Update Count     : 1076
     12// Last Modified On : Thu Jun  7 12:08:55 2018
     13// Update Count     : 1079
    1414//
    1515
     
    545545                                        type->aggregate.params->appendList( q->type->forall ); // augment forall qualifier
    546546                                } else {                                                                // not polymorphic
    547                                         type->aggregate.params = q->type->forall; // make polymorphic type
    548                                         // change implicit typedef from TYPEDEFname to TYPEGENname
    549                                         typedefTable.changeKind( *type->aggregate.name, TYPEGENname );
     547                                        type->aggregate.params = q->type->forall; // set forall qualifier
    550548                                } // if
    551549                        } else {                                                                        // not polymorphic
  • src/Parser/TypedefTable.cc

    rb4e1876 r7951100  
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun  1 16:54:18 2018
    13 // Update Count     : 155
     12// Last Modified On : Thu Jun  7 13:17:56 2018
     13// Update Count     : 192
    1414//
    1515
     
    1717#include "TypedefTable.h"
    1818#include <cassert>                                                                              // for assert
     19#include <iostream>
    1920
    2021#if 0
    21 #include <iostream>
    2222#define debugPrint( code ) code
    2323#else
     
    2727using namespace std;                                                                    // string, iostream
    2828
     29debugPrint(
     30static const char *kindName( int kind ) {
     31        switch ( kind ) {
     32          case IDENTIFIER: return "identifier";
     33          case TYPEDEFname: return "typedef";
     34          case TYPEGENname: return "typegen";
     35          default:
     36                cerr << "Error: cfa-cpp internal error, invalid kind of identifier" << endl;
     37                abort();
     38        } // switch
     39} // kindName
     40)
     41
    2942TypedefTable::~TypedefTable() {
    3043        if ( ! SemanticErrorThrow && kindTable.currentScope() != 0 ) {
    31                 std::cerr << "scope failure " << kindTable.currentScope() << endl;
     44                cerr << "Error: cfa-cpp internal error, scope failure " << kindTable.currentScope() << endl;
     45                abort();
    3246        } // if
    3347} // TypedefTable::~TypedefTable
     
    4458} // TypedefTable::isKind
    4559
    46 void TypedefTable::changeKind( const string & identifier, int kind ) {
    47         KindTable::iterator posn = kindTable.find( identifier );
    48         if ( posn != kindTable.end() ) posn->second = kind;     // exists => update
    49 } // TypedefTable::changeKind
    50 
    5160// SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by
    5261// "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed if the
    5362// name is explicitly used.
    54 void TypedefTable::makeTypedef( const string & name ) {
     63void TypedefTable::makeTypedef( const string & name, int kind ) {
     64//    Check for existence is necessary to handle:
     65//        struct Fred {};
     66//        void Fred();
     67//        void fred() {
     68//           struct Fred act; // do not add as type in this scope
     69//           Fred();
     70//        }
    5571        if ( ! typedefTable.exists( name ) ) {
    56                 typedefTable.addToEnclosingScope( name, TYPEDEFname, "MTD" );
     72                typedefTable.addToEnclosingScope( name, kind, "MTD" );
    5773        } // if
    5874} // TypedefTable::makeTypedef
    5975
    60 void TypedefTable::addToScope( const std::string & identifier, int kind, const char * locn __attribute__((unused)) ) {
     76void TypedefTable::addToScope( const string & identifier, int kind, const char * locn __attribute__((unused)) ) {
    6177        auto scope = kindTable.currentScope();
    62         debugPrint( cerr << "Adding at " << locn << " " << identifier << " as kind " << kind << " scope " << scope << endl );
     78        debugPrint( cerr << "Adding current at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl );
    6379        auto ret = kindTable.insertAt( scope, identifier, kind );
    6480        if ( ! ret.second ) ret.first->second = kind;           // exists => update
    6581} // TypedefTable::addToScope
    6682
    67 void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind, const char * locn __attribute__((unused)) ) {
     83void TypedefTable::addToEnclosingScope( const string & identifier, int kind, const char * locn __attribute__((unused)) ) {
    6884        assert( kindTable.currentScope() >= 1 );
    6985        auto scope = kindTable.currentScope() - 1;
    70         debugPrint( cerr << "Adding+1 at " << locn << " " << identifier << " as kind " << kind << " scope " << scope << endl );
     86        debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl );
    7187        auto ret = kindTable.insertAt( scope, identifier, kind );
    7288        if ( ! ret.second ) ret.first->second = kind;           // exists => update
     
    93109                        debugPrint( cerr << endl << "[" << scope << "]" );
    94110                } // while
    95                 debugPrint( cerr << " " << (*i).first << ":" << (*i).second );
     111                debugPrint( cerr << " " << (*i).first << ":" << kindName( (*i).second ) );
    96112        } // for
    97113        while ( scope > 0 ) {
  • src/Parser/TypedefTable.h

    rb4e1876 r7951100  
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu May 31 23:23:47 2018
    13 // Update Count     : 83
     12// Last Modified On : Thu Jun  7 12:10:17 2018
     13// Update Count     : 85
    1414//
    1515
     
    3030        bool exists( const std::string & identifier );
    3131        int isKind( const std::string & identifier ) const;
    32         void changeKind( const std::string & identifier, int kind );
    33         void makeTypedef( const std::string & name );
     32        void makeTypedef( const std::string & name, int kind = TYPEDEFname );
    3433        void addToScope( const std::string & identifier, int kind, const char * );
    3534        void addToEnclosingScope( const std::string & identifier, int kind, const char * );
  • src/Parser/lex.ll

    rb4e1876 r7951100  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Wed Jun  6 17:31:09 2018
    13  * Update Count     : 677
     12 * Last Modified On : Thu Jun  7 08:27:40 2018
     13 * Update Count     : 679
    1414 */
    1515
     
    452452
    453453%%
     454
    454455// ----end of lexer----
    455456
    456457void yyerror( const char * errmsg ) {
     458        SemanticErrorThrow = true;
    457459        cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1
    458460                 << ": " << ErrorHelpers::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl;
  • src/Parser/parser.yy

    rb4e1876 r7951100  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun  6 14:53:38 2018
    13 // Update Count     : 3522
     12// Last Modified On : Thu Jun  7 10:07:12 2018
     13// Update Count     : 3527
    1414//
    1515
     
    18261826        | aggregate_key attribute_list_opt no_attr_identifier
    18271827                {
    1828                         typedefTable.makeTypedef( *$3 );                        // create typedef
    1829                         if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
     1828                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     1829                        //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18301830                        forall = false;                                                         // reset
    18311831                }
     
    18341834        | aggregate_key attribute_list_opt type_name
    18351835                {
    1836                         typedefTable.makeTypedef( *$3->type->symbolic.name ); // create typedef
    1837                         if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update
     1836                        typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     1837                        //if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update
    18381838                        forall = false;                                                         // reset
    18391839                }
     
    18481848        aggregate_key attribute_list_opt no_attr_identifier
    18491849                {
    1850                         typedefTable.makeTypedef( *$3 );
    1851                         if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
     1850                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname );
     1851                        //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18521852                        forall = false;                                                         // reset
    18531853                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
     
    32643264
    32653265%%
     3266
    32663267// ----end of grammar----
    32673268
  • src/libcfa/bits/locks.h

    rb4e1876 r7951100  
    1818#include "bits/debug.h"
    1919#include "bits/defs.h"
     20#include <assert.h>
     21
     22#ifdef __cforall
     23        extern "C" {
     24                #include <pthread.h>
     25        }
     26#endif
    2027
    2128// pause to prevent excess processor bus usage
     
    112119                __atomic_clear( &this.lock, __ATOMIC_RELEASE );
    113120        }
     121
     122
     123        #ifdef __CFA_WITH_VERIFY__
     124                extern bool __cfaabi_dbg_in_kernel();
     125        #endif
     126
     127        struct __bin_sem_t {
     128                int_fast8_t     counter;
     129                pthread_mutex_t lock;
     130                pthread_cond_t  cond;
     131        };
     132
     133        static inline void ?{}(__bin_sem_t & this) with( this ) {
     134                counter = 0;
     135                pthread_mutex_init(&lock, NULL);
     136                pthread_cond_init (&cond, NULL);
     137        }
     138
     139        static inline void ^?{}(__bin_sem_t & this) with( this ) {
     140                pthread_mutex_destroy(&lock);
     141                pthread_cond_destroy (&cond);
     142        }
     143
     144        static inline void wait(__bin_sem_t & this) with( this ) {
     145                verify(__cfaabi_dbg_in_kernel());
     146                pthread_mutex_lock(&lock);
     147                if(counter != 0) {   // this must be a loop, not if!
     148                        pthread_cond_wait(&cond, &lock);
     149                }
     150                counter = 1;
     151                pthread_mutex_unlock(&lock);
     152        }
     153
     154        static inline void post(__bin_sem_t & this) with( this ) {
     155                verify(__cfaabi_dbg_in_kernel());
     156                pthread_mutex_lock(&lock);
     157                bool needs_signal = counter == 0;
     158                counter = 1;
     159                pthread_mutex_unlock(&lock);
     160                if (!needs_signal)
     161                        pthread_cond_signal(&cond);
     162                }
    114163#endif
  • src/libcfa/concurrency/kernel

    rb4e1876 r7951100  
    133133        // Idle lock
    134134        sem_t idleLock;
     135        // __bin_sem_t idleLock;
    135136
    136137        // Link lists fields
    137         struct {
     138        struct __dbg_node_proc {
    138139                struct processor * next;
    139140                struct processor * prev;
     
    182183
    183184        // Link lists fields
    184         struct {
     185        struct __dbg_node_cltr {
    185186                cluster * next;
    186187                cluster * prev;
  • src/libcfa/concurrency/kernel.c

    rb4e1876 r7951100  
    1717#include <stddef.h>
    1818#include <errno.h>
     19#include <string.h>
    1920extern "C" {
    2021#include <stdio.h>
     
    5051thread_desc * mainThread;
    5152
    52 struct { __dllist_t(cluster) list; __spinlock_t lock; } global_clusters;
     53extern "C" {
     54struct { __dllist_t(cluster) list; __spinlock_t lock; } __cfa_dbg_global_clusters;
     55}
    5356
    5457//-----------------------------------------------------------------------------
     
    150153
    151154void ^?{}(processor & this) with( this ){
    152         if( ! do_terminate ) {
     155        if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) {
    153156                __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);
    154157                terminate(&this);
    155                 verify(this.do_terminate);
     158                verify( __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
    156159                verify( kernelTLS.this_processor != &this);
    157160                P( terminated );
     
    199202
    200203                thread_desc * readyThread = NULL;
    201                 for( unsigned int spin_count = 0; ! this->do_terminate; spin_count++ )
     204                for( unsigned int spin_count = 0; ! __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST); spin_count++ )
    202205                {
    203206                        readyThread = nextThread( this->cltr );
     
    218221                        else
    219222                        {
    220                                 spin(this, &spin_count);
     223                                // spin(this, &spin_count);
     224                                halt(this);
    221225                        }
    222226                }
     
    545549        __cfaabi_dbg_print_safe("Kernel : Starting\n");
    546550
    547         global_clusters.list{ __get };
    548         global_clusters.lock{};
     551        __cfa_dbg_global_clusters.list{ __get };
     552        __cfa_dbg_global_clusters.lock{};
    549553
    550554        // Initialize the main cluster
     
    627631        // When its coroutine terminates, it return control to the mainThread
    628632        // which is currently here
    629         mainProcessor->do_terminate = true;
     633        __atomic_store_n(&mainProcessor->do_terminate, true, __ATOMIC_RELEASE);
    630634        returnToKernel();
     635        mainThread->self_cor.state = Halted;
    631636
    632637        // THE SYSTEM IS NOW COMPLETELY STOPPED
     
    644649        ^(mainThread){};
    645650
    646         ^(global_clusters.list){};
    647         ^(global_clusters.lock){};
     651        ^(__cfa_dbg_global_clusters.list){};
     652        ^(__cfa_dbg_global_clusters.lock){};
    648653
    649654        __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n");
     
    655660
    656661void halt(processor * this) with( *this ) {
     662        verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
     663
    657664        with( *cltr ) {
    658665                lock      (proc_list_lock __cfaabi_dbg_ctx2);
     
    664671        __cfaabi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this);
    665672
    666         verify( ({int sval = 0; sem_getvalue(&this->idleLock, &sval); sval; }) < 200);
     673        // #ifdef __CFA_WITH_VERIFY__
     674        //      int sval = 0;
     675        //      sem_getvalue(&this->idleLock, &sval);
     676        //      verifyf(sval < 200, "Binary semaphore reached value %d : \n", sval);
     677        // #endif
     678
     679        verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
    667680        int __attribute__((unused)) ret = sem_wait(&idleLock);
    668         verify(ret > 0 || errno == EINTR);
     681        // verifyf(ret >= 0 || errno == EINTR, "Sem_wait returned %d (errno %d : %s\n", ret, errno, strerror(errno));
     682
     683        // wait( idleLock );
    669684
    670685        __cfaabi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this);
     
    681696        __cfaabi_dbg_print_safe("Kernel : Waking up processor %p\n", this);
    682697        int __attribute__((unused)) ret = sem_post(&this->idleLock);
    683         verify(ret > 0 || errno == EINTR);
    684         verify( ({int sval = 0; sem_getvalue(&this->idleLock, &sval); sval; }) < 200);
     698        // verifyf(ret >= 0 || errno == EINTR, "Sem_post returned %d (errno %d : %s\n", ret, errno, strerror(errno));
     699
     700        // #ifdef __CFA_WITH_VERIFY__
     701        //      int sval = 0;
     702        //      sem_getvalue(&this->idleLock, &sval);
     703        //      verifyf(sval < 200, "Binary semaphore reached value %d\n", sval);
     704        // #endif
     705
     706        // post( this->idleLock );
    685707}
    686708
     
    798820// Global Queues
    799821void doregister( cluster     & cltr ) {
    800         lock      ( global_clusters.lock __cfaabi_dbg_ctx2);
    801         push_front( global_clusters.list, cltr );
    802         unlock    ( global_clusters.lock );
     822        lock      ( __cfa_dbg_global_clusters.lock __cfaabi_dbg_ctx2);
     823        push_front( __cfa_dbg_global_clusters.list, cltr );
     824        unlock    ( __cfa_dbg_global_clusters.lock );
    803825}
    804826
    805827void unregister( cluster     & cltr ) {
    806         lock  ( global_clusters.lock __cfaabi_dbg_ctx2);
    807         remove( global_clusters.list, cltr );
    808         unlock( global_clusters.lock );
     828        lock  ( __cfa_dbg_global_clusters.lock __cfaabi_dbg_ctx2);
     829        remove( __cfa_dbg_global_clusters.list, cltr );
     830        unlock( __cfa_dbg_global_clusters.lock );
    809831}
    810832
  • src/libcfa/concurrency/preemption.c

    rb4e1876 r7951100  
    265265// kill wrapper : signal a processor
    266266void terminate(processor * this) {
    267         this->do_terminate = true;
    268         wake(this);
     267        disable_interrupts();
     268        __atomic_store_n(&this->do_terminate, true, __ATOMIC_SEQ_CST);
     269        wake( this );
    269270        sigval_t value = { PREEMPT_TERMINATE };
     271        enable_interrupts( __cfaabi_dbg_ctx );
    270272        pthread_sigqueue( this->kernel_thread, SIGUSR1, value );
    271273}
     
    369371        choose(sfp->si_value.sival_int) {
    370372                case PREEMPT_NORMAL   : ;// Normal case, nothing to do here
    371                 case PREEMPT_TERMINATE: verify( kernelTLS.this_processor->do_terminate);
     373                case PREEMPT_TERMINATE: verify( __atomic_load_n( &kernelTLS.this_processor->do_terminate, __ATOMIC_SEQ_CST ) );
    372374                default:
    373375                        abort( "internal error, signal value is %d", sfp->si_value.sival_int );
     
    488490}
    489491
     492#ifdef __CFA_WITH_VERIFY__
     493bool __cfaabi_dbg_in_kernel() {
     494        return !kernelTLS.preemption_state.enabled;
     495}
     496#endif
     497
    490498// Local Variables: //
    491499// mode: c //
  • src/libcfa/stdhdr/assert.h

    rb4e1876 r7951100  
    3333        #define verify(x) assert(x)
    3434        #define verifyf(x, ...) assertf(x, __VA_ARGS__)
     35        #define __CFA_WITH_VERIFY__
    3536#else
    3637        #define verify(x)
  • src/prelude/sync-builtins.cf

    rb4e1876 r7951100  
    248248#endif
    249249
     250_Bool __atomic_load_n(const volatile _Bool *, int);
     251void __atomic_load(const volatile _Bool *, volatile _Bool *, int);
    250252char __atomic_load_n(const volatile char *, int);
    251253char __atomic_load_1(const volatile char *, int);
     
    285287
    286288void __atomic_store_n(volatile _Bool *, _Bool, int);
    287 void __atomic_store_1(volatile _Bool *, _Bool, int);
    288289void __atomic_store(volatile _Bool *, _Bool *, int);
    289290void __atomic_store_n(volatile char *, char, int);
  • src/tests/preempt_longrun/processor.c

    rb4e1876 r7951100  
    22#include <thread>
    33#include <time>
     4
     5#include <unistd.h>
    46
    57#ifndef PREEMPTION_RATE
     
    1517int main(int argc, char* argv[]) {
    1618        processor * p[15];
     19        write(STDERR_FILENO, "Preparing\n", sizeof("Preparing\n"));
    1720        for ( int pi = 0; pi < 15; pi++ ) {
    1821                p[pi] = new();
    1922        }
     23        write(STDERR_FILENO, "Starting\n", sizeof("Starting\n"));
    2024        for ( int i = 0; i < N; i++) {
    2125                int pi = i % 15;
     
    2327                p[pi] = new();
    2428        }
     29        write(STDERR_FILENO, "Stopping\n", sizeof("Stopping\n"));
    2530        for ( int pi = 0; pi < 15; pi++ ) {
    2631                delete( p[pi] );
    2732        }
     33        write(STDERR_FILENO, "Done\n", sizeof("Done\n"));
    2834}
Note: See TracChangeset for help on using the changeset viewer.