Changes in / [83b52f1:6130304]
- Files:
-
- 1 deleted
- 20 edited
-
libcfa/src/heap.cfa (modified) (10 diffs)
-
libcfa/src/stdlib.hfa (modified) (5 diffs)
-
src/InitTweak/InitTweak.cc (modified) (2 diffs)
-
src/InitTweak/InitTweak.h (modified) (2 diffs)
-
src/ResolvExpr/Alternative.h (modified) (1 diff)
-
src/ResolvExpr/FindOpenVars.cc (modified) (9 diffs)
-
src/ResolvExpr/FindOpenVars.h (modified) (1 diff)
-
src/ResolvExpr/Occurs.cc (modified) (3 diffs)
-
src/ResolvExpr/ResolveAssertions.cc (modified) (1 diff)
-
src/ResolvExpr/TypeEnvironment.cc (modified) (7 diffs)
-
src/ResolvExpr/TypeEnvironment.h (modified) (9 diffs)
-
src/ResolvExpr/typeops.h (modified) (2 diffs)
-
src/SynTree/Type.cc (modified) (2 diffs)
-
src/SynTree/Type.h (modified) (2 diffs)
-
src/Tuples/TupleExpansion.cc (modified) (6 diffs)
-
src/Tuples/Tuples.h (modified) (1 diff)
-
tests/.expect/copyfile.txt (modified) (1 diff)
-
tests/.expect/heap.txt (deleted)
-
tests/.in/copyfile.txt (modified) (1 diff)
-
tests/copyfile.cfa (modified) (1 diff)
-
tests/heap.cfa (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/heap.cfa
r83b52f1 r6130304 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Jul 23 14:13:13201913 // Update Count : 5 4912 // Last Modified On : Thu May 9 16:29:12 2019 13 // Update Count : 516 14 14 // 15 15 … … 31 31 32 32 33 enum { 34 __CFA_DEFAULT_MMAP_START__ = (512 * 1024 + 1), 35 __CFA_DEFAULT_HEAP_EXPANSION__ = (1 * 1024 * 1024), 36 }; 37 38 size_t default_mmap_start() __attribute__(( weak )) { 39 return __CFA_DEFAULT_MMAP_START__; 40 } // default_mmap_start 41 42 size_t default_heap_expansion() __attribute__(( weak )) { 43 return __CFA_DEFAULT_HEAP_EXPANSION__; 44 } // default_heap_expansion 45 46 47 // supported mallopt options 48 #ifndef M_MMAP_THRESHOLD 49 #define M_MMAP_THRESHOLD (-1) 50 #endif // M_TOP_PAD 51 #ifndef M_TOP_PAD 52 #define M_TOP_PAD (-2) 53 #endif // M_TOP_PAD 54 55 #define FASTLOOKUP 56 #define __STATISTICS__ 57 58 #define SPINLOCK 0 59 #define LOCKFREE 1 60 #define BUCKETLOCK SPINLOCK 61 #if BUCKETLOCK == LOCKFREE 62 #include <uStackLF.h> 63 #endif // LOCKFREE 64 65 // #comment TD : This defined is significantly different from the __ALIGN__ define from locks.hfa 66 #define ALIGN 16 67 68 // enum { NoBucketSizes = 93, // number of buckets sizes 69 // #ifdef FASTLOOKUP 70 // LookupSizes = 65536, // number of fast lookup sizes 71 // #endif // FASTLOOKUP 72 // }; 73 #define NoBucketSizes 93 // number of buckets sizes 74 #ifdef FASTLOOKUP 75 #define LookupSizes 65536 // number of fast lookup sizes 76 #endif // FASTLOOKUP 77 78 33 79 static bool traceHeap = false; 34 80 … … 86 132 // return temp; 87 133 // } // traceHeapTermOff 88 89 90 enum {91 __CFA_DEFAULT_MMAP_START__ = (512 * 1024 + 1),92 __CFA_DEFAULT_HEAP_EXPANSION__ = (1 * 1024 * 1024),93 };94 95 size_t default_mmap_start() __attribute__(( weak )) {96 return __CFA_DEFAULT_MMAP_START__;97 } // default_mmap_start98 99 size_t default_heap_expansion() __attribute__(( weak )) {100 return __CFA_DEFAULT_HEAP_EXPANSION__;101 } // default_heap_expansion102 134 103 135 … … 128 160 #endif // __CFA_DEBUG__ 129 161 130 // statically allocated variables => zero filled.131 static size_t pageSize; // architecture pagesize132 static size_t heapExpand; // sbrk advance133 static size_t mmapStart; // cross over point for mmap134 static unsigned int maxBucketsUsed; // maximum number of buckets in use135 136 137 // #comment TD : This defined is significantly different from the __ALIGN__ define from locks.hfa138 #define ALIGN 16139 140 #define SPINLOCK 0141 #define LOCKFREE 1142 #define BUCKETLOCK SPINLOCK143 #if BUCKETLOCK == LOCKFREE144 #include <uStackLF.h>145 #endif // LOCKFREE146 147 // Recursive definitions: HeapManager needs size of bucket array and bucket area needs sizeof HeapManager storage.148 // Break recusion by hardcoding number of buckets and statically checking number is correct after bucket array defined.149 enum { NoBucketSizes = 93 }; // number of buckets sizes150 162 151 163 struct HeapManager { … … 222 234 }; // HeapManager 223 235 236 224 237 static inline size_t getKey( const HeapManager.FreeHeader & freeheader ) { return freeheader.blockSize; } 225 238 226 227 #define FASTLOOKUP 228 #define __STATISTICS__ 239 // statically allocated variables => zero filled. 240 static size_t pageSize; // architecture pagesize 241 static size_t heapExpand; // sbrk advance 242 static size_t mmapStart; // cross over point for mmap 243 static unsigned int maxBucketsUsed; // maximum number of buckets in use 229 244 230 245 // Powers of 2 are common allocation sizes, so make powers of 2 generate the minimum required size. 231 static const unsigned int bucketSizes[ ] @= {// different bucket sizes246 static const unsigned int bucketSizes[NoBucketSizes] @= { // different bucket sizes 232 247 16, 32, 48, 64, 233 248 64 + sizeof(HeapManager.Storage), 96, 112, 128, 128 + sizeof(HeapManager.Storage), 160, 192, 224, … … 244 259 4_194_304 + sizeof(HeapManager.Storage) 245 260 }; 246 247 static_assert( NoBucketSizes == sizeof(bucketSizes) / sizeof(bucketSizes[0]), "size of bucket array wrong" );248 249 261 #ifdef FASTLOOKUP 250 static_assert( 16 == sizeof(HeapManager.Storage), "size of HeapManager Storage wrong" ); // FIX ME251 enum { LookupSizes = 65_536 + 16 }; // number of fast lookup sizes252 262 static unsigned char lookup[LookupSizes]; // O(1) lookup for small sizes 253 263 #endif // FASTLOOKUP … … 522 532 523 533 524 size_t Bsearchl( unsigned int key, const unsigned int * vals, size_t dim ) {525 size_t l = 0, m, h = dim;526 while ( l < h ) {527 m = (l + h) / 2;528 if ( (unsigned int &)(vals[m]) < key ) { // cast away const529 l = m + 1;530 } else {531 h = m;532 } // if533 } // while534 return l;535 } // Bsearchl536 537 538 534 static inline void * doMalloc( size_t size ) with ( heapManager ) { 539 535 HeapManager.Storage * block; // pointer to new block of storage … … 544 540 size_t tsize = size + sizeof(HeapManager.Storage); 545 541 if ( likely( tsize < mmapStart ) ) { // small size => sbrk 546 size_t posn; 547 #ifdef FASTLOOKUP 548 if ( tsize < LookupSizes ) posn = lookup[tsize]; 549 else 550 #endif // FASTLOOKUP 551 posn = Bsearchl( (unsigned int)tsize, bucketSizes, (size_t)maxBucketsUsed ); 552 HeapManager.FreeHeader * freeElem = &freeLists[posn]; 553 // #ifdef FASTLOOKUP 554 // if ( tsize < LookupSizes ) 555 // freeElem = &freeLists[lookup[tsize]]; 556 // else 557 // #endif // FASTLOOKUP 558 // freeElem = bsearchl( tsize, freeLists, (size_t)maxBucketsUsed ); // binary search 559 // HeapManager.FreeHeader * freeElem = 560 // #ifdef FASTLOOKUP 561 // tsize < LookupSizes ? &freeLists[lookup[tsize]] : 562 // #endif // FASTLOOKUP 563 // bsearchl( tsize, freeLists, (size_t)maxBucketsUsed ); // binary search 542 HeapManager.FreeHeader * freeElem = 543 #ifdef FASTLOOKUP 544 tsize < LookupSizes ? &freeLists[lookup[tsize]] : 545 #endif // FASTLOOKUP 546 bsearchl( tsize, freeLists, (size_t)maxBucketsUsed ); // binary search 564 547 assert( freeElem <= &freeLists[maxBucketsUsed] ); // subscripting error ? 565 548 assert( tsize <= freeElem->blockSize ); // search failure ? … … 764 747 765 748 766 // supported mallopt options767 #ifndef M_MMAP_THRESHOLD768 #define M_MMAP_THRESHOLD (-1)769 #endif // M_TOP_PAD770 #ifndef M_TOP_PAD771 #define M_TOP_PAD (-2)772 #endif // M_TOP_PAD773 774 775 749 extern "C" { 776 750 // The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not … … 869 843 void * area; 870 844 if ( unlikely( alignment != 0 ) ) { // previous request memalign? 871 area = memalign( alignment, size ); // create new a ligned area845 area = memalign( alignment, size ); // create new area 872 846 } else { 873 847 area = mallocNoStats( size ); // create new area -
libcfa/src/stdlib.hfa
r83b52f1 r6130304 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 23 14:14:59201913 // Update Count : 3 7312 // Last Modified On : Wed Apr 24 17:35:43 2019 13 // Update Count : 352 14 14 // 15 15 … … 17 17 18 18 #include "bits/defs.hfa" 19 #include "bits/align.hfa"20 19 21 20 #include <stdlib.h> // *alloc, strto*, ato* 22 23 21 extern "C" { 24 22 void * memalign( size_t align, size_t size ); // malloc.h … … 41 39 42 40 T * malloc( void ) { 43 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 44 else return (T *)memalign( _Alignof(T), sizeof(T) ); 41 return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 45 42 } // malloc 46 43 47 44 T * calloc( size_t dim ) { 48 if ( _Alignof(T) <= libAlign() )return (T *)(void *)calloc( dim, sizeof(T) ); // C calloc 49 else return (T *)cmemalign( _Alignof(T), dim, sizeof(T) ); 45 return (T *)(void *)calloc( dim, sizeof(T) ); // C calloc 50 46 } // calloc 51 47 52 48 T * realloc( T * ptr, size_t size ) { 53 if ( unlikely( ptr == 0 ) ) return malloc();54 49 return (T *)(void *)realloc( (void *)ptr, size ); 55 50 } // realloc … … 71 66 72 67 T * alloc( void ) { 73 return malloc();68 return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 74 69 } // alloc 75 70 76 71 T * alloc( char fill ) { 77 T * ptr; 78 if ( _Alignof(T) <= libAlign() ) ptr = (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 79 else ptr = (T *)memalign( _Alignof(T), sizeof(T) ); 72 T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 80 73 return (T *)memset( ptr, (int)fill, sizeof(T) ); // initialize with fill value 81 74 } // alloc 82 75 83 76 T * alloc( size_t dim ) { 84 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc 85 else return (T *)memalign( _Alignof(T), dim * sizeof(T) ); 77 return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc 86 78 } // alloc 87 79 88 80 T * alloc( size_t dim, char fill ) { 89 return (T *)memset( (T *)alloc( dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value 81 T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C calloc 82 return (T *)memset( ptr, (int)fill, dim * sizeof(T) ); // initialize with fill value 90 83 } // alloc 91 84 92 85 T * alloc( T ptr[], size_t dim ) { 93 return realloc( ptr, dim * sizeof(T) ); 94 } // alloc 95 } // distribution 86 return (T *)(void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc 87 } // alloc 88 } // distribution 89 90 91 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ); 96 92 97 93 … … 111 107 112 108 T * align_alloc( size_t align, size_t dim, char fill ) { 109 T * ptr; 113 110 if ( fill == '\0' ) { 114 return(T *)cmemalign( align, dim, sizeof(T) );111 ptr = (T *)cmemalign( align, dim, sizeof(T) ); 115 112 } else { 116 return (T *)memset( (T *)memalign( align, dim * sizeof(T) ), (int)fill, dim * sizeof(T) ); 113 ptr = (T *)memalign( align, dim * sizeof(T) ); 114 return (T *)memset( ptr, (int)fill, dim * sizeof(T) ); 117 115 } // if 118 } // align_alloc 119 } // distribution 120 121 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ); 116 return ptr; 117 } // align_alloc 118 } // distribution 122 119 123 120 -
src/InitTweak/InitTweak.cc
r83b52f1 r6130304 9 9 // Author : Rob Schluntz 10 10 // Created On : Fri May 13 11:26:36 2016 11 // Last Modified By : A ndrew Beach12 // Last Modified On : Fri Jun 19 14:34:00 201913 // Update Count : 611 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 10 13:30:00 2019 13 // Update Count : 5 14 14 // 15 15 … … 633 633 return nullptr; 634 634 } 635 636 DeclarationWithType * getFunctionCore( const Expression * expr ) {637 if ( const auto * appExpr = dynamic_cast< const ApplicationExpr * >( expr ) ) {638 return getCalledFunction( appExpr->function );639 } else if ( const auto * untyped = dynamic_cast< const UntypedExpr * >( expr ) ) {640 return getCalledFunction( untyped->function );641 }642 assertf( false, "getFunction with unknown expression: %s", toString( expr ).c_str() );643 }644 635 } 645 636 646 637 DeclarationWithType * getFunction( Expression * expr ) { 647 return getFunctionCore( expr ); 648 } 649 650 const DeclarationWithType * getFunction( const Expression * expr ) { 651 return getFunctionCore( expr ); 638 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr ) ) { 639 return getCalledFunction( appExpr->get_function() ); 640 } else if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * > ( expr ) ) { 641 return getCalledFunction( untyped->get_function() ); 642 } 643 assertf( false, "getFunction received unknown expression: %s", toString( expr ).c_str() ); 652 644 } 653 645 -
src/InitTweak/InitTweak.h
r83b52f1 r6130304 9 9 // Author : Rob Schluntz 10 10 // Created On : Fri May 13 11:26:36 2016 11 // Last Modified By : A ndrew Beach12 // Last Modified On : Fri Jul 19 14:18:00 201913 // Update Count : 611 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 10 13:30:00 2019 13 // Update Count : 5 14 14 // 15 15 … … 61 61 /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr) 62 62 DeclarationWithType * getFunction( Expression * expr ); 63 const DeclarationWithType * getFunction( const Expression * expr );64 63 const ast::DeclWithType * getFunction( const ast::Expr * expr ); 65 64 -
src/ResolvExpr/Alternative.h
r83b52f1 r6130304 29 29 /// One assertion to resolve 30 30 struct AssertionItem { 31 constDeclarationWithType* decl;31 DeclarationWithType* decl; 32 32 AssertionSetValue info; 33 33 34 34 AssertionItem() = default; 35 AssertionItem( const DeclarationWithType* decl, const AssertionSetValue& info )35 AssertionItem( DeclarationWithType* decl, const AssertionSetValue& info ) 36 36 : decl(decl), info(info) {} 37 37 AssertionItem( const AssertionSet::value_type& e ) : decl(e.first), info(e.second) {} -
src/ResolvExpr/FindOpenVars.cc
r83b52f1 r6130304 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 09:42:48 2015 11 // Last Modified By : Andrew12 // Last Modified On : Fri Jul 12 14:18:00 201913 // Update Count : 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 09:45:25 2015 13 // Update Count : 3 14 14 // 15 15 … … 29 29 FindOpenVars_old( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ); 30 30 31 void previsit( constPointerType * pointerType );32 void previsit( constArrayType * arrayType );33 void previsit( constFunctionType * functionType );34 void previsit( constTupleType * tupleType );31 void previsit( PointerType * pointerType ); 32 void previsit( ArrayType * arrayType ); 33 void previsit( FunctionType * functionType ); 34 void previsit( TupleType * tupleType ); 35 35 36 void common_action( constType *type );36 void common_action( Type *type ); 37 37 38 38 OpenVarSet &openVars, &closedVars; … … 41 41 }; 42 42 43 void findOpenVars( constType *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) {43 void findOpenVars( Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) { 44 44 PassVisitor<FindOpenVars_old> finder( openVars, closedVars, needAssertions, haveAssertions, firstIsOpen ); 45 45 type->accept( finder ); … … 50 50 } 51 51 52 void FindOpenVars_old::common_action( const Type *type ) {52 void FindOpenVars_old::common_action( Type *type ) { 53 53 if ( nextIsOpen ) { 54 for ( Type::ForallList::const_iterator i = type-> forall.begin(); i != type->forall.end(); ++i ) {54 for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) { 55 55 openVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) }; 56 56 for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) { … … 61 61 } 62 62 } else { 63 for ( Type::ForallList::const_iterator i = type-> forall.begin(); i != type->forall.end(); ++i ) {63 for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) { 64 64 closedVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) }; 65 65 for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) { … … 78 78 } 79 79 80 void FindOpenVars_old::previsit( const PointerType *pointerType) {80 void FindOpenVars_old::previsit(PointerType *pointerType) { 81 81 common_action( pointerType ); 82 82 } 83 83 84 void FindOpenVars_old::previsit( const ArrayType *arrayType) {84 void FindOpenVars_old::previsit(ArrayType *arrayType) { 85 85 common_action( arrayType ); 86 86 } 87 87 88 void FindOpenVars_old::previsit( const FunctionType *functionType) {88 void FindOpenVars_old::previsit(FunctionType *functionType) { 89 89 common_action( functionType ); 90 90 nextIsOpen = ! nextIsOpen; … … 92 92 } 93 93 94 void FindOpenVars_old::previsit( const TupleType *tupleType) {94 void FindOpenVars_old::previsit(TupleType *tupleType) { 95 95 common_action( tupleType ); 96 96 } … … 104 104 bool nextIsOpen; 105 105 106 FindOpenVars_new( 107 ast::OpenVarSet & o, ast::OpenVarSet & c, ast::AssertionSet & n, 106 FindOpenVars_new( 107 ast::OpenVarSet & o, ast::OpenVarSet & c, ast::AssertionSet & n, 108 108 ast::AssertionSet & h, FirstMode firstIsOpen ) 109 109 : open( o ), closed( c ), need( n ), have( h ), nextIsOpen( firstIsOpen ) {} … … 135 135 } 136 136 137 void findOpenVars( 138 const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed, 137 void findOpenVars( 138 const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed, 139 139 ast::AssertionSet & need, ast::AssertionSet & have, FirstMode firstIsOpen ) { 140 140 ast::Pass< FindOpenVars_new > finder{ open, closed, need, have, firstIsOpen }; -
src/ResolvExpr/FindOpenVars.h
r83b52f1 r6130304 26 26 namespace ResolvExpr { 27 27 // Updates open and closed variables and their associated assertions 28 void findOpenVars( constType *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen );28 void findOpenVars( Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ); 29 29 30 30 enum FirstMode { FirstClosed, FirstOpen }; -
src/ResolvExpr/Occurs.cc
r83b52f1 r6130304 24 24 struct Occurs : public WithVisitorRef<Occurs> { 25 25 Occurs( std::string varName, const TypeEnvironment &env ); 26 void previsit( constTypeInstType * typeInst );26 void previsit( TypeInstType * typeInst ); 27 27 28 28 bool result; … … 31 31 }; 32 32 33 bool occurs( const Type *type, const std::string &varName, const TypeEnvironment &env ) {33 bool occurs( Type *type, std::string varName, const TypeEnvironment &env ) { 34 34 PassVisitor<Occurs> occur( varName, env ); 35 35 type->accept( occur ); … … 45 45 } 46 46 47 void Occurs::previsit( constTypeInstType * typeInst ) {47 void Occurs::previsit( TypeInstType * typeInst ) { 48 48 /// std::cerr << "searching for vars: "; 49 49 /// std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cerr, " " ) ); -
src/ResolvExpr/ResolveAssertions.cc
r83b52f1 r6130304 73 73 CandidateList matches; 74 74 75 DeferItem( constDeclarationWithType* decl, const AssertionSetValue& info, CandidateList&& matches )75 DeferItem( DeclarationWithType* decl, const AssertionSetValue& info, CandidateList&& matches ) 76 76 : decl(decl), info(info), matches(std::move(matches)) {} 77 77 -
src/ResolvExpr/TypeEnvironment.cc
r83b52f1 r6130304 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:19:47 2015 11 // Last Modified By : A ndrew Beach12 // Last Modified On : Fri Jun 18 14:27:00 201913 // Update Count : 511 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 18 11:58:00 2018 13 // Update Count : 4 14 14 // 15 15 … … 315 315 } 316 316 317 bool isFtype( const Type *type ) {318 if ( dynamic_cast< const FunctionType* >( type ) ) {317 bool isFtype( Type *type ) { 318 if ( dynamic_cast< FunctionType* >( type ) ) { 319 319 return true; 320 } else if ( const TypeInstType *typeInst = dynamic_cast< const TypeInstType* >( type ) ) {320 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { 321 321 return typeInst->get_isFtype(); 322 322 } // if … … 324 324 } 325 325 326 bool tyVarCompatible( const TypeDecl::Data & data, const Type *type ) {326 bool tyVarCompatible( const TypeDecl::Data & data, Type *type ) { 327 327 switch ( data.kind ) { 328 328 case TypeDecl::Dtype: … … 336 336 case TypeDecl::Ttype: 337 337 // ttype unifies with any tuple type 338 return dynamic_cast< constTupleType * >( type ) || Tuples::isTtype( type );338 return dynamic_cast< TupleType * >( type ) || Tuples::isTtype( type ); 339 339 default: 340 340 assertf(false, "Unhandled tyvar kind: %d", data.kind); … … 343 343 } 344 344 345 bool TypeEnvironment::bindVar( constTypeInstType *typeInst, Type *bindTo, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer ) {345 bool TypeEnvironment::bindVar( TypeInstType *typeInst, Type *bindTo, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer ) { 346 346 347 347 // remove references from other, so that type variables can only bind to value types … … 361 361 // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to 362 362 std::unique_ptr< Type > newType( curClass->type->clone() ); 363 newType-> tq = typeInst->tq;363 newType->get_qualifiers() = typeInst->get_qualifiers(); 364 364 if ( unifyInexact( newType.get(), bindTo, *this, need, have, openVars, widen & WidenMode( curClass->allowWidening, true ), indexer, common ) ) { 365 365 if ( common ) { … … 386 386 } 387 387 388 bool TypeEnvironment::bindVarToVar( const TypeInstType * var1, const TypeInstType * var2,389 TypeDecl::Data && data, AssertionSet &need, AssertionSet &have, 388 bool TypeEnvironment::bindVarToVar( TypeInstType *var1, TypeInstType *var2, 389 TypeDecl::Data && data, AssertionSet &need, AssertionSet &have, 390 390 const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer ) { 391 391 -
src/ResolvExpr/TypeEnvironment.h
r83b52f1 r6130304 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:24:58 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Jul 19 17:00:10 201913 // Update Count : 1011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 30 23:04:10 2019 13 // Update Count : 9 14 14 // 15 15 … … 40 40 // declarations. 41 41 // 42 // I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this 42 // I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this 43 43 // comparator. 44 44 // … … 46 46 // memory layout can alter compilation time in unpredictable ways. For example, the placement 47 47 // of a line directive can reorder type pointers with respect to each other so that assertions 48 // are seen in different orders, causing a potentially different number of unification calls 49 // when resolving assertions. I've seen a TU go from 36 seconds to 27 seconds by reordering 50 // line directives alone, so it would be nice to fix this comparison so that assertions compare 51 // more consistently. I've tried to modify this to compare on mangle name instead of type as 52 // the second comparator, but this causes some assertions to never be recorded. More 48 // are seen in different orders, causing a potentially different number of unification calls 49 // when resolving assertions. I've seen a TU go from 36 seconds to 27 seconds by reordering 50 // line directives alone, so it would be nice to fix this comparison so that assertions compare 51 // more consistently. I've tried to modify this to compare on mangle name instead of type as 52 // the second comparator, but this causes some assertions to never be recorded. More 53 53 // investigation is needed. 54 54 struct AssertCompare { 55 bool operator()( const DeclarationWithType * d1, constDeclarationWithType * d2 ) const {55 bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) const { 56 56 int cmp = d1->get_name().compare( d2->get_name() ); 57 57 return cmp < 0 || … … 65 65 AssertionSetValue() : isUsed(false), resnSlot(0) {} 66 66 }; 67 typedef std::map< constDeclarationWithType *, AssertionSetValue, AssertCompare > AssertionSet;67 typedef std::map< DeclarationWithType *, AssertionSetValue, AssertCompare > AssertionSet; 68 68 typedef std::unordered_map< std::string, TypeDecl::Data > OpenVarSet; 69 69 … … 78 78 struct EqvClass { 79 79 std::set< std::string > vars; 80 Type * type;80 Type *type; 81 81 bool allowWidening; 82 82 TypeDecl::Data data; … … 111 111 bool isEmpty() const { return env.empty(); } 112 112 void print( std::ostream &os, Indenter indent = {} ) const; 113 113 114 114 /// Simply concatenate the second environment onto this one; no safety checks performed 115 115 void simpleCombine( const TypeEnvironment &second ); … … 126 126 /// Returns false if fails, but does NOT roll back partial changes. 127 127 bool combine( const TypeEnvironment& second, OpenVarSet& openVars, const SymTab::Indexer& indexer ); 128 128 129 129 void extractOpenVars( OpenVarSet &openVars ) const; 130 130 TypeEnvironment *clone() const { return new TypeEnvironment( *this ); } … … 134 134 void addActual( const TypeEnvironment& actualEnv, OpenVarSet& openVars ); 135 135 136 /// Binds the type class represented by `typeInst` to the type `bindTo`; will add 136 /// Binds the type class represented by `typeInst` to the type `bindTo`; will add 137 137 /// the class if needed. Returns false on failure. 138 bool bindVar( const TypeInstType * typeInst, Type *bindTo, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer );139 140 /// Binds the type classes represented by `var1` and `var2` together; will add 138 bool bindVar( TypeInstType *typeInst, Type *bindTo, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer ); 139 140 /// Binds the type classes represented by `var1` and `var2` together; will add 141 141 /// one or both classes if needed. Returns false on failure. 142 bool bindVarToVar( const TypeInstType * var1, const TypeInstType *var2, TypeDecl::Data && data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer );142 bool bindVarToVar( TypeInstType *var1, TypeInstType *var2, TypeDecl::Data && data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer ); 143 143 144 144 /// Disallows widening for all bindings in the environment … … 151 151 private: 152 152 ClassList env; 153 153 154 154 ClassList::iterator internal_lookup( const std::string &var ); 155 155 }; -
src/ResolvExpr/typeops.h
r83b52f1 r6130304 149 149 150 150 // in Occurs.cc 151 bool occurs( const Type * type, const std::string &varName, const TypeEnvironment & env );151 bool occurs( Type * type, std::string varName, const TypeEnvironment & env ); 152 152 // new AST version in TypeEnvironment.cpp (only place it was used in old AST) 153 153 … … 200 200 201 201 // in TypeEnvironment.cc 202 bool isFtype( constType * type );202 bool isFtype( Type * type ); 203 203 } // namespace ResolvExpr 204 204 -
src/SynTree/Type.cc
r83b52f1 r6130304 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Jul 12 15:48:00201913 // Update Count : 4 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jan 31 21:54:16 2019 13 // Update Count : 43 14 14 // 15 15 #include "Type.h" … … 141 141 } 142 142 143 const Type * Type::stripReferences() const {144 const Type * type;145 const ReferenceType * ref;146 for ( type = this; (ref = dynamic_cast<const ReferenceType *>( type )); type = ref->base );147 return type;148 }149 150 143 int Type::referenceDepth() const { return 0; } 151 144 -
src/SynTree/Type.h
r83b52f1 r6130304 172 172 /// return type without outer references 173 173 Type * stripReferences(); 174 const Type * stripReferences() const;175 174 176 175 /// return the number of references occuring consecutively on the outermost layer of this type (i.e. do not count references nested within other types) … … 257 256 BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 258 257 259 Kind get_kind() const{ return kind; }258 Kind get_kind() { return kind; } 260 259 void set_kind( Kind newValue ) { kind = newValue; } 261 260 -
src/Tuples/TupleExpansion.cc
r83b52f1 r6130304 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Jul 19 14:39:00201913 // Update Count : 2 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 13 18:14:12 2019 13 // Update Count : 21 14 14 // 15 15 … … 350 350 } 351 351 352 const TypeInstType * isTtype( const Type * type ) {353 if ( const TypeInstType * inst = dynamic_cast< const TypeInstType * >( type ) ) {354 if ( inst->baseType && inst->baseType->kind == TypeDecl::Ttype ) {355 return inst;356 }357 }358 return nullptr;359 }360 361 352 const ast::TypeInstType * isTtype( const ast::Type * type ) { 362 353 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( type ) ) { … … 373 364 ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {} 374 365 375 void previsit( constApplicationExpr * appExpr ) {366 void previsit( ApplicationExpr * appExpr ) { 376 367 visit_children = false; 377 if ( constDeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {378 if ( function-> linkage== LinkageSpec::Intrinsic ) {379 if ( function-> name == "*?" || function->name== "?[?]" ) {368 if ( DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) { 369 if ( function->get_linkage() == LinkageSpec::Intrinsic ) { 370 if ( function->get_name() == "*?" || function->get_name() == "?[?]" ) { 380 371 // intrinsic dereference, subscript are pure, but need to recursively look for impurity 381 372 visit_children = true; … … 386 377 maybeImpure = true; 387 378 } 388 void previsit( constUntypedExpr * ) { maybeImpure = true; visit_children = false; }389 void previsit( constUniqueExpr * ) {379 void previsit( UntypedExpr * ) { maybeImpure = true; visit_children = false; } 380 void previsit( UniqueExpr * ) { 390 381 if ( ignoreUnique ) { 391 382 // bottom out at unique expression. … … 402 393 } // namespace 403 394 404 bool maybeImpure( constExpression * expr ) {395 bool maybeImpure( Expression * expr ) { 405 396 PassVisitor<ImpurityDetector> detector( false ); 406 397 expr->accept( detector ); … … 408 399 } 409 400 410 bool maybeImpureIgnoreUnique( constExpression * expr ) {401 bool maybeImpureIgnoreUnique( Expression * expr ) { 411 402 PassVisitor<ImpurityDetector> detector( true ); 412 403 expr->accept( detector ); -
src/Tuples/Tuples.h
r83b52f1 r6130304 52 52 /// returns a TypeInstType if `type` is a ttype, nullptr otherwise 53 53 TypeInstType * isTtype( Type * type ); 54 const TypeInstType * isTtype( const Type * type );55 54 const ast::TypeInstType * isTtype( const ast::Type * type ); 56 55 57 56 /// returns true if the expression may contain side-effects. 58 bool maybeImpure( constExpression * expr );57 bool maybeImpure( Expression * expr ); 59 58 bool maybeImpure( const ast::Expr * expr ); 60 59 61 60 /// Returns true if the expression may contain side-effect, 62 61 /// ignoring the presence of unique expressions. 63 bool maybeImpureIgnoreUnique( constExpression * expr );62 bool maybeImpureIgnoreUnique( Expression * expr ); 64 63 bool maybeImpureIgnoreUnique( const ast::Expr * expr ); 65 64 } // namespace Tuples -
tests/.expect/copyfile.txt
r83b52f1 r6130304 10 10 // Created On : Tue Jul 16 16:47:22 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 17 18:04:44201913 // Update Count : 2612 // Last Modified On : Tue Jul 16 16:48:16 2019 13 // Update Count : 1 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include <stdlib.hfa> // new/delete18 17 19 18 int main( int argc, char * argv[] ) { 20 ifstream * in = &stdin;// default files21 ofstream * out = &stdout;22 try {23 choose ( argc ) {24 case 2, 3:25 in = new( (const char *)argv[1] );// open input file first as output creates file26 if ( argc == 3 ) out = new( (const char *)argv[2] );// only open output if input opens as output created if nonexistent27 case 1: ; // use default files28 default:29 exit | "Usage [ input-file (default stdin) [ output-file (default stdout) ] ]";30 } // choose19 ifstream & in = stdin; // default files 20 ofstream & out = stdout; 21 try { 22 choose ( argc ) { 23 case 2, 3: 24 open( in, argv[1] ); // open input file first as output creates file 25 if ( argc == 3 ) open( out, argv[2] ); // only open output if input opens as output created if nonexistent 26 case 1: ; // use default files 27 default: 28 exit | "Usage [ input-file (default stdin) [ output-file (default stdout) ] ]"; 29 } // choose 31 30 32 char ch;33 *out | nlOff;// turn off auto newline34 *in | nlOn;// turn on reading newline31 char ch; 32 out | nlOff; // turn off auto newline 33 in | nlOn; // turn on reading newline 35 34 36 for () {// read all characters37 *in | ch;38 if ( eof( *in ) ) break;// eof ?39 *out | ch;40 } // for41 } finally {42 if ( in != &stdin ) delete( in ); // close file, do not delete stdin!43 if ( out != &stdout ) delete( out ); // close file, do not delete stdout!44 } // try35 for () { // read all characters 36 in | ch; 37 if ( eof( in ) ) break; // eof ? 38 out | ch; 39 } // for 40 } finally { 41 close( in ); // stdin, stdout are never closed 42 close( out ); 43 } // try 45 44 } // main 46 45 -
tests/.in/copyfile.txt
r83b52f1 r6130304 10 10 // Created On : Tue Jul 16 16:47:22 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 17 18:04:44201913 // Update Count : 2612 // Last Modified On : Tue Jul 16 16:48:16 2019 13 // Update Count : 1 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include <stdlib.hfa> // new/delete18 17 19 18 int main( int argc, char * argv[] ) { 20 ifstream * in = &stdin;// default files21 ofstream * out = &stdout;22 try {23 choose ( argc ) {24 case 2, 3:25 in = new( (const char *)argv[1] );// open input file first as output creates file26 if ( argc == 3 ) out = new( (const char *)argv[2] );// only open output if input opens as output created if nonexistent27 case 1: ; // use default files28 default:29 exit | "Usage [ input-file (default stdin) [ output-file (default stdout) ] ]";30 } // choose19 ifstream & in = stdin; // default files 20 ofstream & out = stdout; 21 try { 22 choose ( argc ) { 23 case 2, 3: 24 open( in, argv[1] ); // open input file first as output creates file 25 if ( argc == 3 ) open( out, argv[2] ); // only open output if input opens as output created if nonexistent 26 case 1: ; // use default files 27 default: 28 exit | "Usage [ input-file (default stdin) [ output-file (default stdout) ] ]"; 29 } // choose 31 30 32 char ch;33 *out | nlOff;// turn off auto newline34 *in | nlOn;// turn on reading newline31 char ch; 32 out | nlOff; // turn off auto newline 33 in | nlOn; // turn on reading newline 35 34 36 for () {// read all characters37 *in | ch;38 if ( eof( *in ) ) break;// eof ?39 *out | ch;40 } // for41 } finally {42 if ( in != &stdin ) delete( in ); // close file, do not delete stdin!43 if ( out != &stdout ) delete( out ); // close file, do not delete stdout!44 } // try35 for () { // read all characters 36 in | ch; 37 if ( eof( in ) ) break; // eof ? 38 out | ch; 39 } // for 40 } finally { 41 close( in ); // stdin, stdout are never closed 42 close( out ); 43 } // try 45 44 } // main 46 45 -
tests/copyfile.cfa
r83b52f1 r6130304 10 10 // Created On : Tue Jul 16 16:47:22 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 17 18:04:44201913 // Update Count : 2612 // Last Modified On : Tue Jul 16 16:48:16 2019 13 // Update Count : 1 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include <stdlib.hfa> // new/delete18 17 19 18 int main( int argc, char * argv[] ) { 20 ifstream * in = &stdin;// default files21 ofstream * out = &stdout;22 try {23 choose ( argc ) {24 case 2, 3:25 in = new( (const char *)argv[1] );// open input file first as output creates file26 if ( argc == 3 ) out = new( (const char *)argv[2] );// only open output if input opens as output created if nonexistent27 case 1: ; // use default files28 default:29 exit | "Usage [ input-file (default stdin) [ output-file (default stdout) ] ]";30 } // choose19 ifstream & in = stdin; // default files 20 ofstream & out = stdout; 21 try { 22 choose ( argc ) { 23 case 2, 3: 24 open( in, argv[1] ); // open input file first as output creates file 25 if ( argc == 3 ) open( out, argv[2] ); // only open output if input opens as output created if nonexistent 26 case 1: ; // use default files 27 default: 28 exit | "Usage [ input-file (default stdin) [ output-file (default stdout) ] ]"; 29 } // choose 31 30 32 char ch;33 *out | nlOff;// turn off auto newline34 *in | nlOn;// turn on reading newline31 char ch; 32 out | nlOff; // turn off auto newline 33 in | nlOn; // turn on reading newline 35 34 36 for () {// read all characters37 *in | ch;38 if ( eof( *in ) ) break;// eof ?39 *out | ch;40 } // for41 } finally {42 if ( in != &stdin ) delete( in ); // close file, do not delete stdin!43 if ( out != &stdout ) delete( out ); // close file, do not delete stdout!44 } // try35 for () { // read all characters 36 in | ch; 37 if ( eof( in ) ) break; // eof ? 38 out | ch; 39 } // for 40 } finally { 41 close( in ); // stdin, stdout are never closed 42 close( out ); 43 } // try 45 44 } // main 46 45 -
tests/heap.cfa
r83b52f1 r6130304 10 10 // Created On : Tue Nov 6 17:54:56 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 19 08:22:34 201913 // Update Count : 1 912 // Last Modified On : Tue Dec 11 21:52:40 2018 13 // Update Count : 18 14 14 // 15 15 … … 29 29 #define __U_DEFAULT_MMAP_START__ (512 * 1024 + 1) 30 30 size_t default_mmap_start() __attribute__(( weak )) { 31 return __U_DEFAULT_MMAP_START__;31 return __U_DEFAULT_MMAP_START__; 32 32 } // default_mmap_start 33 33 … … 36 36 37 37 void main( Worker & ) { 38 enum { NoOfAllocs = 5000, NoOfMmaps = 10 };39 char * locns[NoOfAllocs];40 int i;41 42 // check alloc/free43 44 for ( j; 40 ) {38 enum { NoOfAllocs = 5000, NoOfMmaps = 10 }; 39 char * locns[NoOfAllocs]; 40 int i; 41 42 // check alloc/free 43 44 for ( j; 40 ) { 45 45 for ( i; NoOfAllocs ) { 46 46 locns[i] = alloc( i ); … … 67 67 free( locns[i] ); 68 68 } // for 69 } // for70 71 // check malloc/free (sbrk)72 73 for ( i; NoOfAllocs ) {69 } // for 70 71 // check malloc/free (sbrk) 72 73 for ( i; NoOfAllocs ) { 74 74 size_t s = (i + 1) * 20; 75 75 char * area = (char *)malloc( s ); … … 78 78 area[malloc_usable_size( area ) - 1] = '\345'; // fill ultimate byte 79 79 free( area ); 80 } // for81 82 for ( i; NoOfAllocs ) {80 } // for 81 82 for ( i; NoOfAllocs ) { 83 83 size_t s = i + 1; // +1 to make initialization simpler 84 84 locns[i] = (char *)malloc( s ); … … 86 86 locns[i][0] = '\345'; locns[i][s - 1] = '\345'; // fill first/last 87 87 locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte 88 } // for89 for ( i; NoOfAllocs ) {88 } // for 89 for ( i; NoOfAllocs ) { 90 90 size_t s = i + 1; 91 91 if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' || 92 92 locns[i][malloc_usable_size( locns[i] ) - 1] != '\345' ) abort( "malloc/free corrupt storage" ); 93 93 free( locns[i] ); 94 } // for95 96 // check malloc/free (mmap)97 98 for ( i; NoOfMmaps ) {94 } // for 95 96 // check malloc/free (mmap) 97 98 for ( i; NoOfMmaps ) { 99 99 size_t s = i + default_mmap_start(); // cross over point 100 100 char * area = (char *)malloc( s ); … … 103 103 area[malloc_usable_size( area ) - 1] = '\345'; // fill ultimate byte 104 104 free( area ); 105 } // for106 107 for ( i; NoOfMmaps ) {105 } // for 106 107 for ( i; NoOfMmaps ) { 108 108 size_t s = i + default_mmap_start(); // cross over point 109 109 locns[i] = (char *)malloc( s ); … … 111 111 locns[i][0] = '\345'; locns[i][s - 1] = '\345'; // fill first/last 112 112 locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte 113 } // for114 for ( i; NoOfMmaps ) {113 } // for 114 for ( i; NoOfMmaps ) { 115 115 size_t s = i + default_mmap_start(); // cross over point 116 116 if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' || 117 117 locns[i][malloc_usable_size( locns[i] ) - 1] != '\345' ) abort( "malloc/free corrupt storage" ); 118 118 free( locns[i] ); 119 } // for120 121 // check calloc/free (sbrk)122 123 for ( i; NoOfAllocs ) {119 } // for 120 121 // check calloc/free (sbrk) 122 123 for ( i; NoOfAllocs ) { 124 124 size_t s = (i + 1) * 20; 125 125 char * area = (char *)calloc( 5, s ); … … 131 131 area[malloc_usable_size( area ) - 1] = '\345'; // fill ultimate byte 132 132 free( area ); 133 } // for134 135 for ( i; NoOfAllocs ) {133 } // for 134 135 for ( i; NoOfAllocs ) { 136 136 size_t s = i + 1; 137 137 locns[i] = (char *)calloc( 5, s ); … … 142 142 locns[i][0] = '\345'; locns[i][s - 1] = '\345'; // fill first/last 143 143 locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte 144 } // for145 for ( i; NoOfAllocs ) {144 } // for 145 for ( i; NoOfAllocs ) { 146 146 size_t s = i + 1; 147 147 if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' || 148 148 locns[i][malloc_usable_size( locns[i] ) - 1] != '\345' ) abort( "calloc/free corrupt storage3" ); 149 149 free( locns[i] ); 150 } // for151 152 // check calloc/free (mmap)153 154 for ( i; NoOfMmaps ) {150 } // for 151 152 // check calloc/free (mmap) 153 154 for ( i; NoOfMmaps ) { 155 155 size_t s = i + default_mmap_start(); // cross over point 156 156 char * area = (char *)calloc( 1, s ); … … 162 162 area[malloc_usable_size( area ) - 1] = '\345'; // fill ultimate byte 163 163 free( area ); 164 } // for165 166 for ( i; NoOfMmaps ) {164 } // for 165 166 for ( i; NoOfMmaps ) { 167 167 size_t s = i + default_mmap_start(); // cross over point 168 168 locns[i] = (char *)calloc( 1, s ); … … 173 173 locns[i][0] = '\345'; locns[i][s - 1] = '\345'; // fill first/last 174 174 locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte 175 } // for176 for ( i; NoOfMmaps ) {175 } // for 176 for ( i; NoOfMmaps ) { 177 177 size_t s = i + default_mmap_start(); // cross over point 178 178 if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' || 179 179 locns[i][malloc_usable_size( locns[i] ) - 1] != '\345' ) abort( "calloc/free corrupt storage6" ); 180 180 free( locns[i] ); 181 } // for182 183 // check memalign/free (sbrk)184 185 enum { limit = 64 * 1024 }; // check alignments up to here181 } // for 182 183 // check memalign/free (sbrk) 184 185 enum { limit = 64 * 1024 }; // check alignments up to here 186 186 187 187 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 … … 198 198 free( area ); 199 199 } // for 200 } // for201 202 // check memalign/free (mmap)200 } // for 201 202 // check memalign/free (mmap) 203 203 204 204 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 … … 216 216 free( area ); 217 217 } // for 218 } // for219 220 // check calloc/realloc/free (sbrk)221 222 for ( i; 1 ~ 10_000 ~ 12 ) {218 } // for 219 220 // check calloc/realloc/free (sbrk) 221 222 for ( i; 1 ~ 10_000 ~ 12 ) { 223 223 // initial N byte allocation 224 224 char * area = (char *)calloc( 5, i ); … … 237 237 } // for 238 238 free( area ); 239 } // for240 241 // check calloc/realloc/free (mmap)242 243 for ( i; 1 ~ 10_000 ~ 12 ) {239 } // for 240 241 // check calloc/realloc/free (mmap) 242 243 for ( i; 1 ~ 10_000 ~ 12 ) { 244 244 // initial N byte allocation 245 245 size_t s = i + default_mmap_start(); // cross over point … … 259 259 } // for 260 260 free( area ); 261 } // for262 263 // check memalign/realloc/free264 265 size_t amount = 2;261 } // for 262 263 // check memalign/realloc/free 264 265 size_t amount = 2; 266 266 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 267 267 // initial N byte allocation … … 286 286 } // for 287 287 free( area ); 288 } // for289 290 // check cmemalign/free288 } // for 289 290 // check cmemalign/free 291 291 292 292 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 … … 305 305 free( area ); 306 306 } // for 307 } // for308 309 // check cmemalign/realloc/free310 311 amount = 2;307 } // for 308 309 // check cmemalign/realloc/free 310 311 amount = 2; 312 312 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 313 313 // initial N byte allocation … … 338 338 } // for 339 339 free( area ); 340 } // for340 } // for 341 341 //sout | "worker" | thisTask() | "successful completion"; 342 342 } // Worker main 343 343 344 344 int main() { 345 const unsigned int NoOfWorkers = 4;346 {345 const unsigned int NoOfWorkers = 4; 346 { 347 347 processor processors[NoOfWorkers - 1] __attribute__(( unused )); // more than one processor 348 348 Worker workers[NoOfWorkers] __attribute__(( unused )); 349 }349 } 350 350 // checkFreeOn(); 351 // malloc_stats();351 // malloc_stats(); 352 352 } 353 353
Note:
See TracChangeset
for help on using the changeset viewer.