A little script to find LLVM symbols. Ideally this would use c++filt for
[oota-llvm.git] / utils / findsym.pl
1 #!/usr/bin/perl -w
2 #
3 # Program:  findsym.pl
4 #
5 # Synopsis: Generate a list of the libraries in which a symbol is defined or
6 #           referenced.
7 #
8 # Syntax:   GenLibDeps.pl <directory_with_libraries_in_it> <symbol>
9 #
10
11 # Give first option a name.
12 my $Directory = $ARGV[0];
13 my $Symbol = $ARGV[1];
14
15
16 # Open the directory and read its contents, sorting by name and differentiating
17 # by whether its a library (.a) or an object file (.o)
18 opendir DIR,$Directory;
19 my @files = readdir DIR;
20 closedir DIR;
21 @objects = grep(/l?i?b?LLVM.*\.[oa]$/,sort(@files));
22
23 # Gather definitions from the libraries
24 foreach $lib (@objects) {
25   my $head = 0;
26   open SYMS, 
27     "nm $Directory/$lib | grep '$Symbol' | sort --key=3 | uniq |";
28   while (<SYMS>) {
29     if (!$head) { print "$lib:\n"; $head = 1; }
30     chomp($_);
31     print "  $_\n";
32   }
33   close SYMS;
34 }