Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- MCSymbolWasm.h - ----------------------------------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 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; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 21 | Optional<std::string> ImportModule; |
| 22 | Optional<std::string> ImportName; |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 23 | wasm::WasmSignature *Signature = nullptr; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 24 | Optional<wasm::WasmGlobalType> GlobalType; |
| 25 | Optional<wasm::WasmEventType> EventType; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 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 | |
| 31 | public: |
| 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 Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 35 | : MCSymbol(SymbolKindWasm, Name, isTemporary) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 36 | 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 Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 44 | bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; } |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 45 | bool isEvent() const { return Type == wasm::WASM_SYMBOL_TYPE_EVENT; } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 46 | wasm::WasmSymbolType getType() const { return Type; } |
| 47 | void setType(wasm::WasmSymbolType type) { Type = type; } |
| 48 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 49 | bool isExported() const { |
| 50 | return getFlags() & wasm::WASM_SYMBOL_EXPORTED; |
| 51 | } |
| 52 | void setExported() const { |
| 53 | modifyFlags(wasm::WASM_SYMBOL_EXPORTED, wasm::WASM_SYMBOL_EXPORTED); |
| 54 | } |
| 55 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 56 | bool isWeak() const { return IsWeak; } |
| 57 | void setWeak(bool isWeak) { IsWeak = isWeak; } |
| 58 | |
| 59 | bool isHidden() const { return IsHidden; } |
| 60 | void setHidden(bool isHidden) { IsHidden = isHidden; } |
| 61 | |
| 62 | bool isComdat() const { return IsComdat; } |
| 63 | void setComdat(bool isComdat) { IsComdat = isComdat; } |
| 64 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 65 | const StringRef getImportModule() const { |
| 66 | if (ImportModule.hasValue()) { |
| 67 | return ImportModule.getValue(); |
| 68 | } |
| 69 | return "env"; |
| 70 | } |
| 71 | void setImportModule(StringRef Name) { ImportModule = Name; } |
| 72 | |
| 73 | const StringRef getImportName() const { |
| 74 | if (ImportName.hasValue()) { |
| 75 | return ImportName.getValue(); |
| 76 | } |
| 77 | return getName(); |
| 78 | } |
| 79 | void setImportName(StringRef Name) { ImportName = Name; } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 80 | |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 81 | const wasm::WasmSignature *getSignature() const { return Signature; } |
| 82 | void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 83 | |
| 84 | const wasm::WasmGlobalType &getGlobalType() const { |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 85 | assert(GlobalType.hasValue()); |
| 86 | return GlobalType.getValue(); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 87 | } |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 88 | void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 89 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 90 | const wasm::WasmEventType &getEventType() const { |
| 91 | assert(EventType.hasValue()); |
| 92 | return EventType.getValue(); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 93 | } |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 94 | void setEventType(wasm::WasmEventType ET) { EventType = ET; } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 95 | }; |
| 96 | |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 97 | } // end namespace llvm |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 98 | |
| 99 | #endif // LLVM_MC_MCSYMBOLWASM_H |