LLVM 22.0.0git
MCSymbolWasm.h
Go to the documentation of this file.
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
12#include "llvm/MC/MCSymbol.h"
14
15namespace llvm {
16
17class MCSymbolWasm : public MCSymbol {
18 std::optional<wasm::WasmSymbolType> Type;
19 bool IsWeak = false;
20 bool IsHidden = false;
21 bool IsComdat = false;
22 bool OmitFromLinkingSection = false;
23 mutable bool IsUsedInInitArray = false;
24 mutable bool IsUsedInGOT = false;
25 std::optional<StringRef> ImportModule;
26 std::optional<StringRef> ImportName;
27 std::optional<StringRef> ExportName;
28 wasm::WasmSignature *Signature = nullptr;
29 std::optional<wasm::WasmGlobalType> GlobalType;
30 std::optional<wasm::WasmTableType> TableType;
31
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
36public:
39
40 bool isExternal() const { return IsExternal; }
41 void setExternal(bool Value) const { IsExternal = Value; }
42 const MCExpr *getSize() const { return SymbolSize; }
43 void setSize(const MCExpr *SS) { SymbolSize = SS; }
44
45 bool isFunction() const { return Type == wasm::WASM_SYMBOL_TYPE_FUNCTION; }
46 // Data is the default value if not set.
47 bool isData() const { return !Type || Type == wasm::WASM_SYMBOL_TYPE_DATA; }
48 bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; }
49 bool isTable() const { return Type == wasm::WASM_SYMBOL_TYPE_TABLE; }
50 bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; }
51 bool isTag() const { return Type == wasm::WASM_SYMBOL_TYPE_TAG; }
52
53 std::optional<wasm::WasmSymbolType> getType() const { return Type; }
54
55 void setType(wasm::WasmSymbolType type) { Type = type; }
56
57 bool isExported() const {
59 }
63
64 bool isNoStrip() const {
66 }
70
71 bool isTLS() const { return getFlags() & wasm::WASM_SYMBOL_TLS; }
75
76 bool isWeak() const { return IsWeak; }
77 void setWeak(bool isWeak) { IsWeak = isWeak; }
78
79 bool isHidden() const { return IsHidden; }
80 void setHidden(bool isHidden) { IsHidden = isHidden; }
81
82 bool isComdat() const { return IsComdat; }
83 void setComdat(bool isComdat) { IsComdat = isComdat; }
84
85 // wasm-ld understands a finite set of symbol types. This flag allows the
86 // compiler to avoid emitting symbol table entries that would confuse the
87 // linker, unless the user specifically requests the feature.
88 bool omitFromLinkingSection() const { return OmitFromLinkingSection; }
89 void setOmitFromLinkingSection() { OmitFromLinkingSection = true; }
90
91 bool hasImportModule() const { return ImportModule.has_value(); }
93 if (ImportModule)
94 return *ImportModule;
95 // Use a default module name of "env" for now, for compatibility with
96 // existing tools.
97 // TODO(sbc): Find a way to specify a default value in the object format
98 // without picking a hardcoded value like this.
99 return "env";
100 }
101 void setImportModule(StringRef Name) { ImportModule = Name; }
102
103 bool hasImportName() const { return ImportName.has_value(); }
105 if (ImportName)
106 return *ImportName;
107 return getName();
108 }
109 void setImportName(StringRef Name) { ImportName = Name; }
110
111 bool hasExportName() const { return ExportName.has_value(); }
112 StringRef getExportName() const { return *ExportName; }
113 void setExportName(StringRef Name) { ExportName = Name; }
114
115 bool isFunctionTable() const {
116 return isTable() && hasTableType() &&
118 }
125
126 void setUsedInGOT() const { IsUsedInGOT = true; }
127 bool isUsedInGOT() const { return IsUsedInGOT; }
128
129 void setUsedInInitArray() const { IsUsedInInitArray = true; }
130 bool isUsedInInitArray() const { return IsUsedInInitArray; }
131
132 const wasm::WasmSignature *getSignature() const { return Signature; }
133 void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
134
136 assert(GlobalType);
137 return *GlobalType;
138 }
139 void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }
140
141 bool hasTableType() const { return TableType.has_value(); }
144 return *TableType;
145 }
146 void setTableType(wasm::WasmTableType TT) { TableType = TT; }
149 // Declare a table with element type VT and no limits (min size 0, no max
150 // size).
151 wasm::WasmLimits Limits = {flags, 0, 0, 0};
152 setTableType({VT, Limits});
153 }
154};
155
156} // end namespace llvm
157
158#endif // LLVM_MC_MCSYMBOLWASM_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
bool isGlobal() const
void setTableType(wasm::WasmTableType TT)
void setComdat(bool isComdat)
const wasm::WasmTableType & getTableType() const
void setImportModule(StringRef Name)
bool isUsedInGOT() const
StringRef getImportModule() const
bool isExported() const
const wasm::WasmSignature * getSignature() const
StringRef getImportName() const
bool isExternal() const
MCSymbolWasm(const MCSymbolTableEntry *Name, bool isTemporary)
const MCExpr * getSize() const
bool hasImportModule() const
void setSignature(wasm::WasmSignature *Sig)
void setFunctionTable(bool is64)
bool isFunctionTable() const
bool hasTableType() const
void setTableType(wasm::ValType VT, uint8_t flags=wasm::WASM_LIMITS_FLAG_NONE)
void setNoStrip() const
void setImportName(StringRef Name)
void setWeak(bool isWeak)
void setType(wasm::WasmSymbolType type)
void setExportName(StringRef Name)
void setGlobalType(wasm::WasmGlobalType GT)
void setHidden(bool isHidden)
bool isNoStrip() const
void setOmitFromLinkingSection()
void setUsedInInitArray() const
bool isHidden() const
bool isSection() const
bool hasExportName() const
bool omitFromLinkingSection() const
void setExternal(bool Value) const
void setExported() const
bool isTable() const
const wasm::WasmGlobalType & getGlobalType() const
StringRef getExportName() const
bool isComdat() const
bool isData() const
void setUsedInGOT() const
bool isTag() const
bool isUsedInInitArray() const
bool hasImportName() const
bool isTLS() const
bool isFunction() const
void setSize(const MCExpr *SS)
std::optional< wasm::WasmSymbolType > getType() const
void setTLS() const
bool isWeak() const
MCSymbol(const MCSymbolTableEntry *Name, bool isTemporary)
Definition MCSymbol.h:146
friend class MCExpr
Definition MCSymbol.h:134
void modifyFlags(uint32_t Value, uint32_t Mask) const
Modify the flags via a mask.
Definition MCSymbol.h:375
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
uint32_t getFlags() const
Get the (implementation defined) symbol flags.
Definition MCSymbol.h:366
unsigned IsExternal
True if this symbol is visible outside this translation unit.
Definition MCSymbol.h:87
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition MCSymbol.h:205
const MCExpr * Value
If non-null, the value for a variable symbol.
Definition MCSymbol.h:130
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
const unsigned WASM_SYMBOL_NO_STRIP
Definition Wasm.h:250
const unsigned WASM_SYMBOL_TLS
Definition Wasm.h:251
@ WASM_LIMITS_FLAG_IS_64
Definition Wasm.h:161
@ WASM_LIMITS_FLAG_NONE
Definition Wasm.h:158
WasmSymbolType
Definition Wasm.h:219
@ WASM_SYMBOL_TYPE_GLOBAL
Definition Wasm.h:222
@ WASM_SYMBOL_TYPE_DATA
Definition Wasm.h:221
@ WASM_SYMBOL_TYPE_TAG
Definition Wasm.h:224
@ WASM_SYMBOL_TYPE_TABLE
Definition Wasm.h:225
@ WASM_SYMBOL_TYPE_SECTION
Definition Wasm.h:223
@ WASM_SYMBOL_TYPE_FUNCTION
Definition Wasm.h:220
const unsigned WASM_SYMBOL_EXPORTED
Definition Wasm.h:248
This is an optimization pass for GlobalISel generic memory operations.
StringMapEntry< MCSymbolTableValue > MCSymbolTableEntry
MCContext stores MCSymbolTableValue in a string map (see MCSymbol::operator new).