ELFAttributes.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. //===-- ELFAttributes.cpp - ELF Attributes --------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/Support/ELFAttributes.h"
  9. #include "llvm/ADT/StringRef.h"
  10. using namespace llvm;
  11. StringRef ELFAttrs::attrTypeAsString(unsigned attr, TagNameMap tagNameMap,
  12. bool hasTagPrefix) {
  13. auto tagNameIt = find_if(
  14. tagNameMap, [attr](const TagNameItem item) { return item.attr == attr; });
  15. if (tagNameIt == tagNameMap.end())
  16. return "";
  17. StringRef tagName = tagNameIt->tagName;
  18. return hasTagPrefix ? tagName : tagName.drop_front(4);
  19. }
  20. Optional<unsigned> ELFAttrs::attrTypeFromString(StringRef tag,
  21. TagNameMap tagNameMap) {
  22. bool hasTagPrefix = tag.startswith("Tag_");
  23. auto tagNameIt =
  24. find_if(tagNameMap, [tag, hasTagPrefix](const TagNameItem item) {
  25. return item.tagName.drop_front(hasTagPrefix ? 0 : 4) == tag;
  26. });
  27. if (tagNameIt == tagNameMap.end())
  28. return None;
  29. return tagNameIt->attr;
  30. }