2018-02-23 13:08:53 +08:00
|
|
|
//===- InputGlobal.h --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_WASM_INPUT_GLOBAL_H
|
|
|
|
#define LLD_WASM_INPUT_GLOBAL_H
|
|
|
|
|
|
|
|
#include "Config.h"
|
|
|
|
#include "InputFiles.h"
|
|
|
|
#include "WriterUtils.h"
|
|
|
|
#include "lld/Common/ErrorHandler.h"
|
|
|
|
#include "llvm/Object/Wasm.h"
|
|
|
|
|
|
|
|
using llvm::wasm::WasmGlobal;
|
|
|
|
using llvm::wasm::WasmInitExpr;
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace wasm {
|
|
|
|
|
|
|
|
// Represents a single Wasm Global Variable within an input file. These are
|
|
|
|
// combined to form the final GLOBALS section.
|
|
|
|
class InputGlobal {
|
|
|
|
public:
|
2018-04-21 01:28:12 +08:00
|
|
|
InputGlobal(const WasmGlobal &G, ObjFile *F)
|
|
|
|
: File(F), Global(G), Live(!Config->GcSections) {}
|
2018-02-23 13:08:53 +08:00
|
|
|
|
2018-04-21 01:28:12 +08:00
|
|
|
StringRef getName() const { return Global.SymbolName; }
|
2018-02-23 13:08:53 +08:00
|
|
|
const WasmGlobalType &getType() const { return Global.Type; }
|
|
|
|
|
2018-03-13 03:56:23 +08:00
|
|
|
uint32_t getGlobalIndex() const { return GlobalIndex.getValue(); }
|
|
|
|
bool hasGlobalIndex() const { return GlobalIndex.hasValue(); }
|
|
|
|
void setGlobalIndex(uint32_t Index) {
|
|
|
|
assert(!hasGlobalIndex());
|
|
|
|
GlobalIndex = Index;
|
2018-02-23 13:08:53 +08:00
|
|
|
}
|
|
|
|
|
2018-04-21 01:28:12 +08:00
|
|
|
ObjFile *File;
|
2018-02-23 13:08:53 +08:00
|
|
|
WasmGlobal Global;
|
|
|
|
|
2018-04-21 01:28:12 +08:00
|
|
|
bool Live = false;
|
|
|
|
|
2018-02-23 13:08:53 +08:00
|
|
|
protected:
|
2018-03-13 03:56:23 +08:00
|
|
|
llvm::Optional<uint32_t> GlobalIndex;
|
2018-02-23 13:08:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace wasm
|
|
|
|
|
2018-04-21 01:28:12 +08:00
|
|
|
inline std::string toString(const wasm::InputGlobal *G) {
|
|
|
|
return (toString(G->File) + ":(" + G->getName() + ")").str();
|
|
|
|
}
|
|
|
|
|
2018-02-23 13:08:53 +08:00
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif // LLD_WASM_INPUT_GLOBAL_H
|