LLVM 22.0.0git
ELFAttrParserCompact.h
Go to the documentation of this file.
1//===- ELF AttributeParser.h - ELF Attribute Parser -------------*- C++ -*-===//
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#ifndef LLVM_SUPPORT_ELFCOMPACTATTRPARSER_H
10#define LLVM_SUPPORT_ELFCOMPACTATTRPARSER_H
11
12#include "llvm/ADT/ArrayRef.h"
17#include "llvm/Support/Error.h"
18
19#include <optional>
20#include <unordered_map>
21
22namespace llvm {
23class StringRef;
24class ScopedPrinter;
25
27 StringRef vendor;
28 std::unordered_map<unsigned, unsigned> attributes;
29 std::unordered_map<unsigned, StringRef> attributesStr;
30
31 virtual Error handler(uint64_t tag, bool &handled) = 0;
32
33protected:
38
39 void printAttribute(unsigned tag, unsigned value, StringRef valueDesc);
40
41 Error parseStringAttribute(const char *name, unsigned tag,
43 Error parseAttributeList(uint32_t length);
44 void parseIndexList(SmallVectorImpl<uint8_t> &indexList);
45 Error parseSubsection(uint32_t length);
46
47 void setAttributeString(unsigned tag, StringRef value) {
48 attributesStr.emplace(tag, value);
49 }
50
51public:
52 virtual ~ELFCompactAttrParser() { static_cast<void>(!cursor.takeError()); }
53 Error integerAttribute(unsigned tag);
54 Error stringAttribute(unsigned tag);
55
57 StringRef vendor)
58 : vendor(vendor), sw(sw), tagToStringMap(tagNameMap) {}
60 : vendor(vendor), sw(nullptr), tagToStringMap(tagNameMap) {}
61
63
64 std::optional<unsigned> getAttributeValue(unsigned tag) const override {
65 auto I = attributes.find(tag);
66 if (I == attributes.end())
67 return std::nullopt;
68 return I->second;
69 }
70 std::optional<unsigned>
71 getAttributeValue(StringRef buildAttributeSubsectionName,
72 unsigned tag) const override {
73 assert("" == buildAttributeSubsectionName &&
74 "buildAttributeSubsectionName must be an empty string");
75 return getAttributeValue(tag);
76 }
77 std::optional<StringRef> getAttributeString(unsigned tag) const override {
78 auto I = attributesStr.find(tag);
79 if (I == attributesStr.end())
80 return std::nullopt;
81 return I->second;
82 }
83 std::optional<StringRef>
84 getAttributeString(StringRef buildAttributeSubsectionName,
85 unsigned tag) const override {
86 assert("" == buildAttributeSubsectionName &&
87 "buildAttributeSubsectionName must be an empty string");
88 return getAttributeString(tag);
89 }
90};
91
92} // namespace llvm
93#endif // LLVM_SUPPORT_ELFCOMPACTATTRPARSER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition: Compiler.h:213
Given that RA is a live value
#define I(x, y, z)
Definition: MD5.cpp:58
static const char * name
Definition: SMEABIPass.cpp:52
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition: DataExtractor.h:55
std::optional< StringRef > getAttributeString(unsigned tag) const override
ELFCompactAttrParser(ScopedPrinter *sw, TagNameMap tagNameMap, StringRef vendor)
ELFCompactAttrParser(TagNameMap tagNameMap, StringRef vendor)
void setAttributeString(unsigned tag, StringRef value)
std::optional< StringRef > getAttributeString(StringRef buildAttributeSubsectionName, unsigned tag) const override
std::optional< unsigned > getAttributeValue(StringRef buildAttributeSubsectionName, unsigned tag) const override
std::optional< unsigned > getAttributeValue(unsigned tag) const override
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
endianness
Definition: bit.h:71
Definition: regcomp.c:186