mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00
LibJS/Bytecode: Add constants table to Bytecode::Executable
This commit is contained in:
parent
3466771492
commit
e46de4eb59
4 changed files with 16 additions and 0 deletions
|
@ -17,6 +17,7 @@ Executable::Executable(
|
||||||
NonnullOwnPtr<IdentifierTable> identifier_table,
|
NonnullOwnPtr<IdentifierTable> identifier_table,
|
||||||
NonnullOwnPtr<StringTable> string_table,
|
NonnullOwnPtr<StringTable> string_table,
|
||||||
NonnullOwnPtr<RegexTable> regex_table,
|
NonnullOwnPtr<RegexTable> regex_table,
|
||||||
|
Vector<Value> constants,
|
||||||
NonnullRefPtr<SourceCode const> source_code,
|
NonnullRefPtr<SourceCode const> source_code,
|
||||||
size_t number_of_property_lookup_caches,
|
size_t number_of_property_lookup_caches,
|
||||||
size_t number_of_global_variable_caches,
|
size_t number_of_global_variable_caches,
|
||||||
|
@ -28,6 +29,7 @@ Executable::Executable(
|
||||||
, string_table(move(string_table))
|
, string_table(move(string_table))
|
||||||
, identifier_table(move(identifier_table))
|
, identifier_table(move(identifier_table))
|
||||||
, regex_table(move(regex_table))
|
, regex_table(move(regex_table))
|
||||||
|
, constants(move(constants))
|
||||||
, source_code(move(source_code))
|
, source_code(move(source_code))
|
||||||
, number_of_registers(number_of_registers)
|
, number_of_registers(number_of_registers)
|
||||||
, is_strict_mode(is_strict_mode)
|
, is_strict_mode(is_strict_mode)
|
||||||
|
|
|
@ -51,6 +51,7 @@ public:
|
||||||
NonnullOwnPtr<IdentifierTable>,
|
NonnullOwnPtr<IdentifierTable>,
|
||||||
NonnullOwnPtr<StringTable>,
|
NonnullOwnPtr<StringTable>,
|
||||||
NonnullOwnPtr<RegexTable>,
|
NonnullOwnPtr<RegexTable>,
|
||||||
|
Vector<Value> constants,
|
||||||
NonnullRefPtr<SourceCode const>,
|
NonnullRefPtr<SourceCode const>,
|
||||||
size_t number_of_property_lookup_caches,
|
size_t number_of_property_lookup_caches,
|
||||||
size_t number_of_global_variable_caches,
|
size_t number_of_global_variable_caches,
|
||||||
|
@ -69,6 +70,7 @@ public:
|
||||||
NonnullOwnPtr<StringTable> string_table;
|
NonnullOwnPtr<StringTable> string_table;
|
||||||
NonnullOwnPtr<IdentifierTable> identifier_table;
|
NonnullOwnPtr<IdentifierTable> identifier_table;
|
||||||
NonnullOwnPtr<RegexTable> regex_table;
|
NonnullOwnPtr<RegexTable> regex_table;
|
||||||
|
Vector<Value> constants;
|
||||||
|
|
||||||
NonnullRefPtr<SourceCode const> source_code;
|
NonnullRefPtr<SourceCode const> source_code;
|
||||||
size_t number_of_registers { 0 };
|
size_t number_of_registers { 0 };
|
||||||
|
|
|
@ -62,6 +62,7 @@ CodeGenerationErrorOr<NonnullGCPtr<Executable>> Generator::generate(VM& vm, ASTN
|
||||||
move(generator.m_identifier_table),
|
move(generator.m_identifier_table),
|
||||||
move(generator.m_string_table),
|
move(generator.m_string_table),
|
||||||
move(generator.m_regex_table),
|
move(generator.m_regex_table),
|
||||||
|
move(generator.m_constants),
|
||||||
node.source_code(),
|
node.source_code(),
|
||||||
generator.m_next_property_lookup_cache,
|
generator.m_next_property_lookup_cache,
|
||||||
generator.m_next_global_variable_cache,
|
generator.m_next_global_variable_cache,
|
||||||
|
|
|
@ -241,6 +241,16 @@ public:
|
||||||
[[nodiscard]] size_t next_environment_variable_cache() { return m_next_environment_variable_cache++; }
|
[[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]] 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:
|
private:
|
||||||
enum class JumpType {
|
enum class JumpType {
|
||||||
Continue,
|
Continue,
|
||||||
|
@ -267,6 +277,7 @@ private:
|
||||||
NonnullOwnPtr<StringTable> m_string_table;
|
NonnullOwnPtr<StringTable> m_string_table;
|
||||||
NonnullOwnPtr<IdentifierTable> m_identifier_table;
|
NonnullOwnPtr<IdentifierTable> m_identifier_table;
|
||||||
NonnullOwnPtr<RegexTable> m_regex_table;
|
NonnullOwnPtr<RegexTable> m_regex_table;
|
||||||
|
Vector<Value> m_constants;
|
||||||
|
|
||||||
u32 m_next_register { Register::reserved_register_count };
|
u32 m_next_register { Register::reserved_register_count };
|
||||||
u32 m_next_block { 1 };
|
u32 m_next_block { 1 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue