blob: 635ef841bca250c0e7ce22df4f63fcfce31a2c1b [file] [log] [blame]
Sam Cleggc94d3932017-11-17 18:14:09 +00001//===- WriterUtils.h --------------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Sam Cleggc94d3932017-11-17 18:14:09 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLD_WASM_WRITERUTILS_H
10#define LLD_WASM_WRITERUTILS_H
11
Rui Ueyama11842532018-02-16 20:38:00 +000012#include "lld/Common/LLVM.h"
Sam Cleggc94d3932017-11-17 18:14:09 +000013#include "llvm/ADT/Twine.h"
14#include "llvm/Object/Wasm.h"
Sam Cleggc94d3932017-11-17 18:14:09 +000015
16namespace lld {
17namespace wasm {
18
Rui Ueyama136d27a2019-07-11 05:40:30 +000019void debugWrite(uint64_t offset, const Twine &msg);
Sam Cleggc94d3932017-11-17 18:14:09 +000020
Rui Ueyama136d27a2019-07-11 05:40:30 +000021void writeUleb128(raw_ostream &os, uint32_t number, const Twine &msg);
Sam Cleggc94d3932017-11-17 18:14:09 +000022
Rui Ueyama136d27a2019-07-11 05:40:30 +000023void writeSleb128(raw_ostream &os, int32_t number, const Twine &msg);
Sam Cleggc94d3932017-11-17 18:14:09 +000024
Rui Ueyama136d27a2019-07-11 05:40:30 +000025void writeBytes(raw_ostream &os, const char *bytes, size_t count,
26 const Twine &msg);
Sam Cleggc94d3932017-11-17 18:14:09 +000027
Rui Ueyama136d27a2019-07-11 05:40:30 +000028void writeStr(raw_ostream &os, StringRef string, const Twine &msg);
Sam Cleggc94d3932017-11-17 18:14:09 +000029
Rui Ueyama136d27a2019-07-11 05:40:30 +000030void writeU8(raw_ostream &os, uint8_t byte, const Twine &msg);
Sam Cleggc94d3932017-11-17 18:14:09 +000031
Rui Ueyama136d27a2019-07-11 05:40:30 +000032void writeU32(raw_ostream &os, uint32_t number, const Twine &msg);
Sam Cleggc94d3932017-11-17 18:14:09 +000033
Rui Ueyama136d27a2019-07-11 05:40:30 +000034void writeValueType(raw_ostream &os, llvm::wasm::ValType type,
35 const Twine &msg);
Sam Cleggc94d3932017-11-17 18:14:09 +000036
Rui Ueyama136d27a2019-07-11 05:40:30 +000037void writeSig(raw_ostream &os, const llvm::wasm::WasmSignature &sig);
Sam Cleggc94d3932017-11-17 18:14:09 +000038
Thomas Lively09768c52019-09-04 19:50:39 +000039void writeI32Const(raw_ostream &os, int32_t number, const Twine &msg);
40
41void writeI64Const(raw_ostream &os, int32_t number, const Twine &msg);
42
43void writeMemArg(raw_ostream &os, uint32_t alignment, uint32_t offset);
44
Rui Ueyama136d27a2019-07-11 05:40:30 +000045void writeInitExpr(raw_ostream &os, const llvm::wasm::WasmInitExpr &initExpr);
Sam Cleggc94d3932017-11-17 18:14:09 +000046
Rui Ueyama136d27a2019-07-11 05:40:30 +000047void writeLimits(raw_ostream &os, const llvm::wasm::WasmLimits &limits);
Sam Cleggc94d3932017-11-17 18:14:09 +000048
Rui Ueyama136d27a2019-07-11 05:40:30 +000049void writeGlobalType(raw_ostream &os, const llvm::wasm::WasmGlobalType &type);
Sam Clegg1a9b7b92018-01-31 19:54:34 +000050
Rui Ueyama136d27a2019-07-11 05:40:30 +000051void writeGlobal(raw_ostream &os, const llvm::wasm::WasmGlobal &global);
Sam Cleggc94d3932017-11-17 18:14:09 +000052
Rui Ueyama136d27a2019-07-11 05:40:30 +000053void writeEventType(raw_ostream &os, const llvm::wasm::WasmEventType &type);
Heejin Ahne915a712018-12-08 06:17:43 +000054
Rui Ueyama136d27a2019-07-11 05:40:30 +000055void writeEvent(raw_ostream &os, const llvm::wasm::WasmEvent &event);
Heejin Ahne915a712018-12-08 06:17:43 +000056
Rui Ueyama136d27a2019-07-11 05:40:30 +000057void writeTableType(raw_ostream &os, const llvm::wasm::WasmTable &type);
Nicholas Wilson874eedd2018-03-27 17:38:51 +000058
Rui Ueyama136d27a2019-07-11 05:40:30 +000059void writeImport(raw_ostream &os, const llvm::wasm::WasmImport &import);
Sam Cleggc94d3932017-11-17 18:14:09 +000060
Rui Ueyama136d27a2019-07-11 05:40:30 +000061void writeExport(raw_ostream &os, const llvm::wasm::WasmExport &export_);
Sam Cleggc94d3932017-11-17 18:14:09 +000062
Sam Cleggc94d3932017-11-17 18:14:09 +000063} // namespace wasm
Sam Cleggb8621592017-11-30 01:40:08 +000064
Rui Ueyama136d27a2019-07-11 05:40:30 +000065std::string toString(llvm::wasm::ValType type);
66std::string toString(const llvm::wasm::WasmSignature &sig);
67std::string toString(const llvm::wasm::WasmGlobalType &type);
68std::string toString(const llvm::wasm::WasmEventType &type);
Sam Cleggb8621592017-11-30 01:40:08 +000069
Sam Cleggc94d3932017-11-17 18:14:09 +000070} // namespace lld
71
72#endif // LLD_WASM_WRITERUTILS_H