Move handling of @try and @throw to the runtime class.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55983 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index 7242d01..b5834e6 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -471,4 +471,14 @@
   EmitBlock(LoopEnd);
 }
 
+void CodeGenFunction::EmitObjCAtTryStmt(const ObjCAtTryStmt &S)
+{
+  CGM.getObjCRuntime().EmitTryStmt(*this, S);
+}
+
+void CodeGenFunction::EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S)
+{
+  CGM.getObjCRuntime().EmitThrowStmt(*this, S);
+}
+
 CGObjCRuntime::~CGObjCRuntime() {}
diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp
index 2bbbb46..2641d9d 100644
--- a/lib/CodeGen/CGObjCGNU.cpp
+++ b/lib/CodeGen/CGObjCGNU.cpp
@@ -122,6 +122,11 @@
   virtual void GenerateProtocol(const ObjCProtocolDecl *PD);
   virtual llvm::Function *ModuleInitFunction();
   virtual llvm::Function *EnumerationMutationFunction();
+  
+  virtual void EmitTryStmt(CodeGen::CodeGenFunction &CGF,
+                           const ObjCAtTryStmt &S);
+  virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
+                             const ObjCAtThrowStmt &S);
 };
 } // end anonymous namespace
 
@@ -967,6 +972,18 @@
   return 0;
 }
 
+void CGObjCGNU::EmitTryStmt(CodeGen::CodeGenFunction &CGF,
+                            const ObjCAtTryStmt &S)
+{
+  CGF.ErrorUnsupported(&S, "@try statement");
+}
+
+void CGObjCGNU::EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
+                              const ObjCAtThrowStmt &S)
+{
+  CGF.ErrorUnsupported(&S, "@throw statement");
+}
+
 CodeGen::CGObjCRuntime *CodeGen::CreateGNUObjCRuntime(CodeGen::CodeGenModule &CGM){
   return new CGObjCGNU(CGM);
 }
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 26e8c5f..f0e7097 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -373,6 +373,12 @@
 
   virtual llvm::Function *ModuleInitFunction();
   virtual llvm::Function *EnumerationMutationFunction();
+  
+  virtual void EmitTryStmt(CodeGen::CodeGenFunction &CGF,
+                           const ObjCAtTryStmt &S);
+  virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
+                             const ObjCAtThrowStmt &S);
+  
 };
 } // end anonymous namespace
 
@@ -1392,6 +1398,18 @@
   return ObjCTypes.EnumerationMutationFn;
 }
 
+void CGObjCMac::EmitTryStmt(CodeGen::CodeGenFunction &CGF,
+                            const ObjCAtTryStmt &S)
+{
+  CGF.ErrorUnsupported(&S, "@try statement");
+}
+
+void CGObjCMac::EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
+                              const ObjCAtThrowStmt &S)
+{
+  CGF.ErrorUnsupported(&S, "@throw statement");
+}
+
 /* *** Private Interface *** */
 
 /// EmitImageInfo - Emit the image info marker used to encode some module
diff --git a/lib/CodeGen/CGObjCRuntime.h b/lib/CodeGen/CGObjCRuntime.h
index 7b00725..c8efc52 100644
--- a/lib/CodeGen/CGObjCRuntime.h
+++ b/lib/CodeGen/CGObjCRuntime.h
@@ -36,6 +36,8 @@
   class CodeGenFunction;
 }
 
+  class ObjCAtTryStmt;
+  class ObjCAtThrowStmt;
   class ObjCCategoryImplDecl;
   class ObjCImplementationDecl;
   class ObjCInterfaceDecl;
@@ -130,6 +132,11 @@
   /// the structure.  If this returns true then @defs is invalid for this
   /// runtime and a warning should be generated.
   virtual bool LateBoundIVars() const { return false; }
+
+  virtual void EmitTryStmt(CodeGen::CodeGenFunction &CGF,
+                           const ObjCAtTryStmt &S) = 0;
+  virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
+                             const ObjCAtThrowStmt &S) = 0;
 };
 
 /// Creates an instance of an Objective-C runtime class.  
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index b766fe8..4001be4 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -78,16 +78,16 @@
   case Stmt::AsmStmtClass:      EmitAsmStmt(cast<AsmStmt>(*S));           break;
 
   case Stmt::ObjCAtTryStmtClass:
-    ErrorUnsupported(S, "@try statement");
-    break;
+    EmitObjCAtTryStmt(cast<ObjCAtTryStmt>(*S));
+    break;    
   case Stmt::ObjCAtCatchStmtClass:
-    ErrorUnsupported(S, "@catch statement");
+    assert(0 && "@catch statements should be handled by EmitObjCAtTryStmt");
     break;
   case Stmt::ObjCAtFinallyStmtClass:
-    ErrorUnsupported(S, "@finally statement");
+    assert(0 && "@finally statements should be handled by EmitObjCAtTryStmt");
     break;
   case Stmt::ObjCAtThrowStmtClass:
-    ErrorUnsupported(S, "@throw statement");
+    EmitObjCAtThrowStmt(cast<ObjCAtThrowStmt>(*S));
     break;
   case Stmt::ObjCAtSynchronizedStmtClass:
     ErrorUnsupported(S, "@synchronized statement");
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 3d14aed..95b72a4 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -242,6 +242,8 @@
   void EmitAsmStmt(const AsmStmt &S);
   
   void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
+  void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
+  void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
   
   //===--------------------------------------------------------------------===//
   //                         LValue Expression Emission