diff ir/irlandingpad.h @ 319:e9c93739bc4c trunk

[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
author ChristianK
date Sat, 05 Jul 2008 10:22:56 +0200
parents
children d772927ca496
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ir/irlandingpad.h	Sat Jul 05 10:22:56 2008 +0200
@@ -0,0 +1,70 @@
+#ifndef LLVMDC_IR_IRLANDINGPADINFO_H
+#define LLVMDC_IR_IRLANDINGPADINFO_H
+
+#include "ir/ir.h"
+#include "statement.h"
+
+#include <deque>
+#include <stack>
+
+struct IRLandingPadInfo
+{
+    // default constructor for being able to store in a vector
+    IRLandingPadInfo()
+    : target(NULL), finallyBody(NULL), catchType(NULL)
+    {}
+
+    IRLandingPadInfo(Catch* catchstmt, llvm::BasicBlock* end);
+    IRLandingPadInfo(Statement* finallystmt);
+
+    // the target catch bb if this is a catch
+    // or the target finally bb if this is a finally
+    llvm::BasicBlock* target;
+
+    // nonzero if this is a finally
+    Statement* finallyBody;
+
+    // nonzero if this is a catch
+    ClassDeclaration* catchType;
+};
+
+struct IRLandingPad
+{
+    IRLandingPad() : catch_var(NULL) {}
+
+    // builds a new landing pad according to given infos
+    // and the ones on the stack. also stores it as invoke target
+    void push(llvm::BasicBlock* inBB);
+
+    void addCatch(Catch* catchstmt, llvm::BasicBlock* end);
+    void addFinally(Statement* finallystmt);
+
+    // pops the most recently constructed landing pad bb
+    // and its infos
+    void pop();
+
+    // gets the current landing pad
+    llvm::BasicBlock* get();
+
+    // creates or gets storage for exception object
+    LLValue* getExceptionStorage();
+
+private:
+    // constructs the landing pad from infos
+    void constructLandingPad(llvm::BasicBlock* inBB);
+
+    // information needed to create landing pads
+    std::deque<IRLandingPadInfo> infos;
+    std::deque<IRLandingPadInfo> unpushed_infos;
+
+    // the number of infos we had before the push
+    std::stack<size_t> nInfos;
+
+    // the target for invokes
+    std::stack<llvm::BasicBlock*> padBBs;
+
+    // storage for the catch variable
+    LLValue* catch_var;
+};
+
+#endif