xref: /openbsd-src/gnu/llvm/lld/wasm/WriterUtils.h (revision dfe94b169149f14cc1aee2cf6dad58a8d9a1860c)
1ece8a530Spatrick //===- WriterUtils.h --------------------------------------------*- C++ -*-===//
2ece8a530Spatrick //
3ece8a530Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4ece8a530Spatrick // See https://llvm.org/LICENSE.txt for license information.
5ece8a530Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6ece8a530Spatrick //
7ece8a530Spatrick //===----------------------------------------------------------------------===//
8ece8a530Spatrick 
9ece8a530Spatrick #ifndef LLD_WASM_WRITERUTILS_H
10ece8a530Spatrick #define LLD_WASM_WRITERUTILS_H
11ece8a530Spatrick 
12ece8a530Spatrick #include "lld/Common/LLVM.h"
13ece8a530Spatrick #include "llvm/ADT/Twine.h"
14ece8a530Spatrick #include "llvm/Object/Wasm.h"
15ece8a530Spatrick 
16ece8a530Spatrick namespace lld {
17ece8a530Spatrick namespace wasm {
18ece8a530Spatrick 
19*dfe94b16Srobert #ifdef LLVM_DEBUG
20ece8a530Spatrick void debugWrite(uint64_t offset, const Twine &msg);
21*dfe94b16Srobert #else
22*dfe94b16Srobert #define debugWrite(...) (void *)0
23*dfe94b16Srobert #endif
24ece8a530Spatrick 
25bb684c34Spatrick void writeUleb128(raw_ostream &os, uint64_t number, const Twine &msg);
26ece8a530Spatrick 
27bb684c34Spatrick void writeSleb128(raw_ostream &os, int64_t number, const Twine &msg);
28ece8a530Spatrick 
29ece8a530Spatrick void writeBytes(raw_ostream &os, const char *bytes, size_t count,
30ece8a530Spatrick                 const Twine &msg);
31ece8a530Spatrick 
32ece8a530Spatrick void writeStr(raw_ostream &os, StringRef string, const Twine &msg);
33ece8a530Spatrick 
34ece8a530Spatrick void writeU8(raw_ostream &os, uint8_t byte, const Twine &msg);
35ece8a530Spatrick 
36ece8a530Spatrick void writeU32(raw_ostream &os, uint32_t number, const Twine &msg);
37ece8a530Spatrick 
38ece8a530Spatrick void writeValueType(raw_ostream &os, llvm::wasm::ValType type,
39ece8a530Spatrick                     const Twine &msg);
40ece8a530Spatrick 
41ece8a530Spatrick void writeSig(raw_ostream &os, const llvm::wasm::WasmSignature &sig);
42ece8a530Spatrick 
43ece8a530Spatrick void writeI32Const(raw_ostream &os, int32_t number, const Twine &msg);
44ece8a530Spatrick 
45bb684c34Spatrick void writeI64Const(raw_ostream &os, int64_t number, const Twine &msg);
46ece8a530Spatrick 
471cf9926bSpatrick void writePtrConst(raw_ostream &os, int64_t number, bool is64,
481cf9926bSpatrick                    const Twine &msg);
491cf9926bSpatrick 
50bb684c34Spatrick void writeMemArg(raw_ostream &os, uint32_t alignment, uint64_t offset);
51ece8a530Spatrick 
52ece8a530Spatrick void writeInitExpr(raw_ostream &os, const llvm::wasm::WasmInitExpr &initExpr);
53ece8a530Spatrick 
54*dfe94b16Srobert void writeInitExprMVP(raw_ostream &os,
55*dfe94b16Srobert                       const llvm::wasm::WasmInitExprMVP &initExpr);
56*dfe94b16Srobert 
57ece8a530Spatrick void writeLimits(raw_ostream &os, const llvm::wasm::WasmLimits &limits);
58ece8a530Spatrick 
59ece8a530Spatrick void writeGlobalType(raw_ostream &os, const llvm::wasm::WasmGlobalType &type);
60ece8a530Spatrick 
611cf9926bSpatrick void writeTableType(raw_ostream &os, const llvm::wasm::WasmTableType &type);
62ece8a530Spatrick 
63ece8a530Spatrick void writeImport(raw_ostream &os, const llvm::wasm::WasmImport &import);
64ece8a530Spatrick 
65ece8a530Spatrick void writeExport(raw_ostream &os, const llvm::wasm::WasmExport &export_);
66ece8a530Spatrick 
67ece8a530Spatrick } // namespace wasm
68ece8a530Spatrick 
69ece8a530Spatrick std::string toString(llvm::wasm::ValType type);
70ece8a530Spatrick std::string toString(const llvm::wasm::WasmSignature &sig);
71ece8a530Spatrick std::string toString(const llvm::wasm::WasmGlobalType &type);
721cf9926bSpatrick std::string toString(const llvm::wasm::WasmTableType &type);
73ece8a530Spatrick 
74ece8a530Spatrick } // namespace lld
75ece8a530Spatrick 
76ece8a530Spatrick #endif // LLD_WASM_WRITERUTILS_H
77