Basic array support.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26451 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Laskey 2006-03-01 17:53:02 +00:00
parent 0f6ab6ff97
commit f8913f19ae
3 changed files with 311 additions and 16 deletions

View File

@ -67,6 +67,11 @@ enum {
DI_TAG_typedef,
DI_TAG_pointer,
DI_TAG_reference,
DI_TAG_array,
DI_TAG_struct,
DI_TAG_union,
DI_TAG_enum,
DI_TAG_subrange,
DI_TAG_const,
DI_TAG_volatile,
DI_TAG_restrict
@ -88,6 +93,7 @@ public:
/// appropriate action for the type of field.
virtual void Apply(int &Field) = 0;
virtual void Apply(unsigned &Field) = 0;
virtual void Apply(int64_t &Field) = 0;
virtual void Apply(uint64_t &Field) = 0;
virtual void Apply(bool &Field) = 0;
virtual void Apply(std::string &Field) = 0;
@ -130,7 +136,7 @@ public:
// Subclasses should supply the following static methods.
// Implement isa/cast/dyncast.
static bool classof(const DebugInfoDesc *) { return true; }
static bool classof(const DebugInfoDesc *) { return true; }
//===--------------------------------------------------------------------===//
// Subclasses should supply the following virtual methods.
@ -341,7 +347,7 @@ public:
void setEncoding(unsigned E) { Encoding = E; }
// Implement isa/cast/dyncast.
static bool classof(const BasicTypeDesc *) { return true; }
static bool classof(const BasicTypeDesc *) { return true; }
static bool classof(const DebugInfoDesc *D) {
return D->getTag() == DI_TAG_basictype;
}
@ -350,6 +356,14 @@ public:
///
virtual void ApplyToFields(DIVisitor *Visitor);
/// getDescString - Return a string used to compose global names and labels.
///
virtual const char *getDescString() const;
/// getTypeString - Return a string used to label this descriptor's type.
///
virtual const char *getTypeString() const;
#ifndef NDEBUG
virtual void dump();
#endif
@ -371,7 +385,7 @@ public:
void setFromType(TypeDesc *F) { FromType = F; }
// Implement isa/cast/dyncast.
static bool classof(const DerivedTypeDesc *) { return true; }
static bool classof(const DerivedTypeDesc *) { return true; }
static bool classof(const DebugInfoDesc *D) {
unsigned T = D->getTag();
switch (T) {
@ -382,14 +396,108 @@ public:
case DI_TAG_volatile:
case DI_TAG_restrict:
return true;
default: return false;
default: break;
}
return false;
}
/// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
///
virtual void ApplyToFields(DIVisitor *Visitor);
/// getDescString - Return a string used to compose global names and labels.
///
virtual const char *getDescString() const;
/// getTypeString - Return a string used to label this descriptor's type.
///
virtual const char *getTypeString() const;
#ifndef NDEBUG
virtual void dump();
#endif
};
//===----------------------------------------------------------------------===//
/// CompositeTypeDesc - This class packages debug information associated with a
/// array/struct types (eg., arrays, struct, union, enums.)
class CompositeTypeDesc : public DerivedTypeDesc {
private:
std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
public:
CompositeTypeDesc(unsigned T);
// Accessors
std::vector<DebugInfoDesc *> &getElements() { return Elements; }
// Implement isa/cast/dyncast.
static bool classof(const CompositeTypeDesc *) { return true; }
static bool classof(const DebugInfoDesc *D) {
unsigned T = D->getTag();
switch (T) {
case DI_TAG_array:
case DI_TAG_struct:
case DI_TAG_union:
case DI_TAG_enum:
return true;
default: break;
}
return false;
}
/// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
///
virtual void ApplyToFields(DIVisitor *Visitor);
/// getDescString - Return a string used to compose global names and labels.
///
virtual const char *getDescString() const;
/// getTypeString - Return a string used to label this descriptor's type.
///
virtual const char *getTypeString() const;
#ifndef NDEBUG
virtual void dump();
#endif
};
//===----------------------------------------------------------------------===//
/// SubrangeDesc - This class packages debug information associated with integer
/// value ranges.
class SubrangeDesc : public DebugInfoDesc {
private:
int64_t Lo; // Low value of range
int64_t Hi; // High value of range
public:
SubrangeDesc();
// Accessors
int64_t getLo() const { return Lo; }
int64_t getHi() const { return Hi; }
void setLo(int64_t L) { Lo = L; }
void setHi(int64_t H) { Hi = H; }
// Implement isa/cast/dyncast.
static bool classof(const SubrangeDesc *) { return true; }
static bool classof(const DebugInfoDesc *D) {
return D->getTag() == DI_TAG_subrange;
}
/// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
///
virtual void ApplyToFields(DIVisitor *Visitor);
/// getDescString - Return a string used to compose global names and labels.
///
virtual const char *getDescString() const;
/// getTypeString - Return a string used to label this descriptor's type.
///
virtual const char *getTypeString() const;
#ifndef NDEBUG
virtual void dump();
#endif
@ -445,7 +553,7 @@ public:
void setLine(unsigned L) { Line = L; }
// Implement isa/cast/dyncast.
static bool classof(const GlobalVariableDesc *) { return true; }
static bool classof(const GlobalVariableDesc *) { return true; }
static bool classof(const DebugInfoDesc *D) {
return D->getTag() == DI_TAG_global_variable;
}
@ -485,7 +593,7 @@ public:
// FIXME - Other getters/setters.
// Implement isa/cast/dyncast.
static bool classof(const SubprogramDesc *) { return true; }
static bool classof(const SubprogramDesc *) { return true; }
static bool classof(const DebugInfoDesc *D) {
return D->getTag() == DI_TAG_subprogram;
}

View File

@ -1072,12 +1072,12 @@ DIE *DwarfWriter::NewType(CompileUnit *Unit, TypeDesc *TyDesc) {
// Determine which derived type.
unsigned T = 0;
switch (DerivedTy->getTag()) {
case DI_TAG_typedef: T = DW_TAG_typedef; break;
case DI_TAG_pointer: T = DW_TAG_pointer_type; break;
case DI_TAG_reference: T = DW_TAG_reference_type; break;
case DI_TAG_const: T = DW_TAG_const_type; break;
case DI_TAG_volatile: T = DW_TAG_volatile_type; break;
case DI_TAG_restrict: T = DW_TAG_restrict_type; break;
case DI_TAG_typedef: T = DW_TAG_typedef; break;
case DI_TAG_pointer: T = DW_TAG_pointer_type; break;
case DI_TAG_reference: T = DW_TAG_reference_type; break;
case DI_TAG_const: T = DW_TAG_const_type; break;
case DI_TAG_volatile: T = DW_TAG_volatile_type; break;
case DI_TAG_restrict: T = DW_TAG_restrict_type; break;
default: assert( 0 && "Unknown tag on derived type");
}
@ -1088,6 +1088,67 @@ DIE *DwarfWriter::NewType(CompileUnit *Unit, TypeDesc *TyDesc) {
if (TypeDesc *FromTy = DerivedTy->getFromType()) {
Ty->AddDIEntry(DW_AT_type, DW_FORM_ref4, NewType(Unit, FromTy));
}
} else if (CompositeTypeDesc *CompTy = dyn_cast<CompositeTypeDesc>(TyDesc)) {
// Determine which composite type.
unsigned T = 0;
switch (CompTy->getTag()) {
case DI_TAG_array: T = DW_TAG_array_type; break;
case DI_TAG_struct: T = DW_TAG_structure_type; break;
case DI_TAG_union: T = DW_TAG_union_type; break;
case DI_TAG_enum: T = DW_TAG_enumeration_type; break;
default: assert( 0 && "Unknown tag on composite type");
}
// Create specific DIE.
Slot = Ty = new DIE(T);
std::vector<DebugInfoDesc *> &Elements = CompTy->getElements();
switch (CompTy->getTag()) {
case DI_TAG_array: {
// Add element type.
if (TypeDesc *FromTy = CompTy->getFromType()) {
Ty->AddDIEntry(DW_AT_type, DW_FORM_ref4, NewType(Unit, FromTy));
}
// Don't emit size attribute.
Size = 0;
// Construct an anonymous type for index type.
DIE *IndexTy = new DIE(DW_TAG_base_type);
IndexTy->AddUInt(DW_AT_byte_size, 0, 4);
IndexTy->AddUInt(DW_AT_encoding, DW_FORM_data1, DW_ATE_signed);
// Add to context.
Unit->getDie()->AddChild(IndexTy);
// Add subranges to array type.
for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
SubrangeDesc *SRD = cast<SubrangeDesc>(Elements[i]);
int64_t Lo = SRD->getLo();
int64_t Hi = SRD->getHi();
DIE *Subrange = new DIE(DW_TAG_subrange_type);
// If a range is available.
if (Lo != Hi) {
Subrange->AddDIEntry(DW_AT_type, DW_FORM_ref4, IndexTy);
// Only add low if non-zero.
if (Lo) Subrange->AddUInt(DW_AT_lower_bound, 0, Lo);
Subrange->AddUInt(DW_AT_upper_bound, 0, Hi);
}
Ty->AddChild(Subrange);
}
break;
}
case DI_TAG_struct: {
break;
}
case DI_TAG_union: {
break;
}
case DI_TAG_enum: {
break;
}
default: break;
}
}
assert(Ty && "Type not supported yet");

View File

@ -197,6 +197,7 @@ public:
///
virtual void Apply(int &Field) { ++Count; }
virtual void Apply(unsigned &Field) { ++Count; }
virtual void Apply(int64_t &Field) { ++Count; }
virtual void Apply(uint64_t &Field) { ++Count; }
virtual void Apply(bool &Field) { ++Count; }
virtual void Apply(std::string &Field) { ++Count; }
@ -234,6 +235,10 @@ public:
Constant *C = CI->getOperand(I++);
Field = cast<ConstantUInt>(C)->getValue();
}
virtual void Apply(int64_t &Field) {
Constant *C = CI->getOperand(I++);
Field = cast<ConstantSInt>(C)->getValue();
}
virtual void Apply(uint64_t &Field) {
Constant *C = CI->getOperand(I++);
Field = cast<ConstantUInt>(C)->getValue();
@ -290,6 +295,9 @@ public:
virtual void Apply(unsigned &Field) {
Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
}
virtual void Apply(int64_t &Field) {
Elements.push_back(ConstantSInt::get(Type::IntTy, Field));
}
virtual void Apply(uint64_t &Field) {
Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
}
@ -337,7 +345,11 @@ public:
}
Constant *CA = ConstantArray::get(AT, ArrayElements);
Constant *CAE = ConstantExpr::getCast(CA, EmptyTy);
GlobalVariable *CAGV = new GlobalVariable(AT, true,
GlobalValue::InternalLinkage,
CA, "llvm.dbg.array",
SR.getModule());
Constant *CAE = ConstantExpr::getCast(CAGV, EmptyTy);
Elements.push_back(CAE);
}
};
@ -365,6 +377,9 @@ public:
virtual void Apply(unsigned &Field) {
Fields.push_back(Type::UIntTy);
}
virtual void Apply(int64_t &Field) {
Fields.push_back(Type::IntTy);
}
virtual void Apply(uint64_t &Field) {
Fields.push_back(Type::UIntTy);
}
@ -422,6 +437,10 @@ public:
Constant *C = CI->getOperand(I++);
IsValid = IsValid && isa<ConstantInt>(C);
}
virtual void Apply(int64_t &Field) {
Constant *C = CI->getOperand(I++);
IsValid = IsValid && isa<ConstantInt>(C);
}
virtual void Apply(uint64_t &Field) {
Constant *C = CI->getOperand(I++);
IsValid = IsValid && isa<ConstantInt>(C);
@ -491,6 +510,11 @@ DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) {
case DI_TAG_const:
case DI_TAG_volatile:
case DI_TAG_restrict: return new DerivedTypeDesc(Tag);
case DI_TAG_array:
case DI_TAG_struct:
case DI_TAG_union:
case DI_TAG_enum: return new CompositeTypeDesc(Tag);
case DI_TAG_subrange: return new SubrangeDesc();
default: break;
}
return NULL;
@ -681,6 +705,18 @@ void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) {
Visitor->Apply(Encoding);
}
/// getDescString - Return a string used to compose global names and labels.
///
const char *BasicTypeDesc::getDescString() const {
return "llvm.dbg.basictype";
}
/// getTypeString - Return a string used to label this descriptor's type.
///
const char *BasicTypeDesc::getTypeString() const {
return "llvm.dbg.basictype.type";
}
#ifndef NDEBUG
void BasicTypeDesc::dump() {
std::cerr << getDescString() << " "
@ -691,14 +727,13 @@ void BasicTypeDesc::dump() {
<< "Encoding(" << Encoding << ")\n";
}
#endif
//===----------------------------------------------------------------------===//
DerivedTypeDesc::DerivedTypeDesc(unsigned T)
: TypeDesc(T)
, FromType(NULL)
{
assert(classof((const DebugInfoDesc *)this) && "Unknown derived type.");
}
{}
/// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
///
@ -708,6 +743,18 @@ void DerivedTypeDesc::ApplyToFields(DIVisitor *Visitor) {
Visitor->Apply((DebugInfoDesc *&)FromType);
}
/// getDescString - Return a string used to compose global names and labels.
///
const char *DerivedTypeDesc::getDescString() const {
return "llvm.dbg.derivedtype";
}
/// getTypeString - Return a string used to label this descriptor's type.
///
const char *DerivedTypeDesc::getTypeString() const {
return "llvm.dbg.derivedtype.type";
}
#ifndef NDEBUG
void DerivedTypeDesc::dump() {
std::cerr << getDescString() << " "
@ -723,6 +770,85 @@ void DerivedTypeDesc::dump() {
//===----------------------------------------------------------------------===//
CompositeTypeDesc::CompositeTypeDesc(unsigned T)
: DerivedTypeDesc(T)
, Elements()
{}
/// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
///
void CompositeTypeDesc::ApplyToFields(DIVisitor *Visitor) {
DerivedTypeDesc::ApplyToFields(Visitor);
Visitor->Apply(Elements);
}
/// getDescString - Return a string used to compose global names and labels.
///
const char *CompositeTypeDesc::getDescString() const {
return "llvm.dbg.compositetype";
}
/// getTypeString - Return a string used to label this descriptor's type.
///
const char *CompositeTypeDesc::getTypeString() const {
return "llvm.dbg.compositetype.type";
}
#ifndef NDEBUG
void CompositeTypeDesc::dump() {
std::cerr << getDescString() << " "
<< "Tag(" << getTag() << "), "
<< "Context(" << getContext() << "), "
<< "Name(\"" << getName() << "\"), "
<< "Size(" << getSize() << "), "
<< "File(" << getFile() << "), "
<< "Line(" << getLine() << "), "
<< "FromType(" << getFromType() << "), "
<< "Elements.size(" << Elements.size() << ")\n";
}
#endif
//===----------------------------------------------------------------------===//
SubrangeDesc::SubrangeDesc()
: DebugInfoDesc(DI_TAG_subrange)
, Lo(0)
, Hi(0)
{}
/// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
///
void SubrangeDesc::ApplyToFields(DIVisitor *Visitor) {
DebugInfoDesc::ApplyToFields(Visitor);
Visitor->Apply(Lo);
Visitor->Apply(Hi);
}
/// getDescString - Return a string used to compose global names and labels.
///
const char *SubrangeDesc::getDescString() const {
return "llvm.dbg.subrange";
}
/// getTypeString - Return a string used to label this descriptor's type.
///
const char *SubrangeDesc::getTypeString() const {
return "llvm.dbg.subrange.type";
}
#ifndef NDEBUG
void SubrangeDesc::dump() {
std::cerr << getDescString() << " "
<< "Tag(" << getTag() << "), "
<< "Lo(" << Lo << "), "
<< "Hi(" << Hi << ")\n";
}
#endif
//===----------------------------------------------------------------------===//
GlobalDesc::GlobalDesc(unsigned T)
: AnchoredDesc(T)
, Context(0)