summaryrefslogtreecommitdiff
path: root/lib/mjit/x86_assembler.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mjit/x86_assembler.rb')
-rw-r--r--lib/mjit/x86_assembler.rb37
1 files changed, 9 insertions, 28 deletions
diff --git a/lib/mjit/x86_assembler.rb b/lib/mjit/x86_assembler.rb
index b89438f552..f04a9ea6b8 100644
--- a/lib/mjit/x86_assembler.rb
+++ b/lib/mjit/x86_assembler.rb
@@ -6,12 +6,15 @@ module RubyVM::MJIT
@bytes = []
end
- def compile(compiler) = with_dump_disasm(compiler) do
- C.mjit_mark_writable
- write_bytes(compiler.write_addr, @bytes)
- C.mjit_mark_executable
-
- compiler.write_pos += @bytes.size
+ def compile(addr)
+ writer = ByteWriter.new(addr)
+ # If you pack bytes containing \x00, Ruby fails to recognize bytes after \x00.
+ # So writing byte by byte to avoid hitting that situation.
+ @bytes.each_with_index do |byte, index|
+ writer[index] = byte
+ end
+ @bytes.size
+ ensure
@bytes.clear
end
@@ -36,27 +39,5 @@ module RubyVM::MJIT
# [C3]
@bytes.push(0xc3)
end
-
- private
-
- def with_dump_disasm(compiler)
- from = compiler.write_addr
- yield
- to = compiler.write_addr
- if C.mjit_opts.dump_disasm && from < to
- C.dump_disasm(from, to).each do |address, mnemonic, op_str|
- puts " 0x#{"%p" % address}: #{mnemonic} #{op_str}"
- end
- end
- end
-
- def write_bytes(addr, bytes)
- writer = ByteWriter.new(addr)
- # If you pack bytes containing \x00, Ruby fails to recognize bytes after \x00.
- # So writing byte by byte to avoid hitting that situation.
- bytes.each_with_index do |byte, index|
- writer[index] = byte
- end
- end
end
end