LLVM  14.0.0git
ELFAttributes.cpp
Go to the documentation of this file.
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 
10 #include "llvm/ADT/StringRef.h"
11 
12 using namespace llvm;
13 
15  bool hasTagPrefix) {
16  auto tagNameIt = find_if(
17  tagNameMap, [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(4);
22 }
23 
25  TagNameMap tagNameMap) {
26  bool hasTagPrefix = tag.startswith("Tag_");
27  auto tagNameIt =
28  find_if(tagNameMap, [tag, hasTagPrefix](const TagNameItem item) {
29  return item.tagName.drop_front(hasTagPrefix ? 0 : 4) == tag;
30  });
31  if (tagNameIt == tagNameMap.end())
32  return None;
33  return tagNameIt->attr;
34 }
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:286
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
StringRef.h
llvm::ELFAttrs::attrTypeFromString
Optional< unsigned > attrTypeFromString(StringRef tag, TagNameMap tagNameMap)
Definition: ELFAttributes.cpp:24
llvm::Optional< unsigned >
llvm::TagNameItem
Definition: ELFAttributes.h:17
llvm::TagNameItem::tagName
StringRef tagName
Definition: ELFAttributes.h:19
llvm::None
const NoneType None
Definition: None.h:23
ELFAttributes.h
llvm::ArrayRef< TagNameItem >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::find_if
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1574
llvm::StringRef::drop_front
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:653
llvm::TagNameItem::attr
unsigned attr
Definition: ELFAttributes.h:18
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:154
llvm::ELFAttrs::attrTypeAsString
StringRef attrTypeAsString(unsigned attr, TagNameMap tagNameMap, bool hasTagPrefix=true)
Definition: ELFAttributes.cpp:14