Use the term "compile" in different places

This commit is contained in:
Takashi Kokubun 2022-12-30 22:05:53 -08:00
parent c51baf9404
commit 7abff797b4
4 changed files with 16 additions and 8 deletions

View file

@ -10,14 +10,14 @@ module RubyVM::MJIT
end
# @param asm [RubyVM::MJIT::X86Assembler]
def compile(asm)
def write(asm)
return 0 if @write_pos + asm.size >= @mem_size
start_addr = write_addr
# Write machine code
C.mjit_mark_writable
@write_pos += asm.compile(start_addr)
@write_pos += asm.assemble(start_addr)
C.mjit_mark_executable
end_addr = write_addr

View file

@ -37,7 +37,7 @@ module RubyVM::MJIT
end
# @param iseq [RubyVM::MJIT::CPointer::Struct]
def call(iseq)
def compile(iseq)
# TODO: Support has_opt
return if iseq.body.param.flags.has_opt
@ -45,7 +45,7 @@ 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 = @cb.compile(asm)
iseq.body.jit_func = @cb.write(asm)
rescue Exception => e
$stderr.puts e.full_message # TODO: check verbose
end

View file

@ -10,8 +10,6 @@ module RubyVM::MJIT
# REX = 0100WR0B
REX_W = 0b01001000
attr_reader :comments
def initialize
@bytes = []
@labels = {}
@ -19,7 +17,7 @@ module RubyVM::MJIT
@comments = Hash.new { |h, k| h[k] = [] }
end
def compile(addr)
def assemble(addr)
link_labels
writer = ByteWriter.new(addr)
# If you pack bytes containing \x00, Ruby fails to recognize bytes after \x00.
@ -36,6 +34,10 @@ module RubyVM::MJIT
@bytes.size
end
#
# Instructions
#
def add(dst, src)
case [dst, src]
# ADD r/m64, imm8 (Mod 11)
@ -228,6 +230,12 @@ module RubyVM::MJIT
end
end
#
# Utilities
#
attr_reader :comments
def comment(message)
@comments[@bytes.size] << message
end

2
mjit.c
View file

@ -334,7 +334,7 @@ rb_mjit_compile(const rb_iseq_t *iseq)
mjit_stats_p = false; // Avoid impacting JIT stats by itself
VALUE iseq_ptr = rb_funcall(rb_cMJITIseqPtr, rb_intern("new"), 1, SIZET2NUM((size_t)iseq));
rb_funcall(rb_MJITCompiler, rb_intern("call"), 1, iseq_ptr);
rb_funcall(rb_MJITCompiler, rb_intern("compile"), 1, iseq_ptr);
mjit_stats_p = mjit_opts.stats;
mjit_call_p = original_call_p;