diff --git a/Userland/Libraries/LibJS/Bytecode/BasicBlock.cpp b/Userland/Libraries/LibJS/Bytecode/BasicBlock.cpp index 8bac7aa06a..71a14ac7e2 100644 --- a/Userland/Libraries/LibJS/Bytecode/BasicBlock.cpp +++ b/Userland/Libraries/LibJS/Bytecode/BasicBlock.cpp @@ -64,10 +64,4 @@ void BasicBlock::grow(size_t additional_size) VERIFY(m_buffer_size <= m_buffer_capacity); } -void InstructionStreamIterator::operator++() -{ - VERIFY(!at_end()); - m_offset += dereference().length(); -} - } diff --git a/Userland/Libraries/LibJS/Bytecode/BasicBlock.h b/Userland/Libraries/LibJS/Bytecode/BasicBlock.h index 9078287777..b5f7c83eae 100644 --- a/Userland/Libraries/LibJS/Bytecode/BasicBlock.h +++ b/Userland/Libraries/LibJS/Bytecode/BasicBlock.h @@ -13,31 +13,6 @@ namespace JS::Bytecode { -class InstructionStreamIterator { -public: - explicit InstructionStreamIterator(ReadonlyBytes bytes) - : m_bytes(bytes) - { - } - - size_t offset() const { return m_offset; } - bool at_end() const { return m_offset >= m_bytes.size(); } - void jump(size_t offset) - { - VERIFY(offset <= m_bytes.size()); - m_offset = offset; - } - - Instruction const& operator*() const { return dereference(); } - void operator++(); - -private: - Instruction const& dereference() const { return *reinterpret_cast(m_bytes.data() + offset()); } - - ReadonlyBytes m_bytes; - size_t m_offset { 0 }; -}; - struct UnwindInfo { Executable const* executable; BasicBlock const* handler; diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h index 31776b7d3f..941a990b40 100644 --- a/Userland/Libraries/LibJS/Bytecode/Instruction.h +++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #define ENUMERATE_BYTECODE_OPS(O) \ @@ -106,4 +107,35 @@ protected: private: Type m_type {}; }; + +class InstructionStreamIterator { +public: + explicit InstructionStreamIterator(ReadonlyBytes bytes) + : m_bytes(bytes) + { + } + + size_t offset() const { return m_offset; } + bool at_end() const { return m_offset >= m_bytes.size(); } + void jump(size_t offset) + { + VERIFY(offset <= m_bytes.size()); + m_offset = offset; + } + + Instruction const& operator*() const { return dereference(); } + + ALWAYS_INLINE void operator++() + { + VERIFY(!at_end()); + m_offset += dereference().length(); + } + +private: + Instruction const& dereference() const { return *reinterpret_cast(m_bytes.data() + offset()); } + + ReadonlyBytes m_bytes; + size_t m_offset { 0 }; +}; + }