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
12 using namespace llvm;
13
14 const RISCVAttributeParser::DisplayHandler
15 RISCVAttributeParser::displayRoutines[] = {
16 {
17 RISCVAttrs::ARCH,
18 &ELFAttributeParser::stringAttribute,
19 },
20 {
21 RISCVAttrs::PRIV_SPEC,
22 &ELFAttributeParser::integerAttribute,
23 },
24 {
25 RISCVAttrs::PRIV_SPEC_MINOR,
26 &ELFAttributeParser::integerAttribute,
27 },
28 {
29 RISCVAttrs::PRIV_SPEC_REVISION,
30 &ELFAttributeParser::integerAttribute,
31 },
32 {
33 RISCVAttrs::STACK_ALIGN,
34 &RISCVAttributeParser::stackAlign,
35 },
36 {
37 RISCVAttrs::UNALIGNED_ACCESS,
38 &RISCVAttributeParser::unalignedAccess,
39 },
40 {
41 RISCVAttrs::ATOMIC_ABI,
42 &RISCVAttributeParser::atomicAbi,
43 },
44 };
45
atomicAbi(unsigned Tag)46 Error RISCVAttributeParser::atomicAbi(unsigned Tag) {
47 uint64_t Value = de.getULEB128(cursor);
48 printAttribute(Tag, Value, "Atomic ABI is " + utostr(Value));
49 return Error::success();
50 }
51
unalignedAccess(unsigned tag)52 Error RISCVAttributeParser::unalignedAccess(unsigned tag) {
53 static const char *strings[] = {"No unaligned access", "Unaligned access"};
54 return parseStringAttribute("Unaligned_access", tag, ArrayRef(strings));
55 }
56
stackAlign(unsigned tag)57 Error RISCVAttributeParser::stackAlign(unsigned tag) {
58 uint64_t value = de.getULEB128(cursor);
59 std::string description =
60 "Stack alignment is " + utostr(value) + std::string("-bytes");
61 printAttribute(tag, value, description);
62 return Error::success();
63 }
64
handler(uint64_t tag,bool & handled)65 Error 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