Module: IRPrettyPrinter
- Defined in:
- lib/jruby_visualizer/ir_pretty_printer.rb
Overview
Retrieve a nicely formatted string from JRuby’s IRScope
Class Method Summary collapse
Class Method Details
.pretty_ir(scope, indent = '') ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jruby_visualizer/ir_pretty_printer.rb', line 23 def self.pretty_ir(scope, indent='') instrs = if scope.cfg # read instrs from control flow graph scope.cfg.sorted_basic_blocks.reduce([]) do |cfg_instrs, bb| cfg_instrs += bb.instrs end else # if no pass has been executed get them directly without cfg scope.instrs end pretty_str = instrs.map do |instr| f_str = "%s\s\s%s" % [indent, instr] f_str end pretty_str = [indent + scope.to_s] + pretty_str scope.lexical_scopes.each do |lex_scope| pretty_str += pretty_ir(lex_scope, indent + "\s" * 4) end pretty_str end |
.pretty_string(scope) ⇒ Object
51 52 53 54 |
# File 'lib/jruby_visualizer/ir_pretty_printer.rb', line 51 def self.pretty_string(scope) instrs = pretty_ir(scope) instrs.join("\n") end |
.print_ir(scope) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/jruby_visualizer/ir_pretty_printer.rb', line 44 def self.print_ir(scope) instrs = pretty_ir(scope) instrs.each do |instr| puts instr end end |