LLVM  14.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 "ScopedPrinter.h"
14 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/Support/Error.h"
17 
18 #include <unordered_map>
19 
20 namespace llvm {
21 class StringRef;
22 
24  StringRef vendor;
25  std::unordered_map<unsigned, unsigned> attributes;
26  std::unordered_map<unsigned, StringRef> attributesStr;
27 
28  virtual Error handler(uint64_t tag, bool &handled) = 0;
29 
30 protected:
35 
36  void printAttribute(unsigned tag, unsigned value, StringRef valueDesc);
37 
38  Error parseStringAttribute(const char *name, unsigned tag,
39  ArrayRef<const char *> strings);
43 
44 public:
45  virtual ~ELFAttributeParser() { static_cast<void>(!cursor.takeError()); }
46  Error integerAttribute(unsigned tag);
47  Error stringAttribute(unsigned tag);
48 
50  : vendor(vendor), sw(sw), tagToStringMap(tagNameMap) {}
51 
53  : vendor(vendor), sw(nullptr), tagToStringMap(tagNameMap) {}
54 
56 
57  Optional<unsigned> getAttributeValue(unsigned tag) const {
58  auto I = attributes.find(tag);
59  if (I == attributes.end())
60  return None;
61  return I->second;
62  }
64  auto I = attributesStr.find(tag);
65  if (I == attributesStr.end())
66  return None;
67  return I->second;
68  }
69 };
70 
71 } // namespace llvm
72 #endif
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::ELFAttributeParser::parseStringAttribute
Error parseStringAttribute(const char *name, unsigned tag, ArrayRef< const char * > strings)
Definition: ELFAttributeParser.cpp:25
llvm::ELFAttributeParser::printAttribute
void printAttribute(unsigned tag, unsigned value, StringRef valueDesc)
Definition: ELFAttributeParser.cpp:70
llvm::ELFAttributeParser::getAttributeString
Optional< StringRef > getAttributeString(unsigned tag) const
Definition: ELFAttributeParser.h:63
llvm::ELFAttributeParser::ELFAttributeParser
ELFAttributeParser(TagNameMap tagNameMap, StringRef vendor)
Definition: ELFAttributeParser.h:52
Error.h
llvm::Optional< unsigned >
attributes
Deduce and propagate attributes
Definition: Attributor.cpp:3074
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:31
llvm::ELFAttributeParser::ELFAttributeParser
ELFAttributeParser(ScopedPrinter *sw, TagNameMap tagNameMap, StringRef vendor)
Definition: ELFAttributeParser.h:49
llvm::ELFAttributeParser::de
DataExtractor de
Definition: ELFAttributeParser.h:33
llvm::ELFAttributeParser::parseAttributeList
Error parseAttributeList(uint32_t length)
Definition: ELFAttributeParser.cpp:96
llvm::None
const NoneType None
Definition: None.h:23
ELFAttributes.h
uint64_t
I
#define I(x, y, z)
Definition: MD5.cpp:59
ArrayRef.h
llvm::ELFAttributeParser::~ELFAttributeParser
virtual ~ELFAttributeParser()
Definition: ELFAttributeParser.h:45
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:23
llvm::ELFAttributeParser::parse
Error parse(ArrayRef< uint8_t > section, support::endianness endian)
Definition: ELFAttributeParser.cpp:189
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:34
llvm::ELFAttributeParser::integerAttribute
Error integerAttribute(unsigned tag)
Definition: ELFAttributeParser.cpp:38
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:78
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::ScopedPrinter
Definition: ScopedPrinter.h:70
DataExtractor.h
llvm::DataExtractor
Definition: DataExtractor.h:41
llvm::ELFAttributeParser::parseSubsection
Error parseSubsection(uint32_t length)
Definition: ELFAttributeParser.cpp:124
llvm::support::endianness
endianness
Definition: Endian.h:27
llvm::SmallVectorImpl< uint8_t >
llvm::ELFAttributeParser::tagToStringMap
TagNameMap tagToStringMap
Definition: ELFAttributeParser.h:32
llvm::ELFAttributeParser::stringAttribute
Error stringAttribute(unsigned tag)
Definition: ELFAttributeParser.cpp:54
llvm::ELFAttributeParser::getAttributeValue
Optional< unsigned > getAttributeValue(unsigned tag) const
Definition: ELFAttributeParser.h:57
llvm::ELFAttributeParser::parseIndexList
void parseIndexList(SmallVectorImpl< uint8_t > &indexList)
Definition: ELFAttributeParser.cpp:87
ScopedPrinter.h