summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2023-01-21 10:29:21 +0100
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2023-01-25 17:10:05 +0330
commit409fb0fe79071686590cfd1fdbc815193a15d795 (patch)
tree3e65aeb2fdd9261b777192ab1bc3930a4ebd535f /Userland
parent4bad4dc8d5cbca8d5ce44413105d110609a6b17a (diff)
downloadserenity-409fb0fe79071686590cfd1fdbc815193a15d795.zip
LibWasm: Port `Wasm::Printer` to `Core::Stream`
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp3
-rw-r--r--Userland/Libraries/LibWasm/Printer/Printer.cpp2
-rw-r--r--Userland/Libraries/LibWasm/Printer/Printer.h7
-rw-r--r--Userland/Utilities/wasm.cpp24
4 files changed, 17 insertions, 19 deletions
diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp b/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp
index 88de3a1459..43cc915617 100644
--- a/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp
+++ b/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp
@@ -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());
diff --git a/Userland/Libraries/LibWasm/Printer/Printer.cpp b/Userland/Libraries/LibWasm/Printer/Printer.cpp
index 19547499e1..24bef8505b 100644
--- a/Userland/Libraries/LibWasm/Printer/Printer.cpp
+++ b/Userland/Libraries/LibWasm/Printer/Printer.cpp
@@ -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)
diff --git a/Userland/Libraries/LibWasm/Printer/Printer.h b/Userland/Libraries/LibWasm/Printer/Printer.h
index cf060674ad..a3aa735a62 100644
--- a/Userland/Libraries/LibWasm/Printer/Printer.h
+++ b/Userland/Libraries/LibWasm/Printer/Printer.h
@@ -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 };
};
diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp
index 94337c98d9..0d21b98bfc 100644
--- a/Userland/Utilities/wasm.cpp
+++ b/Userland/Utilities/wasm.cpp
@@ -19,7 +19,7 @@
#include <unistd.h>
RefPtr<Line::Editor> g_line_editor;
-static OwnPtr<AK::OutputStream> g_stdout {};
+static OwnPtr<Core::Stream::Stream> g_stdout {};
static OwnPtr<Wasm::Printer> g_printer {};
static bool g_continue { false };
static void (*old_signal)(int);
@@ -53,12 +53,12 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi
if (always_print_stack)
config.dump_stack();
if (always_print_instruction) {
- g_stdout->write(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes());
+ g_stdout->write(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors();
g_printer->print(instr);
}
if (g_continue)
return true;
- g_stdout->write(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes());
+ g_stdout->write(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors();
g_printer->print(instr);
DeprecatedString last_command = "";
for (;;) {
@@ -213,7 +213,7 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi
if (!result.values().is_empty())
warnln("Returned:");
for (auto& value : result.values()) {
- g_stdout->write(" -> "sv.bytes());
+ g_stdout->write(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors();
g_printer->print(value);
}
continue;
@@ -339,8 +339,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (!parse_result.has_value())
return 1;
- auto standard_output = TRY(Core::Stream::File::standard_output());
- g_stdout = TRY(try_make<Core::Stream::WrapInAKOutputStream>(*standard_output));
+ g_stdout = TRY(Core::Stream::File::standard_output());
g_printer = TRY(try_make<Wasm::Printer>(*g_stdout));
if (print && !attempt_instantiate) {
@@ -400,8 +399,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
bool first = true;
for (auto& argument : arguments) {
Core::Stream::AllocatingMemoryStream stream;
- Core::Stream::WrapInAKOutputStream wrapped_stream { stream };
- Wasm::Printer { wrapped_stream }.print(argument);
+ Wasm::Printer { stream }.print(argument);
if (first)
first = false;
else
@@ -454,15 +452,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto print_func = [&](auto const& address) {
Wasm::FunctionInstance* fn = machine.store().get(address);
- g_stdout->write(DeprecatedString::formatted("- Function with address {}, ptr = {}\n", address.value(), fn).bytes());
+ g_stdout->write(DeprecatedString::formatted("- Function with address {}, ptr = {}\n", address.value(), fn).bytes()).release_value_but_fixme_should_propagate_errors();
if (fn) {
- g_stdout->write(DeprecatedString::formatted(" wasm function? {}\n", fn->has<Wasm::WasmFunction>()).bytes());
+ g_stdout->write(DeprecatedString::formatted(" wasm function? {}\n", fn->has<Wasm::WasmFunction>()).bytes()).release_value_but_fixme_should_propagate_errors();
fn->visit(
[&](Wasm::WasmFunction const& func) {
Wasm::Printer printer { *g_stdout, 3 };
- g_stdout->write(" type:\n"sv.bytes());
+ g_stdout->write(" type:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors();
printer.print(func.type());
- g_stdout->write(" code:\n"sv.bytes());
+ g_stdout->write(" code:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors();
printer.print(func.code());
},
[](Wasm::HostFunction const&) {});
@@ -526,7 +524,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (!result.values().is_empty())
warnln("Returned:");
for (auto& value : result.values()) {
- g_stdout->write(" -> "sv.bytes());
+ g_stdout->write(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors();
g_printer->print(value);
}
}