const std::vector<std::unique_ptr<DIE>> &getChildren() const {
return Children;
}
- const SmallVectorImpl<DIEValue> &getValues() const { return Values; }
+
+ typedef SmallVectorImpl<DIEValue>::const_iterator value_iterator;
+ typedef iterator_range<value_iterator> value_range;
+
+ value_iterator begin_values() const { return Values.begin(); }
+ value_iterator end_values() const { return Values.end(); }
+ value_range values() const {
+ return llvm::make_range(begin_values(), end_values());
+ }
+
void setValue(unsigned I, DIEValue New) {
assert(I < Values.size());
Values[I] = New;
dwarf::TagString(Die.getTag()));
EmitULEB128(Die.getAbbrevNumber());
- const SmallVectorImpl<DIEValue> &Values = Die.getValues();
-
// Emit the DIE attribute values.
- for (unsigned i = 0, N = Values.size(); i < N; ++i) {
- dwarf::Attribute Attr = Values[i].getAttribute();
- dwarf::Form Form = Values[i].getForm();
+ for (const auto &V : Die.values()) {
+ dwarf::Attribute Attr = V.getAttribute();
+ dwarf::Form Form = V.getForm();
assert(Form && "Too many attributes for DIE (check abbreviation)");
if (isVerbose()) {
OutStreamer->AddComment(dwarf::AttributeString(Attr));
if (Attr == dwarf::DW_AT_accessibility)
OutStreamer->AddComment(
- dwarf::AccessibilityString(Values[i].getDIEInteger().getValue()));
+ dwarf::AccessibilityString(V.getDIEInteger().getValue()));
}
// Emit an attribute using the defined form.
- Values[i].EmitValue(this, Form);
+ V.EmitValue(this, Form);
}
// Emit the DIE children if any.
}
DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
- const SmallVectorImpl<DIEValue> &Values = getValues();
-
// Iterate through all the attributes until we find the one we're
// looking for, if we can't find it return NULL.
- for (size_t i = 0; i < Values.size(); ++i)
- if (Values[i].getAttribute() == Attribute)
- return Values[i];
+ for (const auto &V : values())
+ if (V.getAttribute() == Attribute)
+ return V;
return DIEValue();
}
/// \brief Grabs the string in whichever attribute is passed in and returns
/// a reference to it.
static StringRef getDIEStringAttr(const DIE &Die, uint16_t Attr) {
- const auto &Values = Die.getValues();
-
// Iterate through all the attributes until we find the one we're
// looking for, if we can't find it return an empty string.
- for (size_t i = 0; i < Values.size(); ++i) {
- if (Values[i].getAttribute() == Attr)
- return Values[i].getDIEString().getString();
- }
+ for (const auto &V : Die.values())
+ if (V.getAttribute() == Attr)
+ return V.getDIEString().getString();
+
return StringRef("");
}
// Collect all of the attributes for a particular DIE in single structure.
void DIEHash::collectAttributes(const DIE &Die, DIEAttrs &Attrs) {
- const SmallVectorImpl<DIEValue> &Values = Die.getValues();
-
#define COLLECT_ATTR(NAME) \
case dwarf::NAME: \
- Attrs.NAME = Values[i]; \
+ Attrs.NAME = V; \
break
- for (size_t i = 0, e = Values.size(); i != e; ++i) {
+ for (const auto &V : Die.values()) {
DEBUG(dbgs() << "Attribute: "
- << dwarf::AttributeString(Values[i].getAttribute())
+ << dwarf::AttributeString(V.getAttribute())
<< " added.\n");
- switch (Values[i].getAttribute()) {
+ switch (V.getAttribute()) {
COLLECT_ATTR(DW_AT_name);
COLLECT_ATTR(DW_AT_accessibility);
COLLECT_ATTR(DW_AT_address_class);
// Hash all of the values in a block like set of values. This assumes that
// all of the data is going to be added as integers.
-void DIEHash::hashBlockData(const SmallVectorImpl<DIEValue> &Values) {
- for (auto I = Values.begin(), E = Values.end(); I != E; ++I)
- Hash.update((uint64_t)I->getDIEInteger().getValue());
+void DIEHash::hashBlockData(const DIE::value_range &Values) {
+ for (const auto &V : Values)
+ Hash.update((uint64_t)V.getDIEInteger().getValue());
}
// Hash the contents of a loclistptr class.
addULEB128(dwarf::DW_FORM_block);
if (Value.getType() == DIEValue::isBlock) {
addULEB128(Value.getDIEBlock().ComputeSize(AP));
- hashBlockData(Value.getDIEBlock().getValues());
+ hashBlockData(Value.getDIEBlock().values());
} else if (Value.getType() == DIEValue::isLoc) {
addULEB128(Value.getDIELoc().ComputeSize(AP));
- hashBlockData(Value.getDIELoc().getValues());
+ hashBlockData(Value.getDIELoc().values());
} else {
// We could add the block length, but that would take
// a bit of work and not add a lot of uniqueness
/// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
/// DW_FORM_exprloc.
- void hashBlockData(const SmallVectorImpl<DIEValue> &Values);
+ void hashBlockData(const DIE::value_range &Values);
/// \brief Hashes the contents pointed to in the .debug_loc section.
void hashLocList(const DIELocList &LocList);
MCSymbol *LineTableStartSym =
Asm->OutStreamer->getDwarfLineTableSymbol(getUniqueID());
- stmtListIndex = UnitDie.getValues().size();
+ stmtListIndex = std::distance(UnitDie.begin_values(), UnitDie.end_values());
// DW_AT_stmt_list is a offset of line number information for this
// compile unit in debug_line section. For split dwarf this is
}
void DwarfCompileUnit::applyStmtList(DIE &D) {
- D.addValue(UnitDie.getValues()[stmtListIndex]);
+ D.addValue(UnitDie.begin_values()[stmtListIndex]);
}
void DwarfCompileUnit::attachLowHighPC(DIE &D, const MCSymbol *Begin,
// Start the size with the size of abbreviation code.
Offset += getULEB128Size(Die.getAbbrevNumber());
- const SmallVectorImpl<DIEValue> &Values = Die.getValues();
- const SmallVectorImpl<DIEAbbrevData> &AbbrevData = Abbrev.getData();
-
// Size the DIE attribute values.
- for (unsigned i = 0, N = Values.size(); i < N; ++i)
+ for (const auto &V : Die.values())
// Size attribute value.
- Offset += Values[i].SizeOf(Asm, AbbrevData[i].getForm());
+ Offset += V.SizeOf(Asm, V.getForm());
// Get the children.
const auto &Children = Die.getChildren();
PatchLocation() : Die(nullptr), Index(0) {}
PatchLocation(DIE &Die, unsigned Index) : Die(&Die), Index(Index) {}
+ PatchLocation(DIE &Die)
+ : Die(&Die), Index(std::distance(Die.begin_values(), Die.end_values())) {}
void set(uint64_t New) const {
assert(Die);
- assert(Index < Die->getValues().size());
- const auto &Old = Die->getValues()[Index];
+ assert(Index < std::distance(Die->begin_values(), Die->end_values()));
+ const auto &Old = Die->begin_values()[Index];
assert(Old.getType() == DIEValue::isInteger);
Die->setValue(Index,
DIEValue(Old.getAttribute(), Old.getForm(), DIEInteger(New)));
uint64_t get() const {
assert(Die);
- assert(Index < Die->getValues().size());
- assert(Die->getValues()[Index].getType() == DIEValue::isInteger);
- return Die->getValues()[Index].getDIEInteger().getValue();
+ assert(Index < std::distance(Die->begin_values(), Die->end_values()));
+ assert(Die->begin_values()[Index].getType() == DIEValue::isInteger);
+ return Die->begin_values()[Index].getDIEInteger().getValue();
}
};
} else {
// A forward reference. Note and fixup later.
Attr = 0xBADDEF;
- Unit.noteForwardReference(NewRefDie, RefUnit,
- PatchLocation(Die, Die.getValues().size()));
+ Unit.noteForwardReference(NewRefDie, RefUnit, PatchLocation(Die));
}
Die.addValue(dwarf::Attribute(AttrSpec.Attr), dwarf::DW_FORM_ref_addr,
DIEInteger(Attr));
}
DIEInteger Attr(Value);
if (AttrSpec.Attr == dwarf::DW_AT_ranges)
- Unit.noteRangeAttribute(Die, PatchLocation(Die, Die.getValues().size()));
+ Unit.noteRangeAttribute(Die, PatchLocation(Die));
// A more generic way to check for location attributes would be
// nice, but it's very unlikely that any other attribute needs a
// location list.
else if (AttrSpec.Attr == dwarf::DW_AT_location ||
AttrSpec.Attr == dwarf::DW_AT_frame_base)
- Unit.noteLocationAttribute(PatchLocation(Die, Die.getValues().size()),
- Info.PCOffset);
+ Unit.noteLocationAttribute(PatchLocation(Die), Info.PCOffset);
else if (AttrSpec.Attr == dwarf::DW_AT_declaration && Value)
Info.IsDeclaration = true;
// Update the cloned DW_AT_stmt_list with the correct debug_line offset.
if (auto *OutputDIE = Unit.getOutputUnitDIE()) {
- const auto &Values = OutputDIE->getValues();
- auto Stmt =
- std::find_if(Values.begin(), Values.end(), [](const DIEValue &Value) {
- return Value.getAttribute() == dwarf::DW_AT_stmt_list;
- });
- assert(Stmt < Values.end() && "Didn't find DW_AT_stmt_list in cloned DIE!");
- OutputDIE->setValue(Stmt - Values.begin(),
+ auto Stmt = std::find_if(OutputDIE->begin_values(), OutputDIE->end_values(),
+ [](const DIEValue &Value) {
+ return Value.getAttribute() == dwarf::DW_AT_stmt_list;
+ });
+ assert(Stmt != OutputDIE->end_values() &&
+ "Didn't find DW_AT_stmt_list in cloned DIE!");
+ OutputDIE->setValue(Stmt - OutputDIE->begin_values(),
DIEValue(Stmt->getAttribute(), Stmt->getForm(),
DIEInteger(Streamer->getLineSectionSize())));
}