1 //===- InputGlobal.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 9 #ifndef LLD_WASM_INPUT_GLOBAL_H 10 #define LLD_WASM_INPUT_GLOBAL_H 11 12 #include "Config.h" 13 #include "InputFiles.h" 14 #include "WriterUtils.h" 15 #include "lld/Common/ErrorHandler.h" 16 #include "llvm/Object/Wasm.h" 17 18 namespace lld { 19 namespace wasm { 20 21 // Represents a single Wasm Global Variable within an input file. These are 22 // combined to form the final GLOBALS section. 23 class InputGlobal { 24 public: InputGlobal(const WasmGlobal & g,ObjFile * f)25 InputGlobal(const WasmGlobal &g, ObjFile *f) 26 : file(f), global(g), live(!config->gcSections) {} 27 getName()28 StringRef getName() const { return global.SymbolName; } getType()29 const WasmGlobalType &getType() const { return global.Type; } 30 getGlobalIndex()31 uint32_t getGlobalIndex() const { return globalIndex.getValue(); } hasGlobalIndex()32 bool hasGlobalIndex() const { return globalIndex.hasValue(); } setGlobalIndex(uint32_t index)33 void setGlobalIndex(uint32_t index) { 34 assert(!hasGlobalIndex()); 35 globalIndex = index; 36 } 37 38 ObjFile *file; 39 WasmGlobal global; 40 41 bool live = false; 42 43 protected: 44 llvm::Optional<uint32_t> globalIndex; 45 }; 46 47 } // namespace wasm 48 toString(const wasm::InputGlobal * g)49inline std::string toString(const wasm::InputGlobal *g) { 50 return (toString(g->file) + ":(" + g->getName() + ")").str(); 51 } 52 53 } // namespace lld 54 55 #endif // LLD_WASM_INPUT_GLOBAL_H 56