]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/include/llvm/MC/MCSymbolWasm.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / include / llvm / MC / MCSymbolWasm.h
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
11 #include "llvm/BinaryFormat/Wasm.h"
12 #include "llvm/MC/MCSymbol.h"
13
14 namespace llvm {
15
16 class MCSymbolWasm : public MCSymbol {
17   wasm::WasmSymbolType Type = wasm::WASM_SYMBOL_TYPE_DATA;
18   bool IsWeak = false;
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;
27
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
32 public:
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(); }
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; }
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; }
49
50   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
57   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
66   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; }
81
82   void setUsedInGOT() const { IsUsedInGOT = true; }
83   bool isUsedInGOT() const { return IsUsedInGOT; }
84
85   const wasm::WasmSignature *getSignature() const { return Signature; }
86   void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
87
88   const wasm::WasmGlobalType &getGlobalType() const {
89     assert(GlobalType.hasValue());
90     return GlobalType.getValue();
91   }
92   void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }
93
94   const wasm::WasmEventType &getEventType() const {
95     assert(EventType.hasValue());
96     return EventType.getValue();
97   }
98   void setEventType(wasm::WasmEventType ET) { EventType = ET; }
99 };
100
101 } // end namespace llvm
102
103 #endif // LLVM_MC_MCSYMBOLWASM_H