mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-06-22 17:30:44 +00:00
Store source map locations as bytecode offset, line, and column. Runtime consumers only emit the start line and column, so source end positions and source text offsets do not need to be carried through Executable source maps, bytecode cache serialization, or the Rust FFI. Keep SourceCode's internal position cache able to track source text offsets so callers can still translate source offsets to line and column pairs when needed. Hash dump-bytecode IDs from the name, first source position, and bytecode size instead of source slices that need end offsets. Bump the bytecode cache format version for the slimmer serialized source map entry shape.
74 lines
2.1 KiB
C++
74 lines
2.1 KiB
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Badge.h>
|
|
#include <AK/String.h>
|
|
#include <LibJS/Bytecode/Executable.h>
|
|
#include <LibJS/Forward.h>
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
class BasicBlock {
|
|
AK_MAKE_NONCOPYABLE(BasicBlock);
|
|
|
|
public:
|
|
static NonnullOwnPtr<BasicBlock> create(u32 index, String name);
|
|
~BasicBlock();
|
|
|
|
u32 index() const { return m_index; }
|
|
|
|
ReadonlyBytes instruction_stream() const LIFETIME_BOUND { return m_buffer.span(); }
|
|
u8* data() { return m_buffer.data(); }
|
|
u8 const* data() const { return m_buffer.data(); }
|
|
size_t size() const { return m_buffer.size(); }
|
|
|
|
void rewind()
|
|
{
|
|
m_buffer.resize_and_keep_capacity(m_last_instruction_start_offset);
|
|
m_terminated = false;
|
|
}
|
|
|
|
void grow(size_t additional_size);
|
|
|
|
void terminate(Badge<Generator>) { m_terminated = true; }
|
|
bool is_terminated() const { return m_terminated; }
|
|
|
|
String const& name() const { return m_name; }
|
|
|
|
void set_handler(BasicBlock const& handler) { m_handler = &handler; }
|
|
|
|
BasicBlock const* handler() const { return m_handler; }
|
|
|
|
auto const& source_map() const { return m_source_map; }
|
|
void add_source_map_entry(u32 bytecode_offset, Position source_start)
|
|
{
|
|
m_source_map.append({ bytecode_offset, source_start.line, source_start.column });
|
|
}
|
|
|
|
[[nodiscard]] bool has_resolved_this() const { return m_has_resolved_this; }
|
|
void set_has_resolved_this() { m_has_resolved_this = true; }
|
|
|
|
[[nodiscard]] size_t last_instruction_start_offset() const { return m_last_instruction_start_offset; }
|
|
void set_last_instruction_start_offset(size_t offset) { m_last_instruction_start_offset = offset; }
|
|
|
|
private:
|
|
explicit BasicBlock(u32 index, String name);
|
|
|
|
u32 m_index { 0 };
|
|
Vector<u8> m_buffer;
|
|
BasicBlock const* m_handler { nullptr };
|
|
String m_name;
|
|
bool m_terminated { false };
|
|
bool m_has_resolved_this { false };
|
|
|
|
Vector<SourceMapEntry> m_source_map;
|
|
|
|
size_t m_last_instruction_start_offset { 0 };
|
|
};
|
|
|
|
}
|