DebugInfo: Refactor CompileUnit into a Unit baseclass and CompileUnit/TypeUnit derive...
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfCompileUnit.h
index 23d3afc024294cd1d14f8c3abb6bea3184821a3a..080e21384a43f1c1d8bf96bedaca66e20c0edc36 100644 (file)
@@ -1,4 +1,4 @@
-//===-- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit ---*- C++ -*--===//
+//===-- llvm/CodeGen/DwarfUnit.h - Dwarf Compile Unit ---*- C++ -*--===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -32,18 +32,16 @@ class ConstantFP;
 class DbgVariable;
 
 //===----------------------------------------------------------------------===//
-/// CompileUnit - This dwarf writer support class manages information associated
+/// Unit - This dwarf writer support class manages information associated
 /// with a source file.
-class CompileUnit {
+class Unit {
+protected:
   /// UniqueID - a numeric ID unique among all CUs in the module
   unsigned UniqueID;
 
   /// Node - MDNode for the compile unit.
   DICompileUnit Node;
 
-  /// Language - Language for the translation unit associated with this CU.
-  uint16_t Language;
-
   /// CUDie - Compile unit debug information entry.
   const OwningPtr<DIE> CUDie;
 
@@ -100,16 +98,15 @@ class CompileUnit {
   // DIEIntegerOne - A preallocated DIEValue because 1 is used frequently.
   DIEInteger *DIEIntegerOne;
 
+  Unit(unsigned UID, DIE *D, DICompileUnit CU, AsmPrinter *A, DwarfDebug *DW,
+       DwarfUnits *DWU);
+
 public:
-  CompileUnit(unsigned UID, DIE *D, DICompileUnit CU, AsmPrinter *A,
-              DwarfDebug *DW, DwarfUnits *DWU);
-  CompileUnit(unsigned UID, DIE *D, uint16_t Language, AsmPrinter *A,
-              DwarfDebug *DW, DwarfUnits *DWU);
-  ~CompileUnit();
+  virtual ~Unit();
 
   // Accessors.
   unsigned getUniqueID() const { return UniqueID; }
-  uint16_t getLanguage() const { return Language; }
+  virtual uint16_t getLanguage() const = 0;
   DICompileUnit getNode() const { return Node; }
   DIE *getCUDie() const { return CUDie.get(); }
   const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; }
@@ -143,12 +140,6 @@ public:
   ///
   void addGlobalName(StringRef Name, DIE *Die, DIScope Context);
 
-  /// addGlobalType - Add a new global type to the compile unit.
-  void addGlobalType(DIType Ty);
-
-  /// addPubTypes - Add a set of types from the subprogram to the global types.
-  void addPubTypes(DISubprogram SP);
-
   /// addAccelName - Add a new name to the name accelerator table.
   void addAccelName(StringRef Name, const DIE *Die);
 
@@ -212,17 +203,22 @@ public:
 
   void addLabel(DIEBlock *Die, dwarf::Form Form, const MCSymbol *Label);
 
-  /// addLabelAddress - Add a dwarf label attribute data and value using
-  /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
-  void addLabelAddress(DIE *Die, dwarf::Attribute Attribute, MCSymbol *Label);
+  /// addSectionLabel - Add a Dwarf section label attribute data and value.
+  ///
+  void addSectionLabel(DIE *Die, dwarf::Attribute Attribute,
+                       const MCSymbol *Label);
+
+  /// addSectionOffset - Add an offset into a section attribute data and value.
+  ///
+  void addSectionOffset(DIE *Die, dwarf::Attribute Attribute, uint64_t Integer);
 
   /// addOpAddress - Add a dwarf op address data and value using the
   /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
   void addOpAddress(DIEBlock *Die, const MCSymbol *Label);
 
-  /// addDelta - Add a label delta attribute data and value.
-  void addDelta(DIE *Die, dwarf::Attribute Attribute, dwarf::Form Form,
-                const MCSymbol *Hi, const MCSymbol *Lo);
+  /// addSectionDelta - Add a label delta attribute data and value.
+  void addSectionDelta(DIE *Die, dwarf::Attribute Attribute, const MCSymbol *Hi,
+                       const MCSymbol *Lo);
 
   /// addDIEEntry - Add a DIE attribute data and value.
   void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIE *Entry);
@@ -310,9 +306,6 @@ public:
   /// getOrCreateContextDIE - Get context owner's DIE.
   DIE *getOrCreateContextDIE(DIScope Context);
 
-  /// createGlobalVariableDIE - create global variable DIE.
-  void createGlobalVariableDIE(DIGlobalVariable GV);
-
   /// constructContainingTypeDIEs - Construct DIEs for types that contain
   /// vtables.
   void constructContainingTypeDIEs();
@@ -325,10 +318,6 @@ public:
   DIE *createAndAddDIE(unsigned Tag, DIE &Parent,
                        DIDescriptor N = DIDescriptor());
 
-  /// constructTypeDIEImpl - Construct type DIE that is not a type unit
-  /// reference from a DICompositeType.
-  void constructTypeDIEImpl(DIE &Buffer, DICompositeType CTy);
-
   /// Compute the size of a header for this unit, not including the initial
   /// length field.
   unsigned getHeaderSize() const {
@@ -340,6 +329,10 @@ public:
   /// Emit the header for this unit, not including the initial length field.
   void emitHeader(const MCSection *ASection, const MCSymbol *ASectionSym);
 
+protected:
+  /// getOrCreateStaticMemberDIE - Create new static data member DIE.
+  DIE *getOrCreateStaticMemberDIE(DIDerivedType DT);
+
 private:
   /// constructTypeDIE - Construct basic type die from DIBasicType.
   void constructTypeDIE(DIE &Buffer, DIBasicType BTy);
@@ -372,9 +365,6 @@ private:
   void constructTemplateValueParameterDIE(DIE &Buffer,
                                           DITemplateValueParameter TVP);
 
-  /// getOrCreateStaticMemberDIE - Create new static data member DIE.
-  DIE *getOrCreateStaticMemberDIE(DIDerivedType DT);
-
   /// getLowerBoundDefault - Return the default lower bound for an array. If the
   /// DWARF version doesn't handle the language, return -1.
   int64_t getDefaultLowerBound() const;
@@ -409,8 +399,33 @@ private:
 
   /// If this is a named finished type then include it in the list of types for
   /// the accelerator tables.
-  void updateAcceleratorTables(DIType Ty, const DIE *TyDIE);
+  void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE *TyDIE);
 };
 
+class CompileUnit : public Unit {
+public:
+  CompileUnit(unsigned UID, DIE *D, DICompileUnit Node, AsmPrinter *A,
+              DwarfDebug *DW, DwarfUnits *DWU);
+
+  /// createGlobalVariableDIE - create global variable DIE.
+  void createGlobalVariableDIE(DIGlobalVariable GV);
+
+  /// addLabelAddress - Add a dwarf label attribute data and value using
+  /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
+  void addLabelAddress(DIE *Die, dwarf::Attribute Attribute, MCSymbol *Label);
+
+  uint16_t getLanguage() const { return getNode().getLanguage(); }
+};
+
+class TypeUnit : public Unit {
+private:
+  uint16_t Language;
+
+public:
+  TypeUnit(unsigned UID, DIE *D, uint16_t Language, AsmPrinter *A,
+           DwarfDebug *DW, DwarfUnits *DWU);
+
+  uint16_t getLanguage() const { return Language; }
+};
 } // end llvm namespace
 #endif