LLVM 20.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/ArrayRef.h"
12
13using namespace llvm;
14using namespace llvm::MSP430Attrs;
15
16constexpr std::array<MSP430AttributeParser::DisplayHandler, 4>
17 MSP430AttributeParser::DisplayRoutines{
18 {{MSP430Attrs::TagISA, &MSP430AttributeParser::parseISA},
19 {MSP430Attrs::TagCodeModel, &MSP430AttributeParser::parseCodeModel},
20 {MSP430Attrs::TagDataModel, &MSP430AttributeParser::parseDataModel},
21 {MSP430Attrs::TagEnumSize, &MSP430AttributeParser::parseEnumSize}}};
22
23Error MSP430AttributeParser::parseISA(AttrType Tag) {
24 static const char *const StringVals[] = {"None", "MSP430", "MSP430X"};
25 return parseStringAttribute("ISA", Tag, ArrayRef(StringVals));
26}
27
28Error MSP430AttributeParser::parseCodeModel(AttrType Tag) {
29 static const char *const StringVals[] = {"None", "Small", "Large"};
30 return parseStringAttribute("Code Model", Tag, ArrayRef(StringVals));
31}
32
33Error MSP430AttributeParser::parseDataModel(AttrType Tag) {
34 static const char *const StringVals[] = {"None", "Small", "Large",
35 "Restricted"};
36 return parseStringAttribute("Data Model", Tag, ArrayRef(StringVals));
37}
38
39Error MSP430AttributeParser::parseEnumSize(AttrType Tag) {
40 static const char *const StringVals[] = {"None", "Small", "Integer",
41 "Don't Care"};
42 return parseStringAttribute("Enum Size", Tag, ArrayRef(StringVals));
43}
44
45Error MSP430AttributeParser::handler(uint64_t Tag, bool &Handled) {
46 Handled = false;
47 for (const DisplayHandler &Disp : DisplayRoutines) {
48 if (uint64_t(Disp.Attribute) != Tag)
49 continue;
50 if (Error E = (this->*Disp.Routine)(static_cast<AttrType>(Tag)))
51 return E;
52 Handled = true;
53 break;
54 }
55 return Error::success();
56}
This file contains support routines for parsing MSP430 ELF build attributes.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Error parseStringAttribute(const char *name, unsigned tag, ArrayRef< const char * > strings)
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18