mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:17:35 +00:00
LibJS: Store strings in a string table
Instead of using Strings in the bytecode ops this adds a global string table to the Executable struct which individual operations can refer to using indices. This brings bytecode ops one step closer to being pointer free.
This commit is contained in:
parent
4efccbd030
commit
6a0d1fa259
16 changed files with 173 additions and 82 deletions
|
@ -12,13 +12,17 @@
|
|||
#include <LibJS/Bytecode/BasicBlock.h>
|
||||
#include <LibJS/Bytecode/Label.h>
|
||||
#include <LibJS/Bytecode/Register.h>
|
||||
#include <LibJS/Bytecode/StringTable.h>
|
||||
#include <LibJS/Forward.h>
|
||||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
struct Executable {
|
||||
NonnullOwnPtrVector<BasicBlock> basic_blocks;
|
||||
NonnullOwnPtr<StringTable> string_table;
|
||||
size_t number_of_registers { 0 };
|
||||
|
||||
String const& get_string(StringTableIndex index) const { return string_table->get(index); }
|
||||
};
|
||||
|
||||
class Generator {
|
||||
|
@ -74,6 +78,11 @@ public:
|
|||
return m_current_basic_block->is_terminated();
|
||||
}
|
||||
|
||||
StringTableIndex intern_string(StringView const& string)
|
||||
{
|
||||
return m_string_table->insert(string);
|
||||
}
|
||||
|
||||
private:
|
||||
Generator();
|
||||
~Generator();
|
||||
|
@ -83,6 +92,7 @@ private:
|
|||
|
||||
BasicBlock* m_current_basic_block { nullptr };
|
||||
NonnullOwnPtrVector<BasicBlock> m_root_basic_blocks;
|
||||
NonnullOwnPtr<StringTable> m_string_table;
|
||||
|
||||
u32 m_next_register { 1 };
|
||||
u32 m_next_block { 1 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue