Changeset 3090127
- Timestamp:
- Mar 30, 2020, 11:36:54 AM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- a685335
- Parents:
- bb2e05e
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/exception.c
rbb2e05e r3090127 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 : Thu Feb 22 18:17:34 201813 // Update Count : 1 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Mar 27 10:19:00 2020 13 // Update Count : 12 14 14 // 15 15 … … 41 41 42 42 // Base exception vtable is abstract, you should not have base exceptions. 43 struct __cfa abi_ehm__base_exception_t_vtable44 ___cfa abi_ehm__base_exception_t_vtable_instance = {43 struct __cfaehm_base_exception_t_vtable 44 ___cfaehm_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 abi_ehm__try_resume_node * top_resume;56 struct __cfa abi_ehm__try_resume_node * current_resume;55 struct __cfaehm_try_resume_node * top_resume; 56 struct __cfaehm_try_resume_node * current_resume; 57 57 58 58 exception_t * current_exception; … … 70 70 // RESUMPTION ================================================================ 71 71 72 void __cfa abi_ehm__throw_resume(exception_t * except) {72 void __cfaehm_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 abi_ehm__try_resume_node * original_head = context->current_resume;78 struct __cfa abi_ehm__try_resume_node * current =77 struct __cfaehm_try_resume_node * original_head = context->current_resume; 78 struct __cfaehm_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 abi_ehm__throw_terminate(except);93 __cfaehm_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 abi_ehm__try_resume_setup(struct __cfaabi_ehm__try_resume_node * node,101 void __cfaehm_try_resume_setup(struct __cfaehm_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 abi_ehm__try_resume_cleanup(struct __cfaabi_ehm__try_resume_node * node) {109 void __cfaehm_try_resume_cleanup(struct __cfaehm_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 abi_ehm__node {121 struct __cfa abi_ehm__node * next;120 struct __cfaehm_node { 121 struct __cfaehm_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 abi_ehm__node *)(except) - 1)125 #define EXCEPT_TO_NODE(except) ((struct __cfaehm_node *)(except) - 1) 126 126 127 127 // Creates a copy of the indicated exception and sets current_exception to it. 128 static void __cfa abi_ehm__allocate_exception( exception_t * except ) {128 static void __cfaehm_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 abi_ehm__node * store = malloc(133 sizeof( struct __cfa abi_ehm__node ) + except->virtual_table->size );132 struct __cfaehm_node * store = malloc( 133 sizeof( struct __cfaehm_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 abi_ehm__delete_exception( exception_t * except ) {149 static void __cfaehm_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 abi_ehm__node * to_free = EXCEPT_TO_NODE(except);156 struct __cfa abi_ehm__node * node;155 struct __cfaehm_node * to_free = EXCEPT_TO_NODE(except); 156 struct __cfaehm_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 abi_ehm__cleanup_terminate( void * except ) {177 if ( *(void**)except ) __cfa abi_ehm__delete_exception( *(exception_t **)except );176 void __cfaehm_cleanup_terminate( void * except ) { 177 if ( *(void**)except ) __cfaehm_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 exception_class, 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 __attribute__((noreturn)) void __cfaabi_ehm__begin_unwind(void) {200 static __attribute__((noreturn)) void __cfaehm_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 abi_ehm__throw_terminate( exception_t * val ) {232 void __cfaehm_throw_terminate( exception_t * val ) { 233 233 __cfaabi_dbg_print_safe("Throwing termination exception\n"); 234 234 235 __cfa abi_ehm__allocate_exception( val );236 __cfa abi_ehm__begin_unwind();237 } 238 239 void __cfa abi_ehm__rethrow_terminate(void) {235 __cfaehm_allocate_exception( val ); 236 __cfaehm_begin_unwind(); 237 } 238 239 void __cfaehm_rethrow_terminate(void) { 240 240 __cfaabi_dbg_print_safe("Rethrowing termination exception\n"); 241 241 242 __cfa abi_ehm__begin_unwind();242 __cfaehm_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, _Unwind_Action actions, unsigned long long exceptionClass, 250 struct _Unwind_Exception* unwind_exception, 251 struct _Unwind_Context* unwind_context) 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) 252 254 { 253 255 254 256 //__cfaabi_dbg_print_safe("CFA: 0x%lx\n", _Unwind_GetCFA(context)); 255 257 __cfaabi_dbg_print_safe("Personality function (%d, %x, %llu, %p, %p):", 256 version, actions, exception Class, unwind_exception, unwind_context);258 version, actions, exception_class, unwind_exception, unwind_context); 257 259 258 260 // If we've reached the end of the stack then there is nothing much we can do... … … 342 344 // - The BSP (Probably the base stack pointer) 343 345 344 345 346 // The current apprach uses one exception table entry per try block 346 347 _uleb128_t imatcher; … … 414 415 // and simply linked from libcfa but there is one problem left, see the exception table for details 415 416 __attribute__((noinline)) 416 void __cfa abi_ehm__try_terminate(void (*try_block)(),417 void __cfaehm_try_terminate(void (*try_block)(), 417 418 void (*catch_block)(int index, exception_t * except), 418 419 __attribute__((unused)) int (*match_block)(exception_t * except)) { … … 480 481 // handler landing pad offset and 1 (action code, gcc seems to use 0). 481 482 ".LLSDACSBCFA2:\n" 482 " .uleb128 .TRYSTART-__cfa abi_ehm__try_terminate\n"483 " .uleb128 .TRYSTART-__cfaehm_try_terminate\n" 483 484 " .uleb128 .TRYEND-.TRYSTART\n" 484 " .uleb128 .CATCH-__cfa abi_ehm__try_terminate\n"485 " .uleb128 .CATCH-__cfaehm_try_terminate\n" 485 486 " .uleb128 1\n" 486 487 ".LLSDACSECFA2:\n" 487 488 // TABLE FOOTER 488 489 " .text\n" 489 " .size __cfa abi_ehm__try_terminate, .-__cfaabi_ehm__try_terminate\n"490 " .size __cfaehm_try_terminate, .-__cfaehm_try_terminate\n" 490 491 ); 491 492 … … 524 525 ".LLSDACSBCFA2:\n" 525 526 // Handled area start (relative to start of function) 526 " .uleb128 .TRYSTART-__cfa abi_ehm__try_terminate\n"527 " .uleb128 .TRYSTART-__cfaehm_try_terminate\n" 527 528 // Handled area length 528 529 " .uleb128 .TRYEND-.TRYSTART\n" 529 530 // Handler landing pad address (relative to start of function) 530 " .uleb128 .CATCH-__cfa abi_ehm__try_terminate\n"531 " .uleb128 .CATCH-__cfaehm_try_terminate\n" 531 532 // Action code, gcc seems to always use 0. 532 533 " .uleb128 1\n" … … 534 535 ".LLSDACSECFA2:\n" 535 536 " .text\n" 536 " .size __cfa abi_ehm__try_terminate, .-__cfaabi_ehm__try_terminate\n"537 " .size __cfaehm_try_terminate, .-__cfaehm_try_terminate\n" 537 538 " .ident \"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n" 538 539 " .section .note.GNU-stack,\"x\",@progbits\n" -
libcfa/src/exception.h
rbb2e05e r3090127 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 : Thu Feb 22 18:11:15 201813 // Update Count : 811 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Mar 27 10:16:00 2020 13 // Update Count : 9 14 14 // 15 15 … … 21 21 #endif 22 22 23 struct __cfa abi_ehm__base_exception_t;24 typedef struct __cfa abi_ehm__base_exception_t exception_t;25 struct __cfa abi_ehm__base_exception_t_vtable {26 const struct __cfa abi_ehm__base_exception_t_vtable * parent;23 struct __cfaehm_base_exception_t; 24 typedef struct __cfaehm_base_exception_t exception_t; 25 struct __cfaehm_base_exception_t_vtable { 26 const struct __cfaehm_base_exception_t_vtable * parent; 27 27 size_t size; 28 void (*copy)(struct __cfa abi_ehm__base_exception_t *this,29 struct __cfa abi_ehm__base_exception_t * other);30 void (*free)(struct __cfa abi_ehm__base_exception_t *this);31 const char * (*msg)(struct __cfa abi_ehm__base_exception_t *this);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 32 }; 33 struct __cfa abi_ehm__base_exception_t {34 struct __cfa abi_ehm__base_exception_t_vtable const * virtual_table;33 struct __cfaehm_base_exception_t { 34 struct __cfaehm_base_exception_t_vtable const * virtual_table; 35 35 }; 36 extern struct __cfa abi_ehm__base_exception_t_vtable37 ___cfa abi_ehm__base_exception_t_vtable_instance;36 extern struct __cfaehm_base_exception_t_vtable 37 ___cfaehm_base_exception_t_vtable_instance; 38 38 39 39 40 40 // Used in throw statement translation. 41 void __cfa abi_ehm__throw_terminate(exception_t * except) __attribute__((noreturn));42 void __cfa abi_ehm__rethrow_terminate() __attribute__((noreturn));43 void __cfa abi_ehm__throw_resume(exception_t * except);41 void __cfaehm_throw_terminate(exception_t * except) __attribute__((noreturn)); 42 void __cfaehm_rethrow_terminate() __attribute__((noreturn)); 43 void __cfaehm_throw_resume(exception_t * except); 44 44 45 45 // Function catches termination exceptions. 46 void __cfa abi_ehm__try_terminate(46 void __cfaehm_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 abi_ehm__cleanup_terminate(void * except);52 void __cfaehm_cleanup_terminate(void * except); 53 53 54 54 // Data structure creates a list of resume handlers. 55 struct __cfa abi_ehm__try_resume_node {56 struct __cfa abi_ehm__try_resume_node * next;55 struct __cfaehm_try_resume_node { 56 struct __cfaehm_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 abi_ehm__try_resume_setup(62 struct __cfa abi_ehm__try_resume_node * node,61 void __cfaehm_try_resume_setup( 62 struct __cfaehm_try_resume_node * node, 63 63 _Bool (*handler)(exception_t * except)); 64 void __cfa abi_ehm__try_resume_cleanup(65 struct __cfa abi_ehm__try_resume_node * node);64 void __cfaehm_try_resume_cleanup( 65 struct __cfaehm_try_resume_node * node); 66 66 67 67 // Check for a standard way to call fake deconstructors. 68 struct __cfa abi_ehm__cleanup_hook {};68 struct __cfaehm_cleanup_hook {}; 69 69 70 70 #ifdef __cforall -
src/ControlStruct/ExceptTranslate.cc
rbb2e05e r3090127 9 9 // Author : Andrew Beach 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Dec 13 23:40:15 201913 // Update Count : 1 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Mar 27 11:58:00 2020 13 // Update Count : 13 14 14 // 15 15 … … 211 211 ThrowStmt *throwStmt ) { 212 212 // __throw_terminate( `throwStmt->get_name()` ); } 213 return create_given_throw( "__cfa abi_ehm__throw_terminate", throwStmt );213 return create_given_throw( "__cfaehm_throw_terminate", throwStmt ); 214 214 } 215 215 … … 232 232 ) ) ); 233 233 result->push_back( new ExprStmt( 234 new UntypedExpr( new NameExpr( "__cfa abi_ehm__rethrow_terminate" ) )234 new UntypedExpr( new NameExpr( "__cfaehm_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 abi_ehm__throw_resume", throwStmt );243 return create_given_throw( "__cfaehm_throw_resume", throwStmt ); 244 244 } 245 245 … … 309 309 local_except->get_attributes().push_back( new Attribute( 310 310 "cleanup", 311 { new NameExpr( "__cfa abi_ehm__cleanup_terminate" ) }311 { new NameExpr( "__cfaehm_cleanup_terminate" ) } 312 312 ) ); 313 313 … … 429 429 FunctionDecl * terminate_catch, 430 430 FunctionDecl * terminate_match ) { 431 // { __cfa abi_ehm__try_terminate(`try`, `catch`, `match`); }431 // { __cfaehm_try_terminate(`try`, `catch`, `match`); } 432 432 433 433 UntypedExpr * caller = new UntypedExpr( new NameExpr( 434 "__cfa abi_ehm__try_terminate" ) );434 "__cfaehm_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 abi_ehm__try_resume_cleanup )));488 // __attribute__((cleanup( __cfaehm_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 abi_ehm__try_resume_setup( &__resume_node, resume_handler );491 // __cfaehm_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 abi_ehm__try_resume_cleanup" ) );497 "__cfaehm_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 abi_ehm__try_resume_setup" ) );516 "__cfaehm_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 abi_ehm__cleanup_hook __finally_hook541 // struct __cfaehm_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 abi_ehm__base_exception_t" ) {595 } else if ( structDecl->get_name() == "__cfaehm_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 abi_ehm__try_resume_node" ) {599 } else if ( structDecl->get_name() == "__cfaehm_try_resume_node" ) { 600 600 assert( nullptr == node_decl ); 601 601 node_decl = structDecl; 602 } else if ( structDecl->get_name() == "__cfa abi_ehm__cleanup_hook" ) {602 } else if ( structDecl->get_name() == "__cfaehm_cleanup_hook" ) { 603 603 assert( nullptr == hook_decl ); 604 604 hook_decl = structDecl; -
src/ResolvExpr/Resolver.cc
rbb2e05e r3090127 9 9 // Author : Aaron B. Moss 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : A aron B. Moss12 // Last Modified On : Wed May 29 11:00:00 201913 // Update Count : 24 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Mar 27 11:58:00 2020 13 // Update Count : 242 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 abi_ehm__base_exception_t" );562 const StructDecl * exception_decl = indexer.lookupStruct( "__cfaehm_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 abi_ehm__base_exception_t" );1479 symtab.lookupStruct( "__cfaehm_base_exception_t" ); 1480 1480 assert( exceptionDecl ); 1481 1481 ast::ptr< ast::Type > exceptType = -
tests/exceptions/except-mac.hfa
rbb2e05e r3090127 7 7 8 8 // The fully (perhaps overly) qualified name of the base exception type: 9 #define BASE_EXCEPT __cfa abi_ehm__base_exception_t9 #define BASE_EXCEPT __cfaehm_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.