LibJS/Bytecode: Add constants table to Bytecode::Executable

This commit is contained in:
Andreas Kling 2024-02-02 09:52:25 +01:00
parent 3466771492
commit e46de4eb59
Notes: sideshowbarker 2024-07-18 04:46:35 +09:00
4 changed files with 16 additions and 0 deletions

View File

@ -17,6 +17,7 @@ Executable::Executable(
NonnullOwnPtr<IdentifierTable> identifier_table,
NonnullOwnPtr<StringTable> string_table,
NonnullOwnPtr<RegexTable> regex_table,
Vector<Value> constants,
NonnullRefPtr<SourceCode const> source_code,
size_t number_of_property_lookup_caches,
size_t number_of_global_variable_caches,
@ -28,6 +29,7 @@ Executable::Executable(
, string_table(move(string_table))
, identifier_table(move(identifier_table))
, regex_table(move(regex_table))
, constants(move(constants))
, source_code(move(source_code))
, number_of_registers(number_of_registers)
, is_strict_mode(is_strict_mode)

View File

@ -51,6 +51,7 @@ public:
NonnullOwnPtr<IdentifierTable>,
NonnullOwnPtr<StringTable>,
NonnullOwnPtr<RegexTable>,
Vector<Value> constants,
NonnullRefPtr<SourceCode const>,
size_t number_of_property_lookup_caches,
size_t number_of_global_variable_caches,
@ -69,6 +70,7 @@ public:
NonnullOwnPtr<StringTable> string_table;
NonnullOwnPtr<IdentifierTable> identifier_table;
NonnullOwnPtr<RegexTable> regex_table;
Vector<Value> constants;
NonnullRefPtr<SourceCode const> source_code;
size_t number_of_registers { 0 };

View File

@ -62,6 +62,7 @@ CodeGenerationErrorOr<NonnullGCPtr<Executable>> Generator::generate(VM& vm, ASTN
move(generator.m_identifier_table),
move(generator.m_string_table),
move(generator.m_regex_table),
move(generator.m_constants),
node.source_code(),
generator.m_next_property_lookup_cache,
generator.m_next_global_variable_cache,

View File

@ -241,6 +241,16 @@ public:
[[nodiscard]] size_t next_environment_variable_cache() { return m_next_environment_variable_cache++; }
[[nodiscard]] size_t next_property_lookup_cache() { return m_next_property_lookup_cache++; }
[[nodiscard]] Operand add_constant(Value value)
{
for (size_t i = 0; i < m_constants.size(); ++i) {
if (m_constants[i] == value)
return Operand(Operand::Type::Constant, i);
}
m_constants.append(value);
return Operand(Operand::Type::Constant, m_constants.size() - 1);
}
private:
enum class JumpType {
Continue,
@ -267,6 +277,7 @@ private:
NonnullOwnPtr<StringTable> m_string_table;
NonnullOwnPtr<IdentifierTable> m_identifier_table;
NonnullOwnPtr<RegexTable> m_regex_table;
Vector<Value> m_constants;
u32 m_next_register { Register::reserved_register_count };
u32 m_next_block { 1 };