The jruby_visualizer
gem takes as input Ruby code and visualizes artifacts of JRuby's compiler/interpreter tool chain.
This includes
- the Abstract Syntax Tree (AST)
- the Intermediate Representation (IR)
- the execution of compiler passes on IR
- a visualization for the Control Flow Graphs (CFGs) on JRuby Scopes
You can install this visualizer as gem into your jruby environment:
- Clone the repository
$ git clone https://github.com/jruby/jruby-visualizer.git
- Build the gem
$ rake build
- Install the gem
$ jruby -S gem install --local pkg/jruby_visualizer-0.1.gem
Either
- call into the library
$ ./lib/jruby_visualizer.rb
RuntimeError: No ruby input for the JRuby Visualizer
Usage:
./lib/jruby_visualizer.rb "def foo; 42; end; foo"
or
./lib/jruby_visualizer.rb foo.rb
(root) at ./lib/jruby_visualizer.rb:15
This is also possible with the following command, to visualize foo.rb
:
$ jruby -Ilib ./bin/jruby_visualizer foo.rb
- Execute the installed binary
$ jruby_visualizer foo.rb
- Use the visualizer as gem in your jruby code
#!/usr/bin/env jruby
require 'jruby_visualizer'
JRubyVisualizer::visualize('def bar; puts "spam HAM"; end; bar')