blob: 281178aea61229158c8a45c629b460b1f7e0786f [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- MCSymbolWasm.h - ----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#ifndef LLVM_MC_MCSYMBOLWASM_H
10#define LLVM_MC_MCSYMBOLWASM_H
11
12#include "llvm/BinaryFormat/Wasm.h"
13#include "llvm/MC/MCSymbol.h"
14
15namespace llvm {
16
17class MCSymbolWasm : public MCSymbol {
18 wasm::WasmSymbolType Type = wasm::WASM_SYMBOL_TYPE_DATA;
19 bool IsWeak = false;
20 bool IsHidden = false;
21 bool IsComdat = false;
22 std::string ModuleName;
Andrew Scull0372a572018-11-16 15:47:06 +000023 wasm::WasmSignature *Signature = nullptr;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010024 wasm::WasmGlobalType GlobalType;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010025 bool GlobalTypeSet = false;
26
27 /// An expression describing how to calculate the size of a symbol. If a
28 /// symbol has no size this field will be NULL.
29 const MCExpr *SymbolSize = nullptr;
30
31public:
32 // Use a module name of "env" for now, for compatibility with existing tools.
33 // This is temporary, and may change, as the ABI is not yet stable.
34 MCSymbolWasm(const StringMapEntry<bool> *Name, bool isTemporary)
Andrew Scull0372a572018-11-16 15:47:06 +000035 : MCSymbol(SymbolKindWasm, Name, isTemporary), ModuleName("env") {}
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010036 static bool classof(const MCSymbol *S) { return S->isWasm(); }
37
38 const MCExpr *getSize() const { return SymbolSize; }
39 void setSize(const MCExpr *SS) { SymbolSize = SS; }
40
41 bool isFunction() const { return Type == wasm::WASM_SYMBOL_TYPE_FUNCTION; }
42 bool isData() const { return Type == wasm::WASM_SYMBOL_TYPE_DATA; }
43 bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010044 bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010045 wasm::WasmSymbolType getType() const { return Type; }
46 void setType(wasm::WasmSymbolType type) { Type = type; }
47
48 bool isWeak() const { return IsWeak; }
49 void setWeak(bool isWeak) { IsWeak = isWeak; }
50
51 bool isHidden() const { return IsHidden; }
52 void setHidden(bool isHidden) { IsHidden = isHidden; }
53
54 bool isComdat() const { return IsComdat; }
55 void setComdat(bool isComdat) { IsComdat = isComdat; }
56
57 const StringRef getModuleName() const { return ModuleName; }
58 void setModuleName(StringRef Name) { ModuleName = Name; }
59
Andrew Scull0372a572018-11-16 15:47:06 +000060 const wasm::WasmSignature *getSignature() const { return Signature; }
61 void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010062
63 const wasm::WasmGlobalType &getGlobalType() const {
64 assert(GlobalTypeSet);
65 return GlobalType;
66 }
67
68 void setGlobalType(wasm::WasmGlobalType GT) {
69 GlobalTypeSet = true;
70 GlobalType = GT;
71 }
72};
73
Andrew Scull0372a572018-11-16 15:47:06 +000074} // end namespace llvm
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010075
76#endif // LLVM_MC_MCSYMBOLWASM_H