LLVM  14.0.0git
MSP430AttributeParser.cpp
Go to the documentation of this file.
1 //===-- MSP430AttributeParser.cpp - MSP430 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 
10 #include "llvm/ADT/StringExtras.h"
11 
12 using namespace llvm;
13 using namespace llvm::MSP430Attrs;
14 
15 constexpr std::array<MSP430AttributeParser::DisplayHandler, 4>
16  MSP430AttributeParser::DisplayRoutines{
17  {{MSP430Attrs::TagISA, &MSP430AttributeParser::parseISA},
18  {MSP430Attrs::TagCodeModel, &MSP430AttributeParser::parseCodeModel},
19  {MSP430Attrs::TagDataModel, &MSP430AttributeParser::parseDataModel},
20  {MSP430Attrs::TagEnumSize, &MSP430AttributeParser::parseEnumSize}}};
21 
22 Error MSP430AttributeParser::parseISA(AttrType Tag) {
23  static const char *StringVals[] = {"None", "MSP430", "MSP430X"};
24  return parseStringAttribute("ISA", Tag, makeArrayRef(StringVals));
25 }
26 
27 Error MSP430AttributeParser::parseCodeModel(AttrType Tag) {
28  static const char *StringVals[] = {"None", "Small", "Large"};
29  return parseStringAttribute("Code Model", Tag, makeArrayRef(StringVals));
30 }
31 
32 Error MSP430AttributeParser::parseDataModel(AttrType Tag) {
33  static const char *StringVals[] = {"None", "Small", "Large", "Restricted"};
34  return parseStringAttribute("Data Model", Tag, makeArrayRef(StringVals));
35 }
36 
37 Error MSP430AttributeParser::parseEnumSize(AttrType Tag) {
38  static const char *StringVals[] = {"None", "Small", "Integer", "Don't Care"};
39  return parseStringAttribute("Enum Size", Tag, makeArrayRef(StringVals));
40 }
41 
42 Error MSP430AttributeParser::handler(uint64_t Tag, bool &Handled) {
43  Handled = false;
44  for (const DisplayHandler &Disp : DisplayRoutines) {
45  if (uint64_t(Disp.Attribute) != Tag)
46  continue;
47  if (Error E = (this->*Disp.Routine)(static_cast<AttrType>(Tag)))
48  return E;
49  Handled = true;
50  break;
51  }
52  return Error::success();
53 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MSP430Attrs::TagISA
@ TagISA
Definition: MSP430Attributes.h:30
llvm::MSP430Attrs
Definition: MSP430Attributes.h:24
llvm::MSP430Attrs::AttrType
AttrType
Definition: MSP430Attributes.h:28
llvm::MSP430Attrs::TagEnumSize
@ TagEnumSize
Definition: MSP430Attributes.h:33
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
MSP430AttributeParser.h
uint64_t
StringExtras.h
llvm::MSP430Attrs::TagDataModel
@ TagDataModel
Definition: MSP430Attributes.h:32
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:474
llvm::MSP430Attrs::TagCodeModel
@ TagCodeModel
Definition: MSP430Attributes.h:31