Changeset cd7ef0b for src/libcfa
- Timestamp:
- Aug 10, 2017, 3:39:11 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 38d70ab
- Parents:
- 275f4b4 (diff), e1780a2 (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. - Location:
- src/libcfa
- Files:
-
- 11 edited
-
Makefile.am (modified) (1 diff)
-
Makefile.in (modified) (1 diff)
-
concurrency/monitor.c (modified) (2 diffs)
-
exception.c (modified) (9 diffs)
-
exception.h (modified) (4 diffs)
-
iostream (modified) (4 diffs)
-
iostream.c (modified) (3 diffs)
-
math (modified) (3 diffs)
-
stdhdr/assert.h (modified) (2 diffs)
-
stdlib (modified) (2 diffs)
-
stdlib.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/Makefile.am
r275f4b4 rcd7ef0b 39 39 40 40 AM_CCASFLAGS = @CFA_FLAGS@ 41 CFLAGS = -quiet -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS} 41 42 #CFLAGS for most libcfa src 43 #use -no-include-stdhdr to prevent rebuild cycles 44 #The built sources must not depend on the installed headers 45 CFLAGS = -quiet -no-include-stdhdr -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS} 42 46 CC = ${abs_top_srcdir}/src/driver/cfa 43 47 -
src/libcfa/Makefile.in
r275f4b4 rcd7ef0b 308 308 CFA_NAME = @CFA_NAME@ 309 309 CFA_PREFIX = @CFA_PREFIX@ 310 CFLAGS = -quiet -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS} 310 311 #CFLAGS for most libcfa src 312 #use -no-include-stdhdr to prevent rebuild cycles 313 #The built sources must not depend on the installed headers 314 CFLAGS = -quiet -no-include-stdhdr -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS} 311 315 CPP = @CPP@ 312 316 CPPFLAGS = @CPPFLAGS@ -
src/libcfa/concurrency/monitor.c
r275f4b4 rcd7ef0b 10 10 // Created On : Thd Feb 23 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:37:11201713 // Update Count : 112 // Last Modified On : Mon Jul 31 14:59:05 2017 13 // Update Count : 3 14 14 // 15 15 … … 484 484 if( !this->monitors ) { 485 485 // LIB_DEBUG_PRINT_SAFE("Branding\n"); 486 assertf( thrd->current_monitors != NULL, "No current monitor to brand condition ", thrd->current_monitors );486 assertf( thrd->current_monitors != NULL, "No current monitor to brand condition %p", thrd->current_monitors ); 487 487 this->monitor_count = thrd->current_monitor_count; 488 488 -
src/libcfa/exception.c
r275f4b4 rcd7ef0b 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Jul 26 10:37:51201713 // Update Count : 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 4 15:20:00 2017 13 // Update Count : 6 14 14 // 15 16 #include <stddef.h> // for size_t 15 17 16 18 #include "exception.h" … … 32 34 #include "lsda.h" 33 35 36 37 // Base exception vtable is abstract, you should not have base exceptions. 38 struct __cfaehm__base_exception_t_vtable 39 ___cfaehm__base_exception_t_vtable_instance = { 40 .parent = NULL, 41 .size = 0, 42 .copy = NULL, 43 .free = NULL, 44 .msg = NULL 45 }; 46 47 34 48 // Temperary global exception context. Does not work with concurency. 35 struct shared_stack_t {49 struct exception_context_t { 36 50 struct __cfaehm__try_resume_node * top_resume; 37 51 struct __cfaehm__try_resume_node * current_resume; 38 52 39 exception current_exception;53 exception * current_exception; 40 54 int current_handler_index; 41 55 } shared_stack = {NULL, NULL, 0, 0}; 42 56 57 // Get the current exception context. 58 // There can be a single global until multithreading occurs, then each stack 59 // needs its own. It will have to be updated to handle that. 60 struct exception_context_t * this_exception_context() { 61 return &shared_stack; 62 } 63 //#define SAVE_EXCEPTION_CONTEXT(to_name) 64 //struct exception_context_t * to_name = this_exception_context(); 65 //exception * this_exception() { 66 // return this_exception_context()->current_exception; 67 //} 43 68 44 69 … … 55 80 56 81 // DEBUG 57 printf("Throwing resumption exception %d\n", *except);82 printf("Throwing resumption exception\n"); 58 83 59 84 struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume; … … 69 94 } 70 95 71 printf("Unhandled exception %d\n", *except);96 printf("Unhandled exception\n"); 72 97 shared_stack.current_resume = original_head; 73 98 … … 94 119 // TERMINATION =============================================================== 95 120 96 // Requires -fexceptions to work. 97 98 // Global which defines the current exception. Currently an int just to make matching easier. 99 //int this_exception; (became shared_stack.current_exception) 121 // MEMORY MANAGEMENT (still for integers) 122 // May have to move to cfa for constructors and destructors (references). 123 124 struct __cfaehm__node { 125 struct __cfaehm__node * next; 126 }; 127 128 #define NODE_TO_EXCEPT(node) ((exception *)(1 + (node))) 129 #define EXCEPT_TO_NODE(except) ((struct __cfaehm__node *)(except) - 1) 130 131 // Creates a copy of the indicated exception and sets current_exception to it. 132 static void __cfaehm__allocate_exception( exception * except ) { 133 struct exception_context_t * context = this_exception_context(); 134 135 // Allocate memory for the exception. 136 struct __cfaehm__node * store = malloc( 137 sizeof( struct __cfaehm__node ) + except->virtual_table->size ); 138 139 if ( ! store ) { 140 // Failure: cannot allocate exception. Terminate thread. 141 abort(); // <- Although I think it might be the process. 142 } 143 144 // Add the node to the list: 145 store->next = EXCEPT_TO_NODE(context->current_exception); 146 context->current_exception = NODE_TO_EXCEPT(store); 147 148 // Copy the exception to storage. 149 except->virtual_table->copy( context->current_exception, except ); 150 } 151 152 // Delete the provided exception, unsetting current_exception if relivant. 153 static void __cfaehm__delete_exception( exception * except ) { 154 struct exception_context_t * context = this_exception_context(); 155 156 // DEBUG 157 printf( "Deleting Exception\n"); 158 159 // Remove the exception from the list. 160 struct __cfaehm__node * to_free = EXCEPT_TO_NODE(except); 161 struct __cfaehm__node * node; 162 163 if ( context->current_exception == except ) { 164 node = to_free->next; 165 context->current_exception = (node) ? NODE_TO_EXCEPT(node) : 0; 166 } else { 167 node = EXCEPT_TO_NODE(context->current_exception); 168 // It may always be in the first or second position. 169 while( to_free != node->next ) { 170 node = node->next; 171 } 172 node->next = to_free->next; 173 } 174 175 // Free the old exception node. 176 except->virtual_table->free( except ); 177 free( to_free ); 178 } 179 180 // If this isn't a rethrow (*except==0), delete the provided exception. 181 void __cfaehm__cleanup_terminate( void * except ) { 182 if ( *(void**)except ) __cfaehm__delete_exception( *(exception**)except ); 183 } 184 100 185 101 186 // We need a piece of storage to raise the exception … … 117 202 } 118 203 119 void __cfaehm__throw_terminate( exception * val ) { 120 // Store the current exception 121 shared_stack.current_exception = *val; 122 123 // DEBUG 124 printf("Throwing termination exception %d\n", *val); 204 // The exception that is being thrown must already be stored. 205 __attribute__((noreturn)) void __cfaehm__begin_unwind(void) { 206 if ( ! this_exception_context()->current_exception ) { 207 printf("UNWIND ERROR missing exception in begin unwind\n"); 208 abort(); 209 } 210 125 211 126 212 // Call stdlibc to raise the exception … … 148 234 } 149 235 150 // Nesting this the other way would probably be faster. 236 void __cfaehm__throw_terminate( exception * val ) { 237 // DEBUG 238 printf("Throwing termination exception\n"); 239 240 __cfaehm__allocate_exception( val ); 241 __cfaehm__begin_unwind(); 242 } 243 151 244 void __cfaehm__rethrow_terminate(void) { 152 245 // DEBUG 153 246 printf("Rethrowing termination exception\n"); 154 247 155 __cfaehm__ throw_terminate(&shared_stack.current_exception);248 __cfaehm__begin_unwind(); 156 249 } 157 250 … … 263 356 _Unwind_Reason_Code (*matcher)(exception *) = 264 357 MATCHER_FROM_CONTEXT(context); 265 int index = matcher( &shared_stack.current_exception);358 int index = matcher(shared_stack.current_exception); 266 359 _Unwind_Reason_Code ret = (0 == index) 267 360 ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND; … … 359 452 // Exception handler 360 453 catch_block( shared_stack.current_handler_index, 361 &shared_stack.current_exception );454 shared_stack.current_exception ); 362 455 } 363 456 -
src/libcfa/exception.h
r275f4b4 rcd7ef0b 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Jun 26 15:11:00 2017 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:57:02201713 // Update Count : 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 4 15:20:00 2017 13 // Update Count : 5 14 14 // 15 15 16 16 #pragma once 17 17 18 // Later to be a special structure type.19 typedef int exception;20 18 21 19 #ifdef __CFORALL__ 22 20 extern "C" { 23 21 #endif 22 23 struct __cfaehm__base_exception_t; 24 typedef struct __cfaehm__base_exception_t exception; 25 struct __cfaehm__base_exception_t_vtable { 26 const struct __cfaehm__base_exception_t_vtable * parent; 27 size_t size; 28 void (*copy)(struct __cfaehm__base_exception_t *this, 29 struct __cfaehm__base_exception_t * other); 30 void (*free)(struct __cfaehm__base_exception_t *this); 31 const char (*msg)(struct __cfaehm__base_exception_t *this); 32 }; 33 struct __cfaehm__base_exception_t { 34 struct __cfaehm__base_exception_t_vtable const * virtual_table; 35 }; 36 extern struct __cfaehm__base_exception_t_vtable 37 ___cfaehm__base_exception_t_vtable_instance; 38 24 39 25 40 // Used in throw statement translation. … … 34 49 int (*match_block)(exception * except)); 35 50 51 // Clean-up the exception in catch blocks. 52 void __cfaehm__cleanup_terminate(void * except); 53 36 54 // Data structure creates a list of resume handlers. 37 55 struct __cfaehm__try_resume_node { … … 40 58 }; 41 59 60 // These act as constructor and destructor for the resume node. 42 61 void __cfaehm__try_resume_setup( 43 62 struct __cfaehm__try_resume_node * node, … … 47 66 48 67 // Check for a standard way to call fake deconstructors. 49 struct __cfaehm__cleanup_hook { 50 }; 68 struct __cfaehm__cleanup_hook {}; 51 69 52 70 #ifdef __CFORALL__ -
src/libcfa/iostream
r275f4b4 rcd7ef0b 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 7 08:35:59201713 // Update Count : 1 1812 // Last Modified On : Wed Aug 9 16:42:47 2017 13 // Update Count : 131 14 14 // 15 15 … … 46 46 }; // ostream 47 47 48 trait writeable( otype T ) { 49 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T ); 48 // trait writeable( otype T ) { 49 // forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T ); 50 // }; // writeable 51 52 trait writeable( otype T, dtype ostype | ostream( ostype ) ) { 53 ostype * ?|?( ostype *, T ); 50 54 }; // writeable 51 55 … … 77 81 78 82 // tuples 79 forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } ) ostype * ?|?( ostype * os, T arg, Params rest ); 83 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype * ?|?( ostype *, Params ); } ) 84 ostype * ?|?( ostype * os, T arg, Params rest ); 80 85 81 86 // manipulators … … 90 95 91 96 // writes the range [begin, end) to the given stream 92 forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )93 void write( iterator_type begin, iterator_type end, os _type *os );97 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 98 void write( iterator_type begin, iterator_type end, ostype * os ); 94 99 95 forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )96 void write_reverse( iterator_type begin, iterator_type end, os _type *os );100 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 101 void write_reverse( iterator_type begin, iterator_type end, ostype * os ); 97 102 98 103 //--------------------------------------- -
src/libcfa/iostream.c
r275f4b4 rcd7ef0b 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jul 16 21:12:03201713 // Update Count : 39812 // Last Modified On : Wed Aug 9 16:46:51 2017 13 // Update Count : 401 14 14 // 15 15 … … 193 193 194 194 // tuples 195 forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T) | { ostype * ?|?( ostype *, Params ); } )195 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype * ?|?( ostype *, Params ); } ) 196 196 ostype * ?|?( ostype * os, T arg, Params rest ) { 197 197 os | arg; // print first argument … … 256 256 //--------------------------------------- 257 257 258 forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )259 void write( iterator type begin, iteratortype end, ostype * os ) {260 void print( elt type i ) { os | i; }258 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 259 void write( iterator_type begin, iterator_type end, ostype * os ) { 260 void print( elt_type i ) { os | i; } 261 261 for_each( begin, end, print ); 262 262 } // ?|? 263 263 264 forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )265 void write_reverse( iterator type begin, iteratortype end, ostype * os ) {266 void print( elt type i ) { os | i; }264 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 265 void write_reverse( iterator_type begin, iterator_type end, ostype * os ) { 266 void print( elt_type i ) { os | i; } 267 267 for_each_reverse( begin, end, print ); 268 268 } // ?|? -
src/libcfa/math
r275f4b4 rcd7ef0b 10 10 // Created On : Mon Apr 18 23:37:04 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 17:03:13201713 // Update Count : 10 112 // Last Modified On : Mon Aug 7 07:51:15 2017 13 // Update Count : 108 14 14 // 15 15 … … 18 18 #include <math.h> 19 19 #include <complex.h> 20 21 //---------------------- General ---------------------- 20 22 21 23 static inline float ?%?( float x, float y ) { return fmodf( x, y ); } … … 37 39 static inline [ int, long double ] remquo( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; } 38 40 39 // alternative name for remquo 40 static inline float div( float x, float y, int * quo ) { return remquof( x, y, quo ); } 41 static inline double div( double x, double y, int * quo ) { return remquo( x, y, quo ); } 42 static inline long double div( long double x, long double y, int * quo ) { return remquol( x, y, quo ); } 43 static inline [ int, float ] div( float x, float y ) { int quo; x = remquof( x, y, &quo ); return [ quo, x ]; } 44 static inline [ int, double ] div( double x, double y ) { int quo; x = remquo( x, y, &quo ); return [ quo, x ]; } 45 static inline [ int, long double ] div( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; } 41 static inline [ float, float ] div( float x, float y ) { y = modff( x / y, &x ); return [ x, y ]; } 42 static inline [ double, double ] div( double x, double y ) { y = modf( x / y, &x ); return [ x, y ]; } 43 static inline [ long double, long double ] div( long double x, long double y ) { y = modfl( x / y, &x ); return [ x, y ]; } 46 44 47 45 static inline float fma( float x, float y, float z ) { return fmaf( x, y, z ); } -
src/libcfa/stdhdr/assert.h
r275f4b4 rcd7ef0b 10 10 // Created On : Mon Jul 4 23:25:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 20 21:06:48201713 // Update Count : 1 112 // Last Modified On : Mon Jul 31 23:09:32 2017 13 // Update Count : 13 14 14 // 15 15 … … 25 25 #define __STRINGIFY__(str) #str 26 26 #define __VSTRINGIFY__(str) __STRINGIFY__(str) 27 #define assertf(expr, fmt, ...) ((expr) ? ((void)0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ )) 28 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn)); 27 #define assertf( expr, fmt, ... ) ((expr) ? ((void)0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ )) 28 29 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn, format( printf, 5, 6) )); 29 30 #endif 30 31 -
src/libcfa/stdlib
r275f4b4 rcd7ef0b 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 20 14:32:37 201713 // Update Count : 22 012 // Last Modified On : Mon Aug 7 11:19:07 2017 13 // Update Count : 223 14 14 // 15 15 … … 183 183 //--------------------------------------- 184 184 185 [ int, int ] div( int num, int denom ); 186 [ long int, long int ] div( long int num, long int denom ); 187 [ long long int, long long int ] div( long long int num, long long int denom ); 185 188 forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } ) 186 [ T, T ] div( T t1, T t2);189 [ T, T ] div( T num, T demon ); 187 190 188 191 //--------------------------------------- -
src/libcfa/stdlib.c
r275f4b4 rcd7ef0b 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Jul 20 16:01:40201713 // Update Count : 2 8212 // Last Modified On : Tue Aug 8 17:31:13 2017 13 // Update Count : 291 14 14 // 15 15 … … 255 255 //--------------------------------------- 256 256 257 [ int, int ] div( int num, int denom ) { div_t qr = div( num, denom ); return [ qr.quot, qr.rem ]; } 258 [ long int, long int ] div( long int num, long int denom ) { ldiv_t qr = ldiv( num, denom ); return [ qr.quot, qr.rem ]; } 259 [ long long int, long long int ] div( long long int num, long long int denom ) { lldiv_t qr = lldiv( num, denom ); return [ qr.quot, qr.rem ]; } 257 260 forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } ) 258 [ T, T ] div( T t1, T t2 ) { return [ t1 / t2, t1 % t2]; }261 [ T, T ] div( T num, T denom ) { return [ num / denom, num % denom ]; } 259 262 260 263 //---------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.