ladybird/Userland/Libraries/LibJS/Bytecode/BasicBlock.h

67 lines
1.8 KiB
C++

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Badge.h>
#include <AK/DeprecatedString.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/Handle.h>
namespace JS::Bytecode {
struct UnwindInfo {
Executable const* executable;
BasicBlock const* handler;
BasicBlock const* finalizer;
JS::GCPtr<Environment> lexical_environment;
bool handler_called { false };
};
class BasicBlock {
AK_MAKE_NONCOPYABLE(BasicBlock);
public:
static NonnullOwnPtr<BasicBlock> create(DeprecatedString name);
~BasicBlock();
void dump(Executable const&) const;
ReadonlyBytes instruction_stream() const { return m_buffer.span(); }
u8* data() { return m_buffer.data(); }
u8 const* data() const { return m_buffer.data(); }
size_t size() const { return m_buffer.size(); }
void grow(size_t additional_size);
void terminate(Badge<Generator>) { m_terminated = true; }
bool is_terminated() const { return m_terminated; }
DeprecatedString const& name() const { return m_name; }
// ==============================================================
// FIXME: This is JIT state and shouldn't be part of BasicBlock itself.
// Offset into the instruction stream where this code block starts.
size_t offset { 0 };
// Offsets into the instruction stream where we have RIP-relative jump offsets to here that need patching.
Vector<size_t> jumps_to_here;
// Offsets into the instruction stream where we have absolute 64-bit references to here that need patching.
Vector<size_t> absolute_references_to_here;
// ==============================================================
private:
explicit BasicBlock(DeprecatedString name);
Vector<u8> m_buffer;
DeprecatedString m_name;
bool m_terminated { false };
};
}