Ignore:
Timestamp:
Mar 4, 2021, 7:40:25 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
77d601f
Parents:
342af53 (diff), a5040fe (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.hfa

    r342af53 r8e4aa05  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Dec 12 13:52:34 2020
    13 // Update Count     : 536
     12// Last Modified On : Thu Jan 21 22:02:13 2021
     13// Update Count     : 574
    1414//
    1515
     
    4848        else return (T *)alignment( _Alignof(T), dim, sizeof(T) )
    4949
    50 static inline forall( dtype T | sized(T) ) {
     50static inline forall( T & | sized(T) ) {
    5151        // CFA safe equivalents, i.e., implicit size specification
    5252
     
    108108
    109109        1. Replace the current forall-block that contains defintions of S_fill and S_realloc with following:
    110                 forall( dtype T | sized(T) ) {
     110                forall( T & | sized(T) ) {
    111111                        union  U_fill           { char c; T * a; T t; };
    112112                        struct S_fill           { char tag; U_fill(T) fill; };
     
    151151typedef struct S_resize                 { inline void *;  }     T_resize;
    152152
    153 forall( dtype T ) {
     153forall( T & ) {
    154154        struct S_fill           { char tag; char c; size_t size; T * at; char t[50]; };
    155155        struct S_realloc        { inline T *; };
     
    159159static inline T_resize  ?`resize  ( void * a )  { return (T_resize){a}; }
    160160
    161 static inline forall( dtype T | sized(T) ) {
     161static inline forall( T & | sized(T) ) {
    162162        S_fill(T) ?`fill ( T t ) {
    163163                S_fill(T) ret = { 't' };
    164164                size_t size = sizeof(T);
    165                 if(size > sizeof(ret.t)) { printf("ERROR: const object of size greater than 50 bytes given for dynamic memory fill\n"); exit(1); }
     165                if ( size > sizeof(ret.t) ) {
     166                        abort( "ERROR: const object of size greater than 50 bytes given for dynamic memory fill\n" );
     167                } // if
    166168                memcpy( &ret.t, &t, size );
    167169                return ret;
     
    173175        S_realloc(T)    ?`realloc ( T * a )                             { return (S_realloc(T)){a}; }
    174176
    175         T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill) {
     177        T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) {
    176178                T * ptr = NULL;
    177179                size_t size = sizeof(T);
     
    181183                        ptr = (T*) (void *) resize( (void *)Resize, Align, Dim * size );
    182184                } else if ( Realloc ) {
    183                         if (Fill.tag != '0') copy_end = min(malloc_size( Realloc ), Dim * size);
    184                         ptr = (T*) (void *) realloc( (void *)Realloc, Align, Dim * size );
     185                        if ( Fill.tag != '0' ) copy_end = min(malloc_size( Realloc ), Dim * size );
     186                        ptr = (T *) (void *) realloc( (void *)Realloc, Align, Dim * size );
    185187                } else {
    186                         ptr = (T*) (void *) memalign( Align, Dim * size );
    187                 }
    188 
    189                 if(Fill.tag == 'c') {
     188                        ptr = (T *) (void *) memalign( Align, Dim * size );
     189                }
     190
     191                if ( Fill.tag == 'c' ) {
    190192                        memset( (char *)ptr + copy_end, (int)Fill.c, Dim * size - copy_end );
    191                 } else if(Fill.tag == 't') {
     193                } else if ( Fill.tag == 't' ) {
    192194                        for ( int i = copy_end; i < Dim * size; i += size ) {
     195                                #pragma GCC diagnostic push
     196                                #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
     197                                assert( size <= sizeof(Fill.t) );
    193198                                memcpy( (char *)ptr + i, &Fill.t, size );
     199                                #pragma GCC diagnostic pop
    194200                        }
    195                 } else if(Fill.tag == 'a') {
     201                } else if ( Fill.tag == 'a' ) {
    196202                        memcpy( (char *)ptr + copy_end, Fill.at, min(Dim * size - copy_end, Fill.size) );
    197                 } else if(Fill.tag == 'T') {
    198                         for ( int i = copy_end; i < Dim * size; i += size ) {
    199                                 memcpy( (char *)ptr + i, Fill.at, size );
    200                         }
     203                } else if ( Fill.tag == 'T' ) {
     204                        memcpy( (char *)ptr + copy_end, Fill.at, Dim * size );
    201205                }
    202206
     
    204208        } // $alloc_internal
    205209
    206         forall( ttype TT | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
     210        forall( TT... | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
    207211
    208212                T * $alloc_internal( void *       , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) {
     
    233237} // distribution T
    234238
    235 static inline forall( dtype T | sized(T) ) {
     239static inline forall( T & | sized(T) ) {
    236240        // CFA safe initialization/copy, i.e., implicit size specification, non-array types
    237241        T * memset( T * dest, char fill ) {
     
    254258
    255259// CFA deallocation for multiple objects
    256 static inline forall( dtype T )                                                 // FIX ME, problems with 0p in list
     260static inline forall( T & )                                                     // FIX ME, problems with 0p in list
    257261void free( T * ptr ) {
    258262        free( (void *)ptr );                                                            // C free
    259263} // free
    260 static inline forall( dtype T, ttype TT | { void free( TT ); } )
     264static inline forall( T &, TT... | { void free( TT ); } )
    261265void free( T * ptr, TT rest ) {
    262266        free( ptr );
     
    265269
    266270// CFA allocation/deallocation and constructor/destructor, non-array types
    267 static inline forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } )
     271static inline forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } )
    268272T * new( TT p ) {
    269         return &(*(T *)malloc()){ p };                                                  // run constructor
     273        return &(*(T *)malloc()){ p };                                          // run constructor
    270274} // new
    271275
    272 static inline forall( dtype T | { void ^?{}( T & ); } )
     276static inline forall( T & | { void ^?{}( T & ); } )
    273277void delete( T * ptr ) {
    274278        // special case for 0-sized object => always call destructor
     
    278282        free( ptr );                                                                            // always call free
    279283} // delete
    280 static inline forall( dtype T, ttype TT | { void ^?{}( T & ); void delete( TT ); } )
     284static inline forall( T &, TT... | { void ^?{}( T & ); void delete( TT ); } )
    281285void delete( T * ptr, TT rest ) {
    282286        delete( ptr );
     
    285289
    286290// CFA allocation/deallocation and constructor/destructor, array types
    287 forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );
    288 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );
    289 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT | { void adelete( TT ); } ) void adelete( T arr[], TT rest );
     291forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );
     292forall( T & | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );
     293forall( T & | sized(T) | { void ^?{}( T & ); }, TT... | { void adelete( TT ); } ) void adelete( T arr[], TT rest );
    290294
    291295//---------------------------------------
     
    327331//---------------------------------------
    328332
    329 forall( otype E | { int ?<?( E, E ); } ) {
     333forall( E | { int ?<?( E, E ); } ) {
    330334        E * bsearch( E key, const E * vals, size_t dim );
    331335        size_t bsearch( E key, const E * vals, size_t dim );
     
    336340} // distribution
    337341
    338 forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } ) {
     342forall( K, E | { int ?<?( K, K ); K getKey( const E & ); } ) {
    339343        E * bsearch( K key, const E * vals, size_t dim );
    340344        size_t bsearch( K key, const E * vals, size_t dim );
     
    345349} // distribution
    346350
    347 forall( otype E | { int ?<?( E, E ); } ) {
     351forall( E | { int ?<?( E, E ); } ) {
    348352        void qsort( E * vals, size_t dim );
    349353} // distribution
Note: See TracChangeset for help on using the changeset viewer.