From d45a80ec1c22576808d0c166ab97265e9e8989a4 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Fri, 24 May 2019 12:10:07 +0200 Subject: [PATCH 1/8] remove updatemakes script, it is just an indirection calling helper.pl --- makefile | 2 +- makefile.mingw | 2 +- makefile.msvc | 2 +- updatemakes.sh | 12 ------------ 4 files changed, 3 insertions(+), 15 deletions(-) delete mode 100755 updatemakes.sh diff --git a/makefile b/makefile index 3c694589d..4f4099104 100644 --- a/makefile +++ b/makefile @@ -149,7 +149,7 @@ zipup: clean astyle new_file manual poster docs gpg -b -a ltm-$(VERSION).zip new_file: - bash updatemakes.sh + perl helper.pl --update-makefiles || exit 1 perl dep.pl perlcritic: diff --git a/makefile.mingw b/makefile.mingw index 2a45b0e12..6023ebcfc 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -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: diff --git a/makefile.msvc b/makefile.msvc index 12ec4affc..ef2b4720b 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -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: diff --git a/updatemakes.sh b/updatemakes.sh deleted file mode 100755 index 917b0e48c..000000000 --- a/updatemakes.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -./helper.pl --update-makefiles || exit 1 - -makefiles=(makefile makefile.shared makefile_include.mk makefile.msvc makefile.unix makefile.mingw) -vcproj=(libtommath_VS2008.vcproj) - -if [ $# -eq 1 ] && [ "$1" == "-c" ]; then - git add ${makefiles[@]} ${vcproj[@]} && git commit -m 'Update makefiles' -fi - -exit 0 From 712919f3378446296ebda65f42579da0248f24a0 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Fri, 24 May 2019 12:17:13 +0200 Subject: [PATCH 2/8] [WIP] start to make dep.pl part of helper.pl --- dep.pl => helper-dep.pl | 0 helper.pl | 6 ++++++ makefile | 3 +-- testme.sh | 7 ++++--- 4 files changed, 11 insertions(+), 5 deletions(-) rename dep.pl => helper-dep.pl (100%) mode change 100755 => 100644 diff --git a/dep.pl b/helper-dep.pl old mode 100755 new mode 100644 similarity index 100% rename from dep.pl rename to helper-dep.pl diff --git a/helper.pl b/helper.pl index 4aac5743a..9543598f8 100755 --- a/helper.pl +++ b/helper.pl @@ -275,6 +275,11 @@ sub process_makefiles { } } +sub update_dep { + system("perl helper-dep.pl"); + return $? != 0; +} + sub die_usage { die <<"MARKER"; usage: $0 -s OR $0 --check-source @@ -300,6 +305,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; diff --git a/makefile b/makefile index 4f4099104..74c557c3a 100644 --- a/makefile +++ b/makefile @@ -149,8 +149,7 @@ zipup: clean astyle new_file manual poster docs gpg -b -a ltm-$(VERSION).zip new_file: - perl helper.pl --update-makefiles || exit 1 - perl dep.pl + perl helper.pl --update-makefiles perlcritic: perlcritic *.pl doc/*.pl diff --git a/testme.sh b/testme.sh index f34d96f6f..0e035ce4f 100755 --- a/testme.sh +++ b/testme.sh @@ -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 From 26548f0f4e3548616cab91162e4300d7ff85b1f9 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Fri, 24 May 2019 12:26:17 +0200 Subject: [PATCH 3/8] make helper-dep.pl part of helper.pl --- helper-dep.pl | 169 -------------------------------------------------- helper.pl | 168 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 165 insertions(+), 172 deletions(-) delete mode 100644 helper-dep.pl diff --git a/helper-dep.pl b/helper-dep.pl deleted file mode 100644 index ceef32d34..000000000 --- a/helper-dep.pl +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/perl -# -# Walk through source, add labels and make classes -# -use strict; -use warnings; - -my %deplist; - -#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 - -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; - } - } - $deplist{$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'); -my $indent = 0; -my $list; -foreach (sort keys %deplist) { - $list = ''; - draw_func($deplist{$_}); - print {$out} "\n\n"; -} -close $out; - -sub draw_func -{ - my @funcs = split ',', $_[0]; - # try this if you want to have a look at a minimized version of the callgraph without all the trivial functions - #if ($list =~ /$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 ($list =~ /$funcs[0]/) { - return; - } else { - $list = $list . $funcs[0]; - } - if ($indent == 0) { - } elsif ($indent >= 1) { - print {$out} '| ' x ($indent - 1) . '+--->'; - } - print {$out} $funcs[0] . "\n"; - shift @funcs; - my $temp = $list; - foreach my $i (@funcs) { - ++$indent; - draw_func($deplist{$i}) if exists $deplist{$i}; - --$indent; - } - $list = $temp; - return; -} diff --git a/helper.pl b/helper.pl index 9543598f8..f155bbed8 100755 --- a/helper.pl +++ b/helper.pl @@ -275,9 +275,171 @@ sub process_makefiles { } } -sub update_dep { - system("perl helper-dep.pl"); - return $? != 0; +my %deplist; +my $deplist; +my $indent = 0; + +sub draw_func +{ + my ($out, $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; + } else { + $deplist = $deplist . $funcs[0]; + } + if ($indent == 0) { + } elsif ($indent >= 1) { + print {$out} '| ' x ($indent - 1) . '+--->'; + } + print {$out} $funcs[0] . "\n"; + shift @funcs; + my $temp = $deplist; + foreach my $i (@funcs) { + ++$indent; + draw_func($out, $deplist{$i}) if exists $deplist{$i}; + --$indent; + } + $deplist = $temp; + return; +} + +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 + + 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; + } + } + $deplist{$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 %deplist) { + $deplist = ''; + draw_func($out, $deplist{$_}); + print {$out} "\n\n"; + } + close $out; } sub die_usage { From 36b4411cc74e73610f915d8c50e72d0dca6262f7 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Fri, 24 May 2019 12:26:50 +0200 Subject: [PATCH 4/8] remove indent global var --- helper.pl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/helper.pl b/helper.pl index f155bbed8..9c232c30c 100755 --- a/helper.pl +++ b/helper.pl @@ -277,11 +277,10 @@ sub process_makefiles { my %deplist; my $deplist; -my $indent = 0; sub draw_func { - my ($out, $funcslist) = @_; + my ($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/) { @@ -298,9 +297,7 @@ sub draw_func shift @funcs; my $temp = $deplist; foreach my $i (@funcs) { - ++$indent; - draw_func($out, $deplist{$i}) if exists $deplist{$i}; - --$indent; + draw_func($out, $indent + 1, $deplist{$i}) if exists $deplist{$i}; } $deplist = $temp; return; @@ -436,7 +433,7 @@ sub update_dep open(my $out, '>', 'callgraph.txt'); foreach (sort keys %deplist) { $deplist = ''; - draw_func($out, $deplist{$_}); + draw_func($out, 0, $deplist{$_}); print {$out} "\n\n"; } close $out; From 4f26de17a201a19870bc063c0d2bd912c9935a8a Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Fri, 24 May 2019 12:35:11 +0200 Subject: [PATCH 5/8] fix return value --- helper.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/helper.pl b/helper.pl index 9c232c30c..614aeb2de 100755 --- a/helper.pl +++ b/helper.pl @@ -437,6 +437,8 @@ sub update_dep print {$out} "\n\n"; } close $out; + + return 0; } sub die_usage { From 25d663d047c45fa4a3c49d87d925f86076b47fa8 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Fri, 24 May 2019 12:35:58 +0200 Subject: [PATCH 6/8] rename deplist to depmap --- helper.pl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/helper.pl b/helper.pl index 614aeb2de..be74c9e37 100755 --- a/helper.pl +++ b/helper.pl @@ -275,7 +275,7 @@ sub process_makefiles { } } -my %deplist; +my %depmap; my $deplist; sub draw_func @@ -297,7 +297,7 @@ sub draw_func shift @funcs; my $temp = $deplist; foreach my $i (@funcs) { - draw_func($out, $indent + 1, $deplist{$i}) if exists $deplist{$i}; + draw_func($out, $indent + 1, $depmap{$i}) if exists $depmap{$i}; } $deplist = $temp; return; @@ -407,7 +407,7 @@ sub update_dep $list = $list . ',' . $a; } } - $deplist{$filename} = $list; + $depmap{$filename} = $list; print {$class} << 'EOS'; #endif @@ -431,9 +431,9 @@ sub update_dep #now let's make a cool call graph... open(my $out, '>', 'callgraph.txt'); - foreach (sort keys %deplist) { + foreach (sort keys %depmap) { $deplist = ''; - draw_func($out, 0, $deplist{$_}); + draw_func($out, 0, $depmap{$_}); print {$out} "\n\n"; } close $out; From dfcaf41f758cbdc9f4015abc7a56734ac51e3dca Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Fri, 24 May 2019 12:38:04 +0200 Subject: [PATCH 7/8] remove global %depmap --- helper.pl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/helper.pl b/helper.pl index be74c9e37..26091a853 100755 --- a/helper.pl +++ b/helper.pl @@ -275,12 +275,11 @@ sub process_makefiles { } } -my %depmap; my $deplist; sub draw_func { - my ($out, $indent, $funcslist) = @_; + my ($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/) { @@ -297,7 +296,7 @@ sub draw_func shift @funcs; my $temp = $deplist; foreach my $i (@funcs) { - draw_func($out, $indent + 1, $depmap{$i}) if exists $depmap{$i}; + draw_func($depmap, $out, $indent + 1, ${$depmap}{$i}) if exists ${$depmap}{$i}; } $deplist = $temp; return; @@ -374,7 +373,7 @@ sub update_dep 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; @@ -433,7 +432,7 @@ sub update_dep open(my $out, '>', 'callgraph.txt'); foreach (sort keys %depmap) { $deplist = ''; - draw_func($out, 0, $depmap{$_}); + draw_func(\%depmap, $out, 0, $depmap{$_}); print {$out} "\n\n"; } close $out; From 64be56e7d0dada6c401017e8075b223beb01e046 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Fri, 24 May 2019 12:40:17 +0200 Subject: [PATCH 8/8] remove global $deplist --- helper.pl | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/helper.pl b/helper.pl index 26091a853..27e145121 100755 --- a/helper.pl +++ b/helper.pl @@ -275,16 +275,14 @@ sub process_makefiles { } } -my $deplist; - sub draw_func { - my ($depmap, $out, $indent, $funcslist) = @_; + 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; + return $deplist; } else { $deplist = $deplist . $funcs[0]; } @@ -294,12 +292,11 @@ sub draw_func } print {$out} $funcs[0] . "\n"; shift @funcs; - my $temp = $deplist; + my $olddeplist = $deplist; foreach my $i (@funcs) { - draw_func($depmap, $out, $indent + 1, ${$depmap}{$i}) if exists ${$depmap}{$i}; + $deplist = draw_func($deplist, $depmap, $out, $indent + 1, ${$depmap}{$i}) if exists ${$depmap}{$i}; } - $deplist = $temp; - return; + return $olddeplist; } sub update_dep @@ -431,8 +428,7 @@ sub update_dep open(my $out, '>', 'callgraph.txt'); foreach (sort keys %depmap) { - $deplist = ''; - draw_func(\%depmap, $out, 0, $depmap{$_}); + draw_func("", \%depmap, $out, 0, $depmap{$_}); print {$out} "\n\n"; } close $out;