summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-01-05 18:33:01 +0000
committerDevang Patel <dpatel@apple.com>2009-01-05 18:33:01 +0000
commit68afdc3ab08975569e59cc8c04c2db9e9478a996 (patch)
treeb500063e9f0bffafb694eb4125aec08c43d7c52a
parentd0ed240e3091607048490f174988976a44b11d30 (diff)
downloadexternal_llvm-68afdc3ab08975569e59cc8c04c2db9e9478a996.zip
external_llvm-68afdc3ab08975569e59cc8c04c2db9e9478a996.tar.gz
external_llvm-68afdc3ab08975569e59cc8c04c2db9e9478a996.tar.bz2
Construct array/vector type DIEs using DebugInfo.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61724 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Analysis/DebugInfo.h22
-rw-r--r--lib/Analysis/DebugInfo.cpp7
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfWriter.cpp40
3 files changed, 58 insertions, 11 deletions
diff --git a/include/llvm/Analysis/DebugInfo.h b/include/llvm/Analysis/DebugInfo.h
index e9a7cb1..fac86b3 100644
--- a/include/llvm/Analysis/DebugInfo.h
+++ b/include/llvm/Analysis/DebugInfo.h
@@ -86,6 +86,15 @@ namespace llvm {
unsigned getAnchorTag() const { return getUnsignedField(1); }
};
+
+ /// DISubrange - This is used to represent ranges, for array bounds.
+ class DISubrange : public DIDescriptor {
+ public:
+ explicit DISubrange(GlobalVariable *GV = 0);
+
+ int64_t getLo() const { return (int64_t)getUInt64Field(1); }
+ int64_t getHi() const { return (int64_t)getUInt64Field(2); }
+ };
/// DIArray - This descriptor holds an array of descriptors.
class DIArray : public DIDescriptor {
@@ -93,7 +102,9 @@ namespace llvm {
explicit DIArray(GlobalVariable *GV = 0) : DIDescriptor(GV) {}
unsigned getNumElements() const;
- DIDescriptor getElement(unsigned Idx) const;
+ DISubrange getElement(unsigned Idx) const {
+ return getFieldAs<DISubrange>(Idx);
+ }
};
/// DICompileUnit - A wrapper for a compile unit.
@@ -118,15 +129,6 @@ namespace llvm {
uint64_t getLanguage() const { return getUInt64Field(2); }
};
- /// DISubrange - This is used to represent ranges, for array bounds.
- class DISubrange : public DIDescriptor {
- public:
- explicit DISubrange(GlobalVariable *GV = 0);
-
- int64_t getLo() const { return (int64_t)getUInt64Field(1); }
- int64_t getHi() const { return (int64_t)getUInt64Field(2); }
- };
-
/// DIType - This is a wrapper for a type.
/// FIXME: Types should be factored much better so that CV qualifiers and
/// others do not require a huge and empty descriptor full of zeros.
diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp
index f1f7d8e..8b802d7 100644
--- a/lib/Analysis/DebugInfo.cpp
+++ b/lib/Analysis/DebugInfo.cpp
@@ -174,7 +174,12 @@ DIVariable::DIVariable(GlobalVariable *GV) : DIDescriptor(GV) {
GV = 0;
}
-
+unsigned DIArray::getNumElements() const {
+ assert (GV && "Invalid DIArray");
+ Constant *C = GV->getInitializer();
+ assert (C && "Invalid DIArray initializer");
+ return C->getNumOperands();
+}
//===----------------------------------------------------------------------===//
// DIFactory: Basic Helpers
diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
index 30f14b7..af41982 100644
--- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
@@ -1512,6 +1512,7 @@ private:
AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
}
+ /// ConstructType - Construct derived type die from DIDerivedType.
void ConstructType(CompileUnit *DW_Unit, DIE &Buffer,
DIDerivedType *DTy) {
@@ -1540,6 +1541,45 @@ private:
// FIXME - Enable this. AddSourceLine(&Buffer, *DTy);
}
+ // ConstructSubrangeDIE - Construct subrange DIE from DISubrange.
+ void ConstructSubrangeDIE (DIE &Buffer, DISubrange *SR, DIE *IndexTy) {
+ int64_t L = SR->getLo();
+ int64_t H = SR->getHi();
+ DIE *DW_Subrange = new DIE(DW_TAG_subrange_type);
+ if (L != H) {
+ AddDIEntry(DW_Subrange, DW_AT_type, DW_FORM_ref4, IndexTy);
+ if (L)
+ AddSInt(DW_Subrange, DW_AT_lower_bound, 0, L);
+ AddSInt(DW_Subrange, DW_AT_upper_bound, 0, H);
+ }
+ Buffer.AddChild(DW_Subrange);
+ }
+
+ /// ConstructArrayTypeDIE - Construct array type DIE from DICompositeType.
+ void ConstructArrayTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
+ DICompositeType *CTy) {
+ Buffer.setTag(DW_TAG_array_type);
+ if (CTy->getTag() == DW_TAG_vector_type)
+ AddUInt(&Buffer, DW_AT_GNU_vector, DW_FORM_flag, 1);
+
+ DIArray Elements = CTy->getTypeArray();
+ // FIXME - Enable this.
+ // AddType(&Buffer, CTy->getTypeDerivedFrom(), DW_Unit);
+
+ // Construct an anonymous type for index type.
+ DIE IdxBuffer(DW_TAG_base_type);
+ AddUInt(&IdxBuffer, DW_AT_byte_size, 0, sizeof(int32_t));
+ AddUInt(&IdxBuffer, DW_AT_encoding, DW_FORM_data1, DW_ATE_signed);
+ DIE *IndexTy = DW_Unit->AddDie(IdxBuffer);
+
+ // Add subranges to array type.
+ for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
+ DISubrange Element = Elements.getElement(i);
+ ConstructSubrangeDIE(Buffer, &Element, IndexTy);
+ }
+ }
+
+
/// ConstructType - Adds all the required attributes to the type.
///
void ConstructType(DIE &Buffer, TypeDesc *TyDesc, CompileUnit *Unit) {