]> granicus.if.org Git - clang/commitdiff
Add a simple RAII object, to be used for pushing a cleanup entry and make the inserti...
authorAnders Carlsson <andersca@mac.com>
Sat, 7 Feb 2009 23:30:41 +0000 (23:30 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 7 Feb 2009 23:30:41 +0000 (23:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64048 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenFunction.h

index 068627139d79c1ed9f6558b1610144ce65c03b0a..1f037600f51f77f9763946f9e1fb766f9d2d288c 100644 (file)
@@ -132,6 +132,25 @@ public:
   /// and return a BasicBlock where cleanup instructions can be added
   llvm::BasicBlock *CreateCleanupBlock();
   
+  /// CleanupScope - RAII object that will create a cleanup block and
+  /// set the insert point to that block. When destructed, it sets the insert
+  /// point to the previous block.
+  class CleanupScope {
+    CodeGenFunction& CGF;
+    llvm::BasicBlock *CurBB;
+    
+  public:
+    CleanupScope(CodeGenFunction &cgf)
+      : CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()) {
+      llvm::BasicBlock *FinallyBB = CGF.CreateCleanupBlock();
+      CGF.Builder.SetInsertPoint(FinallyBB);
+    }
+    
+    ~CleanupScope() {
+      CGF.Builder.SetInsertPoint(CurBB);
+    }
+  };
+
 private:
   /// LabelIDs - Track arbitrary ids assigned to labels for use in
   /// implementing the GCC address-of-label extension and indirect