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
9#include "llvm/Support/ELFAttributes.h"
10#include "llvm/ADT/StringRef.h"
11
12using namespace llvm;
13
14StringRef ELFAttrs::attrTypeAsString(unsigned attr, TagNameMap tagNameMap,
15 bool hasTagPrefix) {
16 auto tagNameIt = find_if(
17 Range&: tagNameMap, P: [attr](const TagNameItem item) { return item.attr == attr; });
18 if (tagNameIt == tagNameMap.end())
19 return "";
20 StringRef tagName = tagNameIt->tagName;
21 return hasTagPrefix ? tagName : tagName.drop_front(N: 4);
22}
23
24std::optional<unsigned> ELFAttrs::attrTypeFromString(StringRef tag,
25 TagNameMap tagNameMap) {
26 bool hasTagPrefix = tag.starts_with(Prefix: "Tag_");
27 auto tagNameIt =
28 find_if(Range&: tagNameMap, P: [tag, hasTagPrefix](const TagNameItem item) {
29 return item.tagName.drop_front(N: hasTagPrefix ? 0 : 4) == tag;
30 });
31 if (tagNameIt == tagNameMap.end())
32 return std::nullopt;
33 return tagNameIt->attr;
34}
35