Wasm.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //===-- llvm/BinaryFormat/Wasm.cpp -------------------------------*- C++-*-===//
  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/BinaryFormat/Wasm.h"
  9. llvm::StringRef llvm::wasm::toString(wasm::WasmSymbolType Type) {
  10. switch (Type) {
  11. case wasm::WASM_SYMBOL_TYPE_FUNCTION:
  12. return "WASM_SYMBOL_TYPE_FUNCTION";
  13. case wasm::WASM_SYMBOL_TYPE_GLOBAL:
  14. return "WASM_SYMBOL_TYPE_GLOBAL";
  15. case wasm::WASM_SYMBOL_TYPE_TABLE:
  16. return "WASM_SYMBOL_TYPE_TABLE";
  17. case wasm::WASM_SYMBOL_TYPE_DATA:
  18. return "WASM_SYMBOL_TYPE_DATA";
  19. case wasm::WASM_SYMBOL_TYPE_SECTION:
  20. return "WASM_SYMBOL_TYPE_SECTION";
  21. case wasm::WASM_SYMBOL_TYPE_TAG:
  22. return "WASM_SYMBOL_TYPE_TAG";
  23. }
  24. llvm_unreachable("unknown symbol type");
  25. }
  26. llvm::StringRef llvm::wasm::relocTypetoString(uint32_t Type) {
  27. switch (Type) {
  28. #define WASM_RELOC(NAME, VALUE) \
  29. case VALUE: \
  30. return #NAME;
  31. #include "llvm/BinaryFormat/WasmRelocs.def"
  32. #undef WASM_RELOC
  33. default:
  34. llvm_unreachable("unknown reloc type");
  35. }
  36. }
  37. llvm::StringRef llvm::wasm::sectionTypeToString(uint32_t Type) {
  38. #define ECase(X) \
  39. case wasm::WASM_SEC_##X: \
  40. return #X;
  41. switch (Type) {
  42. ECase(CUSTOM);
  43. ECase(TYPE);
  44. ECase(IMPORT);
  45. ECase(FUNCTION);
  46. ECase(TABLE);
  47. ECase(MEMORY);
  48. ECase(GLOBAL);
  49. ECase(EXPORT);
  50. ECase(START);
  51. ECase(ELEM);
  52. ECase(CODE);
  53. ECase(DATA);
  54. ECase(DATACOUNT);
  55. ECase(TAG);
  56. default:
  57. llvm_unreachable("unknown section type");
  58. }
  59. #undef ECase
  60. }
  61. bool llvm::wasm::relocTypeHasAddend(uint32_t Type) {
  62. switch (Type) {
  63. case R_WASM_MEMORY_ADDR_LEB:
  64. case R_WASM_MEMORY_ADDR_LEB64:
  65. case R_WASM_MEMORY_ADDR_SLEB:
  66. case R_WASM_MEMORY_ADDR_SLEB64:
  67. case R_WASM_MEMORY_ADDR_REL_SLEB:
  68. case R_WASM_MEMORY_ADDR_REL_SLEB64:
  69. case R_WASM_MEMORY_ADDR_I32:
  70. case R_WASM_MEMORY_ADDR_I64:
  71. case R_WASM_MEMORY_ADDR_TLS_SLEB:
  72. case R_WASM_MEMORY_ADDR_TLS_SLEB64:
  73. case R_WASM_FUNCTION_OFFSET_I32:
  74. case R_WASM_FUNCTION_OFFSET_I64:
  75. case R_WASM_SECTION_OFFSET_I32:
  76. case R_WASM_MEMORY_ADDR_LOCREL_I32:
  77. return true;
  78. default:
  79. return false;
  80. }
  81. }