| 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 | .attribute: RISCVAttrs::ARCH, |
| 18 | .routine: &ELFCompactAttrParser::stringAttribute, |
| 19 | }, |
| 20 | { |
| 21 | .attribute: RISCVAttrs::PRIV_SPEC, |
| 22 | .routine: &ELFCompactAttrParser::integerAttribute, |
| 23 | }, |
| 24 | { |
| 25 | .attribute: RISCVAttrs::PRIV_SPEC_MINOR, |
| 26 | .routine: &ELFCompactAttrParser::integerAttribute, |
| 27 | }, |
| 28 | { |
| 29 | .attribute: RISCVAttrs::PRIV_SPEC_REVISION, |
| 30 | .routine: &ELFCompactAttrParser::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 | |
| 46 | Error 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 | |
| 52 | Error RISCVAttributeParser::unalignedAccess(unsigned tag) { |
| 53 | static const char *const strings[] = {"No unaligned access" , |
| 54 | "Unaligned access" }; |
| 55 | return parseStringAttribute(name: "Unaligned_access" , tag, strings: ArrayRef(strings)); |
| 56 | } |
| 57 | |
| 58 | Error RISCVAttributeParser::stackAlign(unsigned tag) { |
| 59 | uint64_t value = de.getULEB128(C&: cursor); |
| 60 | std::string description = |
| 61 | "Stack alignment is " + utostr(X: value) + std::string("-bytes" ); |
| 62 | printAttribute(tag, value, valueDesc: description); |
| 63 | return Error::success(); |
| 64 | } |
| 65 | |
| 66 | Error RISCVAttributeParser::handler(uint64_t tag, bool &handled) { |
| 67 | handled = false; |
| 68 | for (const auto &AH : displayRoutines) { |
| 69 | if (uint64_t(AH.attribute) == tag) { |
| 70 | if (Error e = (this->*AH.routine)(tag)) |
| 71 | return e; |
| 72 | handled = true; |
| 73 | break; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | return Error::success(); |
| 78 | } |
| 79 | |