summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-12-30 23:42:00 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-05 22:11:20 -0800
commitd7dba4c51066eb706987356ad6b862a0b60b1aeb (patch)
tree7478f150a42c15b82fad0a8e555b5815a45f9263 /lib
parent36cec59f0a54b817ae6b3836fb0e97e342b999ce (diff)
downloadruby-d7dba4c51066eb706987356ad6b862a0b60b1aeb.tar.gz
Colorize outlined code
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby_vm/mjit/code_block.rb17
-rw-r--r--lib/ruby_vm/mjit/compiler.rb2
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/ruby_vm/mjit/code_block.rb b/lib/ruby_vm/mjit/code_block.rb
index 464d13ba8d..b4cc3d721c 100644
--- a/lib/ruby_vm/mjit/code_block.rb
+++ b/lib/ruby_vm/mjit/code_block.rb
@@ -2,11 +2,13 @@ module RubyVM::MJIT
class CodeBlock
# @param mem_block [Integer] JIT buffer address
# @param mem_size [Integer] JIT buffer size
- def initialize(mem_block:, mem_size:)
+ # @param outliend [TrueClass,FalseClass] true for outlined CodeBlock
+ def initialize(mem_block:, mem_size:, outlined: false)
@comments = Hash.new { |h, k| h[k] = [] }
@mem_block = mem_block
@mem_size = mem_size
@write_pos = 0
+ @outlined = outlined
end
# @param asm [RubyVM::MJIT::Assembler]
@@ -44,13 +46,22 @@ module RubyVM::MJIT
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}")
+ puts colorize(" # #{comment}", bold: true)
end
- puts " 0x#{format("%x", address)}: #{mnemonic} #{op_str}"
+ puts colorize(" 0x#{format("%x", address)}: #{mnemonic} #{op_str}")
end
puts
end
+ def colorize(text, bold: false)
+ buf = +''
+ buf << "\e[1m" if bold
+ buf << "\e[34m" if @outlined
+ buf << text
+ buf << "\e[0m"
+ buf
+ end
+
def bold(text)
"\e[1m#{text}\e[0m"
end
diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb
index e114d43e0d..6203863218 100644
--- a/lib/ruby_vm/mjit/compiler.rb
+++ b/lib/ruby_vm/mjit/compiler.rb
@@ -32,7 +32,7 @@ module RubyVM::MJIT
# @param mem_size [Integer] JIT buffer size
def initialize(mem_block, mem_size)
@cb = CodeBlock.new(mem_block: mem_block, mem_size: mem_size / 2)
- @ocb = CodeBlock.new(mem_block: mem_block + mem_size / 2, mem_size: mem_size / 2)
+ @ocb = CodeBlock.new(mem_block: mem_block + mem_size / 2, mem_size: mem_size / 2, outlined: true)
@exit_compiler = ExitCompiler.new
@insn_compiler = InsnCompiler.new(@ocb)
end