Class: BasicBlockBox

Inherits:
Object
  • Object
show all
Includes:
JRubyFX
Defined in:
lib/jruby_visualizer/control_flow_graph_view.rb

Overview

A custom JRubyFX control for a basic block of a CFG. This view is a composite with a TextArea for the basic blocks and live links to basic blocks that can succeed after this one

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(basic_block, cfg, cfg_list_view) ⇒ BasicBlockBox

Returns a new instance of BasicBlockBox.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/jruby_visualizer/control_flow_graph_view.rb', line 30

def initialize(basic_block, cfg, cfg_list_view)
  super(5)
  @basic_block = basic_block
  instructions = instrs
  @instrs_box = TextArea.new(instructions)
  line_no = instructions.lines.count
  @instrs_box.set_pref_row_count(line_no)
  @instrs_box.set_style('-fx-font-family: monospaced')
  @instrs_box.set_editable(false)
  @successors = cfg.get_outgoing_destinations(@basic_block).to_a
  if @successors.empty?
    get_children << @instrs_box
  else
    @successor_buttons = @successors.map do |bb|
      button = Button.new(bb.to_s)
      button.set_on_action do
        # TODO rewrite this ugly code
        i = button.get_text.scan(/.*\[(\d+):.*\]/)[0][0]
        index = i.to_i - 1
        cfg_list_view.selection_model.select(index)
        cfg_list_view.focus_model.focus(index)
        cfg_list_view.scroll_to(index)
      end
      button
    end

    successors_layout = HBox.new(5)
    successors_layout.get_children << Label.new('Successors: ')
    successors_layout.get_children.add_all(@successor_buttons)

    get_children.add_all(@instrs_box, successors_layout)
  end
end

Instance Attribute Details

#basic_blockObject (readonly)

Returns the value of attribute basic_block.



28
29
30
# File 'lib/jruby_visualizer/control_flow_graph_view.rb', line 28

def basic_block
  @basic_block
end

#instrs_boxObject (readonly)

Returns the value of attribute instrs_box.



28
29
30
# File 'lib/jruby_visualizer/control_flow_graph_view.rb', line 28

def instrs_box
  @instrs_box
end

#successor_buttonsObject (readonly)

Returns the value of attribute successor_buttons.



28
29
30
# File 'lib/jruby_visualizer/control_flow_graph_view.rb', line 28

def successor_buttons
  @successor_buttons
end

#successorsObject (readonly)

Returns the value of attribute successors.



28
29
30
# File 'lib/jruby_visualizer/control_flow_graph_view.rb', line 28

def successors
  @successors
end

Instance Method Details

#instrsObject



64
65
66
67
68
69
70
71
# File 'lib/jruby_visualizer/control_flow_graph_view.rb', line 64

def instrs
  instrs_string = @basic_block.to_string_instrs
  if instrs_string.end_with?("\n")
    instrs_string[0...-1]
  else
    instrs_string
  end
end