Changeset 307a732
- Timestamp:
- Jul 4, 2017, 11:52:33 AM (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:
- 44f44617, 67fa9f9, ad0be81
- Parents:
- 86f384b
- Files:
-
- 2 added
- 1 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ExceptTranslate.cc
r86f384b r307a732 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Jun 29 15:18:00 201712 // Last Modified On : Fri Jun 30 13:30:00 2017 13 13 // Update Count : 1 14 14 // … … 22 22 #include "SynTree/Attribute.h" 23 23 24 namespace Control Flow{24 namespace ControlStruct { 25 25 26 26 // This (large) section could probably be moved out of the class … … 29 29 // Type(Qualifiers &, false, std::list<Attribute *> &) 30 30 31 // void (*function)() 32 static FunctionType void_func_t(Type::Qualifiers(), false);31 // void (*function)(); 32 static FunctionType try_func_t(Type::Qualifiers(), false); 33 33 // void (*function)(int, exception); 34 34 static FunctionType catch_func_t(Type::Qualifiers(), false); … … 37 37 // bool (*function)(exception); 38 38 static FunctionType handle_func_t(Type::Qualifiers(), false); 39 // void (*function)(__attribute__((unused)) void *); 40 static FunctionType finally_func_t(Type::Qualifiers(), false); 39 41 40 42 static void init_func_types() { … … 48 50 LinkageSpec::Cforall, 49 51 /*bitfieldWidth*/ NULL, 50 new BasicType( emptyQualifiers, BasicType::UnsignedInt),52 new BasicType( emptyQualifiers, BasicType::SignedInt ), 51 53 /*init*/ NULL 52 );54 ); 53 55 ObjectDecl exception_obj( 54 56 "__exception_inst", … … 56 58 LinkageSpec::Cforall, 57 59 /*bitfieldWidth*/ NULL, 58 new BasicType(emptyQualifiers, BasicType::UnsignedInt), 60 new PointerType( 61 emptyQualifiers, 62 new BasicType( emptyQualifiers, BasicType::SignedInt ) 63 ), 59 64 /*init*/ NULL 60 );65 ); 61 66 ObjectDecl bool_obj( 62 67 "__ret_bool", … … 66 71 new BasicType(emptyQualifiers, BasicType::Bool), 67 72 /*init*/ NULL 68 ); 69 70 catch_func_t.get_parameters().push_back(index_obj.clone()); 71 catch_func_t.get_parameters().push_back(exception_obj.clone()); 72 match_func_t.get_returnVals().push_back(index_obj.clone()); 73 match_func_t.get_parameters().push_back(exception_obj.clone()); 74 handle_func_t.get_returnVals().push_back(bool_obj.clone()); 75 handle_func_t.get_parameters().push_back(exception_obj.clone()); 73 ); 74 ObjectDecl voidptr_obj( 75 "__hook", 76 Type::StorageClasses(), 77 LinkageSpec::Cforall, 78 NULL, 79 new PointerType( 80 emptyQualifiers, 81 new VoidType( 82 emptyQualifiers 83 ), 84 std::list<Attribute *>{new Attribute("unused")} 85 ), 86 NULL 87 ); 88 89 catch_func_t.get_parameters().push_back( index_obj.clone() ); 90 catch_func_t.get_parameters().push_back( exception_obj.clone() ); 91 match_func_t.get_returnVals().push_back( index_obj.clone() ); 92 match_func_t.get_parameters().push_back( exception_obj.clone() ); 93 handle_func_t.get_returnVals().push_back( bool_obj.clone() ); 94 handle_func_t.get_parameters().push_back( exception_obj.clone() ); 95 finally_func_t.get_parameters().push_back( voidptr_obj.clone() ); 76 96 77 97 init_complete = true; … … 114 134 // ThrowStmt Mutation Helpers 115 135 116 Statement * create_terminate_throw( ThrowStmt *throwStmt ) { 117 // __throw_terminate( EXPR ); 118 UntypedExpr * call = new UntypedExpr( new NameExpr( 119 "__cfaehm__throw_termination" ) ); 120 call->get_args().push_back( throwStmt->get_expr() ); 121 Statement * result = new ExprStmt( throwStmt->get_labels(), call ); 136 Statement * create_given_throw( 137 const char * throwFunc, ThrowStmt * throwStmt ) { 138 // { int NAME = EXPR; throwFunc( &NAME ); } 139 CompoundStmt * result = new CompoundStmt( noLabels ); 140 ObjectDecl * local = new ObjectDecl( 141 "__local_exception_copy", 142 Type::StorageClasses(), 143 LinkageSpec::Cforall, 144 NULL, 145 new BasicType( emptyQualifiers, BasicType::SignedInt ), 146 new SingleInit( throwStmt->get_expr() ) 147 ); 148 appendDeclStmt( result, local ); 149 UntypedExpr * call = new UntypedExpr( new NameExpr( throwFunc ) ); 150 call->get_args().push_back( new AddressExpr( nameOf( local ) ) ); 151 result->push_back( new ExprStmt( throwStmt->get_labels(), call ) ); 122 152 throwStmt->set_expr( nullptr ); 123 153 delete throwStmt; 124 154 return result; 155 } 156 157 Statement * create_terminate_throw( ThrowStmt *throwStmt ) { 158 // { int NAME = EXPR; __throw_terminate( &NAME ); } 159 return create_given_throw( "__cfaehm__throw_termination", throwStmt ); 125 160 } 126 161 Statement * create_terminate_rethrow( ThrowStmt *throwStmt ) { … … 136 171 Statement * create_resume_throw( ThrowStmt *throwStmt ) { 137 172 // __throw_resume( EXPR ); 138 UntypedExpr * call = new UntypedExpr( new NameExpr( 139 "__cfaehm__throw_resumption" ) ); 140 call->get_args().push_back( throwStmt->get_expr() ); 141 Statement * result = new ExprStmt( throwStmt->get_labels(), call ); 142 throwStmt->set_expr( nullptr ); 143 delete throwStmt; 144 return result; 173 return create_given_throw( "__cfaehm__throw_resumption", throwStmt ); 145 174 } 146 175 Statement * create_resume_rethrow( ThrowStmt *throwStmt ) { … … 164 193 165 194 return new FunctionDecl( "try", Type::StorageClasses(), 166 LinkageSpec::Cforall, void_func_t.clone(), body );195 LinkageSpec::Cforall, try_func_t.clone(), body ); 167 196 } 168 197 … … 235 264 std::list<Expression *> args; 236 265 args.push_back( number ); 237 args.push_back( nameOf( except_obj ) ); 266 267 std::list<Expression *> rhs_args; 268 rhs_args.push_back( nameOf( except_obj ) ); 269 Expression * rhs = new UntypedExpr( 270 new NameExpr( "*?" ), rhs_args ); 271 args.push_back( rhs ); 272 238 273 cond = new UntypedExpr( new NameExpr( "?==?" /*???*/), args ); 239 274 } … … 276 311 *it = nullptr; 277 312 } 313 314 body->push_back( new ReturnStmt( noLabels, new ConstantExpr( 315 Constant::from_int( 0 ) ) ) ); 278 316 279 317 return new FunctionDecl("match", Type::StorageClasses(), … … 364 402 UntypedExpr *setup = new UntypedExpr( new NameExpr( 365 403 "__cfaehm__try_resume_setup" ) ); 366 setup->get_args().push_back( n ameOf( obj) );404 setup->get_args().push_back( new AddressExpr( nameOf( obj ) ) ); 367 405 setup->get_args().push_back( nameOf( resume_handler ) ); 368 406 … … 381 419 382 420 return new FunctionDecl("finally", Type::StorageClasses(), 383 LinkageSpec::Cforall, void_func_t.clone(), body);421 LinkageSpec::Cforall, finally_func_t.clone(), body); 384 422 } 385 423 -
src/ControlStruct/ExceptTranslate.h
r86f384b r307a732 10 10 // Created On : Tus Jun 06 10:13:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Jun 29 15:18:00 201713 // Update Count : 112 // Last Modified On : Fri Jun 30 10:20:00 2017 13 // Update Count : 2 14 14 // 15 15 … … 20 20 #include "SynTree/SynTree.h" 21 21 22 namespace Control Flow{22 namespace ControlStruct { 23 23 void translateEHM( std::list< Declaration *> & translationUnit ); 24 24 /* Converts exception handling structures into their underlying C code. -
src/Parser/parser.yy
r86f384b r307a732 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Jun 28 22:11:22201713 // Update Count : 241 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jun 30 15:38:00 2017 13 // Update Count : 2415 14 14 // 15 15 … … 104 104 std::string * str; 105 105 bool flag; 106 CatchStmt::Kind catch_kind; 106 107 } 107 108 … … 192 193 %type<sn> switch_clause_list_opt switch_clause_list choose_clause_list_opt choose_clause_list 193 194 %type<sn> /* handler_list */ handler_clause finally_clause 195 %type<catch_kind> handler_key 194 196 195 197 // declarations … … 958 960 handler_clause: 959 961 // TEMPORARY, TEST EXCEPTIONS 960 CATCH '(' push push INTEGERconstant pop ')' compound_statement pop 961 { $$ = new StatementNode( build_catch( CatchStmt::Terminate, nullptr, new ExpressionNode( build_constantInteger( *$5 ) ), $8 ) ); } 962 | handler_clause CATCH '(' push push INTEGERconstant pop ')' compound_statement pop 963 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( CatchStmt::Terminate, nullptr, new ExpressionNode( build_constantInteger( *$6 ) ), $9 ) ) ); } 964 965 | CATCH '(' push push exception_declaration pop ')' compound_statement pop 966 { $$ = new StatementNode( build_catch( CatchStmt::Terminate, $5, nullptr, $8 ) ); } 967 | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop 968 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( CatchStmt::Terminate, $6, nullptr, $9 ) ) ); } 969 | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 970 { $$ = new StatementNode( build_catch( CatchStmt::Resume, $5, nullptr, $8 ) ); } 971 | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 972 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( CatchStmt::Resume, $6, nullptr, $9 ) ) ); } 962 handler_key '(' push push INTEGERconstant pop ')' compound_statement pop 963 { $$ = new StatementNode( build_catch( $1, nullptr, new ExpressionNode( build_constantInteger( *$5 ) ), $8 ) ); } 964 | handler_clause handler_key '(' push push INTEGERconstant pop ')' compound_statement pop 965 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, nullptr, new ExpressionNode( build_constantInteger( *$6 ) ), $9 ) ) ); } 966 967 | handler_key '(' push push exception_declaration pop ')' compound_statement pop 968 { $$ = new StatementNode( build_catch( $1, $5, nullptr, $8 ) ); } 969 | handler_clause handler_key '(' push push exception_declaration pop ')' compound_statement pop 970 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, nullptr, $9 ) ) ); } 971 ; 972 973 handler_key: 974 CATCH 975 { $$ = CatchStmt::Terminate; } 976 | CATCHRESUME 977 { $$ = CatchStmt::Resume; } 973 978 ; 974 979 -
src/ResolvExpr/Resolver.cc
r86f384b r307a732 70 70 virtual void visit( BranchStmt *branchStmt ) override; 71 71 virtual void visit( ReturnStmt *returnStmt ) override; 72 virtual void visit( ThrowStmt *throwStmt ) override; 72 73 73 74 virtual void visit( SingleInit *singleInit ) override; … … 366 367 } 367 368 369 void Resolver::visit( ThrowStmt *throwStmt ) { 370 if ( throwStmt->get_expr() ) { 371 Expression * wrapped = new CastExpr( throwStmt->get_expr(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 372 Expression * newExpr = findSingleExpression( wrapped, *this ); 373 throwStmt->set_expr( newExpr ); 374 } 375 } 376 368 377 template< typename T > 369 378 bool isCharType( T t ) { -
src/SymTab/Indexer.cc
r86f384b r307a732 652 652 for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) { 653 653 // check for C decls with the same name, skipping those with a compatible type (by mangleName) 654 if ( decl->second->get_linkage() == LinkageSpec::C&& decl->first != mangleName ) return true;654 if ( ! LinkageSpec::isMangled( decl->second->get_linkage() ) && decl->first != mangleName ) return true; 655 655 } 656 656 } … … 669 669 // check for C decls with the same name, skipping 670 670 // those with an incompatible type (by mangleName) 671 if ( decl->second->get_linkage() == LinkageSpec::C&& decl->first == mangleName ) return true;671 if ( ! LinkageSpec::isMangled( decl->second->get_linkage() ) && decl->first == mangleName ) return true; 672 672 } 673 673 } … … 724 724 // new definition shadows the autogenerated one, even at the same scope 725 725 return false; 726 } else if ( added->get_linkage() != LinkageSpec::C|| ResolvExpr::typesCompatible( added->get_type(), existing->get_type(), Indexer() ) ) {726 } else if ( LinkageSpec::isMangled( added->get_linkage() ) || ResolvExpr::typesCompatible( added->get_type(), existing->get_type(), Indexer() ) ) { 727 727 // typesCompatible doesn't really do the right thing here. When checking compatibility of function types, 728 728 // we should ignore outermost pointer qualifiers, except _Atomic? … … 765 765 766 766 // this ensures that no two declarations with the same unmangled name at the same scope both have C linkage 767 if ( decl->get_linkage() == LinkageSpec::C) {767 if ( ! LinkageSpec::isMangled( decl->get_linkage() ) ) { 768 768 // NOTE this is broken in Richard's original code in such a way that it never triggers (it 769 769 // doesn't check decls that have the same manglename, and all C-linkage decls are defined to -
src/libcfa/Makefile.am
r86f384b r307a732 50 50 51 51 libobjs = ${headers:=.o} 52 libsrc = libcfa-prelude.c interpose.c libhdr/libdebug.c ${headers:=.c} 52 libsrc = libcfa-prelude.c interpose.c libhdr/libdebug.c ${headers:=.c} exception.c 53 53 54 54 # not all platforms support concurrency, add option do disable it -
src/libcfa/Makefile.in
r86f384b r307a732 102 102 containers/pair.c containers/result.c containers/vector.c \ 103 103 concurrency/coroutine.c concurrency/thread.c \ 104 concurrency/kernel.c concurrency/monitor.c \104 concurrency/kernel.c concurrency/monitor.c exception.c \ 105 105 concurrency/CtxSwitch-@MACHINE_TYPE@.S concurrency/alarm.c \ 106 106 concurrency/invoke.c concurrency/preemption.c … … 126 126 libcfa_d_a-interpose.$(OBJEXT) \ 127 127 libhdr/libcfa_d_a-libdebug.$(OBJEXT) $(am__objects_2) \ 128 $(am__objects_3)128 libcfa_d_a-exception.$(OBJEXT) $(am__objects_3) 129 129 am_libcfa_d_a_OBJECTS = $(am__objects_4) 130 130 libcfa_d_a_OBJECTS = $(am_libcfa_d_a_OBJECTS) … … 136 136 containers/pair.c containers/result.c containers/vector.c \ 137 137 concurrency/coroutine.c concurrency/thread.c \ 138 concurrency/kernel.c concurrency/monitor.c \138 concurrency/kernel.c concurrency/monitor.c exception.c \ 139 139 concurrency/CtxSwitch-@MACHINE_TYPE@.S concurrency/alarm.c \ 140 140 concurrency/invoke.c concurrency/preemption.c … … 158 158 libcfa_a-interpose.$(OBJEXT) \ 159 159 libhdr/libcfa_a-libdebug.$(OBJEXT) $(am__objects_6) \ 160 $(am__objects_7)160 libcfa_a-exception.$(OBJEXT) $(am__objects_7) 161 161 am_libcfa_a_OBJECTS = $(am__objects_8) 162 162 libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS) … … 328 328 libobjs = ${headers:=.o} 329 329 libsrc = libcfa-prelude.c interpose.c libhdr/libdebug.c ${headers:=.c} \ 330 $(am__append_4)330 exception.c $(am__append_4) 331 331 libcfa_a_SOURCES = ${libsrc} 332 332 libcfa_a_CFLAGS = -nodebug -O2 … … 514 514 515 515 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_a-assert.Po@am__quote@ 516 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_a-exception.Po@am__quote@ 516 517 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_a-fstream.Po@am__quote@ 517 518 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_a-interpose.Po@am__quote@ … … 524 525 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_a-stdlib.Po@am__quote@ 525 526 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_d_a-assert.Po@am__quote@ 527 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_d_a-exception.Po@am__quote@ 526 528 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_d_a-fstream.Po@am__quote@ 527 529 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_d_a-interpose.Po@am__quote@ … … 850 852 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_d_a-monitor.obj `if test -f 'concurrency/monitor.c'; then $(CYGPATH_W) 'concurrency/monitor.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/monitor.c'; fi` 851 853 854 libcfa_d_a-exception.obj: exception.c 855 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT libcfa_d_a-exception.obj -MD -MP -MF $(DEPDIR)/libcfa_d_a-exception.Tpo -c -o libcfa_d_a-exception.obj `if test -f 'exception.c'; then $(CYGPATH_W) 'exception.c'; else $(CYGPATH_W) '$(srcdir)/exception.c'; fi` 856 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcfa_d_a-exception.Tpo $(DEPDIR)/libcfa_d_a-exception.Po 857 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='exception.c' object='libcfa_d_a-exception.obj' libtool=no @AMDEPBACKSLASH@ 858 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 859 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -c -o libcfa_d_a-exception.obj `if test -f 'exception.c'; then $(CYGPATH_W) 'exception.c'; else $(CYGPATH_W) '$(srcdir)/exception.c'; fi` 860 852 861 concurrency/libcfa_d_a-alarm.o: concurrency/alarm.c 853 862 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_d_a_CFLAGS) $(CFLAGS) -MT concurrency/libcfa_d_a-alarm.o -MD -MP -MF concurrency/$(DEPDIR)/libcfa_d_a-alarm.Tpo -c -o concurrency/libcfa_d_a-alarm.o `test -f 'concurrency/alarm.c' || echo '$(srcdir)/'`concurrency/alarm.c … … 1143 1152 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1144 1153 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o concurrency/libcfa_a-monitor.obj `if test -f 'concurrency/monitor.c'; then $(CYGPATH_W) 'concurrency/monitor.c'; else $(CYGPATH_W) '$(srcdir)/concurrency/monitor.c'; fi` 1154 1155 libcfa_a-exception.obj: exception.c 1156 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -MT libcfa_a-exception.obj -MD -MP -MF $(DEPDIR)/libcfa_a-exception.Tpo -c -o libcfa_a-exception.obj `if test -f 'exception.c'; then $(CYGPATH_W) 'exception.c'; else $(CYGPATH_W) '$(srcdir)/exception.c'; fi` 1157 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcfa_a-exception.Tpo $(DEPDIR)/libcfa_a-exception.Po 1158 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='exception.c' object='libcfa_a-exception.obj' libtool=no @AMDEPBACKSLASH@ 1159 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1160 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcfa_a_CFLAGS) $(CFLAGS) -c -o libcfa_a-exception.obj `if test -f 'exception.c'; then $(CYGPATH_W) 'exception.c'; else $(CYGPATH_W) '$(srcdir)/exception.c'; fi` 1145 1161 1146 1162 concurrency/libcfa_a-alarm.o: concurrency/alarm.c -
src/libcfa/exception.c
r86f384b r307a732 44 44 // RESUMPTION ================================================================ 45 45 46 void __cfaehm__throw_resum e(exceptionexcept) {47 48 // DEBUG 49 printf("Throwing resumption exception %d\n", except);50 51 struct __ try_resume_node * original_head = shared_stack.current_resume;52 struct __ try_resume_node * current =46 void __cfaehm__throw_resumption(exception * except) { 47 48 // DEBUG 49 printf("Throwing resumption exception %d\n", *except); 50 51 struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume; 52 struct __cfaehm__try_resume_node * current = 53 53 (original_head) ? original_head->next : shared_stack.top_resume; 54 54 55 55 for ( ; current ; current = current->next) { 56 56 shared_stack.current_resume = current; 57 if (current-> try_to_handle(except)) {57 if (current->handler(except)) { 58 58 shared_stack.current_resume = original_head; 59 59 return; … … 61 61 } 62 62 63 printf("Unhandled exception %d\n", except);63 printf("Unhandled exception %d\n", *except); 64 64 shared_stack.current_resume = original_head; 65 65 66 66 // Fall back to termination: 67 __cfaehm__throw_terminat e(except);67 __cfaehm__throw_termination(except); 68 68 // TODO: Default handler for resumption. 69 69 } … … 73 73 * after the node is built but before it is made the top node. 74 74 */ 75 void __ try_resume_setup(struct__try_resume_node * node,76 bool (*handler)(exceptionexcept)) {75 void __cfaehm__try_resume_setup(struct __cfaehm__try_resume_node * node, 76 int (*handler)(exception * except)) { 77 77 node->next = shared_stack.top_resume; 78 node-> try_to_handle= handler;78 node->handler = handler; 79 79 shared_stack.top_resume = node; 80 80 } 81 81 82 void __ try_resume_cleanup(struct__try_resume_node * node) {82 void __cfaehm__try_resume_cleanup(struct __cfaehm__try_resume_node * node) { 83 83 shared_stack.top_resume = node->next; 84 84 } … … 111 111 } 112 112 113 void __cfaehm__throw_terminat e( intval ) {113 void __cfaehm__throw_termination( exception * val ) { 114 114 // Store the current exception 115 shared_stack.current_exception = val;116 117 // DEBUG 118 printf("Throwing termination exception %d\n", val);115 shared_stack.current_exception = *val; 116 117 // DEBUG 118 printf("Throwing termination exception %d\n", *val); 119 119 120 120 // Call stdlibc to raise the exception … … 147 147 148 148 // Nesting this the other way would probably be faster. 149 void __cfaehm__rethrow_terminat e(void) {149 void __cfaehm__rethrow_termination(void) { 150 150 // DEBUG 151 151 printf("Rethrowing termination exception\n"); 152 152 153 __cfaehm__throw_terminat e(shared_stack.current_exception);153 __cfaehm__throw_termination(&shared_stack.current_exception); 154 154 } 155 155 … … 322 322 // for details 323 323 __attribute__((noinline)) 324 void __ try_terminate(void (*try_block)(),325 void (*catch_block)(int index, exception except),326 __attribute__((unused)) int (*match_block)(exception except)) {324 void __cfaehm__try_terminate(void (*try_block)(), 325 void (*catch_block)(int index, exception * except), 326 __attribute__((unused)) int (*match_block)(exception * except)) { 327 327 //! volatile int xy = 0; 328 328 //! printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy); … … 364 364 // Exception handler 365 365 catch_block(shared_stack.current_handler_index, 366 shared_stack.current_exception);366 &shared_stack.current_exception); 367 367 } 368 368 … … 384 384 // Body uses language specific data and therefore could be modified arbitrarily 385 385 ".LLSDACSBCFA2:\n" // BODY start 386 " .uleb128 .TRYSTART-__ try_terminate\n" // Handled area start (relative to start of function)386 " .uleb128 .TRYSTART-__cfaehm__try_terminate\n" // Handled area start (relative to start of function) 387 387 " .uleb128 .TRYEND-.TRYSTART\n" // Handled area length 388 " .uleb128 .CATCH-__ try_terminate\n" // Hanlder landing pad adress (relative to start of function)388 " .uleb128 .CATCH-__cfaehm__try_terminate\n" // Hanlder landing pad adress (relative to start of function) 389 389 " .uleb128 1\n" // Action code, gcc seems to use always 0 390 390 ".LLSDACSECFA2:\n" // BODY end 391 391 " .text\n" // TABLE footer 392 " .size __ try_terminate, .-__try_terminate\n"392 " .size __cfaehm__try_terminate, .-__cfaehm__try_terminate\n" 393 393 " .ident \"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n" 394 394 // " .section .note.GNU-stack,\"x\",@progbits\n" -
src/libcfa/exception.h
r86f384b r307a732 38 38 // Data structure creates a list of resume handlers. 39 39 struct __cfaehm__try_resume_node { 40 __cfaehm__try_resume_node * next;40 struct __cfaehm__try_resume_node * next; 41 41 int (*handler)(exception * except); 42 42 }; 43 43 44 44 void __cfaehm__try_resume_setup( 45 __cfaehm__try_resume_node * node,45 struct __cfaehm__try_resume_node * node, 46 46 int (*handler)(exception * except)); 47 47 void __cfaehm__try_resume_cleanup( 48 __cfaehm__try_resume_node * node);48 struct __cfaehm__try_resume_node * node); 49 49 50 50 // Check for a standard way to call fake deconstructors. -
src/main.cc
r86f384b r307a732 39 39 #include "CodeTools/TrackLoc.h" 40 40 #include "ControlStruct/Mutate.h" 41 #include "ControlStruct/ExceptTranslate.h" 41 42 #include "SymTab/Validate.h" 42 43 #include "ResolvExpr/AlternativePrinter.h" … … 290 291 Tuples::expandUniqueExpr( translationUnit ); 291 292 293 OPTPRINT( "translateEHM" ); 294 ControlStruct::translateEHM( translationUnit ); 295 292 296 OPTPRINT( "convertSpecializations" ) // needs to happen before tuple types are expanded 293 297 GenPoly::convertSpecializations( translationUnit ); -
src/prelude/Makefile.am
r86f384b r307a732 23 23 noinst_DATA = ../libcfa/libcfa-prelude.c 24 24 25 CC = ${abs_top_srcdir}/src/driver/cfa 26 25 27 $(DEPDIR) : 26 28 mkdir $(DEPDIR) … … 45 47 46 48 # create forward declarations for cfa builtins 47 builtins.cf : builtins.c 48 ${AM_V_GEN} @BACKEND_CC@-E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po49 builtins.cf : builtins.c ${CC} 50 ${AM_V_GEN}${CC} -E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po 49 51 ${AM_V_at}sed -i 's/builtins.o/builtins.cf/g' $(DEPDIR)/builtins.Po 50 52 -
src/prelude/Makefile.in
r86f384b r307a732 95 95 AWK = @AWK@ 96 96 BACKEND_CC = @BACKEND_CC@ 97 CC = @CC@97 CC = ${abs_top_srcdir}/src/driver/cfa 98 98 CCAS = @CCAS@ 99 99 CCASDEPMODE = @CCASDEPMODE@ … … 444 444 445 445 # create forward declarations for cfa builtins 446 builtins.cf : builtins.c 447 ${AM_V_GEN} @BACKEND_CC@-E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po446 builtins.cf : builtins.c ${CC} 447 ${AM_V_GEN}${CC} -E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po 448 448 ${AM_V_at}sed -i 's/builtins.o/builtins.cf/g' $(DEPDIR)/builtins.Po 449 449 -
tools/cfa.nanorc
r86f384b r307a732 18 18 # Control Flow Structures 19 19 color brightyellow "\<(if|else|while|do|for|switch|choose|case|default)\>" 20 color brightyellow "\<(try|catch |catchResume|finally)\>"20 color brightyellow "\<(try|catch(Resume)?|finally)\>" 21 21 22 22 # Control Flow Statements 23 color magenta "\<( return|break|continue|fallthru|throw|throwResume)\>"23 color magenta "\<(goto|return|break|continue|fallthr(u|ough)|throw(Resume)?)\>" 24 24 25 25 # Operator Names
Note: See TracChangeset
for help on using the changeset viewer.