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