diff --git a/docs/guide/files.rst b/docs/guide/files.rst index 3928bd804..e697a9c2f 100644 --- a/docs/guide/files.rst +++ b/docs/guide/files.rst @@ -145,6 +145,10 @@ After running Make, the C++ compiler may produce the following: - Intermediate objects * - *{prefix}*\ - Final executable (from --exe) + * - lib\ *{prefix}*\ .a + - Final archive (default lib mode) + * - libverilated.a + - Runtime for verilated model (default lib mode) * - *{prefix}*\ __ALL.a - Library of all Verilated objects * - *{prefix}*\ __ALL.cpp diff --git a/src/V3EmitMk.cpp b/src/V3EmitMk.cpp index 8bea8b362..3f7c29e8d 100644 --- a/src/V3EmitMk.cpp +++ b/src/V3EmitMk.cpp @@ -146,7 +146,7 @@ public: } else if (!v3Global.opt.libCreate().empty()) { of.puts("default: lib" + v3Global.opt.libCreate() + "\n"); } else { - of.puts("default: " + v3Global.opt.prefix() + "__ALL.a\n"); + of.puts("default: lib" + v3Global.opt.prefix() + "\n"); } of.puts("\n### Constants...\n"); of.puts("# Perl executable (from $PERL)\n"); @@ -239,13 +239,12 @@ public: if (v3Global.opt.exe()) { of.puts("\n### Link rules... (from --exe)\n"); + // let default rule depend on '{prefix}__ALL.a', for compatibility of.puts(v3Global.opt.exeName() + ": $(VK_USER_OBJS) $(VK_GLOBAL_OBJS) $(VM_PREFIX)__ALL.a $(VM_HIER_LIBS)\n"); of.puts("\t$(LINK) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) $(LIBS) $(SC_LIBS) -o $@\n"); of.puts("\n"); - } - - if (!v3Global.opt.libCreate().empty()) { + } else if (!v3Global.opt.libCreate().empty()) { const string libCreateDeps = "$(VK_OBJS) $(VK_USER_OBJS) $(VK_GLOBAL_OBJS) " + v3Global.opt.libCreate() + ".o $(VM_HIER_LIBS)"; of.puts("\n### Library rules from --lib-create\n"); @@ -272,6 +271,15 @@ public: of.puts("lib" + v3Global.opt.libCreate() + ": " + v3Global.opt.libCreateName(false) + " " + v3Global.opt.libCreateName(true) + "\n"); } + } else { + const string libname = "lib" + v3Global.opt.prefix() + ".a"; + of.puts("\n### Library rules (default lib mode)\n"); + // The rule to create .a is defined in verilated.mk, so just define dependency here. + of.puts(libname + ": $(VK_OBJS) $(VK_USER_OBJS) $(VM_HIER_LIBS)\n"); + of.puts("libverilated.a: $(VK_GLOBAL_OBJS)\n"); + // let default rule depend on '{prefix}__ALL.a', for compatibility + of.puts("lib" + v3Global.opt.prefix() + ": " + libname + + " libverilated.a $(VM_PREFIX)__ALL.a\n"); } of.puts("\n"); diff --git a/test_regress/t/t_flag_lib_dpi.cpp b/test_regress/t/t_flag_lib_dpi.cpp new file mode 100644 index 000000000..60a3f7eb6 --- /dev/null +++ b/test_regress/t/t_flag_lib_dpi.cpp @@ -0,0 +1,14 @@ +// -*- mode: C++; c-file-style: "cc-mode" -*- +//************************************************************************* +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2023 by Shupei Fan. +// SPDX-License-Identifier: CC0-1.0 +// +//************************************************************************* + +#include "Vt_flag_lib_dpi__Dpi.h" +#include "svdpi.h" + +#include +void write_all_finished() { std::cout << "*-* All Finished *-*" << std::endl; } diff --git a/test_regress/t/t_flag_lib_dpi.mk b/test_regress/t/t_flag_lib_dpi.mk new file mode 100644 index 000000000..d51f28ed7 --- /dev/null +++ b/test_regress/t/t_flag_lib_dpi.mk @@ -0,0 +1,10 @@ +# DESCRIPTION: Verilator: Makefile for Verilog Test module +# +# This file ONLY is placed under the Creative Commons Public Domain, for +# any use, without warranty, 2023 by Shupei Fan. +# SPDX-License-Identifier: CC0-1.0 + +include Vt_flag_lib_dpi.mk + +t_flag_lib_dpi_test: libVt_flag_lib_dpi.a libverilated.a + $(LINK) $(LDFLAGS) $^ $(LDLIBS) -o $@ diff --git a/test_regress/t/t_flag_lib_dpi.pl b/test_regress/t/t_flag_lib_dpi.pl new file mode 100755 index 000000000..9cb3e8bfb --- /dev/null +++ b/test_regress/t/t_flag_lib_dpi.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# This file ONLY is placed under the Creative Commons Public Domain, for +# any use, without warranty, 2023 by Shupei Fan. +# SPDX-License-Identifier: CC0-1.0 + +scenarios(vlt => 1); + +run(logfile => "$Self->{obj_dir}/vlt_compile.log", + cmd => ["perl", + "$ENV{VERILATOR_ROOT}/bin/verilator", + "-cc", + "--build", + '--no-timing', + "-Mdir", + "$Self->{obj_dir}", + "t/t_flag_lib_dpi.v", + "$Self->{t_dir}/t_flag_lib_dpi.cpp", + "$Self->{t_dir}/t_flag_lib_dpi_main.cpp"], + verilator_run => 1, + ); + +run(logfile => "$Self->{obj_dir}/cxx_compile.log", + cmd => ["cd $Self->{obj_dir}" + . " && cp $Self->{t_dir}/t_flag_lib_dpi.mk t_flag_lib_dpi.mk" + . " && $ENV{MAKE} -f t_flag_lib_dpi.mk t_flag_lib_dpi_test" + . " && ./t_flag_lib_dpi_test"], + check_finished => 1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_flag_lib_dpi.v b/test_regress/t/t_flag_lib_dpi.v new file mode 100644 index 000000000..2b16948bc --- /dev/null +++ b/test_regress/t/t_flag_lib_dpi.v @@ -0,0 +1,16 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2023 by Shupei Fan. +// SPDX-License-Identifier: CC0-1.0 + +import "DPI-C" function void write_all_finished(); + +module t (/*AUTOARG*/); + + initial begin + write_all_finished; + $finish; + end + +endmodule diff --git a/test_regress/t/t_flag_lib_dpi_main.cpp b/test_regress/t/t_flag_lib_dpi_main.cpp new file mode 100644 index 000000000..3fcfd8179 --- /dev/null +++ b/test_regress/t/t_flag_lib_dpi_main.cpp @@ -0,0 +1,42 @@ +// -*- mode: C++; c-file-style: "cc-mode" -*- +//************************************************************************* +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2023 by Shupei Fan. +// SPDX-License-Identifier: CC0-1.0 +// +//************************************************************************* +// +// DESCRIPTION: main() calling loop, created with Verilator --main + +#include "verilated.h" + +#include "Vt_flag_lib_dpi.h" + +//====================== + +int main(int argc, char** argv, char**) { + // Setup context, defaults, and parse command line + Verilated::debug(0); + const std::unique_ptr contextp{new VerilatedContext}; + contextp->commandArgs(argc, argv); + + // Construct the Verilated model, from Vtop.h generated from Verilating + const std::unique_ptr topp{new Vt_flag_lib_dpi{contextp.get()}}; + + // Simulate until $finish + while (!contextp->gotFinish()) { + // Evaluate model + topp->eval(); + // Advance time + contextp->timeInc(1); + } + + if (!contextp->gotFinish()) { + VL_DEBUG_IF(VL_PRINTF("+ Exiting without $finish; no events left\n");); + } + + // Final model cleanup + topp->final(); + return 0; +}