Skip to content

Commit c58c7f6

Browse files
authored
Merge pull request #293 from libtom/simplify-scripts
Simplify scripts
2 parents 53d45ad + 64be56e commit c58c7f6

File tree

7 files changed

+169
-188
lines changed

7 files changed

+169
-188
lines changed

dep.pl

Lines changed: 0 additions & 169 deletions
This file was deleted.

helper.pl

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,167 @@ sub process_makefiles {
275275
}
276276
}
277277

278+
sub draw_func
279+
{
280+
my ($deplist, $depmap, $out, $indent, $funcslist) = @_;
281+
my @funcs = split ',', $funcslist;
282+
# try this if you want to have a look at a minimized version of the callgraph without all the trivial functions
283+
#if ($deplist =~ /$funcs[0]/ || $funcs[0] =~ /BN_MP_(ADD|SUB|CLEAR|CLEAR_\S+|DIV|MUL|COPY|ZERO|GROW|CLAMP|INIT|INIT_\S+|SET|ABS|CMP|CMP_D|EXCH)_C/) {
284+
if ($deplist =~ /$funcs[0]/) {
285+
return $deplist;
286+
} else {
287+
$deplist = $deplist . $funcs[0];
288+
}
289+
if ($indent == 0) {
290+
} elsif ($indent >= 1) {
291+
print {$out} '| ' x ($indent - 1) . '+--->';
292+
}
293+
print {$out} $funcs[0] . "\n";
294+
shift @funcs;
295+
my $olddeplist = $deplist;
296+
foreach my $i (@funcs) {
297+
$deplist = draw_func($deplist, $depmap, $out, $indent + 1, ${$depmap}{$i}) if exists ${$depmap}{$i};
298+
}
299+
return $olddeplist;
300+
}
301+
302+
sub update_dep
303+
{
304+
#open class file and write preamble
305+
open(my $class, '>', 'tommath_class.h') or die "Couldn't open tommath_class.h for writing\n";
306+
print {$class} << 'EOS';
307+
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
308+
/* SPDX-License-Identifier: Unlicense */
309+
310+
#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))
311+
#if defined(LTM2)
312+
# define LTM3
313+
#endif
314+
#if defined(LTM1)
315+
# define LTM2
316+
#endif
317+
#define LTM1
318+
#if defined(LTM_ALL)
319+
EOS
320+
321+
foreach my $filename (glob 'bn*.c') {
322+
my $define = $filename;
323+
324+
print "Processing $filename\n";
325+
326+
# convert filename to upper case so we can use it as a define
327+
$define =~ tr/[a-z]/[A-Z]/;
328+
$define =~ tr/\./_/;
329+
print {$class} << "EOS";
330+
# define $define
331+
EOS
332+
333+
# now copy text and apply #ifdef as required
334+
my $apply = 0;
335+
open(my $src, '<', $filename);
336+
open(my $out, '>', 'tmp');
337+
338+
# first line will be the #ifdef
339+
my $line = <$src>;
340+
if ($line =~ /include/) {
341+
print {$out} $line;
342+
} else {
343+
print {$out} << "EOS";
344+
#include "tommath_private.h"
345+
#ifdef $define
346+
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
347+
/* SPDX-License-Identifier: Unlicense */
348+
$line
349+
EOS
350+
$apply = 1;
351+
}
352+
while (<$src>) {
353+
if (!($_ =~ /tommath\.h/)) {
354+
print {$out} $_;
355+
}
356+
}
357+
if ($apply == 1) {
358+
print {$out} << 'EOS';
359+
#endif
360+
EOS
361+
}
362+
close $src;
363+
close $out;
364+
365+
unlink $filename;
366+
rename 'tmp', $filename;
367+
}
368+
print {$class} << 'EOS';
369+
#endif
370+
EOS
371+
372+
# now do classes
373+
my %depmap;
374+
foreach my $filename (glob 'bn*.c') {
375+
open(my $src, '<', $filename) or die "Can't open source file!\n";
376+
read $src, my $content, -s $src;
377+
close $src;
378+
379+
# convert filename to upper case so we can use it as a define
380+
$filename =~ tr/[a-z]/[A-Z]/;
381+
$filename =~ tr/\./_/;
382+
383+
print {$class} << "EOS";
384+
#if defined($filename)
385+
EOS
386+
my $list = $filename;
387+
388+
# strip comments
389+
$content =~ s{/\*.*?\*/}{}gs;
390+
391+
# scan for mp_* and make classes
392+
foreach my $line (split /\n/, $content) {
393+
while ($line =~ /(fast_)?(s_)?mp\_[a-z_0-9]*(?=\()|(?<=\()mp\_[a-z_0-9]*(?=,)/g) {
394+
my $a = $&;
395+
next if $a eq "mp_err";
396+
$a =~ tr/[a-z]/[A-Z]/;
397+
$a = 'BN_' . $a . '_C';
398+
if (!($list =~ /$a/)) {
399+
print {$class} << "EOS";
400+
# define $a
401+
EOS
402+
}
403+
$list = $list . ',' . $a;
404+
}
405+
}
406+
$depmap{$filename} = $list;
407+
408+
print {$class} << 'EOS';
409+
#endif
410+
411+
EOS
412+
}
413+
414+
print {$class} << 'EOS';
415+
#ifdef LTM3
416+
# define LTM_LAST
417+
#endif
418+
419+
#include "tommath_superclass.h"
420+
#include "tommath_class.h"
421+
#else
422+
# define LTM_LAST
423+
#endif
424+
EOS
425+
close $class;
426+
427+
#now let's make a cool call graph...
428+
429+
open(my $out, '>', 'callgraph.txt');
430+
foreach (sort keys %depmap) {
431+
draw_func("", \%depmap, $out, 0, $depmap{$_});
432+
print {$out} "\n\n";
433+
}
434+
close $out;
435+
436+
return 0;
437+
}
438+
278439
sub die_usage {
279440
die <<"MARKER";
280441
usage: $0 -s OR $0 --check-source
@@ -300,6 +461,7 @@ sub die_usage {
300461
$failure ||= check_doc() if $check_doc; # temporarily excluded from --check-all
301462
$failure ||= process_makefiles(0) if $check_all || $check_makefiles;
302463
$failure ||= process_makefiles(1) if $update_makefiles;
464+
$failure ||= update_dep() if $update_makefiles;
303465

304466
die_usage unless defined $failure;
305467
exit $failure ? 1 : 0;

makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ zipup: clean astyle new_file manual poster docs
149149
gpg -b -a ltm-$(VERSION).zip
150150

151151
new_file:
152-
bash updatemakes.sh
153-
perl dep.pl
152+
perl helper.pl --update-makefiles
154153

155154
perlcritic:
156155
perlcritic *.pl doc/*.pl

makefile.mingw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MAKEFILE for MS Windows (mingw + gcc + gmake)
22
#
3-
# BEWARE: variable OBJECTS is updated via ./updatemakes.sh
3+
# BEWARE: variable OBJECTS is updated via helper.pl
44

55
### USAGE:
66
# Open a command prompt with gcc + gmake in PATH and start:

makefile.msvc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MAKEFILE for MS Windows (nmake + Windows SDK)
22
#
3-
# BEWARE: variable OBJECTS is updated via ./updatemakes.sh
3+
# BEWARE: variable OBJECTS is updated via helper.pl
44

55
### USAGE:
66
# Open a command prompt with WinSDK variables set and start:

testme.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,10 @@ if [[ "$CHECK_FORMAT" == "1" ]]
295295
then
296296
make astyle
297297
_check_git "make astyle"
298-
make new_file
299-
_check_git "make format"
300-
perl helper.pl -a
298+
perl helper.pl --update-makefiles
299+
_check_git "helper.pl --update-makefiles"
300+
perl helper.pl --check-all
301+
_check_git "helper.pl --check-all"
301302
exit $?
302303
fi
303304

updatemakes.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)