mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:37:35 +00:00
LibWasm: Add a module pretty printer
This commit is contained in:
parent
7a12f23c28
commit
bd8dac111c
5 changed files with 885 additions and 16 deletions
72
Userland/Libraries/LibWasm/Printer/Printer.h
Normal file
72
Userland/Libraries/LibWasm/Printer/Printer.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWasm/Types.h>
|
||||
|
||||
namespace Wasm {
|
||||
|
||||
struct Printer {
|
||||
explicit Printer(OutputStream& stream)
|
||||
: m_stream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
void print(const Wasm::BlockType&);
|
||||
void print(const Wasm::CodeSection&);
|
||||
void print(const Wasm::CodeSection::Code&);
|
||||
void print(const Wasm::ConstrainedStream&);
|
||||
void print(const Wasm::CustomSection&);
|
||||
void print(const Wasm::DataCountSection&);
|
||||
void print(const Wasm::DataSection&);
|
||||
void print(const Wasm::DataSection::Data&);
|
||||
void print(const Wasm::ElementSection&);
|
||||
void print(const Wasm::ElementSection::Element&);
|
||||
void print(const Wasm::ExportSection&);
|
||||
void print(const Wasm::ExportSection::Export&);
|
||||
void print(const Wasm::Expression&);
|
||||
void print(const Wasm::Func&);
|
||||
void print(const Wasm::FunctionSection&);
|
||||
void print(const Wasm::FunctionType&);
|
||||
void print(const Wasm::GlobalSection&);
|
||||
void print(const Wasm::GlobalSection::Global&);
|
||||
void print(const Wasm::GlobalType&);
|
||||
void print(const Wasm::ImportSection&);
|
||||
void print(const Wasm::ImportSection::Import&);
|
||||
void print(const Wasm::Instruction&);
|
||||
void print(const Wasm::Limits&);
|
||||
void print(const Wasm::Locals&);
|
||||
void print(const Wasm::MemorySection&);
|
||||
void print(const Wasm::MemorySection::Memory&);
|
||||
void print(const Wasm::MemoryType&);
|
||||
void print(const Wasm::Module&);
|
||||
void print(const Wasm::Module::Function&);
|
||||
void print(const Wasm::ReconsumableStream&);
|
||||
void print(const Wasm::ResultType&);
|
||||
void print(const Wasm::StartSection&);
|
||||
void print(const Wasm::StartSection::StartFunction&);
|
||||
void print(const Wasm::TableSection&);
|
||||
void print(const Wasm::TableSection::Table&);
|
||||
void print(const Wasm::TableType&);
|
||||
void print(const Wasm::TypeSection&);
|
||||
void print(const Wasm::ValueType&);
|
||||
|
||||
private:
|
||||
void print_indent();
|
||||
template<typename... Args>
|
||||
void print(CheckedFormatString<Args...> fmt, Args&&... args)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.appendff(fmt.view(), forward<Args>(args)...);
|
||||
m_stream.write_or_error(builder.string_view().bytes());
|
||||
}
|
||||
|
||||
OutputStream& m_stream;
|
||||
size_t m_indent { 0 };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue