Class: RegularExpression::CFG::Graph
- Inherits:
-
Object
- Object
- RegularExpression::CFG::Graph
- Defined in:
- lib/regular_expression/cfg.rb
Overview
A graph is a set of EBBs.
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#exit_map ⇒ Object
readonly
Returns the value of attribute exit_map.
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(blocks, exit_map) ⇒ Graph
constructor
A new instance of Graph.
- #start ⇒ Object
- #to_dot(graph) ⇒ Object
Constructor Details
#initialize(blocks, exit_map) ⇒ Graph
Returns a new instance of Graph.
118 119 120 121 |
# File 'lib/regular_expression/cfg.rb', line 118 def initialize(blocks, exit_map) @blocks = blocks @exit_map = exit_map end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
116 117 118 |
# File 'lib/regular_expression/cfg.rb', line 116 def blocks @blocks end |
#exit_map ⇒ Object (readonly)
Returns the value of attribute exit_map.
116 117 118 |
# File 'lib/regular_expression/cfg.rb', line 116 def exit_map @exit_map end |
Instance Method Details
#dump ⇒ Object
127 128 129 130 131 |
# File 'lib/regular_expression/cfg.rb', line 127 def dump output = StringIO.new blocks.each { |block| block.dump(exit_map, io: output) } output.string end |
#start ⇒ Object
123 124 125 |
# File 'lib/regular_expression/cfg.rb', line 123 def start blocks.first end |
#to_dot(graph) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/regular_expression/cfg.rb', line 133 def to_dot(graph) nodes = {} blocks.each do |block| label = [] label.push("#{block.name}:") block.insns.each { |insn| label.push(" #{insn}") } nodes[block] = graph.add_node(block.object_id, label: label.join($/), labeljust: "l", shape: "box") end blocks.each do |block| successors = block.exits.map { |exit| nodes[exit_map[exit]] }.uniq successors.each do |successor| nodes[block].connect(successor) end end end |