module AdLint::Ld::DebugUtil

Public Class Methods

dump_function_call_graph(phase_ctxt) click to toggle source
# File lib/adlint/ld/util.rb, line 36
def dump_function_call_graph(phase_ctxt)
  if $DEBUG
    proj_name = phase_ctxt.traits.of_project.project_name
    map_fname = Pathname.new("#{proj_name}.map")
    map_fpath = map_fname.expand_path(phase_ctxt.msg_fpath.dirname)

    map = phase_ctxt[:ld_function_map]
    call_graph = phase_ctxt[:ld_call_graph]
    return unless map && call_graph

    File.open(map_fpath, "w") do |io|
      io.puts("-- Function Call Graph --")
      map.all_functions.each do |callee|
        io.puts("DC of #{callee.signature}")
        call_graph.direct_callers_of(callee).each do |ref|
          if fun = ref.function
            io.puts(" #{fun.signature}")
          end
        end
        io.puts
        io.puts("IC of #{callee.signature}")
        call_graph.indirect_callers_of(callee).each do |ref|
          if fun = ref.function
            io.puts(" #{fun.signature}")
          end
        end
        io.puts
      end
    end
  end
end
dump_variable_reference_graph(phase_ctxt) click to toggle source
# File lib/adlint/ld/util.rb, line 69
def dump_variable_reference_graph(phase_ctxt)
  if $DEBUG
    proj_name = phase_ctxt.traits.of_project.project_name
    map_fname = Pathname.new("#{proj_name}.map")
    map_fpath = map_fname.expand_path(phase_ctxt.msg_fpath.dirname)

    map = phase_ctxt[:ld_variable_map]
    ref_graph = phase_ctxt[:ld_xref_graph]
    return unless map && ref_graph

    File.open(map_fpath, "a") do |io|
      io.puts("-- Variable Reference Graph --")
      map.all_variables.each do |accessee|
        io.puts("DR of #{accessee.name}")
        ref_graph.direct_referrers_of(accessee).each do |ref|
          if fun = ref.function
            io.puts(" #{fun.signature}")
          end
        end
        io.puts
        io.puts("IR or #{accessee.name}")
        ref_graph.indirect_referrers_of(accessee).each do |ref|
          if fun = ref.function
            io.puts(" #{fun.signature}")
          end
        end
        io.puts
      end
    end
  end
end

Private Instance Methods

dump_function_call_graph(phase_ctxt) click to toggle source
# File lib/adlint/ld/util.rb, line 36
def dump_function_call_graph(phase_ctxt)
  if $DEBUG
    proj_name = phase_ctxt.traits.of_project.project_name
    map_fname = Pathname.new("#{proj_name}.map")
    map_fpath = map_fname.expand_path(phase_ctxt.msg_fpath.dirname)

    map = phase_ctxt[:ld_function_map]
    call_graph = phase_ctxt[:ld_call_graph]
    return unless map && call_graph

    File.open(map_fpath, "w") do |io|
      io.puts("-- Function Call Graph --")
      map.all_functions.each do |callee|
        io.puts("DC of #{callee.signature}")
        call_graph.direct_callers_of(callee).each do |ref|
          if fun = ref.function
            io.puts(" #{fun.signature}")
          end
        end
        io.puts
        io.puts("IC of #{callee.signature}")
        call_graph.indirect_callers_of(callee).each do |ref|
          if fun = ref.function
            io.puts(" #{fun.signature}")
          end
        end
        io.puts
      end
    end
  end
end
dump_variable_reference_graph(phase_ctxt) click to toggle source
# File lib/adlint/ld/util.rb, line 69
def dump_variable_reference_graph(phase_ctxt)
  if $DEBUG
    proj_name = phase_ctxt.traits.of_project.project_name
    map_fname = Pathname.new("#{proj_name}.map")
    map_fpath = map_fname.expand_path(phase_ctxt.msg_fpath.dirname)

    map = phase_ctxt[:ld_variable_map]
    ref_graph = phase_ctxt[:ld_xref_graph]
    return unless map && ref_graph

    File.open(map_fpath, "a") do |io|
      io.puts("-- Variable Reference Graph --")
      map.all_variables.each do |accessee|
        io.puts("DR of #{accessee.name}")
        ref_graph.direct_referrers_of(accessee).each do |ref|
          if fun = ref.function
            io.puts(" #{fun.signature}")
          end
        end
        io.puts
        io.puts("IR or #{accessee.name}")
        ref_graph.indirect_referrers_of(accessee).each do |ref|
          if fun = ref.function
            io.puts(" #{fun.signature}")
          end
        end
        io.puts
      end
    end
  end
end