From ec620387afc9779929628bc497fed27017b34cd7 Mon Sep 17 00:00:00 2001 From: Todd Strader Date: Tue, 27 Aug 2019 21:36:59 -0400 Subject: [PATCH] Add --dpi-hdr-only, bug1491. --- Changes | 2 ++ bin/verilator | 6 ++++ src/V3EmitC.h | 2 +- src/V3EmitCSyms.cpp | 17 ++++++---- src/V3Options.cpp | 2 ++ src/V3Options.h | 2 ++ src/Verilator.cpp | 17 +++++++--- test_regress/driver.pl | 5 +++ test_regress/t/t_dpi_import_hdr_only.pl | 45 +++++++++++++++++++++++++ 9 files changed, 86 insertions(+), 12 deletions(-) create mode 100755 test_regress/t/t_dpi_import_hdr_only.pl diff --git a/Changes b/Changes index 4da553b37..ba0a9420f 100644 --- a/Changes +++ b/Changes @@ -26,6 +26,8 @@ The contributors that suggested a given feature are shown in []. Thanks! **** Fix internal error on gate optimization of assign, bug1475. [Oyvind Harboe] +**** Add --dpi-hdr-only, bug1491. [Todd Strader] + * Verilator 4.016 2019-06-16 diff --git a/bin/verilator b/bin/verilator index d935ce1e3..f014f2d37 100755 --- a/bin/verilator +++ b/bin/verilator @@ -298,6 +298,7 @@ detailed descriptions in L for more information. --debugi- Enable debugging a source file at a level --default-language Default language to parse +define+= Set preprocessor define + --dpi-hdr-only Only produce the DPI header file --dump-defines Show preprocessor defines with -E --dump-tree Enable dumping .tree files --dump-treei Enable dumping .tree files at a level @@ -741,6 +742,11 @@ Defines the given preprocessor symbol, or multiple symbols if separated by plusses. Similar to -D; +define is fairly standard across Verilog tools while -D is an alias for GCC compatibility. +=item --dpi-hdr-only + +Only generate the DPI header file. This option has no effect on the name +or location of the file. + =item --dump-defines With -E, suppress normal output, and instead print a list of all defines diff --git a/src/V3EmitC.h b/src/V3EmitC.h index c7b878814..a509526e5 100644 --- a/src/V3EmitC.h +++ b/src/V3EmitC.h @@ -33,7 +33,7 @@ class V3EmitC { public: static void emitc(); static void emitcInlines(); - static void emitcSyms(); + static void emitcSyms(bool dpiHdrOnly = false); static void emitcTrace(); }; diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 06f0cd226..55975a69c 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -90,6 +90,7 @@ class EmitCSyms : EmitCBaseVisitor { V3LanguageWords m_words; // Reserved word detector int m_coverBins; // Coverage bin number int m_labelNum; // Next label number + bool m_dpiHdrOnly; // Only emit the DPI header // METHODS void emitSymHdr(); @@ -181,11 +182,13 @@ class EmitCSyms : EmitCBaseVisitor { stable_sort(m_dpis.begin(), m_dpis.end(), CmpDpi()); // Output - emitSymHdr(); - emitSymImp(); + if (!m_dpiHdrOnly) { + emitSymHdr(); + emitSymImp(); + } if (v3Global.dpi()) { emitDpiHdr(); - emitDpiImp(); + if (!m_dpiHdrOnly) emitDpiImp(); } } virtual void visit(AstNodeModule* nodep) { @@ -253,7 +256,9 @@ class EmitCSyms : EmitCBaseVisitor { //--------------------------------------- // ACCESSORS public: - explicit EmitCSyms(AstNetlist* nodep) { + explicit EmitCSyms(AstNetlist* nodep, bool dpiHdrOnly): + m_dpiHdrOnly(dpiHdrOnly) + { m_funcp = NULL; m_modp = NULL; m_coverBins = 0; @@ -661,7 +666,7 @@ void EmitCSyms::emitDpiImp() { //###################################################################### // EmitC class functions -void V3EmitC::emitcSyms() { +void V3EmitC::emitcSyms(bool dpiHdrOnly) { UINFO(2,__FUNCTION__<<": "<{obj_dir}/simx.vcd"; } +sub obj_dir { + my $self = shift; + return $self->{obj_dir}; +} + sub get_default_vltmt_threads { return $Vltmt_threads; } diff --git a/test_regress/t/t_dpi_import_hdr_only.pl b/test_regress/t/t_dpi_import_hdr_only.pl new file mode 100755 index 000000000..d89c46dd8 --- /dev/null +++ b/test_regress/t/t_dpi_import_hdr_only.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2019 by Todd Strader. This program is free software; you can +# redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. + +use File::Temp; +use File::Compare; + +scenarios(simulator => 1); + +top_filename("t/t_dpi_import.v"); + +my $tmp_dir = File::Temp->newdir(); + +compile( + verilator_flags2 => ["-Wall -Wno-DECLFILENAME -Mdir " . $tmp_dir . " --dpi-hdr-only"], + verilator_make_gcc => 0, + ); + +my @files = glob($tmp_dir . "/*"); + +die "Did not produce DPI header" if scalar(@files) == 0; +die "Too many files created" if scalar(@files) > 1; +my $tmp_header = $files[0]; +print("============".$tmp_header."\n"); +die "Unexpected file $tmp_header" unless $tmp_header =~ /__Dpi\.h$/; + +compile( + verilator_flags2 => ["-Wall -Wno-DECLFILENAME"], + verilator_make_gcc => 0, + ); + +@files = glob($Self->obj_dir . "/*__Dpi.h"); +my $header = @files[0]; + +if (compare($tmp_header, $header) != 0) { + die "DPI header files are not the same"; +} + +ok(1); +1;