Class: SyntaxTree::YARV::DataFlowGraph::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/data_flow_graph.rb

Overview

This class is responsible for creating a data flow graph from the given control flow graph.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg) ⇒ Compiler

Returns a new instance of Compiler.



221
222
223
224
225
# File 'lib/syntax_tree/yarv/data_flow_graph.rb', line 221

def initialize(cfg)
  @cfg = cfg
  @insn_flows = cfg.insns.to_h { |length, _| [length, DataFlow.new] }
  @block_flows = cfg.blocks.to_h { |block| [block.id, DataFlow.new] }
end

Instance Attribute Details

#block_flowsObject (readonly)

This data structure will hold the data flow between basic blocks.



219
220
221
# File 'lib/syntax_tree/yarv/data_flow_graph.rb', line 219

def block_flows
  @block_flows
end

#cfgObject (readonly)

This is the control flow graph that is being compiled.



212
213
214
# File 'lib/syntax_tree/yarv/data_flow_graph.rb', line 212

def cfg
  @cfg
end

#insn_flowsObject (readonly)

This data structure will hold the data flow between instructions within individual basic blocks.



216
217
218
# File 'lib/syntax_tree/yarv/data_flow_graph.rb', line 216

def insn_flows
  @insn_flows
end

Instance Method Details

#compileObject



227
228
229
230
231
# File 'lib/syntax_tree/yarv/data_flow_graph.rb', line 227

def compile
  find_internal_flow
  find_external_flow
  DataFlowGraph.new(cfg, insn_flows, block_flows).tap(&:verify)
end