source:
doc/theses/andrew_beach_MMath/code/throw-other.cfa@
166b384
| Last change on this file since 166b384 was f79ee0d, checked in by , 4 years ago | |
|---|---|
|
|
| File size: 1.1 KB | |
| Rev | Line | |
|---|---|---|
| [ea593a3] | 1 | // Throw Across Other Handler |
| [ee23a8d] | 2 | #include <clock.hfa> |
| [ea593a3] | 3 | #include <exception.hfa> |
| [ee23a8d] | 4 | #include <fstream.hfa> |
| [f79ee0d] | 5 | #include <stdlib.hfa> // strto |
| [ea593a3] | 6 | |
| [f79ee0d] | 7 | exception empty_exception; |
| 8 | vtable(empty_exception) empty_vt; | |
| 9 | exception not_raised_exception; | |
| [ea593a3] | 10 | |
| [f79ee0d] | 11 | unsigned int frames; // use global because of gcc thunk problem |
| [ea593a3] | 12 | |
| [f79ee0d] | 13 | void unwind_other(unsigned int dummy) { |
| [ea593a3] | 14 | if (frames) { |
| [f79ee0d] | 15 | frames -= 1; |
| [ea593a3] | 16 | try { |
| [f79ee0d] | 17 | unwind_other(42); |
| [ea593a3] | 18 | } catch (not_raised_exception *) { |
| [54651005] | 19 | asm volatile ("# catch block (stack)"); |
| [ea593a3] | 20 | } |
| 21 | } else { | |
| [f79ee0d] | 22 | dummy = 42; |
| [ea593a3] | 23 | throw (empty_exception){&empty_vt}; |
| 24 | } | |
| 25 | } | |
| 26 | ||
| 27 | int main(int argc, char * argv[]) { | |
| 28 | unsigned int times = 1; | |
| 29 | unsigned int total_frames = 1; | |
| [ee23a8d] | 30 | if (1 < argc) { |
| [f79ee0d] | 31 | times = strto(argv[1], 0p, 10); |
| [ea593a3] | 32 | } |
| [ee23a8d] | 33 | if (2 < argc) { |
| [f79ee0d] | 34 | total_frames = strto(argv[2], 0p, 10); |
| [ea593a3] | 35 | } |
| [f79ee0d] | 36 | frames = total_frames; |
| [ea593a3] | 37 | |
| [ee23a8d] | 38 | Time start_time = timeHiRes(); |
| [ea593a3] | 39 | for (int count = 0 ; count < times ; ++count) { |
| 40 | try { | |
| [f79ee0d] | 41 | unwind_other(42); |
| [ea593a3] | 42 | } catch (empty_exception *) { |
| [54651005] | 43 | asm volatile ("# catch block (base)"); |
| [ea593a3] | 44 | } |
| 45 | } | |
| [ee23a8d] | 46 | Time end_time = timeHiRes(); |
| [f79ee0d] | 47 | sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.); |
| [ea593a3] | 48 | } |
Note:
See TracBrowser
for help on using the repository browser.