Sha256: f1161a26a681a339254457eef35fcad8d263394b3a5f5c9127fb8ba2f317b844

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

module Furnace
  module Transform
    module Generic
      class CFGNormalize
        def transform(cfg, method)
          cfg.nodes.each do |node|
            # If a last operation is an unconditional jump, optimize it out.
            last = node.operations.last
            if last.type == :jump
              edge = node.leaving_edge(last.metadata[:label])

              node.operations.delete last

              cfg.edges.delete edge
              cfg.edges.add CFG::Edge.new(cfg, nil, node.label, edge.target.label)
            end

            # Remove no-ops.
            node.operations.delete_if { |op| op.type == :nop }
          end

          # Remove empty nodes.
          cfg.nodes.delete_if do |node|
            if node.operations.empty?
              node.entering_edges.each do |edge|
                edge.target = node.default_leaving_edge.target
              end
              cfg.edges.subtract node.leaving_edges

              true
            else
              false
            end
          end

          [ cfg, method ]
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
furnace-0.1.2 lib/furnace/transform/generic/cfg_normalize.rb
furnace-0.1.1 lib/furnace/transform/generic/cfg_normalize.rb
furnace-0.1.0 lib/furnace/transform/generic/cfg_normalize.rb
furnace-0.0.8 lib/furnace/transform/generic/cfg_normalize.rb
furnace-0.0.7 lib/furnace/transform/generic/cfg_normalize.rb
furnace-0.0.6 lib/furnace/transform/generic/cfg_normalize.rb
furnace-0.0.4 lib/furnace/transform/generic/cfg_normalize.rb
furnace-0.0.3 lib/furnace/transform/generic/cfg_normalize.rb
furnace-0.0.2 lib/furnace/transform/generic/cfg_normalize.rb
furnace-0.0.1 lib/furnace/transform/generic/cfg_normalize.rb