Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 1 | //===- WriterUtils.h --------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // 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 Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLD_WASM_WRITERUTILS_H |
| 10 | #define LLD_WASM_WRITERUTILS_H |
| 11 | |
Rui Ueyama | 1184253 | 2018-02-16 20:38:00 +0000 | [diff] [blame] | 12 | #include "lld/Common/LLVM.h" |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/Twine.h" |
| 14 | #include "llvm/Object/Wasm.h" |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 15 | |
| 16 | namespace lld { |
| 17 | namespace wasm { |
| 18 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 19 | void debugWrite(uint64_t offset, const Twine &msg); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 20 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 21 | void writeUleb128(raw_ostream &os, uint32_t number, const Twine &msg); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 22 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 23 | void writeSleb128(raw_ostream &os, int32_t number, const Twine &msg); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 24 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 25 | void writeBytes(raw_ostream &os, const char *bytes, size_t count, |
| 26 | const Twine &msg); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 27 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 28 | void writeStr(raw_ostream &os, StringRef string, const Twine &msg); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 29 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 30 | void writeU8(raw_ostream &os, uint8_t byte, const Twine &msg); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 31 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 32 | void writeU32(raw_ostream &os, uint32_t number, const Twine &msg); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 33 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 34 | void writeValueType(raw_ostream &os, llvm::wasm::ValType type, |
| 35 | const Twine &msg); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 36 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 37 | void writeSig(raw_ostream &os, const llvm::wasm::WasmSignature &sig); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 38 | |
Thomas Lively | 09768c5 | 2019-09-04 19:50:39 +0000 | [diff] [blame] | 39 | void writeI32Const(raw_ostream &os, int32_t number, const Twine &msg); |
| 40 | |
| 41 | void writeI64Const(raw_ostream &os, int32_t number, const Twine &msg); |
| 42 | |
| 43 | void writeMemArg(raw_ostream &os, uint32_t alignment, uint32_t offset); |
| 44 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 45 | void writeInitExpr(raw_ostream &os, const llvm::wasm::WasmInitExpr &initExpr); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 46 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 47 | void writeLimits(raw_ostream &os, const llvm::wasm::WasmLimits &limits); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 48 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 49 | void writeGlobalType(raw_ostream &os, const llvm::wasm::WasmGlobalType &type); |
Sam Clegg | 1a9b7b9 | 2018-01-31 19:54:34 +0000 | [diff] [blame] | 50 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 51 | void writeGlobal(raw_ostream &os, const llvm::wasm::WasmGlobal &global); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 52 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 53 | void writeEventType(raw_ostream &os, const llvm::wasm::WasmEventType &type); |
Heejin Ahn | e915a71 | 2018-12-08 06:17:43 +0000 | [diff] [blame] | 54 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 55 | void writeEvent(raw_ostream &os, const llvm::wasm::WasmEvent &event); |
Heejin Ahn | e915a71 | 2018-12-08 06:17:43 +0000 | [diff] [blame] | 56 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 57 | void writeTableType(raw_ostream &os, const llvm::wasm::WasmTable &type); |
Nicholas Wilson | 874eedd | 2018-03-27 17:38:51 +0000 | [diff] [blame] | 58 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 59 | void writeImport(raw_ostream &os, const llvm::wasm::WasmImport &import); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 60 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 61 | void writeExport(raw_ostream &os, const llvm::wasm::WasmExport &export_); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 62 | |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 63 | } // namespace wasm |
Sam Clegg | b862159 | 2017-11-30 01:40:08 +0000 | [diff] [blame] | 64 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 +0000 | [diff] [blame] | 65 | std::string toString(llvm::wasm::ValType type); |
| 66 | std::string toString(const llvm::wasm::WasmSignature &sig); |
| 67 | std::string toString(const llvm::wasm::WasmGlobalType &type); |
| 68 | std::string toString(const llvm::wasm::WasmEventType &type); |
Sam Clegg | b862159 | 2017-11-30 01:40:08 +0000 | [diff] [blame] | 69 | |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 70 | } // namespace lld |
| 71 | |
| 72 | #endif // LLD_WASM_WRITERUTILS_H |