2021-10-24 11:30:49 +00:00
|
|
|
/*
|
2024-03-03 10:34:36 +00:00
|
|
|
* Copyright (c) 2021-2024, Andreas Kling <kling@serenityos.org>
|
2021-10-24 11:30:49 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-01-09 00:23:00 +00:00
|
|
|
#include <AK/DeprecatedFlyString.h>
|
2023-10-19 21:18:54 +00:00
|
|
|
#include <AK/HashMap.h>
|
2023-03-06 16:39:59 +00:00
|
|
|
#include <AK/NonnullOwnPtr.h>
|
2023-10-20 10:21:30 +00:00
|
|
|
#include <AK/OwnPtr.h>
|
2023-07-08 15:43:26 +00:00
|
|
|
#include <AK/WeakPtr.h>
|
2021-10-24 13:34:30 +00:00
|
|
|
#include <LibJS/Bytecode/IdentifierTable.h>
|
2023-10-19 21:18:54 +00:00
|
|
|
#include <LibJS/Bytecode/Label.h>
|
2021-10-24 11:30:49 +00:00
|
|
|
#include <LibJS/Bytecode/StringTable.h>
|
2023-10-08 10:25:58 +00:00
|
|
|
#include <LibJS/Forward.h>
|
2023-11-27 12:23:59 +00:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
|
|
|
#include <LibJS/Heap/CellAllocator.h>
|
2023-10-26 08:39:40 +00:00
|
|
|
#include <LibJS/Runtime/EnvironmentCoordinate.h>
|
2024-05-06 04:44:08 +00:00
|
|
|
#include <LibJS/SourceRange.h>
|
2021-10-24 11:30:49 +00:00
|
|
|
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
2023-07-08 15:43:26 +00:00
|
|
|
struct PropertyLookupCache {
|
|
|
|
WeakPtr<Shape> shape;
|
|
|
|
Optional<u32> property_offset;
|
2024-05-04 13:48:23 +00:00
|
|
|
WeakPtr<Object> prototype;
|
|
|
|
WeakPtr<PrototypeChainValidity> prototype_chain_validity;
|
2023-07-08 15:43:26 +00:00
|
|
|
};
|
|
|
|
|
2023-07-12 02:06:59 +00:00
|
|
|
struct GlobalVariableCache : public PropertyLookupCache {
|
|
|
|
u64 environment_serial_number { 0 };
|
|
|
|
};
|
|
|
|
|
2023-09-01 14:53:55 +00:00
|
|
|
struct SourceRecord {
|
|
|
|
u32 source_start_offset {};
|
|
|
|
u32 source_end_offset {};
|
|
|
|
};
|
|
|
|
|
2023-11-27 12:23:59 +00:00
|
|
|
class Executable final : public Cell {
|
|
|
|
JS_CELL(Executable, Cell);
|
|
|
|
JS_DECLARE_ALLOCATOR(Executable);
|
|
|
|
|
2023-10-03 06:18:10 +00:00
|
|
|
public:
|
|
|
|
Executable(
|
2024-05-06 04:44:08 +00:00
|
|
|
Vector<u8> bytecode,
|
2023-10-03 06:18:10 +00:00
|
|
|
NonnullOwnPtr<IdentifierTable>,
|
|
|
|
NonnullOwnPtr<StringTable>,
|
|
|
|
NonnullOwnPtr<RegexTable>,
|
2024-02-02 08:52:25 +00:00
|
|
|
Vector<Value> constants,
|
2023-10-03 06:18:10 +00:00
|
|
|
NonnullRefPtr<SourceCode const>,
|
|
|
|
size_t number_of_property_lookup_caches,
|
|
|
|
size_t number_of_global_variable_caches,
|
|
|
|
size_t number_of_registers,
|
|
|
|
bool is_strict_mode);
|
|
|
|
|
2023-11-27 12:23:59 +00:00
|
|
|
virtual ~Executable() override;
|
2023-10-03 06:18:10 +00:00
|
|
|
|
2023-01-09 00:23:00 +00:00
|
|
|
DeprecatedFlyString name;
|
2024-05-06 04:44:08 +00:00
|
|
|
Vector<u8> bytecode;
|
2023-07-08 15:43:26 +00:00
|
|
|
Vector<PropertyLookupCache> property_lookup_caches;
|
2023-07-12 02:06:59 +00:00
|
|
|
Vector<GlobalVariableCache> global_variable_caches;
|
2021-10-24 11:30:49 +00:00
|
|
|
NonnullOwnPtr<StringTable> string_table;
|
2021-10-24 13:34:30 +00:00
|
|
|
NonnullOwnPtr<IdentifierTable> identifier_table;
|
2023-07-13 08:49:07 +00:00
|
|
|
NonnullOwnPtr<RegexTable> regex_table;
|
2024-02-02 08:52:25 +00:00
|
|
|
Vector<Value> constants;
|
2023-10-19 21:18:54 +00:00
|
|
|
|
2023-09-01 14:53:55 +00:00
|
|
|
NonnullRefPtr<SourceCode const> source_code;
|
2021-10-24 11:30:49 +00:00
|
|
|
size_t number_of_registers { 0 };
|
2022-07-17 17:56:36 +00:00
|
|
|
bool is_strict_mode { false };
|
2021-10-24 11:30:49 +00:00
|
|
|
|
2024-05-06 04:44:08 +00:00
|
|
|
struct ExceptionHandlers {
|
|
|
|
size_t start_offset;
|
|
|
|
size_t end_offset;
|
|
|
|
Optional<size_t> handler_offset;
|
|
|
|
Optional<size_t> finalizer_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<ExceptionHandlers> exception_handlers;
|
|
|
|
Vector<size_t> basic_block_start_offsets;
|
|
|
|
|
2024-05-06 05:51:14 +00:00
|
|
|
HashMap<size_t, SourceRecord> source_map;
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString const& get_string(StringTableIndex index) const { return string_table->get(index); }
|
2023-01-09 00:23:00 +00:00
|
|
|
DeprecatedFlyString const& get_identifier(IdentifierTableIndex index) const { return identifier_table->get(index); }
|
2021-10-24 11:30:49 +00:00
|
|
|
|
2024-03-29 15:26:10 +00:00
|
|
|
Optional<DeprecatedFlyString const&> get_identifier(Optional<IdentifierTableIndex> const& index) const
|
|
|
|
{
|
|
|
|
if (!index.has_value())
|
|
|
|
return {};
|
|
|
|
return get_identifier(*index);
|
|
|
|
}
|
|
|
|
|
2024-05-06 04:44:08 +00:00
|
|
|
[[nodiscard]] Optional<ExceptionHandlers const&> exception_handlers_for_offset(size_t offset) const;
|
|
|
|
|
|
|
|
[[nodiscard]] UnrealizedSourceRange source_range_at(size_t offset) const;
|
|
|
|
|
2021-10-24 11:30:49 +00:00
|
|
|
void dump() const;
|
2024-03-03 10:34:36 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual void visit_edges(Visitor&) override;
|
2021-10-24 11:30:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|