2022-12-11 21:42:25 -08:00
|
|
|
require 'mjit/x86_64/assembler'
|
|
|
|
|
2022-12-11 21:16:33 -08:00
|
|
|
class RubyVM::MJIT::Compiler
|
2022-12-11 21:42:25 -08:00
|
|
|
# MJIT internals
|
|
|
|
Assembler = RubyVM::MJIT::Assembler
|
|
|
|
C = RubyVM::MJIT::C
|
|
|
|
|
|
|
|
# Ruby constants
|
|
|
|
Qundef = Fiddle::Qundef
|
|
|
|
|
|
|
|
attr_accessor :write_pos
|
2022-09-04 21:53:46 -07:00
|
|
|
|
2022-12-11 21:32:24 -08:00
|
|
|
# @param mem_block [Integer] JIT buffer address
|
|
|
|
def initialize(mem_block)
|
|
|
|
@mem_block = mem_block
|
|
|
|
@write_pos = 0
|
|
|
|
end
|
2022-11-28 21:33:55 -08:00
|
|
|
|
|
|
|
# @param iseq [RubyVM::MJIT::CPointer::Struct]
|
2022-12-11 21:16:33 -08:00
|
|
|
def compile(iseq)
|
2022-12-11 21:42:25 -08:00
|
|
|
return if iseq.body.location.label == '<main>'
|
|
|
|
|
|
|
|
iseq.body.jit_func = write_addr
|
|
|
|
asm = Assembler.new
|
|
|
|
asm.mov(:eax, Qundef)
|
|
|
|
asm.ret
|
|
|
|
asm.compile(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def write_addr
|
|
|
|
@mem_block + @write_pos
|
2022-09-04 21:53:46 -07:00
|
|
|
end
|
|
|
|
end
|