blob: 156b714cb1a2c4e490524407bd3a5eb3d53c8894 [file] [log] [blame]
Chris Lattner7f455192003-08-30 23:17:51 +00001//===- 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.
15static llvm_exception *UncaughtExceptionStack = 0;
16
17// __llvm_eh_has_uncaught_exception - This is used to implement
18// std::uncaught_exception.
19//
20bool __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//
28void *__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!
38void __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!
46llvm_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.
53llvm_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}