Changeset e9145a3
- Timestamp:
- Aug 17, 2017, 4:13:42 PM (7 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:
- 8f6dfe7
- Parents:
- 21f0aa8
- Location:
- src
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ExceptTranslate.cc
r21f0aa8 re9145a3 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T us Aug 8 16:54:00 201713 // Update Count : 712 // Last Modified On : Thr Aug 17 15:48:00 2017 13 // Update Count : 8 14 14 // 15 15 … … 387 387 } 388 388 389 // TODO: Stoping the function from generating the 'return variable' 390 // entirely would be cleaner. But this does get ride of warnings. 391 CompoundStmt * set_and_ret(DeclarationWithType * var, Expression * val) { 392 CompoundStmt * block = new CompoundStmt( noLabels ); 393 block->push_back( new ExprStmt( noLabels, 394 UntypedExpr::createAssign( new VariableExpr( var ), val ) 395 ) ); 396 block->push_back( new ReturnStmt( noLabels, 397 new VariableExpr( var ) 398 ) ); 399 return block; 400 } 401 389 402 FunctionDecl * ExceptionMutatorCore::create_terminate_match( 390 403 CatchList &handlers ) { … … 397 410 FunctionType * func_type = match_func_t.clone(); 398 411 DeclarationWithType * except_obj = func_type->get_parameters().back(); 412 DeclarationWithType * index_obj = func_type->get_returnVals().front(); 399 413 400 414 // Index 1..{number of handlers} … … 409 423 410 424 // Create new body. 411 handler->set_body( new ReturnStmt( noLabels,425 handler->set_body( set_and_ret( index_obj, 412 426 new ConstantExpr( Constant::from_int( index ) ) ) ); 413 427 … … 417 431 } 418 432 419 body->push_back( new ReturnStmt( noLabels, new ConstantExpr(420 Constant::from_int( 0 ) ) ) );433 body->push_back( set_and_ret( index_obj, 434 new ConstantExpr( Constant::from_int( 0 ) ) ) ); 421 435 422 436 return new FunctionDecl("match", Type::StorageClasses(), … … 449 463 CompoundStmt * body = new CompoundStmt( noLabels ); 450 464 451 FunctionType * func_type = match_func_t.clone();465 FunctionType * func_type = handle_func_t.clone(); 452 466 DeclarationWithType * except_obj = func_type->get_parameters().back(); 467 DeclarationWithType * bool_obj = func_type->get_returnVals().front(); 453 468 454 469 CatchList::iterator it; … … 463 478 handling_code->push_back( handler->get_body() ); 464 479 } 465 handling_code->push_back( new ReturnStmt( noLabels,480 handling_code->push_back( set_and_ret( bool_obj, 466 481 new ConstantExpr( Constant::from_bool( true ) ) ) ); 467 482 handler->set_body( handling_code ); … … 472 487 } 473 488 474 body->push_back( new ReturnStmt( noLabels, new ConstantExpr(475 Constant::from_bool( false ) ) ) );489 body->push_back( set_and_ret( bool_obj, 490 new ConstantExpr( Constant::from_bool( false ) ) ) ); 476 491 477 492 return new FunctionDecl("handle", Type::StorageClasses(), -
src/driver/cfa.cc
r21f0aa8 re9145a3 9 9 // Author : Peter A. Buhr 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Jan 20 14:38:45201713 // Update Count : 15 511 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 17 15:24:00 2017 13 // Update Count : 156 14 14 // 15 15 … … 281 281 #endif //HAVE_LIBCFA 282 282 283 // Add exception flags (unconditionally) 284 args[nargs] = "-fexceptions"; 285 nargs += 1; 286 283 287 // add the correct set of flags based on the type of compile this is 284 288 -
src/libcfa/exception.c
r21f0aa8 re9145a3 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 4 15:20:00 201713 // Update Count : 612 // Last Modified On : Thr Aug 17 15:45:00 2017 13 // Update Count : 7 14 14 // 15 15 … … 23 23 #include <stdio.h> 24 24 #include <unwind.h> 25 #include <libhdr/libdebug.h> 25 26 26 27 // FIX ME: temporary hack to keep ARM build working … … 79 80 void __cfaehm__throw_resume(exception * except) { 80 81 81 // DEBUG 82 printf("Throwing resumption exception\n"); 82 LIB_DEBUG_PRINT_SAFE("Throwing resumption exception\n"); 83 83 84 84 struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume; … … 94 94 } 95 95 96 printf("Unhandled exception\n");96 LIB_DEBUG_PRINT_SAFE("Unhandled exception\n"); 97 97 shared_stack.current_resume = original_head; 98 98 … … 106 106 107 107 void __cfaehm__try_resume_setup(struct __cfaehm__try_resume_node * node, 108 int(*handler)(exception * except)) {108 _Bool (*handler)(exception * except)) { 109 109 node->next = shared_stack.top_resume; 110 110 node->handler = handler; … … 154 154 struct exception_context_t * context = this_exception_context(); 155 155 156 // DEBUG 157 printf( "Deleting Exception\n"); 156 LIB_DEBUG_PRINT_SAFE("Deleting Exception\n"); 158 157 159 158 // Remove the exception from the list. … … 235 234 236 235 void __cfaehm__throw_terminate( exception * val ) { 237 // DEBUG 238 printf("Throwing termination exception\n"); 236 LIB_DEBUG_PRINT_SAFE("Throwing termination exception\n"); 239 237 240 238 __cfaehm__allocate_exception( val ); … … 243 241 244 242 void __cfaehm__rethrow_terminate(void) { 245 // DEBUG 246 printf("Rethrowing termination exception\n"); 243 LIB_DEBUG_PRINT_SAFE("Rethrowing termination exception\n"); 247 244 248 245 __cfaehm__begin_unwind(); … … 257 254 { 258 255 259 // DEBUG 260 //printf("CFA: 0x%lx\n", _Unwind_GetCFA(context)); 261 printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context); 256 //LIB_DEBUG_PRINT_SAFE("CFA: 0x%lx\n", _Unwind_GetCFA(context)); 257 LIB_DEBUG_PRINT_SAFE("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context); 262 258 263 259 // If we've reached the end of the stack then there is nothing much we can do... 264 260 if( actions & _UA_END_OF_STACK ) return _URC_END_OF_STACK; 265 261 266 // DEBUG267 262 if (actions & _UA_SEARCH_PHASE) { 268 printf(" lookup phase"); 269 } 270 // DEBUG 263 LIB_DEBUG_PRINT_SAFE(" lookup phase"); 264 } 271 265 else if (actions & _UA_CLEANUP_PHASE) { 272 printf(" cleanup phase");266 LIB_DEBUG_PRINT_SAFE(" cleanup phase"); 273 267 } 274 268 // Just in case, probably can't actually happen … … 306 300 // Have we reach the correct frame info yet? 307 301 if( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) { 308 //DEBUG BEGIN 302 #ifdef __CFA_DEBUG_PRINT__ 309 303 void * ls = (void*)lsd_info.Start; 310 304 void * cs = (void*)callsite_start; … … 313 307 void * ep = (void*)lsd_info.Start + callsite_start + callsite_len; 314 308 void * ip = (void*)instruction_ptr; 315 printf("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip);316 //DEBUG END 309 LIB_DEBUG_PRINT_SAFE("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip); 310 #endif // __CFA_DEBUG_PRINT__ 317 311 continue; 318 312 } … … 362 356 363 357 // Based on the return value, check if we matched the exception 364 if( ret == _URC_HANDLER_FOUND) printf(" handler found\n"); 365 else printf(" no handler\n"); 358 if( ret == _URC_HANDLER_FOUND) { 359 LIB_DEBUG_PRINT_SAFE(" handler found\n"); 360 } else { 361 LIB_DEBUG_PRINT_SAFE(" no handler\n"); 362 } 366 363 return ret; 367 364 } 368 365 369 366 // This is only a cleanup handler, ignore it 370 printf(" no action");367 LIB_DEBUG_PRINT_SAFE(" no action"); 371 368 } 372 369 else if (actions & _UA_CLEANUP_PHASE) { … … 388 385 _Unwind_SetIP( context, ((lsd_info.LPStart) + (callsite_landing_pad)) ); 389 386 390 // DEBUG 391 printf(" action\n"); 387 LIB_DEBUG_PRINT_SAFE(" action\n"); 392 388 393 389 // Return have some action to run … … 397 393 398 394 // Nothing to do, move along 399 printf(" no landing pad");395 LIB_DEBUG_PRINT_SAFE(" no landing pad"); 400 396 } 401 397 // No handling found 402 printf(" table end reached\n"); 403 404 // DEBUG 398 LIB_DEBUG_PRINT_SAFE(" table end reached\n"); 399 405 400 UNWIND: 406 printf(" unwind\n");401 LIB_DEBUG_PRINT_SAFE(" unwind\n"); 407 402 408 403 // Keep unwinding the stack -
src/libcfa/exception.h
r21f0aa8 re9145a3 10 10 // Created On : Mon Jun 26 15:11:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 4 15:20:00 201713 // Update Count : 512 // Last Modified On : Thr Aug 17 15:44:00 2017 13 // Update Count : 6 14 14 // 15 15 … … 55 55 struct __cfaehm__try_resume_node { 56 56 struct __cfaehm__try_resume_node * next; 57 int(*handler)(exception * except);57 _Bool (*handler)(exception * except); 58 58 }; 59 59 … … 61 61 void __cfaehm__try_resume_setup( 62 62 struct __cfaehm__try_resume_node * node, 63 int(*handler)(exception * except));63 _Bool (*handler)(exception * except)); 64 64 void __cfaehm__try_resume_cleanup( 65 65 struct __cfaehm__try_resume_node * node); -
src/tests/except-0.c
r21f0aa8 re9145a3 7 7 #include <stdio.h> 8 8 #include <stdbool.h> 9 10 #include "except-mac.h" 11 TRIVIAL_EXCEPTION(yin) 12 TRIVIAL_EXCEPTION(yang) 13 TRIVIAL_EXCEPTION(zen) 14 9 15 10 16 // Local type to mark exits from scopes. (see ERROR) … … 23 29 24 30 25 // Local Exception Types and manual vtable types. 26 //#define TRIVIAL_EXCEPTION(name) //TRIVAL_EXCEPTION(yin) 27 struct yin; 28 struct yin_vtable { 29 struct exception_t_vtable const * parent; 30 size_t size; 31 void (*copy)(yin *this, yin * other); 32 void (*free)(yin *this); 33 const char (*msg)(yin *this); 34 }; 35 struct yin { 36 struct yin_vtable const * parent; 37 }; 38 void yin_msg(yin) { 39 return "in"; 40 } 41 yin_vtable _yin_vtable_instance = { 42 &_exception_t_vtable_instance, sizeof(yin), ?{}, ^?{}, yin_msg 43 } 44 45 46 void terminate(exception * except_value) { 31 // Mark throws: make sure to only pass in exception types. 32 forall(dtype T) 33 void terminate(T * except_value) { 47 34 signal_exit a = {"terminate function"}; 48 throw except_value;35 THROW(except_value); 49 36 printf("terminate returned\n"); 50 37 } 51 38 52 void resume(exception * except_value) { 39 forall(dtype T) 40 void resume(T * except_value) { 53 41 signal_exit a = {"resume function"}; 54 throwResume except_value;42 THROW_RESUME(except_value); 55 43 printf("resume returned\n"); 56 44 } … … 60 48 signal_exit a = {"bar function"}; 61 49 try { 62 terminate( 4);63 } catch ( 3) {64 printf("bar caught exception 3.\n");50 terminate(&(zen){}); 51 } catch (yin * error) { 52 printf("bar caught exception yin.\n"); 65 53 } 66 54 } … … 70 58 try { 71 59 bar(); 72 } catch ( 4) {73 printf("foo caught exception 4.\n");74 } catch ( 2) {75 printf("foo caught exception 2.\n");60 } catch (yang * error) { 61 printf("foo caught exception yang.\n"); 62 } catch (zen * error) { 63 printf("foo caught exception zen.\n"); 76 64 } 77 65 } … … 81 69 signal_exit a = {"beta function"}; 82 70 try { 83 resume(4); 84 } catchResume (3) { 85 printf("beta caught exception 3\n"); 71 zen x; 72 resume(&x); 73 } catchResume (yin * error) { 74 printf("beta caught exception yin\n"); 86 75 } 87 76 } … … 91 80 try { 92 81 beta(); 93 } catchResume ( 2) {94 printf("alpha caught exception 2\n");95 } catchResume ( 4) {96 printf("alpha caught exception 4\n");82 } catchResume (yang * error) { 83 printf("alpha caught exception yang\n"); 84 } catchResume (zen * error) { 85 printf("alpha caught exception zen\n"); 97 86 } 98 87 } … … 117 106 void fallback() { 118 107 try { 119 resume(2); 120 } catch (2) { 121 printf("fallback caught termination 2\n"); 108 zen x; 109 resume(&x); 110 } catch (zen * error) { 111 printf("fallback caught termination zen\n"); 122 112 } 123 113 } … … 127 117 signal_exit a = {"terminate_swap"}; 128 118 try { 129 terminate(2); 130 } catch (2) { 131 terminate(3); 119 yin x; 120 terminate(&x); 121 } catch (yin * error) { 122 yang y; 123 terminate(&y); 132 124 } 133 125 } … … 137 129 try { 138 130 terminate_swap(); 139 } catch ( 3) {140 printf("terminate_swapped caught exception 3\n");131 } catch (yang * error) { 132 printf("terminate_swapped caught exception yang\n"); 141 133 } 142 134 } … … 146 138 signal_exit a = {"resume_swap"}; 147 139 try { 148 resume(2); 149 } catchResume (2) { 150 resume(3); 140 yin x; 141 resume(&x); 142 } catchResume (yin * error) { 143 yang y; 144 resume(&y); 151 145 } 152 146 } … … 155 149 try { 156 150 resume_swap(); 157 } catchResume ( 3) {158 printf("resume_swapped caught exception 3\n");151 } catchResume (yang * error) { 152 printf("resume_swapped caught exception yang\n"); 159 153 } 160 154 } … … 164 158 try { 165 159 try { 166 terminate(2); 167 } catch (2) { 168 printf("reterminate 2 caught and " 169 "will rethrow exception 2\n"); 160 zen x; 161 terminate(&x); 162 } catch (zen * error) { 163 printf("reterminate zen caught and " 164 "will rethrow exception zen\n"); 170 165 throw; 171 166 } 172 } catch ( 2) {173 printf("reterminate 1 caught exception 2\n");167 } catch (zen * error) { 168 printf("reterminate 1 caught exception zen\n"); 174 169 } 175 170 } … … 179 174 try { 180 175 try { 181 resume(2); 182 } catchResume (2) { 183 printf("reresume 2 caught and rethrows exception 2\n"); 176 zen x; 177 resume(&x); 178 } catchResume (zen * error) { 179 printf("reresume zen caught and rethrows exception zen\n"); 184 180 throwResume; 185 181 } 186 } catchResume ( 2) {187 printf("reresume 1 caught exception 2\n");182 } catchResume (zen * error) { 183 printf("reresume 1 caught exception zen\n"); 188 184 } 189 185 } … … 193 189 // terminate block, call resume 194 190 try { 195 resume(3); 196 } catch (3) { 197 printf("fum caught exception 3\n"); 191 zen x; 192 resume(&x); 193 } catch (zen * error) { 194 printf("fum caught exception zen\n"); 198 195 } 199 196 } … … 202 199 // resume block, call terminate 203 200 try { 204 terminate(3); 205 } catchResume (3) { 206 printf("foe caught exception 3\n"); 201 zen y; 202 terminate(&y); 203 } catchResume (zen * error) { 204 printf("foe caught exception zen\n"); 207 205 } 208 206 } … … 212 210 try { 213 211 foe(); 214 } catch ( 3) {215 printf("fy caught exception 3\n");212 } catch (zen * error) { 213 printf("fy caught exception zen\n"); 216 214 fum(); 217 215 } … … 222 220 try { 223 221 fy(); 224 } catchResume ( 3) {225 printf("fee caught exception 3\n");222 } catchResume (zen * error) { 223 printf("fee caught exception zen\n"); 226 224 } 227 225 } … … 242 240 reresume(); printf("\n"); 243 241 fee(); printf("\n"); 242 244 243 // Uncaught termination test. 245 terminate(7); 246 } 244 printf("Throw uncaught.\n"); 245 yang z; 246 terminate(&z); 247 } -
src/tests/except-1.c
r21f0aa8 re9145a3 5 5 #include <stdio.h> 6 6 7 #include "except-mac.h" 8 TRIVIAL_EXCEPTION(yin) 9 TRIVIAL_EXCEPTION(yang) 10 7 11 int main() 8 12 { 9 13 try { 10 throw 3; 14 yin a; 15 THROW(&a); 11 16 } 12 catch( 3) {17 catch( yin * err ) { 13 18 printf("First Caught\n"); 14 19 try { 15 throw 4; 20 yang b; 21 THROW(&b); 16 22 } 17 catch( 4) {23 catch( yang * err ) { 18 24 printf("Both Caught\n"); 19 25 } … … 23 29 try { 24 30 try { 25 throw 2; 31 yang c; 32 THROW(&c); 26 33 } 27 catch( 2) {34 catch( yang * err ) { 28 35 printf("First Catch and rethrow\n"); 29 36 throw; 30 37 } 31 38 } 32 catch( 2) {39 catch( yang * err ) { 33 40 printf("Second Catch\n"); 34 41 } … … 37 44 try { 38 45 try { 39 throw 5; 46 yin d; 47 THROW(&d); 40 48 } 41 catch( 5) {49 catch( yin * err ) { 42 50 printf("Throw before cleanup\n"); 43 throw 6; 51 yang e; 52 THROW(&e); 44 53 } 45 54 } 46 catch( 6) {55 catch( yang * err ) { 47 56 printf("Catch after cleanup\n"); 48 57 } … … 51 60 try { 52 61 try { 53 throw 7; 62 yin f; 63 THROW(&f); 54 64 } 55 catch( 7) {65 catch( yin * err ) { 56 66 printf("Caught initial throw.\n"); 57 67 try { 58 throw 8; 68 yang g; 69 THROW(&g); 59 70 } 60 catch( 8) {71 catch( yang * err ) { 61 72 printf("Caught intermediate throw.\n"); 62 73 } … … 64 75 } 65 76 } 66 catch( 7) {77 catch( yin * err ) { 67 78 printf("Caught final throw.\n"); 68 79 } -
src/tests/except-2.c
r21f0aa8 re9145a3 2 2 3 3 4 #include <string.h> 4 #include <stdlib> 5 #include "except-mac.h" 5 6 6 // Local Exception Types and manual vtable types.7 #define GLUE2(left, right) left##right8 #define GLUE3(left, middle, right) left##middle##right9 #define BASE_EXCEPT __cfaehm__base_exception_t10 #define TABLE(name) GLUE2(name,_vtable)11 #define INSTANCE(name) GLUE3(_,name,_vtable_instance)12 #define TRIVIAL_EXCEPTION(name) \13 struct name; \14 struct TABLE(name) { \15 struct TABLE(BASE_EXCEPT) const * parent; \16 size_t size; \17 void (*copy)(name *this, name * other); \18 void (*free)(name *this); \19 const char * (*msg)(name *this); \20 }; \21 extern TABLE(name) INSTANCE(name); \22 struct name { \23 struct TABLE(name) const * virtual_table; \24 }; \25 const char * name##_msg(name * this) { \26 return #name; \27 } \28 void name##_copy(name * this, name * other) { \29 this->virtual_table = other->virtual_table; \30 } \31 TABLE(name) INSTANCE(name) @= { \32 .parent : &INSTANCE(BASE_EXCEPT), \33 .size : sizeof(name), .copy : name##_copy, \34 .free : ^?{}, .msg : name##_msg \35 }; \36 void ?{}(name * this) { \37 this->virtual_table = &INSTANCE(name); \38 }39 7 TRIVIAL_EXCEPTION(yin) 40 8 TRIVIAL_EXCEPTION(yang) … … 50 18 }; 51 19 extern num_error_vtable INSTANCE(num_error); 20 52 21 struct num_error { 53 22 struct num_error_vtable const * virtual_table; … … 55 24 int num; 56 25 }; 26 57 27 void num_error_msg(num_error * this) { 58 28 if ( ! this->msg ) { 59 const char * base = "Num Error with code: X"; 60 this->msg = strdup( base ); 29 static const char * base = "Num Error with code: X"; 30 this->msg = malloc(22); 31 for (int i = 0 ; (this->msg[i] = base[i]) ; ++i); 61 32 } 62 33 this->msg[21] = '0' + this->num; … … 90 61 try { 91 62 yin black; 92 throw (BASE_EXCEPT *)&black;63 THROW(&black); 93 64 } catch ( yin * error ) { 94 65 printf("throw yin caught.\n"); … … 97 68 try { 98 69 yang white; 99 throwResume (BASE_EXCEPT *)&white;70 THROW_RESUME(&white); 100 71 printf("> throwResume returned.\n"); 101 72 } catchResume ( yang * error ) { … … 105 76 try { 106 77 num_error x = { 2 }; 107 throw (BASE_EXCEPT *)&x;78 THROW(&x); 108 79 } 109 80 catch (num_error * error ; 3 == error->virtual_table->code( error ) ) {
Note: See TracChangeset
for help on using the changeset viewer.