From da77e2aa4f993557174a09dbaa3a1f639db8ddec Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 24 Oct 2021 13:30:49 +0200 Subject: LibJS: Add Bytecode::Executable::dump() Let's have a helper for producing a consistent executable dump instead of repeating the logic in multiple places. --- Userland/Libraries/LibJS/Bytecode/Executable.cpp | 21 ++++++++++++++++++++ Userland/Libraries/LibJS/Bytecode/Executable.h | 25 ++++++++++++++++++++++++ Userland/Libraries/LibJS/Bytecode/Generator.h | 9 +-------- 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 Userland/Libraries/LibJS/Bytecode/Executable.cpp create mode 100644 Userland/Libraries/LibJS/Bytecode/Executable.h (limited to 'Userland/Libraries/LibJS/Bytecode') diff --git a/Userland/Libraries/LibJS/Bytecode/Executable.cpp b/Userland/Libraries/LibJS/Bytecode/Executable.cpp new file mode 100644 index 0000000000..caa34ba450 --- /dev/null +++ b/Userland/Libraries/LibJS/Bytecode/Executable.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace JS::Bytecode { + +void Executable::dump() const +{ + for (auto& block : basic_blocks) + block.dump(*this); + if (!string_table->is_empty()) { + outln(); + string_table->dump(); + } +} + +} diff --git a/Userland/Libraries/LibJS/Bytecode/Executable.h b/Userland/Libraries/LibJS/Bytecode/Executable.h new file mode 100644 index 0000000000..7b20e8004d --- /dev/null +++ b/Userland/Libraries/LibJS/Bytecode/Executable.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace JS::Bytecode { + +struct Executable { + NonnullOwnPtrVector basic_blocks; + NonnullOwnPtr string_table; + size_t number_of_registers { 0 }; + + String const& get_string(StringTableIndex index) const { return string_table->get(index); } + + void dump() const; +}; + +} diff --git a/Userland/Libraries/LibJS/Bytecode/Generator.h b/Userland/Libraries/LibJS/Bytecode/Generator.h index 49b34e138a..a0491deaaf 100644 --- a/Userland/Libraries/LibJS/Bytecode/Generator.h +++ b/Userland/Libraries/LibJS/Bytecode/Generator.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -18,14 +19,6 @@ namespace JS::Bytecode { -struct Executable { - NonnullOwnPtrVector basic_blocks; - NonnullOwnPtr string_table; - size_t number_of_registers { 0 }; - - String const& get_string(StringTableIndex index) const { return string_table->get(index); } -}; - class Generator { public: static Executable generate(ASTNode const&, bool is_in_generator_function = false); -- cgit v1.2.3