ruby/lib/ruby_vm/mjit/jit_state.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1.3 KiB
Ruby
Raw Normal View History

2022-12-28 13:50:24 -08:00
module RubyVM::MJIT
class JITState < Struct.new(
2023-02-16 22:29:58 -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 }
:record_boundary_patch_point, # @param [TrueClass,FalseClass]
2022-12-28 13:50:24 -08:00
)
2023-02-16 22:29:58 -08:00
def initialize(side_exits: {}, record_boundary_patch_point: false, **) = super
2023-01-02 22:53:14 -08:00
2023-01-07 13:21:14 -08:00
def insn
Compiler.decode_insn(C.VALUE.new(pc).*)
end
2023-02-13 07:30:25 -08:00
def operand(index, signed: false)
addr = pc + (index + 1) * Fiddle::SIZEOF_VOIDP
Fiddle::Pointer.new(addr)[0, Fiddle::SIZEOF_VOIDP].unpack(signed ? 'q' : 'Q')[0]
2022-12-28 13:50:24 -08:00
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-02-08 09:30:47 -08:00
# rb_mjit_branch_stub_hit updates SP, so you don't need to worry about sp_offset
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