mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:57:35 +00:00
LibJS: Add Bytecode::Executable::dump()
Let's have a helper for producing a consistent executable dump instead of repeating the logic in multiple places.
This commit is contained in:
parent
b41954182a
commit
da77e2aa4f
5 changed files with 56 additions and 30 deletions
21
Userland/Libraries/LibJS/Bytecode/Executable.cpp
Normal file
21
Userland/Libraries/LibJS/Bytecode/Executable.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Bytecode/Executable.h>
|
||||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
void Executable::dump() const
|
||||
{
|
||||
for (auto& block : basic_blocks)
|
||||
block.dump(*this);
|
||||
if (!string_table->is_empty()) {
|
||||
outln();
|
||||
string_table->dump();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
25
Userland/Libraries/LibJS/Bytecode/Executable.h
Normal file
25
Userland/Libraries/LibJS/Bytecode/Executable.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/NonnullOwnPtrVector.h>
|
||||
#include <LibJS/Bytecode/BasicBlock.h>
|
||||
#include <LibJS/Bytecode/StringTable.h>
|
||||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
struct Executable {
|
||||
NonnullOwnPtrVector<BasicBlock> basic_blocks;
|
||||
NonnullOwnPtr<StringTable> string_table;
|
||||
size_t number_of_registers { 0 };
|
||||
|
||||
String const& get_string(StringTableIndex index) const { return string_table->get(index); }
|
||||
|
||||
void dump() const;
|
||||
};
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
#include <AK/OwnPtr.h>
|
||||
#include <AK/SinglyLinkedList.h>
|
||||
#include <LibJS/Bytecode/BasicBlock.h>
|
||||
#include <LibJS/Bytecode/Executable.h>
|
||||
#include <LibJS/Bytecode/Label.h>
|
||||
#include <LibJS/Bytecode/Op.h>
|
||||
#include <LibJS/Bytecode/Register.h>
|
||||
|
@ -18,14 +19,6 @@
|
|||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
struct Executable {
|
||||
NonnullOwnPtrVector<BasicBlock> basic_blocks;
|
||||
NonnullOwnPtr<StringTable> 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue