LLVM 20.0.0git
ELFAttributeParser.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_ELFATTRIBUTEPARSER_H
10#define LLVM_SUPPORT_ELFATTRIBUTEPARSER_H
11
12#include "ELFAttributes.h"
13#include "llvm/ADT/ArrayRef.h"
15#include "llvm/Support/Error.h"
16
17#include <optional>
18#include <unordered_map>
19
20namespace llvm {
21class StringRef;
22class ScopedPrinter;
23
25 StringRef vendor;
26 std::unordered_map<unsigned, unsigned> attributes;
27 std::unordered_map<unsigned, StringRef> attributesStr;
28
29 virtual Error handler(uint64_t tag, bool &handled) = 0;
30
31protected:
36
37 void printAttribute(unsigned tag, unsigned value, StringRef valueDesc);
38
39 Error parseStringAttribute(const char *name, unsigned tag,
44
45 void setAttributeString(unsigned tag, StringRef value) {
46 attributesStr.emplace(tag, value);
47 }
48
49public:
50 virtual ~ELFAttributeParser() { static_cast<void>(!cursor.takeError()); }
51 Error integerAttribute(unsigned tag);
52 Error stringAttribute(unsigned tag);
53
55 : vendor(vendor), sw(sw), tagToStringMap(tagNameMap) {}
56
58 : vendor(vendor), sw(nullptr), tagToStringMap(tagNameMap) {}
59
61
62 std::optional<unsigned> getAttributeValue(unsigned tag) const {
63 auto I = attributes.find(tag);
64 if (I == attributes.end())
65 return std::nullopt;
66 return I->second;
67 }
68 std::optional<StringRef> getAttributeString(unsigned tag) const {
69 auto I = attributesStr.find(tag);
70 if (I == attributesStr.end())
71 return std::nullopt;
72 return I->second;
73 }
74};
75
76} // namespace llvm
77#endif
Given that RA is a live value
#define I(x, y, z)
Definition: MD5.cpp:58
static const char * name
Definition: SMEABIPass.cpp:50
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition: DataExtractor.h:54
Error takeError()
Return error contained inside this Cursor, if any.
Definition: DataExtractor.h:78
void setAttributeString(unsigned tag, StringRef value)
Error parseSubsection(uint32_t length)
std::optional< StringRef > getAttributeString(unsigned tag) const
std::optional< unsigned > getAttributeValue(unsigned tag) const
Error integerAttribute(unsigned tag)
DataExtractor::Cursor cursor
ELFAttributeParser(ScopedPrinter *sw, TagNameMap tagNameMap, StringRef vendor)
ELFAttributeParser(TagNameMap tagNameMap, StringRef vendor)
Error stringAttribute(unsigned tag)
void parseIndexList(SmallVectorImpl< uint8_t > &indexList)
Error parseStringAttribute(const char *name, unsigned tag, ArrayRef< const char * > strings)
void printAttribute(unsigned tag, unsigned value, StringRef valueDesc)
Error parseAttributeList(uint32_t length)
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
endianness
Definition: bit.h:70
Definition: regcomp.c:192