Changeset 307a732


Ignore:
Timestamp:
Jul 4, 2017, 11:52:33 AM (7 years ago)
Author:
Andrew Beach <ajbeach@…>
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
Message:

The exception handling code compilers and translates, but the translation crashes.

Files:
2 added
1 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ExceptTranslate.cc

    r86f384b r307a732  
    1010// Created On       : Wed Jun 14 16:49:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Jun 29 15:18:00 2017
     12// Last Modified On : Fri Jun 30 13:30:00 2017
    1313// Update Count     : 1
    1414//
     
    2222#include "SynTree/Attribute.h"
    2323
    24 namespace ControlFlow {
     24namespace ControlStruct {
    2525
    2626        // This (large) section could probably be moved out of the class
     
    2929        // Type(Qualifiers &, false, std::list<Attribute *> &)
    3030
    31         // void (*function)()
    32         static FunctionType void_func_t(Type::Qualifiers(), false);
     31        // void (*function)();
     32        static FunctionType try_func_t(Type::Qualifiers(), false);
    3333        // void (*function)(int, exception);
    3434        static FunctionType catch_func_t(Type::Qualifiers(), false);
     
    3737        // bool (*function)(exception);
    3838        static FunctionType handle_func_t(Type::Qualifiers(), false);
     39        // void (*function)(__attribute__((unused)) void *);
     40        static FunctionType finally_func_t(Type::Qualifiers(), false);
    3941
    4042        static void init_func_types() {
     
    4850                        LinkageSpec::Cforall,
    4951                        /*bitfieldWidth*/ NULL,
    50                         new BasicType(emptyQualifiers, BasicType::UnsignedInt),
     52                        new BasicType( emptyQualifiers, BasicType::SignedInt ),
    5153                        /*init*/ NULL
    52                 );
     54                        );
    5355                ObjectDecl exception_obj(
    5456                        "__exception_inst",
     
    5658                        LinkageSpec::Cforall,
    5759                        /*bitfieldWidth*/ NULL,
    58                         new BasicType(emptyQualifiers, BasicType::UnsignedInt),
     60                        new PointerType(
     61                                emptyQualifiers,
     62                                new BasicType( emptyQualifiers, BasicType::SignedInt )
     63                                ),
    5964                        /*init*/ NULL
    60                 );
     65                        );
    6166                ObjectDecl bool_obj(
    6267                        "__ret_bool",
     
    6671                        new BasicType(emptyQualifiers, BasicType::Bool),
    6772                        /*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() );
    7696
    7797                init_complete = true;
     
    114134        // ThrowStmt Mutation Helpers
    115135
    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 ) );
    122152                throwStmt->set_expr( nullptr );
    123153                delete throwStmt;
    124154                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 );
    125160        }
    126161        Statement * create_terminate_rethrow( ThrowStmt *throwStmt ) {
     
    136171        Statement * create_resume_throw( ThrowStmt *throwStmt ) {
    137172                // __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 );
    145174        }
    146175        Statement * create_resume_rethrow( ThrowStmt *throwStmt ) {
     
    164193
    165194                return new FunctionDecl( "try", Type::StorageClasses(),
    166                         LinkageSpec::Cforall, void_func_t.clone(), body );
     195                        LinkageSpec::Cforall, try_func_t.clone(), body );
    167196        }
    168197
     
    235264                        std::list<Expression *> args;
    236265                        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
    238273                        cond = new UntypedExpr( new NameExpr( "?==?" /*???*/), args );
    239274                }
     
    276311                        *it = nullptr;
    277312                }
     313
     314                body->push_back( new ReturnStmt( noLabels, new ConstantExpr(
     315                        Constant::from_int( 0 ) ) ) );
    278316
    279317                return new FunctionDecl("match", Type::StorageClasses(),
     
    364402                UntypedExpr *setup = new UntypedExpr( new NameExpr(
    365403                        "__cfaehm__try_resume_setup" ) );
    366                 setup->get_args().push_back( nameOf( obj ) );
     404                setup->get_args().push_back( new AddressExpr( nameOf( obj ) ) );
    367405                setup->get_args().push_back( nameOf( resume_handler ) );
    368406
     
    381419
    382420                return new FunctionDecl("finally", Type::StorageClasses(),
    383                         LinkageSpec::Cforall, void_func_t.clone(), body);
     421                        LinkageSpec::Cforall, finally_func_t.clone(), body);
    384422        }
    385423
  • src/ControlStruct/ExceptTranslate.h

    r86f384b r307a732  
    1010// Created On       : Tus Jun 06 10:13:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Jun 29 15:18:00 2017
    13 // Update Count     : 1
     12// Last Modified On : Fri Jun 30 10:20:00 2017
     13// Update Count     : 2
    1414//
    1515
     
    2020#include "SynTree/SynTree.h"
    2121
    22 namespace ControlFlow {
     22namespace ControlStruct {
    2323        void translateEHM( std::list< Declaration *> & translationUnit );
    2424        /* Converts exception handling structures into their underlying C code.
  • src/Parser/parser.yy

    r86f384b r307a732  
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Sep  1 20:22:55 2001
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 28 22:11:22 2017
    13 // Update Count     : 2414
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Jun 30 15:38:00 2017
     13// Update Count     : 2415
    1414//
    1515
     
    104104        std::string * str;
    105105        bool flag;
     106        CatchStmt::Kind catch_kind;
    106107}
    107108
     
    192193%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    193194%type<sn> /* handler_list */                    handler_clause                          finally_clause
     195%type<catch_kind> handler_key
    194196
    195197// declarations
     
    958960handler_clause:
    959961        // 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
     973handler_key:
     974        CATCH
     975                { $$ = CatchStmt::Terminate; }
     976        | CATCHRESUME
     977                { $$ = CatchStmt::Resume; }
    973978        ;
    974979
  • src/ResolvExpr/Resolver.cc

    r86f384b r307a732  
    7070                virtual void visit( BranchStmt *branchStmt ) override;
    7171                virtual void visit( ReturnStmt *returnStmt ) override;
     72                virtual void visit( ThrowStmt *throwStmt ) override;
    7273
    7374                virtual void visit( SingleInit *singleInit ) override;
     
    366367        }
    367368
     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
    368377        template< typename T >
    369378        bool isCharType( T t ) {
  • src/SymTab/Indexer.cc

    r86f384b r307a732  
    652652                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
    653653                                // 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;
    655655                        }
    656656                }
     
    669669                                // check for C decls with the same name, skipping
    670670                                // 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;
    672672                        }
    673673                }
     
    724724                        // new definition shadows the autogenerated one, even at the same scope
    725725                        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() ) ) {
    727727                        // typesCompatible doesn't really do the right thing here. When checking compatibility of function types,
    728728                        // we should ignore outermost pointer qualifiers, except _Atomic?
     
    765765
    766766                // 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() ) ) {
    768768                        // NOTE this is broken in Richard's original code in such a way that it never triggers (it
    769769                        // doesn't check decls that have the same manglename, and all C-linkage decls are defined to
  • src/libcfa/Makefile.am

    r86f384b r307a732  
    5050
    5151libobjs = ${headers:=.o}
    52 libsrc = libcfa-prelude.c interpose.c libhdr/libdebug.c ${headers:=.c}
     52libsrc = libcfa-prelude.c interpose.c libhdr/libdebug.c ${headers:=.c} exception.c
    5353
    5454# not all platforms support concurrency, add option do disable it
  • src/libcfa/Makefile.in

    r86f384b r307a732  
    102102        containers/pair.c containers/result.c containers/vector.c \
    103103        concurrency/coroutine.c concurrency/thread.c \
    104         concurrency/kernel.c concurrency/monitor.c \
     104        concurrency/kernel.c concurrency/monitor.c exception.c \
    105105        concurrency/CtxSwitch-@MACHINE_TYPE@.S concurrency/alarm.c \
    106106        concurrency/invoke.c concurrency/preemption.c
     
    126126        libcfa_d_a-interpose.$(OBJEXT) \
    127127        libhdr/libcfa_d_a-libdebug.$(OBJEXT) $(am__objects_2) \
    128         $(am__objects_3)
     128        libcfa_d_a-exception.$(OBJEXT) $(am__objects_3)
    129129am_libcfa_d_a_OBJECTS = $(am__objects_4)
    130130libcfa_d_a_OBJECTS = $(am_libcfa_d_a_OBJECTS)
     
    136136        containers/pair.c containers/result.c containers/vector.c \
    137137        concurrency/coroutine.c concurrency/thread.c \
    138         concurrency/kernel.c concurrency/monitor.c \
     138        concurrency/kernel.c concurrency/monitor.c exception.c \
    139139        concurrency/CtxSwitch-@MACHINE_TYPE@.S concurrency/alarm.c \
    140140        concurrency/invoke.c concurrency/preemption.c
     
    158158        libcfa_a-interpose.$(OBJEXT) \
    159159        libhdr/libcfa_a-libdebug.$(OBJEXT) $(am__objects_6) \
    160         $(am__objects_7)
     160        libcfa_a-exception.$(OBJEXT) $(am__objects_7)
    161161am_libcfa_a_OBJECTS = $(am__objects_8)
    162162libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS)
     
    328328libobjs = ${headers:=.o}
    329329libsrc = libcfa-prelude.c interpose.c libhdr/libdebug.c ${headers:=.c} \
    330         $(am__append_4)
     330        exception.c $(am__append_4)
    331331libcfa_a_SOURCES = ${libsrc}
    332332libcfa_a_CFLAGS = -nodebug -O2
     
    514514
    515515@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@
    516517@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_a-fstream.Po@am__quote@
    517518@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_a-interpose.Po@am__quote@
     
    524525@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_a-stdlib.Po@am__quote@
    525526@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@
    526528@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_d_a-fstream.Po@am__quote@
    527529@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa_d_a-interpose.Po@am__quote@
     
    850852@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`
    851853
     854libcfa_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
    852861concurrency/libcfa_d_a-alarm.o: concurrency/alarm.c
    853862@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
     
    11431152@AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    11441153@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
     1155libcfa_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`
    11451161
    11461162concurrency/libcfa_a-alarm.o: concurrency/alarm.c
  • src/libcfa/exception.c

    r86f384b r307a732  
    4444// RESUMPTION ================================================================
    4545
    46 void __cfaehm__throw_resume(exception except) {
    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 =
     46void __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 =
    5353                (original_head) ? original_head->next : shared_stack.top_resume;
    5454
    5555        for ( ; current ; current = current->next) {
    5656                shared_stack.current_resume = current;
    57                 if (current->try_to_handle(except)) {
     57                if (current->handler(except)) {
    5858                        shared_stack.current_resume = original_head;
    5959                        return;
     
    6161        }
    6262
    63         printf("Unhandled exception %d\n", except);
     63        printf("Unhandled exception %d\n", *except);
    6464        shared_stack.current_resume = original_head;
    6565
    6666        // Fall back to termination:
    67         __cfaehm__throw_terminate(except);
     67        __cfaehm__throw_termination(except);
    6868        // TODO: Default handler for resumption.
    6969}
     
    7373 * after the node is built but before it is made the top node.
    7474 */
    75 void __try_resume_setup(struct __try_resume_node * node,
    76                         bool (*handler)(exception except)) {
     75void __cfaehm__try_resume_setup(struct __cfaehm__try_resume_node * node,
     76                        int (*handler)(exception * except)) {
    7777        node->next = shared_stack.top_resume;
    78         node->try_to_handle = handler;
     78        node->handler = handler;
    7979        shared_stack.top_resume = node;
    8080}
    8181
    82 void __try_resume_cleanup(struct __try_resume_node * node) {
     82void __cfaehm__try_resume_cleanup(struct __cfaehm__try_resume_node * node) {
    8383        shared_stack.top_resume = node->next;
    8484}
     
    111111}
    112112
    113 void __cfaehm__throw_terminate( int val ) {
     113void __cfaehm__throw_termination( exception * val ) {
    114114        // 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);
    119119
    120120        // Call stdlibc to raise the exception
     
    147147
    148148// Nesting this the other way would probably be faster.
    149 void __cfaehm__rethrow_terminate(void) {
     149void __cfaehm__rethrow_termination(void) {
    150150        // DEBUG
    151151        printf("Rethrowing termination exception\n");
    152152
    153         __cfaehm__throw_terminate(shared_stack.current_exception);
     153        __cfaehm__throw_termination(&shared_stack.current_exception);
    154154}
    155155
     
    322322// for details
    323323__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)) {
     324void __cfaehm__try_terminate(void (*try_block)(),
     325                void (*catch_block)(int index, exception * except),
     326                __attribute__((unused)) int (*match_block)(exception * except)) {
    327327        //! volatile int xy = 0;
    328328        //! printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
     
    364364        // Exception handler
    365365        catch_block(shared_stack.current_handler_index,
    366                     shared_stack.current_exception);
     366                    &shared_stack.current_exception);
    367367}
    368368
     
    384384        // Body uses language specific data and therefore could be modified arbitrarily
    385385        ".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)
    387387        "       .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)
    389389        "       .uleb128 1\n"                                           // Action code, gcc seems to use always 0
    390390        ".LLSDACSECFA2:\n"                                              // BODY end
    391391        "       .text\n"                                                        // TABLE footer
    392         "       .size   __try_terminate, .-__try_terminate\n"
     392        "       .size   __cfaehm__try_terminate, .-__cfaehm__try_terminate\n"
    393393        "       .ident  \"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n"
    394394//      "       .section        .note.GNU-stack,\"x\",@progbits\n"
  • src/libcfa/exception.h

    r86f384b r307a732  
    3838// Data structure creates a list of resume handlers.
    3939struct __cfaehm__try_resume_node {
    40     __cfaehm__try_resume_node * next;
     40    struct __cfaehm__try_resume_node * next;
    4141    int (*handler)(exception * except);
    4242};
    4343
    4444void __cfaehm__try_resume_setup(
    45     __cfaehm__try_resume_node * node,
     45    struct __cfaehm__try_resume_node * node,
    4646    int (*handler)(exception * except));
    4747void __cfaehm__try_resume_cleanup(
    48     __cfaehm__try_resume_node * node);
     48    struct __cfaehm__try_resume_node * node);
    4949
    5050// Check for a standard way to call fake deconstructors.
  • src/main.cc

    r86f384b r307a732  
    3939#include "CodeTools/TrackLoc.h"
    4040#include "ControlStruct/Mutate.h"
     41#include "ControlStruct/ExceptTranslate.h"
    4142#include "SymTab/Validate.h"
    4243#include "ResolvExpr/AlternativePrinter.h"
     
    290291                Tuples::expandUniqueExpr( translationUnit );
    291292
     293                OPTPRINT( "translateEHM" );
     294                ControlStruct::translateEHM( translationUnit );
     295
    292296                OPTPRINT( "convertSpecializations" ) // needs to happen before tuple types are expanded
    293297                GenPoly::convertSpecializations( translationUnit );
  • src/prelude/Makefile.am

    r86f384b r307a732  
    2323noinst_DATA = ../libcfa/libcfa-prelude.c
    2424
     25CC = ${abs_top_srcdir}/src/driver/cfa
     26
    2527$(DEPDIR) :
    2628        mkdir $(DEPDIR)
     
    4547
    4648# 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.Po
     49builtins.cf : builtins.c ${CC}
     50        ${AM_V_GEN}${CC} -E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po
    4951        ${AM_V_at}sed -i 's/builtins.o/builtins.cf/g' $(DEPDIR)/builtins.Po
    5052
  • src/prelude/Makefile.in

    r86f384b r307a732  
    9595AWK = @AWK@
    9696BACKEND_CC = @BACKEND_CC@
    97 CC = @CC@
     97CC = ${abs_top_srcdir}/src/driver/cfa
    9898CCAS = @CCAS@
    9999CCASDEPMODE = @CCASDEPMODE@
     
    444444
    445445# 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.Po
     446builtins.cf : builtins.c ${CC}
     447        ${AM_V_GEN}${CC} -E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po
    448448        ${AM_V_at}sed -i 's/builtins.o/builtins.cf/g' $(DEPDIR)/builtins.Po
    449449
  • tools/cfa.nanorc

    r86f384b r307a732  
    1818# Control Flow Structures
    1919color brightyellow "\<(if|else|while|do|for|switch|choose|case|default)\>"
    20 color brightyellow "\<(try|catch|catchResume|finally)\>"
     20color brightyellow "\<(try|catch(Resume)?|finally)\>"
    2121
    2222# Control Flow Statements
    23 color magenta "\<(return|break|continue|fallthru|throw|throwResume)\>"
     23color magenta "\<(goto|return|break|continue|fallthr(u|ough)|throw(Resume)?)\>"
    2424
    2525# Operator Names
Note: See TracChangeset for help on using the changeset viewer.