38818b60c5
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
149 lines
4.4 KiB
C++
149 lines
4.4 KiB
C++
//===-- CSKYAttributeParser.cpp - CSKY Attribute Parser -----------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Support/CSKYAttributeParser.h"
|
|
#include "llvm/ADT/StringExtras.h"
|
|
#include "llvm/Support/Errc.h"
|
|
|
|
using namespace llvm;
|
|
|
|
const CSKYAttributeParser::DisplayHandler
|
|
CSKYAttributeParser::displayRoutines[] = {
|
|
{
|
|
CSKYAttrs::CSKY_ARCH_NAME,
|
|
&ELFAttributeParser::stringAttribute,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_CPU_NAME,
|
|
&ELFAttributeParser::stringAttribute,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_ISA_FLAGS,
|
|
&ELFAttributeParser::integerAttribute,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_ISA_EXT_FLAGS,
|
|
&ELFAttributeParser::integerAttribute,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_DSP_VERSION,
|
|
&CSKYAttributeParser::dspVersion,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_VDSP_VERSION,
|
|
&CSKYAttributeParser::vdspVersion,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_FPU_VERSION,
|
|
&CSKYAttributeParser::fpuVersion,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_FPU_ABI,
|
|
&CSKYAttributeParser::fpuABI,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_FPU_ROUNDING,
|
|
&CSKYAttributeParser::fpuRounding,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_FPU_DENORMAL,
|
|
&CSKYAttributeParser::fpuDenormal,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_FPU_EXCEPTION,
|
|
&CSKYAttributeParser::fpuException,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_FPU_NUMBER_MODULE,
|
|
&ELFAttributeParser::stringAttribute,
|
|
},
|
|
{
|
|
CSKYAttrs::CSKY_FPU_HARDFP,
|
|
&CSKYAttributeParser::fpuHardFP,
|
|
}};
|
|
|
|
Error CSKYAttributeParser::handler(uint64_t tag, bool &handled) {
|
|
handled = false;
|
|
for (const auto &AH : displayRoutines) {
|
|
if (uint64_t(AH.attribute) == tag) {
|
|
if (Error e = (this->*AH.routine)(tag))
|
|
return e;
|
|
handled = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return Error::success();
|
|
}
|
|
|
|
Error CSKYAttributeParser::dspVersion(unsigned tag) {
|
|
static const char *strings[] = {"Error", "DSP Extension", "DSP 2.0"};
|
|
return parseStringAttribute("Tag_CSKY_DSP_VERSION", tag, ArrayRef(strings));
|
|
}
|
|
|
|
Error CSKYAttributeParser::vdspVersion(unsigned tag) {
|
|
static const char *strings[] = {"Error", "VDSP Version 1", "VDSP Version 2"};
|
|
return parseStringAttribute("Tag_CSKY_VDSP_VERSION", tag, ArrayRef(strings));
|
|
}
|
|
|
|
Error CSKYAttributeParser::fpuVersion(unsigned tag) {
|
|
static const char *strings[] = {"Error", "FPU Version 1", "FPU Version 2",
|
|
"FPU Version 3"};
|
|
return parseStringAttribute("Tag_CSKY_FPU_VERSION", tag, ArrayRef(strings));
|
|
}
|
|
|
|
Error CSKYAttributeParser::fpuABI(unsigned tag) {
|
|
static const char *strings[] = {"Error", "Soft", "SoftFP", "Hard"};
|
|
return parseStringAttribute("Tag_CSKY_FPU_ABI", tag, ArrayRef(strings));
|
|
}
|
|
|
|
Error CSKYAttributeParser::fpuRounding(unsigned tag) {
|
|
static const char *strings[] = {"None", "Needed"};
|
|
return parseStringAttribute("Tag_CSKY_FPU_ROUNDING", tag, ArrayRef(strings));
|
|
}
|
|
|
|
Error CSKYAttributeParser::fpuDenormal(unsigned tag) {
|
|
static const char *strings[] = {"None", "Needed"};
|
|
return parseStringAttribute("Tag_CSKY_FPU_DENORMAL", tag, ArrayRef(strings));
|
|
}
|
|
|
|
Error CSKYAttributeParser::fpuException(unsigned tag) {
|
|
static const char *strings[] = {"None", "Needed"};
|
|
return parseStringAttribute("Tag_CSKY_FPU_EXCEPTION", tag, ArrayRef(strings));
|
|
}
|
|
|
|
Error CSKYAttributeParser::fpuHardFP(unsigned tag) {
|
|
uint64_t value = de.getULEB128(cursor);
|
|
ListSeparator LS(" ");
|
|
|
|
std::string description;
|
|
|
|
if (value & 0x1) {
|
|
description += LS;
|
|
description += "Half";
|
|
}
|
|
if ((value >> 1) & 0x1) {
|
|
description += LS;
|
|
description += "Single";
|
|
}
|
|
if ((value >> 2) & 0x1) {
|
|
description += LS;
|
|
description += "Double";
|
|
}
|
|
|
|
if (description.empty()) {
|
|
printAttribute(tag, value, "");
|
|
return createStringError(errc::invalid_argument,
|
|
"unknown Tag_CSKY_FPU_HARDFP value: " +
|
|
Twine(value));
|
|
}
|
|
|
|
printAttribute(tag, value, description);
|
|
return Error::success();
|
|
}
|