LLVM 17.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/Endian.h"
16#include "llvm/Support/Error.h"
17
18#include <optional>
19#include <unordered_map>
20
21namespace llvm {
22class StringRef;
23class ScopedPrinter;
24
26 StringRef vendor;
27 std::unordered_map<unsigned, unsigned> attributes;
28 std::unordered_map<unsigned, StringRef> attributesStr;
29
30 virtual Error handler(uint64_t tag, bool &handled) = 0;
31
32protected:
37
38 void printAttribute(unsigned tag, unsigned value, StringRef valueDesc);
39
40 Error parseStringAttribute(const char *name, unsigned tag,
45
46 void setAttributeString(unsigned tag, StringRef value) {
47 attributesStr.emplace(tag, value);
48 }
49
50public:
51 virtual ~ELFAttributeParser() { static_cast<void>(!cursor.takeError()); }
52 Error integerAttribute(unsigned tag);
53 Error stringAttribute(unsigned tag);
54
56 : vendor(vendor), sw(sw), tagToStringMap(tagNameMap) {}
57
59 : vendor(vendor), sw(nullptr), tagToStringMap(tagNameMap) {}
60
62
63 std::optional<unsigned> getAttributeValue(unsigned tag) const {
64 auto I = attributes.find(tag);
65 if (I == attributes.end())
66 return std::nullopt;
67 return I->second;
68 }
69 std::optional<StringRef> getAttributeString(unsigned tag) const {
70 auto I = attributesStr.find(tag);
71 if (I == attributesStr.end())
72 return std::nullopt;
73 return I->second;
74 }
75};
76
77} // namespace llvm
78#endif
Deduce and propagate attributes
Given that RA is a live value
#define I(x, y, z)
Definition: MD5.cpp:58
static const char * name
Definition: SMEABIPass.cpp:49
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:156
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
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
Definition: regcomp.c:192