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 | |
9 | #include "llvm/Support/MSP430AttributeParser.h" |
10 | #include "llvm/ADT/ArrayRef.h" |
11 | #include "llvm/Support/ErrorHandling.h" |
12 | |
13 | using namespace llvm; |
14 | using namespace llvm::MSP430Attrs; |
15 | |
16 | constexpr std::array<MSP430AttributeParser::DisplayHandler, 4> |
17 | MSP430AttributeParser::DisplayRoutines{ |
18 | ._M_elems: {{.Attribute: MSP430Attrs::TagISA, .Routine: &MSP430AttributeParser::parseISA}, |
19 | {.Attribute: MSP430Attrs::TagCodeModel, .Routine: &MSP430AttributeParser::parseCodeModel}, |
20 | {.Attribute: MSP430Attrs::TagDataModel, .Routine: &MSP430AttributeParser::parseDataModel}, |
21 | {.Attribute: MSP430Attrs::TagEnumSize, .Routine: &MSP430AttributeParser::parseEnumSize}}}; |
22 | |
23 | Error MSP430AttributeParser::parseISA(AttrType Tag) { |
24 | static const char *StringVals[] = {"None" , "MSP430" , "MSP430X" }; |
25 | return parseStringAttribute(name: "ISA" , tag: Tag, strings: ArrayRef(StringVals)); |
26 | } |
27 | |
28 | Error MSP430AttributeParser::parseCodeModel(AttrType Tag) { |
29 | static const char *StringVals[] = {"None" , "Small" , "Large" }; |
30 | return parseStringAttribute(name: "Code Model" , tag: Tag, strings: ArrayRef(StringVals)); |
31 | } |
32 | |
33 | Error MSP430AttributeParser::parseDataModel(AttrType Tag) { |
34 | static const char *StringVals[] = {"None" , "Small" , "Large" , "Restricted" }; |
35 | return parseStringAttribute(name: "Data Model" , tag: Tag, strings: ArrayRef(StringVals)); |
36 | } |
37 | |
38 | Error MSP430AttributeParser::parseEnumSize(AttrType Tag) { |
39 | static const char *StringVals[] = {"None" , "Small" , "Integer" , "Don't Care" }; |
40 | return parseStringAttribute(name: "Enum Size" , tag: Tag, strings: ArrayRef(StringVals)); |
41 | } |
42 | |
43 | Error MSP430AttributeParser::handler(uint64_t Tag, bool &Handled) { |
44 | Handled = false; |
45 | for (const DisplayHandler &Disp : DisplayRoutines) { |
46 | if (uint64_t(Disp.Attribute) != Tag) |
47 | continue; |
48 | if (Error E = (this->*Disp.Routine)(static_cast<AttrType>(Tag))) |
49 | return E; |
50 | Handled = true; |
51 | break; |
52 | } |
53 | return Error::success(); |
54 | } |
55 | |