Mercurial > projects > ldc
annotate ir/irlandingpad.h @ 831:7e59caf41433
Fix with(symbol) statement.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 07 Dec 2008 16:02:43 +0100 |
parents | eef8ac26c66c |
children | dc608dc33081 |
rev | line source |
---|---|
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
612
diff
changeset
|
1 #ifndef LDC_IR_IRLANDINGPADINFO_H |
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
612
diff
changeset
|
2 #define LDC_IR_IRLANDINGPADINFO_H |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
3 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
4 #include "ir/ir.h" |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
5 #include "statement.h" |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
6 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
7 #include <deque> |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
8 #include <stack> |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
9 |
320
d772927ca496
[svn r341] Fix all regressions between [332] and [340]:
ChristianK
parents:
319
diff
changeset
|
10 // only to be used within IRLandingPad |
d772927ca496
[svn r341] Fix all regressions between [332] and [340]:
ChristianK
parents:
319
diff
changeset
|
11 // holds information about a single catch or finally |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
12 struct IRLandingPadInfo |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
13 { |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
14 // default constructor for being able to store in a vector |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
15 IRLandingPadInfo() |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
16 : target(NULL), finallyBody(NULL), catchType(NULL) |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
17 {} |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
18 |
320
d772927ca496
[svn r341] Fix all regressions between [332] and [340]:
ChristianK
parents:
319
diff
changeset
|
19 // constructor for catch |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
20 IRLandingPadInfo(Catch* catchstmt, llvm::BasicBlock* end); |
320
d772927ca496
[svn r341] Fix all regressions between [332] and [340]:
ChristianK
parents:
319
diff
changeset
|
21 |
d772927ca496
[svn r341] Fix all regressions between [332] and [340]:
ChristianK
parents:
319
diff
changeset
|
22 // constructor for finally |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
23 IRLandingPadInfo(Statement* finallystmt); |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
24 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
25 // the target catch bb if this is a catch |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
26 // or the target finally bb if this is a finally |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
27 llvm::BasicBlock* target; |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
28 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
29 // nonzero if this is a finally |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
30 Statement* finallyBody; |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
31 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
32 // nonzero if this is a catch |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
33 ClassDeclaration* catchType; |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
34 }; |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
35 |
320
d772927ca496
[svn r341] Fix all regressions between [332] and [340]:
ChristianK
parents:
319
diff
changeset
|
36 |
d772927ca496
[svn r341] Fix all regressions between [332] and [340]:
ChristianK
parents:
319
diff
changeset
|
37 // holds information about all possible catch and finally actions |
d772927ca496
[svn r341] Fix all regressions between [332] and [340]:
ChristianK
parents:
319
diff
changeset
|
38 // and can emit landing pads to be called from the unwind runtime |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
39 struct IRLandingPad |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
40 { |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
41 IRLandingPad() : catch_var(NULL) {} |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
42 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
43 // builds a new landing pad according to given infos |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
44 // and the ones on the stack. also stores it as invoke target |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
45 void push(llvm::BasicBlock* inBB); |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
46 |
320
d772927ca496
[svn r341] Fix all regressions between [332] and [340]:
ChristianK
parents:
319
diff
changeset
|
47 // add catch information, will be used in next call to push |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
48 void addCatch(Catch* catchstmt, llvm::BasicBlock* end); |
320
d772927ca496
[svn r341] Fix all regressions between [332] and [340]:
ChristianK
parents:
319
diff
changeset
|
49 // add finally information, will be used in next call to push |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
50 void addFinally(Statement* finallystmt); |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
51 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
52 // pops the most recently constructed landing pad bb |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
53 // and its infos |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
54 void pop(); |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
55 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
56 // gets the current landing pad |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
57 llvm::BasicBlock* get(); |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
58 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
59 // creates or gets storage for exception object |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
60 LLValue* getExceptionStorage(); |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
61 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
62 private: |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
63 // constructs the landing pad from infos |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
64 void constructLandingPad(llvm::BasicBlock* inBB); |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
65 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
66 // information needed to create landing pads |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
67 std::deque<IRLandingPadInfo> infos; |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
68 std::deque<IRLandingPadInfo> unpushed_infos; |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
69 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
70 // the number of infos we had before the push |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
71 std::stack<size_t> nInfos; |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
72 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
73 // the target for invokes |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
74 std::stack<llvm::BasicBlock*> padBBs; |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
75 |
612
d97b017a8aef
Fix issue with EH table indices and nested try-catch.
Christian Kamm <kamm incasoftware de>
parents:
320
diff
changeset
|
76 // associate increasing ints with each unique classdecl encountered |
d97b017a8aef
Fix issue with EH table indices and nested try-catch.
Christian Kamm <kamm incasoftware de>
parents:
320
diff
changeset
|
77 std::map<ClassDeclaration*, int> catchToInt; |
d97b017a8aef
Fix issue with EH table indices and nested try-catch.
Christian Kamm <kamm incasoftware de>
parents:
320
diff
changeset
|
78 |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
79 // storage for the catch variable |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
80 LLValue* catch_var; |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
81 }; |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
82 |
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
diff
changeset
|
83 #endif |