From d5a6d3b04101d8b0c27eab3d65bae04e93c2e05b Mon Sep 17 00:00:00 2001 From: piecea Date: Mon, 16 May 2022 15:30:08 +0200 Subject: [PATCH 1/8] Add -MMD option --- t/80_vppreproc.t | 63 +++++++++++++++++++++++++----- t/80_vppreproc_v_hier_top_mmd.d | 1 + t/80_vppreproc_v_hier_top_mmd_mp.d | 3 ++ t/80_vppreproc_v_res.d | 2 + vppreproc | 60 ++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 t/80_vppreproc_v_hier_top_mmd.d create mode 100644 t/80_vppreproc_v_hier_top_mmd_mp.d create mode 100644 t/80_vppreproc_v_res.d diff --git a/t/80_vppreproc.t b/t/80_vppreproc.t index dd7e689..ca74bf4 100755 --- a/t/80_vppreproc.t +++ b/t/80_vppreproc.t @@ -9,13 +9,13 @@ use IO::File; use strict; use Test::More; -BEGIN { plan tests => 15 } +BEGIN { plan tests => 24 } BEGIN { require "./t/test_utils.pl"; } print "Checking vppreproc...\n"; -vppreproc ("t/80_vppreproc_none.out", "test_dir/vppreproc_none.v", ""); -vppreproc ("t/80_vppreproc_cmped.out", "test_dir/vppreproc_cmped.v", "--nocomment --pedantic"); +vppreproc ("t/80_vppreproc_none.out", "test_dir/vppreproc_none.v", ""); +vppreproc ("t/80_vppreproc_cmped.out", "test_dir/vppreproc_cmped.v", "--nocomment --pedantic"); vppreproc ("t/80_vppreproc_simple.out", "test_dir/vppreproc_simple.v", "--simple"); vppreproc ("t/80_vppreproc_defines.out", "test_dir/vppreproc_defines.v", "--dump-defines"); vppreproc ("t/80_vppreproc_rel_file.out", "test_dir/vppreproc_rel_file.v", "-f verilog/t_80_foo.f"); @@ -28,12 +28,57 @@ sub vppreproc { my $cmd = "${PERL} ./vppreproc ${flags} -y verilog inc2.v > $out"; if (0 == run_system_no_die ($cmd)) { - pass("run command"); - ok(-r $out, "vppreproc output from: $cmd"); - ok(files_identical ($out, $checkname), "diff"); + pass("run command"); + ok(-r $out, "vppreproc output from: $cmd"); + ok(files_identical ($out, $checkname), "diff"); } else { - fail ("run command"); - fail ("no output file created"); - fail ("no output file to compare"); + fail ("run command"); + fail ("no output file created"); + fail ("no output file to compare"); } } + + + +# Test -MMD -MP +vppreproc_d ("t/80_vppreproc_v_hier_top_mmd_mp.d", "-MMD -MP"); +vppreproc_d ("t/80_vppreproc_v_hier_top_mmd.d", "-MMD"); +vppreproc_d_o(); + +sub vppreproc_d { + my $checkname = shift; + my $flags = shift; + my $defaultcfg = "verilog/v_hier_top.v verilog/v_sv_intf.v +incdir+verilog"; + my $cmd = "${PERL} ./vppreproc $flags $defaultcfg"; + my $dotd = "verilog/v_hier_top.v.d"; + if (0 == run_system_no_die ($cmd)) { + pass("run command"); + ok(-r $dotd, "vppreproc .d from: $cmd"); + ok(files_identical ($dotd, $checkname), "diff"); + } else { + fail ("run command"); + fail ("no output file created"); + fail ("no output file to compare"); + } + system ("/bin/rm -f verilog/v_hier_top.v.d verilog/v_sv_intf.v.d"); +} + +sub vppreproc_d_o { + my $obasename = "res"; + my $checkname = "t/80_vppreproc_v_res.d"; + my $defaultcfg = "verilog/v_hier_top.v verilog/v_sv_intf.v +incdir+verilog"; + my $cmd = "${PERL} ./vppreproc -MMD -o test_dir/$obasename.vpp $defaultcfg"; + my $dotd = "test_dir/$obasename.d"; + + system ("/bin/rm -f $dotd"); + if (0 == run_system_no_die ($cmd)) { + pass("run command"); + ok(-r $dotd, "vppreproc .d from: $cmd"); + ok(files_identical ($dotd, $checkname), "diff"); + } else { + fail ("run command"); + fail ("no output file created"); + fail ("no output file to compare"); + } +} + diff --git a/t/80_vppreproc_v_hier_top_mmd.d b/t/80_vppreproc_v_hier_top_mmd.d new file mode 100644 index 0000000..05569d3 --- /dev/null +++ b/t/80_vppreproc_v_hier_top_mmd.d @@ -0,0 +1 @@ +verilog/v_hier_top.v.d: verilog/v_hier_top.v verilog/v_hier_inc.vh diff --git a/t/80_vppreproc_v_hier_top_mmd_mp.d b/t/80_vppreproc_v_hier_top_mmd_mp.d new file mode 100644 index 0000000..75391d5 --- /dev/null +++ b/t/80_vppreproc_v_hier_top_mmd_mp.d @@ -0,0 +1,3 @@ +verilog/v_hier_top.v.d: verilog/v_hier_top.v verilog/v_hier_inc.vh + +verilog/v_hier_inc.vh: diff --git a/t/80_vppreproc_v_res.d b/t/80_vppreproc_v_res.d new file mode 100644 index 0000000..e6582af --- /dev/null +++ b/t/80_vppreproc_v_res.d @@ -0,0 +1,2 @@ +test_dir/res.vpp: verilog/v_hier_top.v verilog/v_hier_inc.vh +test_dir/res.vpp: verilog/v_sv_intf.v verilog/v_sv_pkg.v diff --git a/vppreproc b/vppreproc index a1f6a05..9a6a0ad 100755 --- a/vppreproc +++ b/vppreproc @@ -10,6 +10,7 @@ use lib "$RealBin"; use Getopt::Long; use IO::File; use Pod::Usage; +use File::Basename; use Verilog::Preproc; use Verilog::Getopt; @@ -25,6 +26,8 @@ $Debug = 0; my $opt_output_filename = undef; my $opt_blank=1; my $opt_dump_defines; +my $opt_mmd; +my $opt_mp; my @opt_files; my @opt_pp_flags; @@ -45,6 +48,8 @@ if (! GetOptions ( "blank!" => \$opt_blank, "comment!" => sub { push @opt_pp_flags, (keep_comments=>$_[1]); }, "dump-defines!" => \$opt_dump_defines, + "MMD!" => \$opt_mmd, + "MP!" => \$opt_mp, "line!" => sub { push @opt_pp_flags, (line_directives=>$_[1]); }, "P!" => sub { $opt_blank=0; push @opt_pp_flags, (line_directives=>$_[1]); }, "pedantic!" => sub { push @opt_pp_flags, (pedantic=>$_[1]); }, @@ -93,6 +98,53 @@ if ($opt_dump_defines) { } } + +# MMD MP option +# produces a list of makefile dependency rules suitable for use by a make utility +if ($opt_mmd) { + my $opt_output_filename_d; # .d file + my $dep_file; # MMD target + if ($opt_output_filename) { + # Create a single .d + my($filename, $dirs, $suffix) = File::Basename::fileparse($opt_output_filename, qr/\.[^.]*/); + $opt_output_filename_d = File::Spec->canonpath("$dirs$filename.d"); + open(TARGET_D, '>', $opt_output_filename_d) or die "%Error: $! $opt_output_filename\n"; + } else { + # Create a .d for each input file + } + my %includes = %{$Opt->{includes}}; + foreach my $target (sort (keys %includes)) { + # Setup dep file + if($opt_output_filename){ + $dep_file = $opt_output_filename; + } else { + $dep_file = "$target.d"; + open(TARGET_D, '>', $dep_file) or die $!; + } + # Create mmd dep + printf TARGET_D "$dep_file: $target"; + my @deps = (sort (keys %{$includes{$target}})); + foreach my $dep (@deps) { + $dep = File::Spec->canonpath($Opt->file_path($dep)); + printf TARGET_D " $dep"; + } + printf TARGET_D "\n"; + # Create phony dependency targets (MP) + if ($opt_mp) { + foreach my $dep (@deps) { + $dep = File::Spec->canonpath($Opt->file_path($dep)); + printf TARGET_D "\n$dep:\n"; + } + } + if (!$opt_output_filename){ + close(TARGET_D); + } + } + if ($opt_output_filename) { + close(TARGET_D); + } +} + exit(0); ###################################################################### @@ -201,6 +253,14 @@ Use the given filename for output instead of stdout. Suppress normal output, and instead print a list of all defines existing at the end of processing the input file. +=item --MMD + +Create .d dependency files. + +=item --MP + +Create phony dependency targets. + =item --noblank Removes empty lines from the output. Should be used with --noline, as if From b0d642378d4cfbd954a92151307356684216c6b8 Mon Sep 17 00:00:00 2001 From: piecea <104574800+piecea@users.noreply.github.com> Date: Tue, 17 May 2022 09:50:58 +0200 Subject: [PATCH 2/8] Add doc Co-authored-by: Wilson Snyder --- vppreproc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vppreproc b/vppreproc index 9a6a0ad..11268d8 100755 --- a/vppreproc +++ b/vppreproc @@ -255,7 +255,7 @@ the end of processing the input file. =item --MMD -Create .d dependency files. +Create .d dependency files, similar to "gcc -MMD" behavior. =item --MP From a7ae0f8d11c4e1d00028bde776e43cf7ecdb1f9d Mon Sep 17 00:00:00 2001 From: piecea <104574800+piecea@users.noreply.github.com> Date: Tue, 17 May 2022 09:51:08 +0200 Subject: [PATCH 3/8] Add doc Co-authored-by: Wilson Snyder --- vppreproc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vppreproc b/vppreproc index 11268d8..8c35fa6 100755 --- a/vppreproc +++ b/vppreproc @@ -259,7 +259,7 @@ Create .d dependency files, similar to "gcc -MMD" behavior. =item --MP -Create phony dependency targets. +Create phony dependency targets, similar to "gcc -MP" behavior. =item --noblank From 3141ee4270b82357f78c16c2629eabff0b4e7539 Mon Sep 17 00:00:00 2001 From: piecea <104574800+piecea@users.noreply.github.com> Date: Tue, 17 May 2022 10:00:15 +0200 Subject: [PATCH 4/8] Update t/80_vppreproc.t typo Co-authored-by: Wilson Snyder --- t/80_vppreproc.t | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/80_vppreproc.t b/t/80_vppreproc.t index ca74bf4..58dbbc6 100755 --- a/t/80_vppreproc.t +++ b/t/80_vppreproc.t @@ -32,9 +32,9 @@ sub vppreproc { ok(-r $out, "vppreproc output from: $cmd"); ok(files_identical ($out, $checkname), "diff"); } else { - fail ("run command"); - fail ("no output file created"); - fail ("no output file to compare"); + fail("run command"); + fail("no output file created"); + fail("no output file to compare"); } } From ef09a051689eb284a60f2038a709488361103b7e Mon Sep 17 00:00:00 2001 From: piecea <104574800+piecea@users.noreply.github.com> Date: Tue, 17 May 2022 10:00:25 +0200 Subject: [PATCH 5/8] Update t/80_vppreproc.t typo Co-authored-by: Wilson Snyder --- t/80_vppreproc.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/80_vppreproc.t b/t/80_vppreproc.t index 58dbbc6..da3b043 100755 --- a/t/80_vppreproc.t +++ b/t/80_vppreproc.t @@ -41,8 +41,8 @@ sub vppreproc { # Test -MMD -MP -vppreproc_d ("t/80_vppreproc_v_hier_top_mmd_mp.d", "-MMD -MP"); -vppreproc_d ("t/80_vppreproc_v_hier_top_mmd.d", "-MMD"); +vppreproc_d("t/80_vppreproc_v_hier_top_mmd_mp.d", "-MMD -MP"); +vppreproc_d("t/80_vppreproc_v_hier_top_mmd.d", "-MMD"); vppreproc_d_o(); sub vppreproc_d { From c746d299241415fb841ab7203f72947d7000c90a Mon Sep 17 00:00:00 2001 From: piecea <104574800+piecea@users.noreply.github.com> Date: Tue, 17 May 2022 10:00:34 +0200 Subject: [PATCH 6/8] Update t/80_vppreproc.t typo Co-authored-by: Wilson Snyder --- t/80_vppreproc.t | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/t/80_vppreproc.t b/t/80_vppreproc.t index da3b043..59efc30 100755 --- a/t/80_vppreproc.t +++ b/t/80_vppreproc.t @@ -51,16 +51,16 @@ sub vppreproc_d { my $defaultcfg = "verilog/v_hier_top.v verilog/v_sv_intf.v +incdir+verilog"; my $cmd = "${PERL} ./vppreproc $flags $defaultcfg"; my $dotd = "verilog/v_hier_top.v.d"; - if (0 == run_system_no_die ($cmd)) { + if (0 == run_system_no_die($cmd)) { pass("run command"); ok(-r $dotd, "vppreproc .d from: $cmd"); ok(files_identical ($dotd, $checkname), "diff"); } else { - fail ("run command"); - fail ("no output file created"); - fail ("no output file to compare"); + fail("run command"); + fail("no output file created"); + fail("no output file to compare"); } - system ("/bin/rm -f verilog/v_hier_top.v.d verilog/v_sv_intf.v.d"); + system("/bin/rm -f verilog/v_hier_top.v.d verilog/v_sv_intf.v.d"); } sub vppreproc_d_o { From fab491ae01f3c7edf35bcaca9273b48e0b05c069 Mon Sep 17 00:00:00 2001 From: piecea <104574800+piecea@users.noreply.github.com> Date: Tue, 17 May 2022 10:00:48 +0200 Subject: [PATCH 7/8] Update t/80_vppreproc.t typo Co-authored-by: Wilson Snyder --- t/80_vppreproc.t | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/t/80_vppreproc.t b/t/80_vppreproc.t index 59efc30..eecbcac 100755 --- a/t/80_vppreproc.t +++ b/t/80_vppreproc.t @@ -70,15 +70,15 @@ sub vppreproc_d_o { my $cmd = "${PERL} ./vppreproc -MMD -o test_dir/$obasename.vpp $defaultcfg"; my $dotd = "test_dir/$obasename.d"; - system ("/bin/rm -f $dotd"); - if (0 == run_system_no_die ($cmd)) { + system("/bin/rm -f $dotd"); + if (0 == run_system_no_die($cmd)) { pass("run command"); ok(-r $dotd, "vppreproc .d from: $cmd"); - ok(files_identical ($dotd, $checkname), "diff"); + ok(files_identical($dotd, $checkname), "diff"); } else { - fail ("run command"); - fail ("no output file created"); - fail ("no output file to compare"); + fail("run command"); + fail("no output file created"); + fail("no output file to compare"); } } From b9c8a445cfe6000b04d470a822214229e1cccf14 Mon Sep 17 00:00:00 2001 From: piecea Date: Tue, 17 May 2022 10:33:05 +0200 Subject: [PATCH 8/8] Use IO::File style handles and add a header to generated .d files. --- t/80_vppreproc_v_hier_top_mmd.d | 2 ++ t/80_vppreproc_v_hier_top_mmd_mp.d | 2 ++ t/80_vppreproc_v_res.d | 2 ++ vppreproc | 31 +++++++++++++++--------------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/t/80_vppreproc_v_hier_top_mmd.d b/t/80_vppreproc_v_hier_top_mmd.d index 05569d3..893b8d9 100644 --- a/t/80_vppreproc_v_hier_top_mmd.d +++ b/t/80_vppreproc_v_hier_top_mmd.d @@ -1 +1,3 @@ +# Generated by vppreproc + verilog/v_hier_top.v.d: verilog/v_hier_top.v verilog/v_hier_inc.vh diff --git a/t/80_vppreproc_v_hier_top_mmd_mp.d b/t/80_vppreproc_v_hier_top_mmd_mp.d index 75391d5..5755164 100644 --- a/t/80_vppreproc_v_hier_top_mmd_mp.d +++ b/t/80_vppreproc_v_hier_top_mmd_mp.d @@ -1,3 +1,5 @@ +# Generated by vppreproc + verilog/v_hier_top.v.d: verilog/v_hier_top.v verilog/v_hier_inc.vh verilog/v_hier_inc.vh: diff --git a/t/80_vppreproc_v_res.d b/t/80_vppreproc_v_res.d index e6582af..60e60e2 100644 --- a/t/80_vppreproc_v_res.d +++ b/t/80_vppreproc_v_res.d @@ -1,2 +1,4 @@ +# Generated by vppreproc + test_dir/res.vpp: verilog/v_hier_top.v verilog/v_hier_inc.vh test_dir/res.vpp: verilog/v_sv_intf.v verilog/v_sv_pkg.v diff --git a/vppreproc b/vppreproc index 8c35fa6..aeb8886 100755 --- a/vppreproc +++ b/vppreproc @@ -97,51 +97,52 @@ if ($opt_dump_defines) { printf "`define %s%s %s\n", $name,$par,$value; } } - - + # MMD MP option # produces a list of makefile dependency rules suitable for use by a make utility if ($opt_mmd) { - my $opt_output_filename_d; # .d file - my $dep_file; # MMD target + my $fh = IO::File->new; if ($opt_output_filename) { # Create a single .d - my($filename, $dirs, $suffix) = File::Basename::fileparse($opt_output_filename, qr/\.[^.]*/); - $opt_output_filename_d = File::Spec->canonpath("$dirs$filename.d"); - open(TARGET_D, '>', $opt_output_filename_d) or die "%Error: $! $opt_output_filename\n"; + my ($filename, $dirs, $suffix) = File::Basename::fileparse($opt_output_filename, qr/\.[^.]*/); + my $opt_output_filename_d = File::Spec->canonpath("$dirs$filename.d"); # .d file + $fh->open(">$opt_output_filename_d") or die "%Error: $! $opt_output_filename_d\n"; + printf $fh "# Generated by vppreproc\n\n" } else { # Create a .d for each input file } my %includes = %{$Opt->{includes}}; foreach my $target (sort (keys %includes)) { + my $dep_file; # MMD target # Setup dep file - if($opt_output_filename){ + if ($opt_output_filename) { $dep_file = $opt_output_filename; } else { $dep_file = "$target.d"; - open(TARGET_D, '>', $dep_file) or die $!; + $fh->open(">$dep_file") or die "%Error: $! $dep_file\n"; + printf $fh "# Generated by vppreproc\n\n" } # Create mmd dep - printf TARGET_D "$dep_file: $target"; + printf $fh "$dep_file: $target"; my @deps = (sort (keys %{$includes{$target}})); foreach my $dep (@deps) { $dep = File::Spec->canonpath($Opt->file_path($dep)); - printf TARGET_D " $dep"; + printf $fh " $dep"; } - printf TARGET_D "\n"; + printf $fh "\n"; # Create phony dependency targets (MP) if ($opt_mp) { foreach my $dep (@deps) { $dep = File::Spec->canonpath($Opt->file_path($dep)); - printf TARGET_D "\n$dep:\n"; + printf $fh "\n$dep:\n"; } } if (!$opt_output_filename){ - close(TARGET_D); + $fh->close; } } if ($opt_output_filename) { - close(TARGET_D); + $fh->close; } }