mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
LibWasm: Use AllocatingMemoryStream
around Wasm::Printer
This commit is contained in:
parent
7d4a30af56
commit
52cb066cae
2 changed files with 12 additions and 6 deletions
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibCore/MemoryStream.h>
|
||||||
#include <LibWasm/AbstractMachine/Configuration.h>
|
#include <LibWasm/AbstractMachine/Configuration.h>
|
||||||
#include <LibWasm/AbstractMachine/Interpreter.h>
|
#include <LibWasm/AbstractMachine/Interpreter.h>
|
||||||
#include <LibWasm/Printer/Printer.h>
|
#include <LibWasm/Printer/Printer.h>
|
||||||
|
@ -85,9 +86,11 @@ Result Configuration::execute(Interpreter& interpreter)
|
||||||
void Configuration::dump_stack()
|
void Configuration::dump_stack()
|
||||||
{
|
{
|
||||||
auto print_value = []<typename... Ts>(CheckedFormatString<Ts...> format, Ts... vs) {
|
auto print_value = []<typename... Ts>(CheckedFormatString<Ts...> format, Ts... vs) {
|
||||||
DuplexMemoryStream memory_stream;
|
Core::Stream::AllocatingMemoryStream memory_stream;
|
||||||
Printer { memory_stream }.print(vs...);
|
Core::Stream::WrapInAKOutputStream wrapped_memory_stream { memory_stream };
|
||||||
ByteBuffer buffer = memory_stream.copy_into_contiguous_buffer();
|
Printer { wrapped_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());
|
dbgln(format.view(), StringView(buffer).trim_whitespace());
|
||||||
};
|
};
|
||||||
for (auto const& entry : stack().entries()) {
|
for (auto const& entry : stack().entries()) {
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/FileStream.h>
|
#include <LibCore/FileStream.h>
|
||||||
#include <LibCore/MappedFile.h>
|
#include <LibCore/MappedFile.h>
|
||||||
|
#include <LibCore/MemoryStream.h>
|
||||||
#include <LibLine/Editor.h>
|
#include <LibLine/Editor.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <LibWasm/AbstractMachine/AbstractMachine.h>
|
#include <LibWasm/AbstractMachine/AbstractMachine.h>
|
||||||
|
@ -396,13 +397,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
StringBuilder argument_builder;
|
StringBuilder argument_builder;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto& argument : arguments) {
|
for (auto& argument : arguments) {
|
||||||
DuplexMemoryStream stream;
|
Core::Stream::AllocatingMemoryStream stream;
|
||||||
Wasm::Printer { stream }.print(argument);
|
Core::Stream::WrapInAKOutputStream wrapped_stream { stream };
|
||||||
|
Wasm::Printer { wrapped_stream }.print(argument);
|
||||||
if (first)
|
if (first)
|
||||||
first = false;
|
first = false;
|
||||||
else
|
else
|
||||||
argument_builder.append(", "sv);
|
argument_builder.append(", "sv);
|
||||||
ByteBuffer buffer = stream.copy_into_contiguous_buffer();
|
auto buffer = ByteBuffer::create_uninitialized(stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors();
|
||||||
|
stream.read_entire_buffer(buffer).release_value_but_fixme_should_propagate_errors();
|
||||||
argument_builder.append(StringView(buffer).trim_whitespace());
|
argument_builder.append(StringView(buffer).trim_whitespace());
|
||||||
}
|
}
|
||||||
dbgln("[wasm runtime] Stub function {} was called with the following arguments: {}", name, argument_builder.to_deprecated_string());
|
dbgln("[wasm runtime] Stub function {} was called with the following arguments: {}", name, argument_builder.to_deprecated_string());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue