LLVM  15.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 <unordered_map>
19 
20 namespace llvm {
21 class StringRef;
22 class 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 
31 protected:
36 
37  void printAttribute(unsigned tag, unsigned value, StringRef valueDesc);
38 
39  Error parseStringAttribute(const char *name, unsigned tag,
40  ArrayRef<const char *> strings);
44 
45 public:
46  virtual ~ELFAttributeParser() { static_cast<void>(!cursor.takeError()); }
47  Error integerAttribute(unsigned tag);
48  Error stringAttribute(unsigned tag);
49 
51  : vendor(vendor), sw(sw), tagToStringMap(tagNameMap) {}
52 
54  : vendor(vendor), sw(nullptr), tagToStringMap(tagNameMap) {}
55 
57 
58  Optional<unsigned> getAttributeValue(unsigned tag) const {
59  auto I = attributes.find(tag);
60  if (I == attributes.end())
61  return None;
62  return I->second;
63  }
65  auto I = attributesStr.find(tag);
66  if (I == attributesStr.end())
67  return None;
68  return I->second;
69  }
70 };
71 
72 } // namespace llvm
73 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::ELFAttributeParser::parseStringAttribute
Error parseStringAttribute(const char *name, unsigned tag, ArrayRef< const char * > strings)
Definition: ELFAttributeParser.cpp:23
llvm::ELFAttributeParser::printAttribute
void printAttribute(unsigned tag, unsigned value, StringRef valueDesc)
Definition: ELFAttributeParser.cpp:68
llvm::ELFAttributeParser::getAttributeString
Optional< StringRef > getAttributeString(unsigned tag) const
Definition: ELFAttributeParser.h:64
llvm::ELFAttributeParser::ELFAttributeParser
ELFAttributeParser(TagNameMap tagNameMap, StringRef vendor)
Definition: ELFAttributeParser.h:53
Error.h
llvm::Optional< unsigned >
attributes
Deduce and propagate attributes
Definition: Attributor.cpp:3469
llvm::support::endian
Definition: Endian.h:42
llvm::DataExtractor::Cursor::takeError
Error takeError()
Return error contained inside this Cursor, if any.
Definition: DataExtractor.h:78
llvm::ELFAttributeParser::sw
ScopedPrinter * sw
Definition: ELFAttributeParser.h:32
llvm::ELFAttributeParser::ELFAttributeParser
ELFAttributeParser(ScopedPrinter *sw, TagNameMap tagNameMap, StringRef vendor)
Definition: ELFAttributeParser.h:50
llvm::ELFAttributeParser::de
DataExtractor de
Definition: ELFAttributeParser.h:34
llvm::ELFAttributeParser::parseAttributeList
Error parseAttributeList(uint32_t length)
Definition: ELFAttributeParser.cpp:94
llvm::None
const NoneType None
Definition: None.h:24
ELFAttributes.h
uint64_t
I
#define I(x, y, z)
Definition: MD5.cpp:58
ArrayRef.h
llvm::ELFAttributeParser::~ELFAttributeParser
virtual ~ELFAttributeParser()
Definition: ELFAttributeParser.h:46
llvm::DataExtractor::Cursor
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition: DataExtractor.h:54
llvm::ELFAttributeParser
Definition: ELFAttributeParser.h:24
llvm::ELFAttributeParser::parse
Error parse(ArrayRef< uint8_t > section, support::endianness endian)
Definition: ELFAttributeParser.cpp:187
llvm::ArrayRef< TagNameItem >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::ELFAttributeParser::cursor
DataExtractor::Cursor cursor
Definition: ELFAttributeParser.h:35
llvm::ELFAttributeParser::integerAttribute
Error integerAttribute(unsigned tag)
Definition: ELFAttributeParser.cpp:36
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:74
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::ScopedPrinter
Definition: ScopedPrinter.h:100
DataExtractor.h
llvm::DataExtractor
Definition: DataExtractor.h:41
llvm::ELFAttributeParser::parseSubsection
Error parseSubsection(uint32_t length)
Definition: ELFAttributeParser.cpp:122
llvm::support::endianness
endianness
Definition: Endian.h:27
llvm::SmallVectorImpl< uint8_t >
llvm::ELFAttributeParser::tagToStringMap
TagNameMap tagToStringMap
Definition: ELFAttributeParser.h:33
Endian.h
llvm::ELFAttributeParser::stringAttribute
Error stringAttribute(unsigned tag)
Definition: ELFAttributeParser.cpp:52
llvm::ELFAttributeParser::getAttributeValue
Optional< unsigned > getAttributeValue(unsigned tag) const
Definition: ELFAttributeParser.h:58
llvm::ELFAttributeParser::parseIndexList
void parseIndexList(SmallVectorImpl< uint8_t > &indexList)
Definition: ELFAttributeParser.cpp:85