mirror of
https://github.com/ruby/ruby.git
synced 2025-08-26 06:25:31 +02:00
Colorize outlined code
This commit is contained in:
parent
36cec59f0a
commit
d7dba4c510
2 changed files with 15 additions and 4 deletions
|
@ -2,11 +2,13 @@ module RubyVM::MJIT
|
||||||
class CodeBlock
|
class CodeBlock
|
||||||
# @param mem_block [Integer] JIT buffer address
|
# @param mem_block [Integer] JIT buffer address
|
||||||
# @param mem_size [Integer] JIT buffer size
|
# @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] = [] }
|
@comments = Hash.new { |h, k| h[k] = [] }
|
||||||
@mem_block = mem_block
|
@mem_block = mem_block
|
||||||
@mem_size = mem_size
|
@mem_size = mem_size
|
||||||
@write_pos = 0
|
@write_pos = 0
|
||||||
|
@outlined = outlined
|
||||||
end
|
end
|
||||||
|
|
||||||
# @param asm [RubyVM::MJIT::Assembler]
|
# @param asm [RubyVM::MJIT::Assembler]
|
||||||
|
@ -44,13 +46,22 @@ module RubyVM::MJIT
|
||||||
def dump_disasm(from, to)
|
def dump_disasm(from, to)
|
||||||
C.dump_disasm(from, to).each do |address, mnemonic, op_str|
|
C.dump_disasm(from, to).each do |address, mnemonic, op_str|
|
||||||
@comments.fetch(address, []).each do |comment|
|
@comments.fetch(address, []).each do |comment|
|
||||||
puts bold(" # #{comment}")
|
puts colorize(" # #{comment}", bold: true)
|
||||||
end
|
end
|
||||||
puts " 0x#{format("%x", address)}: #{mnemonic} #{op_str}"
|
puts colorize(" 0x#{format("%x", address)}: #{mnemonic} #{op_str}")
|
||||||
end
|
end
|
||||||
puts
|
puts
|
||||||
end
|
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)
|
def bold(text)
|
||||||
"\e[1m#{text}\e[0m"
|
"\e[1m#{text}\e[0m"
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,7 @@ module RubyVM::MJIT
|
||||||
# @param mem_size [Integer] JIT buffer size
|
# @param mem_size [Integer] JIT buffer size
|
||||||
def initialize(mem_block, mem_size)
|
def initialize(mem_block, mem_size)
|
||||||
@cb = CodeBlock.new(mem_block: mem_block, mem_size: mem_size / 2)
|
@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
|
@exit_compiler = ExitCompiler.new
|
||||||
@insn_compiler = InsnCompiler.new(@ocb)
|
@insn_compiler = InsnCompiler.new(@ocb)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue