Module: AdLint::Ld::DebugUtil

Defined in:
lib/adlint/ld/util.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.dump_function_call_graph(phase_ctxt) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 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