implement CodeGen/X86/inline-asm-x-scalar.ll:test3
[oota-llvm.git] / lib / CodeGen / DwarfWriter.cpp
index 15386048058e1358fdc472345e9a4651f51967cf..1ca9e218375fddc30018d46cbc648fec037548f0 100644 (file)
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file contains support for writing dwarf debug info into asm files.
+// This file contains support for writing dwarf info into asm files.
 //
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Module.h"
 #include "llvm/Type.h"
 #include "llvm/CodeGen/AsmPrinter.h"
-#include "llvm/CodeGen/MachineDebugInfo.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/MachineLocation.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/DataTypes.h"
@@ -29,8 +30,9 @@
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/MRegisterInfo.h"
 #include "llvm/Target/TargetData.h"
-#include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetFrameInfo.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetOptions.h"
 #include <ostream>
 #include <string>
 using namespace llvm;
@@ -54,7 +56,7 @@ class DIEValue;
 
 //===----------------------------------------------------------------------===//
 /// DWLabel - Labels are used to track locations in the assembler file.
-/// Labels appear in the form <prefix>debug_<Tag><Number>, where the tag is a
+/// Labels appear in the form <prefix><Tag><Number>, where the tag is a
 /// category of label (Ex. location) and number is a value unique in that
 /// category.
 class DWLabel {
@@ -79,7 +81,7 @@ public:
     if (O) print(*O);
   }
   void print(std::ostream &O) const {
-    O << ".debug_" << Tag;
+    O << "." << Tag;
     if (Number) O << Number;
   }
 #endif
@@ -180,7 +182,7 @@ public:
   
   /// Emit - Print the abbreviation using the specified Dwarf writer.
   ///
-  void Emit(const Dwarf &DW) const; 
+  void Emit(const DwarfDebug &DD) const; 
       
 #ifndef NDEBUG
   void print(std::ostream *O) {
@@ -235,7 +237,7 @@ public:
   unsigned getOffset()                       const { return Offset; }
   unsigned getSize()                         const { return Size; }
   const std::vector<DIE *> &getChildren()    const { return Children; }
-  const std::vector<DIEValue *> &getValues() const { return Values; }
+  std::vector<DIEValue *> &getValues()       { return Values; }
   void setTag(unsigned Tag)                  { Abbrev.setTag(Tag); }
   void setOffset(unsigned O)                 { Offset = O; }
   void setSize(unsigned S)                   { Size = S; }
@@ -313,11 +315,11 @@ public:
   
   /// EmitValue - Emit value via the Dwarf writer.
   ///
-  virtual void EmitValue(const Dwarf &DW, unsigned Form) const = 0;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form) = 0;
   
   /// SizeOf - Return the size of a value in bytes.
   ///
-  virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const = 0;
+  virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const = 0;
   
   /// Profile - Used to gather unique data for the value folding set.
   ///
@@ -363,11 +365,11 @@ public:
     
   /// EmitValue - Emit integer of appropriate size.
   ///
-  virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of integer value in bytes.
   ///
-  virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
+  virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
   
   /// Profile - Used to gather unique data for the value folding set.
   ///
@@ -400,11 +402,11 @@ public:
   
   /// EmitValue - Emit string value.
   ///
-  virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of string value in bytes.
   ///
-  virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const {
+  virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const {
     return String.size() + sizeof(char); // sizeof('\0');
   }
   
@@ -439,11 +441,11 @@ public:
   
   /// EmitValue - Emit label value.
   ///
-  virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of label value in bytes.
   ///
-  virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
+  virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
   
   /// Profile - Used to gather unique data for the value folding set.
   ///
@@ -477,11 +479,11 @@ public:
   
   /// EmitValue - Emit label value.
   ///
-  virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of label value in bytes.
   ///
-  virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
+  virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
   
   /// Profile - Used to gather unique data for the value folding set.
   ///
@@ -515,11 +517,11 @@ public:
   
   /// EmitValue - Emit delta value.
   ///
-  virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of delta value in bytes.
   ///
-  virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
+  virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
   
   /// Profile - Used to gather unique data for the value folding set.
   ///
@@ -557,11 +559,11 @@ public:
   
   /// EmitValue - Emit debug information entry offset.
   ///
-  virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of debug information entry in bytes.
   ///
-  virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const {
+  virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const {
     return sizeof(int32_t);
   }
   
@@ -609,7 +611,7 @@ public:
   
   /// ComputeSize - calculate the size of the block.
   ///
-  unsigned ComputeSize(Dwarf &DW);
+  unsigned ComputeSize(DwarfDebug &DD);
   
   /// BestForm - Choose the best form for data.
   ///
@@ -622,11 +624,11 @@ public:
 
   /// EmitValue - Emit block data.
   ///
-  virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of block data in bytes.
   ///
-  virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
+  virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
   
 
   /// Profile - Used to gather unique data for the value folding set.
@@ -720,14 +722,14 @@ public:
   
   /// getDieMapSlotFor - Returns the debug information entry map slot for the
   /// specified debug descriptor.
-  DIE *&getDieMapSlotFor(DebugInfoDesc *DD) {
-    return DescToDieMap[DD];
+  DIE *&getDieMapSlotFor(DebugInfoDesc *DID) {
+    return DescToDieMap[DID];
   }
   
   /// getDIEntrySlotFor - Returns the debug information entry proxy slot for the
   /// specified debug descriptor.
-  DIEntry *&getDIEntrySlotFor(DebugInfoDesc *DD) {
-    return DescToDIEntryMap[DD];
+  DIEntry *&getDIEntrySlotFor(DebugInfoDesc *DID) {
+    return DescToDIEntryMap[DID];
   }
   
   /// AddDie - Adds or interns the DIE to the compile unit.
@@ -750,14 +752,14 @@ public:
 };
 
 //===----------------------------------------------------------------------===//
-/// Dwarf - Emits Dwarf debug and exception handling directives. 
+/// Dwarf - Emits general Dwarf directives. 
 ///
 class Dwarf {
 
-private:
+protected:
 
   //===--------------------------------------------------------------------===//
-  // Core attributes used by the Dwarf  writer.
+  // Core attributes used by the Dwarf writer.
   //
   
   //
@@ -786,62 +788,28 @@ private:
   ///
   MachineFunction *MF;
   
-  /// DebugInfo - Collected debug information.
-  ///
-  MachineDebugInfo *DebugInfo;
-  
-  /// didInitial - Flag to indicate if initial emission has been done.
-  ///
-  bool didInitial;
-  
-  /// shouldEmit - Flag to indicate if debug information should be emitted.
+  /// MMI - Collected machine module information.
   ///
-  bool shouldEmit;
+  MachineModuleInfo *MMI;
   
   /// SubprogramCount - The running count of functions being compiled.
   ///
   unsigned SubprogramCount;
-  
-  //===--------------------------------------------------------------------===//
-  // Attributes used to construct specific Dwarf sections.
-  //
-  
-  /// CompileUnits - All the compile units involved in this build.  The index
-  /// of each entry in this vector corresponds to the sources in DebugInfo.
-  std::vector<CompileUnit *> CompileUnits;
-  
-  /// AbbreviationsSet - Used to uniquely define abbreviations.
-  ///
-  FoldingSet<DIEAbbrev> AbbreviationsSet;
-
-  /// Abbreviations - A list of all the unique abbreviations in use.
-  ///
-  std::vector<DIEAbbrev *> Abbreviations;
-  
-  /// ValuesSet - Used to uniquely define values.
-  ///
-  FoldingSet<DIEValue> ValuesSet;
-  
-  /// Values - A list of all the unique values in use.
-  ///
-  std::vector<DIEValue *> Values;
-  
-  /// StringPool - A UniqueVector of strings used by indirect references.
-  ///
-  UniqueVector<std::string> StringPool;
-
-  /// UnitMap - Map debug information descriptor to compile unit.
-  ///
-  std::map<DebugInfoDesc *, CompileUnit *> DescToUnitMap;
-  
-  /// SectionMap - Provides a unique id per text section.
-  ///
-  UniqueVector<std::string> SectionMap;
-  
-  /// SectionSourceLines - Tracks line numbers per text section.
-  ///
-  std::vector<std::vector<SourceLineInfo> > SectionSourceLines;
 
+  unsigned SetCounter;
+  Dwarf(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
+  : O(OS)
+  , Asm(A)
+  , TAI(T)
+  , TD(Asm->TM.getTargetData())
+  , RI(Asm->TM.getRegisterInfo())
+  , M(NULL)
+  , MF(NULL)
+  , MMI(NULL)
+  , SubprogramCount(0)
+  , SetCounter(1)
+  {
+  }
 
 public:
 
@@ -849,16 +817,20 @@ public:
   // Accessors.
   //
   AsmPrinter *getAsm() const { return Asm; }
+  MachineModuleInfo *getMMI() const { return MMI; }
+  const TargetAsmInfo *getTargetAsmInfo() const { return TAI; }
 
   /// PrintLabelName - Print label name in form used by Dwarf writer.
   ///
   void PrintLabelName(DWLabel Label) const {
     PrintLabelName(Label.Tag, Label.Number);
   }
-  void PrintLabelName(const char *Tag, unsigned Number) const {
-    O << TAI->getPrivateGlobalPrefix()
-      << "debug_"
-      << Tag;
+  void PrintLabelName(const char *Tag, unsigned Number,
+                      bool isInSection = false) const {
+    if (isInSection && TAI->getDwarfSectionOffsetDirective())
+      O << TAI->getDwarfSectionOffsetDirective() << Tag;
+    else
+      O << TAI->getPrivateGlobalPrefix() << Tag;
     if (Number) O << Number;
   }
   
@@ -874,41 +846,44 @@ public:
   
   /// EmitReference - Emit a reference to a label.
   ///
-  void EmitReference(DWLabel Label) const {
-    EmitReference(Label.Tag, Label.Number);
+  void EmitReference(DWLabel Label, bool IsPCRelative = false) const {
+    EmitReference(Label.Tag, Label.Number, IsPCRelative);
   }
-  void EmitReference(const char *Tag, unsigned Number) const {
+  void EmitReference(const char *Tag, unsigned Number,
+                     bool IsPCRelative = false) const {
     if (TAI->getAddressSize() == sizeof(int32_t))
       O << TAI->getData32bitsDirective();
     else
       O << TAI->getData64bitsDirective();
       
     PrintLabelName(Tag, Number);
+    
+    if (IsPCRelative) O << "-" << TAI->getPCSymbol();
   }
-  void EmitReference(const std::string &Name) const {
+  void EmitReference(const std::string &Name, bool IsPCRelative = false) const {
     if (TAI->getAddressSize() == sizeof(int32_t))
       O << TAI->getData32bitsDirective();
     else
       O << TAI->getData64bitsDirective();
       
     O << Name;
+    
+    if (IsPCRelative) O << "-" << TAI->getPCSymbol();
   }
 
   /// EmitDifference - Emit the difference between two labels.  Some
   /// assemblers do not behave with absolute expressions with data directives,
   /// so there is an option (needsSet) to use an intermediary set expression.
   void EmitDifference(DWLabel LabelHi, DWLabel LabelLo,
-                      bool IsSmall = false) const {
+                      bool IsSmall = false) {
     EmitDifference(LabelHi.Tag, LabelHi.Number,
                    LabelLo.Tag, LabelLo.Number,
                    IsSmall);
   }
   void EmitDifference(const char *TagHi, unsigned NumberHi,
                       const char *TagLo, unsigned NumberLo,
-                      bool IsSmall = false) const {
+                      bool IsSmall = false) {
     if (TAI->needsSet()) {
-      static unsigned SetCounter = 0;
-      
       O << "\t.set\t";
       PrintLabelName("set", SetCounter);
       O << ",";
@@ -936,7 +911,198 @@ public:
       PrintLabelName(TagLo, NumberLo);
     }
   }
-                      
+
+  void EmitSectionOffset(const char* Label, const char* Section,
+                         unsigned LabelNumber, unsigned SectionNumber,
+                         bool IsSmall = false) {
+    if (TAI->needsSet()) {
+      O << "\t.set\t";
+      PrintLabelName("set", SetCounter);
+      O << ",";
+      PrintLabelName(Label, LabelNumber, true);
+      if (!TAI->isAbsoluteSectionOffsets()) {
+        O << "-";
+        PrintLabelName(Section, SectionNumber);
+      }      
+      O << "\n";
+      
+      if (IsSmall || TAI->getAddressSize() == sizeof(int32_t))
+        O << TAI->getData32bitsDirective();
+      else
+        O << TAI->getData64bitsDirective();
+        
+      PrintLabelName("set", SetCounter);
+      ++SetCounter;
+    } else {
+      if (IsSmall || TAI->getAddressSize() == sizeof(int32_t))
+        O << TAI->getData32bitsDirective();
+      else
+        O << TAI->getData64bitsDirective();
+        
+      PrintLabelName(Label, LabelNumber, true);
+      if (!TAI->isAbsoluteSectionOffsets()) {
+        O << "-";
+        PrintLabelName(Section, SectionNumber);
+      }
+    }    
+  }
+  
+  /// EmitFrameMoves - Emit frame instructions to describe the layout of the
+  /// frame.
+  void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
+                                   std::vector<MachineMove> &Moves) {
+    int stackGrowth =
+        Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
+          TargetFrameInfo::StackGrowsUp ?
+            TAI->getAddressSize() : -TAI->getAddressSize();
+    bool IsLocal = BaseLabel && strcmp(BaseLabel, "label") == 0;
+
+    for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
+      MachineMove &Move = Moves[i];
+      unsigned LabelID = Move.getLabelID();
+      
+      if (LabelID) {
+        LabelID = MMI->MappedLabel(LabelID);
+      
+        // Throw out move if the label is invalid.
+        if (!LabelID) continue;
+      }
+      
+      const MachineLocation &Dst = Move.getDestination();
+      const MachineLocation &Src = Move.getSource();
+      
+      // Advance row if new location.
+      if (BaseLabel && LabelID && (BaseLabelID != LabelID || !IsLocal)) {
+        Asm->EmitInt8(DW_CFA_advance_loc4);
+        Asm->EOL("DW_CFA_advance_loc4");
+        EmitDifference("label", LabelID, BaseLabel, BaseLabelID, true);
+        Asm->EOL();
+        
+        BaseLabelID = LabelID;
+        BaseLabel = "label";
+        IsLocal = true;
+      }
+      
+      // If advancing cfa.
+      if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
+        if (!Src.isRegister()) {
+          if (Src.getRegister() == MachineLocation::VirtualFP) {
+            Asm->EmitInt8(DW_CFA_def_cfa_offset);
+            Asm->EOL("DW_CFA_def_cfa_offset");
+          } else {
+            Asm->EmitInt8(DW_CFA_def_cfa);
+            Asm->EOL("DW_CFA_def_cfa");
+            Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister()));
+            Asm->EOL("Register");
+          }
+          
+          int Offset = -Src.getOffset();
+          
+          Asm->EmitULEB128Bytes(Offset);
+          Asm->EOL("Offset");
+        } else {
+          assert(0 && "Machine move no supported yet.");
+        }
+      } else if (Src.isRegister() &&
+        Src.getRegister() == MachineLocation::VirtualFP) {
+        if (Dst.isRegister()) {
+          Asm->EmitInt8(DW_CFA_def_cfa_register);
+          Asm->EOL("DW_CFA_def_cfa_register");
+          Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getRegister()));
+          Asm->EOL("Register");
+        } else {
+          assert(0 && "Machine move no supported yet.");
+        }
+      } else {
+        unsigned Reg = RI->getDwarfRegNum(Src.getRegister());
+        int Offset = Dst.getOffset() / stackGrowth;
+        
+        if (Offset < 0) {
+          Asm->EmitInt8(DW_CFA_offset_extended_sf);
+          Asm->EOL("DW_CFA_offset_extended_sf");
+          Asm->EmitULEB128Bytes(Reg);
+          Asm->EOL("Reg");
+          Asm->EmitSLEB128Bytes(Offset);
+          Asm->EOL("Offset");
+        } else if (Reg < 64) {
+          Asm->EmitInt8(DW_CFA_offset + Reg);
+          Asm->EOL("DW_CFA_offset + Reg");
+          Asm->EmitULEB128Bytes(Offset);
+          Asm->EOL("Offset");
+        } else {
+          Asm->EmitInt8(DW_CFA_offset_extended);
+          Asm->EOL("DW_CFA_offset_extended");
+          Asm->EmitULEB128Bytes(Reg);
+          Asm->EOL("Reg");
+          Asm->EmitULEB128Bytes(Offset);
+          Asm->EOL("Offset");
+        }
+      }
+    }
+  }
+
+};
+
+//===----------------------------------------------------------------------===//
+/// DwarfDebug - Emits Dwarf debug directives. 
+///
+class DwarfDebug : public Dwarf {
+
+private:
+  //===--------------------------------------------------------------------===//
+  // Attributes used to construct specific Dwarf sections.
+  //
+  
+  /// CompileUnits - All the compile units involved in this build.  The index
+  /// of each entry in this vector corresponds to the sources in MMI.
+  std::vector<CompileUnit *> CompileUnits;
+  
+  /// AbbreviationsSet - Used to uniquely define abbreviations.
+  ///
+  FoldingSet<DIEAbbrev> AbbreviationsSet;
+
+  /// Abbreviations - A list of all the unique abbreviations in use.
+  ///
+  std::vector<DIEAbbrev *> Abbreviations;
+  
+  /// ValuesSet - Used to uniquely define values.
+  ///
+  FoldingSet<DIEValue> ValuesSet;
+  
+  /// Values - A list of all the unique values in use.
+  ///
+  std::vector<DIEValue *> Values;
+  
+  /// StringPool - A UniqueVector of strings used by indirect references.
+  ///
+  UniqueVector<std::string> StringPool;
+
+  /// UnitMap - Map debug information descriptor to compile unit.
+  ///
+  std::map<DebugInfoDesc *, CompileUnit *> DescToUnitMap;
+  
+  /// SectionMap - Provides a unique id per text section.
+  ///
+  UniqueVector<std::string> SectionMap;
+  
+  /// SectionSourceLines - Tracks line numbers per text section.
+  ///
+  std::vector<std::vector<SourceLineInfo> > SectionSourceLines;
+
+  /// didInitial - Flag to indicate if initial emission has been done.
+  ///
+  bool didInitial;
+  
+  /// shouldEmit - Flag to indicate if debug information should be emitted.
+  ///
+  bool shouldEmit;
+
+public:
+  
+  /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made.
+  ///
+  bool ShouldEmitDwarf() const { return shouldEmit; }
+
   /// AssignAbbrevNumber - Define a unique number for the abbreviation.
   ///  
   void AssignAbbrevNumber(DIEAbbrev &Abbrev) {
@@ -1522,8 +1688,11 @@ private:
   CompileUnit *NewCompileUnit(CompileUnitDesc *UnitDesc, unsigned ID) {
     // Construct debug information entry.
     DIE *Die = new DIE(DW_TAG_compile_unit);
-    AddDelta(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0),
-                                                  DWLabel("section_line", 0));
+    if (TAI->isAbsoluteSectionOffsets())
+      AddLabel(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0));
+    else
+      AddDelta(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0),
+               DWLabel("section_line", 0));      
     AddString(Die, DW_AT_producer,  DW_FORM_string, UnitDesc->getProducer());
     AddUInt  (Die, DW_AT_language,  DW_FORM_data1,  UnitDesc->getLanguage());
     AddString(Die, DW_AT_name,      DW_FORM_string, UnitDesc->getFileName());
@@ -1702,8 +1871,8 @@ private:
       // FIXME - Ignore inlined functions for the time being.
       if (!Scope->getParent()) continue;
       
-      unsigned StartID = DebugInfo->MappedLabel(Scope->getStartLabelID());
-      unsigned EndID = DebugInfo->MappedLabel(Scope->getEndLabelID());
+      unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID());
+      unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID());
 
       // Ignore empty scopes.
       if (StartID == EndID && StartID != 0) continue;
@@ -1718,14 +1887,14 @@ private:
         // Add the scope bounds.
         if (StartID) {
           AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
-                             DWLabel("loc", StartID));
+                             DWLabel("label", StartID));
         } else {
           AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
                              DWLabel("func_begin", SubprogramCount));
         }
         if (EndID) {
           AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
-                             DWLabel("loc", EndID));
+                             DWLabel("label", EndID));
         } else {
           AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
                              DWLabel("func_end", SubprogramCount));
@@ -1807,12 +1976,12 @@ private:
 
   /// EmitDIE - Recusively Emits a debug information entry.
   ///
-  void EmitDIE(DIE *Die) const {
+  void EmitDIE(DIE *Die) {
     // Get the abbreviation for this DIE.
     unsigned AbbrevNumber = Die->getAbbrevNumber();
     const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
     
-    Asm->EOL("");
+    Asm->EOL();
 
     // Emit the code (index) for the abbreviation.
     Asm->EmitULEB128Bytes(AbbrevNumber);
@@ -1822,7 +1991,7 @@ private:
              ":0x" + utohexstr(Die->getSize()) + " " +
              TagString(Abbrev->getTag())));
     
-    const std::vector<DIEValue *> &Values = Die->getValues();
+    std::vector<DIEValue *> &Values = Die->getValues();
     const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData();
     
     // Emit the DIE attribute values.
@@ -1919,101 +2088,9 @@ private:
     SizeAndOffsetDie(Unit->getDie(), Offset, true);
   }
 
-  /// EmitFrameMoves - Emit frame instructions to describe the layout of the
-  /// frame.
-  void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
-                                   std::vector<MachineMove> &Moves) {
-    int stackGrowth =
-        Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
-          TargetFrameInfo::StackGrowsUp ?
-            TAI->getAddressSize() : -TAI->getAddressSize();
-
-    for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
-      MachineMove &Move = Moves[i];
-      unsigned LabelID = Move.getLabelID();
-      
-      if (LabelID) {
-        LabelID = DebugInfo->MappedLabel(LabelID);
-      
-        // Throw out move if the label is invalid.
-        if (!LabelID) continue;
-      }
-      
-      const MachineLocation &Dst = Move.getDestination();
-      const MachineLocation &Src = Move.getSource();
-      
-      // Advance row if new location.
-      if (BaseLabel && LabelID && BaseLabelID != LabelID) {
-        Asm->EmitInt8(DW_CFA_advance_loc4);
-        Asm->EOL("DW_CFA_advance_loc4");
-        EmitDifference("loc", LabelID, BaseLabel, BaseLabelID, true);
-        Asm->EOL("");
-        
-        BaseLabelID = LabelID;
-        BaseLabel = "loc";
-      }
-      
-      // If advancing cfa.
-      if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
-        if (!Src.isRegister()) {
-          if (Src.getRegister() == MachineLocation::VirtualFP) {
-            Asm->EmitInt8(DW_CFA_def_cfa_offset);
-            Asm->EOL("DW_CFA_def_cfa_offset");
-          } else {
-            Asm->EmitInt8(DW_CFA_def_cfa);
-            Asm->EOL("DW_CFA_def_cfa");
-            Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister()));
-            Asm->EOL("Register");
-          }
-          
-          int Offset = Src.getOffset() / stackGrowth;
-          
-          Asm->EmitULEB128Bytes(Offset);
-          Asm->EOL("Offset");
-        } else {
-          assert(0 && "Machine move no supported yet.");
-        }
-      } else if (Src.isRegister() &&
-        Src.getRegister() == MachineLocation::VirtualFP) {
-        if (Dst.isRegister()) {
-          Asm->EmitInt8(DW_CFA_def_cfa_register);
-          Asm->EOL("DW_CFA_def_cfa_register");
-          Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getRegister()));
-          Asm->EOL("Register");
-        } else {
-          assert(0 && "Machine move no supported yet.");
-        }
-      } else {
-        unsigned Reg = RI->getDwarfRegNum(Src.getRegister());
-        int Offset = Dst.getOffset() / stackGrowth;
-        
-        if (Offset < 0) {
-          Asm->EmitInt8(DW_CFA_offset_extended_sf);
-          Asm->EOL("DW_CFA_offset_extended_sf");
-          Asm->EmitULEB128Bytes(Reg);
-          Asm->EOL("Reg");
-          Asm->EmitSLEB128Bytes(Offset);
-          Asm->EOL("Offset");
-        } else if (Reg < 64) {
-          Asm->EmitInt8(DW_CFA_offset + Reg);
-          Asm->EOL("DW_CFA_offset + Reg");
-          Asm->EmitULEB128Bytes(Offset);
-          Asm->EOL("Offset");
-        } else {
-          Asm->EmitInt8(DW_CFA_offset_extended);
-          Asm->EOL("DW_CFA_offset_extended");
-          Asm->EmitULEB128Bytes(Reg);
-          Asm->EOL("Reg");
-          Asm->EmitULEB128Bytes(Offset);
-          Asm->EOL("Offset");
-        }
-      }
-    }
-  }
-
   /// EmitDebugInfo - Emit the debug info section.
   ///
-  void EmitDebugInfo() const {
+  void EmitDebugInfo() {
     // Start debug info section.
     Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
     
@@ -2030,7 +2107,7 @@ private:
                            
     Asm->EmitInt32(ContentSize);  Asm->EOL("Length of Compilation Unit Info");
     Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number");
-    EmitDifference("abbrev_begin", 0, "section_abbrev", 0, true);
+    EmitSectionOffset("abbrev_begin", "section_abbrev", 0, 0, true);
     Asm->EOL("Offset Into Abbrev. Section");
     Asm->EmitInt8(TAI->getAddressSize()); Asm->EOL("Address Size (in bytes)");
   
@@ -2042,7 +2119,7 @@ private:
     Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
     EmitLabel("info_end", Unit->getID());
     
-    Asm->EOL("");
+    Asm->EOL();
   }
 
   /// EmitAbbreviations - Emit the abbreviation section.
@@ -2067,18 +2144,21 @@ private:
         // Emit the abbreviations data.
         Abbrev->Emit(*this);
     
-        Asm->EOL("");
+        Asm->EOL();
       }
       
+      // Mark end of abbreviations.
+      Asm->EmitULEB128Bytes(0); Asm->EOL("EOM(3)");
+
       EmitLabel("abbrev_end", 0);
     
-      Asm->EOL("");
+      Asm->EOL();
     }
   }
 
   /// EmitDebugLines - Emit source line information.
   ///
-  void EmitDebugLines() const {
+  void EmitDebugLines() {
     // Minimum line delta, thus ranging from -10..(255-10).
     const int MinLineDelta = -(DW_LNS_fixed_advance_pc + 1);
     // Maximum line delta, thus ranging from -10..(255-10).
@@ -2120,9 +2200,9 @@ private:
     Asm->EmitInt8(0); Asm->EOL("DW_LNS_const_add_pc arg count");
     Asm->EmitInt8(1); Asm->EOL("DW_LNS_fixed_advance_pc arg count");
 
-    const UniqueVector<std::string> &Directories = DebugInfo->getDirectories();
+    const UniqueVector<std::string> &Directories = MMI->getDirectories();
     const UniqueVector<SourceFileInfo>
-      &SourceFiles = DebugInfo->getSourceFiles();
+      &SourceFiles = MMI->getSourceFiles();
 
     // Emit directories.
     for (unsigned DirectoryID = 1, NDID = Directories.size();
@@ -2162,7 +2242,7 @@ private:
       // Construct rows of the address, source, line, column matrix.
       for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
         const SourceLineInfo &LineInfo = LineInfos[i];
-        unsigned LabelID = DebugInfo->MappedLabel(LineInfo.getLabelID());
+        unsigned LabelID = MMI->MappedLabel(LineInfo.getLabelID());
         if (!LabelID) continue;
         
         unsigned SourceID = LineInfo.getSourceID();
@@ -2177,7 +2257,7 @@ private:
         Asm->EmitInt8(0); Asm->EOL("Extended Op");
         Asm->EmitInt8(TAI->getAddressSize() + 1); Asm->EOL("Op size");
         Asm->EmitInt8(DW_LNE_set_address); Asm->EOL("DW_LNE_set_address");
-        EmitReference("loc",  LabelID); Asm->EOL("Location label");
+        EmitReference("label",  LabelID); Asm->EOL("Location label");
         
         // If change of source, then switch to the new source.
         if (Source != LineInfo.getSourceID()) {
@@ -2219,13 +2299,13 @@ private:
 
       // Mark end of matrix.
       Asm->EmitInt8(0); Asm->EOL("DW_LNE_end_sequence");
-      Asm->EmitULEB128Bytes(1); Asm->EOL("");
-      Asm->EmitInt8(1); Asm->EOL("");
+      Asm->EmitULEB128Bytes(1); Asm->EOL();
+      Asm->EmitInt8(1); Asm->EOL();
     }
     
     EmitLabel("line_end", 0);
     
-    Asm->EOL("");
+    Asm->EOL();
   }
     
   /// EmitInitialDebugFrame - Emit common frame info into a debug frame section.
@@ -2268,7 +2348,7 @@ private:
     Asm->EmitAlignment(2);
     EmitLabel("frame_common_end", 0);
     
-    Asm->EOL("");
+    Asm->EOL();
   }
 
   /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
@@ -2285,8 +2365,8 @@ private:
     Asm->EOL("Length of Frame Information Entry");
     
     EmitLabel("frame_begin", SubprogramCount);
-    
-    EmitDifference("frame_common", 0, "section_frame", 0, true);
+
+    EmitSectionOffset("frame_common_begin", "section_frame", 0, 0, true);
     Asm->EOL("FDE CIE offset");
 
     EmitReference("func_begin", SubprogramCount);
@@ -2295,14 +2375,14 @@ private:
                    "func_begin", SubprogramCount);
     Asm->EOL("FDE address range");
     
-    std::vector<MachineMove> &Moves = DebugInfo->getFrameMoves();
+    std::vector<MachineMove> &Moves = MMI->getFrameMoves();
     
     EmitFrameMoves("func_begin", SubprogramCount, Moves);
     
     Asm->EmitAlignment(2);
     EmitLabel("frame_end", SubprogramCount);
 
-    Asm->EOL("");
+    Asm->EOL();
   }
 
   /// EmitDebugPubNames - Emit visible names into a debug pubnames section.
@@ -2320,8 +2400,8 @@ private:
     EmitLabel("pubnames_begin", Unit->getID());
     
     Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF Version");
-    
-    EmitDifference("info_begin", Unit->getID(), "section_info", 0, true);
+
+    EmitSectionOffset("info_begin", "section_info", Unit->getID(), 0, true);
     Asm->EOL("Offset of Compilation Unit Info");
 
     EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID(),true);
@@ -2342,7 +2422,7 @@ private:
     Asm->EmitInt32(0); Asm->EOL("End Mark");
     EmitLabel("pubnames_end", Unit->getID());
   
-    Asm->EOL("");
+    Asm->EOL();
   }
 
   /// EmitDebugStr - Emit visible names into a debug str section.
@@ -2360,10 +2440,10 @@ private:
         EmitLabel("string", StringID);
         // Emit the string itself.
         const std::string &String = StringPool[StringID];
-        Asm->EmitString(String); Asm->EOL("");
+        Asm->EmitString(String); Asm->EOL();
       }
     
-      Asm->EOL("");
+      Asm->EOL();
     }
   }
 
@@ -2373,7 +2453,7 @@ private:
     // Start the dwarf loc section.
     Asm->SwitchToDataSection(TAI->getDwarfLocSection());
     
-    Asm->EOL("");
+    Asm->EOL();
   }
 
   /// EmitDebugARanges - Emit visible names into a debug aranges section.
@@ -2408,7 +2488,7 @@ private:
     Asm->EmitInt32(0); Asm->EOL("EOM (1)");
     Asm->EmitInt32(0); Asm->EOL("EOM (2)");
     
-    Asm->EOL("");
+    Asm->EOL();
   #endif
   }
 
@@ -2418,7 +2498,7 @@ private:
     // Start the dwarf ranges section.
     Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
     
-    Asm->EOL("");
+    Asm->EOL();
   }
 
   /// EmitDebugMacInfo - Emit visible names into a debug macinfo section.
@@ -2427,16 +2507,16 @@ private:
     // Start the dwarf macinfo section.
     Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
     
-    Asm->EOL("");
+    Asm->EOL();
   }
 
   /// ConstructCompileUnitDIEs - Create a compile unit DIE for each source and
   /// header file.
   void ConstructCompileUnitDIEs() {
-    const UniqueVector<CompileUnitDesc *> CUW = DebugInfo->getCompileUnits();
+    const UniqueVector<CompileUnitDesc *> CUW = MMI->getCompileUnits();
     
     for (unsigned i = 1, N = CUW.size(); i <= N; ++i) {
-      unsigned ID = DebugInfo->RecordSource(CUW[i]);
+      unsigned ID = MMI->RecordSource(CUW[i]);
       CompileUnit *Unit = NewCompileUnit(CUW[i], ID);
       CompileUnits.push_back(Unit);
     }
@@ -2446,7 +2526,7 @@ private:
   /// global variables.
   void ConstructGlobalDIEs() {
     std::vector<GlobalVariableDesc *> GlobalVariables =
-        DebugInfo->getAnchoredDescriptors<GlobalVariableDesc>(*M);
+        MMI->getAnchoredDescriptors<GlobalVariableDesc>(*M);
     
     for (unsigned i = 0, N = GlobalVariables.size(); i < N; ++i) {
       GlobalVariableDesc *GVD = GlobalVariables[i];
@@ -2458,7 +2538,7 @@ private:
   /// subprograms.
   void ConstructSubprogramDIEs() {
     std::vector<SubprogramDesc *> Subprograms =
-        DebugInfo->getAnchoredDescriptors<SubprogramDesc>(*M);
+        MMI->getAnchoredDescriptors<SubprogramDesc>(*M);
     
     for (unsigned i = 0, N = Subprograms.size(); i < N; ++i) {
       SubprogramDesc *SPD = Subprograms[i];
@@ -2466,26 +2546,12 @@ private:
     }
   }
 
-  /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made.
-  ///
-  bool ShouldEmitDwarf() const { return shouldEmit; }
-
 public:
   //===--------------------------------------------------------------------===//
   // Main entry points.
   //
-  Dwarf(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
-  : O(OS)
-  , Asm(A)
-  , TAI(T)
-  , TD(Asm->TM.getTargetData())
-  , RI(Asm->TM.getRegisterInfo())
-  , M(NULL)
-  , MF(NULL)
-  , DebugInfo(NULL)
-  , didInitial(false)
-  , shouldEmit(false)
-  , SubprogramCount(0)
+  DwarfDebug(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
+  : Dwarf(OS, A, T)
   , CompileUnits()
   , AbbreviationsSet(InitAbbreviationsSetSize)
   , Abbreviations()
@@ -2495,25 +2561,23 @@ public:
   , DescToUnitMap()
   , SectionMap()
   , SectionSourceLines()
+  , didInitial(false)
+  , shouldEmit(false)
   {
   }
-  virtual ~Dwarf() {
+  virtual ~DwarfDebug() {
     for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i)
       delete CompileUnits[i];
     for (unsigned j = 0, M = Values.size(); j < M; ++j)
       delete Values[j];
   }
 
-  // Accessors.
-  //
-  const TargetAsmInfo *getTargetAsmInfo() const { return TAI; }
-  
-  /// SetDebugInfo - Set DebugInfo when it's known that pass manager has
-  /// created it.  Set by the target AsmPrinter.
-  void SetDebugInfo(MachineDebugInfo *DI) {
+  /// SetModuleInfo - Set machine module information when it's known that pass
+  /// manager has created it.  Set by the target AsmPrinter.
+  void SetModuleInfo(MachineModuleInfo *mmi) {
     // Make sure initial declarations are made.
-    if (!DebugInfo && DI->hasInfo()) {
-      DebugInfo = DI;
+    if (!MMI && mmi->hasDebugInfo()) {
+      MMI = mmi;
       shouldEmit = true;
       
       // Emit initial sections
@@ -2539,14 +2603,12 @@ public:
     this->M = M;
     
     if (!ShouldEmitDwarf()) return;
-    Asm->EOL("Dwarf Begin Module");
   }
 
   /// EndModule - Emit all Dwarf sections that should come after the content.
   ///
   void EndModule() {
     if (!ShouldEmitDwarf()) return;
-    Asm->EOL("Dwarf End Module");
     
     // Standard sections final addresses.
     Asm->SwitchToTextSection(TAI->getTextSection());
@@ -2597,26 +2659,24 @@ public:
     this->MF = MF;
     
     if (!ShouldEmitDwarf()) return;
-    Asm->EOL("Dwarf Begin Function");
 
     // Begin accumulating function debug information.
-    DebugInfo->BeginFunction(MF);
+    MMI->BeginFunction(MF);
     
     // Assumes in correct section after the entry point.
     EmitLabel("func_begin", ++SubprogramCount);
   }
-
+  
   /// EndFunction - Gather and emit post-function debug information.
   ///
   void EndFunction() {
     if (!ShouldEmitDwarf()) return;
-    Asm->EOL("Dwarf End Function");
     
     // Define end label for subprogram.
     EmitLabel("func_end", SubprogramCount);
       
     // Get function line info.
-    const std::vector<SourceLineInfo> &LineInfos = DebugInfo->getSourceLines();
+    const std::vector<SourceLineInfo> &LineInfos = MMI->getSourceLines();
 
     if (!LineInfos.empty()) {
       // Get section line info.
@@ -2629,16 +2689,445 @@ public:
     }
     
     // Construct scopes for subprogram.
-    ConstructRootScope(DebugInfo->getRootScope());
+    ConstructRootScope(MMI->getRootScope());
     
     // Emit function frame information.
     EmitFunctionDebugFrame();
+  }
+};
+
+//===----------------------------------------------------------------------===//
+/// DwarfException - Emits Dwarf exception handling directives. 
+///
+class DwarfException : public Dwarf  {
+
+private:
+
+  /// didInitial - Flag to indicate if initial emission has been done.
+  ///
+  bool didInitial;
+  
+  /// shouldEmit - Flag to indicate if debug information should be emitted.
+  ///
+  bool shouldEmit;
+  
+  /// FuncCPPPersonality - C++ persoanlity function.
+  ///
+  Function *FuncCPPPersonality;
+
+  /// EmitCommonEHFrame - Emit the common eh unwind frame.
+  ///
+  void EmitCommonEHFrame() {
+    // Only do it once.
+    if (didInitial) return;
+    didInitial = true;
     
-    // Reset the line numbers for the next function.
-    DebugInfo->ClearLineInfo();
+    // If there is a personality present then we need to indicate that
+    // in the common eh frame.
+    Function *Personality = FuncCPPPersonality;
 
-    // Clear function debug information.
-    DebugInfo->EndFunction();
+    // Size and sign of stack growth.
+    int stackGrowth =
+        Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
+          TargetFrameInfo::StackGrowsUp ?
+        TAI->getAddressSize() : -TAI->getAddressSize();
+
+    // Begin eh frame section.
+    Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
+    O << "EH_frame:\n";
+    EmitLabel("section_eh_frame", 0);
+
+    // Define base labels.
+    EmitLabel("eh_frame_common", 0);
+    
+    // Define the eh frame length.
+    EmitDifference("eh_frame_common_end", 0,
+                   "eh_frame_common_begin", 0, true);
+    Asm->EOL("Length of Common Information Entry");
+
+    // EH frame header.
+    EmitLabel("eh_frame_common_begin", 0);
+    Asm->EmitInt32((int)0);
+    Asm->EOL("CIE Identifier Tag");
+    Asm->EmitInt8(DW_CIE_VERSION);
+    Asm->EOL("CIE Version");
+    
+    // The personality presence indicates that language specific information
+    // will show up in the eh frame.
+    Asm->EmitString(Personality ? "zPLR" : "zR");
+    Asm->EOL("CIE Augmentation");
+    
+    // Round out reader.
+    Asm->EmitULEB128Bytes(1);
+    Asm->EOL("CIE Code Alignment Factor");
+    Asm->EmitSLEB128Bytes(stackGrowth);
+    Asm->EOL("CIE Data Alignment Factor");   
+    Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister()));
+    Asm->EOL("CIE RA Column");
+    
+    // If there is a personality, we need to indicate the functions location.
+    if (Personality) {
+      Asm->EmitULEB128Bytes(7);
+      Asm->EOL("Augmentation Size");
+      Asm->EmitInt8(DW_EH_PE_indirect |
+                            DW_EH_PE_pcrel |
+                            DW_EH_PE_sdata4);
+      Asm->EOL("Personality (indirect pcrel sdata4)");
+      
+      O << TAI->getData32bitsDirective();
+      Asm->EmitExternalGlobal((const GlobalVariable *)(Personality));
+      O << "-" << TAI->getPCSymbol();
+      Asm->EOL("Personality");
+      
+      Asm->EmitULEB128Bytes(DW_EH_PE_pcrel);
+      Asm->EOL("LSDA Encoding (pcrel)");
+      Asm->EmitULEB128Bytes(DW_EH_PE_pcrel);
+      Asm->EOL("FDE Encoding (pcrel)");
+   } else {
+      Asm->EmitULEB128Bytes(1);
+      Asm->EOL("Augmentation Size");
+      Asm->EmitULEB128Bytes(DW_EH_PE_pcrel);
+      Asm->EOL("FDE Encoding (pcrel)");
+    }
+
+    // Indicate locations of general callee saved registers in frame.
+    std::vector<MachineMove> Moves;
+    RI->getInitialFrameState(Moves);
+    EmitFrameMoves(NULL, 0, Moves);
+
+    Asm->EmitAlignment(2);
+    EmitLabel("eh_frame_common_end", 0);
+    
+    Asm->EOL();
+  }
+  
+  /// EmitEHFrame - Emit initial exception information.
+  ///
+  void EmitEHFrame() {
+    // If there is a personality present then we need to indicate that
+    // in the common eh frame.
+    Function *Personality = FuncCPPPersonality;
+//    Function *Personality = MMI->getPersonality();
+    MachineFrameInfo *MFI = MF->getFrameInfo();
+
+    Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
+
+    // Externally visible entry into the functions eh frame info.
+    if (const char *GlobalDirective = TAI->getGlobalDirective())
+      O << GlobalDirective << getAsm()->CurrentFnName << ".eh\n";
+    
+    // If there are no calls then you can't unwind.
+    if (!MFI->hasCalls()) { 
+      O << getAsm()->CurrentFnName << ".eh = 0\n";
+    } else {
+      O << getAsm()->CurrentFnName << ".eh:\n";
+      
+      // EH frame header.
+      EmitDifference("eh_frame_end", SubprogramCount,
+                     "eh_frame_begin", SubprogramCount, true);
+      Asm->EOL("Length of Frame Information Entry");
+      
+      EmitLabel("eh_frame_begin", SubprogramCount);
+
+      EmitSectionOffset("eh_frame_begin", "section_eh_frame",
+                        SubprogramCount, 0, true);
+      Asm->EOL("FDE CIE offset");
+
+      EmitReference("eh_func_begin", SubprogramCount, true);
+      Asm->EOL("FDE initial location");
+      EmitDifference("eh_func_end", SubprogramCount,
+                     "eh_func_begin", SubprogramCount);
+      Asm->EOL("FDE address range");
+      
+      // If there is a personality and landing pads then point to the language
+      // specific data area in the exception table.
+      if (Personality) {
+        Asm->EmitULEB128Bytes(4);
+        Asm->EOL("Augmentation size");
+        
+        if (!MMI->getLandingPads().empty()) {
+          EmitReference("exception", SubprogramCount, true);
+        } else if(TAI->getAddressSize() == 8) {
+          Asm->EmitInt64((int)0);
+        } else {
+          Asm->EmitInt32((int)0);
+        }
+        Asm->EOL("Language Specific Data Area");
+      } else {
+        Asm->EmitULEB128Bytes(0);
+        Asm->EOL("Augmentation size");
+      }
+      
+      // Indicate locations of function specific  callee saved registers in
+      // frame.
+      std::vector<MachineMove> &Moves = MMI->getFrameMoves();
+      EmitFrameMoves("eh_func_begin", SubprogramCount, Moves);
+      
+      Asm->EmitAlignment(2);
+      EmitLabel("eh_frame_end", SubprogramCount);
+    }
+    
+    if (const char *UsedDirective = TAI->getUsedDirective())
+      O << UsedDirective << getAsm()->CurrentFnName << ".eh\n\n";
+  }
+  
+  /// EmitExceptionTable - Emit landpads and actions.
+  ///
+  /// The general organization of the table is complex, but the basic concepts
+  /// are easy.  First there is a header which describes the location and
+  /// organization of the three components that follow.
+  ///  1. The landing pad site information describes the range of code covered
+  ///     by the try.  In our case it's an accumulation of the ranges covered
+  ///     by the invokes in the try.  There is also a reference to the landing
+  ///     pad that handles the exception once processed.  Finally an index into
+  ///     the actions table.
+  ///  2. The action table, in our case, is composed of pairs of type ids
+  ///     and next action offset.  Starting with the action index from the
+  ///     landing pad site, each type Id is checked for a match to the current
+  ///     exception.  If it matches then the exception and type id are passed
+  ///     on to the landing pad.  Otherwise the next action is looked up.  This
+  ///     chain is terminated with a next action of zero.  If no type id is
+  ///     found the the frame is unwound and handling continues.
+  ///  3. Type id table contains references to all the C++ typeinfo for all
+  ///     catches in the function.  This tables is reversed indexed base 1.
+  void EmitExceptionTable() {
+    // Map all labels and get rid of any dead landing pads.
+    MMI->TidyLandingPads();
+    
+    const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
+    const std::vector<LandingPadInfo> &LandingPads = MMI->getLandingPads();
+    if (LandingPads.empty()) return;
+    
+    // FIXME - Should fold actions for multiple landing pads.
+    
+    // Gather first action index for each landing pad site.
+    SmallVector<unsigned, 8> Actions;
+    
+    // FIXME - Assume there is only one filter typeinfo list per function
+    // time being.  I.E., Each call to eh_filter will have the same list.
+    // This can change if a function is inlined. 
+    const LandingPadInfo *Filter = 0;
+
+    // Compute sizes for exception table.
+    unsigned SizeHeader = sizeof(int8_t) + // LPStart format
+                          sizeof(int8_t) + // TType format
+                          sizeof(int8_t) + // TType base offset (NEED ULEB128)
+                          sizeof(int8_t) + // Call site format
+                          sizeof(int8_t);  // Call-site table length
+    unsigned SizeSites = 0;
+    unsigned SizeActions = 0;
+
+    // Look at each landing pad site to compute size.  We need the size of each
+    // landing pad site info and the size of the landing pad's actions.
+    for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
+      const LandingPadInfo &LandingPad = LandingPads[i];
+      bool IsFilter = LandingPad.IsFilter;
+      unsigned SizeSiteActions = 0;
+      const std::vector<unsigned> &TypeIds = LandingPad.TypeIds;
+      unsigned SizeAction = 0;
+      signed FirstAction;
+      
+      if (IsFilter) {
+        // FIXME - Assume there is only one filter typeinfo list per function
+        // time being.  I.E., Each call to eh_filter will have the same list.
+        // This can change if a function is inlined. 
+        Filter = &LandingPad;
+        SizeAction =  Asm->SizeSLEB128(-1) + Asm->SizeSLEB128(0);
+        SizeSiteActions += SizeAction;
+        // Record the first action of the landing pad site.
+        FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
+      } else if (TypeIds.empty()) {
+        FirstAction = 0;
+      } else {
+        // Gather the action sizes
+        for (unsigned j = 0, M = TypeIds.size(); j != M; ++j) {
+          unsigned TypeID = TypeIds[i];
+          unsigned SizeTypeID = Asm->SizeSLEB128(TypeID);
+          signed Action = j ? -(SizeAction + SizeTypeID) : 0;
+          SizeAction = SizeTypeID + Asm->SizeSLEB128(Action);
+          SizeSiteActions += SizeAction;
+        }
+        
+        // Record the first action of the landing pad site.
+        FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
+      }
+      
+      Actions.push_back(FirstAction);
+      
+      // Compute this sites contribution to size.
+      SizeActions += SizeSiteActions;
+      SizeSites += sizeof(int32_t) + // Site start.
+                   sizeof(int32_t) + // Site length.
+                   sizeof(int32_t) + // Landing pad.
+                   Asm->SizeSLEB128(FirstAction); // Action.
+    }
+    
+    // Final tallies.
+    unsigned SizeTypes = TypeInfos.size() * TAI->getAddressSize();
+    unsigned SizePreType = SizeHeader + SizeSites + SizeActions;
+    unsigned SizeAlign =  (4 - SizePreType) & 3;
+    unsigned TypeOffset = SizePreType +
+                          SizeTypes +
+                          SizeAlign - 
+                          sizeof(int8_t) - // LPStart format
+                          sizeof(int8_t) - // TType format
+                          sizeof(int8_t);  // TType base offset (NEED ULEB128)
+    
+    // Begin the exception table.
+    Asm->SwitchToDataSection(TAI->getDwarfExceptionSection());
+    O << "GCC_except_table" << SubprogramCount << ":\n";
+    EmitLabel("exception", SubprogramCount);
+    
+    // Emit the header.
+    Asm->EmitInt8(DW_EH_PE_omit);
+    Asm->EOL("LPStart format (DW_EH_PE_omit)");
+    Asm->EmitInt8(DW_EH_PE_absptr);
+    Asm->EOL("TType format (DW_EH_PE_absptr)");
+    Asm->EmitULEB128Bytes(TypeOffset);
+    Asm->EOL("TType base offset");
+    Asm->EmitInt8(DW_EH_PE_udata4);
+    Asm->EOL("Call site format (DW_EH_PE_udata4)");
+    Asm->EmitULEB128Bytes(SizeSites);
+    Asm->EOL("Call-site table length");
+    
+    // Emit the landng pad site information.
+    for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
+      const LandingPadInfo &LandingPad = LandingPads[i];
+      EmitSectionOffset("label", "eh_func_begin",
+                        LandingPad.BeginLabel, SubprogramCount);
+      Asm->EOL("Region start");
+      
+      EmitDifference("label", LandingPad.EndLabel,
+                     "label", LandingPad.BeginLabel);
+      Asm->EOL("Region length");
+      
+      if (LandingPad.TypeIds.empty()) {
+        if (TAI->getAddressSize() == sizeof(int32_t))
+          Asm->EmitInt32(0);
+        else
+          Asm->EmitInt64(0);
+      } else {
+        EmitSectionOffset("label", "eh_func_begin",
+                          LandingPad.LandingPadLabel, SubprogramCount);
+      }
+      Asm->EOL("Landing pad");
+
+      Asm->EmitULEB128Bytes(Actions[i]);
+      Asm->EOL("Action");
+    }
+    
+    // Emit the actions.
+    for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
+      const LandingPadInfo &LandingPad = LandingPads[i];
+      const std::vector<unsigned> &TypeIds = LandingPad.TypeIds;
+      unsigned SizeAction = 0;
+      
+      if (LandingPad.IsFilter) {
+        Asm->EmitSLEB128Bytes(-1);
+        Asm->EOL("TypeInfo index");
+        Asm->EmitSLEB128Bytes(0);
+        Asm->EOL("Next action");
+      } else {
+        for (unsigned j = 0, M = TypeIds.size(); j < M; ++j) {
+          unsigned TypeID = TypeIds[j];
+          unsigned SizeTypeID = Asm->SizeSLEB128(TypeID);
+          Asm->EmitSLEB128Bytes(TypeID);
+          Asm->EOL("TypeInfo index");
+          signed Action = j ? -(SizeAction + SizeTypeID) : 0;
+          SizeAction = SizeTypeID + Asm->SizeSLEB128(Action);
+          Asm->EmitSLEB128Bytes(Action);
+          Asm->EOL("Next action");
+        }
+      }
+    }
+
+    // Emit the type ids.
+    Asm->EmitAlignment(2);
+    for (unsigned M = TypeInfos.size(); M; --M) {
+      GlobalVariable *GV = TypeInfos[M - 1];
+      
+      if (TAI->getAddressSize() == sizeof(int32_t))
+        O << TAI->getData32bitsDirective();
+      else
+        O << TAI->getData64bitsDirective();
+
+      if (GV)
+        O << Asm->getGlobalLinkName(GV);
+      else
+        O << "0";
+      
+      Asm->EOL("TypeInfo");
+    }
+
+    // Emit the filter typeinfo.
+    if (Filter) {
+      const std::vector<unsigned> &TypeIds = Filter->TypeIds;
+      for (unsigned j = 0, M = TypeIds.size(); j < M; ++j) {
+        unsigned TypeID = TypeIds[j];
+        Asm->EmitSLEB128Bytes(TypeID);
+        Asm->EOL("TypeInfo index");
+      }
+      Asm->EmitSLEB128Bytes(0);
+      Asm->EOL("End of filter typeinfo");
+    }
+    
+    Asm->EmitAlignment(2);
+  }
+
+public:
+  //===--------------------------------------------------------------------===//
+  // Main entry points.
+  //
+  DwarfException(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
+  : Dwarf(OS, A, T)
+  , didInitial(false)
+  , shouldEmit(false)
+  , FuncCPPPersonality(NULL)
+  {}
+  
+  virtual ~DwarfException() {}
+
+  /// SetModuleInfo - Set machine module information when it's known that pass
+  /// manager has created it.  Set by the target AsmPrinter.
+  void SetModuleInfo(MachineModuleInfo *mmi) {
+    MMI = mmi;
+  }
+
+  /// BeginModule - Emit all exception information that should come prior to the
+  /// content.
+  void BeginModule(Module *M) {
+    this->M = M;
+    FuncCPPPersonality = M->getFunction("__gxx_personality_v0");
+  }
+
+  /// EndModule - Emit all exception information that should come after the
+  /// content.
+  void EndModule() {
+  }
+
+  /// BeginFunction - Gather pre-function exception information.  Assumes being 
+  /// emitted immediately after the function entry point.
+  void BeginFunction(MachineFunction *MF) {
+    this->MF = MF;
+    
+    if (MMI &&
+        ExceptionHandling &&
+        TAI->getSupportsExceptionHandling()) {
+      shouldEmit = true;
+      // Assumes in correct section after the entry point.
+      EmitLabel("eh_func_begin", ++SubprogramCount);
+    }
+  }
+
+  /// EndFunction - Gather and emit post-function exception information.
+  ///
+  void EndFunction() {
+    if (!shouldEmit) return;
+
+    EmitLabel("eh_func_end", SubprogramCount);
+    EmitExceptionTable();
+    EmitCommonEHFrame();
+    EmitEHFrame();
   }
 };
 
@@ -2648,31 +3137,31 @@ public:
 
 /// Emit - Print the abbreviation using the specified Dwarf writer.
 ///
-void DIEAbbrev::Emit(const Dwarf &DW) const {
+void DIEAbbrev::Emit(const DwarfDebug &DD) const {
   // Emit its Dwarf tag type.
-  DW.getAsm()->EmitULEB128Bytes(Tag);
-  DW.getAsm()->EOL(TagString(Tag));
+  DD.getAsm()->EmitULEB128Bytes(Tag);
+  DD.getAsm()->EOL(TagString(Tag));
   
   // Emit whether it has children DIEs.
-  DW.getAsm()->EmitULEB128Bytes(ChildrenFlag);
-  DW.getAsm()->EOL(ChildrenString(ChildrenFlag));
+  DD.getAsm()->EmitULEB128Bytes(ChildrenFlag);
+  DD.getAsm()->EOL(ChildrenString(ChildrenFlag));
   
   // For each attribute description.
   for (unsigned i = 0, N = Data.size(); i < N; ++i) {
     const DIEAbbrevData &AttrData = Data[i];
     
     // Emit attribute type.
-    DW.getAsm()->EmitULEB128Bytes(AttrData.getAttribute());
-    DW.getAsm()->EOL(AttributeString(AttrData.getAttribute()));
+    DD.getAsm()->EmitULEB128Bytes(AttrData.getAttribute());
+    DD.getAsm()->EOL(AttributeString(AttrData.getAttribute()));
     
     // Emit form type.
-    DW.getAsm()->EmitULEB128Bytes(AttrData.getForm());
-    DW.getAsm()->EOL(FormEncodingString(AttrData.getForm()));
+    DD.getAsm()->EmitULEB128Bytes(AttrData.getForm());
+    DD.getAsm()->EOL(FormEncodingString(AttrData.getForm()));
   }
 
   // Mark end of abbreviation.
-  DW.getAsm()->EmitULEB128Bytes(0); DW.getAsm()->EOL("EOM(1)");
-  DW.getAsm()->EmitULEB128Bytes(0); DW.getAsm()->EOL("EOM(2)");
+  DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(1)");
+  DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(2)");
 }
 
 #ifndef NDEBUG
@@ -2708,26 +3197,26 @@ void DIEValue::dump() {
 
 /// EmitValue - Emit integer of appropriate size.
 ///
-void DIEInteger::EmitValue(const Dwarf &DW, unsigned Form) const {
+void DIEInteger::EmitValue(DwarfDebug &DD, unsigned Form) {
   switch (Form) {
   case DW_FORM_flag:  // Fall thru
   case DW_FORM_ref1:  // Fall thru
-  case DW_FORM_data1: DW.getAsm()->EmitInt8(Integer);         break;
+  case DW_FORM_data1: DD.getAsm()->EmitInt8(Integer);         break;
   case DW_FORM_ref2:  // Fall thru
-  case DW_FORM_data2: DW.getAsm()->EmitInt16(Integer);        break;
+  case DW_FORM_data2: DD.getAsm()->EmitInt16(Integer);        break;
   case DW_FORM_ref4:  // Fall thru
-  case DW_FORM_data4: DW.getAsm()->EmitInt32(Integer);        break;
+  case DW_FORM_data4: DD.getAsm()->EmitInt32(Integer);        break;
   case DW_FORM_ref8:  // Fall thru
-  case DW_FORM_data8: DW.getAsm()->EmitInt64(Integer);        break;
-  case DW_FORM_udata: DW.getAsm()->EmitULEB128Bytes(Integer); break;
-  case DW_FORM_sdata: DW.getAsm()->EmitSLEB128Bytes(Integer); break;
+  case DW_FORM_data8: DD.getAsm()->EmitInt64(Integer);        break;
+  case DW_FORM_udata: DD.getAsm()->EmitULEB128Bytes(Integer); break;
+  case DW_FORM_sdata: DD.getAsm()->EmitSLEB128Bytes(Integer); break;
   default: assert(0 && "DIE Value form not supported yet");   break;
   }
 }
 
 /// SizeOf - Determine size of integer value in bytes.
 ///
-unsigned DIEInteger::SizeOf(const Dwarf &DW, unsigned Form) const {
+unsigned DIEInteger::SizeOf(const DwarfDebug &DD, unsigned Form) const {
   switch (Form) {
   case DW_FORM_flag:  // Fall thru
   case DW_FORM_ref1:  // Fall thru
@@ -2738,8 +3227,8 @@ unsigned DIEInteger::SizeOf(const Dwarf &DW, unsigned Form) const {
   case DW_FORM_data4: return sizeof(int32_t);
   case DW_FORM_ref8:  // Fall thru
   case DW_FORM_data8: return sizeof(int64_t);
-  case DW_FORM_udata: return DW.getAsm()->SizeULEB128(Integer);
-  case DW_FORM_sdata: return DW.getAsm()->SizeSLEB128(Integer);
+  case DW_FORM_udata: return DD.getAsm()->SizeULEB128(Integer);
+  case DW_FORM_sdata: return DD.getAsm()->SizeSLEB128(Integer);
   default: assert(0 && "DIE Value form not supported yet"); break;
   }
   return 0;
@@ -2749,72 +3238,72 @@ unsigned DIEInteger::SizeOf(const Dwarf &DW, unsigned Form) const {
 
 /// EmitValue - Emit string value.
 ///
-void DIEString::EmitValue(const Dwarf &DW, unsigned Form) const {
-  DW.getAsm()->EmitString(String);
+void DIEString::EmitValue(DwarfDebug &DD, unsigned Form) {
+  DD.getAsm()->EmitString(String);
 }
 
 //===----------------------------------------------------------------------===//
 
 /// EmitValue - Emit label value.
 ///
-void DIEDwarfLabel::EmitValue(const Dwarf &DW, unsigned Form) const {
-  DW.EmitReference(Label);
+void DIEDwarfLabel::EmitValue(DwarfDebug &DD, unsigned Form) {
+  DD.EmitReference(Label);
 }
 
 /// SizeOf - Determine size of label value in bytes.
 ///
-unsigned DIEDwarfLabel::SizeOf(const Dwarf &DW, unsigned Form) const {
-  return DW.getTargetAsmInfo()->getAddressSize();
+unsigned DIEDwarfLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
+  return DD.getTargetAsmInfo()->getAddressSize();
 }
 
 //===----------------------------------------------------------------------===//
 
 /// EmitValue - Emit label value.
 ///
-void DIEObjectLabel::EmitValue(const Dwarf &DW, unsigned Form) const {
-  DW.EmitReference(Label);
+void DIEObjectLabel::EmitValue(DwarfDebug &DD, unsigned Form) {
+  DD.EmitReference(Label);
 }
 
 /// SizeOf - Determine size of label value in bytes.
 ///
-unsigned DIEObjectLabel::SizeOf(const Dwarf &DW, unsigned Form) const {
-  return DW.getTargetAsmInfo()->getAddressSize();
+unsigned DIEObjectLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
+  return DD.getTargetAsmInfo()->getAddressSize();
 }
     
 //===----------------------------------------------------------------------===//
 
 /// EmitValue - Emit delta value.
 ///
-void DIEDelta::EmitValue(const Dwarf &DW, unsigned Form) const {
+void DIEDelta::EmitValue(DwarfDebug &DD, unsigned Form) {
   bool IsSmall = Form == DW_FORM_data4;
-  DW.EmitDifference(LabelHi, LabelLo, IsSmall);
+  DD.EmitDifference(LabelHi, LabelLo, IsSmall);
 }
 
 /// SizeOf - Determine size of delta value in bytes.
 ///
-unsigned DIEDelta::SizeOf(const Dwarf &DW, unsigned Form) const {
+unsigned DIEDelta::SizeOf(const DwarfDebug &DD, unsigned Form) const {
   if (Form == DW_FORM_data4) return 4;
-  return DW.getTargetAsmInfo()->getAddressSize();
+  return DD.getTargetAsmInfo()->getAddressSize();
 }
 
 //===----------------------------------------------------------------------===//
 
 /// EmitValue - Emit debug information entry offset.
 ///
-void DIEntry::EmitValue(const Dwarf &DW, unsigned Form) const {
-  DW.getAsm()->EmitInt32(Entry->getOffset());
+void DIEntry::EmitValue(DwarfDebug &DD, unsigned Form) {
+  DD.getAsm()->EmitInt32(Entry->getOffset());
 }
     
 //===----------------------------------------------------------------------===//
 
 /// ComputeSize - calculate the size of the block.
 ///
-unsigned DIEBlock::ComputeSize(Dwarf &DW) {
+unsigned DIEBlock::ComputeSize(DwarfDebug &DD) {
   if (!Size) {
     const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
     
     for (unsigned i = 0, N = Values.size(); i < N; ++i) {
-      Size += Values[i]->SizeOf(DW, AbbrevData[i].getForm());
+      Size += Values[i]->SizeOf(DD, AbbrevData[i].getForm());
     }
   }
   return Size;
@@ -2822,31 +3311,31 @@ unsigned DIEBlock::ComputeSize(Dwarf &DW) {
 
 /// EmitValue - Emit block data.
 ///
-void DIEBlock::EmitValue(const Dwarf &DW, unsigned Form) const {
+void DIEBlock::EmitValue(DwarfDebug &DD, unsigned Form) {
   switch (Form) {
-  case DW_FORM_block1: DW.getAsm()->EmitInt8(Size);         break;
-  case DW_FORM_block2: DW.getAsm()->EmitInt16(Size);        break;
-  case DW_FORM_block4: DW.getAsm()->EmitInt32(Size);        break;
-  case DW_FORM_block:  DW.getAsm()->EmitULEB128Bytes(Size); break;
+  case DW_FORM_block1: DD.getAsm()->EmitInt8(Size);         break;
+  case DW_FORM_block2: DD.getAsm()->EmitInt16(Size);        break;
+  case DW_FORM_block4: DD.getAsm()->EmitInt32(Size);        break;
+  case DW_FORM_block:  DD.getAsm()->EmitULEB128Bytes(Size); break;
   default: assert(0 && "Improper form for block");          break;
   }
   
   const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
 
   for (unsigned i = 0, N = Values.size(); i < N; ++i) {
-    DW.getAsm()->EOL("");
-    Values[i]->EmitValue(DW, AbbrevData[i].getForm());
+    DD.getAsm()->EOL();
+    Values[i]->EmitValue(DD, AbbrevData[i].getForm());
   }
 }
 
 /// SizeOf - Determine size of block data in bytes.
 ///
-unsigned DIEBlock::SizeOf(const Dwarf &DW, unsigned Form) const {
+unsigned DIEBlock::SizeOf(const DwarfDebug &DD, unsigned Form) const {
   switch (Form) {
   case DW_FORM_block1: return Size + sizeof(int8_t);
   case DW_FORM_block2: return Size + sizeof(int16_t);
   case DW_FORM_block4: return Size + sizeof(int32_t);
-  case DW_FORM_block: return Size + DW.getAsm()->SizeULEB128(Size);
+  case DW_FORM_block: return Size + DD.getAsm()->SizeULEB128(Size);
   default: assert(0 && "Improper form for block"); break;
   }
   return 0;
@@ -2941,39 +3430,51 @@ void DIE::dump() {
 
 DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A,
                          const TargetAsmInfo *T) {
-  DW = new Dwarf(OS, A, T);
+  DE = new DwarfException(OS, A, T);
+  DD = new DwarfDebug(OS, A, T);
 }
 
 DwarfWriter::~DwarfWriter() {
-  delete DW;
+  delete DE;
+  delete DD;
 }
 
-/// SetDebugInfo - Set DebugInfo when it's known that pass manager has
-/// created it.  Set by the target AsmPrinter.
-void DwarfWriter::SetDebugInfo(MachineDebugInfo *DI) {
-  DW->SetDebugInfo(DI);
+/// SetModuleInfo - Set machine module info when it's known that pass manager
+/// has created it.  Set by the target AsmPrinter.
+void DwarfWriter::SetModuleInfo(MachineModuleInfo *MMI) {
+  DD->SetModuleInfo(MMI);
+  DE->SetModuleInfo(MMI);
 }
 
 /// BeginModule - Emit all Dwarf sections that should come prior to the
 /// content.
 void DwarfWriter::BeginModule(Module *M) {
-  DW->BeginModule(M);
+  DE->BeginModule(M);
+  DD->BeginModule(M);
 }
 
 /// EndModule - Emit all Dwarf sections that should come after the content.
 ///
 void DwarfWriter::EndModule() {
-  DW->EndModule();
+  DE->EndModule();
+  DD->EndModule();
 }
 
 /// BeginFunction - Gather pre-function debug information.  Assumes being 
 /// emitted immediately after the function entry point.
 void DwarfWriter::BeginFunction(MachineFunction *MF) {
-  DW->BeginFunction(MF);
+  DE->BeginFunction(MF);
+  DD->BeginFunction(MF);
 }
 
 /// EndFunction - Gather and emit post-function debug information.
 ///
 void DwarfWriter::EndFunction() {
-  DW->EndFunction();
+  DD->EndFunction();
+  DE->EndFunction();
+  
+  if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI()) {
+    // Clear function debug information.
+    MMI->EndFunction();
+  }
 }