class SyntaxTree::YARV::DataFlowGraph::Compiler

def find_external_flow

Find the data that flows between basic blocks.
def find_external_flow
  stack = [*cfg.blocks]
  until stack.empty?
    block = stack.pop
    block_flow = block_flows.fetch(block.id)
    block.incoming_blocks.each do |incoming_block|
      incoming_flow = block_flows.fetch(incoming_block.id)
      # Does a predecessor block have fewer outputs than the successor
      # has inputs?
      if incoming_flow.out.size < block_flow.in.size
        # If so then add arguments to pass data through from the
        # incoming block's incoming blocks.
        (block_flow.in.size - incoming_flow.out.size).times do |index|
          name = BlockArgument.new(:"pass_#{index}")
          incoming_flow.in.unshift(name)
          incoming_flow.out.unshift(name)
        end
        # Since we modified the incoming block, add it back to the stack
        # so it'll be considered as an outgoing block again, and
        # propogate the external data flow back up the control flow
        # graph.
        stack << incoming_block
      end
    end
  end
end