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
9#include "llvm/Support/RISCVAttributeParser.h"
10#include "llvm/ADT/StringExtras.h"
11
12using namespace llvm;
13
14const RISCVAttributeParser::DisplayHandler
15 RISCVAttributeParser::displayRoutines[] = {
16 {
17 .attribute: RISCVAttrs::ARCH,
18 .routine: &ELFAttributeParser::stringAttribute,
19 },
20 {
21 .attribute: RISCVAttrs::PRIV_SPEC,
22 .routine: &ELFAttributeParser::integerAttribute,
23 },
24 {
25 .attribute: RISCVAttrs::PRIV_SPEC_MINOR,
26 .routine: &ELFAttributeParser::integerAttribute,
27 },
28 {
29 .attribute: RISCVAttrs::PRIV_SPEC_REVISION,
30 .routine: &ELFAttributeParser::integerAttribute,
31 },
32 {
33 .attribute: RISCVAttrs::STACK_ALIGN,
34 .routine: &RISCVAttributeParser::stackAlign,
35 },
36 {
37 .attribute: RISCVAttrs::UNALIGNED_ACCESS,
38 .routine: &RISCVAttributeParser::unalignedAccess,
39 }};
40
41Error RISCVAttributeParser::unalignedAccess(unsigned tag) {
42 static const char *strings[] = {"No unaligned access", "Unaligned access"};
43 return parseStringAttribute(name: "Unaligned_access", tag, strings: ArrayRef(strings));
44}
45
46Error RISCVAttributeParser::stackAlign(unsigned tag) {
47 uint64_t value = de.getULEB128(C&: cursor);
48 std::string description =
49 "Stack alignment is " + utostr(X: value) + std::string("-bytes");
50 printAttribute(tag, value, valueDesc: description);
51 return Error::success();
52}
53
54Error RISCVAttributeParser::handler(uint64_t tag, bool &handled) {
55 handled = false;
56 for (const auto &AH : displayRoutines) {
57 if (uint64_t(AH.attribute) == tag) {
58 if (Error e = (this->*AH.routine)(tag))
59 return e;
60 handled = true;
61 break;
62 }
63 }
64
65 return Error::success();
66}
67

source code of llvm/lib/Support/RISCVAttributeParser.cpp