From 31223d4058eecaa61b66dbb332b52eb9a489d689 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 26 Jan 2021 20:10:27 -0500 Subject: [PATCH] Fix $ in filenames (#2768). --- src/V3Options.cpp | 9 +++++---- test_regress/t/t_mod_dollar$.pl | 25 +++++++++++++++++++++++++ test_regress/t/t_mod_dollar$.v | 12 ++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100755 test_regress/t/t_mod_dollar$.pl create mode 100644 test_regress/t/t_mod_dollar$.v diff --git a/src/V3Options.cpp b/src/V3Options.cpp index fdc56aa08..5eebd637e 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -18,6 +18,7 @@ #include "verilatedos.h" #include "V3Global.h" +#include "V3Ast.h" #include "V3String.h" #include "V3Os.h" #include "V3Options.h" @@ -864,10 +865,10 @@ void V3Options::parseOpts(FileLine* fl, int argc, char** argv) { } // Default prefix to the filename - if (prefix() == "" && topModule() != "") m_prefix = string("V") + topModule(); - if (prefix() == "" && vFilesList.size() >= 1) { - m_prefix = string("V") + V3Os::filenameNonExt(*(vFilesList.begin())); - } + if (prefix() == "" && topModule() != "") + m_prefix = string("V") + AstNode::encodeName(topModule()); + if (prefix() == "" && vFilesList.size() >= 1) + m_prefix = string("V") + AstNode::encodeName(V3Os::filenameNonExt(*(vFilesList.begin()))); if (modPrefix() == "") m_modPrefix = prefix(); // Find files in makedir diff --git a/test_regress/t/t_mod_dollar$.pl b/test_regress/t/t_mod_dollar$.pl new file mode 100755 index 000000000..2d8172ca7 --- /dev/null +++ b/test_regress/t/t_mod_dollar$.pl @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2019 by Wilson Snyder. 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. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(vlt => 1); + +# This doesn't use the general compile rule as we want to make sure we form +# prefix properly using post-escaped identifiers +run(cmd => ["../bin/verilator", + "--cc", + "--Mdir obj_vlt/t_mod_dollar", + "--exe --build --main", + 't/t_mod_dollar$.v', + ], + verilator_run => 1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_mod_dollar$.v b/test_regress/t/t_mod_dollar$.v new file mode 100644 index 000000000..ee7d6ad75 --- /dev/null +++ b/test_regress/t/t_mod_dollar$.v @@ -0,0 +1,12 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2020 by engr248. +// SPDX-License-Identifier: CC0-1.0 + +module \foo$bar (/*AUTOARG*/); + initial begin + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule