2018-02-23 13:08:53 +08:00
|
|
|
//===- InputGlobal.h --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-02-23 13:08:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
|
|
|
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:
|
2019-07-11 13:40:30 +08:00
|
|
|
InputGlobal(const WasmGlobal &g, ObjFile *f)
|
|
|
|
: file(f), global(g), live(!config->gcSections) {}
|
2018-02-23 13:08:53 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
StringRef getName() const { return global.SymbolName; }
|
|
|
|
const WasmGlobalType &getType() const { return global.Type; }
|
2018-02-23 13:08:53 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
uint32_t getGlobalIndex() const { return globalIndex.getValue(); }
|
|
|
|
bool hasGlobalIndex() const { return globalIndex.hasValue(); }
|
|
|
|
void setGlobalIndex(uint32_t index) {
|
2018-03-13 03:56:23 +08:00
|
|
|
assert(!hasGlobalIndex());
|
2019-07-11 13:40:30 +08:00
|
|
|
globalIndex = index;
|
2018-02-23 13:08:53 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
ObjFile *file;
|
|
|
|
WasmGlobal global;
|
2018-02-23 13:08:53 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
bool live = false;
|
2018-04-21 01:28:12 +08:00
|
|
|
|
2018-02-23 13:08:53 +08:00
|
|
|
protected:
|
2019-07-11 13:40:30 +08:00
|
|
|
llvm::Optional<uint32_t> globalIndex;
|
2018-02-23 13:08:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace wasm
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
inline std::string toString(const wasm::InputGlobal *g) {
|
|
|
|
return (toString(g->file) + ":(" + g->getName() + ")").str();
|
2018-04-21 01:28:12 +08:00
|
|
|
}
|
|
|
|
|
2018-02-23 13:08:53 +08:00
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif // LLD_WASM_INPUT_GLOBAL_H
|