2017-02-22 02:23:18 +01:00
|
|
|
//===- MCSymbolWasm.h - ----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-02-22 02:23:18 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_MC_MCSYMBOLWASM_H
|
|
|
|
#define LLVM_MC_MCSYMBOLWASM_H
|
|
|
|
|
2017-06-07 05:48:56 +02:00
|
|
|
#include "llvm/BinaryFormat/Wasm.h"
|
2017-02-22 02:23:18 +01:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
2017-06-13 20:51:50 +02:00
|
|
|
|
2017-02-22 02:23:18 +01:00
|
|
|
class MCSymbolWasm : public MCSymbol {
|
2021-02-02 02:28:00 +01:00
|
|
|
Optional<wasm::WasmSymbolType> Type;
|
2017-06-20 06:04:59 +02:00
|
|
|
bool IsWeak = false;
|
2017-12-03 02:19:23 +01:00
|
|
|
bool IsHidden = false;
|
2018-01-11 21:35:17 +01:00
|
|
|
bool IsComdat = false;
|
2021-02-12 11:22:13 +01:00
|
|
|
bool OmitFromLinkingSection = false;
|
2020-03-31 02:37:01 +02:00
|
|
|
mutable bool IsUsedInInitArray = false;
|
2019-03-26 20:46:15 +01:00
|
|
|
mutable bool IsUsedInGOT = false;
|
2020-04-07 23:02:20 +02:00
|
|
|
Optional<StringRef> ImportModule;
|
|
|
|
Optional<StringRef> ImportName;
|
|
|
|
Optional<StringRef> ExportName;
|
|
|
|
wasm::WasmSignature *Signature = nullptr;
|
2018-11-14 03:46:21 +01:00
|
|
|
Optional<wasm::WasmGlobalType> GlobalType;
|
2021-03-23 16:13:54 +01:00
|
|
|
Optional<wasm::WasmTableType> TableType;
|
2021-06-15 10:49:43 +02:00
|
|
|
Optional<wasm::WasmTagType> TagType;
|
2017-02-25 00:18:00 +01:00
|
|
|
|
|
|
|
/// An expression describing how to calculate the size of a symbol. If a
|
|
|
|
/// symbol has no size this field will be NULL.
|
|
|
|
const MCExpr *SymbolSize = nullptr;
|
|
|
|
|
2017-02-22 02:23:18 +01:00
|
|
|
public:
|
|
|
|
MCSymbolWasm(const StringMapEntry<bool> *Name, bool isTemporary)
|
2019-02-01 23:27:34 +01:00
|
|
|
: MCSymbol(SymbolKindWasm, Name, isTemporary) {}
|
2017-02-22 02:23:18 +01:00
|
|
|
static bool classof(const MCSymbol *S) { return S->isWasm(); }
|
2017-02-25 00:18:00 +01:00
|
|
|
|
|
|
|
const MCExpr *getSize() const { return SymbolSize; }
|
|
|
|
void setSize(const MCExpr *SS) { SymbolSize = SS; }
|
|
|
|
|
2018-02-23 06:08:34 +01:00
|
|
|
bool isFunction() const { return Type == wasm::WASM_SYMBOL_TYPE_FUNCTION; }
|
2021-02-02 02:28:00 +01:00
|
|
|
// Data is the default value if not set.
|
|
|
|
bool isData() const { return !Type || Type == wasm::WASM_SYMBOL_TYPE_DATA; }
|
2018-02-23 06:08:34 +01:00
|
|
|
bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; }
|
2020-10-13 16:13:10 +02:00
|
|
|
bool isTable() const { return Type == wasm::WASM_SYMBOL_TYPE_TABLE; }
|
2018-04-30 21:40:57 +02:00
|
|
|
bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; }
|
2021-06-15 10:49:43 +02:00
|
|
|
bool isTag() const { return Type == wasm::WASM_SYMBOL_TYPE_TAG; }
|
2021-02-02 02:28:00 +01:00
|
|
|
|
|
|
|
Optional<wasm::WasmSymbolType> getType() const { return Type; }
|
|
|
|
|
2018-02-23 06:08:34 +01:00
|
|
|
void setType(wasm::WasmSymbolType type) { Type = type; }
|
2017-02-25 00:18:00 +01:00
|
|
|
|
2019-02-07 02:24:44 +01:00
|
|
|
bool isExported() const {
|
|
|
|
return getFlags() & wasm::WASM_SYMBOL_EXPORTED;
|
|
|
|
}
|
|
|
|
void setExported() const {
|
|
|
|
modifyFlags(wasm::WASM_SYMBOL_EXPORTED, wasm::WASM_SYMBOL_EXPORTED);
|
|
|
|
}
|
|
|
|
|
2019-08-30 00:40:00 +02:00
|
|
|
bool isNoStrip() const {
|
|
|
|
return getFlags() & wasm::WASM_SYMBOL_NO_STRIP;
|
|
|
|
}
|
|
|
|
void setNoStrip() const {
|
|
|
|
modifyFlags(wasm::WASM_SYMBOL_NO_STRIP, wasm::WASM_SYMBOL_NO_STRIP);
|
|
|
|
}
|
|
|
|
|
2017-06-20 06:04:59 +02:00
|
|
|
bool isWeak() const { return IsWeak; }
|
|
|
|
void setWeak(bool isWeak) { IsWeak = isWeak; }
|
|
|
|
|
2017-12-03 02:19:23 +01:00
|
|
|
bool isHidden() const { return IsHidden; }
|
|
|
|
void setHidden(bool isHidden) { IsHidden = isHidden; }
|
|
|
|
|
2018-01-11 21:35:17 +01:00
|
|
|
bool isComdat() const { return IsComdat; }
|
|
|
|
void setComdat(bool isComdat) { IsComdat = isComdat; }
|
|
|
|
|
2021-02-12 11:22:13 +01:00
|
|
|
// wasm-ld understands a finite set of symbol types. This flag allows the
|
|
|
|
// compiler to avoid emitting symbol table entries that would confuse the
|
|
|
|
// linker, unless the user specifically requests the feature.
|
|
|
|
bool omitFromLinkingSection() const { return OmitFromLinkingSection; }
|
|
|
|
void setOmitFromLinkingSection() { OmitFromLinkingSection = true; }
|
|
|
|
|
2020-04-07 23:02:20 +02:00
|
|
|
bool hasImportModule() const { return ImportModule.hasValue(); }
|
2020-04-07 22:22:03 +02:00
|
|
|
StringRef getImportModule() const {
|
2020-04-07 23:02:20 +02:00
|
|
|
if (ImportModule.hasValue())
|
|
|
|
return ImportModule.getValue();
|
2020-04-07 05:46:11 +02:00
|
|
|
// Use a default module name of "env" for now, for compatibility with
|
|
|
|
// existing tools.
|
|
|
|
// TODO(sbc): Find a way to specify a default value in the object format
|
|
|
|
// without picking a hardcoded value like this.
|
|
|
|
return "env";
|
2020-01-28 20:23:46 +01:00
|
|
|
}
|
2020-04-07 23:02:20 +02:00
|
|
|
void setImportModule(StringRef Name) { ImportModule = Name; }
|
2019-02-01 23:27:34 +01:00
|
|
|
|
2020-04-07 23:02:20 +02:00
|
|
|
bool hasImportName() const { return ImportName.hasValue(); }
|
2020-04-07 22:22:03 +02:00
|
|
|
StringRef getImportName() const {
|
2020-04-07 23:02:20 +02:00
|
|
|
if (ImportName.hasValue())
|
|
|
|
return ImportName.getValue();
|
2020-04-07 05:46:11 +02:00
|
|
|
return getName();
|
2020-01-28 20:23:46 +01:00
|
|
|
}
|
2020-04-07 23:02:20 +02:00
|
|
|
void setImportName(StringRef Name) { ImportName = Name; }
|
2017-02-25 00:18:00 +01:00
|
|
|
|
2020-04-07 23:02:20 +02:00
|
|
|
bool hasExportName() const { return ExportName.hasValue(); }
|
|
|
|
StringRef getExportName() const { return ExportName.getValue(); }
|
|
|
|
void setExportName(StringRef Name) { ExportName = Name; }
|
2019-11-05 19:15:56 +01:00
|
|
|
|
2020-11-25 17:31:05 +01:00
|
|
|
bool isFunctionTable() const {
|
|
|
|
return isTable() && hasTableType() &&
|
2021-03-23 16:13:54 +01:00
|
|
|
getTableType().ElemType == wasm::WASM_TYPE_FUNCREF;
|
2020-11-25 17:31:05 +01:00
|
|
|
}
|
|
|
|
void setFunctionTable() {
|
|
|
|
setType(wasm::WASM_SYMBOL_TYPE_TABLE);
|
|
|
|
setTableType(wasm::ValType::FUNCREF);
|
|
|
|
}
|
|
|
|
|
2019-03-26 20:46:15 +01:00
|
|
|
void setUsedInGOT() const { IsUsedInGOT = true; }
|
|
|
|
bool isUsedInGOT() const { return IsUsedInGOT; }
|
|
|
|
|
2020-03-31 02:37:01 +02:00
|
|
|
void setUsedInInitArray() const { IsUsedInInitArray = true; }
|
|
|
|
bool isUsedInInitArray() const { return IsUsedInInitArray; }
|
|
|
|
|
2018-10-04 00:22:48 +02:00
|
|
|
const wasm::WasmSignature *getSignature() const { return Signature; }
|
|
|
|
void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
|
2018-02-23 06:08:34 +01:00
|
|
|
|
|
|
|
const wasm::WasmGlobalType &getGlobalType() const {
|
2018-11-14 03:46:21 +01:00
|
|
|
assert(GlobalType.hasValue());
|
|
|
|
return GlobalType.getValue();
|
2018-02-23 06:08:34 +01:00
|
|
|
}
|
2018-11-14 03:46:21 +01:00
|
|
|
void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }
|
2018-02-23 06:08:34 +01:00
|
|
|
|
2020-11-25 17:31:05 +01:00
|
|
|
bool hasTableType() const { return TableType.hasValue(); }
|
2021-03-23 16:13:54 +01:00
|
|
|
const wasm::WasmTableType &getTableType() const {
|
2020-11-25 17:31:05 +01:00
|
|
|
assert(hasTableType());
|
2020-10-13 16:13:10 +02:00
|
|
|
return TableType.getValue();
|
|
|
|
}
|
2021-03-23 16:13:54 +01:00
|
|
|
void setTableType(wasm::WasmTableType TT) { TableType = TT; }
|
|
|
|
void setTableType(wasm::ValType VT) {
|
|
|
|
// Declare a table with element type VT and no limits (min size 0, no max
|
|
|
|
// size).
|
|
|
|
wasm::WasmLimits Limits = {wasm::WASM_LIMITS_FLAG_NONE, 0, 0};
|
|
|
|
setTableType({uint8_t(VT), Limits});
|
|
|
|
}
|
2020-10-13 16:13:10 +02:00
|
|
|
|
2021-06-15 10:49:43 +02:00
|
|
|
const wasm::WasmTagType &getTagType() const {
|
|
|
|
assert(TagType.hasValue());
|
|
|
|
return TagType.getValue();
|
2018-02-23 06:08:34 +01:00
|
|
|
}
|
2021-06-15 10:49:43 +02:00
|
|
|
void setTagType(wasm::WasmTagType ET) { TagType = ET; }
|
2017-02-22 02:23:18 +01:00
|
|
|
};
|
|
|
|
|
2018-09-05 03:27:38 +02:00
|
|
|
} // end namespace llvm
|
2017-06-13 20:51:50 +02:00
|
|
|
|
|
|
|
#endif // LLVM_MC_MCSYMBOLWASM_H
|