2021-10-24 11:30:49 +00:00
|
|
|
/*
|
2023-07-08 15:43:26 +00:00
|
|
|
* Copyright (c) 2021-2023, 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-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>
|
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-10-20 10:21:30 +00:00
|
|
|
#include <LibJS/JIT/NativeExecutable.h>
|
2023-10-26 08:39:40 +00:00
|
|
|
#include <LibJS/Runtime/EnvironmentCoordinate.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;
|
2023-07-10 18:45:31 +00:00
|
|
|
u64 unique_shape_serial_number { 0 };
|
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-10-03 06:18:10 +00:00
|
|
|
class Executable final : public RefCounted<Executable> {
|
|
|
|
public:
|
|
|
|
Executable(
|
|
|
|
NonnullOwnPtr<IdentifierTable>,
|
|
|
|
NonnullOwnPtr<StringTable>,
|
|
|
|
NonnullOwnPtr<RegexTable>,
|
|
|
|
NonnullRefPtr<SourceCode const>,
|
|
|
|
size_t number_of_property_lookup_caches,
|
|
|
|
size_t number_of_global_variable_caches,
|
2023-10-26 08:39:40 +00:00
|
|
|
size_t number_of_environment_variable_caches,
|
2023-10-03 06:18:10 +00:00
|
|
|
size_t number_of_registers,
|
|
|
|
Vector<NonnullOwnPtr<BasicBlock>>,
|
|
|
|
bool is_strict_mode);
|
|
|
|
|
|
|
|
~Executable();
|
|
|
|
|
2023-01-09 00:23:00 +00:00
|
|
|
DeprecatedFlyString name;
|
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;
|
2023-10-26 08:39:40 +00:00
|
|
|
Vector<Optional<EnvironmentCoordinate>> environment_variable_caches;
|
2023-03-06 16:16:25 +00:00
|
|
|
Vector<NonnullOwnPtr<BasicBlock>> basic_blocks;
|
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;
|
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
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString 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
|
|
|
|
|
|
|
void dump() const;
|
2023-10-20 10:21:30 +00:00
|
|
|
|
|
|
|
JIT::NativeExecutable const* get_or_create_native_executable();
|
|
|
|
|
|
|
|
private:
|
|
|
|
OwnPtr<JIT::NativeExecutable> m_native_executable;
|
|
|
|
bool m_did_try_jitting { false };
|
2021-10-24 11:30:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|