CSKYAttributeParser.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //===-- CSKYAttributeParser.cpp - CSKY 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/CSKYAttributeParser.h"
  9. #include "llvm/ADT/StringExtras.h"
  10. #include "llvm/Support/Errc.h"
  11. using namespace llvm;
  12. const CSKYAttributeParser::DisplayHandler
  13. CSKYAttributeParser::displayRoutines[] = {
  14. {
  15. CSKYAttrs::CSKY_ARCH_NAME,
  16. &ELFAttributeParser::stringAttribute,
  17. },
  18. {
  19. CSKYAttrs::CSKY_CPU_NAME,
  20. &ELFAttributeParser::stringAttribute,
  21. },
  22. {
  23. CSKYAttrs::CSKY_ISA_FLAGS,
  24. &ELFAttributeParser::integerAttribute,
  25. },
  26. {
  27. CSKYAttrs::CSKY_ISA_EXT_FLAGS,
  28. &ELFAttributeParser::integerAttribute,
  29. },
  30. {
  31. CSKYAttrs::CSKY_DSP_VERSION,
  32. &CSKYAttributeParser::dspVersion,
  33. },
  34. {
  35. CSKYAttrs::CSKY_VDSP_VERSION,
  36. &CSKYAttributeParser::vdspVersion,
  37. },
  38. {
  39. CSKYAttrs::CSKY_FPU_VERSION,
  40. &CSKYAttributeParser::fpuVersion,
  41. },
  42. {
  43. CSKYAttrs::CSKY_FPU_ABI,
  44. &CSKYAttributeParser::fpuABI,
  45. },
  46. {
  47. CSKYAttrs::CSKY_FPU_ROUNDING,
  48. &CSKYAttributeParser::fpuRounding,
  49. },
  50. {
  51. CSKYAttrs::CSKY_FPU_DENORMAL,
  52. &CSKYAttributeParser::fpuDenormal,
  53. },
  54. {
  55. CSKYAttrs::CSKY_FPU_EXCEPTION,
  56. &CSKYAttributeParser::fpuException,
  57. },
  58. {
  59. CSKYAttrs::CSKY_FPU_NUMBER_MODULE,
  60. &ELFAttributeParser::stringAttribute,
  61. },
  62. {
  63. CSKYAttrs::CSKY_FPU_HARDFP,
  64. &CSKYAttributeParser::fpuHardFP,
  65. }};
  66. Error CSKYAttributeParser::handler(uint64_t tag, bool &handled) {
  67. handled = false;
  68. for (const auto &AH : displayRoutines) {
  69. if (uint64_t(AH.attribute) == tag) {
  70. if (Error e = (this->*AH.routine)(tag))
  71. return e;
  72. handled = true;
  73. break;
  74. }
  75. }
  76. return Error::success();
  77. }
  78. Error CSKYAttributeParser::dspVersion(unsigned tag) {
  79. static const char *strings[] = {"Error", "DSP Extension", "DSP 2.0"};
  80. return parseStringAttribute("Tag_CSKY_DSP_VERSION", tag, ArrayRef(strings));
  81. }
  82. Error CSKYAttributeParser::vdspVersion(unsigned tag) {
  83. static const char *strings[] = {"Error", "VDSP Version 1", "VDSP Version 2"};
  84. return parseStringAttribute("Tag_CSKY_VDSP_VERSION", tag, ArrayRef(strings));
  85. }
  86. Error CSKYAttributeParser::fpuVersion(unsigned tag) {
  87. static const char *strings[] = {"Error", "FPU Version 1", "FPU Version 2",
  88. "FPU Version 3"};
  89. return parseStringAttribute("Tag_CSKY_FPU_VERSION", tag, ArrayRef(strings));
  90. }
  91. Error CSKYAttributeParser::fpuABI(unsigned tag) {
  92. static const char *strings[] = {"Error", "Soft", "SoftFP", "Hard"};
  93. return parseStringAttribute("Tag_CSKY_FPU_ABI", tag, ArrayRef(strings));
  94. }
  95. Error CSKYAttributeParser::fpuRounding(unsigned tag) {
  96. static const char *strings[] = {"None", "Needed"};
  97. return parseStringAttribute("Tag_CSKY_FPU_ROUNDING", tag, ArrayRef(strings));
  98. }
  99. Error CSKYAttributeParser::fpuDenormal(unsigned tag) {
  100. static const char *strings[] = {"None", "Needed"};
  101. return parseStringAttribute("Tag_CSKY_FPU_DENORMAL", tag, ArrayRef(strings));
  102. }
  103. Error CSKYAttributeParser::fpuException(unsigned tag) {
  104. static const char *strings[] = {"None", "Needed"};
  105. return parseStringAttribute("Tag_CSKY_FPU_EXCEPTION", tag, ArrayRef(strings));
  106. }
  107. Error CSKYAttributeParser::fpuHardFP(unsigned tag) {
  108. uint64_t value = de.getULEB128(cursor);
  109. ListSeparator LS(" ");
  110. std::string description;
  111. if (value & 0x1) {
  112. description += LS;
  113. description += "Half";
  114. }
  115. if ((value >> 1) & 0x1) {
  116. description += LS;
  117. description += "Single";
  118. }
  119. if ((value >> 2) & 0x1) {
  120. description += LS;
  121. description += "Double";
  122. }
  123. if (description.empty()) {
  124. printAttribute(tag, value, "");
  125. return createStringError(errc::invalid_argument,
  126. "unknown Tag_CSKY_FPU_HARDFP value: " +
  127. Twine(value));
  128. }
  129. printAttribute(tag, value, description);
  130. return Error::success();
  131. }