MSP430AttributeParser.cpp 2.1 KB

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