blob: c50cd0ee4709014212dcea142f14c255863bf4f2 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- MCSymbolWasm.h - ----------------------------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
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
14namespace llvm {
15
16class MCSymbolWasm : public MCSymbol {
17 wasm::WasmSymbolType Type = wasm::WASM_SYMBOL_TYPE_DATA;
18 bool IsWeak = false;
19 bool IsHidden = false;
20 bool IsComdat = false;
Andrew Walbran3d2c1972020-04-07 12:24:26 +010021 mutable bool IsUsedInGOT = false;
Andrew Walbran16937d02019-10-22 13:54:20 +010022 Optional<std::string> ImportModule;
23 Optional<std::string> ImportName;
Andrew Scull0372a572018-11-16 15:47:06 +000024 wasm::WasmSignature *Signature = nullptr;
Andrew Walbran16937d02019-10-22 13:54:20 +010025 Optional<wasm::WasmGlobalType> GlobalType;
26 Optional<wasm::WasmEventType> EventType;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010027
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;
31
32public:
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)
Andrew Walbran16937d02019-10-22 13:54:20 +010036 : MCSymbol(SymbolKindWasm, Name, isTemporary) {}
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010037 static bool classof(const MCSymbol *S) { return S->isWasm(); }
38
39 const MCExpr *getSize() const { return SymbolSize; }
40 void setSize(const MCExpr *SS) { SymbolSize = SS; }
41
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; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010045 bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; }
Andrew Walbran16937d02019-10-22 13:54:20 +010046 bool isEvent() const { return Type == wasm::WASM_SYMBOL_TYPE_EVENT; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010047 wasm::WasmSymbolType getType() const { return Type; }
48 void setType(wasm::WasmSymbolType type) { Type = type; }
49
Andrew Walbran16937d02019-10-22 13:54:20 +010050 bool isExported() const {
51 return getFlags() & wasm::WASM_SYMBOL_EXPORTED;
52 }
53 void setExported() const {
54 modifyFlags(wasm::WASM_SYMBOL_EXPORTED, wasm::WASM_SYMBOL_EXPORTED);
55 }
56
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010057 bool isWeak() const { return IsWeak; }
58 void setWeak(bool isWeak) { IsWeak = isWeak; }
59
60 bool isHidden() const { return IsHidden; }
61 void setHidden(bool isHidden) { IsHidden = isHidden; }
62
63 bool isComdat() const { return IsComdat; }
64 void setComdat(bool isComdat) { IsComdat = isComdat; }
65
Andrew Walbran16937d02019-10-22 13:54:20 +010066 const StringRef getImportModule() const {
67 if (ImportModule.hasValue()) {
68 return ImportModule.getValue();
69 }
70 return "env";
71 }
72 void setImportModule(StringRef Name) { ImportModule = Name; }
73
74 const StringRef getImportName() const {
75 if (ImportName.hasValue()) {
76 return ImportName.getValue();
77 }
78 return getName();
79 }
80 void setImportName(StringRef Name) { ImportName = Name; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010081
Andrew Walbran3d2c1972020-04-07 12:24:26 +010082 void setUsedInGOT() const { IsUsedInGOT = true; }
83 bool isUsedInGOT() const { return IsUsedInGOT; }
84
Andrew Scull0372a572018-11-16 15:47:06 +000085 const wasm::WasmSignature *getSignature() const { return Signature; }
86 void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010087
88 const wasm::WasmGlobalType &getGlobalType() const {
Andrew Walbran16937d02019-10-22 13:54:20 +010089 assert(GlobalType.hasValue());
90 return GlobalType.getValue();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010091 }
Andrew Walbran16937d02019-10-22 13:54:20 +010092 void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010093
Andrew Walbran16937d02019-10-22 13:54:20 +010094 const wasm::WasmEventType &getEventType() const {
95 assert(EventType.hasValue());
96 return EventType.getValue();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010097 }
Andrew Walbran16937d02019-10-22 13:54:20 +010098 void setEventType(wasm::WasmEventType ET) { EventType = ET; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010099};
100
Andrew Scull0372a572018-11-16 15:47:06 +0000101} // end namespace llvm
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100102
103#endif // LLVM_MC_MCSYMBOLWASM_H