1 //===- MCSymbolWasm.h - ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_MC_MCSYMBOLWASM_H
9 #define LLVM_MC_MCSYMBOLWASM_H
11 #include "llvm/BinaryFormat/Wasm.h"
12 #include "llvm/MC/MCSymbol.h"
16 class MCSymbolWasm
: public MCSymbol
{
17 wasm::WasmSymbolType Type
= wasm::WASM_SYMBOL_TYPE_DATA
;
19 bool IsHidden
= false;
20 bool IsComdat
= false;
21 mutable bool IsUsedInGOT
= false;
22 Optional
<std::string
> ImportModule
;
23 Optional
<std::string
> ImportName
;
24 wasm::WasmSignature
*Signature
= nullptr;
25 Optional
<wasm::WasmGlobalType
> GlobalType
;
26 Optional
<wasm::WasmEventType
> EventType
;
28 /// An expression describing how to calculate the size of a symbol. If a
29 /// symbol has no size this field will be NULL.
30 const MCExpr
*SymbolSize
= nullptr;
33 // Use a module name of "env" for now, for compatibility with existing tools.
34 // This is temporary, and may change, as the ABI is not yet stable.
35 MCSymbolWasm(const StringMapEntry
<bool> *Name
, bool isTemporary
)
36 : MCSymbol(SymbolKindWasm
, Name
, isTemporary
) {}
37 static bool classof(const MCSymbol
*S
) { return S
->isWasm(); }
39 const MCExpr
*getSize() const { return SymbolSize
; }
40 void setSize(const MCExpr
*SS
) { SymbolSize
= SS
; }
42 bool isFunction() const { return Type
== wasm::WASM_SYMBOL_TYPE_FUNCTION
; }
43 bool isData() const { return Type
== wasm::WASM_SYMBOL_TYPE_DATA
; }
44 bool isGlobal() const { return Type
== wasm::WASM_SYMBOL_TYPE_GLOBAL
; }
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
; }
50 bool isExported() const {
51 return getFlags() & wasm::WASM_SYMBOL_EXPORTED
;
53 void setExported() const {
54 modifyFlags(wasm::WASM_SYMBOL_EXPORTED
, wasm::WASM_SYMBOL_EXPORTED
);
57 bool isNoStrip() const {
58 return getFlags() & wasm::WASM_SYMBOL_NO_STRIP
;
60 void setNoStrip() const {
61 modifyFlags(wasm::WASM_SYMBOL_NO_STRIP
, wasm::WASM_SYMBOL_NO_STRIP
);
64 bool isWeak() const { return IsWeak
; }
65 void setWeak(bool isWeak
) { IsWeak
= isWeak
; }
67 bool isHidden() const { return IsHidden
; }
68 void setHidden(bool isHidden
) { IsHidden
= isHidden
; }
70 bool isComdat() const { return IsComdat
; }
71 void setComdat(bool isComdat
) { IsComdat
= isComdat
; }
73 const StringRef
getImportModule() const {
74 if (ImportModule
.hasValue()) {
75 return ImportModule
.getValue();
79 void setImportModule(StringRef Name
) { ImportModule
= Name
; }
81 const StringRef
getImportName() const {
82 if (ImportName
.hasValue()) {
83 return ImportName
.getValue();
87 void setImportName(StringRef Name
) { ImportName
= Name
; }
89 void setUsedInGOT() const { IsUsedInGOT
= true; }
90 bool isUsedInGOT() const { return IsUsedInGOT
; }
92 const wasm::WasmSignature
*getSignature() const { return Signature
; }
93 void setSignature(wasm::WasmSignature
*Sig
) { Signature
= Sig
; }
95 const wasm::WasmGlobalType
&getGlobalType() const {
96 assert(GlobalType
.hasValue());
97 return GlobalType
.getValue();
99 void setGlobalType(wasm::WasmGlobalType GT
) { GlobalType
= GT
; }
101 const wasm::WasmEventType
&getEventType() const {
102 assert(EventType
.hasValue());
103 return EventType
.getValue();
105 void setEventType(wasm::WasmEventType ET
) { EventType
= ET
; }
108 } // end namespace llvm
110 #endif // LLVM_MC_MCSYMBOLWASM_H