15ffd83dbSDimitry Andric //===-- ELFAttributes.cpp - ELF Attributes --------------------------------===// 25ffd83dbSDimitry Andric // 35ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 45ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 55ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65ffd83dbSDimitry Andric // 75ffd83dbSDimitry Andric //===----------------------------------------------------------------------===// 85ffd83dbSDimitry Andric 95ffd83dbSDimitry Andric #include "llvm/Support/ELFAttributes.h" 105ffd83dbSDimitry Andric #include "llvm/ADT/StringRef.h" 115ffd83dbSDimitry Andric 125ffd83dbSDimitry Andric using namespace llvm; 135ffd83dbSDimitry Andric 145ffd83dbSDimitry Andric StringRef ELFAttrs::attrTypeAsString(unsigned attr, TagNameMap tagNameMap, 155ffd83dbSDimitry Andric bool hasTagPrefix) { 165ffd83dbSDimitry Andric auto tagNameIt = find_if( 175ffd83dbSDimitry Andric tagNameMap, [attr](const TagNameItem item) { return item.attr == attr; }); 185ffd83dbSDimitry Andric if (tagNameIt == tagNameMap.end()) 195ffd83dbSDimitry Andric return ""; 205ffd83dbSDimitry Andric StringRef tagName = tagNameIt->tagName; 215ffd83dbSDimitry Andric return hasTagPrefix ? tagName : tagName.drop_front(4); 225ffd83dbSDimitry Andric } 235ffd83dbSDimitry Andric 24bdd1243dSDimitry Andric std::optional<unsigned> ELFAttrs::attrTypeFromString(StringRef tag, 255ffd83dbSDimitry Andric TagNameMap tagNameMap) { 26*5f757f3fSDimitry Andric bool hasTagPrefix = tag.starts_with("Tag_"); 275ffd83dbSDimitry Andric auto tagNameIt = 285ffd83dbSDimitry Andric find_if(tagNameMap, [tag, hasTagPrefix](const TagNameItem item) { 295ffd83dbSDimitry Andric return item.tagName.drop_front(hasTagPrefix ? 0 : 4) == tag; 305ffd83dbSDimitry Andric }); 315ffd83dbSDimitry Andric if (tagNameIt == tagNameMap.end()) 32bdd1243dSDimitry Andric return std::nullopt; 335ffd83dbSDimitry Andric return tagNameIt->attr; 345ffd83dbSDimitry Andric } 35