Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify scripts #293

Merged
merged 8 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 0 additions & 169 deletions dep.pl

This file was deleted.

162 changes: 162 additions & 0 deletions helper.pl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,167 @@ sub process_makefiles {
}
}

sub draw_func
{
my ($deplist, $depmap, $out, $indent, $funcslist) = @_;
my @funcs = split ',', $funcslist;
# try this if you want to have a look at a minimized version of the callgraph without all the trivial functions
#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/) {
if ($deplist =~ /$funcs[0]/) {
return $deplist;
} else {
$deplist = $deplist . $funcs[0];
}
if ($indent == 0) {
} elsif ($indent >= 1) {
print {$out} '| ' x ($indent - 1) . '+--->';
}
print {$out} $funcs[0] . "\n";
shift @funcs;
my $olddeplist = $deplist;
foreach my $i (@funcs) {
$deplist = draw_func($deplist, $depmap, $out, $indent + 1, ${$depmap}{$i}) if exists ${$depmap}{$i};
}
return $olddeplist;
}

sub update_dep
{
#open class file and write preamble
open(my $class, '>', 'tommath_class.h') or die "Couldn't open tommath_class.h for writing\n";
print {$class} << 'EOS';
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */

#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))
#if defined(LTM2)
# define LTM3
#endif
#if defined(LTM1)
# define LTM2
#endif
#define LTM1
#if defined(LTM_ALL)
EOS

foreach my $filename (glob 'bn*.c') {
my $define = $filename;

print "Processing $filename\n";

# convert filename to upper case so we can use it as a define
$define =~ tr/[a-z]/[A-Z]/;
$define =~ tr/\./_/;
print {$class} << "EOS";
# define $define
EOS

# now copy text and apply #ifdef as required
my $apply = 0;
open(my $src, '<', $filename);
open(my $out, '>', 'tmp');

# first line will be the #ifdef
my $line = <$src>;
if ($line =~ /include/) {
print {$out} $line;
} else {
print {$out} << "EOS";
#include "tommath_private.h"
#ifdef $define
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
$line
EOS
$apply = 1;
}
while (<$src>) {
if (!($_ =~ /tommath\.h/)) {
print {$out} $_;
}
}
if ($apply == 1) {
print {$out} << 'EOS';
#endif
EOS
}
close $src;
close $out;

unlink $filename;
rename 'tmp', $filename;
}
print {$class} << 'EOS';
#endif
EOS

# now do classes
my %depmap;
foreach my $filename (glob 'bn*.c') {
open(my $src, '<', $filename) or die "Can't open source file!\n";
read $src, my $content, -s $src;
close $src;

# convert filename to upper case so we can use it as a define
$filename =~ tr/[a-z]/[A-Z]/;
$filename =~ tr/\./_/;

print {$class} << "EOS";
#if defined($filename)
EOS
my $list = $filename;

# strip comments
$content =~ s{/\*.*?\*/}{}gs;

# scan for mp_* and make classes
foreach my $line (split /\n/, $content) {
while ($line =~ /(fast_)?(s_)?mp\_[a-z_0-9]*(?=\()|(?<=\()mp\_[a-z_0-9]*(?=,)/g) {
my $a = $&;
next if $a eq "mp_err";
$a =~ tr/[a-z]/[A-Z]/;
$a = 'BN_' . $a . '_C';
if (!($list =~ /$a/)) {
print {$class} << "EOS";
# define $a
EOS
}
$list = $list . ',' . $a;
}
}
$depmap{$filename} = $list;

print {$class} << 'EOS';
#endif

EOS
}

print {$class} << 'EOS';
#ifdef LTM3
# define LTM_LAST
#endif

#include "tommath_superclass.h"
#include "tommath_class.h"
#else
# define LTM_LAST
#endif
EOS
close $class;

#now let's make a cool call graph...

open(my $out, '>', 'callgraph.txt');
foreach (sort keys %depmap) {
draw_func("", \%depmap, $out, 0, $depmap{$_});
print {$out} "\n\n";
}
close $out;

return 0;
}

sub die_usage {
die <<"MARKER";
usage: $0 -s OR $0 --check-source
Expand All @@ -300,6 +461,7 @@ sub die_usage {
$failure ||= check_doc() if $check_doc; # temporarily excluded from --check-all
$failure ||= process_makefiles(0) if $check_all || $check_makefiles;
$failure ||= process_makefiles(1) if $update_makefiles;
$failure ||= update_dep() if $update_makefiles;

die_usage unless defined $failure;
exit $failure ? 1 : 0;
3 changes: 1 addition & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ zipup: clean astyle new_file manual poster docs
gpg -b -a ltm-$(VERSION).zip

new_file:
bash updatemakes.sh
perl dep.pl
perl helper.pl --update-makefiles

perlcritic:
perlcritic *.pl doc/*.pl
Expand Down
2 changes: 1 addition & 1 deletion makefile.mingw
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MAKEFILE for MS Windows (mingw + gcc + gmake)
#
# BEWARE: variable OBJECTS is updated via ./updatemakes.sh
# BEWARE: variable OBJECTS is updated via helper.pl

### USAGE:
# Open a command prompt with gcc + gmake in PATH and start:
Expand Down
2 changes: 1 addition & 1 deletion makefile.msvc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MAKEFILE for MS Windows (nmake + Windows SDK)
#
# BEWARE: variable OBJECTS is updated via ./updatemakes.sh
# BEWARE: variable OBJECTS is updated via helper.pl

### USAGE:
# Open a command prompt with WinSDK variables set and start:
Expand Down
7 changes: 4 additions & 3 deletions testme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,10 @@ if [[ "$CHECK_FORMAT" == "1" ]]
then
make astyle
_check_git "make astyle"
make new_file
_check_git "make format"
perl helper.pl -a
perl helper.pl --update-makefiles
_check_git "helper.pl --update-makefiles"
perl helper.pl --check-all
_check_git "helper.pl --check-all"
exit $?
fi

Expand Down
12 changes: 0 additions & 12 deletions updatemakes.sh

This file was deleted.