Changes in / [2c6c893:a4683611]
- Files:
-
- 6 edited
-
doc/working/exception/impl/except.c (modified) (3 diffs)
-
doc/working/exception/impl/main.c (modified) (5 diffs)
-
doc/working/exception/reference.c (modified) (1 diff)
-
src/Common/PassVisitor.impl.h (modified) (17 diffs)
-
src/Makefile.am (modified) (1 diff)
-
src/Makefile.in (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
doc/working/exception/impl/except.c
r2c6c893 ra4683611 4 4 5 5 #include "lsda.h" 6 7 // This macro should be the only thing that needs to change across machines.8 // struct _Unwind_Context * -> _Unwind_Reason_Code(*)()9 #define MATCHER_FROM_CONTEXT(ptr_to_context) \10 (*(_Unwind_Reason_Code(**)())(_Unwind_GetCFA(ptr_to_context) + 8))11 12 6 13 7 //Global which defines the current exception … … 23 17 struct _Unwind_Exception* unwind_exception, struct _Unwind_Context* context) 24 18 { 25 printf("CFA: 0x%lx\n", _Unwind_GetCFA(context));26 27 19 //DEBUG 28 20 printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context); … … 119 111 120 112 //Get a function pointer from the relative offset and call it 121 // _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher; 122 123 _Unwind_Reason_Code (*matcher)() = 124 MATCHER_FROM_CONTEXT(context); 113 _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher; 125 114 _Unwind_Reason_Code ret = matcher(); 126 115 -
doc/working/exception/impl/main.c
r2c6c893 ra4683611 1 1 #include <stdio.h> 2 2 #include "except.h" 3 4 // Requires -fexceptions to work.5 3 6 4 #define EXCEPTION 2 … … 28 26 extern int this_exception; 29 27 _Unwind_Reason_Code foo_try_match() { 30 printf(" (foo_try_match called)"); 31 return this_exception == EXCEPTION ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 28 return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 32 29 } 33 30 … … 37 34 //for details 38 35 __attribute__((noinline)) 39 void try( void (*try_block)(), void (*catch_block)(), 40 _Unwind_Reason_Code (*match_block)() ) 36 void try( void (*try_block)(), void (*catch_block)() ) 41 37 { 42 volatile int xy = 0;43 printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);44 45 38 //Setup statments 46 39 //These 2 statments won't actually result in any code, … … 102 95 " .uleb128 .CATCH-try\n" //Hanlder landing pad adress (relative to start of function) 103 96 " .uleb128 1\n" //Action code, gcc seems to use always 0 97 //Beyond this point we don't match gcc data' 98 " .uleb128 foo_try_match-try\n" //Handler routine to check if the exception is matched 104 99 ".LLSDACSECFA2:\n" //BODY end 105 100 " .text\n" //TABLE footer … … 127 122 128 123 //Actual call to the try block 129 try( foo_try_block, foo_catch_block , foo_try_match);124 try( foo_try_block, foo_catch_block ); 130 125 131 126 printf( "Foo exited normally\n" ); 132 127 } 133 128 134 // Not in main.cfa135 void fy() {136 // Currently not destroyed if the exception is caught in fee.137 raii_t a = { "Fy dtor" };138 139 void fy_try_block() {140 raii_t b = { "Fy try dtor" };141 142 throw( 3 );143 }144 145 void fy_catch_block() {146 printf("Fy caught exception\n");147 }148 149 _Unwind_Reason_Code fy_match_block() {150 return this_exception == 2 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;151 }152 153 try(fy_try_block, fy_catch_block, fy_match_block);154 155 printf( "Fy exited normally\n" );156 }157 158 void fee() {159 raii_t a = { "Fee dtor" };160 161 void fee_try_block() {162 raii_t b = { "Fee try dtor" };163 164 fy();165 166 printf("fy returned\n");167 }168 169 void fee_catch_block() {170 printf("Fee caught exception\n");171 }172 173 _Unwind_Reason_Code fee_match_block() {174 return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;175 }176 177 try(fee_try_block, fee_catch_block, fee_match_block);178 179 printf( "Fee exited normally\n" );180 }181 // End not in main.cfa182 183 129 int main() { 184 130 raii_t a = { "Main dtor" }; 185 131 186 //for (unsigned int i = 0 ; i < 100000000 ; ++i) 187 foo(); 188 fee(); 132 for (unsigned int i = 0 ; i < 100000000 ; ++i) foo(); 189 133 190 134 printf("End of program reached\n"); -
doc/working/exception/reference.c
r2c6c893 ra4683611 114 114 // __builtin_eh_return_data_regno(^) ^=[0..3]? gives index. 115 115 116 // Locally we also seem to have:117 _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);118 116 119 117 // GCC (Dwarf2 ?) Frame Layout Macros 120 // See: https://gcc.gnu.org/onlinedocs/gccint/Frame-Layout.html 121 // Include from: ??? 118 // https://gcc.gnu.org/onlinedocs/gccint/Frame-Layout.html 122 119 123 120 FIRST_PARAM_OFFSET(fundecl) -
src/Common/PassVisitor.impl.h
r2c6c893 ra4683611 1 1 #pragma once 2 3 #define VISIT_START( node ) \4 call_previsit( node ); \5 6 #define VISIT_END( node ) \7 return call_postvisit( node ); \8 2 9 3 #define MUTATE_START( node ) \ 10 4 call_premutate( node ); \ 11 5 6 12 7 #define MUTATE_END( type, node ) \ 13 8 return call_postmutate< type * >( node ); \ … … 15 10 16 11 #define VISIT_BODY( node ) \ 17 VISIT_START( node ); \12 call_previsit( node ); \ 18 13 Visitor::visit( node ); \ 19 VISIT_END( node ); \14 call_postvisit( node ); \ 20 15 21 16 … … 44 39 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 45 40 try { 46 (*i)->accept( *this );41 *i = (*i)->accept( *this ); 47 42 } catch ( SemanticError &e ) { 48 43 errors.append( e ); … … 83 78 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 84 79 85 maybeAccept( stmt, *this );80 Statement *newStmt = maybeVisit( stmt, *this ); 86 81 87 82 StmtList_t* beforeStmts = get_beforeStmts(); 88 83 StmtList_t* afterStmts = get_afterStmts(); 89 84 90 if( empty(beforeStmts) && empty(afterStmts) ) { return stmt; }85 if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; } 91 86 92 87 CompoundStmt *compound = new CompoundStmt( noLabels ); 93 88 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 94 compound->get_kids().push_back( stmt );89 compound->get_kids().push_back( newStmt ); 95 90 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 96 91 return compound; … … 192 187 } 193 188 194 //--------------------------------------------------------------------------195 // CompoundStmt196 189 template< typename pass_type > 197 190 void PassVisitor< pass_type >::visit( CompoundStmt * node ) { 198 VISIT_START( node ); 199 call_beginScope(); 200 201 visitStatementList( node->get_kids() ); 202 203 call_endScope(); 204 VISIT_END( node ); 191 VISIT_BODY( node ); 205 192 } 206 193 … … 216 203 } 217 204 218 //--------------------------------------------------------------------------219 // ExprStmt220 205 template< typename pass_type > 221 206 void PassVisitor< pass_type >::visit( ExprStmt * node ) { 222 VISIT_START( node ); 223 call_beginScope(); 224 225 visitExpression( node->get_expr() ); 226 227 call_endScope(); 228 VISIT_END( node ); 207 VISIT_BODY( node ); 229 208 } 230 209 … … 243 222 } 244 223 245 //--------------------------------------------------------------------------246 // IfStmt247 224 template< typename pass_type > 248 225 void PassVisitor< pass_type >::visit( IfStmt * node ) { 249 VISIT_START( node ); 250 251 visitExpression( node->get_condition() ); 252 node->set_thenPart ( visitStatement( node->get_thenPart() ) ); 253 node->set_elsePart ( visitStatement( node->get_elsePart() ) ); 254 255 VISIT_END( node ); 226 VISIT_BODY( node ); 256 227 } 257 228 … … 267 238 } 268 239 269 //--------------------------------------------------------------------------270 // WhileStmt271 240 template< typename pass_type > 272 241 void PassVisitor< pass_type >::visit( WhileStmt * node ) { 273 VISIT_START( node ); 274 275 visitExpression( node->get_condition() ); 276 node->set_body( visitStatement( node->get_body() ) ); 277 278 VISIT_END( node ); 242 VISIT_BODY( node ); 279 243 } 280 244 … … 289 253 } 290 254 291 //-------------------------------------------------------------------------- 292 // WhileStmt 255 293 256 template< typename pass_type > 294 257 void PassVisitor< pass_type >::visit( ForStmt * node ) { 295 VISIT_START( node ); 296 297 acceptAll( node->get_initialization(), *this ); 298 visitExpression( node->get_condition() ); 299 visitExpression( node->get_increment() ); 300 node->set_body( visitStatement( node->get_body() ) ); 301 302 VISIT_END( node ); 258 VISIT_BODY( node ); 303 259 } 304 260 … … 308 264 309 265 mutateAll( node->get_initialization(), *this ); 310 node->set_condition( mutateExpression( node->get_condition() ) );311 node->set_increment( mutateExpression( node->get_increment() ) );312 node->set_body( mutateStatement( node->get_body() ) );266 node->set_condition( mutateExpression( node->get_condition() ) ); 267 node->set_increment( mutateExpression( node->get_increment() ) ); 268 node->set_body( mutateStatement( node->get_body() ) ); 313 269 314 270 MUTATE_END( Statement, node ); 315 271 } 316 272 317 //--------------------------------------------------------------------------318 // SwitchStmt319 273 template< typename pass_type > 320 274 void PassVisitor< pass_type >::visit( SwitchStmt * node ) { 321 VISIT_START( node ); 322 323 visitExpression( node->get_condition() ); 324 visitStatementList( node->get_statements() ); 325 326 VISIT_END( node ); 275 VISIT_BODY( node ); 327 276 } 328 277 … … 337 286 } 338 287 339 //--------------------------------------------------------------------------340 // SwitchStmt341 288 template< typename pass_type > 342 289 void PassVisitor< pass_type >::visit( CaseStmt * node ) { 343 VISIT_START( node ); 344 345 visitExpression( node->get_condition() ); 346 visitStatementList( node->get_statements() ); 347 348 VISIT_END( node ); 290 VISIT_BODY( node ); 349 291 } 350 292 … … 364 306 } 365 307 366 //--------------------------------------------------------------------------367 // ReturnStmt368 308 template< typename pass_type > 369 309 void PassVisitor< pass_type >::visit( ReturnStmt * node ) { 370 VISIT_START( node ); 371 372 visitExpression( node->get_expr() ); 373 374 VISIT_END( node ); 310 VISIT_BODY( node ); 375 311 } 376 312 … … 384 320 } 385 321 386 //--------------------------------------------------------------------------387 // TryStmt388 322 template< typename pass_type > 389 323 void PassVisitor< pass_type >::visit( TryStmt * node ) { 390 VISIT_START( node ); 391 392 maybeAccept( node->get_block(), *this ); 393 acceptAll( node->get_catchers(), *this ); 394 395 VISIT_END( node ); 324 VISIT_BODY( node ); 396 325 } 397 326 … … 406 335 } 407 336 408 //--------------------------------------------------------------------------409 // CatchStmt410 337 template< typename pass_type > 411 338 void PassVisitor< pass_type >::visit( CatchStmt * node ) { 412 VISIT_START( node ); 413 414 node->set_body( visitStatement( node->get_body() ) ); 415 maybeAccept( node->get_decl(), *this ); 416 417 VISIT_END( node ); 339 VISIT_BODY( node ); 418 340 } 419 341 … … 453 375 } 454 376 455 //--------------------------------------------------------------------------456 // UntypedExpr457 377 template< typename pass_type > 458 378 void PassVisitor< pass_type >::visit( UntypedExpr * node ) { 459 VISIT_START( node ); 460 461 for ( auto expr : node->get_args() ) { 462 visitExpression( expr ); 463 } 464 465 VISIT_END( node ); 379 VISIT_BODY( node ); 466 380 } 467 381 … … 622 536 } 623 537 624 //--------------------------------------------------------------------------625 // UntypedExpr626 538 template< typename pass_type > 627 539 void PassVisitor< pass_type >::visit( StmtExpr * node ) { 628 VISIT_START( node ); 629 630 // don't want statements from outer CompoundStmts to be added to this StmtExpr 631 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 632 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 633 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 634 635 Visitor::visit( node ); 636 637 VISIT_END( node ); 540 VISIT_BODY( node ); 638 541 } 639 542 … … 737 640 } 738 641 739 //--------------------------------------------------------------------------740 // UntypedExpr741 642 template< typename pass_type > 742 643 void PassVisitor< pass_type >::visit( SingleInit * node ) { 743 VISIT_START( node ); 744 745 visitExpression( node->get_value() ); 746 747 VISIT_END( node ); 644 VISIT_BODY( node ); 748 645 } 749 646 -
src/Makefile.am
r2c6c893 ra4683611 43 43 driver_cfa_cpp_SOURCES = ${SRC} 44 44 driver_cfa_cpp_LDADD = ${LEXLIB} -ldl # yywrap 45 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall - DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++1445 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Werror -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14 46 46 driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic 47 47 -
src/Makefile.in
r2c6c893 ra4683611 447 447 driver_cfa_cpp_SOURCES = ${SRC} 448 448 driver_cfa_cpp_LDADD = ${LEXLIB} -ldl # yywrap 449 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall - DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14449 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Werror -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14 450 450 driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic 451 451 all: $(BUILT_SOURCES)
Note:
See TracChangeset
for help on using the changeset viewer.