diff options
Diffstat (limited to 'lib/ruby_vm/mjit/compiler.rb')
-rw-r--r-- | lib/ruby_vm/mjit/compiler.rb | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb index 75314501c1..9383c189b2 100644 --- a/lib/ruby_vm/mjit/compiler.rb +++ b/lib/ruby_vm/mjit/compiler.rb @@ -9,9 +9,6 @@ module RubyVM::MJIT EndBlock = :end_block class Compiler - # Ruby constants - Qundef = Fiddle::Qundef - attr_accessor :write_pos # @param mem_block [Integer] JIT buffer address @@ -24,7 +21,11 @@ module RubyVM::MJIT # @param iseq [RubyVM::MJIT::CPointer::Struct] def call(iseq) return if iseq.body.location.label == '<main>' - iseq.body.jit_func = compile_block(iseq) + + asm = X86Assembler.new + compile_prologue(asm) + compile_block(asm, iseq) + iseq.body.jit_func = compile(asm) rescue Exception => e $stderr.puts e.full_message # TODO: check verbose end @@ -35,25 +36,13 @@ module RubyVM::MJIT private - def compile(asm) - start_addr = write_addr - - C.mjit_mark_writable - @write_pos += asm.compile(start_addr) - C.mjit_mark_executable - - end_addr = write_addr - if C.mjit_opts.dump_disasm && start_addr < end_addr - dump_disasm(start_addr, end_addr) - end - start_addr + # ec: rdi + # cfp: rsi + def compile_prologue(asm) + asm.mov(:rbx, [:rsi, C.rb_control_frame_t.offsetof(:sp)]) # rbx = cfp->sp end - # ec -> RDI, cfp -> RSI - def compile_block(iseq) - addr = write_addr - asm = X86Assembler.new - + def compile_block(asm, iseq) index = 0 while index < iseq.body.iseq_size insn = decode_insn(iseq.body.iseq_encoded[index]) @@ -63,8 +52,6 @@ module RubyVM::MJIT end index += insn.len end - - compile(asm) end def compile_insn(asm, insn) @@ -75,6 +62,20 @@ module RubyVM::MJIT end end + def compile(asm) + start_addr = write_addr + + C.mjit_mark_writable + @write_pos += asm.compile(start_addr) + C.mjit_mark_executable + + end_addr = write_addr + if C.mjit_opts.dump_disasm && start_addr < end_addr + dump_disasm(start_addr, end_addr) + end + start_addr + end + def decode_insn(encoded) INSNS.fetch(C.rb_vm_insn_decode(encoded)) end |