2022-12-28 13:50:24 -08:00
|
|
|
module RubyVM::MJIT
|
|
|
|
class JITState < Struct.new(
|
2023-01-02 22:53:14 -08:00
|
|
|
:iseq, # @param `RubyVM::MJIT::CPointer::Struct_rb_iseq_t`
|
|
|
|
:pc, # @param [Integer] The JIT target PC
|
|
|
|
:cfp, # @param `RubyVM::MJIT::CPointer::Struct_rb_control_frame_t` The JIT source CFP (before MJIT is called)
|
|
|
|
:block, # @param [RubyVM::MJIT::Block]
|
|
|
|
:side_exits, # @param [Hash{ Integer => Integer }] { PC => address }
|
2022-12-28 13:50:24 -08:00
|
|
|
)
|
2023-01-02 22:53:14 -08:00
|
|
|
def initialize(side_exits: {}, **) = super
|
|
|
|
|
2023-01-07 13:21:14 -08:00
|
|
|
def insn
|
|
|
|
Compiler.decode_insn(C.VALUE.new(pc).*)
|
|
|
|
end
|
|
|
|
|
2022-12-28 13:50:24 -08:00
|
|
|
def operand(index)
|
|
|
|
C.VALUE.new(pc)[index + 1]
|
|
|
|
end
|
2022-12-31 13:41:32 -08:00
|
|
|
|
|
|
|
def at_current_insn?
|
|
|
|
pc == cfp.pc.to_i
|
|
|
|
end
|
2023-01-02 22:53:14 -08:00
|
|
|
|
2023-01-07 21:24:30 -08:00
|
|
|
def peek_at_stack(depth_from_top)
|
2023-01-02 22:53:14 -08:00
|
|
|
raise 'not at current insn' unless at_current_insn?
|
2023-01-07 21:24:30 -08:00
|
|
|
offset = -(1 + depth_from_top)
|
2023-01-02 22:53:14 -08:00
|
|
|
value = (cfp.sp + offset).*
|
|
|
|
C.to_ruby(value)
|
|
|
|
end
|
2023-02-07 14:42:58 -08:00
|
|
|
|
|
|
|
def peek_at_self
|
|
|
|
C.to_ruby(cfp.self)
|
|
|
|
end
|
2022-12-28 13:50:24 -08:00
|
|
|
end
|
2022-12-26 14:09:45 -08:00
|
|
|
end
|