]> granicus.if.org Git - clang/commitdiff
Add plumbing for the cleanup stack.
authorAnders Carlsson <andersca@mac.com>
Sat, 7 Feb 2009 22:53:43 +0000 (22:53 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 7 Feb 2009 22:53:43 +0000 (22:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64043 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenFunction.h

index f5a802f0b7442fee5a384df6b2bd5fb068de071d..4ba4d600f864693a3659845641f3364648640820 100644 (file)
@@ -512,3 +512,12 @@ llvm::Value* CodeGenFunction::EmitVAListRef(const Expr* E) {
   }
   return EmitLValue(E).getAddress();
 }
+
+llvm::BasicBlock *CodeGenFunction::CreateCleanupBlock()
+{
+  llvm::BasicBlock *CleanupBlock = createBasicBlock("cleanup");
+  
+  CleanupEntries.push_back(CleanupEntry(CleanupBlock));
+  
+  return CleanupBlock;  
+}
index 9d8d3a3f4a057c575529722ef2250197a5a6b034..4ff3badd99df8dc3a22ab9111f7dcb7cc67be616 100644 (file)
@@ -128,6 +128,10 @@ public:
   void EmitJumpThroughFinally(ObjCEHEntry *Entry, llvm::BasicBlock *Dest,
                               bool ExecuteTryExit=true);
   
+  /// CreateCleanupBlock - Will push a new cleanup entry on the stack
+  /// and return a BasicBlock where cleanup instructions can be added
+  llvm::BasicBlock *CreateCleanupBlock();
+  
 private:
   /// LabelIDs - Track arbitrary ids assigned to labels for use in
   /// implementing the GCC address-of-label extension and indirect
@@ -206,6 +210,24 @@ private:
   /// label.
   void EmitStackUpdate(const LabelStmt &S);
 
+  struct CleanupEntry {
+    /// CleanupBlock - The block of code that does the actual cleanup.
+    llvm::BasicBlock *CleanupBlock;
+    
+    /// Blocks - Basic blocks that were emitted in the current cleanup scope.
+    std::vector<llvm::BasicBlock *> Blocks;
+
+    /// BranchFixups - Branch instructions to basic blocks that haven't been
+    /// inserted into the current function yet.
+    std::vector<llvm::BranchInst*> BranchFixups;
+
+    explicit CleanupEntry(llvm::BasicBlock *cb)
+      : CleanupBlock(cb) {}
+  };
+  
+  /// CleanupEntries - Stack of cleanup entries.
+  llvm::SmallVector<CleanupEntry, 8> CleanupEntries;
+
 public:
   CodeGenFunction(CodeGenModule &cgm);