RISCVAttributeParser.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, ArrayRef(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 (const auto &AH : displayRoutines) {
  51. if (uint64_t(AH.attribute) == tag) {
  52. if (Error e = (this->*AH.routine)(tag))
  53. return e;
  54. handled = true;
  55. break;
  56. }
  57. }
  58. return Error::success();
  59. }