1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00

LibJS: Include executable name in bytecode dumps

This commit is contained in:
Andreas Kling 2021-10-24 14:33:56 +02:00
parent c95dde971b
commit f75d78f56a
6 changed files with 16 additions and 6 deletions

View file

@ -10,6 +10,7 @@ namespace JS::Bytecode {
void Executable::dump() const
{
dbgln("\033[33;1mJS::Bytecode::Executable\033[0m ({})", name);
for (auto& block : basic_blocks)
block.dump(*this);
if (!string_table->is_empty()) {

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/FlyString.h>
#include <AK/NonnullOwnPtrVector.h>
#include <LibJS/Bytecode/BasicBlock.h>
#include <LibJS/Bytecode/StringTable.h>
@ -13,6 +14,7 @@
namespace JS::Bytecode {
struct Executable {
FlyString name;
NonnullOwnPtrVector<BasicBlock> basic_blocks;
NonnullOwnPtr<StringTable> string_table;
size_t number_of_registers { 0 };

View file

@ -44,7 +44,7 @@ Executable Generator::generate(ASTNode const& node, bool is_in_generator_functio
generator.emit<Bytecode::Op::Yield>(nullptr);
}
}
return { move(generator.m_root_basic_blocks), move(generator.m_string_table), generator.m_next_register };
return { {}, move(generator.m_root_basic_blocks), move(generator.m_string_table), generator.m_next_register };
}
void Generator::grow(size_t additional_size)

View file

@ -678,14 +678,15 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
TRY(function_declaration_instantiation(nullptr));
if (!m_bytecode_executable.has_value()) {
m_bytecode_executable = Bytecode::Generator::generate(m_ecmascript_code, m_kind == FunctionKind::Generator);
m_bytecode_executable->name = m_name;
auto& passes = JS::Bytecode::Interpreter::optimization_pipeline();
passes.perform(*m_bytecode_executable);
if constexpr (JS_BYTECODE_DEBUG) {
dbgln("Optimisation passes took {}us", passes.elapsed());
dbgln("Compiled Bytecode::Block for function '{}':", m_name);
for (auto& block : m_bytecode_executable->basic_blocks)
block.dump(*m_bytecode_executable);
}
if (JS::Bytecode::g_dump_bytecode)
m_bytecode_executable->dump();
}
auto result = bytecode_interpreter->run(*m_bytecode_executable);
if (auto* exception = vm.exception())

View file

@ -337,6 +337,7 @@ inline JSFileResult TestRunner::run_file_test(const String& test_path)
if (g_run_bytecode) {
auto executable = JS::Bytecode::Generator::generate(m_test_script->parse_node());
executable.name = test_path;
if (JS::Bytecode::g_dump_bytecode)
executable.dump();
JS::Bytecode::Interpreter bytecode_interpreter(interpreter->global_object(), interpreter->realm());
@ -352,6 +353,7 @@ inline JSFileResult TestRunner::run_file_test(const String& test_path)
return { test_path, file_script.error() };
if (g_run_bytecode) {
auto executable = JS::Bytecode::Generator::generate(file_script.value()->parse_node());
executable.name = test_path;
if (JS::Bytecode::g_dump_bytecode)
executable.dump();
JS::Bytecode::Interpreter bytecode_interpreter(interpreter->global_object(), interpreter->realm());

View file

@ -807,7 +807,7 @@ static bool write_to_file(String const& path)
return true;
}
static bool parse_and_run(JS::Interpreter& interpreter, StringView const& source)
static bool parse_and_run(JS::Interpreter& interpreter, StringView source, StringView source_name)
{
auto program_type = s_as_module ? JS::Program::Type::Module : JS::Program::Type::Script;
auto parser = JS::Parser(JS::Lexer(source), program_type);
@ -825,6 +825,7 @@ static bool parse_and_run(JS::Interpreter& interpreter, StringView const& source
} else {
if (JS::Bytecode::g_dump_bytecode || s_run_bytecode) {
auto executable = JS::Bytecode::Generator::generate(*program);
executable.name = source_name;
if (s_opt_bytecode) {
auto& passes = JS::Bytecode::Interpreter::optimization_pipeline();
passes.perform(executable);
@ -1006,7 +1007,7 @@ static void repl(JS::Interpreter& interpreter)
if (piece.is_empty())
continue;
repl_statements.append(piece);
parse_and_run(interpreter, piece);
parse_and_run(interpreter, piece, "REPL");
}
}
@ -1400,7 +1401,10 @@ int main(int argc, char** argv)
builder.append(source);
}
if (!parse_and_run(*interpreter, builder.to_string()))
StringBuilder source_name_builder;
source_name_builder.join(", ", script_paths);
if (!parse_and_run(*interpreter, builder.string_view(), source_name_builder.string_view()))
return 1;
}