MCSymbolWasm.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- MCSymbolWasm.h - ----------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_MC_MCSYMBOLWASM_H
  14. #define LLVM_MC_MCSYMBOLWASM_H
  15. #include "llvm/BinaryFormat/Wasm.h"
  16. #include "llvm/MC/MCSymbol.h"
  17. namespace llvm {
  18. class MCSymbolWasm : public MCSymbol {
  19. wasm::WasmSymbolType Type = wasm::WASM_SYMBOL_TYPE_DATA;
  20. bool IsWeak = false;
  21. bool IsHidden = false;
  22. bool IsComdat = false;
  23. mutable bool IsUsedInInitArray = false;
  24. mutable bool IsUsedInGOT = false;
  25. Optional<StringRef> ImportModule;
  26. Optional<StringRef> ImportName;
  27. Optional<StringRef> ExportName;
  28. wasm::WasmSignature *Signature = nullptr;
  29. Optional<wasm::WasmGlobalType> GlobalType;
  30. Optional<wasm::ValType> TableType;
  31. Optional<wasm::WasmEventType> EventType;
  32. /// An expression describing how to calculate the size of a symbol. If a
  33. /// symbol has no size this field will be NULL.
  34. const MCExpr *SymbolSize = nullptr;
  35. public:
  36. MCSymbolWasm(const StringMapEntry<bool> *Name, bool isTemporary)
  37. : MCSymbol(SymbolKindWasm, Name, isTemporary) {}
  38. static bool classof(const MCSymbol *S) { return S->isWasm(); }
  39. const MCExpr *getSize() const { return SymbolSize; }
  40. void setSize(const MCExpr *SS) { SymbolSize = SS; }
  41. bool isFunction() const { return Type == wasm::WASM_SYMBOL_TYPE_FUNCTION; }
  42. bool isData() const { return Type == wasm::WASM_SYMBOL_TYPE_DATA; }
  43. bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; }
  44. bool isTable() const { return Type == wasm::WASM_SYMBOL_TYPE_TABLE; }
  45. bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; }
  46. bool isEvent() const { return Type == wasm::WASM_SYMBOL_TYPE_EVENT; }
  47. wasm::WasmSymbolType getType() const { return Type; }
  48. void setType(wasm::WasmSymbolType type) { Type = type; }
  49. bool isExported() const {
  50. return getFlags() & wasm::WASM_SYMBOL_EXPORTED;
  51. }
  52. void setExported() const {
  53. modifyFlags(wasm::WASM_SYMBOL_EXPORTED, wasm::WASM_SYMBOL_EXPORTED);
  54. }
  55. bool isNoStrip() const {
  56. return getFlags() & wasm::WASM_SYMBOL_NO_STRIP;
  57. }
  58. void setNoStrip() const {
  59. modifyFlags(wasm::WASM_SYMBOL_NO_STRIP, wasm::WASM_SYMBOL_NO_STRIP);
  60. }
  61. bool isWeak() const { return IsWeak; }
  62. void setWeak(bool isWeak) { IsWeak = isWeak; }
  63. bool isHidden() const { return IsHidden; }
  64. void setHidden(bool isHidden) { IsHidden = isHidden; }
  65. bool isComdat() const { return IsComdat; }
  66. void setComdat(bool isComdat) { IsComdat = isComdat; }
  67. bool hasImportModule() const { return ImportModule.hasValue(); }
  68. StringRef getImportModule() const {
  69. if (ImportModule.hasValue())
  70. return ImportModule.getValue();
  71. // Use a default module name of "env" for now, for compatibility with
  72. // existing tools.
  73. // TODO(sbc): Find a way to specify a default value in the object format
  74. // without picking a hardcoded value like this.
  75. return "env";
  76. }
  77. void setImportModule(StringRef Name) { ImportModule = Name; }
  78. bool hasImportName() const { return ImportName.hasValue(); }
  79. StringRef getImportName() const {
  80. if (ImportName.hasValue())
  81. return ImportName.getValue();
  82. return getName();
  83. }
  84. void setImportName(StringRef Name) { ImportName = Name; }
  85. bool hasExportName() const { return ExportName.hasValue(); }
  86. StringRef getExportName() const { return ExportName.getValue(); }
  87. void setExportName(StringRef Name) { ExportName = Name; }
  88. bool isFunctionTable() const {
  89. return isTable() && hasTableType() &&
  90. getTableType() == wasm::ValType::FUNCREF;
  91. }
  92. void setFunctionTable() {
  93. setType(wasm::WASM_SYMBOL_TYPE_TABLE);
  94. setTableType(wasm::ValType::FUNCREF);
  95. }
  96. void setUsedInGOT() const { IsUsedInGOT = true; }
  97. bool isUsedInGOT() const { return IsUsedInGOT; }
  98. void setUsedInInitArray() const { IsUsedInInitArray = true; }
  99. bool isUsedInInitArray() const { return IsUsedInInitArray; }
  100. const wasm::WasmSignature *getSignature() const { return Signature; }
  101. void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
  102. const wasm::WasmGlobalType &getGlobalType() const {
  103. assert(GlobalType.hasValue());
  104. return GlobalType.getValue();
  105. }
  106. void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }
  107. bool hasTableType() const { return TableType.hasValue(); }
  108. wasm::ValType getTableType() const {
  109. assert(hasTableType());
  110. return TableType.getValue();
  111. }
  112. void setTableType(wasm::ValType TT) { TableType = TT; }
  113. const wasm::WasmEventType &getEventType() const {
  114. assert(EventType.hasValue());
  115. return EventType.getValue();
  116. }
  117. void setEventType(wasm::WasmEventType ET) { EventType = ET; }
  118. };
  119. } // end namespace llvm
  120. #endif // LLVM_MC_MCSYMBOLWASM_H
  121. #ifdef __GNUC__
  122. #pragma GCC diagnostic pop
  123. #endif