File indexing completed on 2026-05-10 08:44:15
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef LLVM_MC_MCSYMBOLWASM_H
0009 #define LLVM_MC_MCSYMBOLWASM_H
0010
0011 #include "llvm/BinaryFormat/Wasm.h"
0012 #include "llvm/MC/MCSymbol.h"
0013 #include "llvm/MC/MCSymbolTableEntry.h"
0014
0015 namespace llvm {
0016
0017 class MCSymbolWasm : public MCSymbol {
0018 std::optional<wasm::WasmSymbolType> Type;
0019 bool IsWeak = false;
0020 bool IsHidden = false;
0021 bool IsComdat = false;
0022 bool OmitFromLinkingSection = false;
0023 mutable bool IsUsedInInitArray = false;
0024 mutable bool IsUsedInGOT = false;
0025 std::optional<StringRef> ImportModule;
0026 std::optional<StringRef> ImportName;
0027 std::optional<StringRef> ExportName;
0028 wasm::WasmSignature *Signature = nullptr;
0029 std::optional<wasm::WasmGlobalType> GlobalType;
0030 std::optional<wasm::WasmTableType> TableType;
0031
0032
0033
0034 const MCExpr *SymbolSize = nullptr;
0035
0036 public:
0037 MCSymbolWasm(const MCSymbolTableEntry *Name, bool isTemporary)
0038 : MCSymbol(SymbolKindWasm, Name, isTemporary) {}
0039 static bool classof(const MCSymbol *S) { return S->isWasm(); }
0040
0041 const MCExpr *getSize() const { return SymbolSize; }
0042 void setSize(const MCExpr *SS) { SymbolSize = SS; }
0043
0044 bool isFunction() const { return Type == wasm::WASM_SYMBOL_TYPE_FUNCTION; }
0045
0046 bool isData() const { return !Type || Type == wasm::WASM_SYMBOL_TYPE_DATA; }
0047 bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; }
0048 bool isTable() const { return Type == wasm::WASM_SYMBOL_TYPE_TABLE; }
0049 bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; }
0050 bool isTag() const { return Type == wasm::WASM_SYMBOL_TYPE_TAG; }
0051
0052 std::optional<wasm::WasmSymbolType> getType() const { return Type; }
0053
0054 void setType(wasm::WasmSymbolType type) { Type = type; }
0055
0056 bool isExported() const {
0057 return getFlags() & wasm::WASM_SYMBOL_EXPORTED;
0058 }
0059 void setExported() const {
0060 modifyFlags(wasm::WASM_SYMBOL_EXPORTED, wasm::WASM_SYMBOL_EXPORTED);
0061 }
0062
0063 bool isNoStrip() const {
0064 return getFlags() & wasm::WASM_SYMBOL_NO_STRIP;
0065 }
0066 void setNoStrip() const {
0067 modifyFlags(wasm::WASM_SYMBOL_NO_STRIP, wasm::WASM_SYMBOL_NO_STRIP);
0068 }
0069
0070 bool isTLS() const { return getFlags() & wasm::WASM_SYMBOL_TLS; }
0071 void setTLS() const {
0072 modifyFlags(wasm::WASM_SYMBOL_TLS, wasm::WASM_SYMBOL_TLS);
0073 }
0074
0075 bool isWeak() const { return IsWeak; }
0076 void setWeak(bool isWeak) { IsWeak = isWeak; }
0077
0078 bool isHidden() const { return IsHidden; }
0079 void setHidden(bool isHidden) { IsHidden = isHidden; }
0080
0081 bool isComdat() const { return IsComdat; }
0082 void setComdat(bool isComdat) { IsComdat = isComdat; }
0083
0084
0085
0086
0087 bool omitFromLinkingSection() const { return OmitFromLinkingSection; }
0088 void setOmitFromLinkingSection() { OmitFromLinkingSection = true; }
0089
0090 bool hasImportModule() const { return ImportModule.has_value(); }
0091 StringRef getImportModule() const {
0092 if (ImportModule)
0093 return *ImportModule;
0094
0095
0096
0097
0098 return "env";
0099 }
0100 void setImportModule(StringRef Name) { ImportModule = Name; }
0101
0102 bool hasImportName() const { return ImportName.has_value(); }
0103 StringRef getImportName() const {
0104 if (ImportName)
0105 return *ImportName;
0106 return getName();
0107 }
0108 void setImportName(StringRef Name) { ImportName = Name; }
0109
0110 bool hasExportName() const { return ExportName.has_value(); }
0111 StringRef getExportName() const { return *ExportName; }
0112 void setExportName(StringRef Name) { ExportName = Name; }
0113
0114 bool isFunctionTable() const {
0115 return isTable() && hasTableType() &&
0116 getTableType().ElemType == wasm::ValType::FUNCREF;
0117 }
0118 void setFunctionTable(bool is64) {
0119 setType(wasm::WASM_SYMBOL_TYPE_TABLE);
0120 uint8_t flags =
0121 is64 ? wasm::WASM_LIMITS_FLAG_IS_64 : wasm::WASM_LIMITS_FLAG_NONE;
0122 setTableType(wasm::ValType::FUNCREF, flags);
0123 }
0124
0125 void setUsedInGOT() const { IsUsedInGOT = true; }
0126 bool isUsedInGOT() const { return IsUsedInGOT; }
0127
0128 void setUsedInInitArray() const { IsUsedInInitArray = true; }
0129 bool isUsedInInitArray() const { return IsUsedInInitArray; }
0130
0131 const wasm::WasmSignature *getSignature() const { return Signature; }
0132 void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
0133
0134 const wasm::WasmGlobalType &getGlobalType() const {
0135 assert(GlobalType);
0136 return *GlobalType;
0137 }
0138 void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }
0139
0140 bool hasTableType() const { return TableType.has_value(); }
0141 const wasm::WasmTableType &getTableType() const {
0142 assert(hasTableType());
0143 return *TableType;
0144 }
0145 void setTableType(wasm::WasmTableType TT) { TableType = TT; }
0146 void setTableType(wasm::ValType VT,
0147 uint8_t flags = wasm::WASM_LIMITS_FLAG_NONE) {
0148
0149
0150 wasm::WasmLimits Limits = {flags, 0, 0};
0151 setTableType({VT, Limits});
0152 }
0153 };
0154
0155 }
0156
0157 #endif