mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 22:06:06 +00:00

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
55 lines
2.1 KiB
C++
55 lines
2.1 KiB
C++
//===-- MSP430AttributeParser.cpp - MSP430 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/MSP430AttributeParser.h"
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::MSP430Attrs;
|
|
|
|
constexpr std::array<MSP430AttributeParser::DisplayHandler, 4>
|
|
MSP430AttributeParser::DisplayRoutines{
|
|
{{MSP430Attrs::TagISA, &MSP430AttributeParser::parseISA},
|
|
{MSP430Attrs::TagCodeModel, &MSP430AttributeParser::parseCodeModel},
|
|
{MSP430Attrs::TagDataModel, &MSP430AttributeParser::parseDataModel},
|
|
{MSP430Attrs::TagEnumSize, &MSP430AttributeParser::parseEnumSize}}};
|
|
|
|
Error MSP430AttributeParser::parseISA(AttrType Tag) {
|
|
static const char *StringVals[] = {"None", "MSP430", "MSP430X"};
|
|
return parseStringAttribute("ISA", Tag, ArrayRef(StringVals));
|
|
}
|
|
|
|
Error MSP430AttributeParser::parseCodeModel(AttrType Tag) {
|
|
static const char *StringVals[] = {"None", "Small", "Large"};
|
|
return parseStringAttribute("Code Model", Tag, ArrayRef(StringVals));
|
|
}
|
|
|
|
Error MSP430AttributeParser::parseDataModel(AttrType Tag) {
|
|
static const char *StringVals[] = {"None", "Small", "Large", "Restricted"};
|
|
return parseStringAttribute("Data Model", Tag, ArrayRef(StringVals));
|
|
}
|
|
|
|
Error MSP430AttributeParser::parseEnumSize(AttrType Tag) {
|
|
static const char *StringVals[] = {"None", "Small", "Integer", "Don't Care"};
|
|
return parseStringAttribute("Enum Size", Tag, ArrayRef(StringVals));
|
|
}
|
|
|
|
Error MSP430AttributeParser::handler(uint64_t Tag, bool &Handled) {
|
|
Handled = false;
|
|
for (const DisplayHandler &Disp : DisplayRoutines) {
|
|
if (uint64_t(Disp.Attribute) != Tag)
|
|
continue;
|
|
if (Error E = (this->*Disp.Routine)(static_cast<AttrType>(Tag)))
|
|
return E;
|
|
Handled = true;
|
|
break;
|
|
}
|
|
return Error::success();
|
|
}
|