summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Bytecode/Generator.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-06-09 00:50:42 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-09 00:50:42 +0200
commitb8a5ea1f8dbcf3d777a67c3eabd81071a4527765 (patch)
treea7b493153ec3319a886a493a962d6541ae6a4ff9 /Userland/Libraries/LibJS/Bytecode/Generator.h
parenta01bd35c67e35e9f0e33f46bb3a4431e49af1b60 (diff)
downloadserenity-b8a5ea1f8dbcf3d777a67c3eabd81071a4527765.zip
Revert "LibJS: Add bytecode instruction handles"
This reverts commit a01bd35c67e35e9f0e33f46bb3a4431e49af1b60. This broke simple programs like: function sum(a, b) { return a + b; } console.log(sum(1, 2));
Diffstat (limited to 'Userland/Libraries/LibJS/Bytecode/Generator.h')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Generator.h27
1 files changed, 13 insertions, 14 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/Generator.h b/Userland/Libraries/LibJS/Bytecode/Generator.h
index 110ad25ac5..88bac76ebe 100644
--- a/Userland/Libraries/LibJS/Bytecode/Generator.h
+++ b/Userland/Libraries/LibJS/Bytecode/Generator.h
@@ -7,8 +7,8 @@
#pragma once
#include <AK/OwnPtr.h>
-#include <LibJS/Bytecode/Block.h>
#include <LibJS/Bytecode/Label.h>
+#include <LibJS/Bytecode/Register.h>
#include <LibJS/Forward.h>
namespace JS::Bytecode {
@@ -20,15 +20,21 @@ public:
Register allocate_register();
template<typename OpType, typename... Args>
- InstructionHandle<OpType> emit(Args&&... args)
+ OpType& emit(Args&&... args)
{
- return make_instruction<OpType>(0, forward<Args>(args)...);
+ void* slot = next_slot();
+ grow(sizeof(OpType));
+ new (slot) OpType(forward<Args>(args)...);
+ return *static_cast<OpType*>(slot);
}
template<typename OpType, typename... Args>
- InstructionHandle<OpType> emit_with_extra_register_slots(size_t extra_register_slots, Args&&... args)
+ OpType& emit_with_extra_register_slots(size_t extra_register_slots, Args&&... args)
{
- return make_instruction<OpType>(extra_register_slots, forward<Args>(args)...);
+ void* slot = next_slot();
+ grow(sizeof(OpType) + extra_register_slots * sizeof(Register));
+ new (slot) OpType(forward<Args>(args)...);
+ return *static_cast<OpType*>(slot);
}
Label make_label() const;
@@ -42,15 +48,8 @@ private:
Generator();
~Generator();
- template<typename OpType, typename... Args>
- InstructionHandle<OpType> make_instruction(size_t extra_register_slots, Args&&... args)
- {
- auto& buffer = m_block->buffer();
- auto offset = buffer.size();
- buffer.resize(buffer.size() + sizeof(OpType) + extra_register_slots * sizeof(Register));
- new (buffer.data() + offset) OpType(forward<Args>(args)...);
- return InstructionHandle<OpType>(offset, m_block);
- }
+ void grow(size_t);
+ void* next_slot();
OwnPtr<Block> m_block;
u32 m_next_register { 1 };