Sha256: f823b0e0c2e25d01fa52fc70894ea292b004bab96e1f1638f48043f79dea9f85

Contents?: true

Size: 986 Bytes

Versions: 1

Compression:

Stored size: 986 Bytes

Contents

module Furnace
  class SSA::Module
    def initialize
      @functions = {}
      @next_id   = 0
    end

    def to_a
      @functions.values
    end

    def each(&block)
      @functions.values.each(&block)
    end

    def include?(name)
      @functions.include? name
    end

    def [](name)
      unless @functions.include? name
        raise ArgumentError, "function #{name} is not found"
      end

      @functions[name]
    end

    def add(function, name_prefix=nil)
      if name_prefix ||
          function.name.nil? ||
          @functions.include?(function.name)

        basename = name_prefix || function.name || 'function'
        basename = basename.gsub /;\d+$/, ''

        function.name = "#{basename};#{make_id}"
      end

      @functions[function.name] = function

      SSA.instrument(self)
    end

    def remove(name)
      @functions.delete name

      SSA.instrument(self)
    end

    protected

    def make_id
      @next_id += 1
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
furnace-0.4.0.beta.2 lib/furnace/ssa/module.rb