1 //===-- ELFAttributes.cpp - ELF Attributes --------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/ELFAttributes.h"
10 #include "llvm/ADT/StringRef.h"
14 StringRef
ELFAttrs::attrTypeAsString(unsigned attr
, TagNameMap tagNameMap
,
16 auto tagNameIt
= find_if(
17 tagNameMap
, [attr
](const TagNameItem item
) { return item
.attr
== attr
; });
18 if (tagNameIt
== tagNameMap
.end())
20 StringRef tagName
= tagNameIt
->tagName
;
21 return hasTagPrefix
? tagName
: tagName
.drop_front(4);
24 std::optional
<unsigned> ELFAttrs::attrTypeFromString(StringRef tag
,
25 TagNameMap tagNameMap
) {
26 bool hasTagPrefix
= tag
.starts_with("Tag_");
28 find_if(tagNameMap
, [tag
, hasTagPrefix
](const TagNameItem item
) {
29 return item
.tagName
.drop_front(hasTagPrefix
? 0 : 4) == tag
;
31 if (tagNameIt
== tagNameMap
.end())
33 return tagNameIt
->attr
;