aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm14/lib/Support/MSP430AttributeParser.cpp
blob: a230a3a70adb6a7cca220293b6879ec692f216b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//===-- 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, makeArrayRef(StringVals));
}

Error MSP430AttributeParser::parseCodeModel(AttrType Tag) {
  static const char *StringVals[] = {"None", "Small", "Large"};
  return parseStringAttribute("Code Model", Tag, makeArrayRef(StringVals));
}

Error MSP430AttributeParser::parseDataModel(AttrType Tag) {
  static const char *StringVals[] = {"None", "Small", "Large", "Restricted"};
  return parseStringAttribute("Data Model", Tag, makeArrayRef(StringVals));
}

Error MSP430AttributeParser::parseEnumSize(AttrType Tag) {
  static const char *StringVals[] = {"None", "Small", "Integer", "Don't Care"};
  return parseStringAttribute("Enum Size", Tag, makeArrayRef(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();
}