Fix bug where sys::Wait could wait on wrong pid.
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DIE.h
index fa39806f1aa27b833564bedc814c9b422a3ba6ea..e310aef3dcbbbb1839808427e0ae7bb0240d5053 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef CODEGEN_ASMPRINTER_DIE_H__
-#define CODEGEN_ASMPRINTER_DIE_H__
+#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
+#define LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
 
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/MC/MCExpr.h"
-#include "llvm/Support/Compiler.h"
 #include "llvm/Support/Dwarf.h"
 #include <vector>
 
 namespace llvm {
 class AsmPrinter;
+class MCExpr;
 class MCSymbol;
-class MCSymbolRefExpr;
 class raw_ostream;
 class DwarfTypeUnit;
 
@@ -126,7 +124,13 @@ protected:
 
   /// Children DIEs.
   ///
-  std::vector<DIE *> Children;
+  // This can't be a vector<DIE> because pointer validity is requirent for the
+  // Parent pointer and DIEEntry.
+  // It can't be a list<DIE> because some clients need pointer validity before
+  // the object has been added to any child list
+  // (eg: DwarfUnit::constructVariableDIE). These aren't insurmountable, but may
+  // be more convoluted than beneficial.
+  std::vector<std::unique_ptr<DIE>> Children;
 
   DIE *Parent;
 
@@ -134,11 +138,15 @@ protected:
   ///
   SmallVector<DIEValue *, 12> Values;
 
+protected:
+  DIE()
+      : Offset(0), Size(0), Abbrev((dwarf::Tag)0, dwarf::DW_CHILDREN_no),
+        Parent(nullptr) {}
+
 public:
-  explicit DIE(unsigned Tag)
+  explicit DIE(dwarf::Tag Tag)
       : Offset(0), Size(0), Abbrev((dwarf::Tag)Tag, dwarf::DW_CHILDREN_no),
-        Parent(0) {}
-  ~DIE();
+        Parent(nullptr) {}
 
   // Accessors.
   DIEAbbrev &getAbbrev() { return Abbrev; }
@@ -147,7 +155,9 @@ public:
   dwarf::Tag getTag() const { return Abbrev.getTag(); }
   unsigned getOffset() const { return Offset; }
   unsigned getSize() const { return Size; }
-  const std::vector<DIE *> &getChildren() const { return Children; }
+  const std::vector<std::unique_ptr<DIE>> &getChildren() const {
+    return Children;
+  }
   const SmallVectorImpl<DIEValue *> &getValues() const { return Values; }
   DIE *getParent() const { return Parent; }
   /// Climb up the parent chain to get the compile or type unit DIE this DIE
@@ -168,11 +178,11 @@ public:
 
   /// addChild - Add a child to the DIE.
   ///
-  void addChild(DIE *Child) {
+  void addChild(std::unique_ptr<DIE> Child) {
     assert(!Child->getParent());
     Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
-    Children.push_back(Child);
     Child->Parent = this;
+    Children.push_back(std::move(Child));
   }
 
   /// findAttribute - Find a value in the DIE with the attribute given,
@@ -202,7 +212,8 @@ public:
     isEntry,
     isTypeSignature,
     isBlock,
-    isLoc
+    isLoc,
+    isLocList,
   };
 
 protected:
@@ -264,19 +275,19 @@ public:
 
   /// EmitValue - Emit integer of appropriate size.
   ///
-  virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
+  void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
 
   uint64_t getValue() const { return Integer; }
 
   /// SizeOf - Determine size of integer value in bytes.
   ///
-  virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
+  unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
 
   // Implement isa/cast/dyncast.
   static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
 
 #ifndef NDEBUG
-  virtual void print(raw_ostream &O) const;
+  void print(raw_ostream &O) const override;
 #endif
 };
 
@@ -291,7 +302,7 @@ public:
 
   /// EmitValue - Emit expression value.
   ///
-  virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
+  void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
 
   /// getValue - Get MCExpr.
   ///
@@ -299,13 +310,13 @@ public:
 
   /// SizeOf - Determine size of expression value in bytes.
   ///
-  virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
+  unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
 
   // Implement isa/cast/dyncast.
   static bool classof(const DIEValue *E) { return E->getType() == isExpr; }
 
 #ifndef NDEBUG
-  virtual void print(raw_ostream &O) const;
+  void print(raw_ostream &O) const override;
 #endif
 };
 
@@ -320,7 +331,7 @@ public:
 
   /// EmitValue - Emit label value.
   ///
-  virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
+  void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
 
   /// getValue - Get MCSymbol.
   ///
@@ -328,13 +339,13 @@ public:
 
   /// SizeOf - Determine size of label value in bytes.
   ///
-  virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
+  unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
 
   // Implement isa/cast/dyncast.
   static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
 
 #ifndef NDEBUG
-  virtual void print(raw_ostream &O) const;
+  void print(raw_ostream &O) const override;
 #endif
 };
 
@@ -351,17 +362,17 @@ public:
 
   /// EmitValue - Emit delta value.
   ///
-  virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
+  void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
 
   /// SizeOf - Determine size of delta value in bytes.
   ///
-  virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
+  unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
 
   // Implement isa/cast/dyncast.
   static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
 
 #ifndef NDEBUG
-  virtual void print(raw_ostream &O) const;
+  void print(raw_ostream &O) const override;
 #endif
 };
 
@@ -370,10 +381,10 @@ public:
 ///
 class DIEString : public DIEValue {
   const DIEValue *Access;
-  const StringRef Str;
+  StringRef Str;
 
 public:
-  DIEString(const DIEValue *Acc, const StringRef S)
+  DIEString(const DIEValue *Acc, StringRef S)
       : DIEValue(isString), Access(Acc), Str(S) {}
 
   /// getString - Grab the string out of the object.
@@ -381,17 +392,17 @@ public:
 
   /// EmitValue - Emit delta value.
   ///
-  virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
+  void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
 
   /// SizeOf - Determine size of delta value in bytes.
   ///
-  virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
+  unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
 
   // Implement isa/cast/dyncast.
   static bool classof(const DIEValue *D) { return D->getType() == isString; }
 
 #ifndef NDEBUG
-  virtual void print(raw_ostream &O) const;
+  void print(raw_ostream &O) const override;
 #endif
 };
 
@@ -400,22 +411,21 @@ public:
 /// this class can also be used as a proxy for a debug information entry not
 /// yet defined (ie. types.)
 class DIEEntry : public DIEValue {
-  DIE *const Entry;
+  DIE &Entry;
 
 public:
-  explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {
-    assert(E && "Cannot construct a DIEEntry with a null DIE");
+  explicit DIEEntry(DIE &E) : DIEValue(isEntry), Entry(E) {
   }
 
-  DIE *getEntry() const { return Entry; }
+  DIE &getEntry() const { return Entry; }
 
   /// EmitValue - Emit debug information entry offset.
   ///
-  virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
+  void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
 
   /// SizeOf - Determine size of debug information entry in bytes.
   ///
-  virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
+   unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override {
     return Form == dwarf::DW_FORM_ref_addr ? getRefAddrSize(AP)
                                            : sizeof(int32_t);
   }
@@ -427,7 +437,7 @@ public:
   static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
 
 #ifndef NDEBUG
-  virtual void print(raw_ostream &O) const;
+  void print(raw_ostream &O) const override;
 #endif
 };
 
@@ -441,10 +451,10 @@ public:
       : DIEValue(isTypeSignature), Unit(Unit) {}
 
   /// \brief Emit type unit signature.
-  virtual void EmitValue(AsmPrinter *Asm, dwarf::Form Form) const;
+  void EmitValue(AsmPrinter *Asm, dwarf::Form Form) const override;
 
   /// Returns size of a ref_sig8 entry.
-  virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
+  unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override {
     assert(Form == dwarf::DW_FORM_ref_sig8);
     return 8;
   }
@@ -454,7 +464,7 @@ public:
     return E->getType() == isTypeSignature;
   }
 #ifndef NDEBUG
-  virtual void print(raw_ostream &O) const;
+  void print(raw_ostream &O) const override;
   void dump() const;
 #endif
 };
@@ -465,7 +475,7 @@ public:
 class DIELoc : public DIEValue, public DIE {
   mutable unsigned Size; // Size in bytes excluding size header.
 public:
-  DIELoc() : DIEValue(isLoc), DIE(0), Size(0) {}
+  DIELoc() : DIEValue(isLoc), Size(0) {}
 
   /// ComputeSize - Calculate the size of the location expression.
   ///
@@ -488,17 +498,17 @@ public:
 
   /// EmitValue - Emit location data.
   ///
-  virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
+  void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
 
   /// SizeOf - Determine size of location data in bytes.
   ///
-  virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
+  unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
 
   // Implement isa/cast/dyncast.
   static bool classof(const DIEValue *E) { return E->getType() == isLoc; }
 
 #ifndef NDEBUG
-  virtual void print(raw_ostream &O) const;
+  void print(raw_ostream &O) const override;
 #endif
 };
 
@@ -508,7 +518,7 @@ public:
 class DIEBlock : public DIEValue, public DIE {
   mutable unsigned Size; // Size in bytes excluding size header.
 public:
-  DIEBlock() : DIEValue(isBlock), DIE(0), Size(0) {}
+  DIEBlock() : DIEValue(isBlock), Size(0) {}
 
   /// ComputeSize - Calculate the size of the location expression.
   ///
@@ -528,19 +538,50 @@ public:
 
   /// EmitValue - Emit location data.
   ///
-  virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
+  void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
 
   /// SizeOf - Determine size of location data in bytes.
   ///
-  virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
+  unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
 
   // Implement isa/cast/dyncast.
   static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
 
 #ifndef NDEBUG
-  virtual void print(raw_ostream &O) const;
+  void print(raw_ostream &O) const override;
+#endif
+};
+
+//===--------------------------------------------------------------------===//
+/// DIELocList - Represents a pointer to a location list in the debug_loc
+/// section.
+//
+class DIELocList : public DIEValue {
+  // Index into the .debug_loc vector.
+  size_t Index;
+
+public:
+  DIELocList(size_t I) : DIEValue(isLocList), Index(I) {}
+
+  /// getValue - Grab the current index out.
+  size_t getValue() const { return Index; }
+
+  /// EmitValue - Emit location data.
+  ///
+  void EmitValue(AsmPrinter *AP, dwarf::Form Form) const override;
+
+  /// SizeOf - Determine size of location data in bytes.
+  ///
+  unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const override;
+
+  // Implement isa/cast/dyncast.
+  static bool classof(const DIEValue *E) { return E->getType() == isLocList; }
+
+#ifndef NDEBUG
+  void print(raw_ostream &O) const override;
 #endif
 };
+
 } // end llvm namespace
 
 #endif