2021-04-27 22:13:01 +04:30
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2025-08-08 12:10:39 -07:00
|
|
|
#include <LibWasm/Export.h>
|
2021-04-27 22:13:01 +04:30
|
|
|
#include <LibWasm/Types.h>
|
|
|
|
|
|
|
|
namespace Wasm {
|
|
|
|
|
2021-09-30 23:30:46 +02:00
|
|
|
class Reference;
|
2021-06-04 03:30:09 +04:30
|
|
|
class Value;
|
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString instruction_name(OpCode const& opcode);
|
2021-12-04 18:00:30 +03:30
|
|
|
Optional<OpCode> instruction_from_name(StringView name);
|
2021-05-01 03:19:01 +04:30
|
|
|
|
2025-08-08 12:10:39 -07:00
|
|
|
struct WASM_API Printer {
|
2023-02-10 01:00:18 +01:00
|
|
|
explicit Printer(Stream& stream, size_t initial_indent = 0)
|
2021-04-27 22:13:01 +04:30
|
|
|
: m_stream(stream)
|
2021-05-01 01:07:08 +04:30
|
|
|
, m_indent(initial_indent)
|
2021-04-27 22:13:01 +04:30
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-04 03:42:11 +04:30
|
|
|
void print(Wasm::BlockType const&);
|
|
|
|
void print(Wasm::CodeSection const&);
|
|
|
|
void print(Wasm::CodeSection::Code const&);
|
|
|
|
void print(Wasm::CodeSection::Func const&);
|
|
|
|
void print(Wasm::CustomSection const&);
|
|
|
|
void print(Wasm::DataCountSection const&);
|
|
|
|
void print(Wasm::DataSection const&);
|
|
|
|
void print(Wasm::DataSection::Data const&);
|
|
|
|
void print(Wasm::ElementSection const&);
|
|
|
|
void print(Wasm::ElementSection::Element const&);
|
|
|
|
void print(Wasm::ExportSection const&);
|
|
|
|
void print(Wasm::ExportSection::Export const&);
|
|
|
|
void print(Wasm::Expression const&);
|
|
|
|
void print(Wasm::FunctionSection const&);
|
|
|
|
void print(Wasm::FunctionType const&);
|
|
|
|
void print(Wasm::GlobalSection const&);
|
|
|
|
void print(Wasm::GlobalSection::Global const&);
|
|
|
|
void print(Wasm::GlobalType const&);
|
|
|
|
void print(Wasm::ImportSection const&);
|
|
|
|
void print(Wasm::ImportSection::Import const&);
|
2025-09-25 03:35:34 +02:00
|
|
|
void print(Wasm::TagSection const&);
|
|
|
|
void print(Wasm::TagSection::Tag const&);
|
2021-06-04 03:42:11 +04:30
|
|
|
void print(Wasm::Instruction const&);
|
|
|
|
void print(Wasm::Limits const&);
|
|
|
|
void print(Wasm::Locals const&);
|
|
|
|
void print(Wasm::MemorySection const&);
|
|
|
|
void print(Wasm::MemorySection::Memory const&);
|
|
|
|
void print(Wasm::MemoryType const&);
|
|
|
|
void print(Wasm::Module const&);
|
|
|
|
void print(Wasm::Reference const&);
|
|
|
|
void print(Wasm::StartSection const&);
|
|
|
|
void print(Wasm::StartSection::StartFunction const&);
|
|
|
|
void print(Wasm::TableSection const&);
|
|
|
|
void print(Wasm::TableSection::Table const&);
|
|
|
|
void print(Wasm::TableType const&);
|
|
|
|
void print(Wasm::TypeSection const&);
|
|
|
|
void print(Wasm::ValueType const&);
|
2025-09-25 03:35:34 +02:00
|
|
|
void print(Wasm::TagType const&);
|
2021-06-04 03:42:11 +04:30
|
|
|
void print(Wasm::Value const&);
|
2024-08-04 08:06:50 -07:00
|
|
|
void print(Wasm::Value const&, ValueType const&);
|
2025-09-25 03:35:34 +02:00
|
|
|
void print(Wasm::Catch const&);
|
|
|
|
void print(Wasm::TypeIndex const&);
|
2021-04-27 22:13:01 +04:30
|
|
|
|
|
|
|
private:
|
|
|
|
void print_indent();
|
|
|
|
template<typename... Args>
|
|
|
|
void print(CheckedFormatString<Args...> fmt, Args&&... args)
|
|
|
|
{
|
|
|
|
StringBuilder builder;
|
|
|
|
builder.appendff(fmt.view(), forward<Args>(args)...);
|
2023-03-01 15:37:45 +01:00
|
|
|
m_stream.write_until_depleted(builder.string_view().bytes()).release_value_but_fixme_should_propagate_errors();
|
2021-04-27 22:13:01 +04:30
|
|
|
}
|
|
|
|
|
2023-02-10 01:00:18 +01:00
|
|
|
Stream& m_stream;
|
2021-04-27 22:13:01 +04:30
|
|
|
size_t m_indent { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|