LLVM 20.0.0git
CSKYAttributeParser.cpp
Go to the documentation of this file.
1//===-- CSKYAttributeParser.cpp - CSKY 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
11#include "llvm/Support/Errc.h"
12
13using namespace llvm;
14
15const CSKYAttributeParser::DisplayHandler
16 CSKYAttributeParser::displayRoutines[] = {
17 {
20 },
21 {
24 },
25 {
28 },
29 {
32 },
33 {
35 &CSKYAttributeParser::dspVersion,
36 },
37 {
39 &CSKYAttributeParser::vdspVersion,
40 },
41 {
43 &CSKYAttributeParser::fpuVersion,
44 },
45 {
47 &CSKYAttributeParser::fpuABI,
48 },
49 {
51 &CSKYAttributeParser::fpuRounding,
52 },
53 {
55 &CSKYAttributeParser::fpuDenormal,
56 },
57 {
59 &CSKYAttributeParser::fpuException,
60 },
61 {
64 },
65 {
67 &CSKYAttributeParser::fpuHardFP,
68 }};
69
70Error CSKYAttributeParser::handler(uint64_t tag, bool &handled) {
71 handled = false;
72 for (const auto &AH : displayRoutines) {
73 if (uint64_t(AH.attribute) == tag) {
74 if (Error e = (this->*AH.routine)(tag))
75 return e;
76 handled = true;
77 break;
78 }
79 }
80
81 return Error::success();
82}
83
84Error 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));
87}
88
89Error CSKYAttributeParser::vdspVersion(unsigned tag) {
90 static const char *const strings[] = {"Error", "VDSP Version 1",
91 "VDSP Version 2"};
92 return parseStringAttribute("Tag_CSKY_VDSP_VERSION", tag, ArrayRef(strings));
93}
94
95Error 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));
99}
100
101Error CSKYAttributeParser::fpuABI(unsigned tag) {
102 static const char *const strings[] = {"Error", "Soft", "SoftFP", "Hard"};
103 return parseStringAttribute("Tag_CSKY_FPU_ABI", tag, ArrayRef(strings));
104}
105
106Error CSKYAttributeParser::fpuRounding(unsigned tag) {
107 static const char *const strings[] = {"None", "Needed"};
108 return parseStringAttribute("Tag_CSKY_FPU_ROUNDING", tag, ArrayRef(strings));
109}
110
111Error CSKYAttributeParser::fpuDenormal(unsigned tag) {
112 static const char *const strings[] = {"None", "Needed"};
113 return parseStringAttribute("Tag_CSKY_FPU_DENORMAL", tag, ArrayRef(strings));
114}
115
116Error CSKYAttributeParser::fpuException(unsigned tag) {
117 static const char *const strings[] = {"None", "Needed"};
118 return parseStringAttribute("Tag_CSKY_FPU_EXCEPTION", tag, ArrayRef(strings));
119}
120
121Error CSKYAttributeParser::fpuHardFP(unsigned tag) {
123 ListSeparator LS(" ");
124
125 std::string description;
126
127 if (value & 0x1) {
128 description += LS;
129 description += "Half";
130 }
131 if ((value >> 1) & 0x1) {
132 description += LS;
133 description += "Single";
134 }
135 if ((value >> 2) & 0x1) {
136 description += LS;
137 description += "Double";
138 }
139
140 if (description.empty()) {
141 printAttribute(tag, value, "");
143 "unknown Tag_CSKY_FPU_HARDFP value: " +
144 Twine(value));
145 }
146
147 printAttribute(tag, value, description);
148 return Error::success();
149}
Given that RA is a live value
This file contains some functions that are useful when dealing with strings.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
uint64_t getULEB128(uint64_t *offset_ptr, llvm::Error *Err=nullptr) const
Extract a unsigned LEB128 value from *offset_ptr.
Error integerAttribute(unsigned tag)
DataExtractor::Cursor cursor
Error stringAttribute(unsigned tag)
Error parseStringAttribute(const char *name, unsigned tag, ArrayRef< const char * > strings)
void printAttribute(unsigned tag, unsigned value, StringRef valueDesc)
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
constexpr double e
Definition: MathExtras.h:47
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1286