1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:37:35 +00:00

LibWasm: Port Wasm::Printer to Core::Stream

This commit is contained in:
Tim Schumacher 2023-01-21 10:29:21 +01:00 committed by Ali Mohammad Pur
parent 4bad4dc8d5
commit 409fb0fe79
4 changed files with 17 additions and 19 deletions

View file

@ -87,8 +87,7 @@ void Configuration::dump_stack()
{
auto print_value = []<typename... Ts>(CheckedFormatString<Ts...> format, Ts... vs) {
Core::Stream::AllocatingMemoryStream memory_stream;
Core::Stream::WrapInAKOutputStream wrapped_memory_stream { memory_stream };
Printer { wrapped_memory_stream }.print(vs...);
Printer { memory_stream }.print(vs...);
auto buffer = ByteBuffer::create_uninitialized(memory_stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors();
memory_stream.read_entire_buffer(buffer).release_value_but_fixme_should_propagate_errors();
dbgln(format.view(), StringView(buffer).trim_whitespace());

View file

@ -34,7 +34,7 @@ Optional<OpCode> instruction_from_name(StringView name)
void Printer::print_indent()
{
for (size_t i = 0; i < m_indent; ++i)
m_stream.write_or_error(" "sv.bytes());
m_stream.write_entire_buffer(" "sv.bytes()).release_value_but_fixme_should_propagate_errors();
}
void Printer::print(Wasm::BlockType const& type)

View file

@ -6,6 +6,7 @@
#pragma once
#include <LibCore/Stream.h>
#include <LibWasm/Types.h>
namespace Wasm {
@ -17,7 +18,7 @@ DeprecatedString instruction_name(OpCode const& opcode);
Optional<OpCode> instruction_from_name(StringView name);
struct Printer {
explicit Printer(OutputStream& stream, size_t initial_indent = 0)
explicit Printer(Core::Stream::Stream& stream, size_t initial_indent = 0)
: m_stream(stream)
, m_indent(initial_indent)
{
@ -68,10 +69,10 @@ private:
{
StringBuilder builder;
builder.appendff(fmt.view(), forward<Args>(args)...);
m_stream.write_or_error(builder.string_view().bytes());
m_stream.write_entire_buffer(builder.string_view().bytes()).release_value_but_fixme_should_propagate_errors();
}
OutputStream& m_stream;
Core::Stream::Stream& m_stream;
size_t m_indent { 0 };
};