Changes in / [a685335:aa7a56e]
- Files:
-
- 5 edited
-
libcfa/src/exception.c (modified) (20 diffs)
-
libcfa/src/exception.h (modified) (3 diffs)
-
src/ControlStruct/ExceptTranslate.cc (modified) (11 diffs)
-
src/ResolvExpr/Resolver.cc (modified) (3 diffs)
-
tests/exceptions/except-mac.hfa (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/exception.c
ra685335 raa7a56e 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Mar 27 10:19:00 202013 // Update Count : 1 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 22 18:17:34 2018 13 // Update Count : 11 14 14 // 15 15 … … 41 41 42 42 // Base exception vtable is abstract, you should not have base exceptions. 43 struct __cfa ehm_base_exception_t_vtable44 ___cfa ehm_base_exception_t_vtable_instance = {43 struct __cfaabi_ehm__base_exception_t_vtable 44 ___cfaabi_ehm__base_exception_t_vtable_instance = { 45 45 .parent = NULL, 46 46 .size = 0, … … 53 53 // Temperary global exception context. Does not work with concurency. 54 54 struct exception_context_t { 55 struct __cfa ehm_try_resume_node * top_resume;56 struct __cfa ehm_try_resume_node * current_resume;55 struct __cfaabi_ehm__try_resume_node * top_resume; 56 struct __cfaabi_ehm__try_resume_node * current_resume; 57 57 58 58 exception_t * current_exception; … … 70 70 // RESUMPTION ================================================================ 71 71 72 void __cfa ehm_throw_resume(exception_t * except) {72 void __cfaabi_ehm__throw_resume(exception_t * except) { 73 73 struct exception_context_t * context = this_exception_context(); 74 74 75 75 __cfaabi_dbg_print_safe("Throwing resumption exception\n"); 76 76 77 struct __cfa ehm_try_resume_node * original_head = context->current_resume;78 struct __cfa ehm_try_resume_node * current =77 struct __cfaabi_ehm__try_resume_node * original_head = context->current_resume; 78 struct __cfaabi_ehm__try_resume_node * current = 79 79 (original_head) ? original_head->next : context->top_resume; 80 80 … … 91 91 92 92 // Fall back to termination: 93 __cfa ehm_throw_terminate(except);93 __cfaabi_ehm__throw_terminate(except); 94 94 // TODO: Default handler for resumption. 95 95 } … … 99 99 // be added after the node is built but before it is made the top node. 100 100 101 void __cfa ehm_try_resume_setup(struct __cfaehm_try_resume_node * node,101 void __cfaabi_ehm__try_resume_setup(struct __cfaabi_ehm__try_resume_node * node, 102 102 _Bool (*handler)(exception_t * except)) { 103 103 struct exception_context_t * context = this_exception_context(); … … 107 107 } 108 108 109 void __cfa ehm_try_resume_cleanup(struct __cfaehm_try_resume_node * node) {109 void __cfaabi_ehm__try_resume_cleanup(struct __cfaabi_ehm__try_resume_node * node) { 110 110 struct exception_context_t * context = this_exception_context(); 111 111 context->top_resume = node->next; … … 118 118 // May have to move to cfa for constructors and destructors (references). 119 119 120 struct __cfa ehm_node {121 struct __cfa ehm_node * next;120 struct __cfaabi_ehm__node { 121 struct __cfaabi_ehm__node * next; 122 122 }; 123 123 124 124 #define NODE_TO_EXCEPT(node) ((exception_t *)(1 + (node))) 125 #define EXCEPT_TO_NODE(except) ((struct __cfa ehm_node *)(except) - 1)125 #define EXCEPT_TO_NODE(except) ((struct __cfaabi_ehm__node *)(except) - 1) 126 126 127 127 // Creates a copy of the indicated exception and sets current_exception to it. 128 static void __cfa ehm_allocate_exception( exception_t * except ) {128 static void __cfaabi_ehm__allocate_exception( exception_t * except ) { 129 129 struct exception_context_t * context = this_exception_context(); 130 130 131 131 // Allocate memory for the exception. 132 struct __cfa ehm_node * store = malloc(133 sizeof( struct __cfa ehm_node ) + except->virtual_table->size );132 struct __cfaabi_ehm__node * store = malloc( 133 sizeof( struct __cfaabi_ehm__node ) + except->virtual_table->size ); 134 134 135 135 if ( ! store ) { … … 147 147 148 148 // Delete the provided exception, unsetting current_exception if relivant. 149 static void __cfa ehm_delete_exception( exception_t * except ) {149 static void __cfaabi_ehm__delete_exception( exception_t * except ) { 150 150 struct exception_context_t * context = this_exception_context(); 151 151 … … 153 153 154 154 // Remove the exception from the list. 155 struct __cfa ehm_node * to_free = EXCEPT_TO_NODE(except);156 struct __cfa ehm_node * node;155 struct __cfaabi_ehm__node * to_free = EXCEPT_TO_NODE(except); 156 struct __cfaabi_ehm__node * node; 157 157 158 158 if ( context->current_exception == except ) { … … 174 174 175 175 // If this isn't a rethrow (*except==0), delete the provided exception. 176 void __cfa ehm_cleanup_terminate( void * except ) {177 if ( *(void**)except ) __cfa ehm_delete_exception( *(exception_t **)except );176 void __cfaabi_ehm__cleanup_terminate( void * except ) { 177 if ( *(void**)except ) __cfaabi_ehm__delete_exception( *(exception_t **)except ); 178 178 } 179 179 … … 187 187 int version, 188 188 _Unwind_Action actions, 189 _Unwind_Exception_Class exception _class,189 _Unwind_Exception_Class exceptionClass, 190 190 struct _Unwind_Exception * unwind_exception, 191 191 struct _Unwind_Context * unwind_context, … … 198 198 199 199 // The exception that is being thrown must already be stored. 200 static __attribute__((noreturn)) void __cfaehm_begin_unwind(void) {200 __attribute__((noreturn)) void __cfaabi_ehm__begin_unwind(void) { 201 201 if ( ! this_exception_context()->current_exception ) { 202 202 printf("UNWIND ERROR missing exception in begin unwind\n"); … … 230 230 } 231 231 232 void __cfa ehm_throw_terminate( exception_t * val ) {232 void __cfaabi_ehm__throw_terminate( exception_t * val ) { 233 233 __cfaabi_dbg_print_safe("Throwing termination exception\n"); 234 234 235 __cfa ehm_allocate_exception( val );236 __cfa ehm_begin_unwind();237 } 238 239 void __cfa ehm_rethrow_terminate(void) {235 __cfaabi_ehm__allocate_exception( val ); 236 __cfaabi_ehm__begin_unwind(); 237 } 238 239 void __cfaabi_ehm__rethrow_terminate(void) { 240 240 __cfaabi_dbg_print_safe("Rethrowing termination exception\n"); 241 241 242 __cfa ehm_begin_unwind();242 __cfaabi_ehm__begin_unwind(); 243 243 } 244 244 … … 246 246 // ".cfi_personality 0x3,__gcfa_personality_v0" this function will be called twice when unwinding. 247 247 // Once in the search phase and once in the cleanup phase. 248 _Unwind_Reason_Code __gcfa_personality_v0( 249 int version, 250 _Unwind_Action actions, 251 unsigned long long exception_class, 252 struct _Unwind_Exception * unwind_exception, 253 struct _Unwind_Context * unwind_context) 248 _Unwind_Reason_Code __gcfa_personality_v0 ( 249 int version, _Unwind_Action actions, unsigned long long exceptionClass, 250 struct _Unwind_Exception* unwind_exception, 251 struct _Unwind_Context* unwind_context) 254 252 { 255 253 256 254 //__cfaabi_dbg_print_safe("CFA: 0x%lx\n", _Unwind_GetCFA(context)); 257 255 __cfaabi_dbg_print_safe("Personality function (%d, %x, %llu, %p, %p):", 258 version, actions, exception _class, unwind_exception, unwind_context);256 version, actions, exceptionClass, unwind_exception, unwind_context); 259 257 260 258 // If we've reached the end of the stack then there is nothing much we can do... … … 344 342 // - The BSP (Probably the base stack pointer) 345 343 344 346 345 // The current apprach uses one exception table entry per try block 347 346 _uleb128_t imatcher; … … 415 414 // and simply linked from libcfa but there is one problem left, see the exception table for details 416 415 __attribute__((noinline)) 417 void __cfa ehm_try_terminate(void (*try_block)(),416 void __cfaabi_ehm__try_terminate(void (*try_block)(), 418 417 void (*catch_block)(int index, exception_t * except), 419 418 __attribute__((unused)) int (*match_block)(exception_t * except)) { … … 481 480 // handler landing pad offset and 1 (action code, gcc seems to use 0). 482 481 ".LLSDACSBCFA2:\n" 483 " .uleb128 .TRYSTART-__cfa ehm_try_terminate\n"482 " .uleb128 .TRYSTART-__cfaabi_ehm__try_terminate\n" 484 483 " .uleb128 .TRYEND-.TRYSTART\n" 485 " .uleb128 .CATCH-__cfa ehm_try_terminate\n"484 " .uleb128 .CATCH-__cfaabi_ehm__try_terminate\n" 486 485 " .uleb128 1\n" 487 486 ".LLSDACSECFA2:\n" 488 487 // TABLE FOOTER 489 488 " .text\n" 490 " .size __cfa ehm_try_terminate, .-__cfaehm_try_terminate\n"489 " .size __cfaabi_ehm__try_terminate, .-__cfaabi_ehm__try_terminate\n" 491 490 ); 492 491 … … 525 524 ".LLSDACSBCFA2:\n" 526 525 // Handled area start (relative to start of function) 527 " .uleb128 .TRYSTART-__cfa ehm_try_terminate\n"526 " .uleb128 .TRYSTART-__cfaabi_ehm__try_terminate\n" 528 527 // Handled area length 529 528 " .uleb128 .TRYEND-.TRYSTART\n" 530 529 // Handler landing pad address (relative to start of function) 531 " .uleb128 .CATCH-__cfa ehm_try_terminate\n"530 " .uleb128 .CATCH-__cfaabi_ehm__try_terminate\n" 532 531 // Action code, gcc seems to always use 0. 533 532 " .uleb128 1\n" … … 535 534 ".LLSDACSECFA2:\n" 536 535 " .text\n" 537 " .size __cfa ehm_try_terminate, .-__cfaehm_try_terminate\n"536 " .size __cfaabi_ehm__try_terminate, .-__cfaabi_ehm__try_terminate\n" 538 537 " .ident \"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n" 539 538 " .section .note.GNU-stack,\"x\",@progbits\n" -
libcfa/src/exception.h
ra685335 raa7a56e 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Jun 26 15:11:00 2017 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Mar 27 10:16:00 202013 // Update Count : 911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 22 18:11:15 2018 13 // Update Count : 8 14 14 // 15 15 … … 21 21 #endif 22 22 23 struct __cfa ehm_base_exception_t;24 typedef struct __cfa ehm_base_exception_t exception_t;25 struct __cfa ehm_base_exception_t_vtable {26 const struct __cfa ehm_base_exception_t_vtable * parent;23 struct __cfaabi_ehm__base_exception_t; 24 typedef struct __cfaabi_ehm__base_exception_t exception_t; 25 struct __cfaabi_ehm__base_exception_t_vtable { 26 const struct __cfaabi_ehm__base_exception_t_vtable * parent; 27 27 size_t size; 28 void (*copy)(struct __cfa ehm_base_exception_t *this,29 struct __cfa ehm_base_exception_t * other);30 void (*free)(struct __cfa ehm_base_exception_t *this);31 const char * (*msg)(struct __cfa ehm_base_exception_t *this);28 void (*copy)(struct __cfaabi_ehm__base_exception_t *this, 29 struct __cfaabi_ehm__base_exception_t * other); 30 void (*free)(struct __cfaabi_ehm__base_exception_t *this); 31 const char * (*msg)(struct __cfaabi_ehm__base_exception_t *this); 32 32 }; 33 struct __cfa ehm_base_exception_t {34 struct __cfa ehm_base_exception_t_vtable const * virtual_table;33 struct __cfaabi_ehm__base_exception_t { 34 struct __cfaabi_ehm__base_exception_t_vtable const * virtual_table; 35 35 }; 36 extern struct __cfa ehm_base_exception_t_vtable37 ___cfa ehm_base_exception_t_vtable_instance;36 extern struct __cfaabi_ehm__base_exception_t_vtable 37 ___cfaabi_ehm__base_exception_t_vtable_instance; 38 38 39 39 40 40 // Used in throw statement translation. 41 void __cfa ehm_throw_terminate(exception_t * except) __attribute__((noreturn));42 void __cfa ehm_rethrow_terminate() __attribute__((noreturn));43 void __cfa ehm_throw_resume(exception_t * except);41 void __cfaabi_ehm__throw_terminate(exception_t * except) __attribute__((noreturn)); 42 void __cfaabi_ehm__rethrow_terminate() __attribute__((noreturn)); 43 void __cfaabi_ehm__throw_resume(exception_t * except); 44 44 45 45 // Function catches termination exceptions. 46 void __cfa ehm_try_terminate(46 void __cfaabi_ehm__try_terminate( 47 47 void (*try_block)(), 48 48 void (*catch_block)(int index, exception_t * except), … … 50 50 51 51 // Clean-up the exception in catch blocks. 52 void __cfa ehm_cleanup_terminate(void * except);52 void __cfaabi_ehm__cleanup_terminate(void * except); 53 53 54 54 // Data structure creates a list of resume handlers. 55 struct __cfa ehm_try_resume_node {56 struct __cfa ehm_try_resume_node * next;55 struct __cfaabi_ehm__try_resume_node { 56 struct __cfaabi_ehm__try_resume_node * next; 57 57 _Bool (*handler)(exception_t * except); 58 58 }; 59 59 60 60 // These act as constructor and destructor for the resume node. 61 void __cfa ehm_try_resume_setup(62 struct __cfa ehm_try_resume_node * node,61 void __cfaabi_ehm__try_resume_setup( 62 struct __cfaabi_ehm__try_resume_node * node, 63 63 _Bool (*handler)(exception_t * except)); 64 void __cfa ehm_try_resume_cleanup(65 struct __cfa ehm_try_resume_node * node);64 void __cfaabi_ehm__try_resume_cleanup( 65 struct __cfaabi_ehm__try_resume_node * node); 66 66 67 67 // Check for a standard way to call fake deconstructors. 68 struct __cfa ehm_cleanup_hook {};68 struct __cfaabi_ehm__cleanup_hook {}; 69 69 70 70 #ifdef __cforall -
src/ControlStruct/ExceptTranslate.cc
ra685335 raa7a56e 9 9 // Author : Andrew Beach 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Mar 27 11:58:00 202013 // Update Count : 1 311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:40:15 2019 13 // Update Count : 12 14 14 // 15 15 … … 211 211 ThrowStmt *throwStmt ) { 212 212 // __throw_terminate( `throwStmt->get_name()` ); } 213 return create_given_throw( "__cfa ehm_throw_terminate", throwStmt );213 return create_given_throw( "__cfaabi_ehm__throw_terminate", throwStmt ); 214 214 } 215 215 … … 232 232 ) ) ); 233 233 result->push_back( new ExprStmt( 234 new UntypedExpr( new NameExpr( "__cfa ehm_rethrow_terminate" ) )234 new UntypedExpr( new NameExpr( "__cfaabi_ehm__rethrow_terminate" ) ) 235 235 ) ); 236 236 delete throwStmt; … … 241 241 ThrowStmt *throwStmt ) { 242 242 // __throw_resume( `throwStmt->get_name` ); 243 return create_given_throw( "__cfa ehm_throw_resume", throwStmt );243 return create_given_throw( "__cfaabi_ehm__throw_resume", throwStmt ); 244 244 } 245 245 … … 309 309 local_except->get_attributes().push_back( new Attribute( 310 310 "cleanup", 311 { new NameExpr( "__cfa ehm_cleanup_terminate" ) }311 { new NameExpr( "__cfaabi_ehm__cleanup_terminate" ) } 312 312 ) ); 313 313 … … 429 429 FunctionDecl * terminate_catch, 430 430 FunctionDecl * terminate_match ) { 431 // { __cfa ehm_try_terminate(`try`, `catch`, `match`); }431 // { __cfaabi_ehm__try_terminate(`try`, `catch`, `match`); } 432 432 433 433 UntypedExpr * caller = new UntypedExpr( new NameExpr( 434 "__cfa ehm_try_terminate" ) );434 "__cfaabi_ehm__try_terminate" ) ); 435 435 std::list<Expression *>& args = caller->get_args(); 436 436 args.push_back( nameOf( try_wrapper ) ); … … 486 486 487 487 // struct __try_resume_node __resume_node 488 // __attribute__((cleanup( __cfa ehm_try_resume_cleanup )));488 // __attribute__((cleanup( __cfaabi_ehm__try_resume_cleanup ))); 489 489 // ** unwinding of the stack here could cause problems ** 490 490 // ** however I don't think that can happen currently ** 491 // __cfa ehm_try_resume_setup( &__resume_node, resume_handler );491 // __cfaabi_ehm__try_resume_setup( &__resume_node, resume_handler ); 492 492 493 493 std::list< Attribute * > attributes; … … 495 495 std::list< Expression * > attr_params; 496 496 attr_params.push_back( new NameExpr( 497 "__cfa ehm_try_resume_cleanup" ) );497 "__cfaabi_ehm__try_resume_cleanup" ) ); 498 498 attributes.push_back( new Attribute( "cleanup", attr_params ) ); 499 499 } … … 514 514 515 515 UntypedExpr *setup = new UntypedExpr( new NameExpr( 516 "__cfa ehm_try_resume_setup" ) );516 "__cfaabi_ehm__try_resume_setup" ) ); 517 517 setup->get_args().push_back( new AddressExpr( nameOf( obj ) ) ); 518 518 setup->get_args().push_back( nameOf( resume_handler ) ); … … 539 539 ObjectDecl * ExceptionMutatorCore::create_finally_hook( 540 540 FunctionDecl * finally_wrapper ) { 541 // struct __cfa ehm_cleanup_hook __finally_hook541 // struct __cfaabi_ehm__cleanup_hook __finally_hook 542 542 // __attribute__((cleanup( finally_wrapper ))); 543 543 … … 593 593 // Skip children? 594 594 return; 595 } else if ( structDecl->get_name() == "__cfa ehm_base_exception_t" ) {595 } else if ( structDecl->get_name() == "__cfaabi_ehm__base_exception_t" ) { 596 596 assert( nullptr == except_decl ); 597 597 except_decl = structDecl; 598 598 init_func_types(); 599 } else if ( structDecl->get_name() == "__cfa ehm_try_resume_node" ) {599 } else if ( structDecl->get_name() == "__cfaabi_ehm__try_resume_node" ) { 600 600 assert( nullptr == node_decl ); 601 601 node_decl = structDecl; 602 } else if ( structDecl->get_name() == "__cfa ehm_cleanup_hook" ) {602 } else if ( structDecl->get_name() == "__cfaabi_ehm__cleanup_hook" ) { 603 603 assert( nullptr == hook_decl ); 604 604 hook_decl = structDecl; -
src/ResolvExpr/Resolver.cc
ra685335 raa7a56e 9 9 // Author : Aaron B. Moss 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : A ndrew Beach12 // Last Modified On : Fri Mar 27 11:58:00 202013 // Update Count : 24 211 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Wed May 29 11:00:00 2019 13 // Update Count : 241 14 14 // 15 15 … … 560 560 // TODO: Replace *exception type with &exception type. 561 561 if ( throwStmt->get_expr() ) { 562 const StructDecl * exception_decl = indexer.lookupStruct( "__cfa ehm_base_exception_t" );562 const StructDecl * exception_decl = indexer.lookupStruct( "__cfaabi_ehm__base_exception_t" ); 563 563 assert( exception_decl ); 564 564 Type * exceptType = new PointerType( noQualifiers, new StructInstType( noQualifiers, const_cast<StructDecl *>(exception_decl) ) ); … … 1477 1477 if ( throwStmt->expr ) { 1478 1478 const ast::StructDecl * exceptionDecl = 1479 symtab.lookupStruct( "__cfa ehm_base_exception_t" );1479 symtab.lookupStruct( "__cfaabi_ehm__base_exception_t" ); 1480 1480 assert( exceptionDecl ); 1481 1481 ast::ptr< ast::Type > exceptType = -
tests/exceptions/except-mac.hfa
ra685335 raa7a56e 7 7 8 8 // The fully (perhaps overly) qualified name of the base exception type: 9 #define BASE_EXCEPT __cfa ehm_base_exception_t9 #define BASE_EXCEPT __cfaabi_ehm__base_exception_t 10 10 11 11 // Get the name of the vtable type and vtable instance for an exception type:
Note:
See TracChangeset
for help on using the changeset viewer.