class Bpl::Modification

Public Class Methods

stmt_modifies(stmt) click to toggle source
# File lib/bpl/passes/analysis/modification.rb, line 18
def self.stmt_modifies(stmt)
  case stmt
  when HavocStatement
    stmt.identifiers
  when AssignStatement
    stmt.lhs.map(&:ident)
  when CallStatement
    stmt.assignments.map(&:ident)
  else
    []
  end
end

Public Instance Methods

run!(program) click to toggle source
# File lib/bpl/passes/analysis/modification.rb, line 31
def run! program
  work_list = []
  program.declarations.each do |proc|
    next unless proc.is_a?(ProcedureDeclaration)
    work_list << proc
    modifies[proc] = Set.new
    proc.each do |elem|
      modifies[proc] +=
        self.class.stmt_modifies(elem).select(&:is_global?).map(&:name)
    end
  end

  until work_list.empty?
    proc = work_list.shift
    targets = call_graph_construction.callers[proc]
    targets << proc.declaration if proc.respond_to?(:declaration) && proc.declaration
    targets.each do |caller|
      mods = modifies[proc] - modifies[caller]
      unless mods.empty?
        modifies[caller] += mods
        work_list |= [caller]
      end
    end
  end

end