File: findsym.pl

package info (click to toggle)
asymptote 2.69%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 18,532 kB
  • sloc: cpp: 61,286; ansic: 48,418; python: 8,585; javascript: 4,283; sh: 4,069; perl: 1,564; lisp: 1,505; makefile: 609; yacc: 554; lex: 446
file content (53 lines) | stat: -rwxr-xr-x 1,245 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env perl
#####
# findsym.pl
# Andy Hammerlindl 2010/06/01
#
#  Extract static symbols used in builtin.cc and write code so that they are
#  translated only once when creating the symbol table.
#####

$outname = shift(@ARGV);
if (not $outname) {
    print STDERR "usage ./findsym.pl out_symbols.h file1.cc file2.cc ...\n";
    exit(1);
}

open(header, ">$outname") ||
    die("Couldn't open $outname for writing");

print header <<END;
/*****
 * This file is automatically generated by findsym.pl
 * Changes will be overwritten.
 *****/

// If the ADDSYMBOL macro is not already defined, define it with the default
// purpose of referring to an external pre-translated symbol, such that
// SYM(name) also refers to that symbol.
#ifndef ADDSYMBOL
    #define ADDSYMBOL(name) extern sym::symbol PRETRANSLATED_SYMBOL_##name
    #define SYM(name) PRETRANSLATED_SYMBOL_##name
#endif

END

sub add {
  print header "ADDSYMBOL(".$_[0].");\n";
}

my %symbols = ();

foreach my $inname (@ARGV) {
    open(infile, $inname) ||
        die("Couldn't open $inname");
    while (<infile>) {
        while (m/SYM\(([_A-Za-z][_A-Za-z0-9]*)\)/gx) {
            $symbols{ $1 } = 1;
        }
    }
}

foreach my $s (sort keys %symbols) {
    add($s);
}