LLVM  14.0.0git
RISCVAttributeParser.cpp
Go to the documentation of this file.
1 //===-- RISCVAttributeParser.cpp - RISCV Attribute Parser -----------------===//
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 
10 #include "llvm/ADT/StringExtras.h"
11 
12 using namespace llvm;
13 
14 const RISCVAttributeParser::DisplayHandler
15  RISCVAttributeParser::displayRoutines[] = {
16  {
19  },
20  {
23  },
24  {
27  },
28  {
31  },
32  {
34  &RISCVAttributeParser::stackAlign,
35  },
36  {
38  &RISCVAttributeParser::unalignedAccess,
39  }};
40 
41 Error RISCVAttributeParser::unalignedAccess(unsigned tag) {
42  static const char *strings[] = {"No unaligned access", "Unaligned access"};
43  return parseStringAttribute("Unaligned_access", tag, makeArrayRef(strings));
44 }
45 
46 Error RISCVAttributeParser::stackAlign(unsigned tag) {
47  uint64_t value = de.getULEB128(cursor);
48  std::string description =
49  "Stack alignment is " + utostr(value) + std::string("-bytes");
50  printAttribute(tag, value, description);
51  return Error::success();
52 }
53 
54 Error RISCVAttributeParser::handler(uint64_t tag, bool &handled) {
55  handled = false;
56  for (unsigned AHI = 0, AHE = array_lengthof(displayRoutines); AHI != AHE;
57  ++AHI) {
58  if (uint64_t(displayRoutines[AHI].attribute) == tag) {
59  if (Error e = (this->*displayRoutines[AHI].routine)(tag))
60  return e;
61  handled = true;
62  break;
63  }
64  }
65 
66  return Error::success();
67 }
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::ELFAttributeParser::parseStringAttribute
Error parseStringAttribute(const char *name, unsigned tag, ArrayRef< const char * > strings)
Definition: ELFAttributeParser.cpp:25
llvm::RISCVAttrs::PRIV_SPEC
@ PRIV_SPEC
Definition: RISCVAttributes.h:32
llvm::ELFAttributeParser::printAttribute
void printAttribute(unsigned tag, unsigned value, StringRef valueDesc)
Definition: ELFAttributeParser.cpp:70
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::RISCVAttrs::STACK_ALIGN
@ STACK_ALIGN
Definition: RISCVAttributes.h:29
llvm::RISCVAttrs::PRIV_SPEC_MINOR
@ PRIV_SPEC_MINOR
Definition: RISCVAttributes.h:33
llvm::DataExtractor::getULEB128
uint64_t getULEB128(uint64_t *offset_ptr, llvm::Error *Err=nullptr) const
Extract a unsigned LEB128 value from *offset_ptr.
Definition: DataExtractor.cpp:221
llvm::ELFAttributeParser::de
DataExtractor de
Definition: ELFAttributeParser.h:33
llvm::array_lengthof
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Definition: STLExtras.h:1394
uint64_t
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
RISCVAttributeParser.h
StringExtras.h
llvm::RISCVAttrs::ARCH
@ ARCH
Definition: RISCVAttributes.h:30
llvm::ELFAttributeParser::cursor
DataExtractor::Cursor cursor
Definition: ELFAttributeParser.h:34
llvm::ELFAttributeParser::integerAttribute
Error integerAttribute(unsigned tag)
Definition: ELFAttributeParser.cpp:38
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::RISCVAttrs::UNALIGNED_ACCESS
@ UNALIGNED_ACCESS
Definition: RISCVAttributes.h:31
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::ELFAttributeParser::stringAttribute
Error stringAttribute(unsigned tag)
Definition: ELFAttributeParser.cpp:54
llvm::RISCVAttrs::PRIV_SPEC_REVISION
@ PRIV_SPEC_REVISION
Definition: RISCVAttributes.h:34