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 {
41 .attribute: RISCVAttrs::ATOMIC_ABI,
42 .routine: &RISCVAttributeParser::atomicAbi,
43 },
44};
45
46Error RISCVAttributeParser::atomicAbi(unsigned Tag) {
47 uint64_t Value = de.getULEB128(C&: cursor);
48 printAttribute(tag: Tag, value: Value, valueDesc: "Atomic ABI is " + utostr(X: Value));
49 return Error::success();
50}
51
52Error RISCVAttributeParser::unalignedAccess(unsigned tag) {
53 static const char *strings[] = {"No unaligned access", "Unaligned access"};
54 return parseStringAttribute(name: "Unaligned_access", tag, strings: ArrayRef(strings));
55}
56
57Error RISCVAttributeParser::stackAlign(unsigned tag) {
58 uint64_t value = de.getULEB128(C&: cursor);
59 std::string description =
60 "Stack alignment is " + utostr(X: value) + std::string("-bytes");
61 printAttribute(tag, value, valueDesc: description);
62 return Error::success();
63}
64
65Error RISCVAttributeParser::handler(uint64_t tag, bool &handled) {
66 handled = false;
67 for (const auto &AH : displayRoutines) {
68 if (uint64_t(AH.attribute) == tag) {
69 if (Error e = (this->*AH.routine)(tag))
70 return e;
71 handled = true;
72 break;
73 }
74 }
75
76 return Error::success();
77}
78