1 //===-- RISCVAttributeParser.cpp - RISCV Attribute Parser -----------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/RISCVAttributeParser.h"
10 #include "llvm/ADT/StringExtras.h"
14 const RISCVAttributeParser::DisplayHandler
15 RISCVAttributeParser::displayRoutines
[] = {
18 &ELFAttributeParser::stringAttribute
,
21 RISCVAttrs::PRIV_SPEC
,
22 &ELFAttributeParser::integerAttribute
,
25 RISCVAttrs::PRIV_SPEC_MINOR
,
26 &ELFAttributeParser::integerAttribute
,
29 RISCVAttrs::PRIV_SPEC_REVISION
,
30 &ELFAttributeParser::integerAttribute
,
33 RISCVAttrs::STACK_ALIGN
,
34 &RISCVAttributeParser::stackAlign
,
37 RISCVAttrs::UNALIGNED_ACCESS
,
38 &RISCVAttributeParser::unalignedAccess
,
41 RISCVAttrs::ATOMIC_ABI
,
42 &RISCVAttributeParser::atomicAbi
,
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();
52 Error
RISCVAttributeParser::unalignedAccess(unsigned tag
) {
53 static const char *const strings
[] = {"No unaligned access",
55 return parseStringAttribute("Unaligned_access", tag
, ArrayRef(strings
));
58 Error
RISCVAttributeParser::stackAlign(unsigned tag
) {
59 uint64_t value
= de
.getULEB128(cursor
);
60 std::string description
=
61 "Stack alignment is " + utostr(value
) + std::string("-bytes");
62 printAttribute(tag
, value
, description
);
63 return Error::success();
66 Error
RISCVAttributeParser::handler(uint64_t tag
, bool &handled
) {
68 for (const auto &AH
: displayRoutines
) {
69 if (uint64_t(AH
.attribute
) == tag
) {
70 if (Error e
= (this->*AH
.routine
)(tag
))
77 return Error::success();