Path: blob/main/contrib/llvm-project/llvm/lib/Support/ELFAttributes.cpp
35233 views
//===-- ELFAttributes.cpp - ELF Attributes --------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/Support/ELFAttributes.h"9#include "llvm/ADT/StringRef.h"1011using namespace llvm;1213StringRef ELFAttrs::attrTypeAsString(unsigned attr, TagNameMap tagNameMap,14bool hasTagPrefix) {15auto tagNameIt = find_if(16tagNameMap, [attr](const TagNameItem item) { return item.attr == attr; });17if (tagNameIt == tagNameMap.end())18return "";19StringRef tagName = tagNameIt->tagName;20return hasTagPrefix ? tagName : tagName.drop_front(4);21}2223std::optional<unsigned> ELFAttrs::attrTypeFromString(StringRef tag,24TagNameMap tagNameMap) {25bool hasTagPrefix = tag.starts_with("Tag_");26auto tagNameIt =27find_if(tagNameMap, [tag, hasTagPrefix](const TagNameItem item) {28return item.tagName.drop_front(hasTagPrefix ? 0 : 4) == tag;29});30if (tagNameIt == tagNameMap.end())31return std::nullopt;32return tagNameIt->attr;33}343536