var_sym: fix expr_to_vsl() for dereferences
[smatch.git] / smatch_scripts / follow_params.pl
blobb2b8e77320cae26bc51e1754167b543b9e402615
1 #!/usr/bin/perl
3 use strict;
5 sub usage()
7 print "$0 <smatch output file> <function> <parameter>\n";
8 print "Give this program a function and parameter and it follows to find\n";
9 print "how the parameter gets passed down to lower levels.\n'";
10 exit(1);
13 my %param_map;
15 my $UNUSED = 0;
16 my $USED = 1;
18 sub print_link($)
20 my $link = shift;
22 $link =~ s/%/ /;
23 print "$link\n";
26 sub recurse($)
28 my $link = shift;
30 if ($param_map{$link}{used} == $USED) {
31 return;
33 ${param_map}{$link}->{used} = $USED;
35 print_link($link);
37 foreach my $l (@{$param_map{$link}{links}}){
38 recurse($l);
43 sub follow($$)
45 my $f = shift;
46 my $p = shift;
48 recurse("$f%$p");
51 sub add_link($$)
53 my $one = shift;
54 my $two = shift;
56 if (!defined($param_map{$one})) {
57 $param_map{$one} = {used => $UNUSED, links => []};
59 push @{$param_map{$one}{links}}, $two;
62 sub load_all($)
64 my $file = shift;
66 open(FILE, "<$file");
67 while (<FILE>) {
68 if (/.*?:\d+ (.*?)\(\) info: param_mapper (\d+) => (.*?) (\d+)/) {
69 add_link("$1%$2", "$3%$4");
74 sub set_all_unused()
76 foreach my $func (keys %param_map){
77 ($param_map{$func}{used} = $UNUSED);
82 my $file = shift();
83 my $func = shift();
84 my $param = shift();
86 if (!defined($file) or !defined($func) or !defined($param)) {
87 usage();
90 if (! -e $file) {
91 printf("Error: $file does not exist.\n");
92 exit(1);
95 load_all($file);
97 while (1) {
98 follow($func, $param);
100 $func = shift();
101 $param = shift();
102 if (!defined($func) || !defined($param)) {
103 last;
105 set_all_unused();