annotate dep.pl @ 203:e109027b9edf libtommath LTM_DB_0.46 LTM_DB_0.47

Don't remove ~ files on make clean (and find -type was wrong anyway)
author Matt Johnston <matt@ucc.asn.au>
date Wed, 11 May 2005 16:27:28 +0000
parents d8254fc979e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
142
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #!/usr/bin/perl
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 # Walk through source, add labels and make classes
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 #
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 #use strict;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 my %deplist;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 #open class file and write preamble
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 open(CLASS, ">tommath_class.h") or die "Couldn't open tommath_class.h for writing\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 print CLASS "#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))\n#if defined(LTM2)\n#define LTM3\n#endif\n#if defined(LTM1)\n#define LTM2\n#endif\n#define LTM1\n\n#if defined(LTM_ALL)\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 foreach my $filename (glob "bn*.c") {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 my $define = $filename;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15
190
d8254fc979e9 Initial import of libtommath 0.35
Matt Johnston <matt@ucc.asn.au>
parents: 142
diff changeset
16 print "Processing $filename\n";
d8254fc979e9 Initial import of libtommath 0.35
Matt Johnston <matt@ucc.asn.au>
parents: 142
diff changeset
17
142
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 # convert filename to upper case so we can use it as a define
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 $define =~ tr/[a-z]/[A-Z]/;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 $define =~ tr/\./_/;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 print CLASS "#define $define\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 # now copy text and apply #ifdef as required
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 my $apply = 0;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 open(SRC, "<$filename");
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 open(OUT, ">tmp");
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 # first line will be the #ifdef
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 my $line = <SRC>;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 if ($line =~ /include/) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 print OUT $line;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 } else {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 print OUT "#include <tommath.h>\n#ifdef $define\n$line";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 $apply = 1;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 while (<SRC>) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 if (!($_ =~ /tommath\.h/)) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 print OUT $_;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 if ($apply == 1) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 print OUT "#endif\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 close SRC;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 close OUT;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 unlink($filename);
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 rename("tmp", $filename);
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 print CLASS "#endif\n\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 # now do classes
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 foreach my $filename (glob "bn*.c") {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 open(SRC, "<$filename") or die "Can't open source file!\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 # convert filename to upper case so we can use it as a define
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 $filename =~ tr/[a-z]/[A-Z]/;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 $filename =~ tr/\./_/;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 print CLASS "#if defined($filename)\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 my $list = $filename;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 # scan for mp_* and make classes
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 while (<SRC>) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 my $line = $_;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 while ($line =~ m/(fast_)*(s_)*mp\_[a-z_0-9]*/) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 $line = $';
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 # now $& is the match, we want to skip over LTM keywords like
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 # mp_int, mp_word, mp_digit
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 if (!($& eq "mp_digit") && !($& eq "mp_word") && !($& eq "mp_int")) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 my $a = $&;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 $a =~ tr/[a-z]/[A-Z]/;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 $a = "BN_" . $a . "_C";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 if (!($list =~ /$a/)) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 print CLASS " #define $a\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 $list = $list . "," . $a;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 @deplist{$filename} = $list;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 print CLASS "#endif\n\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 close SRC;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 print CLASS "#ifdef LTM3\n#define LTM_LAST\n#endif\n#include <tommath_superclass.h>\n#include <tommath_class.h>\n#else\n#define LTM_LAST\n#endif\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 close CLASS;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 #now let's make a cool call graph...
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 open(OUT,">callgraph.txt");
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 $indent = 0;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 foreach (keys %deplist) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 $list = "";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 draw_func(@deplist{$_});
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 print OUT "\n\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 close(OUT);
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 sub draw_func()
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 my @funcs = split(",", $_[0]);
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 if ($list =~ /@funcs[0]/) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 return;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 } else {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 $list = $list . @funcs[0];
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 if ($indent == 0) { }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 elsif ($indent >= 1) { print OUT "| " x ($indent - 1) . "+--->"; }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 print OUT @funcs[0] . "\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 shift @funcs;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 my $temp = $list;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 foreach my $i (@funcs) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 ++$indent;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 draw_func(@deplist{$i});
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 --$indent;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 $list = $temp;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123