2017-11-18 02:14:09 +08:00
|
|
|
//===- WriterUtils.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_WRITERUTILS_H
|
|
|
|
#define LLD_WASM_WRITERUTILS_H
|
|
|
|
|
2018-02-17 04:38:00 +08:00
|
|
|
#include "lld/Common/LLVM.h"
|
2017-11-18 02:14:09 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/Object/Wasm.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using llvm::raw_ostream;
|
|
|
|
|
2017-11-30 09:40:08 +08:00
|
|
|
// Needed for WasmSignatureDenseMapInfo
|
|
|
|
inline bool operator==(const llvm::wasm::WasmSignature &LHS,
|
|
|
|
const llvm::wasm::WasmSignature &RHS) {
|
|
|
|
return LHS.ReturnType == RHS.ReturnType && LHS.ParamTypes == RHS.ParamTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const llvm::wasm::WasmSignature &LHS,
|
|
|
|
const llvm::wasm::WasmSignature &RHS) {
|
|
|
|
return !(LHS == RHS);
|
|
|
|
}
|
|
|
|
|
2018-02-23 13:08:53 +08:00
|
|
|
// Used for general comparison
|
|
|
|
inline bool operator==(const llvm::wasm::WasmGlobalType &LHS,
|
|
|
|
const llvm::wasm::WasmGlobalType &RHS) {
|
|
|
|
return LHS.Type == RHS.Type && LHS.Mutable == RHS.Mutable;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const llvm::wasm::WasmGlobalType &LHS,
|
|
|
|
const llvm::wasm::WasmGlobalType &RHS) {
|
|
|
|
return !(LHS == RHS);
|
|
|
|
}
|
|
|
|
|
2017-11-18 02:14:09 +08:00
|
|
|
namespace lld {
|
|
|
|
namespace wasm {
|
|
|
|
|
2018-02-17 04:38:00 +08:00
|
|
|
void debugWrite(uint64_t Offset, const Twine &Msg);
|
2017-11-18 02:14:09 +08:00
|
|
|
|
2018-02-17 04:38:00 +08:00
|
|
|
void writeUleb128(raw_ostream &OS, uint32_t Number, StringRef Msg);
|
2017-11-18 02:14:09 +08:00
|
|
|
|
2018-02-17 04:38:00 +08:00
|
|
|
void writeSleb128(raw_ostream &OS, int32_t Number, StringRef Msg);
|
2017-11-18 02:14:09 +08:00
|
|
|
|
2018-02-17 04:38:00 +08:00
|
|
|
void writeBytes(raw_ostream &OS, const char *Bytes, size_t count, StringRef Msg);
|
2017-11-18 02:14:09 +08:00
|
|
|
|
2018-02-17 04:38:00 +08:00
|
|
|
void writeStr(raw_ostream &OS, StringRef String, StringRef Msg);
|
2017-11-18 02:14:09 +08:00
|
|
|
|
2018-02-17 04:38:00 +08:00
|
|
|
void writeU8(raw_ostream &OS, uint8_t byte, StringRef Msg);
|
2017-11-18 02:14:09 +08:00
|
|
|
|
2018-02-17 04:38:00 +08:00
|
|
|
void writeU32(raw_ostream &OS, uint32_t Number, StringRef Msg);
|
2017-11-18 02:14:09 +08:00
|
|
|
|
2018-02-17 04:38:00 +08:00
|
|
|
void writeValueType(raw_ostream &OS, int32_t Type, StringRef Msg);
|
2017-11-18 02:14:09 +08:00
|
|
|
|
|
|
|
void writeSig(raw_ostream &OS, const llvm::wasm::WasmSignature &Sig);
|
|
|
|
|
|
|
|
void writeInitExpr(raw_ostream &OS, const llvm::wasm::WasmInitExpr &InitExpr);
|
|
|
|
|
|
|
|
void writeLimits(raw_ostream &OS, const llvm::wasm::WasmLimits &Limits);
|
|
|
|
|
2018-02-01 03:54:34 +08:00
|
|
|
void writeGlobalType(raw_ostream &OS, const llvm::wasm::WasmGlobalType &Type);
|
|
|
|
|
2017-11-18 02:14:09 +08:00
|
|
|
void writeGlobal(raw_ostream &OS, const llvm::wasm::WasmGlobal &Global);
|
|
|
|
|
|
|
|
void writeImport(raw_ostream &OS, const llvm::wasm::WasmImport &Import);
|
|
|
|
|
|
|
|
void writeExport(raw_ostream &OS, const llvm::wasm::WasmExport &Export);
|
|
|
|
|
|
|
|
} // namespace wasm
|
2017-11-30 09:40:08 +08:00
|
|
|
|
|
|
|
std::string toString(const llvm::wasm::ValType Type);
|
|
|
|
std::string toString(const llvm::wasm::WasmSignature &Sig);
|
2018-02-23 13:08:53 +08:00
|
|
|
std::string toString(const llvm::wasm::WasmGlobalType &Sig);
|
2017-11-30 09:40:08 +08:00
|
|
|
|
2017-11-18 02:14:09 +08:00
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif // LLD_WASM_WRITERUTILS_H
|