Implement a really simple DwarfSjLjException.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130947 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 63bfa2f..dad581b 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -193,6 +193,8 @@
   case ExceptionHandling::None:
     return false;
   case ExceptionHandling::SjLj:
+    DE = new DwarfSjLjException(this);
+    return false;
   case ExceptionHandling::DwarfTable:
     DE = new DwarfTableException(this);
     return false;
diff --git a/lib/CodeGen/AsmPrinter/CMakeLists.txt b/lib/CodeGen/AsmPrinter/CMakeLists.txt
index d2be552..bf80f5f 100644
--- a/lib/CodeGen/AsmPrinter/CMakeLists.txt
+++ b/lib/CodeGen/AsmPrinter/CMakeLists.txt
@@ -8,6 +8,7 @@
   DwarfCompileUnit.cpp
   DwarfDebug.cpp
   DwarfException.cpp
+  DwarfSjLjException.cpp
   DwarfTableException.cpp
   OcamlGCPrinter.cpp
   )
diff --git a/lib/CodeGen/AsmPrinter/DwarfException.h b/lib/CodeGen/AsmPrinter/DwarfException.h
index f111641..d212a63 100644
--- a/lib/CodeGen/AsmPrinter/DwarfException.h
+++ b/lib/CodeGen/AsmPrinter/DwarfException.h
@@ -238,6 +238,25 @@
   virtual void EndFunction();
 };
 
+class DwarfSjLjException : public DwarfException {
+public:
+  //===--------------------------------------------------------------------===//
+  // Main entry points.
+  //
+  DwarfSjLjException(AsmPrinter *A);
+  virtual ~DwarfSjLjException();
+
+  /// EndModule - Emit all exception information that should come after the
+  /// content.
+  virtual void EndModule();
+
+  /// BeginFunction - Gather pre-function exception information.  Assumes being
+  /// emitted immediately after the function entry point.
+  virtual void BeginFunction(const MachineFunction *MF);
+
+  /// EndFunction - Gather and emit post-function exception information.
+  virtual void EndFunction();
+};
 
 class ARMException : public DwarfException {
   /// shouldEmitTable - Per-function flag to indicate if EH tables should
diff --git a/lib/CodeGen/AsmPrinter/DwarfSjLjException.cpp b/lib/CodeGen/AsmPrinter/DwarfSjLjException.cpp
new file mode 100644
index 0000000..4718d71
--- /dev/null
+++ b/lib/CodeGen/AsmPrinter/DwarfSjLjException.cpp
@@ -0,0 +1,46 @@
+//===-- CodeGen/AsmPrinter/DwarfTableException.cpp - Dwarf Exception Impl --==//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a simple implementation of DwarfException that just produces
+// the exception table for use with SjLj.
+//
+//===----------------------------------------------------------------------===//
+
+#include "DwarfException.h"
+#include "llvm/CodeGen/MachineLocation.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+using namespace llvm;
+
+DwarfSjLjException::DwarfSjLjException(AsmPrinter *A) : DwarfException(A) {
+}
+
+DwarfSjLjException::~DwarfSjLjException() {}
+
+/// EndModule - Emit all exception information that should come after the
+/// content.
+void DwarfSjLjException::EndModule() {
+}
+
+/// BeginFunction - Gather pre-function exception information. Assumes it's
+/// being emitted immediately after the function entry point.
+void DwarfSjLjException::BeginFunction(const MachineFunction *MF) {
+}
+
+/// EndFunction - Gather and emit post-function exception information.
+///
+void DwarfSjLjException::EndFunction() {
+  // Record if this personality index uses a landing pad.
+  bool HasLandingPad = !MMI->getLandingPads().empty();
+
+  // Map all labels and get rid of any dead landing pads.
+  MMI->TidyLandingPads();
+
+  if (HasLandingPad)
+    EmitExceptionTable();
+}