[cfe-commits] r64048 - /cfe/trunk/lib/CodeGen/CodeGenFunction.h

Anders Carlsson andersca at mac.com
Sat Feb 7 15:30:41 PST 2009


Author: andersca
Date: Sat Feb  7 17:30:41 2009
New Revision: 64048

URL: http://llvm.org/viewvc/llvm-project?rev=64048&view=rev
Log:
Add a simple RAII object, to be used for pushing a cleanup entry and make the insertion point be the cleanup block.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=64048&r1=64047&r2=64048&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat Feb  7 17:30:41 2009
@@ -132,6 +132,25 @@
   /// 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





More information about the cfe-commits mailing list