mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-21 19:30:27 +00:00
LibJS: Add dump_to_string() for AST nodes and bytecode executables
Add the ability to dump AST and bytecode to a String instead of only to stdout/stderr. This is done by adding an optional StringBuilder output sink to ASTDumpState, and a new dump_to_string() method on both ASTNode and Bytecode::Executable. These will be used for comparing output between compilation pipelines.
This commit is contained in:
parent
234203ed9b
commit
7f0e59396f
Notes:
github-actions[bot]
2026-02-24 08:41:46 +00:00
Author: https://github.com/awesomekling
Commit: 7f0e59396f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8104
4 changed files with 72 additions and 8 deletions
|
|
@ -92,6 +92,45 @@ void Executable::dump() const
|
|||
warnln("");
|
||||
}
|
||||
|
||||
String Executable::dump_to_string() const
|
||||
{
|
||||
StringBuilder output;
|
||||
output.appendff("JS bytecode executable \"{}\"\n", name);
|
||||
InstructionStreamIterator it(bytecode, this);
|
||||
|
||||
size_t basic_block_offset_index = 0;
|
||||
|
||||
while (!it.at_end()) {
|
||||
bool print_basic_block_marker = false;
|
||||
if (basic_block_offset_index < basic_block_start_offsets.size()
|
||||
&& it.offset() == basic_block_start_offsets[basic_block_offset_index]) {
|
||||
++basic_block_offset_index;
|
||||
print_basic_block_marker = true;
|
||||
}
|
||||
|
||||
output.appendff("[{:4x}] ", it.offset());
|
||||
if (print_basic_block_marker)
|
||||
output.appendff("{:4}: ", basic_block_offset_index - 1);
|
||||
else
|
||||
output.append(" "sv);
|
||||
output.appendff("{}\n", (*it).to_byte_string(*this));
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
if (!exception_handlers.is_empty()) {
|
||||
output.append("\nException handlers:\n"sv);
|
||||
for (auto& handlers : exception_handlers) {
|
||||
output.appendff(" from {:4x} to {:4x} handler {:4x}\n",
|
||||
handlers.start_offset,
|
||||
handlers.end_offset,
|
||||
handlers.handler_offset);
|
||||
}
|
||||
}
|
||||
|
||||
return output.to_string_without_validation();
|
||||
}
|
||||
|
||||
void Executable::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue