1 //===-- CSKYAttributeParser.cpp - CSKY 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/CSKYAttributeParser.h"
10 #include "llvm/ADT/StringExtras.h"
11 #include "llvm/Support/Errc.h"
15 const CSKYAttributeParser::DisplayHandler
16 CSKYAttributeParser::displayRoutines
[] = {
18 CSKYAttrs::CSKY_ARCH_NAME
,
19 &ELFAttributeParser::stringAttribute
,
22 CSKYAttrs::CSKY_CPU_NAME
,
23 &ELFAttributeParser::stringAttribute
,
26 CSKYAttrs::CSKY_ISA_FLAGS
,
27 &ELFAttributeParser::integerAttribute
,
30 CSKYAttrs::CSKY_ISA_EXT_FLAGS
,
31 &ELFAttributeParser::integerAttribute
,
34 CSKYAttrs::CSKY_DSP_VERSION
,
35 &CSKYAttributeParser::dspVersion
,
38 CSKYAttrs::CSKY_VDSP_VERSION
,
39 &CSKYAttributeParser::vdspVersion
,
42 CSKYAttrs::CSKY_FPU_VERSION
,
43 &CSKYAttributeParser::fpuVersion
,
46 CSKYAttrs::CSKY_FPU_ABI
,
47 &CSKYAttributeParser::fpuABI
,
50 CSKYAttrs::CSKY_FPU_ROUNDING
,
51 &CSKYAttributeParser::fpuRounding
,
54 CSKYAttrs::CSKY_FPU_DENORMAL
,
55 &CSKYAttributeParser::fpuDenormal
,
58 CSKYAttrs::CSKY_FPU_EXCEPTION
,
59 &CSKYAttributeParser::fpuException
,
62 CSKYAttrs::CSKY_FPU_NUMBER_MODULE
,
63 &ELFAttributeParser::stringAttribute
,
66 CSKYAttrs::CSKY_FPU_HARDFP
,
67 &CSKYAttributeParser::fpuHardFP
,
70 Error
CSKYAttributeParser::handler(uint64_t tag
, bool &handled
) {
72 for (const auto &AH
: displayRoutines
) {
73 if (uint64_t(AH
.attribute
) == tag
) {
74 if (Error e
= (this->*AH
.routine
)(tag
))
81 return Error::success();
84 Error
CSKYAttributeParser::dspVersion(unsigned tag
) {
85 static const char *const strings
[] = {"Error", "DSP Extension", "DSP 2.0"};
86 return parseStringAttribute("Tag_CSKY_DSP_VERSION", tag
, ArrayRef(strings
));
89 Error
CSKYAttributeParser::vdspVersion(unsigned tag
) {
90 static const char *const strings
[] = {"Error", "VDSP Version 1",
92 return parseStringAttribute("Tag_CSKY_VDSP_VERSION", tag
, ArrayRef(strings
));
95 Error
CSKYAttributeParser::fpuVersion(unsigned tag
) {
96 static const char *const strings
[] = {"Error", "FPU Version 1",
97 "FPU Version 2", "FPU Version 3"};
98 return parseStringAttribute("Tag_CSKY_FPU_VERSION", tag
, ArrayRef(strings
));
101 Error
CSKYAttributeParser::fpuABI(unsigned tag
) {
102 static const char *const strings
[] = {"Error", "Soft", "SoftFP", "Hard"};
103 return parseStringAttribute("Tag_CSKY_FPU_ABI", tag
, ArrayRef(strings
));
106 Error
CSKYAttributeParser::fpuRounding(unsigned tag
) {
107 static const char *const strings
[] = {"None", "Needed"};
108 return parseStringAttribute("Tag_CSKY_FPU_ROUNDING", tag
, ArrayRef(strings
));
111 Error
CSKYAttributeParser::fpuDenormal(unsigned tag
) {
112 static const char *const strings
[] = {"None", "Needed"};
113 return parseStringAttribute("Tag_CSKY_FPU_DENORMAL", tag
, ArrayRef(strings
));
116 Error
CSKYAttributeParser::fpuException(unsigned tag
) {
117 static const char *const strings
[] = {"None", "Needed"};
118 return parseStringAttribute("Tag_CSKY_FPU_EXCEPTION", tag
, ArrayRef(strings
));
121 Error
CSKYAttributeParser::fpuHardFP(unsigned tag
) {
122 uint64_t value
= de
.getULEB128(cursor
);
123 ListSeparator
LS(" ");
125 std::string description
;
129 description
+= "Half";
131 if ((value
>> 1) & 0x1) {
133 description
+= "Single";
135 if ((value
>> 2) & 0x1) {
137 description
+= "Double";
140 if (description
.empty()) {
141 printAttribute(tag
, value
, "");
142 return createStringError(errc::invalid_argument
,
143 "unknown Tag_CSKY_FPU_HARDFP value: " +
147 printAttribute(tag
, value
, description
);
148 return Error::success();