1 //===- MCSymbolWasm.h - ----------------------------------------*- 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 #ifndef LLVM_MC_MCSYMBOLWASM_H 9 #define LLVM_MC_MCSYMBOLWASM_H 10 11 #include "llvm/BinaryFormat/Wasm.h" 12 #include "llvm/MC/MCSymbol.h" 13 14 namespace llvm { 15 16 class MCSymbolWasm : public MCSymbol { 17 wasm::WasmSymbolType Type = wasm::WASM_SYMBOL_TYPE_DATA; 18 bool IsWeak = false; 19 bool IsHidden = false; 20 bool IsComdat = false; 21 mutable bool IsUsedInGOT = false; 22 Optional<std::string> ImportModule; 23 Optional<std::string> ImportName; 24 Optional<std::string> ExportName; 25 wasm::WasmSignature *Signature = nullptr; 26 Optional<wasm::WasmGlobalType> GlobalType; 27 Optional<wasm::WasmEventType> EventType; 28 29 /// An expression describing how to calculate the size of a symbol. If a 30 /// symbol has no size this field will be NULL. 31 const MCExpr *SymbolSize = nullptr; 32 33 public: 34 // Use a module name of "env" for now, for compatibility with existing tools. 35 // This is temporary, and may change, as the ABI is not yet stable. 36 MCSymbolWasm(const StringMapEntry<bool> *Name, bool isTemporary) 37 : MCSymbol(SymbolKindWasm, Name, isTemporary) {} 38 static bool classof(const MCSymbol *S) { return S->isWasm(); } 39 40 const MCExpr *getSize() const { return SymbolSize; } 41 void setSize(const MCExpr *SS) { SymbolSize = SS; } 42 43 bool isFunction() const { return Type == wasm::WASM_SYMBOL_TYPE_FUNCTION; } 44 bool isData() const { return Type == wasm::WASM_SYMBOL_TYPE_DATA; } 45 bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; } 46 bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; } 47 bool isEvent() const { return Type == wasm::WASM_SYMBOL_TYPE_EVENT; } 48 wasm::WasmSymbolType getType() const { return Type; } 49 void setType(wasm::WasmSymbolType type) { Type = type; } 50 51 bool isExported() const { 52 return getFlags() & wasm::WASM_SYMBOL_EXPORTED; 53 } 54 void setExported() const { 55 modifyFlags(wasm::WASM_SYMBOL_EXPORTED, wasm::WASM_SYMBOL_EXPORTED); 56 } 57 58 bool isNoStrip() const { 59 return getFlags() & wasm::WASM_SYMBOL_NO_STRIP; 60 } 61 void setNoStrip() const { 62 modifyFlags(wasm::WASM_SYMBOL_NO_STRIP, wasm::WASM_SYMBOL_NO_STRIP); 63 } 64 65 bool isWeak() const { return IsWeak; } 66 void setWeak(bool isWeak) { IsWeak = isWeak; } 67 68 bool isHidden() const { return IsHidden; } 69 void setHidden(bool isHidden) { IsHidden = isHidden; } 70 71 bool isComdat() const { return IsComdat; } 72 void setComdat(bool isComdat) { IsComdat = isComdat; } 73 74 const StringRef getImportModule() const { 75 if (ImportModule.hasValue()) { 76 return ImportModule.getValue(); 77 } 78 return "env"; 79 } 80 void setImportModule(StringRef Name) { ImportModule = Name; } 81 82 bool hasImportName() const { return ImportName.hasValue(); } 83 const StringRef getImportName() const { 84 if (ImportName.hasValue()) { 85 return ImportName.getValue(); 86 } 87 return getName(); 88 } 89 void setImportName(StringRef Name) { ImportName = Name; } 90 91 bool hasExportName() const { return ExportName.hasValue(); } 92 const StringRef getExportName() const { return ExportName.getValue(); } 93 void setExportName(StringRef Name) { ExportName = Name; } 94 95 void setUsedInGOT() const { IsUsedInGOT = true; } 96 bool isUsedInGOT() const { return IsUsedInGOT; } 97 98 const wasm::WasmSignature *getSignature() const { return Signature; } 99 void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; } 100 101 const wasm::WasmGlobalType &getGlobalType() const { 102 assert(GlobalType.hasValue()); 103 return GlobalType.getValue(); 104 } 105 void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; } 106 107 const wasm::WasmEventType &getEventType() const { 108 assert(EventType.hasValue()); 109 return EventType.getValue(); 110 } 111 void setEventType(wasm::WasmEventType ET) { EventType = ET; } 112 }; 113 114 } // end namespace llvm 115 116 #endif // LLVM_MC_MCSYMBOLWASM_H 117