From 728d6066899e9f1bc9d61365e64c14582ce1746d Mon Sep 17 00:00:00 2001 From: Nick Kledzik Date: Fri, 27 Jun 2014 00:30:31 +0000 Subject: [PATCH] Add utility to SimpleDefinedAtom to sort references llvm-svn: 211825 --- lld/include/lld/Core/Simple.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lld/include/lld/Core/Simple.h b/lld/include/lld/Core/Simple.h index 6e6a991..ad041b6 100644 --- a/lld/include/lld/Core/Simple.h +++ b/lld/include/lld/Core/Simple.h @@ -171,12 +171,27 @@ public: _references.push_back(SimpleReference(ns, arch, kindValue, off, target, a)); } + /// Sort references in a canonical order (by offset, then by kind). + void sortReferences() const { + std::sort(_references.begin(), _references.end(), + [] (SimpleReference &lhs, SimpleReference &rhs) -> bool { + uint64_t lhsOffset = lhs.offsetInAtom(); + uint64_t rhsOffset = rhs.offsetInAtom(); + if (rhsOffset != lhsOffset) + return (lhsOffset < rhsOffset); + if (rhs.kindNamespace() != lhs.kindNamespace()) + return (lhs.kindNamespace() < rhs.kindNamespace()); + if (rhs.kindArch() != lhs.kindArch()) + return (lhs.kindArch() < rhs.kindArch()); + return (lhs.kindValue() < rhs.kindValue()); + }); + } void setOrdinal(uint64_t ord) { _ordinal = ord; } private: const File &_file; uint64_t _ordinal; - std::vector _references; + mutable std::vector _references; }; class SimpleUndefinedAtom : public UndefinedAtom { -- 2.7.4