From 22088c907f12a4cb78fc74a47e8c159706c36764 Mon Sep 17 00:00:00 2001 From: Stefan Wallentowitz Date: Tue, 21 Jan 2020 12:17:31 +0100 Subject: [PATCH] Set maximum number width (#2128) Adjust the maximum number width to 64K. Add --max-num-width option to adjust this setting. Closes #2082 --- Changes | 2 ++ bin/verilator | 6 ++++++ src/V3Number.cpp | 8 ++++---- src/V3Options.cpp | 5 +++++ src/V3Options.h | 2 ++ test_regress/t/t_fuzz_negwidth_bad.out | 4 ++++ test_regress/t/t_fuzz_negwidth_bad.pl | 1 + test_regress/t/t_fuzz_negwidth_bad.v | 3 ++- test_regress/t/t_lint_numwidth.pl | 17 +++++++++++++++++ test_regress/t/t_lint_numwidth.v | 8 ++++++++ 10 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 test_regress/t/t_fuzz_negwidth_bad.out create mode 100755 test_regress/t/t_lint_numwidth.pl create mode 100644 test_regress/t/t_lint_numwidth.v diff --git a/Changes b/Changes index aff2e9be8..bb956d7ea 100644 --- a/Changes +++ b/Changes @@ -19,6 +19,8 @@ The contributors that suggested a given feature are shown in []. Thanks! **** Add error on misused define. [Topa Tota] +**** Add parameter to set maximum signal width. #2082. [Øyvind Harboe] + * Verilator 4.026 2020-01-11 diff --git a/bin/verilator b/bin/verilator index 272860bf6..7dfed68b9 100755 --- a/bin/verilator +++ b/bin/verilator @@ -323,6 +323,7 @@ detailed descriptions in L for more information. --language Default language standard to parse +libext++[ext]... Extensions for finding modules --lint-only Lint, but do not make output + --max-num-width Maximum number width (default: 64K) --MMD Create .d dependency files --MP Create phony dependency targets --Mdir Name of output object directory @@ -968,6 +969,11 @@ stylistic and not enabled by default. If the design is not to be completely Verilated see also the --bbox-sys and --bbox-unsup options. +=item --max-num-width I + +Set the maximum number literal width (e.g. in 1024'd22 this it the 1024). +Defaults to 64K. + =item --MMD =item --no-MMD diff --git a/src/V3Number.cpp b/src/V3Number.cpp index f90b80e91..5bf498ae0 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -32,7 +32,6 @@ #include #define MAX_SPRINTF_DOUBLE_SIZE 100 // Maximum characters with a sprintf %e/%f/%g (probably < 30) -#define MAX_WIDTH 5*1024 // Maximum width before error // Number operations build output in-place so can't call e.g. foo.opX(foo) #define NUM_ASSERT_OP_ARGS1(arg1) \ @@ -125,10 +124,11 @@ void V3Number::V3NumberCreate(AstNode* nodep, const char* sourcep, FileLine* fl) value_startp = cp; if (atoi(widthn.c_str())) { - if (atoi(widthn.c_str()) < 0 || atoi(widthn.c_str()) > MAX_WIDTH) { + if (atoi(widthn.c_str()) < 0 || atoi(widthn.c_str()) > v3Global.opt.maxNumWidth()) { // atoi might convert large number to negative, so can't tell which - v3error("Unsupported: Width of number exceeds implementation limit: "<v3fatal("Unknown --make system specified: '"< 1); lint( fails => 1, + expect_filename => $Self->{golden_filename}, ); ok(1); diff --git a/test_regress/t/t_fuzz_negwidth_bad.v b/test_regress/t/t_fuzz_negwidth_bad.v index 730712a5c..245e36a71 100644 --- a/test_regress/t/t_fuzz_negwidth_bad.v +++ b/test_regress/t/t_fuzz_negwidth_bad.v @@ -4,4 +4,5 @@ // without warranty, 2019 by Wilson Snyder. int a = -12'd1; -int b = 1231232312312312'd1; +int b = 65536'd1; +int c = 1231232312312312'd1; diff --git a/test_regress/t/t_lint_numwidth.pl b/test_regress/t/t_lint_numwidth.pl new file mode 100755 index 000000000..adf0894d6 --- /dev/null +++ b/test_regress/t/t_lint_numwidth.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2008 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. + +scenarios(linter => 1); + +lint( + verilator_flags2 => ["--max-num-width 131072"], + ); + +ok(1); +1; diff --git a/test_regress/t/t_lint_numwidth.v b/test_regress/t/t_lint_numwidth.v new file mode 100644 index 000000000..ff0d77aa3 --- /dev/null +++ b/test_regress/t/t_lint_numwidth.v @@ -0,0 +1,8 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2010 by Wilson Snyder. + +logic [65535:0] a = 65536'd1; +logic [65536:0] b = 65537'd1; +logic [131071:0] c = 131072'd1;