Changeset f79ee0d for doc/theses/andrew_beach_MMath/code/cond-catch.cfa
- Timestamp:
- Aug 19, 2021, 1:58:46 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
- Children:
- 262deda0
- Parents:
- 8a1d95af
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/code/cond-catch.cfa
r8a1d95af rf79ee0d 3 3 #include <exception.hfa> 4 4 #include <fstream.hfa> 5 #include <stdlib.h >5 #include <stdlib.hfa> // strto 6 6 7 EHM_EXCEPTION(empty_exception)(); 8 9 EHM_VIRTUAL_TABLE(empty_exception, empty_vt); 7 exception empty_exception; 8 vtable(empty_exception) empty_vt; 10 9 11 10 bool should_catch = false; 12 13 void throw_exception() {14 throw (empty_exception){&empty_vt};15 }16 17 void cond_catch() {18 try {19 throw_exception();20 } catch (empty_exception * exc ; should_catch) {21 asm volatile ("# catch block (conditional)");22 }23 }24 11 25 12 int main(int argc, char * argv[]) { 26 13 unsigned int times = 1; 27 14 if (1 < argc) { 28 times = strto l(argv[1], 0p, 10);15 times = strto(argv[1], 0p, 10); 29 16 } 30 17 if (2 < argc) { 31 should_catch = strtol(argv[2], 0p, 10);18 should_catch = (unsigned int)strto(argv[2], 0p, 2); 32 19 } 33 20 … … 35 22 for (unsigned int count = 0 ; count < times ; ++count) { 36 23 try { 37 cond_catch(); 24 throw (empty_exception){&empty_vt}; 25 } catch (empty_exception * exc ; should_catch) { 26 asm volatile ("# catch block (conditional)"); 38 27 } catch (empty_exception * exc) { 39 28 asm volatile ("# catch block (unconditional)"); … … 41 30 } 42 31 Time end_time = timeHiRes(); 43 sout | "Run-Time ( ns): " | (end_time - start_time)`ns;32 sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.); 44 33 }
Note: See TracChangeset
for help on using the changeset viewer.