RISCVAttributeParser.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //===-- RISCVAttributeParser.cpp - RISCV 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/RISCVAttributeParser.h"
  9. #include "llvm/ADT/StringExtras.h"
  10. using namespace llvm;
  11. const RISCVAttributeParser::DisplayHandler
  12. RISCVAttributeParser::displayRoutines[] = {
  13. {
  14. RISCVAttrs::ARCH,
  15. &ELFAttributeParser::stringAttribute,
  16. },
  17. {
  18. RISCVAttrs::PRIV_SPEC,
  19. &ELFAttributeParser::integerAttribute,
  20. },
  21. {
  22. RISCVAttrs::PRIV_SPEC_MINOR,
  23. &ELFAttributeParser::integerAttribute,
  24. },
  25. {
  26. RISCVAttrs::PRIV_SPEC_REVISION,
  27. &ELFAttributeParser::integerAttribute,
  28. },
  29. {
  30. RISCVAttrs::STACK_ALIGN,
  31. &RISCVAttributeParser::stackAlign,
  32. },
  33. {
  34. RISCVAttrs::UNALIGNED_ACCESS,
  35. &RISCVAttributeParser::unalignedAccess,
  36. }};
  37. Error RISCVAttributeParser::unalignedAccess(unsigned tag) {
  38. static const char *strings[] = {"No unaligned access", "Unaligned access"};
  39. return parseStringAttribute("Unaligned_access", tag, makeArrayRef(strings));
  40. }
  41. Error RISCVAttributeParser::stackAlign(unsigned tag) {
  42. uint64_t value = de.getULEB128(cursor);
  43. std::string description =
  44. "Stack alignment is " + utostr(value) + std::string("-bytes");
  45. printAttribute(tag, value, description);
  46. return Error::success();
  47. }
  48. Error RISCVAttributeParser::handler(uint64_t tag, bool &handled) {
  49. handled = false;
  50. for (unsigned AHI = 0, AHE = array_lengthof(displayRoutines); AHI != AHE;
  51. ++AHI) {
  52. if (uint64_t(displayRoutines[AHI].attribute) == tag) {
  53. if (Error e = (this->*displayRoutines[AHI].routine)(tag))
  54. return e;
  55. handled = true;
  56. break;
  57. }
  58. }
  59. return Error::success();
  60. }