Chris Lattner | 7f45519 | 2003-08-30 23:17:51 +0000 | [diff] [blame^] | 1 | //===- Exception.cpp - Generic language-independent exceptions ------------===// |
| 2 | // |
| 3 | // This file defines the the shared data structures used by all language |
| 4 | // specific exception handling runtime libraries. |
| 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | |
| 8 | #include "Exception.h" |
| 9 | #include <cassert> |
| 10 | |
| 11 | // Thread local state for exception handling. FIXME: This should really be made |
| 12 | // thread-local! |
| 13 | |
| 14 | // UncaughtExceptionStack - The stack of exceptions currently being thrown. |
| 15 | static llvm_exception *UncaughtExceptionStack = 0; |
| 16 | |
| 17 | // __llvm_eh_has_uncaught_exception - This is used to implement |
| 18 | // std::uncaught_exception. |
| 19 | // |
| 20 | bool __llvm_eh_has_uncaught_exception() throw() { |
| 21 | return UncaughtExceptionStack != 0; |
| 22 | } |
| 23 | |
| 24 | // __llvm_eh_current_uncaught_exception - This function checks to see if the |
| 25 | // current uncaught exception is of the specified language type. If so, it |
| 26 | // returns a pointer to the exception area data. |
| 27 | // |
| 28 | void *__llvm_eh_current_uncaught_exception_type(unsigned HandlerType) throw() { |
| 29 | assert(UncaughtExceptionStack && "No uncaught exception!"); |
| 30 | if (UncaughtExceptionStack->ExceptionType == HandlerType) |
| 31 | return UncaughtExceptionStack+1; |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | // __llvm_eh_add_uncaught_exception - This adds the specified exception to the |
| 36 | // top of the uncaught exception stack. The exception should not already be on |
| 37 | // the stack! |
| 38 | void __llvm_eh_add_uncaught_exception(llvm_exception *E) throw() { |
| 39 | E->Next = UncaughtExceptionStack; |
| 40 | UncaughtExceptionStack = E; |
| 41 | } |
| 42 | |
| 43 | |
| 44 | // __llvm_eh_get_uncaught_exception - Returns the current uncaught exception. |
| 45 | // There must be an uncaught exception for this to work! |
| 46 | llvm_exception *__llvm_eh_get_uncaught_exception() throw() { |
| 47 | assert(UncaughtExceptionStack && "There are no uncaught exceptions!?!?"); |
| 48 | return UncaughtExceptionStack; |
| 49 | } |
| 50 | |
| 51 | // __llvm_eh_pop_from_uncaught_stack - Remove the current uncaught exception |
| 52 | // from the top of the stack. |
| 53 | llvm_exception *__llvm_eh_pop_from_uncaught_stack() throw() { |
| 54 | llvm_exception *E = __llvm_eh_get_uncaught_exception(); |
| 55 | UncaughtExceptionStack = E->Next; |
| 56 | return E; |
| 57 | } |