annotate dep.pl @ 163:8e94663164c6 libtommath LTM_DB_0.44

make pointers volatile so that memory zeroing won't get optimised away
author Matt Johnston <matt@ucc.asn.au>
date Sun, 02 Jan 2005 17:09:26 +0000
parents d29b64170cf0
children d8254fc979e9
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
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 # 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
17 $define =~ tr/[a-z]/[A-Z]/;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 $define =~ tr/\./_/;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 print CLASS "#define $define\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 # now copy text and apply #ifdef as required
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 my $apply = 0;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 open(SRC, "<$filename");
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 open(OUT, ">tmp");
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 # first line will be the #ifdef
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 my $line = <SRC>;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 if ($line =~ /include/) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 print OUT $line;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 } else {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 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
32 $apply = 1;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 while (<SRC>) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 if (!($_ =~ /tommath\.h/)) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 print OUT $_;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 if ($apply == 1) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 print OUT "#endif\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 close SRC;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 close OUT;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 unlink($filename);
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 rename("tmp", $filename);
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 print CLASS "#endif\n\n";
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 # now do classes
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 foreach my $filename (glob "bn*.c") {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 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
54
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 # 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
56 $filename =~ tr/[a-z]/[A-Z]/;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 $filename =~ tr/\./_/;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 print CLASS "#if defined($filename)\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 my $list = $filename;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 # scan for mp_* and make classes
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 while (<SRC>) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 my $line = $_;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 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
66 $line = $';
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 # 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
68 # mp_int, mp_word, mp_digit
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 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
70 my $a = $&;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 $a =~ tr/[a-z]/[A-Z]/;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 $a = "BN_" . $a . "_C";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 if (!($list =~ /$a/)) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 print CLASS " #define $a\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 $list = $list . "," . $a;
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 }
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 @deplist{$filename} = $list;
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 print CLASS "#endif\n\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 close SRC;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 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
87 close CLASS;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 #now let's make a cool call graph...
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 open(OUT,">callgraph.txt");
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 $indent = 0;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 foreach (keys %deplist) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 $list = "";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 draw_func(@deplist{$_});
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 print OUT "\n\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 close(OUT);
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 sub draw_func()
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 my @funcs = split(",", $_[0]);
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 if ($list =~ /@funcs[0]/) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 return;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 } else {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 $list = $list . @funcs[0];
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 if ($indent == 0) { }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 elsif ($indent >= 1) { print OUT "| " x ($indent - 1) . "+--->"; }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 print OUT @funcs[0] . "\n";
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 shift @funcs;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 my $temp = $list;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 foreach my $i (@funcs) {
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 ++$indent;
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 draw_func(@deplist{$i});
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 }
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 $list = $temp;
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
d29b64170cf0 import of libtommath 0.32
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121