comparison dep.pl @ 142:d29b64170cf0 libtommath-orig

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