1*21bce900SZi Xuan Wu //===-- CSKYAttributeParser.cpp - CSKY Attribute Parser -----------------===//
2*21bce900SZi Xuan Wu //
3*21bce900SZi Xuan Wu // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*21bce900SZi Xuan Wu // See https://llvm.org/LICENSE.txt for license information.
5*21bce900SZi Xuan Wu // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*21bce900SZi Xuan Wu //
7*21bce900SZi Xuan Wu //===----------------------------------------------------------------------===//
8*21bce900SZi Xuan Wu
9*21bce900SZi Xuan Wu #include "llvm/Support/CSKYAttributeParser.h"
10*21bce900SZi Xuan Wu #include "llvm/ADT/StringExtras.h"
11*21bce900SZi Xuan Wu #include "llvm/Support/Errc.h"
12*21bce900SZi Xuan Wu
13*21bce900SZi Xuan Wu using namespace llvm;
14*21bce900SZi Xuan Wu
15*21bce900SZi Xuan Wu const CSKYAttributeParser::DisplayHandler
16*21bce900SZi Xuan Wu CSKYAttributeParser::displayRoutines[] = {
17*21bce900SZi Xuan Wu {
18*21bce900SZi Xuan Wu CSKYAttrs::CSKY_ARCH_NAME,
19*21bce900SZi Xuan Wu &ELFAttributeParser::stringAttribute,
20*21bce900SZi Xuan Wu },
21*21bce900SZi Xuan Wu {
22*21bce900SZi Xuan Wu CSKYAttrs::CSKY_CPU_NAME,
23*21bce900SZi Xuan Wu &ELFAttributeParser::stringAttribute,
24*21bce900SZi Xuan Wu },
25*21bce900SZi Xuan Wu {
26*21bce900SZi Xuan Wu CSKYAttrs::CSKY_ISA_FLAGS,
27*21bce900SZi Xuan Wu &ELFAttributeParser::integerAttribute,
28*21bce900SZi Xuan Wu },
29*21bce900SZi Xuan Wu {
30*21bce900SZi Xuan Wu CSKYAttrs::CSKY_ISA_EXT_FLAGS,
31*21bce900SZi Xuan Wu &ELFAttributeParser::integerAttribute,
32*21bce900SZi Xuan Wu },
33*21bce900SZi Xuan Wu {
34*21bce900SZi Xuan Wu CSKYAttrs::CSKY_DSP_VERSION,
35*21bce900SZi Xuan Wu &CSKYAttributeParser::dspVersion,
36*21bce900SZi Xuan Wu },
37*21bce900SZi Xuan Wu {
38*21bce900SZi Xuan Wu CSKYAttrs::CSKY_VDSP_VERSION,
39*21bce900SZi Xuan Wu &CSKYAttributeParser::vdspVersion,
40*21bce900SZi Xuan Wu },
41*21bce900SZi Xuan Wu {
42*21bce900SZi Xuan Wu CSKYAttrs::CSKY_FPU_VERSION,
43*21bce900SZi Xuan Wu &CSKYAttributeParser::fpuVersion,
44*21bce900SZi Xuan Wu },
45*21bce900SZi Xuan Wu {
46*21bce900SZi Xuan Wu CSKYAttrs::CSKY_FPU_ABI,
47*21bce900SZi Xuan Wu &CSKYAttributeParser::fpuABI,
48*21bce900SZi Xuan Wu },
49*21bce900SZi Xuan Wu {
50*21bce900SZi Xuan Wu CSKYAttrs::CSKY_FPU_ROUNDING,
51*21bce900SZi Xuan Wu &CSKYAttributeParser::fpuRounding,
52*21bce900SZi Xuan Wu },
53*21bce900SZi Xuan Wu {
54*21bce900SZi Xuan Wu CSKYAttrs::CSKY_FPU_DENORMAL,
55*21bce900SZi Xuan Wu &CSKYAttributeParser::fpuDenormal,
56*21bce900SZi Xuan Wu },
57*21bce900SZi Xuan Wu {
58*21bce900SZi Xuan Wu CSKYAttrs::CSKY_FPU_EXCEPTION,
59*21bce900SZi Xuan Wu &CSKYAttributeParser::fpuException,
60*21bce900SZi Xuan Wu },
61*21bce900SZi Xuan Wu {
62*21bce900SZi Xuan Wu CSKYAttrs::CSKY_FPU_NUMBER_MODULE,
63*21bce900SZi Xuan Wu &ELFAttributeParser::stringAttribute,
64*21bce900SZi Xuan Wu },
65*21bce900SZi Xuan Wu {
66*21bce900SZi Xuan Wu CSKYAttrs::CSKY_FPU_HARDFP,
67*21bce900SZi Xuan Wu &CSKYAttributeParser::fpuHardFP,
68*21bce900SZi Xuan Wu }};
69*21bce900SZi Xuan Wu
handler(uint64_t tag,bool & handled)70*21bce900SZi Xuan Wu Error CSKYAttributeParser::handler(uint64_t tag, bool &handled) {
71*21bce900SZi Xuan Wu handled = false;
72*21bce900SZi Xuan Wu for (unsigned AHI = 0, AHE = array_lengthof(displayRoutines); AHI != AHE;
73*21bce900SZi Xuan Wu ++AHI) {
74*21bce900SZi Xuan Wu if (uint64_t(displayRoutines[AHI].attribute) == tag) {
75*21bce900SZi Xuan Wu if (Error e = (this->*displayRoutines[AHI].routine)(tag))
76*21bce900SZi Xuan Wu return e;
77*21bce900SZi Xuan Wu handled = true;
78*21bce900SZi Xuan Wu break;
79*21bce900SZi Xuan Wu }
80*21bce900SZi Xuan Wu }
81*21bce900SZi Xuan Wu
82*21bce900SZi Xuan Wu return Error::success();
83*21bce900SZi Xuan Wu }
84*21bce900SZi Xuan Wu
dspVersion(unsigned tag)85*21bce900SZi Xuan Wu Error CSKYAttributeParser::dspVersion(unsigned tag) {
86*21bce900SZi Xuan Wu static const char *strings[] = {"Error", "DSP Extension", "DSP 2.0"};
87*21bce900SZi Xuan Wu return parseStringAttribute("Tag_CSKY_DSP_VERSION", tag,
88*21bce900SZi Xuan Wu makeArrayRef(strings));
89*21bce900SZi Xuan Wu }
90*21bce900SZi Xuan Wu
vdspVersion(unsigned tag)91*21bce900SZi Xuan Wu Error CSKYAttributeParser::vdspVersion(unsigned tag) {
92*21bce900SZi Xuan Wu static const char *strings[] = {"Error", "VDSP Version 1", "VDSP Version 2"};
93*21bce900SZi Xuan Wu return parseStringAttribute("Tag_CSKY_VDSP_VERSION", tag,
94*21bce900SZi Xuan Wu makeArrayRef(strings));
95*21bce900SZi Xuan Wu }
96*21bce900SZi Xuan Wu
fpuVersion(unsigned tag)97*21bce900SZi Xuan Wu Error CSKYAttributeParser::fpuVersion(unsigned tag) {
98*21bce900SZi Xuan Wu static const char *strings[] = {"Error", "FPU Version 1", "FPU Version 2",
99*21bce900SZi Xuan Wu "FPU Version 3"};
100*21bce900SZi Xuan Wu return parseStringAttribute("Tag_CSKY_FPU_VERSION", tag,
101*21bce900SZi Xuan Wu makeArrayRef(strings));
102*21bce900SZi Xuan Wu }
103*21bce900SZi Xuan Wu
fpuABI(unsigned tag)104*21bce900SZi Xuan Wu Error CSKYAttributeParser::fpuABI(unsigned tag) {
105*21bce900SZi Xuan Wu static const char *strings[] = {"Error", "Soft", "SoftFP", "Hard"};
106*21bce900SZi Xuan Wu return parseStringAttribute("Tag_CSKY_FPU_ABI", tag, makeArrayRef(strings));
107*21bce900SZi Xuan Wu }
108*21bce900SZi Xuan Wu
fpuRounding(unsigned tag)109*21bce900SZi Xuan Wu Error CSKYAttributeParser::fpuRounding(unsigned tag) {
110*21bce900SZi Xuan Wu static const char *strings[] = {"None", "Needed"};
111*21bce900SZi Xuan Wu return parseStringAttribute("Tag_CSKY_FPU_ROUNDING", tag,
112*21bce900SZi Xuan Wu makeArrayRef(strings));
113*21bce900SZi Xuan Wu }
114*21bce900SZi Xuan Wu
fpuDenormal(unsigned tag)115*21bce900SZi Xuan Wu Error CSKYAttributeParser::fpuDenormal(unsigned tag) {
116*21bce900SZi Xuan Wu static const char *strings[] = {"None", "Needed"};
117*21bce900SZi Xuan Wu return parseStringAttribute("Tag_CSKY_FPU_DENORMAL", tag,
118*21bce900SZi Xuan Wu makeArrayRef(strings));
119*21bce900SZi Xuan Wu }
120*21bce900SZi Xuan Wu
fpuException(unsigned tag)121*21bce900SZi Xuan Wu Error CSKYAttributeParser::fpuException(unsigned tag) {
122*21bce900SZi Xuan Wu static const char *strings[] = {"None", "Needed"};
123*21bce900SZi Xuan Wu return parseStringAttribute("Tag_CSKY_FPU_EXCEPTION", tag,
124*21bce900SZi Xuan Wu makeArrayRef(strings));
125*21bce900SZi Xuan Wu }
126*21bce900SZi Xuan Wu
fpuHardFP(unsigned tag)127*21bce900SZi Xuan Wu Error CSKYAttributeParser::fpuHardFP(unsigned tag) {
128*21bce900SZi Xuan Wu uint64_t value = de.getULEB128(cursor);
129*21bce900SZi Xuan Wu ListSeparator LS(" ");
130*21bce900SZi Xuan Wu
131*21bce900SZi Xuan Wu std::string description;
132*21bce900SZi Xuan Wu
133*21bce900SZi Xuan Wu if (value & 0x1) {
134*21bce900SZi Xuan Wu description += LS;
135*21bce900SZi Xuan Wu description += "Half";
136*21bce900SZi Xuan Wu }
137*21bce900SZi Xuan Wu if ((value >> 1) & 0x1) {
138*21bce900SZi Xuan Wu description += LS;
139*21bce900SZi Xuan Wu description += "Single";
140*21bce900SZi Xuan Wu }
141*21bce900SZi Xuan Wu if ((value >> 2) & 0x1) {
142*21bce900SZi Xuan Wu description += LS;
143*21bce900SZi Xuan Wu description += "Double";
144*21bce900SZi Xuan Wu }
145*21bce900SZi Xuan Wu
146*21bce900SZi Xuan Wu if (description.empty()) {
147*21bce900SZi Xuan Wu printAttribute(tag, value, "");
148*21bce900SZi Xuan Wu return createStringError(errc::invalid_argument,
149*21bce900SZi Xuan Wu "unknown Tag_CSKY_FPU_HARDFP value: " +
150*21bce900SZi Xuan Wu Twine(value));
151*21bce900SZi Xuan Wu }
152*21bce900SZi Xuan Wu
153*21bce900SZi Xuan Wu printAttribute(tag, value, description);
154*21bce900SZi Xuan Wu return Error::success();
155*21bce900SZi Xuan Wu }
156