- const SmallVectorImpl<DIEValue *> &Values = Die->getValues();
- const DIEAbbrev &Abbrevs = Die->getAbbrev();
-
- // 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 (Abbrevs.getData()[i].getAttribute() == Attr) {
- DIEValue *V = Values[i];
- assert(isa<DIEString>(V) && "String requested. Not a string.");
- DIEString *S = cast<DIEString>(V);
- return S->getString();
- }
- }
- return StringRef("");
-}
-
-/// \brief Adds the string in \p Str to the hash in \p Hash. This also hashes
-/// a trailing NULL with the string.
-static void addStringToHash(MD5 &Hash, StringRef Str) {
- DEBUG(dbgs() << "Adding string " << Str << " to hash.\n");
- HashValue SVal((const uint8_t *)Str.data(), Str.size());
- const uint8_t NB = '\0';
- HashValue NBVal((const uint8_t *)&NB, 1);
- Hash.update(SVal);
- Hash.update(NBVal);
-}
-
-// FIXME: These are copied and only slightly modified out of LEB128.h.
-
-/// \brief Adds the unsigned in \p N to the hash in \p Hash. This also encodes
-/// the unsigned as a ULEB128.
-static void addULEB128ToHash(MD5 &Hash, uint64_t Value) {
- DEBUG(dbgs() << "Adding ULEB128 " << Value << " to hash.\n");
- do {
- uint8_t Byte = Value & 0x7f;
- Value >>= 7;
- if (Value != 0)
- Byte |= 0x80; // Mark this byte to show that more bytes will follow.
- Hash.update(Byte);
- } while (Value != 0);
-}
-
-/// \brief Including \p Parent adds the context of Parent to \p Hash.
-static void addParentContextToHash(MD5 &Hash, DIE *Parent) {
- unsigned Tag = Parent->getTag();
-
- DEBUG(dbgs() << "Adding parent context to hash...\n");
-
- // For each surrounding type or namespace...
- if (Tag != dwarf::DW_TAG_namespace && Tag != dwarf::DW_TAG_class_type &&
- Tag != dwarf::DW_TAG_structure_type)
- return;
-
- // ... beginning with the outermost such construct...
- if (Parent->getParent() != NULL)
- addParentContextToHash(Hash, Parent->getParent());
-
- // Append the letter "C" to the sequence.
- addULEB128ToHash(Hash, 'C');
-
- // Followed by the DWARF tag of the construct.
- addULEB128ToHash(Hash, Parent->getTag());
-
- // Then the name, taken from the DW_AT_name attribute.
- StringRef Name = getDIEStringAttr(Parent, dwarf::DW_AT_name);
- if (!Name.empty())
- addStringToHash(Hash, Name);
-}
-
-/// This is based on the type signature computation given in section 7.27 of the
-/// DWARF4 standard. It is the md5 hash of a flattened description of the DIE.
-static void addDIEODRSignature(MD5 &Hash, CompileUnit *CU, DIE *Die) {
-
- // Add the contexts to the hash.
- DIE *Parent = Die->getParent();
- if (Parent)
- addParentContextToHash(Hash, Parent);
-
- // Add the current DIE information.
-
- // Add the DWARF tag of the DIE.
- addULEB128ToHash(Hash, Die->getTag());
-
- // Add the name of the type to the hash.
- addStringToHash(Hash, getDIEStringAttr(Die, dwarf::DW_AT_name));
-
- // Now get the result.
- MD5::MD5Result Result;
- Hash.final(Result);