summaryrefslogtreecommitdiff
path: root/lib/ruby_vm/mjit/compiler.rb
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2022-12-30 21:34:36 -0800
committerTakashi Kokubun <[email protected]>2023-03-05 22:11:20 -0800
commitc51baf9404373c8cb37a1fb887c50c0216576186 (patch)
treebfb9dd19008f8dae1e2fc7ff3035abcac4b74620 /lib/ruby_vm/mjit/compiler.rb
parent28290d519860a7dce138e4c5684f72b0215180e9 (diff)
Carve out CodeBlock
Diffstat (limited to 'lib/ruby_vm/mjit/compiler.rb')
-rw-r--r--lib/ruby_vm/mjit/compiler.rb52
1 files changed, 5 insertions, 47 deletions
diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb
index 99984980f1..c5a7380226 100644
--- a/lib/ruby_vm/mjit/compiler.rb
+++ b/lib/ruby_vm/mjit/compiler.rb
@@ -1,3 +1,4 @@
+require 'ruby_vm/mjit/code_block'
require 'ruby_vm/mjit/context'
require 'ruby_vm/mjit/exit_compiler'
require 'ruby_vm/mjit/insn_compiler'
@@ -28,10 +29,9 @@ module RubyVM::MJIT
end
# @param mem_block [Integer] JIT buffer address
- def initialize(mem_block)
- @comments = Hash.new { |h, k| h[k] = [] }
- @mem_block = mem_block
- @write_pos = 0
+ # @param mem_size [Integer] JIT buffer size
+ def initialize(mem_block, mem_size)
+ @cb = CodeBlock.new(mem_block:, mem_size:)
@exit_compiler = ExitCompiler.new
@insn_compiler = InsnCompiler.new
end
@@ -45,41 +45,13 @@ module RubyVM::MJIT
asm.comment("Block: #{iseq.body.location.label}@#{pathobj_path(iseq.body.location.pathobj)}:#{iseq.body.location.first_lineno}")
compile_prologue(asm)
compile_block(asm, iseq)
- iseq.body.jit_func = compile(asm)
+ iseq.body.jit_func = @cb.compile(asm)
rescue Exception => e
$stderr.puts e.full_message # TODO: check verbose
end
- def write_addr
- @mem_block + @write_pos
- end
-
private
- # @param asm [RubyVM::MJIT::X86Assembler]
- def compile(asm)
- start_addr = write_addr
-
- # Write machine code
- C.mjit_mark_writable
- @write_pos += asm.compile(start_addr)
- C.mjit_mark_executable
-
- end_addr = write_addr
-
- # Convert comment indexes to addresses
- asm.comments.each do |index, comments|
- @comments[start_addr + index] += comments
- end
- asm.comments.clear
-
- # Dump disasm if --mjit-dump-disasm
- if C.mjit_opts.dump_disasm && start_addr < end_addr
- dump_disasm(start_addr, end_addr)
- end
- start_addr
- end
-
# ec: rdi
# cfp: rsi
#
@@ -226,20 +198,6 @@ module RubyVM::MJIT
end
end
- def dump_disasm(from, to)
- C.dump_disasm(from, to).each do |address, mnemonic, op_str|
- @comments.fetch(address, []).each do |comment|
- puts bold(" # #{comment}")
- end
- puts " 0x#{format("%x", address)}: #{mnemonic} #{op_str}"
- end
- puts
- end
-
- def bold(text)
- "\e[1m#{text}\e[0m"
- end
-
# vm_core.h: pathobj_path
def pathobj_path(pathobj)
if pathobj.is_a?(String)