Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/llvm/lib/Support/ELFAttributes.cpp
Line
Count
Source (jump to first uncovered line)
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
12
using namespace llvm;
13
14
StringRef ELFAttrs::attrTypeAsString(unsigned attr, TagNameMap tagNameMap,
15
0
                                     bool hasTagPrefix) {
16
0
  auto tagNameIt = find_if(
17
0
      tagNameMap, [attr](const TagNameItem item) { return item.attr == attr; });
18
0
  if (tagNameIt == tagNameMap.end())
19
0
    return "";
20
0
  StringRef tagName = tagNameIt->tagName;
21
0
  return hasTagPrefix ? tagName : tagName.drop_front(4);
22
0
}
23
24
std::optional<unsigned> ELFAttrs::attrTypeFromString(StringRef tag,
25
0
                                                     TagNameMap tagNameMap) {
26
0
  bool hasTagPrefix = tag.starts_with("Tag_");
27
0
  auto tagNameIt =
28
0
      find_if(tagNameMap, [tag, hasTagPrefix](const TagNameItem item) {
29
0
        return item.tagName.drop_front(hasTagPrefix ? 0 : 4) == tag;
30
0
      });
31
0
  if (tagNameIt == tagNameMap.end())
32
0
    return std::nullopt;
33
0
  return tagNameIt->attr;
34
0
}