Compare commits

...
54 Commits
Author SHA1 Message Date
Wilson Snyder 132f61e900 Fix version 2017-10-14 16:20:17 -04:00
Wilson Snyder 0e9be8eea0 Version bump 2017-10-14 16:15:07 -04:00
Wilson Snyder 96f5f66c26 Move generated objects into bin/ to match --prefix installations 2017-10-14 16:09:02 -04:00
Wilson Snyder bbed4d50ab Fix clang and cppcheck warnings. 2017-10-14 14:51:57 -04:00
Wilson Snyder 4b7ee8267b Slicing: Fix off-by-one error earlier this version. 2017-10-14 14:04:15 -04:00
Wilson Snyder f6a745a4c2 Fix clang warnings. 2017-10-14 14:03:12 -04:00
Wilson Snyder a23a5505c4 configure: Check compiler works. 2017-10-14 13:20:58 -04:00
Wilson Snyder 21030f0a4f Internals: C++ style casts. No functional change intended. 2017-10-14 13:00:42 -04:00
Wilson Snyder d21824cbae Internals: Refactor verilated_vcd to move singleton into only .cpp. No functional change intended. 2017-10-14 13:00:25 -04:00
Wilson Snyder 124786ad1b Tests: Require newest compiler with thread test. 2017-10-14 12:57:42 -04:00
Wilson Snyder f81daac9c0 Fix MacOS portability, bug1231. 2017-10-14 12:56:16 -04:00
Wilson Snyder db8e8392fa Fix MacOS portability, bug1230. 2017-10-14 09:00:39 -04:00
Wilson Snyder 5bc2f87d3e Fix --skip-identical to handle closer timestamps looking at ctime. 2017-10-13 20:34:36 -04:00
Wilson Snyder de35c90847 Fix float-conversion warning, bug1229. 2017-10-11 19:01:37 -04:00
Wilson Snyder bc813fddcc tests: Fix examples when VERILATOR_ROOT not set 2017-10-11 19:01:02 -04:00
Wilson Snyder 13c91f5fce Internals: Refactor VerilatorSerialize to remove intermediate class. No functional change intended. 2017-10-11 18:55:31 -04:00
Wilson Snyder ac4690d74b Internals: Add const's. No functional change 2017-10-10 22:22:17 -04:00
Wilson Snyder a1a8f17617 Internals: Add const's. No functional change 2017-10-10 20:24:10 -04:00
Wilson Snyder 12be852a43 Fix ` expansion of defines, bug1227, bug1228. 2017-10-10 18:44:10 -04:00
Wilson Snyder 440fbef79b Untabify examples. No functional change. 2017-10-10 07:18:01 -04:00
Wilson Snyder e1c221a4d5 Tests: Add t_dist_tabs.pl 2017-10-09 22:08:22 -04:00
Wilson Snyder e1f1c82d4e Fix -E duplicating output, bug1226. 2017-10-09 21:08:50 -04:00
Wilson Snyder 3c1b82255e Change VL_THREADED to use C++11, and compute and test related GCC flags automatically 2017-10-07 21:29:57 -04:00
Wilson Snyder 6bd47b54df Tests: Add t_include_all. Fix GCC warning when DPI with VPI. 2017-10-07 21:21:12 -04:00
Wilson Snyder 3261a45ec1 configure: Add new _MY_CXX_CHECK_SET. No functional change. 2017-10-07 15:25:23 -04:00
Wilson Snyder 0ac116bb4e Internals: Favor C++ cast style. No functional change intended. 2017-10-07 15:01:19 -04:00
Wilson Snyder 221e4ff6fe Fix ` expansion of empty defines, bug1225. 2017-10-07 14:09:33 -04:00
Wilson Snyder fe80499f9c Internals: Move preproc DEV expansion when in ifndef, cleanup prep for bug1225. 2017-10-07 14:09:31 -04:00
Wilson Snyder d3d1f3ab60 Internals: Cleanup preproc in prep for bug1225. No functional change. 2017-10-07 14:09:17 -04:00
Chris Randall 264b888ef2 Add /*verilator tag*/ for XML extraction applications.
Signed-off-by: Wilson Snyder <[email protected]>
2017-10-06 07:33:52 -04:00
John Coiner ba270e09a4 Add --no-relative-cfuncs and related default optimization, bug1224.
Signed-off-by: Wilson Snyder <[email protected]>
2017-10-05 18:18:11 -04:00
Wilson Snyder 8281ee1520 Optimize arrayed if assignments 2017-10-04 22:10:44 -04:00
Wilson Snyder 75aab4e9d2 Fix conditional slices and add related optimizations. 2017-10-04 21:27:34 -04:00
Wilson Snyder b532a47e4a Internals: Prep for V3Slice rewrite. No functional change intended. 2017-10-04 21:15:19 -04:00
Wilson Snyder 77a3d683e3 Fix unnecessary Vdly variables, bug1224 partial. 2017-10-03 21:26:42 -04:00
Wilson Snyder c132d0e1fe Fix extra duplicate multiclk blocks when dtypes differ 2017-10-02 22:58:34 -04:00
Wilson Snyder 1a6348f113 Optimize display+display statements. 2017-10-02 20:25:10 -04:00
Wilson Snyder 89ac6ab594 Fix memory leak in VerilatedVcd dumps, bug1222 partial. 2017-10-02 18:49:00 -04:00
Wilson Snyder 3d1012b73b Allow disabling BLKLOOPINIT (Intentionally undocumented), part of last commit 2017-10-01 23:36:19 -04:00
Wilson Snyder c98ad79e68 Allow disabling BLKLOOPINIT (Intentionally undocumented) 2017-10-01 23:23:02 -04:00
Wilson Snyder 82460b0da3 Commentary 2017-10-01 23:06:16 -04:00
Wilson Snyder 0bdc57a14a Fix lost .tree debug file extensions in recent commit. 2017-10-01 22:17:37 -04:00
Wilson Snyder 33780a09df Add --x-initial option 2017-10-01 21:31:40 -04:00
John Coiner a9c9d5ca4b Fix over-aggressive inlining, bug1223.
Signed-off-by: Wilson Snyder <[email protected]>
2017-10-01 18:02:58 -04:00
Wilson Snyder ab07dbdb9d Fix over-aggressive inlining, bug1223. 2017-10-01 18:00:27 -04:00
Wilson Snyder 6dd6750985 Remove empty _configure_coverage in emitted code. 2017-10-01 16:44:53 -04:00
John Coiner 59aa0f43d5 Tests: In t_dist_whitespace, indicate what line has errant whitespace
Signed-off-by: Wilson Snyder <[email protected]>
2017-10-01 16:09:56 -04:00
Wilson Snyder 04ca6a4307 Fix compiler warning when WIDTH warning ignored on large compare. 2017-10-01 10:21:27 -04:00
John Coiner c7cbe11ba4 Fix Ubuntu 17.10 issues, bug1223 partial.
Signed-off-by: Wilson Snyder <[email protected]>
2017-09-30 13:33:14 -04:00
Wilson Snyder 4794093aba Replaced test_c/test_sc with new examples/ directory. 2017-09-23 21:18:07 -04:00
Wilson Snyder 46e300b2c5 Add --getenv option. 2017-09-23 18:03:39 -04:00
Wilson Snyder c693e52f6c Fix false unused warning on line coverage objects 2017-09-23 18:00:44 -04:00
Wilson Snyder 4e2ec09f9a Tests: The internal test_verilated test directory is moved to be part of test_regress. 2017-09-23 10:49:29 -04:00
Wilson Snyder cdbae456d5 devel release 2017-09-23 10:11:06 -04:00
162 changed files with 3878 additions and 1917 deletions
+38
View File
@@ -2,6 +2,44 @@ Revision history for Verilator
The contributors that suggested a given feature are shown in []. Thanks!
* Verilator 3.914 2017-10-14
** Added new examples/ directory with appropriate examples. This replaces the
old test_c and test_sc directories.
*** Add --getenv option for simplifying Makefiles.
*** Add --x-initial option for specifying initial value assignment behavior.
*** Add --no-relative-cfuncs and related default optimization, bug1224. [John Coiner]
*** Add /*verilator tag*/ for XML extraction applications. [Chris Randall]
**** The internal test_verilated test directory is moved to be part of test_regress.
**** The experimental VL_THREADED setting (only, not normal mode) now requires C++11.
**** Fix over-aggressive inlining, bug1223. [John Coiner]
**** Fix Ubuntu 17.10 issues, bug1223 partial. [John Coiner]
**** Fix compiler warning when WIDTH warning ignored on large compare.
**** Fix memory leak in VerilatedVcd dumps, bug1222 partial. [Shareef Jalloq]
**** Fix unnecessary Vdly variables, bug1224 partial. [John Coiner]
**** Fix conditional slices and add related optimizations.
**** Fix `` expansion of `defines, bug1225, bug1227, bug1228. [Odd Magne Reitan]
**** Fix -E duplicating output, bug1226. [Odd Magne Reitan]
**** Fix float-conversion warning, bug1229. [Robert Henry]
**** Fix MacOS portability, bug1230, bug1231. [Jeff Bush]
* Verilator 3.912 2017-09-23
** Verilated headers no longer "use namespace std;"
+3
View File
@@ -20,6 +20,8 @@
/cov_work/
/logs/
^Makefile$
bin/verilator_bin.*
bin/verilator_coverage_bin.*
src/Makefile$
src/Makefile_obj$
include/verilated.mk$
@@ -39,5 +41,6 @@ nodist/
/vc_hdrs.h$
/csrc/
doxygen-doc/.*
obj_dir/.*
TAGS
.*~
+55 -43
View File
@@ -101,7 +101,9 @@ PACKAGE_VERSION = @PACKAGE_VERSION@
SHELL = /bin/sh
SUBDIRS = src test_verilated test_c test_sc test_regress
SUBDIRS = src test_regress \
examples/hello_world_c examples/hello_world_sc \
examples/tracing_c examples/tracing_sc \
INFOS = README README.html README.pdf internals.txt internals.html \
internals.pdf verilator.txt verilator.html verilator.pdf \
@@ -114,7 +116,11 @@ DISTFILES_INC = $(INFOS) .gitignore Artistic COPYING COPYING.LESSER \
*.in *.ac \
Changes TODO \
MANIFEST.SKIP \
bin/* \
bin/verilator \
bin/verilator_coverage \
bin/verilator_difftree \
bin/verilator_includer \
bin/verilator_profcfunc \
doxygen-mainpage doxygen.config veripool-logo.png \
install-sh configure mkinstalldirs *.pod \
include/*.[chv]* \
@@ -127,9 +133,10 @@ DISTFILES_INC = $(INFOS) .gitignore Artistic COPYING COPYING.LESSER \
src/vlcovgen \
src/.gdbinit \
src/*.pl src/*.pod \
examples/*/.*ignore examples/*/Makefile* \
examples/*/*.[chv]* examples/*/*.pl \
test_*/.*ignore test_*/Makefile* test_*/*.cpp \
test_*/*.pl test_*/*.v test_*/*.vc test_*/*.vh \
test_verilated/vgen*.pl \
test_regress/t/t*/*.sv* \
test_regress/t/t*/*.v* \
test_regress/t/t*/*/*.sv* \
@@ -153,9 +160,9 @@ INST_PROJ_FILES = \
include/vltstd/*.[chv]* \
INST_PROJ_BIN_FILES = \
verilator_bin \
verilator_bin_dbg \
verilator_coverage_bin_dbg \
bin/verilator_bin \
bin/verilator_bin_dbg \
bin/verilator_coverage_bin_dbg \
DISTFILES := $(DISTFILES_INC)
@@ -182,33 +189,33 @@ verilator_exe verilator_bin verilator_bin_dbg verilator_coverage_bin_dbg:
msg_test: all_nomsg
@echo "Build complete!"
@echo
@echo "Type 'make test' to test."
@echo "Now type 'make test' to test."
@echo
.PHONY:test
.PHONY: test
ifeq ($(CFG_WITH_LONGTESTS),yes) # Local... Else don't burden users
test: test_c test_sc test_verilated test_regress
test: smoke-test examples test_regress
else
test: test_c test_sc
test: smoke-test examples
endif
@echo "Tests passed!"
@echo
@echo "Type 'make install' to install documentation."
@echo "Now type 'make install' to install."
@echo "Or type 'make' inside an examples subdirectory."
@echo
test_c: all_nomsg
@(cd test_c && $(MAKE))
test_c_debug: all_nomsg
@(cd test_c && $(MAKE) test_debug)
test_sc: all_nomsg
@(cd test_sc && $(MAKE))
test_sc_debug: all_nomsg
@(cd test_sc && $(MAKE) test_debug)
test_verilated: all_nomsg
@(cd test_verilated && $(MAKE))
smoke-test: all_nomsg
test_regress/t/t_a_first_cc.pl
test_regress/t/t_a_first_sc.pl
test_regress: all_nomsg
@(cd test_regress && $(MAKE))
examples: all_nomsg
for p in examples/* ; do \
$(MAKE) -C $$p VERILATOR_ROOT=`pwd` ; \
done
info: $(INFOS)
# Use --no-split to avoid creating filenames > 14 chars.
@@ -281,18 +288,16 @@ VL_INST_INC_SRCDIR_FILES = \
include/vltstd/*.[chv]* \
VL_INST_DATA_SRCDIR_FILES = \
test_v/*.[chv]* \
test_c/*.[chv]* test_c/Makefile test_c/Makefile_obj \
test_sc/*.[chv]* test_sc/Makefile test_sc/Makefile_obj \
examples/*/*.[chv]* examples/*/Makefile* \
installbin:
$(SHELL) ${srcdir}/mkinstalldirs $(DESTDIR)$(bindir)
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator $(DESTDIR)$(bindir)/verilator )
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_coverage $(DESTDIR)$(bindir)/verilator_coverage )
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_profcfunc $(DESTDIR)$(bindir)/verilator_profcfunc )
( $(INSTALL_PROGRAM) verilator_bin $(DESTDIR)$(bindir)/verilator_bin )
( $(INSTALL_PROGRAM) verilator_bin_dbg $(DESTDIR)$(bindir)/verilator_bin_dbg )
( $(INSTALL_PROGRAM) verilator_coverage_bin_dbg $(DESTDIR)$(bindir)/verilator_coverage_bin_dbg )
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_bin $(DESTDIR)$(bindir)/verilator_bin )
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_bin_dbg $(DESTDIR)$(bindir)/verilator_bin_dbg )
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_coverage_bin_dbg $(DESTDIR)$(bindir)/verilator_coverage_bin_dbg )
$(SHELL) ${srcdir}/mkinstalldirs $(DESTDIR)$(pkgdatadir)/bin
( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_includer $(DESTDIR)$(pkgdatadir)/bin/verilator_includer )
@@ -314,12 +319,13 @@ installdata:
; for p in $(VL_INST_INC_SRCDIR_FILES) ; do \
$(INSTALL_DATA) $$p $(DESTDIR)$(pkgdatadir)/$$p; \
done
$(SHELL) ${srcdir}/mkinstalldirs $(DESTDIR)$(pkgdatadir)/examples/test_c
$(SHELL) ${srcdir}/mkinstalldirs $(DESTDIR)$(pkgdatadir)/examples/test_sc
$(SHELL) ${srcdir}/mkinstalldirs $(DESTDIR)$(pkgdatadir)/examples/test_v
$(SHELL) ${srcdir}/mkinstalldirs $(DESTDIR)$(pkgdatadir)/examples/hello_world_c
$(SHELL) ${srcdir}/mkinstalldirs $(DESTDIR)$(pkgdatadir)/examples/hello_world_sc
$(SHELL) ${srcdir}/mkinstalldirs $(DESTDIR)$(pkgdatadir)/examples/tracing_c
$(SHELL) ${srcdir}/mkinstalldirs $(DESTDIR)$(pkgdatadir)/examples/tracing_sc
cd $(srcdir) \
; for p in $(VL_INST_DATA_SRCDIR_FILES) ; do \
$(INSTALL_DATA) $$p $(DESTDIR)$(pkgdatadir)/examples/$$p; \
$(INSTALL_DATA) $$p $(DESTDIR)$(pkgdatadir)/$$p; \
done
$(SHELL) ${srcdir}/mkinstalldirs $(DESTDIR)$(pkgconfigdir)
$(INSTALL_DATA) verilator.pc $(DESTDIR)$(pkgconfigdir)
@@ -331,15 +337,15 @@ uninstall:
-cd $(DESTDIR)$(mandir)/man1 && rm -f $(VL_INST_MAN_FILES)
-cd $(DESTDIR)$(pkgdatadir) && rm -f $(VL_INST_INC_BLDDIR_FILES)
-cd $(DESTDIR)$(pkgdatadir) && rm -f $(VL_INST_INC_SRCDIR_FILES)
-cd $(DESTDIR)$(pkgdatadir)/examples && rm -f $(VL_INST_DATA_SRCDIR_FILES)
-cd $(DESTDIR)$(pkgdatadir) && rm -f $(VL_INST_DATA_SRCDIR_FILES)
-rm $(DESTDIR)$(pkgconfigdir)/verilator.pc
-rmdir $(DESTDIR)$(pkgdatadir)/bin
-rmdir $(DESTDIR)$(pkgdatadir)/include/vltstd
-rmdir $(DESTDIR)$(pkgdatadir)/include
-rmdir $(DESTDIR)$(pkgdatadir)/examples/test_c
-rmdir $(DESTDIR)$(pkgdatadir)/examples/test_sc
-rmdir $(DESTDIR)$(pkgdatadir)/examples/test_sp
-rmdir $(DESTDIR)$(pkgdatadir)/examples/test_v
-rmdir $(DESTDIR)$(pkgdatadir)/examples/hello_world_c
-rmdir $(DESTDIR)$(pkgdatadir)/examples/hello_world_sc
-rmdir $(DESTDIR)$(pkgdatadir)/examples/tracing_c
-rmdir $(DESTDIR)$(pkgdatadir)/examples/tracing_sc
-rmdir $(DESTDIR)$(pkgdatadir)/examples
-rmdir $(DESTDIR)$(pkgdatadir)
-rmdir $(DESTDIR)$(pkgconfigdir)
@@ -358,8 +364,8 @@ INST_PROJ_CVS = cp_if_cvs_diff
install-project: dist
@echo "Install-project to $(DIRPROJECT)"
strip verilator_bin*
strip verilator_coverage_bin*
strip bin/verilator_bin*
strip bin/verilator_coverage_bin*
$(MAKE) install-project-quick
for p in $(VL_INST_MAN_FILES) ; do \
$(INSTALL_DATA) $$p $(DIRPROJECT_PREFIX)/man/man1/$$p; \
@@ -382,8 +388,8 @@ endif
install-cadtools: dist
@echo "Install-project to $(CAD_DIR)"
strip verilator_bin*
strip verilator_coverage_bin*
strip bin/verilator_bin*
strip bin/verilator_coverage_bin*
$(MAKE) install-cadtools-quick
$(SHELL) ${srcdir}/mkinstalldirs $(VERILATOR_CAD_DIR)/man/man1
for p in $(VL_INST_MAN_FILES) ; do \
@@ -421,12 +427,15 @@ CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/src/obj_dbg -I$(srcdir)/src
cppcheck: $(CPPCHECK_DEP)
%.cppcheck: %.cpp
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 $(CPPCHECK_INC) $<
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $<
ftp: info
install-msg:
@echo "Installed!"
@echo
@echo "Installed binaries to $(DESTDIR)$(bindir)/verilator"
@echo "Installed man to $(DESTDIR)$(mandir)/man1"
@echo "Installed examples to $(DESTDIR)$(pkgdatadir)/examples"
@echo
@echo "For documentation see 'man verilator' or 'verilator --help'"
@echo "For forums and to report bugs see http://www.veripool.org/verilator"
@@ -454,7 +463,7 @@ endif
maintainer-clean::
@echo "This command is intended for maintainers to use;"
@echo "rebuilding the deleted files requires makeinfo."
rm -f *.info* $(INFOS) configure
rm -f *.info* *.1 $(INFOS) configure
clean mostlyclean distclean maintainer-clean maintainer-copy::
for dir in $(SUBDIRS); do \
@@ -468,10 +477,13 @@ clean mostlyclean distclean maintainer-clean::
rm -f *.pg *.pgs *.toc *.tp *.tps *.vr *.vrs *.idx
rm -f *.ev *.evs *.ov *.ovs *.cv *.cvs *.ma *.mas
rm -f *.tex
rm -rf test_*/obj_dir
rm -rf examples/*/obj_dir examples/*/logs
distclean maintainer-clean::
rm -f Makefile config.status config.cache config.log TAGS
rm -f verilator_bin* verilator_coverage_bin*
rm -f bin/verilator_bin* bin/verilator_coverage_bin*
rm -f include/verilated.mk include/verilated_config.h
TAGFILES=${srcdir}/*/*.cpp ${srcdir}/*/*.h ${srcdir}/*/*.in \
+7 -4
View File
@@ -169,6 +169,9 @@ have the verilator binary directory in your PATH (this should already be
true if using the default configure), and make sure VERILATOR_ROOT is not
set.
You may now wish to consult the examples directory. Type C<make> inside any
example directory to run the example.
=back
=head1 USAGE DOCUMENTATION
@@ -190,10 +193,10 @@ The directories in the kit after de-taring are as follows:
include/verilated.v => Stub defines for linting
include/verilated.mk => Common makefile
src/ => Translator source code
test_v => Example Verilog code for other test dirs
test_c => Example Verilog->C++ conversion
test_sc => Example Verilog->SystemC conversion
test_verilated => Internal tests
examples/hello_world_c => Example simple Verilog->C++ conversion
examples/hello_world_sc => Example simple Verilog->SystemC conversion
examples/tracing_c => Example Verilog->C++ with tracing
examples/tracing_sc => Example Verilog->SystemC with tracing
test_regress => Internal tests
=head1 LIMITATIONS
+96 -37
View File
@@ -183,8 +183,8 @@ sub run {
}
if ($status & 127) {
if (($status & 127) == 4 # SIGILL
|| ($status & 127) == 8 # SIGFPA
|| ($status & 127) == 11) { # SIGSEGV
|| ($status & 127) == 8 # SIGFPA
|| ($status & 127) == 11) { # SIGSEGV
warn "%Error: Verilator internal fault, sorry. Consider trying --debug --gdbbt\n" if !$Debug;
} elsif (($status & 127) == 6) { # SIGABRT
warn "%Error: Verilator aborted. Consider trying --debug --gdbbt\n" if !$Debug;
@@ -286,6 +286,7 @@ descriptions in the next sections for more information.
-G<name>=<value> Overwrite toplevel parameter
--gdb Run Verilator under GDB interactively
--gdbbt Run Verilator under GDB for backtrace
--getenv <var> Get environment variable with defaults
--help Display this help
-I<dir> Directory to search for includes
--if-depth <value> Tune IFDEPTH warning
@@ -327,6 +328,7 @@ descriptions in the next sections for more information.
--public Debugging; see docs
-pvalue+<name>=<value> Overwrite toplevel parameter
--relative-includes Resolve includes relative to current file
--no-relative-cfuncs Disallow 'this->' in generated functions
--report-unoptflat Extra diagnostics for UNOPTFLAT
--savable Enable model save-restore
--sc Create SystemC output
@@ -358,7 +360,8 @@ descriptions in the next sections for more information.
-Wno-lint Disable all lint warnings
-Wno-style Disable all style warnings
-Wno-fatal Disable fatal exit on warnings
--x-assign <mode> Initially assign Xs to this value
--x-assign <mode> Assign non-initial Xs to this value
--x-initial <mode> Assign initial Xs to this value
--x-initial-edge Enable initial X->0 and X->1 edge triggers
-y <dir> Directory to search for modules
@@ -428,9 +431,6 @@ C<+1364-1995ext+> etc. specify both the syntax I<and> semantics to be used.
Enable all assertions.
See also --x-assign and --x-initial-edge; setting "--x-assign unique"
and/or "--x-initial-edge" may be desirable.
=item --autoflush
After every $display or $fdisplay, flush the output stream. This insures
@@ -762,6 +762,14 @@ backtrace on exit, then exit GDB immediately. Without --debug or if GDB
doesn't seem to work, this flag is ignored. Intended for easy creation of
backtraces by users; otherwise see the --gdb flag.
=item --getenv I<variable>
If the variable is declared in the environment, print it and exit
immediately. Otherwise, if it's built into Verilator (e.g. VERILATOR_ROOT),
print that and exit immediately. Otherwise, print a newline and exit
immediately. This can be useful in makefiles. See also -V, and the various
*.mk files.
=item --help
Displays this message and program version and exits.
@@ -873,6 +881,22 @@ change the ultimate model's performance, but may in some cases.
Backward compatible alias for "--pins-bv 33".
=item --no-relative-cfuncs
Disable 'this->' references in generated functions, and instead Verilator
will generate absolute references starting from 'vlTOPp->'. This prevents
V3Combine from merging functions from multiple instances of the same
module, so it can grow the instruction stream.
This is a work around for old compilers. Don't set this if your C++
compiler supports __restrict__ properly, as GCC 4.5.x and newer do. For
older compilers, test if this switch gives you better performance or not.
Compilers which don't honor __restrict__ will suspect that 'this->'
references and 'vlTOPp->' references may alias, and may write slow code
with extra loads and stores to handle the (imaginary) aliasing. Using only
'vlTOPp->' references allows these old compilers to produce tight code.
=item --no-skip-identical
Rarely needed. Disables skipping execution of Verilator if all source
@@ -1181,7 +1205,7 @@ Setting it to "" disables matching.
=item -V
Shows the verbose version, including configuration information compiled
into Verilator. (Similar to perl -V.)
into Verilator. (Similar to perl -V.) See also --getenv.
=item -v I<filename>
@@ -1298,7 +1322,30 @@ enable rerunning with that same seed so you can reproduce bugs.
B<Note.> This option applies only to variables which are explicitly assigned
to X in the Verilog source code. Initial values of clocks are set to 0 unless
--x-initial-edge is specified. Initial values of all other state holding
variables are set as though --x-assign unique had been specified.
variables are controlled with --x-initial.
=item --x-initial 0
=item --x-initial fast
=item --x-initial unique (default)
Controls the two-state value that is used to initialize variables that are
not otherwise initialized.
--x-initial=0, initializes all otherwise uninitialized variables to zero.
--x-initial=unique, the default, initializes variables using a function,
which determines the value to use each initialization. This gives greatest
flexibility and allows finding reset bugs. See L</"Unknown states">
--x-initial=fast, is best for performance, and initializes all variables to
a state Verilator determines is optimal. This may allow further code
optimizations, but will likely hide any code bugs relating to missing
resets.
B<Note.> This option applies only to initial values of variables. Initial
values of clocks are set to 0 unless --x-initial-edge is specified.
=item --x-initial-edge
@@ -1360,7 +1407,7 @@ We'll compile this example into C++.
cat <<EOF >sim_main.cpp
#include "Vour.h"
#include "verilated.h"
int main(int argc, char **argv, char **env) {
int main(int argc, char** argv, char** env) {
Verilated::commandArgs(argc, argv);
Vour* top = new Vour;
while (!Verilated::gotFinish()) { top->eval(); }
@@ -1409,8 +1456,8 @@ And we get as output
Really, you're better off writing a Makefile to do all this for you. Then,
when your source changes it will automatically run all of these steps; to
aid this Verilator can create a makefile dependency file. See the test_c
directory in the distribution for an example.
aid this Verilator can create a makefile dependency file. See the examples
directory in the distribution.
=head1 EXAMPLE SYSTEMC EXECUTION
@@ -1487,15 +1534,16 @@ And we get the same output as the C++ example:
Really, you're better off using a Makefile to do all this for you. Then,
when your source changes it will automatically run all of these steps. See
the test_sc directory in the distribution for an example.
the examples directory in the distribution.
=head1 BENCHMARKING & OPTIMIZATION
For best performance, run Verilator with the "-O3 --x-assign=fast
--noassert" flags. The -O3 flag will require longer compile times, and
--x-assign=fast may increase the risk of reset bugs in trade for
performance; see the above documentation for these flags.
--x-initial=fast --noassert" flags. The -O3 flag will require longer
compile times, and --x-assign=fast --x-initial=fast may increase the risk
of reset bugs in trade for performance; see the above documentation for
these flags.
Minor Verilog code changes can also give big wins. You should not have any
UNOPTFLAT warnings from Verilator. Fixing these warnings can result in
@@ -1973,7 +2021,7 @@ accesses the above signal "readme" would be:
printf("Value of v: %d\n", v.value.integer); // Prints "readme"
}
int main(int argc, char **argv, char **env) {
int main(int argc, char** argv, char** env) {
Verilated::commandArgs(argc, argv);
Vour* top = new Vour;
Verilated::internalsDump(); // See scopes to help debug
@@ -2526,6 +2574,12 @@ indicate the function or task should pass all remaining arguments through
$sformatf. This allows creation of DPI functions with $display like
behavior. See the test_regress/t/t_dpi_display.v file for an example.
=item /*verilator tag <text...>*/
Attached after a variable or structure member to indicate opaque (to
Verilator) text that should be passed through to the XML output as a tag,
for use by downstream applications.
=item /*verilator tracing_off*/
Disable waveform tracing for all future signals that are declared in this
@@ -2638,24 +2692,25 @@ value (see the --x-assign switch.) Thus if the value is actually used, the
random value should cause downstream errors. Integers also randomize, even
though the Verilog 2001 specification says they initialize to zero.
All variables are randomly initialized using a function. By running
several random simulation runs you can determine that reset is working
correctly. On the first run, the function initializes variables to zero.
On the second, have it initialize variables to one. On the third and
following runs have it initialize them randomly. If the results match,
reset works. (Note this is what the hardware will really do.) In
practice, just setting all variables to one at startup finds most problems.
All variables, depending on --x-initial setting, are typically randomly
initialized using a function. By running several random simulation runs
you can determine that reset is working correctly. On the first run, the
function initializes variables to zero. On the second, have it initialize
variables to one. On the third and following runs have it initialize them
randomly. If the results match, reset works. (Note this is what the
hardware will really do.) In practice, just setting all variables to one
at startup finds most problems (since typically control signals are
active-high).
B<Note.> --x-assign applies to variables explicitly initialized or assigned to
X. Uninitialized clocks are initialized to zero, while all other state holding
variables are initialized to a random value.
Event driven simulators will generally trigger an edge on a transition from X
to 1 (C<posedge>) or X to 0 (C<negedge>). However, by default, since clocks
are initialized to zero, Verilator will not trigger an initial negedge. Some
code (particularly for reset) may rely on X->0 triggering an edge. Verilator
provides a switch (see --x-initial-edge) to enable this behavior. Comparing
runs with and without this switch will find such problems.
--x-assign applies to variables explicitly initialized or assigned to
X. Uninitialized clocks are initialized to zero, while all other state
holding variables are initialized to a random value. Event driven
simulators will generally trigger an edge on a transition from X to 1
(C<posedge>) or X to 0 (C<negedge>). However, by default, since clocks are
initialized to zero, Verilator will not trigger an initial negedge. Some
code (particularly for reset) may rely on X->0 triggering an edge. The
--x-initial-edge switch enables this behavior. Comparing runs with and
without this switch will find such problems.
=head2 Tri/Inout
@@ -3671,7 +3726,7 @@ trace file if you want all data to land in the same output file.
#include "verilated_vcd_c.h"
...
int main(int argc, char **argv, char **env) {
int main(int argc, char** argv, char** env) {
...
Verilated::traceEverOn(true);
VerilatedVcdC* tfp = new VerilatedVcdC;
@@ -3685,6 +3740,8 @@ trace file if you want all data to land in the same output file.
tfp->close();
}
Also see the examples/tracing_cc directory in the distribution.
=item How do I generate waveforms (traces) in SystemC?
Add the --trace switch to Verilator, and in your top level C sc_main code,
@@ -3707,7 +3764,7 @@ trace file if you want all data to land in the same output file.
#include "verilated_vcd_sc.h"
...
int main(int argc, char **argv, char **env) {
int main(int argc, char** argv, char** env) {
...
Verilated::traceEverOn(true);
VerilatedVcdSc* tfp = new VerilatedVcdSc;
@@ -3719,11 +3776,13 @@ trace file if you want all data to land in the same output file.
tfp->close();
}
Also see the examples/tracing_cc directory in the distribution.
=item How do I view waveforms (traces)?
Verilator makes standard VCD (Value Change Dump) files. They are viewable
with the public domain Dinotrace or GtkWave programs, or any of the many
commercial offerings.
with the public domain GtkWave (recommended) or Dinotrace (legacy)
programs, or any of the many commercial offerings.
=item How do I reduce the size of large waveform (trace) files?
+2 -2
View File
@@ -13,8 +13,8 @@ use warnings;
print "// DESCR"."IPTION: Generated by verilator_includer via makefile\n";
foreach my $param (@ARGV) {
if ($param =~ /^-D([^=]+)=(.*)/) {
print "#define $1 $2\n"
print "#define $1 $2\n"
} else {
print "#include \"$param\"\n"
print "#include \"$param\"\n"
}
}
+73 -24
View File
@@ -6,7 +6,7 @@
#AC_INIT([Verilator],[#.### YYYY-MM-DD])
#AC_INIT([Verilator],[#.### devel])
AC_INIT([Verilator],[3.912 2017-09-23])
AC_INIT([Verilator],[3.914 2017-10-14])
# When releasing, also update header of Changes file
# and commit using "devel release" or "Version bump" message
@@ -43,7 +43,7 @@ AC_ARG_ENABLE([ccwarn],
x) CFG_WITH_CCWARN=no ;;
*) CFG_WITH_CCWARN=yes ;;
esac]
)
)
AC_SUBST(CFG_WITH_CCWARN)
AC_MSG_RESULT($CFG_WITH_CCWARN)
@@ -61,7 +61,7 @@ AC_ARG_ENABLE([longtests],
x) CFG_WITH_LONGTESTS=no ;;
*) CFG_WITH_LONGTESTS=yes ;;
esac]
)
)
AC_SUBST(CFG_WITH_LONGTESTS)
AC_MSG_RESULT($CFG_WITH_LONGTESTS)
@@ -79,10 +79,10 @@ AC_PROG_INSTALL
AC_LANG_PUSH(C++)
AC_MSG_CHECKING([that C++ compiler can compile simple program])
AC_RUN_IFELSE(
[AC_LANG_SOURCE([int main() { return 0; }])],
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no);AC_MSG_ERROR([a working C++ compiler is required]),
AC_MSG_RESULT(yes))
[AC_LANG_SOURCE([int main() { return 0; }])],
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no);AC_MSG_ERROR([a working C++ compiler is required]),
AC_MSG_RESULT(yes))
AC_PATH_PROG(PERL,perl)
if test "x$PERL" = "x" ; then
@@ -106,43 +106,89 @@ AC_TYPE_SIZE_T
# Checks for compiler characteristics.
AC_C_INLINE
AC_DEFUN([_MY_CXX_CHECK_OPT],
[# _MY_CXX_CHECK_OPT(flag) -- Check if compiler supports specific options
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([], [[int* a=new int; delete a; ]])],
[], [AC_MSG_ERROR([$CXX does not seem to successfully compile a simple C++ program])])
AC_DEFUN([_MY_CXX_CHECK_FLAG],
[# _MY_CXX_CHECK_FLAG(flag) -- Check if compiler supports specific options
# Set $_my_result appropriately
ACO_SAVE_CXXFLAGS="$CXXFLAGS"
# -Werror needed otherwise unknown -Wno-div-by-zero won't report problems
CXXFLAGS="$CXXFLAGS $2 -Werror"
AC_MSG_CHECKING([whether $CXX accepts $2])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([],[])],
[_my_result=yes
if test -s conftest.err; then
if grep -e "$2" conftest.err >/dev/null; then
_my_result=no
fi
fi],
[_my_result=no])
# new/delete is needed to find -faligned-new link problem on Darwin
CXXFLAGS="$CXXFLAGS $1 -Werror"
AC_MSG_CHECKING([whether $CXX accepts $1])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([], [[int* a=new int; delete a; ]])],
[_my_result=yes
if test -s conftest.err; then
if grep -e "$1" conftest.err >/dev/null; then
_my_result=no
fi
fi],
[_my_result=no])
# GCC is annoying, trying to be helpful, it postpones unknown -Wno-
# options if there's no error We want to see them regardless, so try
# forcing an error and see if we get a gcc warning
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[an_error "intentional-error-for-test.h"
]],[])],
]],[])],
[], # Ignore ok exit
[if test -s conftest.err; then
if grep -e "$2" conftest.err >/dev/null; then
if grep -e "$1" conftest.err >/dev/null; then
_my_result=no
fi
fi])
AC_MSG_RESULT($_my_result)
CXXFLAGS="$ACO_SAVE_CXXFLAGS"
])
AC_DEFUN([_MY_CXX_CHECK_SET],
[# _MY_CXX_CHECK_SET(variable,flag) -- Check if compiler supports specific options
# If it does, set variable to flag, only if not previously set
if test "$$1" = ""; then
_MY_CXX_CHECK_FLAG($2)
if test "$_my_result" = "yes" ; then
$1="$2"
fi
fi
])
AC_DEFUN([_MY_CXX_CHECK_OPT],
[# _MY_CXX_CHECK_OPT(flag) -- Check if compiler supports specific options
# If it does, append flag to variable
_MY_CXX_CHECK_FLAG($2)
if test "$_my_result" = "yes" ; then
$1="$$1 $2"
fi
CXXFLAGS="$ACO_SAVE_CXXFLAGS"
])# _MY_CXX_CHECK_OPT
])
# Flag to select newest language standard supported
# Macros work such that first option that passes is the one we take
# gnu++14 is the newest that Verilator supports
# std++03 is the oldest that Verilator supports
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_NEWEST,-std=gnu++14)
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_NEWEST,-std=gnu++11)
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_NEWEST,-std=gnu++03)
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_NEWEST,-std=c++14)
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_NEWEST,-std=c++11)
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_NEWEST,-std=c++03)
AC_SUBST(CFG_CXXFLAGS_STD_NEWEST)
# And likewise oldest standard (same list above, backwards)
# This is used for internal testing
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_OLDEST,-std=std++03)
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_OLDEST,-std=std++11)
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_OLDEST,-std=std++14)
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_OLDEST,-std=gnu++03)
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_OLDEST,-std=gnu++11)
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_OLDEST,-std=gnu++14)
_MY_CXX_CHECK_SET(CFG_CXXFLAGS_STD_OLDEST,-std=gnu++17)
AC_SUBST(CFG_CXXFLAGS_STD_OLDEST)
# Flags for compiling Verilator internals including parser, and Verilated files
# These turn on extra warnings and are only used with 'configure --enable-ccwarn'
_MY_CXX_CHECK_OPT(CFG_CXXFLAGS_WEXTRA,-Wextra)
_MY_CXX_CHECK_OPT(CFG_CXXFLAGS_WEXTRA,-Wfloat-conversion)
_MY_CXX_CHECK_OPT(CFG_CXXFLAGS_WEXTRA,-Wlogical-op)
AC_SUBST(CFG_CXXFLAGS_WEXTRA)
@@ -181,6 +227,9 @@ _MY_CXX_CHECK_OPT(CFG_CXXFLAGS_NO_UNUSED,-Wno-shadow)
AC_SUBST(CFG_CXXFLAGS_NO_UNUSED)
# Checks for library functions.
AC_CHECK_MEMBER([struct stat.st_mtim.tv_nsec],
[AC_DEFINE([HAVE_STAT_NSEC],[1],[Defined if struct stat has st_mtim.tv_nsec])],
[], [#include <sys/stat.h>])
# Checks for system services
+1 -2
View File
@@ -635,8 +635,7 @@ INPUT = doxygen-mainpage \
test_c \
test_regress \
test_sc \
test_v \
test_verilated
test_v
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
@@ -3,4 +3,4 @@
*.csrc
*.vcd
obj_*
project
logs
+52
View File
@@ -0,0 +1,52 @@
######################################################################
#
# DESCRIPTION: Verilator Example: Small Makefile
#
# This calls the object directory makefile. That allows the objects to
# be placed in the "current directory" which simplifies the Makefile.
#
# Copyright 2003-2017 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.
#
######################################################################
# Check for sanity to avoid later confusion
ifneq ($(words $(CURDIR)),1)
$(error Unsupported: GNU Make cannot build in directories containing spaces, build elsewhere: '$(CURDIR)')
endif
######################################################################
# This is intended to be a minimal example. Before copying this to start a
# real project, it is better to start with a more complete example,
# e.g. examples/tracing_c.
# If $VERILATOR_ROOT isn't in the enviornment, we assume it is part of a
# package inatall, and verilator is in your path. Otherwise find the
# binary relative to $VERILATOR_ROOT (such as when inside the git sources).
ifeq ($(VERILATOR_ROOT),)
VERILATOR = verilator
else
export VERILATOR_ROOT
VERILATOR = $(VERILATOR_ROOT)/bin/verilator
endif
default:
@echo "-- Verilator hello-world simple example"
@echo "-- VERILATE ----------------"
$(VERILATOR) -cc --exe top.v sim_main.cpp
@echo "-- COMPILE -----------------"
$(MAKE) -j 4 -C obj_dir -f Vtop.mk
@echo "-- RUN ---------------------"
obj_dir/Vtop
@echo "-- DONE --------------------"
@echo "Note: Once this example is understood, see examples/tracing_c."
@echo "Note: Also see the EXAMPLE section in the verilator manpage/document."
######################################################################
maintainer-copy::
clean mostlyclean distclean maintainer-clean::
-rm -rf obj_dir *.log *.dmp *.vpd core
+41
View File
@@ -0,0 +1,41 @@
// DESCRIPTION: Verilator: Verilog example module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2017 by Wilson Snyder.
//======================================================================
// Include common routines
#include <verilated.h>
// Include model header, generated from Verilating "top.v"
#include "Vtop.h"
int main(int argc, char** argv, char** env) {
// See a similar example walkthrough in the verilator manpage.
// This is intended to be a minimal example. Before copying this to start a
// real project, it is better to start with a more complete example,
// e.g. examples/c_tracing.
// Prevent unused variable warnings
if (0 && argc && argv && env) {}
// Construct the Verilated model, from Vtop.h generated from Verilating "top.v"
Vtop* top = new Vtop;
// Simulate until $finish
while (!Verilated::gotFinish()) {
// Evaluate model
top->eval();
}
// Final model cleanup
top->final();
// Destroy model
delete top;
// Fin
exit(0);
}
+12
View File
@@ -0,0 +1,12 @@
// DESCRIPTION: Verilator: Verilog example module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2017 by Wilson Snyder.
// See also the EXAMPLE section in the verilator manpage/document.
module top;
initial begin
$display("Hello World!");
$finish;
end
endmodule
@@ -1,8 +1,6 @@
*.old
*.dmp
*.log
*.csrc
*.vcd
obj_*
logs
project
+67
View File
@@ -0,0 +1,67 @@
######################################################################
#
# DESCRIPTION: Verilator Example: Small Makefile
#
# This calls the object directory makefile. That allows the objects to
# be placed in the "current directory" which simplifies the Makefile.
#
# Copyright 2003-2017 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.
#
######################################################################
# Check for sanity to avoid later confusion
ifneq ($(words $(CURDIR)),1)
$(error Unsupported: GNU Make cannot build in directories containing spaces, build elsewhere: '$(CURDIR)')
endif
######################################################################
# This is intended to be a minimal example. Before copying this to start a
# real project, it is better to start with a more complete example,
# e.g. examples/tracing_sc.
# If $VERILATOR_ROOT isn't in the enviornment, we assume it is part of a
# package inatall, and verilator is in your path. Otherwise find the
# binary relative to $VERILATOR_ROOT (such as when inside the git sources).
ifeq ($(VERILATOR_ROOT),)
VERILATOR = verilator
else
export VERILATOR_ROOT
VERILATOR = $(VERILATOR_ROOT)/bin/verilator
endif
# Check if SC exists via a verilator call (empty if not)
SYSTEMC_EXISTS := $(shell $(VERILATOR) --getenv SYSTEMC_INCLUDE)
ifneq ($(SYSTEMC_EXISTS),)
default: run
else
default: nosc
endif
run:
@echo "-- Verilator hello-world simple example"
@echo "-- VERILATE ----------------"
$(VERILATOR) -sc --exe top.v sc_main.cpp
@echo "-- COMPILE -----------------"
$(MAKE) -j 4 -C obj_dir -f Vtop.mk
@echo "-- RUN ---------------------"
obj_dir/Vtop
@echo "-- DONE --------------------"
@echo "Note: Once this example is understood, see examples/tracing_sc."
@echo "Note: Also see the EXAMPLE section in the verilator manpage/document."
######################################################################
nosc:
@echo
@echo "%Skip: SYSTEMC_INCLUDE not in environment"
@echo "(If you have SystemC see the README, and rebuild Verilator)"
@echo
maintainer-copy::
clean mostlyclean distclean maintainer-clean::
-rm -rf obj_dir *.log *.dmp *.vpd core
+51
View File
@@ -0,0 +1,51 @@
// -*- SystemC -*-
// DESCRIPTION: Verilator Example: Top level main for invoking SystemC model
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2017 by Wilson Snyder.
//======================================================================
// SystemC global header
#include <systemc.h>
// Include common routines
#include <verilated.h>
// Include model header, generated from Verilating "top.v"
#include "Vtop.h"
int sc_main(int argc, char* argv[]) {
// See a similar example walkthrough in the verilator manpage.
// This is intended to be a minimal example. Before copying this to start a
// real project, it is better to start with a more complete example,
// e.g. examples/c_tracing.
// Prevent unused variable warnings
if (0 && argc && argv) {}
// Construct the Verilated model, from Vtop.h generated from Verilating "top.v"
Vtop* top = new Vtop("top");
// Initialize SC model
#if (SYSTEMC_VERSION>=20070314)
sc_start(1,SC_NS);
#else
sc_start(1);
#endif
// Simulate until $finish
while (!Verilated::gotFinish()) {
#if (SYSTEMC_VERSION>=20070314)
sc_start(1,SC_NS);
#else
sc_start(1);
#endif
}
// Final model cleanup
top->final();
// Fin
return 0;
}
+12
View File
@@ -0,0 +1,12 @@
// DESCRIPTION: Verilator: Verilog example module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2017 by Wilson Snyder.
// See also the EXAMPLE section in the verilator manpage/document.
module top;
initial begin
$display("Hello World!");
$finish;
end
endmodule
+6
View File
@@ -0,0 +1,6 @@
*.dmp
*.log
*.csrc
*.vcd
obj_*
logs
+96
View File
@@ -0,0 +1,96 @@
######################################################################
#
# DESCRIPTION: Verilator Example: Small Makefile
#
# This calls the object directory makefile. That allows the objects to
# be placed in the "current directory" which simplifies the Makefile.
#
# Copyright 2003-2017 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.
#
######################################################################
# Check for sanity to avoid later confusion
ifneq ($(words $(CURDIR)),1)
$(error Unsupported: GNU Make cannot build in directories containing spaces, build elsewhere: '$(CURDIR)')
endif
######################################################################
# Set up variables
# If $VERILATOR_ROOT isn't in the enviornment, we assume it is part of a
# package inatall, and verilator is in your path. Otherwise find the
# binary relative to $VERILATOR_ROOT (such as when inside the git sources).
ifeq ($(VERILATOR_ROOT),)
VERILATOR = verilator
VERILATOR_COVERAGE = verilator_coverage
else
export VERILATOR_ROOT
VERILATOR = $(VERILATOR_ROOT)/bin/verilator
VERILATOR_COVERAGE = $(VERILATOR_ROOT)/bin/verilator_coverage
endif
VERILATOR_FLAGS =
# Generate C++ in executable form
VERILATOR_FLAGS += -cc --exe
# Generate makefile dependencies (not shown as complicates the Makefile)
#VERILATOR_FLAGS += -MMD
# Optimize
VERILATOR_FLAGS += -O2 -x-assign 0
# Warn abount lint issues; may not want this on less solid designs
VERILATOR_FLAGS += -Wall
# Make waveforms
VERILATOR_FLAGS += --trace
# Check SystemVerilog assertions
VERILATOR_FLAGS += --assert
# Generate coverage analysis
VERILATOR_FLAGS += --coverage
# Run Verilator in debug mode
#VERILATOR_FLAGS += --debug
# Add this trace to get a backtrace in gdb
#VERILATOR_FLAGS += --gdbbt
######################################################################
default: run
run:
@echo
@echo "-- Verilator tracing example"
@echo
@echo "-- VERILATE ----------------"
$(VERILATOR) $(VERILATOR_FLAGS) -f input.vc top.v sim_main.cpp
@echo
@echo "-- COMPILE -----------------"
# To compile, we can either just do what Verilator asks,
# or call a submakefile where we can override the rules ourselves
# $(MAKE) -j 4 -C obj_dir -f Vtop.mk
$(MAKE) -j 4 -C obj_dir -f ../Makefile_obj
@echo
@echo "-- RUN ---------------------"
@mkdir -p logs
obj_dir/Vtop | tee logs/sim.log
@echo
@echo "-- COVERAGE ----------------"
$(VERILATOR_COVERAGE) --annotate logs/annotated logs/coverage.dat
@echo
@echo "-- DONE --------------------"
@echo "To see waveforms, open vlt_dump.vcd in a waveform viewer"
@echo
######################################################################
# Other targets
show-config:
$(VERILATOR) -V
maintainer-copy::
clean mostlyclean distclean maintainer-clean::
-rm -rf obj_dir logs *.log *.dmp *.vpd coverage.dat core
+55
View File
@@ -0,0 +1,55 @@
# -*- Makefile -*-
#######################################################################
#
# DESCRIPTION: Verilator Example: Makefile for inside object directory
#
# This is executed in the object directory, and called by ../Makefile
#
# Copyright 2003-2017 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.
#
#######################################################################
default: Vtop
# Include the rules made by Verilator
include Vtop.mk
#######################################################################
# Compile flags
# Override some default compile flags
CPPFLAGS += -MMD -MP
CPPFLAGS += -DVL_DEBUG=1
# Turn on some more flags (when configured appropriately)
# For testing inside Verilator, "configure --enable-ccwarn" will do this
# automatically; otherwise you may want this unconditionally enabled
ifeq ($(CFG_WITH_CCWARN),yes) # Local... Else don't burden users
USER_CPPFLAGS_WALL += -W -Werror -Wall
endif
# See the benchmarking section of bin/verilator.
# Support class optimizations. This includes the tracing and symbol table.
# SystemC takes minutes to optimize, thus it is off by default.
OPT_SLOW =
# Fast path optimizations. Most time is spent in these classes.
OPT_FAST = -O2 -fstrict-aliasing
#OPT_FAST = -O
#OPT_FAST =
#######################################################################
# Linking final exe -- presumes have a sim_main.cpp
# Special compile rule
sim_main.o: sim_main.cpp $(VM_PREFIX).h
######################################################################
######################################################################
# Automatically understand dependencies
DEPS := $(wildcard *.d)
ifneq ($(DEPS),)
include $(DEPS)
endif
+2
View File
@@ -0,0 +1,2 @@
// This file typically lists flags required by a large project, e.g. include directories
+librescan +libext+.v+.sv+.vh+.svh -y .
+114
View File
@@ -0,0 +1,114 @@
// DESCRIPTION: Verilator: Verilog example module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2017 by Wilson Snyder.
//======================================================================
// Include common routines
#include <verilated.h>
#include <sys/stat.h> // mkdir
// Include model header, generated from Verilating "top.v"
#include "Vtop.h"
// If "verilator --trace" is used, include the tracing class
#if VM_TRACE
# include <verilated_vcd_c.h>
#endif
// Current simulation time (64-bit unsigned)
vluint64_t main_time = 0;
// Called by $time in Verilog
double sc_time_stamp () {
return main_time; // Note does conversion to real, to match SystemC
}
int main(int argc, char** argv, char** env) {
// This is a more complicated example, please also see the simpler examples/hello_world_c.
// Prevent unused variable warnings
if (0 && argc && argv && env) {}
// Pass arguments so Verilated code can see them, e.g. $value$plusargs
Verilated::commandArgs(argc, argv);
// Set debug level, 0 is off, 9 is highest presently used
Verilated::debug(0);
// Randomization reset policy
Verilated::randReset(2);
// Construct the Verilated model, from Vtop.h generated from Verilating "top.v"
Vtop* top = new Vtop; // Or use a const unique_ptr, or the VL_UNIQUE_PTR wrapper
// If verilator was invoked with --trace, open trace
#if VM_TRACE
Verilated::traceEverOn(true); // Verilator must compute traced signals
VL_PRINTF("Enabling waves into logs/vlt_dump.vcd...\n");
VerilatedVcdC* tfp = new VerilatedVcdC;
top->trace(tfp, 99); // Trace 99 levels of hierarchy
mkdir("logs", 0777);
tfp->open("logs/vlt_dump.vcd"); // Open the dump file
#endif
// Set some inputs
top->reset_l = !0;
top->fastclk = 0;
top->clk = 0;
top->in_small = 1;
top->in_quad = 0x1234;
top->in_wide[0] = 0x1;
top->in_wide[1] = 0x22222222;
top->in_wide[2] = 0x33333333;
// Simulate until $finish
while (!Verilated::gotFinish()) {
main_time++; // Time passes...
// Toggle clocks and such
top->fastclk = !top->fastclk;
if ((main_time % 10) == 3) {
top->clk = 1;
}
if ((main_time % 10) == 8) {
top->clk = 0;
}
if (main_time > 1 && main_time < 10) {
top->reset_l = !1; // Assert reset
} else {
top->reset_l = !0; // Deassert reset
}
// Assign some other inputs
top->in_quad += 0x12;
// Evaluate model
top->eval();
// Read outputs
VL_PRINTF ("[%" VL_PRI64 "d] clk=%x rstl=%x iquad=%" VL_PRI64 "x"
" -> oquad=%" VL_PRI64"x owide=%x_%08x_%08x\n",
main_time, top->clk, top->reset_l, top->in_quad,
top->out_quad, top->out_wide[2], top->out_wide[1], top->out_wide[0]);
}
// Final model cleanup
top->final();
// Close trace if opened
#if VM_TRACE
if (tfp) { tfp->close(); }
#endif
// Coverage analysis (since test passed)
#if VM_COVERAGE
mkdir("logs", 0777);
VerilatedCov::write("logs/coverage.dat");
#endif
// Destroy model
delete top; top = NULL;
// Fin
exit(0);
}
+58
View File
@@ -0,0 +1,58 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2003 by Wilson Snyder.
// ======================================================================
module sub
(
input clk,
input fastclk,
input reset_l
);
// Example counter/flop
reg [31:0] count_f;
always_ff @ (posedge fastclk) begin
if (!reset_l) begin
/*AUTORESET*/
// Beginning of autoreset for uninitialized flops
count_f <= 32'h0;
// End of automatics
end
else begin
count_f <= count_f + 1;
end
end
// Another example flop
reg [31:0] count_c;
always_ff @ (posedge clk) begin
if (!reset_l) begin
/*AUTORESET*/
// Beginning of autoreset for uninitialized flops
count_c <= 32'h0;
// End of automatics
end
else begin
count_c <= count_c + 1;
if (count_c >= 3) begin
$display("[%0t] fastclk is %0d times faster than clk\n",
$time, count_f/count_c);
// This write is a magic value the Makefile uses to make sure the
// test completes successfully.
$write("*-* All Finished *-*\n");
$finish;
end
end
end
// An example assertion
always_ff @ (posedge clk) begin
AssertionExample: assert (!reset_l || count_c<100);
end
// And example coverage analysis
cover property (@(posedge clk) count_c==3);
endmodule
+42
View File
@@ -0,0 +1,42 @@
// DESCRIPTION: Verilator: Verilog example module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2003 by Wilson Snyder.
// ======================================================================
// This is intended to be a complex example of several features, please also
// see the simpler examples/hello_world_c.
module top
(
// Declare some signals so we can see how I/O works
input clk,
input fastclk,
input reset_l,
output [1:0] out_small,
output [39:0] out_quad,
output [69:0] out_wide,
input [1:0] in_small,
input [39:0] in_quad,
input [69:0] in_wide
);
// Connect up the outputs, using some trivial logic
wire [1:0] out_small = ~reset_l ? '0 : (in_small + 2'b1);
wire [39:0] out_quad = ~reset_l ? '0 : (in_quad + 40'b1);
wire [69:0] out_wide = ~reset_l ? '0 : (in_wide + 70'b1);
// And an example sub module. The submodule will print stuff.
sub sub (/*AUTOINST*/
// Inputs
.clk (clk),
.fastclk (fastclk),
.reset_l (reset_l));
// Print some stuff as an example
initial begin
$display("[%0t] Model running...\n", $time);
end
endmodule
+6
View File
@@ -0,0 +1,6 @@
*.dmp
*.log
*.csrc
*.vcd
obj_*
logs
+109
View File
@@ -0,0 +1,109 @@
######################################################################
#
# DESCRIPTION: Verilator Example: Small Makefile
#
# This calls the object directory makefile. That allows the objects to
# be placed in the "current directory" which simplifies the Makefile.
#
# Copyright 2003-2017 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.
#
######################################################################
# Check for sanity to avoid later confusion
ifneq ($(words $(CURDIR)),1)
$(error Unsupported: GNU Make cannot build in directories containing spaces, build elsewhere: '$(CURDIR)')
endif
######################################################################
# Set up variables
# If $VERILATOR_ROOT isn't in the enviornment, we assume it is part of a
# package inatall, and verilator is in your path. Otherwise find the
# binary relative to $VERILATOR_ROOT (such as when inside the git sources).
ifeq ($(VERILATOR_ROOT),)
VERILATOR = verilator
VERILATOR_COVERAGE = verilator_coverage
else
export VERILATOR_ROOT
VERILATOR = $(VERILATOR_ROOT)/bin/verilator
VERILATOR_COVERAGE = $(VERILATOR_ROOT)/bin/verilator_coverage
endif
VERILATOR_FLAGS =
# Generate SystemC in executable form
VERILATOR_FLAGS += -sc --exe
# Generate makefile dependencies (not shown as complicates the Makefile)
#VERILATOR_FLAGS += -MMD
# Optimize
VERILATOR_FLAGS += -O2 -x-assign 0
# Warn abount lint issues; may not want this on less solid designs
VERILATOR_FLAGS += -Wall
# Make waveforms
VERILATOR_FLAGS += --trace
# Check SystemVerilog assertions
VERILATOR_FLAGS += --assert
# Generate coverage analysis
VERILATOR_FLAGS += --coverage
# Run Verilator in debug mode
#VERILATOR_FLAGS += --debug
# Add this trace to get a backtrace in gdb
#VERILATOR_FLAGS += --gdbbt
# Check if SC exists via a verilator call (empty if not)
SYSTEMC_EXISTS := $(shell $(VERILATOR) --getenv SYSTEMC_INCLUDE)
######################################################################
ifneq ($(SYSTEMC_EXISTS),)
default: run
else
default: nosc
endif
run:
@echo
@echo "-- Verilator tracing example"
@echo
@echo "-- VERILATE ----------------"
$(VERILATOR) $(VERILATOR_FLAGS) -f input.vc top.v sc_main.cpp
@echo
@echo "-- COMPILE ----------------="
# To compile, we can either just do what Verilator asks,
# or call a submakefile where we can override the rules ourselves
# $(MAKE) -j 4 -C obj_dir -f Vtop.mk
$(MAKE) -j 4 -C obj_dir -f ../Makefile_obj
@echo
@echo "-- RUN ---------------------"
@mkdir -p logs
obj_dir/Vtop | tee logs/sim.log
@echo
@echo "-- COVERAGE ----------------"
$(VERILATOR_COVERAGE) --annotate logs/annotated logs/coverage.dat
@echo
@echo "-- DONE --------------------"
@echo "To see waveforms, open vlt_dump.vcd in a waveform viewer"
@echo
######################################################################
# Other targets
nosc:
@echo
@echo "%Skip: SYSTEMC_INCLUDE not in environment"
@echo "(If you have SystemC see the README, and rebuild Verilator)"
@echo
show-config:
$(VERILATOR) -V
maintainer-copy::
clean mostlyclean distclean maintainer-clean::
-rm -rf obj_dir logs *.log *.dmp *.vpd coverage.dat core
+63
View File
@@ -0,0 +1,63 @@
# -*- Makefile -*-
#######################################################################
#
# DESCRIPTION: Verilator Example: Makefile for inside object directory
#
# This is executed in the object directory, and called by ../Makefile
#
# Copyright 2003-2017 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.
#
#######################################################################
default: Vtop
# Include the rules made by Verilator
include Vtop.mk
#######################################################################
# Compile flags
# Override some default compile flags
CPPFLAGS += -MMD -MP
CPPFLAGS += -DVL_DEBUG=1
# SystemC isn't too clean
CPPFLAGS += -Wno-deprecated
# Turn on some more flags (when configured appropriately)
# For testing inside Verilator, "configure --enable-ccwarn" will do this
# automatically; otherwise you may want this unconditionally enabled
ifeq ($(CFG_WITH_CCWARN),yes) # Local... Else don't burden users
USER_CPPFLAGS_WALL += -W -Werror -Wall
endif
# If you build your own rules from scratch, note you need to include
# SystemC as follows (Vtop.mk file includes verilated.mk with these
# already).
# CPPFLAGS += $(SYSTEMC_CXX_FLAGS) -I$(SYSTEMC_INCLUDE)
# LDFLAGS += $(SYSTEMC_CXX_FLAGS) -L$(SYSTEMC_LIBDIR)
# See the benchmarking section of bin/verilator.
# Support class optimizations. This includes the tracing and symbol table.
# SystemC takes minutes to optimize, thus it is off by default.
OPT_SLOW =
# Fast path optimizations. Most time is spent in these classes.
OPT_FAST = -O2 -fstrict-aliasing
#OPT_FAST = -O
#OPT_FAST =
#######################################################################
# Linking final exe -- presumes have a sim_main.cpp
# Special compile rule
sim_main.o: sim_main.cpp $(VM_PREFIX).h
######################################################################
######################################################################
# Automatically understand dependencies
DEPS := $(wildcard *.d)
ifneq ($(DEPS),)
include $(DEPS)
endif
+2
View File
@@ -0,0 +1,2 @@
// This file typically lists flags required by a large project, e.g. include directories
+librescan +libext+.v+.sv+.vh+.svh -y .
+136
View File
@@ -0,0 +1,136 @@
// -*- SystemC -*-
// DESCRIPTION: Verilator Example: Top level main for invoking SystemC model
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2017 by Wilson Snyder.
//======================================================================
// SystemC global header
#include <systemc.h>
// Include common routines
#include <verilated.h>
#if VM_TRACE
#include <verilated_vcd_sc.h>
#endif
#include <sys/stat.h> // mkdir
// Include model header, generated from Verilating "top.v"
#include "Vtop.h"
int sc_main(int argc, char* argv[]) {
// This is a more complicated example, please also see the simpler examples/hello_world_c.
// Prevent unused variable warnings
if (0 && argc && argv) {}
// Pass arguments so Verilated code can see them, e.g. $value$plusargs
Verilated::commandArgs(argc, argv);
// Set debug level, 0 is off, 9 is highest presently used
Verilated::debug(0);
// Randomization reset policy
Verilated::randReset(2);
// General logfile
ios::sync_with_stdio();
// Defaults time
#if (SYSTEMC_VERSION>20011000)
#else
sc_time dut(1.0, sc_ns);
sc_set_default_time_unit(dut);
#endif
// Define clocks
#if (SYSTEMC_VERSION>=20070314)
sc_clock clk ("clk", 10,SC_NS, 0.5, 3,SC_NS, true);
sc_clock fastclk ("fastclk", 2,SC_NS, 0.5, 2,SC_NS, true);
#else
sc_clock clk ("clk", 10, 0.5, 3, true);
sc_clock fastclk ("fastclk", 2, 0.5, 2, true);
#endif
// Define interconnect
sc_signal<bool> reset_l;
sc_signal<vluint32_t> in_small;
sc_signal<vluint64_t> in_quad;
sc_signal<sc_bv<70> > in_wide;
sc_signal<vluint32_t> out_small;
sc_signal<vluint64_t> out_quad;
sc_signal<sc_bv<70> > out_wide;
// Construct the Verilated model, from inside Vtop.h
Vtop* top = new Vtop("top");
// Attach signals to the model
top->clk (clk);
top->fastclk (fastclk);
top->reset_l (reset_l);
top->in_small (in_small);
top->in_quad (in_quad);
top->in_wide (in_wide);
top->out_small (out_small);
top->out_quad (out_quad);
top->out_wide (out_wide);
#if VM_TRACE
// Before any evaluation, need to know to calculate those signals only used for tracing
Verilated::traceEverOn(true);
#endif
// You must do one evaluation before enabling waves, in order to allow
// SystemC to interconnect everything for testing.
#if (SYSTEMC_VERSION>=20070314)
sc_start(1,SC_NS);
#else
sc_start(1);
#endif
// Turn on waves
#if VM_TRACE
cout << "Enabling waves into logs/vlt_dump.vcd...\n";
VerilatedVcdSc* tfp = new VerilatedVcdSc;
top->trace (tfp, 99);
mkdir("logs", 0777);
tfp->open ("logs/vlt_dump.vcd");
#endif
// Simulate until $finish
while (!Verilated::gotFinish()) {
#if VM_TRACE
// Flush the wave files each cycle so we can immediately see the output
// Don't do this in "real" programs, do it in an abort() handler instead
if (tfp) tfp->flush();
// Apply inputs
if (VL_TIME_Q() > 1 && VL_TIME_Q() < 10) {
reset_l = !1; // Assert reset
} else if (VL_TIME_Q() > 1) {
reset_l = !0; // Deassert reset
}
#endif
// Simulate 1ns
#if (SYSTEMC_VERSION>=20070314)
sc_start(1,SC_NS);
#else
sc_start(1);
#endif
}
// Close Waves
#if VM_TRACE
if (tfp) tfp->close();
#endif
// Final model cleanup
top->final();
// Coverage analysis (since test passed)
#if VM_COVERAGE
mkdir("logs", 0777);
VerilatedCov::write("logs/coverage.dat");
#endif
// Fin
return 0;
}
+58
View File
@@ -0,0 +1,58 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2003 by Wilson Snyder.
// ======================================================================
module sub
(
input clk,
input fastclk,
input reset_l
);
// Example counter/flop
reg [31:0] count_f;
always_ff @ (posedge fastclk) begin
if (!reset_l) begin
/*AUTORESET*/
// Beginning of autoreset for uninitialized flops
count_f <= 32'h0;
// End of automatics
end
else begin
count_f <= count_f + 1;
end
end
// Another example flop
reg [31:0] count_c;
always_ff @ (posedge clk) begin
if (!reset_l) begin
/*AUTORESET*/
// Beginning of autoreset for uninitialized flops
count_c <= 32'h0;
// End of automatics
end
else begin
count_c <= count_c + 1;
if (count_c >= 3) begin
$display("[%0t] fastclk is %0d times faster than clk\n",
$time, count_f/count_c);
// This write is a magic value the Makefile uses to make sure the
// test completes successfully.
$write("*-* All Finished *-*\n");
$finish;
end
end
end
// An example assertion
always_ff @ (posedge clk) begin
AssertionExample: assert (!reset_l || count_c<100);
end
// And example coverage analysis
cover property (@(posedge clk) count_c==3);
endmodule
+42
View File
@@ -0,0 +1,42 @@
// DESCRIPTION: Verilator: Verilog example module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2003 by Wilson Snyder.
// ======================================================================
// This is intended to be a complex example of several features, please also
// see the simpler examples/hello_world_c.
module top
(
// Declare some signals so we can see how I/O works
input clk,
input fastclk,
input reset_l,
output [1:0] out_small,
output [39:0] out_quad,
output [69:0] out_wide,
input [1:0] in_small,
input [39:0] in_quad,
input [69:0] in_wide
);
// Connect up the outputs, using some trivial logic
wire [1:0] out_small = ~reset_l ? '0 : (in_small + 2'b1);
wire [39:0] out_quad = ~reset_l ? '0 : (in_quad + 40'b1);
wire [69:0] out_wide = ~reset_l ? '0 : (in_wide + 70'b1);
// And an example sub module. The submodule will print stuff.
sub sub (/*AUTOINST*/
// Inputs
.clk (clk),
.fastclk (fastclk),
.reset_l (reset_l));
// Print some stuff as an example
initial begin
$display("[%0t] Model running...\n", $time);
end
endmodule
+65 -62
View File
@@ -37,9 +37,9 @@ VerilatedVoidCb Verilated::s_flushCb = NULL;
// Keep below together in one cache line
Verilated::Serialized Verilated::s_s;
VL_THREAD const VerilatedScope* Verilated::t_dpiScopep = NULL;
VL_THREAD const char* Verilated::t_dpiFilename = "";
VL_THREAD int Verilated::t_dpiLineno = 0;
VL_THREAD_LOCAL const VerilatedScope* Verilated::t_dpiScopep = NULL;
VL_THREAD_LOCAL const char* Verilated::t_dpiFilename = "";
VL_THREAD_LOCAL int Verilated::t_dpiLineno = 0;
struct Verilated::CommandArgValues Verilated::s_args = {0, NULL};
VerilatedImp VerilatedImp::s_s;
@@ -194,9 +194,9 @@ WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, boo
if (vw == 1) { // Single divisor word breaks rest of algorithm
vluint64_t k = 0;
for (int j = uw-1; j >= 0; --j) {
vluint64_t unw64 = ((k<<VL_ULL(32)) + (vluint64_t)(lwp[j]));
owp[j] = unw64 / (vluint64_t)(rwp[0]);
k = unw64 - (vluint64_t)(owp[j])*(vluint64_t)(rwp[0]);
vluint64_t unw64 = ((k<<VL_ULL(32)) + static_cast<vluint64_t>(lwp[j]));
owp[j] = unw64 / static_cast<vluint64_t>(rwp[0]);
k = unw64 - static_cast<vluint64_t>(owp[j])*static_cast<vluint64_t>(rwp[0]);
}
if (is_modulus) {
owp[0] = k;
@@ -233,9 +233,9 @@ WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, boo
// Main loop
for (int j = uw - vw; j >= 0; --j) {
// Estimate
vluint64_t unw64 = ((vluint64_t)(un[j+vw])<<VL_ULL(32) | (vluint64_t)(un[j+vw-1]));
vluint64_t qhat = unw64 / (vluint64_t)(vn[vw-1]);
vluint64_t rhat = unw64 - qhat*(vluint64_t)(vn[vw-1]);
vluint64_t unw64 = (static_cast<vluint64_t>(un[j+vw])<<VL_ULL(32) | static_cast<vluint64_t>(un[j+vw-1]));
vluint64_t qhat = unw64 / static_cast<vluint64_t>(vn[vw-1]);
vluint64_t rhat = unw64 - qhat*static_cast<vluint64_t>(vn[vw-1]);
again:
if (qhat >= VL_ULL(0x100000000)
@@ -262,7 +262,7 @@ WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, boo
owp[j]--;
k = 0;
for (int i=0; i<vw; ++i) {
t = (vluint64_t)(un[i+j]) + (vluint64_t)(vn[i]) + k;
t = static_cast<vluint64_t>(un[i+j]) + static_cast<vluint64_t>(vn[i]) + k;
un[i+j] = t;
k = t >> VL_ULL(32);
}
@@ -372,8 +372,8 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) {
// Note uses a single buffer internally; presumes only one usage per printf
// Note also assumes variables < 64 are not wide, this assumption is
// sometimes not true in low-level routines written here in verilated.cpp
static VL_THREAD char tmp[VL_VALUE_STRING_MAX_WIDTH];
static VL_THREAD char tmpf[VL_VALUE_STRING_MAX_WIDTH];
static VL_THREAD_LOCAL char tmp[VL_VALUE_STRING_MAX_WIDTH];
static VL_THREAD_LOCAL char tmpf[VL_VALUE_STRING_MAX_WIDTH];
const char* pctp = NULL; // Most recent %##.##g format
bool inPct = false;
bool widthSet = false;
@@ -467,7 +467,8 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) {
}
break;
case 'd': { // Signed decimal
int digits=sprintf(tmp,"%" VL_PRI64 "d",(vlsint64_t)(VL_EXTENDS_QQ(lbits,lbits,ld)));
int digits = sprintf(tmp,"%" VL_PRI64 "d",
static_cast<vlsint64_t>(VL_EXTENDS_QQ(lbits,lbits,ld)));
int needmore = width-digits;
if (needmore>0) {
if (pctp && pctp[0] && pctp[1]=='0') { //%0
@@ -498,8 +499,8 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) {
digits=sprintf(tmp,"%" VL_PRI64 "u",ld);
} else if (VL_TIME_MULTIPLIER==1000) {
digits=sprintf(tmp,"%" VL_PRI64 "u.%03" VL_PRI64 "u",
(QData)(ld/VL_TIME_MULTIPLIER),
(QData)(ld%VL_TIME_MULTIPLIER));
static_cast<QData>(ld/VL_TIME_MULTIPLIER),
static_cast<QData>(ld%VL_TIME_MULTIPLIER));
} else {
vl_fatal(__FILE__,__LINE__,"","Unsupported VL_TIME_MULTIPLIER");
}
@@ -529,20 +530,20 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) {
case 'u': // Packed 2-state
output.reserve(output.size() + 4*VL_WORDS_I(lbits));
for (int i=0; i<VL_WORDS_I(lbits); ++i) {
output += (char)((lwp[i] ) & 0xff);
output += (char)((lwp[i] >> 8) & 0xff);
output += (char)((lwp[i] >> 16) & 0xff);
output += (char)((lwp[i] >> 24) & 0xff);
output += static_cast<char>((lwp[i] ) & 0xff);
output += static_cast<char>((lwp[i] >> 8) & 0xff);
output += static_cast<char>((lwp[i] >> 16) & 0xff);
output += static_cast<char>((lwp[i] >> 24) & 0xff);
}
break;
case 'z': // Packed 4-state
output.reserve(output.size() + 8*VL_WORDS_I(lbits));
for (int i=0; i<VL_WORDS_I(lbits); ++i) {
output += (char)((lwp[i] ) & 0xff);
output += (char)((lwp[i] >> 8) & 0xff);
output += (char)((lwp[i] >> 16) & 0xff);
output += (char)((lwp[i] >> 24) & 0xff);
output += "\0\0\0\0"; // No tristate
output += static_cast<char>((lwp[i] ) & 0xff);
output += static_cast<char>((lwp[i] >> 8) & 0xff);
output += static_cast<char>((lwp[i] >> 16) & 0xff);
output += static_cast<char>((lwp[i] >> 24) & 0xff);
output += "\0\0\0\0"; // No tristate
}
break;
case 'v': // Strength; assume always strong
@@ -622,10 +623,10 @@ static inline void _vl_vsss_setbit(WDataOutP owp, int obits, int lsb, int nbits,
VL_ASSIGNBIT_WI(0, lsb, owp, ld & 1);
}
}
static inline void _vl_vsss_based(WDataOutP owp, int obits, int baseLog2, const char* strp, int posstart, int posend) {
static inline void _vl_vsss_based(WDataOutP owp, int obits, int baseLog2, const char* strp, size_t posstart, size_t posend) {
// Read in base "2^^baseLog2" digits from strp[posstart..posend-1] into owp of size obits.
int lsb = 0;
for (int i=0, pos=posend-1; i<obits && pos>=posstart; --pos) {
for (int i=0, pos=static_cast<int>(posend)-1; i<obits && pos>=static_cast<int>(posstart); --pos) {
switch (tolower (strp[pos])) {
case 'x': case 'z': case '?': //FALLTHRU
case '0': lsb += baseLog2; break;
@@ -656,7 +657,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
// Read a Verilog $sscanf/$fscanf style format into the output list
// The format must be pre-processed (and lower cased) by Verilator
// Arguments are in "width, arg-value (or WDataIn* if wide)" form
static VL_THREAD char tmp[VL_VALUE_STRING_MAX_WIDTH];
static VL_THREAD_LOCAL char tmp[VL_VALUE_STRING_MAX_WIDTH];
int floc = fbits - 1;
IData got = 0;
bool inPct = false;
@@ -706,7 +707,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
_vl_vsss_skipspace(fp,floc,fromp,fstr);
_vl_vsss_read(fp,floc,fromp,fstr, tmp, NULL);
if (!tmp[0]) goto done;
int lpos = ((int)strlen(tmp))-1;
int lpos = (static_cast<int>(strlen(tmp)))-1;
int lsb = 0;
for (int i=0; i<obits && lpos>=0; --lpos) {
_vl_vsss_setbit(owp,obits,lsb, 8, tmp[lpos]); lsb+=8;
@@ -748,21 +749,21 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
_vl_vsss_skipspace(fp,floc,fromp,fstr);
_vl_vsss_read(fp,floc,fromp,fstr, tmp, "01xXzZ?_");
if (!tmp[0]) goto done;
_vl_vsss_based(owp,obits, 1, tmp, 0, (int)strlen(tmp));
_vl_vsss_based(owp,obits, 1, tmp, 0, strlen(tmp));
break;
}
case 'o': {
_vl_vsss_skipspace(fp,floc,fromp,fstr);
_vl_vsss_read(fp,floc,fromp,fstr, tmp, "01234567xXzZ?_");
if (!tmp[0]) goto done;
_vl_vsss_based(owp,obits, 3, tmp, 0, (int)strlen(tmp));
_vl_vsss_based(owp,obits, 3, tmp, 0, strlen(tmp));
break;
}
case 'x': {
_vl_vsss_skipspace(fp,floc,fromp,fstr);
_vl_vsss_read(fp,floc,fromp,fstr, tmp, "0123456789abcdefABCDEFxXzZ?_");
if (!tmp[0]) goto done;
_vl_vsss_based(owp,obits, 4, tmp, 0, (int)strlen(tmp));
_vl_vsss_based(owp,obits, 4, tmp, 0, strlen(tmp));
break;
}
default:
@@ -814,12 +815,12 @@ void _VL_VINT_TO_STRING(int obits, char* destoutp, WDataInP sourcep) {
if (!start) while (isspace(*(destp-1)) && destp>destoutp) *--destp = '\0'; // Drop trailing spaces
}
void _VL_STRING_TO_VINT(int obits, void* destp, int srclen, const char* srcp) {
void _VL_STRING_TO_VINT(int obits, void* destp, size_t srclen, const char* srcp) {
// Convert C string to Verilog format
int bytes = VL_BYTES_I(obits);
char* op = ((char*)(destp));
size_t bytes = VL_BYTES_I(obits);
char* op = reinterpret_cast<char*>(destp);
if (srclen > bytes) srclen = bytes; // Don't overflow destination
int i;
size_t i;
for (i=0; i<srclen; ++i) { *op++ = srcp[srclen-1-i]; }
for (; i<bytes; ++i) { *op++ = 0; }
}
@@ -880,58 +881,58 @@ void VL_FCLOSE_I(IData fdi) {
}
void VL_SFORMAT_X(int obits, CData& destr, const char* formatp, ...) {
VL_STATIC_OR_THREAD std::string output; // static only for speed
static VL_THREAD_LOCAL std::string output; // static only for speed
output = "";
va_list ap;
va_start(ap,formatp);
_vl_vsformat(output, formatp, ap);
va_end(ap);
_VL_STRING_TO_VINT(obits, &destr, (int)output.length(), output.c_str());
_VL_STRING_TO_VINT(obits, &destr, output.length(), output.c_str());
}
void VL_SFORMAT_X(int obits, SData& destr, const char* formatp, ...) {
VL_STATIC_OR_THREAD std::string output; // static only for speed
static VL_THREAD_LOCAL std::string output; // static only for speed
output = "";
va_list ap;
va_start(ap,formatp);
_vl_vsformat(output, formatp, ap);
va_end(ap);
_VL_STRING_TO_VINT(obits, &destr, (int)output.length(), output.c_str());
_VL_STRING_TO_VINT(obits, &destr, output.length(), output.c_str());
}
void VL_SFORMAT_X(int obits, IData& destr, const char* formatp, ...) {
VL_STATIC_OR_THREAD std::string output; // static only for speed
static VL_THREAD_LOCAL std::string output; // static only for speed
output = "";
va_list ap;
va_start(ap,formatp);
_vl_vsformat(output, formatp, ap);
va_end(ap);
_VL_STRING_TO_VINT(obits, &destr, (int)output.length(), output.c_str());
_VL_STRING_TO_VINT(obits, &destr, output.length(), output.c_str());
}
void VL_SFORMAT_X(int obits, QData& destr, const char* formatp, ...) {
VL_STATIC_OR_THREAD std::string output; // static only for speed
static VL_THREAD_LOCAL std::string output; // static only for speed
output = "";
va_list ap;
va_start(ap,formatp);
_vl_vsformat(output, formatp, ap);
va_end(ap);
_VL_STRING_TO_VINT(obits, &destr, (int)output.length(), output.c_str());
_VL_STRING_TO_VINT(obits, &destr, output.length(), output.c_str());
}
void VL_SFORMAT_X(int obits, void* destp, const char* formatp, ...) {
VL_STATIC_OR_THREAD std::string output; // static only for speed
static VL_THREAD_LOCAL std::string output; // static only for speed
output = "";
va_list ap;
va_start(ap,formatp);
_vl_vsformat(output, formatp, ap);
va_end(ap);
_VL_STRING_TO_VINT(obits, destp, (int)output.length(), output.c_str());
_VL_STRING_TO_VINT(obits, destp, output.length(), output.c_str());
}
void VL_SFORMAT_X(int obits_ignored, std::string &output, const char* formatp, ...) {
@@ -944,7 +945,7 @@ void VL_SFORMAT_X(int obits_ignored, std::string &output, const char* formatp, .
}
std::string VL_SFORMATF_NX(const char* formatp, ...) {
VL_STATIC_OR_THREAD std::string output; // static only for speed
static VL_THREAD_LOCAL std::string output; // static only for speed
output = "";
va_list ap;
va_start(ap,formatp);
@@ -955,7 +956,7 @@ std::string VL_SFORMATF_NX(const char* formatp, ...) {
}
void VL_WRITEF(const char* formatp, ...) {
VL_STATIC_OR_THREAD std::string output; // static only for speed
static VL_THREAD_LOCAL std::string output; // static only for speed
output = "";
va_list ap;
va_start(ap,formatp);
@@ -967,7 +968,7 @@ void VL_WRITEF(const char* formatp, ...) {
}
void VL_FWRITEF(IData fpi, const char* formatp, ...) {
VL_STATIC_OR_THREAD std::string output; // static only for speed
static VL_THREAD_LOCAL std::string output; // static only for speed
output = "";
FILE* fp = VL_CVT_I_FP(fpi);
if (VL_UNLIKELY(!fp)) return;
@@ -1088,32 +1089,34 @@ void VL_READMEM_N(bool hex, int width, int depth, int array_lsb, int fnwords,
} else {
needinc = true;
//printf(" Value width=%d @%x = %c\n", width, addr, c);
if (VL_UNLIKELY(addr >= (IData)(depth+array_lsb) || addr < (IData)(array_lsb))) {
if (VL_UNLIKELY(addr >= static_cast<IData>(depth+array_lsb)
|| addr < static_cast<IData>(array_lsb))) {
vl_fatal (ofilenamep.c_str(), linenum, "", "$readmem file address beyond bounds of array");
} else {
int entry = addr - array_lsb;
QData shift = hex ? VL_ULL(4) : VL_ULL(1);
// Shift value in
if (width<=8) {
CData* datap = &((CData*)(memp))[entry];
CData* datap = &(reinterpret_cast<CData*>(memp))[entry];
if (!innum) { *datap = 0; }
*datap = ((*datap << shift) + value) & VL_MASK_I(width);
} else if (width<=16) {
SData* datap = &((SData*)(memp))[entry];
SData* datap = &(reinterpret_cast<SData*>(memp))[entry];
if (!innum) { *datap = 0; }
*datap = ((*datap << shift) + value) & VL_MASK_I(width);
} else if (width<=VL_WORDSIZE) {
IData* datap = &((IData*)(memp))[entry];
IData* datap = &(reinterpret_cast<IData*>(memp))[entry];
if (!innum) { *datap = 0; }
*datap = ((*datap << shift) + value) & VL_MASK_I(width);
} else if (width<=VL_QUADSIZE) {
QData* datap = &((QData*)(memp))[entry];
QData* datap = &(reinterpret_cast<QData*>(memp))[entry];
if (!innum) { *datap = 0; }
*datap = ((*datap << (QData)(shift)) + (QData)(value)) & VL_MASK_Q(width);
*datap = ((*datap << static_cast<QData>(shift))
+ static_cast<QData>(value)) & VL_MASK_Q(width);
} else {
WDataOutP datap = &((WDataOutP)(memp))[ entry*VL_WORDS_I(width) ];
WDataOutP datap = &(reinterpret_cast<WDataOutP>(memp))[ entry*VL_WORDS_I(width) ];
if (!innum) { VL_ZERO_RESET_W(width, datap); }
_VL_SHIFTL_INPLACE_W(width, datap, (IData)shift);
_VL_SHIFTL_INPLACE_W(width, datap, static_cast<IData>(shift));
datap[0] |= value;
}
if (VL_UNLIKELY(value>=(1<<shift))) {
@@ -1191,17 +1194,17 @@ IData VL_VALUEPLUSARGS_INW(int rbits, const std::string& ld, WDataOutP rwp) {
VL_SET_WQ(rwp,lld);
break;
case 'b':
_vl_vsss_based(rwp,rbits, 1, dp, 0, (int)strlen(dp));
_vl_vsss_based(rwp,rbits, 1, dp, 0, strlen(dp));
break;
case 'o':
_vl_vsss_based(rwp,rbits, 3, dp, 0, (int)strlen(dp));
_vl_vsss_based(rwp,rbits, 3, dp, 0, strlen(dp));
break;
case 'h': //FALLTHRU
case 'x':
_vl_vsss_based(rwp,rbits, 4, dp, 0, (int)strlen(dp));
_vl_vsss_based(rwp,rbits, 4, dp, 0, strlen(dp));
break;
case 's': // string/no conversion
for (int i=0, lsb=0, posp=((int)strlen(dp))-1; i<rbits && posp>=0; --posp) {
for (int i=0, lsb=0, posp=static_cast<int>(strlen(dp))-1; i<rbits && posp>=0; --posp) {
_vl_vsss_setbit(rwp,rbits,lsb, 8, dp[posp]); lsb+=8;
}
break;
@@ -1244,7 +1247,7 @@ IData VL_VALUEPLUSARGS_INN(int, const std::string& ld, std::string& rdr) {
const char* vl_mc_scan_plusargs(const char* prefixp) {
const std::string& match = VerilatedImp::argPlusMatch(prefixp);
static VL_THREAD char outstr[VL_VALUE_STRING_MAX_WIDTH];
static VL_THREAD_LOCAL char outstr[VL_VALUE_STRING_MAX_WIDTH];
if (match == "") return NULL;
strncpy(outstr, match.c_str()+strlen(prefixp)+1, // +1 to skip the "+"
VL_VALUE_STRING_MAX_WIDTH);
@@ -1312,7 +1315,7 @@ void Verilated::commandArgs(int argc, const char** argv) {
const char* Verilated::commandArgsPlusMatch(const char* prefixp) {
const std::string& match = VerilatedImp::argPlusMatch(prefixp);
static VL_THREAD char outstr[VL_VALUE_STRING_MAX_WIDTH];
static VL_THREAD_LOCAL char outstr[VL_VALUE_STRING_MAX_WIDTH];
if (match == "") return "";
strncpy(outstr, match.c_str(), VL_VALUE_STRING_MAX_WIDTH);
outstr[VL_VALUE_STRING_MAX_WIDTH-1] = '\0';
+51 -51
View File
@@ -234,9 +234,9 @@ class Verilated {
Serialized();
} s_s;
static VL_THREAD const VerilatedScope* t_dpiScopep; ///< DPI context scope
static VL_THREAD const char* t_dpiFilename; ///< DPI context filename
static VL_THREAD int t_dpiLineno; ///< DPI context line number
static VL_THREAD_LOCAL const VerilatedScope* t_dpiScopep; ///< DPI context scope
static VL_THREAD_LOCAL const char* t_dpiFilename; ///< DPI context filename
static VL_THREAD_LOCAL int t_dpiLineno; ///< DPI context line number
// no need to be save-restored (serialized) the
// assumption is that the restore is allowed to pass different arguments
@@ -286,7 +286,7 @@ public:
/// Record command line arguments, for retrieval by $test$plusargs/$value$plusargs
static void commandArgs(int argc, const char** argv);
static void commandArgs(int argc, char** argv) { commandArgs(argc,(const char**)argv); }
static void commandArgs(int argc, char** argv) { commandArgs(argc, const_cast<const char**>(argv)); }
static void commandArgsAdd(int argc, const char** argv);
static CommandArgValues* getCommandArgs() {return &s_args;}
/// Match plusargs with a given prefix. Returns static char* valid only for a single call
@@ -404,10 +404,10 @@ extern const char* vl_mc_scan_plusargs(const char* prefixp); // PLIish
/// Create two 32-bit words from quadword
/// WData is always at least 2 words; does not clean upper bits
#define VL_SET_WQ(owp,data) { owp[0]=(IData)(data); owp[1]=(IData)((data)>>VL_WORDSIZE); }
#define VL_SET_WI(owp,data) { owp[0]=(IData)(data); owp[1]=0; }
#define VL_SET_QW(lwp) ( ((QData)(lwp[0])) | ((QData)(lwp[1])<<((QData)(VL_WORDSIZE)) ))
#define _VL_SET_QII(ld,rd) ( ((QData)(ld)<<VL_ULL(32)) | (QData)(rd) )
#define VL_SET_WQ(owp,data) { owp[0]=static_cast<IData>(data); owp[1]=static_cast<IData>((data)>>VL_WORDSIZE); }
#define VL_SET_WI(owp,data) { owp[0]=static_cast<IData>(data); owp[1]=0; }
#define VL_SET_QW(lwp) ( (static_cast<QData>(lwp[0])) | (static_cast<QData>(lwp[1])<<(static_cast<QData>(VL_WORDSIZE)) ))
#define _VL_SET_QII(ld,rd) ( (static_cast<QData>(ld)<<VL_ULL(32)) | static_cast<QData>(rd) )
/// Return FILE* from IData
extern FILE* VL_CVT_I_FP(IData lhs);
@@ -422,11 +422,11 @@ static inline double VL_CVT_D_Q(QData lhs) { union { double d; QData q; } u; u.q
/// Return QData from double (bits, not numerically)
static inline QData VL_CVT_Q_D(double lhs) { union { double d; QData q; } u; u.d=lhs; return u.q; }
/// Return double from QData (numeric)
static inline double VL_ITOR_D_I(IData lhs) { return ((double)((vlsint32_t)(lhs))); }
static inline double VL_ITOR_D_I(IData lhs) { return static_cast<double>(static_cast<vlsint32_t>(lhs)); }
/// Return QData from double (numeric)
static inline IData VL_RTOI_I_D(double lhs) { return ((vlsint32_t)(VL_TRUNC(lhs))); }
static inline IData VL_RTOI_I_D(double lhs) { return static_cast<vlsint32_t>(VL_TRUNC(lhs)); }
/// Return QData from double (numeric)
static inline IData VL_RTOIROUND_I_D(double lhs) { return ((vlsint32_t)(VL_ROUND(lhs))); }
static inline IData VL_RTOIROUND_I_D(double lhs) { return static_cast<vlsint32_t>(VL_ROUND(lhs)); }
// Sign extend such that if MSB set, we get ffff_ffff, else 0s
// (Requires clean input)
@@ -441,7 +441,7 @@ static inline IData VL_EXTENDSIGN_I(int lbits, IData lhs) { return (-((lhs)&(VL
static inline QData VL_EXTENDSIGN_Q(int lbits, QData lhs) { return (-((lhs)&(VL_ULL(1)<<(lbits-1)))); }
// Debugging prints
void _VL_DEBUG_PRINT_W(int lbits, WDataInP iwp);
extern void _VL_DEBUG_PRINT_W(int lbits, WDataInP iwp);
//=========================================================================
// Pli macros
@@ -455,13 +455,13 @@ void _VL_DEBUG_PRINT_W(int lbits, WDataInP iwp);
/// Return current simulation time
#if defined(SYSTEMC_VERSION) && (SYSTEMC_VERSION>20011000)
# define VL_TIME_I() ((IData)(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER))
# define VL_TIME_Q() ((QData)(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER))
# define VL_TIME_D() ((double)(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER))
# define VL_TIME_I() (static_cast<IData>(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER))
# define VL_TIME_Q() (static_cast<QData>(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER))
# define VL_TIME_D() (static_cast<double>(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER))
#else
# define VL_TIME_I() ((IData)(sc_time_stamp()*VL_TIME_MULTIPLIER))
# define VL_TIME_Q() ((QData)(sc_time_stamp()*VL_TIME_MULTIPLIER))
# define VL_TIME_D() ((double)(sc_time_stamp()*VL_TIME_MULTIPLIER))
# define VL_TIME_I() (static_cast<IData>(sc_time_stamp()*VL_TIME_MULTIPLIER))
# define VL_TIME_Q() (static_cast<QData>(sc_time_stamp()*VL_TIME_MULTIPLIER))
# define VL_TIME_D() (static_cast<double>(sc_time_stamp()*VL_TIME_MULTIPLIER))
extern double sc_time_stamp();
#endif
@@ -581,8 +581,8 @@ static inline void VL_ASSIGNBIT_WO(int, int bit, WDataOutP owp, IData) {
od = (svar.read().get_word(0)) & VL_MASK_I(obits); \
}
#define VL_ASSIGN_QSW(obits,od,svar) { \
od = (((QData)svar.read().get_word(1))<<VL_WORDSIZE | svar.read().get_word(0)) \
& VL_MASK_Q(obits); \
od = ((static_cast<QData>(svar.read().get_word(1)))<<VL_WORDSIZE | svar.read().get_word(0)) \
& VL_MASK_Q(obits); \
}
#define VL_ASSIGN_WSW(obits,owp,svar) { \
int words = VL_WORDS_I(obits); \
@@ -616,8 +616,8 @@ static inline void VL_ASSIGNBIT_WO(int, int bit, WDataOutP owp, IData) {
}
#define VL_ASSIGN_SWQ(obits,svar,rd) { \
sc_bv<obits> _bvtemp; \
_bvtemp.set_word(0,(IData)(rd)); \
_bvtemp.set_word(1,(IData)((rd)>>VL_WORDSIZE)); \
_bvtemp.set_word(0, static_cast<IData>(rd)); \
_bvtemp.set_word(1, static_cast<IData>((rd)>>VL_WORDSIZE)); \
svar.write(_bvtemp); \
}
#define VL_ASSIGN_SWW(obits,svar,rwp) { \
@@ -648,7 +648,7 @@ static inline void VL_ASSIGNBIT_WO(int, int bit, WDataOutP owp, IData) {
// Right must be clean because otherwise size increase would pick up bad bits
// EMIT_RULE: VL_EXTEND: oclean=clean; rclean==clean;
#define VL_EXTEND_II(obits,lbits,lhs) ((lhs))
#define VL_EXTEND_QI(obits,lbits,lhs) ((QData)(lhs))
#define VL_EXTEND_QI(obits,lbits,lhs) (static_cast<QData>(lhs))
#define VL_EXTEND_QQ(obits,lbits,lhs) ((lhs))
static inline WDataOutP VL_EXTEND_WI(int obits, int, WDataOutP owp, IData ld) {
@@ -768,7 +768,7 @@ static inline IData VL_REDXOR_64(QData r) {
return __builtin_parityll(r);
#else
r=(r^(r>>1)); r=(r^(r>>2)); r=(r^(r>>4)); r=(r^(r>>8)); r=(r^(r>>16)); r=(r^(r>>32));
return (IData)r;
return static_cast<IData>(r);
#endif
}
static inline IData VL_REDXOR_W(int words, WDataInP lwp) {
@@ -787,7 +787,7 @@ static inline IData VL_COUNTONES_I(IData lhs) {
return r;
}
static inline IData VL_COUNTONES_Q(QData lhs) {
return VL_COUNTONES_I((IData)lhs) + VL_COUNTONES_I((IData)(lhs>>32));
return VL_COUNTONES_I(static_cast<IData>(lhs)) + VL_COUNTONES_I(static_cast<IData>(lhs>>32));
}
static inline IData VL_COUNTONES_W(int words, WDataInP lwp) {
IData r = 0;
@@ -1024,7 +1024,7 @@ static inline int _VL_CMPS_W(int lbits, WDataInP lwp, WDataInP rwp) {
static inline WDataOutP VL_ADD_W(int words, WDataOutP owp,WDataInP lwp,WDataInP rwp){
QData carry = 0;
for (int i=0; i<words; ++i) {
carry = carry + (QData)(lwp[i]) + (QData)(rwp[i]);
carry = carry + static_cast<QData>(lwp[i]) + static_cast<QData>(rwp[i]);
owp[i] = (carry & VL_ULL(0xffffffff));
carry = (carry >> VL_ULL(32)) & VL_ULL(0xffffffff);
}
@@ -1034,7 +1034,7 @@ static inline WDataOutP VL_ADD_W(int words, WDataOutP owp,WDataInP lwp,WDataInP
static inline WDataOutP VL_SUB_W(int words, WDataOutP owp,WDataInP lwp,WDataInP rwp){
QData carry = 0;
for (int i=0; i<words; ++i) {
carry = carry + (QData)(lwp[i]) + (QData)(IData)(~rwp[i]);
carry = carry + static_cast<QData>(lwp[i]) + static_cast<QData>(static_cast<IData>(~rwp[i]));
if (i==0) carry++; // Negation of temp2
owp[i] = (carry & VL_ULL(0xffffffff));
carry = (carry >> VL_ULL(32)) & VL_ULL(0xffffffff);
@@ -1051,7 +1051,7 @@ static inline QData VL_NEGATE_Q(QData data) { return -data; }
static inline WDataOutP VL_NEGATE_W(int words, WDataOutP owp,WDataInP lwp){
QData carry = 0;
for (int i=0; i<words; ++i) {
carry = carry + (QData)(IData)(~lwp[i]);
carry = carry + static_cast<QData>(static_cast<IData>(~lwp[i]));
if (i==0) carry++; // Negation of temp2
owp[i] = (carry & VL_ULL(0xffffffff));
carry = (carry >> VL_ULL(32)) & VL_ULL(0xffffffff);
@@ -1063,9 +1063,9 @@ static inline WDataOutP VL_MUL_W(int words, WDataOutP owp,WDataInP lwp,WDataInP
for (int i=0; i<words; ++i) owp[i] = 0;
for (int lword=0; lword<words; ++lword) {
for (int rword=0; rword<words; ++rword) {
QData mul = (QData)(lwp[lword]) * (QData)(rwp[rword]);
QData mul = static_cast<QData>(lwp[lword]) * static_cast<QData>(rwp[rword]);
for (int qword=lword+rword; qword<words; ++qword) {
mul += (QData)(owp[qword]);
mul += static_cast<QData>(owp[qword]);
owp[qword] = (mul & VL_ULL(0xffffffff));
mul = (mul >> VL_ULL(32)) & VL_ULL(0xffffffff);
}
@@ -1111,7 +1111,7 @@ static inline WDataOutP VL_MULS_WWW(int,int lbits,int, WDataOutP owp,WDataInP lw
if ((lneg ^ rneg) & 1) { // Negate output (not using NEGATE, as owp==lwp)
QData carry = 0;
for (int i=0; i<words; ++i) {
carry = carry + (QData)(IData)(~owp[i]);
carry = carry + static_cast<QData>(static_cast<IData>(~owp[i]));
if (i==0) carry++; // Negation of temp2
owp[i] = (carry & VL_ULL(0xffffffff));
carry = (carry >> VL_ULL(32)) & VL_ULL(0xffffffff);
@@ -1357,7 +1357,7 @@ static inline void _VL_INSERT_WQ(int obits, WDataOutP owp, QData ld, int hbit, i
// EMIT_RULE: VL_REPLICATE: oclean=clean>width32, dirty<=width32; lclean=clean; rclean==clean;
// RHS MUST BE CLEAN CONSTANT.
#define VL_REPLICATE_IOI(obits,lbits,rbits, ld, rep) (-(ld)) // Iff lbits==1
#define VL_REPLICATE_QOI(obits,lbits,rbits, ld, rep) (-((QData)ld)) // Iff lbits==1
#define VL_REPLICATE_QOI(obits,lbits,rbits, ld, rep) (-(static_cast<QData>(ld))) // Iff lbits==1
static inline IData VL_REPLICATE_III(int, int lbits, int, IData ld, IData rep) {
IData returndata = ld;
@@ -1371,7 +1371,7 @@ static inline QData VL_REPLICATE_QII(int, int lbits, int, IData ld, IData rep) {
QData returndata = ld;
for (unsigned i=1; i < rep; ++i){
returndata = returndata << lbits;
returndata |= (QData)ld;
returndata |= static_cast<QData>(ld);
}
return (returndata);
}
@@ -1497,7 +1497,7 @@ static inline QData VL_STREAML_QQI(int, int lbits, int, QData ld, IData rd) {
static inline WDataOutP VL_STREAML_WWI(int, int lbits, int, WDataOutP owp, WDataInP lwp, IData rd) {
VL_ZERO_W(lbits, owp);
// Slice size should never exceed the lhs width
int ssize = (rd < (IData)lbits) ? rd : ((IData)lbits);
int ssize = (rd < static_cast<IData>(lbits)) ? rd : (static_cast<IData>(lbits));
for (int istart=0; istart<lbits; istart+=rd) {
int ostart=lbits-rd-istart;
ostart = ostart > 0 ? ostart : 0;
@@ -1515,11 +1515,11 @@ static inline WDataOutP VL_STREAML_WWI(int, int lbits, int, WDataOutP owp, WData
// Thus we specify inputs must be clean, so we don't need to clean the output.
// Note the bit shifts are always constants, so the adds in these constify out.
// Casts required, as args may be 8 bit entities, and need to shift to appropriate output size
#define VL_CONCAT_III(obits,lbits,rbits,ld,rd) ((IData)(ld)<<(rbits) | (IData)(rd))
#define VL_CONCAT_QII(obits,lbits,rbits,ld,rd) ((QData)(ld)<<(rbits) | (QData)(rd))
#define VL_CONCAT_QIQ(obits,lbits,rbits,ld,rd) ((QData)(ld)<<(rbits) | (QData)(rd))
#define VL_CONCAT_QQI(obits,lbits,rbits,ld,rd) ((QData)(ld)<<(rbits) | (QData)(rd))
#define VL_CONCAT_QQQ(obits,lbits,rbits,ld,rd) ((QData)(ld)<<(rbits) | (QData)(rd))
#define VL_CONCAT_III(obits,lbits,rbits,ld,rd) (static_cast<IData>(ld)<<(rbits) | static_cast<IData>(rd))
#define VL_CONCAT_QII(obits,lbits,rbits,ld,rd) (static_cast<QData>(ld)<<(rbits) | static_cast<QData>(rd))
#define VL_CONCAT_QIQ(obits,lbits,rbits,ld,rd) (static_cast<QData>(ld)<<(rbits) | static_cast<QData>(rd))
#define VL_CONCAT_QQI(obits,lbits,rbits,ld,rd) (static_cast<QData>(ld)<<(rbits) | static_cast<QData>(rd))
#define VL_CONCAT_QQQ(obits,lbits,rbits,ld,rd) (static_cast<QData>(ld)<<(rbits) | static_cast<QData>(rd))
static inline WDataOutP VL_CONCAT_WII(int obits,int lbits,int rbits,WDataOutP owp,IData ld,IData rd) {
owp[0] = rd;
@@ -1597,7 +1597,7 @@ static inline void _VL_SHIFTL_INPLACE_W(int obits,WDataOutP iowp,IData rd/*1 or
static inline WDataOutP VL_SHIFTL_WWI(int obits,int,int,WDataOutP owp,WDataInP lwp, IData rd) {
int word_shift = VL_BITWORD_I(rd);
int bit_shift = VL_BITBIT_I(rd);
if (rd >= (IData)obits) { // rd may be huge with MSB set
if (rd >= static_cast<IData>(obits)) { // rd may be huge with MSB set
for (int i=0; i < VL_WORDS_I(obits); ++i) owp[i] = 0;
} else if (bit_shift==0) { // Aligned word shift (<<0,<<32,<<64 etc)
for (int i=0; i < word_shift; ++i) owp[i] = 0;
@@ -1631,7 +1631,7 @@ static inline IData VL_SHIFTL_IIW(int obits,int,int rbits,IData lhs, WDataInP rw
static inline WDataOutP VL_SHIFTR_WWI(int obits,int,int,WDataOutP owp,WDataInP lwp, IData rd) {
int word_shift = VL_BITWORD_I(rd); // Maybe 0
int bit_shift = VL_BITBIT_I(rd);
if (rd >= (IData)obits) { // rd may be huge with MSB set
if (rd >= static_cast<IData>(obits)) { // rd may be huge with MSB set
for (int i=0; i < VL_WORDS_I(obits); ++i) owp[i] = 0;
} else if (bit_shift==0) { // Aligned word shift (>>0,>>32,>>64 etc)
int copy_words = (VL_WORDS_I(obits)-word_shift);
@@ -1686,14 +1686,14 @@ static inline QData VL_SHIFTRS_QQI(int obits, int lbits, int, QData lhs, IData r
return (lhs >> rhs) | (sign & VL_CLEAN_QQ(obits,obits,signext));
}
static inline IData VL_SHIFTRS_IQI(int obits, int lbits, int rbits, QData lhs, IData rhs) {
return (IData)(VL_SHIFTRS_QQI(obits, lbits, rbits, lhs, rhs));
return static_cast<IData>(VL_SHIFTRS_QQI(obits, lbits, rbits, lhs, rhs));
}
static inline WDataOutP VL_SHIFTRS_WWI(int obits,int lbits,int,WDataOutP owp,WDataInP lwp, IData rd) {
int word_shift = VL_BITWORD_I(rd);
int bit_shift = VL_BITBIT_I(rd);
int lmsw = VL_WORDS_I(obits)-1;
IData sign = VL_SIGNONES_I(lbits,lwp[lmsw]);
if (rd >= (IData)obits) { // Shifting past end, sign in all of lbits
if (rd >= static_cast<IData>(obits)) { // Shifting past end, sign in all of lbits
for (int i=0; i <= lmsw; ++i) owp[i] = sign;
owp[lmsw] &= VL_MASK_I(lbits);
} else if (bit_shift==0) { // Aligned word shift (>>0,>>32,>>64 etc)
@@ -1766,11 +1766,11 @@ static inline QData VL_SHIFTRS_QQQ(int obits,int lbits,int rbits,QData lhs, QDat
#define VL_BITSEL_IIII(obits,lbits,rbits,zbits,lhs,rhs) ((lhs)>>(rhs))
#define VL_BITSEL_QIII(obits,lbits,rbits,zbits,lhs,rhs) ((lhs)>>(rhs))
#define VL_BITSEL_QQII(obits,lbits,rbits,zbits,lhs,rhs) ((lhs)>>(rhs))
#define VL_BITSEL_IQII(obits,lbits,rbits,zbits,lhs,rhs) ((IData)((lhs)>>(rhs)))
#define VL_BITSEL_IQII(obits,lbits,rbits,zbits,lhs,rhs) (static_cast<IData>((lhs)>>(rhs)))
static inline IData VL_BITSEL_IWII(int, int lbits, int, int, WDataInP lwp, IData rd) {
int word = VL_BITWORD_I(rd);
if (VL_UNLIKELY(rd>(IData)lbits)) {
if (VL_UNLIKELY(rd > static_cast<IData>(lbits))) {
return ~0; // Spec says you can go outside the range of a array. Don't coredump if so.
// We return all 1's as that's more likely to find bugs (?) than 0's.
} else {
@@ -1782,13 +1782,13 @@ static inline IData VL_BITSEL_IWII(int, int lbits, int, int, WDataInP lwp, IData
// <msb> & <lsb> MUST BE CLEAN (currently constant)
#define VL_SEL_IIII(obits,lbits,rbits,tbits,lhs,lsb,width) ((lhs)>>(lsb))
#define VL_SEL_QQII(obits,lbits,rbits,tbits,lhs,lsb,width) ((lhs)>>(lsb))
#define VL_SEL_IQII(obits,lbits,rbits,tbits,lhs,lsb,width) ((IData)((lhs)>>(lsb)))
#define VL_SEL_IQII(obits,lbits,rbits,tbits,lhs,lsb,width) (static_cast<IData>((lhs)>>(lsb)))
static inline IData VL_SEL_IWII(int, int lbits, int, int, WDataInP lwp, IData lsb, IData width) {
int msb = lsb+width-1;
if (VL_UNLIKELY(msb>lbits)) {
return ~0; // Spec says you can go outside the range of a array. Don't coredump if so.
} else if (VL_BITWORD_I(msb)==VL_BITWORD_I((int)lsb)) {
} else if (VL_BITWORD_I(msb)==VL_BITWORD_I(static_cast<int>(lsb))) {
return (lwp[VL_BITWORD_I(lsb)]>>VL_BITBIT_I(lsb));
} else {
// 32 bit extraction may span two words
@@ -1802,9 +1802,9 @@ static inline QData VL_SEL_QWII(int, int lbits, int, int, WDataInP lwp, IData ls
int msb = lsb+width-1;
if (VL_UNLIKELY(msb>lbits)) {
return ~0; // Spec says you can go outside the range of a array. Don't coredump if so.
} else if (VL_BITWORD_I(msb)==VL_BITWORD_I((int)lsb)) {
} else if (VL_BITWORD_I(msb)==VL_BITWORD_I(static_cast<int>(lsb))) {
return (lwp[VL_BITWORD_I(lsb)]>>VL_BITBIT_I(lsb));
} else if (VL_BITWORD_I(msb)==1+VL_BITWORD_I((int)lsb)) {
} else if (VL_BITWORD_I(msb)==1+VL_BITWORD_I(static_cast<int>(lsb))) {
int nbitsfromlow = 32-VL_BITBIT_I(lsb);
QData hi = (lwp[VL_BITWORD_I(msb)]);
QData lo = (lwp[VL_BITWORD_I(lsb)]>>VL_BITBIT_I(lsb));
@@ -1837,7 +1837,7 @@ static inline WDataOutP VL_SEL_WWII(int obits,int lbits,int,int,WDataOutP owp,WD
for (int i=0; i<words; ++i) {
owp[i] = lwp[i+word_shift]>>loffset;
int upperword = i+word_shift+1;
if (upperword <= (int)VL_BITWORD_I(msb)) {
if (upperword <= static_cast<int>(VL_BITWORD_I(msb))) {
owp[i] |= lwp[upperword]<< nbitsfromlow;
}
}
@@ -1900,7 +1900,7 @@ static inline WDataOutP VL_COND_WIWW(int obits, int, int, int,
// If changing the number of functions here, also change EMITCINLINES_NUM_CONSTW
#define _END(obits,wordsSet) \
for(int i=(wordsSet);i<VL_WORDS_I(obits);++i) o[i] = (IData)0x0; \
for(int i=(wordsSet);i<VL_WORDS_I(obits);++i) o[i] = 0; \
return o
static inline WDataOutP VL_CONST_W_1X(int obits, WDataOutP o,
+4
View File
@@ -16,6 +16,10 @@ RANLIB = ranlib
CFG_WITH_CCWARN = @CFG_WITH_CCWARN@
CFG_WITH_LONGTESTS = @CFG_WITH_LONGTESTS@
# Select newest language
CFG_CXXFLAGS_STD_NEWEST = @CFG_CXXFLAGS_STD_NEWEST@
# Select oldest language (for Verilator internal testing only)
CFG_CXXFLAGS_STD_OLDEST = @CFG_CXXFLAGS_STD_OLDEST@
# Compiler flags to use to turn off unused and generated code warnings, such as -Wno-div-by-zero
CFG_CXXFLAGS_NO_UNUSED = @CFG_CXXFLAGS_NO_UNUSED@
# Compiler flags that turn on extra warnings
+9 -9
View File
@@ -128,7 +128,7 @@ private:
m_indexValues.insert(std::make_pair(nextIndex, value));
return nextIndex;
}
std::string dequote(const std::string& text) {
static std::string dequote(const std::string& text) {
// Quote any special characters
std::string rtn;
for (const char* pos = text.c_str(); *pos; ++pos) {
@@ -141,7 +141,7 @@ private:
}
return rtn;
}
bool legalKey(const std::string& key) {
static bool legalKey(const std::string& key) {
// Because we compress long keys to a single letter, and
// don't want applications to either get confused if they use
// a letter differently, nor want them to rely on our compression...
@@ -150,7 +150,7 @@ private:
if (key.length()==2 && isdigit(key[1])) return false;
return true;
}
std::string keyValueFormatter (const std::string& key, const std::string& value) {
static std::string keyValueFormatter (const std::string& key, const std::string& value) {
std::string name;
if (key.length()==1 && isalpha(key[0])) {
name += std::string("\001")+key;
@@ -160,7 +160,7 @@ private:
name += std::string("\002")+dequote(value);
return name;
}
std::string combineHier (const std::string& old, const std::string& add) {
static std::string combineHier (const std::string& old, const std::string& add) {
// (foo.a.x, foo.b.x) => foo.*.x
// (foo.a.x, foo.b.y) => foo.*
// (foo.a.x, foo.b) => foo.*
@@ -206,7 +206,7 @@ private:
}
return false;
}
void selftest() {
static void selftest() {
// Little selftest
if (combineHier ("a.b.c","a.b.c") !="a.b.c") vl_fatal(__FILE__,__LINE__,"","%Error: selftest\n");
if (combineHier ("a.b.c","a.b") !="a.b*") vl_fatal(__FILE__,__LINE__,"","%Error: selftest\n");
@@ -221,7 +221,7 @@ private:
public:
// PUBLIC METHODS
void clear() {
for (ItemList::iterator it=m_items.begin(); it!=m_items.end(); ++it) {
for (ItemList::const_iterator it=m_items.begin(); it!=m_items.end(); ++it) {
VerilatedCovImpItem* itemp = *(it);
delete itemp;
}
@@ -244,7 +244,7 @@ public:
}
}
void zero() {
for (ItemList::iterator it=m_items.begin(); it!=m_items.end(); ++it) {
for (ItemList::const_iterator it=m_items.begin(); it!=m_items.end(); ++it) {
(*it)->zero();
}
}
@@ -320,7 +320,7 @@ public:
std::ofstream os (filename);
if (os.fail()) {
std::string msg = (std::string)"%Error: Can't write '"+filename+"'";
std::string msg = std::string("%Error: Can't write '")+filename+"'";
vl_fatal("",0,"",msg.c_str());
return;
}
@@ -372,7 +372,7 @@ public:
}
// Output body
for (EventMap::iterator it=eventCounts.begin(); it!=eventCounts.end(); ++it) {
for (EventMap::const_iterator it=eventCounts.begin(); it!=eventCounts.end(); ++it) {
os<<"C '"<<std::dec;
os<<it->first;
if (it->second.first != "") os<<keyValueFormatter(VL_CIK_HIER,it->second.first);
+4 -2
View File
@@ -30,7 +30,9 @@
// On MSVC++ we need svdpi.h to declare exports, not imports
#define DPI_PROTOTYPES
#undef XXTERN
#define XXTERN DPI_EXTERN DPI_DLLESPEC
#undef EETERN
#define EETERN DPI_EXTERN DPI_DLLESPEC
#include "vltstd/svdpi.h"
@@ -261,13 +263,13 @@ svScope svGetScope() {
svScope svSetScope(const svScope scope) {
const VerilatedScope* prevScopep = Verilated::dpiScope();
const VerilatedScope* vscopep = (const VerilatedScope*)(scope);
const VerilatedScope* vscopep = reinterpret_cast<const VerilatedScope*>(scope);
Verilated::dpiScope(vscopep);
return (svScope)prevScopep;
}
const char* svGetNameFromScope(const svScope scope) {
const VerilatedScope* vscopep = (const VerilatedScope*)(scope);
const VerilatedScope* vscopep = reinterpret_cast<const VerilatedScope*>(scope);
return vscopep->name();
}
+3 -3
View File
@@ -16,9 +16,9 @@
/// \file
/// \brief Verilator: Common include for all Verilated C files that use DPI
///
/// This file is included automatically by Verilator at the top of
/// all C++ files it generates where DPI is used. It contains
/// DPI interface functions required by the Verilated code.
/// This file is included automatically by Verilator at the top of
/// all C++ files it generates where DPI is used. It contains
/// DPI interface functions required by the Verilated code.
///
/// Code available from: http://www.veripool.org/verilator
///
+4 -4
View File
@@ -16,10 +16,10 @@
/// \file
/// \brief Verilator: String include for all Verilated C files
///
/// This file is included automatically by Verilator at the top of
/// all C++ files it generates. It is used when strings or other
/// heavyweight types are required; these contents are not part of
/// verilated.h to save compile time when such types aren't used.
/// This file is included automatically by Verilator at the top of
/// all C++ files it generates. It is used when strings or other
/// heavyweight types are required; these contents are not part of
/// verilated.h to save compile time when such types aren't used.
///
/// Code available from: http://www.veripool.org/verilator
///
+10 -10
View File
@@ -80,7 +80,7 @@ public: // But only for verilated*.cpp
static void internalsDump() {
VL_PRINTF("internalsDump:\n");
VL_PRINTF(" Argv:");
for (ArgVec::iterator it=s_s.m_argVec.begin(); it!=s_s.m_argVec.end(); ++it) {
for (ArgVec::const_iterator it=s_s.m_argVec.begin(); it!=s_s.m_argVec.end(); ++it) {
VL_PRINTF(" %s",it->c_str());
}
VL_PRINTF("\n");
@@ -109,7 +109,7 @@ public: // But only for verilated*.cpp
"%Error: Verilog called $test$plusargs or $value$plusargs without"
" testbench C first calling Verilated::commandArgs(argc,argv).");
}
for (ArgVec::iterator it=s_s.m_argVec.begin(); it!=s_s.m_argVec.end(); ++it) {
for (ArgVec::const_iterator it=s_s.m_argVec.begin(); it!=s_s.m_argVec.end(); ++it) {
if ((*it)[0]=='+') {
if (0==strncmp(prefixp, it->c_str()+1, len)) return *it;
}
@@ -128,7 +128,7 @@ public: // But only for verilated*.cpp
else s_s.m_userMap.insert(it, std::make_pair(std::make_pair(scopep,userKey),userData));
}
static inline void* userFind(const void* scopep, void* userKey) {
UserMap::iterator it=s_s.m_userMap.find(std::make_pair(scopep,userKey));
UserMap::const_iterator it=s_s.m_userMap.find(std::make_pair(scopep,userKey));
if (VL_LIKELY(it != s_s.m_userMap.end())) return it->second;
else return NULL;
}
@@ -146,7 +146,7 @@ private:
}
static void userDump() {
bool first = true;
for (UserMap::iterator it=s_s.m_userMap.begin(); it!=s_s.m_userMap.end(); ++it) {
for (UserMap::const_iterator it=s_s.m_userMap.begin(); it!=s_s.m_userMap.end(); ++it) {
if (first) { VL_PRINTF(" userDump:\n"); first=false; }
VL_PRINTF(" DPI_USER_DATA scope %p key %p: %p\n",
it->first.first, it->first.second, it->second);
@@ -163,7 +163,7 @@ public: // But only for verilated*.cpp
}
}
static inline const VerilatedScope* scopeFind(const char* namep) {
VerilatedScopeNameMap::iterator it=s_s.m_nameMap.find(namep);
VerilatedScopeNameMap::const_iterator it=s_s.m_nameMap.find(namep);
if (VL_LIKELY(it != s_s.m_nameMap.end())) return it->second;
else return NULL;
}
@@ -175,7 +175,7 @@ public: // But only for verilated*.cpp
}
static void scopesDump() {
VL_PRINTF(" scopesDump:\n");
for (VerilatedScopeNameMap::iterator it=s_s.m_nameMap.begin(); it!=s_s.m_nameMap.end(); ++it) {
for (VerilatedScopeNameMap::const_iterator it=s_s.m_nameMap.begin(); it!=s_s.m_nameMap.end(); ++it) {
const VerilatedScope* scopep = it->second;
scopep->scopeDump();
}
@@ -205,7 +205,7 @@ public: // But only for verilated*.cpp
}
}
static int exportFind(const char* namep) {
ExportNameMap::iterator it=s_s.m_exportMap.find(namep);
ExportNameMap::const_iterator it=s_s.m_exportMap.find(namep);
if (VL_LIKELY(it != s_s.m_exportMap.end())) return it->second;
std::string msg = (std::string("%Error: Testbench C called ")+namep
+" but no such DPI export function name exists in ANY model");
@@ -214,14 +214,14 @@ public: // But only for verilated*.cpp
}
static const char* exportName(int funcnum) {
// Slowpath; find name for given export; errors only so no map to reverse-map it
for (ExportNameMap::iterator it=s_s.m_exportMap.begin(); it!=s_s.m_exportMap.end(); ++it) {
for (ExportNameMap::const_iterator it=s_s.m_exportMap.begin(); it!=s_s.m_exportMap.end(); ++it) {
if (it->second == funcnum) return it->first;
}
return "*UNKNOWN*";
}
static void exportsDump() {
bool first = true;
for (ExportNameMap::iterator it=s_s.m_exportMap.begin(); it!=s_s.m_exportMap.end(); ++it) {
for (ExportNameMap::const_iterator it=s_s.m_exportMap.begin(); it!=s_s.m_exportMap.end(); ++it) {
if (first) { VL_PRINTF(" exportDump:\n"); first=false; }
VL_PRINTF(" DPI_EXPORT_NAME %05d: %s\n", it->second, it->first);
}
@@ -238,7 +238,7 @@ public: // But only for verilated*.cpp
// Need to create more space in m_fdps and m_fdFree
size_t start = s_s.m_fdps.size();
s_s.m_fdps.resize(start*2);
for (size_t i=start; i<start*2; ++i) s_s.m_fdFree.push_back((IData)i);
for (size_t i=start; i<start*2; ++i) s_s.m_fdFree.push_back(static_cast<IData>(i));
}
IData idx = s_s.m_fdFree.back(); s_s.m_fdFree.pop_back();
s_s.m_fdps[idx] = fp;
+5 -5
View File
@@ -40,8 +40,8 @@
#endif
// CONSTANTS
static const char* VLTSAVE_HEADER_STR = "verilatorsave01\n"; ///< Value of first bytes of each file
static const char* VLTSAVE_TRAILER_STR = "vltsaved"; ///< Value of last bytes of each file
static const char* const VLTSAVE_HEADER_STR = "verilatorsave01\n"; ///< Value of first bytes of each file
static const char* const VLTSAVE_TRAILER_STR = "vltsaved"; ///< Value of last bytes of each file
//=============================================================================
//=============================================================================
@@ -61,7 +61,7 @@ bool VerilatedDeserialize::readDiffers (const void* __restrict datap, size_t siz
VerilatedDeserialize& VerilatedDeserialize::readAssert (const void* __restrict datap, size_t size) {
if (VL_UNLIKELY(readDiffers(datap,size))) {
std::string fn = filename();
std::string msg = (std::string)"Can't deserialize save-restore file as was made from different model";
std::string msg = std::string("Can't deserialize save-restore file as was made from different model");
vl_fatal(fn.c_str(), 0, "", msg.c_str());
close();
}
@@ -82,7 +82,7 @@ void VerilatedDeserialize::header() {
VerilatedDeserialize& os = *this; // So can cut and paste standard >> code below
if (VL_UNLIKELY(os.readDiffers(VLTSAVE_HEADER_STR, strlen(VLTSAVE_HEADER_STR)))) {
std::string fn = filename();
std::string msg = (std::string)"Can't deserialize; file has wrong header signature";
std::string msg = std::string("Can't deserialize; file has wrong header signature");
vl_fatal(fn.c_str(), 0, "", msg.c_str());
close();
}
@@ -99,7 +99,7 @@ void VerilatedDeserialize::trailer() {
VerilatedDeserialize& os = *this; // So can cut and paste standard >> code below
if (VL_UNLIKELY(os.readDiffers(VLTSAVE_TRAILER_STR, strlen(VLTSAVE_TRAILER_STR)))) {
std::string fn = filename();
std::string msg = (std::string)"Can't deserialize; file has wrong end-of-file signature";
std::string msg = std::string("Can't deserialize; file has wrong end-of-file signature");
vl_fatal(fn.c_str(), 0, "", msg.c_str());
close();
}
+45 -36
View File
@@ -27,31 +27,30 @@
#include <string>
//=============================================================================
// VerilatedSerialBase - internal base class for common code between VerilatedSerialize and VerilatedDeserialize
// VerilatedSerialize - convert structures to a stream representation
class VerilatedSerialBase {
class VerilatedSerialize {
protected:
// MEMBERS
// For speed, keep m_cp as the first member of this structure
vluint8_t* m_cp; ///< Current pointer into m_bufp buffer
vluint8_t* m_bufp; ///< Output buffer
bool m_isOpen; ///< True indicates open file/stream
std::string m_filename;
std::string m_filename; ///< Filename, for error messages
inline static size_t bufferSize() { return 256*1024; } // See below for slack calculation
inline static size_t bufferInsertSize() { return 16*1024; }
void header();
void trailer();
public:
// CREATORS
VerilatedSerialBase() {
VerilatedSerialize() {
m_isOpen = false;
m_bufp = new vluint8_t [bufferSize()];
m_cp = m_bufp;
}
private:
VerilatedSerialBase(const VerilatedSerialBase& ); ///< N/A, no copy constructor
public:
// CREATORS
virtual ~VerilatedSerialBase() {
virtual ~VerilatedSerialize() {
close();
if (m_bufp) { delete m_bufp; m_bufp=NULL; }
}
@@ -60,30 +59,6 @@ public:
std::string filename() const { return m_filename; }
virtual void close() { flush(); }
virtual void flush() {}
};
//=============================================================================
// VerilatedSerialize - convert structures to a stream representation
class VerilatedSerialize : public VerilatedSerialBase {
protected:
virtual void close() { flush(); }
virtual void flush() {}
void header();
void trailer();
public:
// CREATORS
VerilatedSerialize() {}
virtual ~VerilatedSerialize() { close(); }
// METHODS
VerilatedSerialize& bufferCheck() {
// Flush the write buffer if there's not enough space left for new information
// We only call this once per vector, so we need enough slop for a very wide "b###" line
if (VL_UNLIKELY(m_cp > (m_bufp+(bufferSize()-bufferInsertSize())))) {
flush();
}
return *this; // For function chaining
}
inline VerilatedSerialize& write (const void* __restrict datap, size_t size) {
const vluint8_t* __restrict dp = (const vluint8_t* __restrict)datap;
while (size) {
@@ -95,22 +70,54 @@ public:
}
return *this; // For function chaining
}
private:
VerilatedSerialize(const VerilatedSerialize& ); ///< N/A, no copy constructor
VerilatedSerialize& bufferCheck() {
// Flush the write buffer if there's not enough space left for new information
// We only call this once per vector, so we need enough slop for a very wide "b###" line
if (VL_UNLIKELY(m_cp > (m_bufp+(bufferSize()-bufferInsertSize())))) {
flush();
}
return *this; // For function chaining
}
};
//=============================================================================
// VerilatedDeserial - load structures from a stream representation
class VerilatedDeserialize : public VerilatedSerialBase {
class VerilatedDeserialize {
protected:
// MEMBERS
// For speed, keep m_cp as the first member of this structure
vluint8_t* m_cp; ///< Current pointer into m_bufp buffer
vluint8_t* m_bufp; ///< Output buffer
vluint8_t* m_endp; ///< Last valid byte in m_bufp buffer
bool m_isOpen; ///< True indicates open file/stream
std::string m_filename; ///< Filename, for error messages
inline static size_t bufferSize() { return 256*1024; } // See below for slack calculation
inline static size_t bufferInsertSize() { return 16*1024; }
virtual void fill() = 0;
void header();
void trailer();
public:
// CREATORS
VerilatedDeserialize() { m_endp = NULL; }
virtual ~VerilatedDeserialize() { close(); }
VerilatedDeserialize() {
m_isOpen = false;
m_bufp = new vluint8_t [bufferSize()];
m_cp = m_bufp;
m_endp = NULL;
}
virtual ~VerilatedDeserialize() {
close();
if (m_bufp) { delete m_bufp; m_bufp=NULL; }
}
// METHODS
bool isOpen() const { return m_isOpen; }
std::string filename() const { return m_filename; }
virtual void close() { flush(); }
virtual void flush() {}
inline VerilatedDeserialize& read (void* __restrict datap, size_t size) {
vluint8_t* __restrict dp = (vluint8_t* __restrict)datap;
while (size) {
@@ -126,6 +133,8 @@ public:
bool readDiffers (const void* __restrict datap, size_t size);
VerilatedDeserialize& readAssert (const void* __restrict datap, size_t size);
VerilatedDeserialize& readAssert (vluint64_t data) { return readAssert(&data, sizeof(data)); }
private:
VerilatedDeserialize(const VerilatedDeserialize& ); ///< N/A, no copy constructor
VerilatedDeserialize& bufferCheck() {
// Flush the write buffer if there's not enough space left for new information
// We only call this once per vector, so we need enough slop for a very wide "b###" line
+5 -5
View File
@@ -16,8 +16,8 @@
/// \file
/// \brief Verilator: Common include for all Verilated SystemC files
///
/// This file is included automatically by Verilator at the top of
/// all SystemC files it generates.
/// This file is included automatically by Verilator at the top of
/// all SystemC files it generates.
///
/// Code available from: http://www.veripool.org/verilator
///
@@ -39,9 +39,9 @@
#define VL_SC_BV_DATAP(bv) (VlScBvExposer::sp_datap(bv))
class VlScBvExposer : public sc_bv_base {
public:
static vluint32_t* sp_datap(const sc_bv_base& base) {
return static_cast<const VlScBvExposer*>(&base)->sp_datatp(); }
vluint32_t* sp_datatp() const { return (vluint32_t*)(m_data); }
static const vluint32_t* sp_datap(const sc_bv_base& base) {
return static_cast<const VlScBvExposer*>(&base)->sp_datatp(); }
const vluint32_t* sp_datatp() const { return reinterpret_cast<vluint32_t*>(m_data); }
// Above reads this protected element in sc_bv_base:
// sc_digit* m_data; // data array
};
+1 -1
View File
@@ -71,7 +71,7 @@ public:
~VerilatedVar() {}
void* datap() const { return m_datap; }
VerilatedVarType vltype() const { return m_vltype; }
VerilatedVarFlags vldir() const { return (VerilatedVarFlags)((int)m_vlflags & VLVF_MASK_DIR); }
VerilatedVarFlags vldir() const { return static_cast<VerilatedVarFlags>(static_cast<int>(m_vlflags) & VLVF_MASK_DIR); }
vluint32_t entSize() const;
bool isPublicRW() const { return ((m_vlflags & VLVF_PUB_RW) != 0); }
const VerilatedRange& range() const { return m_range; }
+45 -17
View File
@@ -46,6 +46,34 @@
# define O_NONBLOCK 0
#endif
//=============================================================================
// VerilatedVcdImp
/// Base class to hold some static state
/// This is an internally used class
class VerilatedVcdSingleton {
private:
typedef std::vector<VerilatedVcd*> VcdVec;
struct Singleton {
VcdVec s_vcdVecp; ///< List of all created traces
};
static Singleton& singleton() { static Singleton s; return s; }
public:
static void pushVcd(VerilatedVcd* vcdp) {
singleton().s_vcdVecp.push_back(vcdp);
}
static void removeVcd(const VerilatedVcd* vcdp) {
VcdVec::iterator pos = find(singleton().s_vcdVecp.begin(), singleton().s_vcdVecp.end(), vcdp);
if (pos != singleton().s_vcdVecp.end()) { singleton().s_vcdVecp.erase(pos); }
}
static void flush_all() {
for (VcdVec::const_iterator it=singleton().s_vcdVecp.begin(); it!=singleton().s_vcdVecp.end(); ++it) {
VerilatedVcd* vcdp = *it;
vcdp->flush();
}
}
};
//=============================================================================
// VerilatedVcdCallInfo
/// Internal callback routines for each module being traced.
@@ -67,6 +95,7 @@ protected:
VerilatedVcdCallback_t changecb,
void* ut, vluint32_t code)
: m_initcb(icb), m_fullcb(fcb), m_changecb(changecb), m_userthis(ut), m_code(code) {};
~VerilatedVcdCallInfo() {}
};
//=============================================================================
@@ -116,7 +145,7 @@ void VerilatedVcd::open (const char* filename) {
// Set member variables
m_filename = filename;
singleton().s_vcdVecp.push_back(this);
VerilatedVcdSingleton::pushVcd(this);
// SPDIFF_OFF
// Set callback so an early exit will flush us
@@ -199,13 +228,13 @@ void VerilatedVcd::makeNameMap() {
// If no scope was specified, prefix everything with a "top"
// This comes from user instantiations with no name - IE Vtop("").
bool nullScope = false;
for (NameMap::iterator it=m_namemapp->begin(); it!=m_namemapp->end(); ++it) {
for (NameMap::const_iterator it=m_namemapp->begin(); it!=m_namemapp->end(); ++it) {
const std::string& hiername = it->first;
if (hiername.size() >= 1 && hiername[0] == '\t') nullScope=true;
}
if (nullScope) {
NameMap* newmapp = new NameMap;
for (NameMap::iterator it=m_namemapp->begin(); it!=m_namemapp->end(); ++it) {
for (NameMap::const_iterator it=m_namemapp->begin(); it!=m_namemapp->end(); ++it) {
const std::string& hiername = it->first;
const std::string& decl = it->second;
std::string newname = std::string("top");
@@ -228,9 +257,11 @@ VerilatedVcd::~VerilatedVcd() {
if (m_sigs_oldvalp) { delete[] m_sigs_oldvalp; m_sigs_oldvalp=NULL; }
deleteNameMap();
if (m_filep && m_fileNewed) { delete m_filep; m_filep = NULL; }
// Remove from list of traces
VcdVec::iterator pos = find(singleton().s_vcdVecp.begin(), singleton().s_vcdVecp.end(), this);
if (pos != singleton().s_vcdVecp.end()) { singleton().s_vcdVecp.erase(pos); }
for (CallbackVec::const_iterator it=m_callbacks.begin(); it!=m_callbacks.end(); ++it) {
delete (*it);
}
m_callbacks.clear();
VerilatedVcdSingleton::removeVcd(this);
}
void VerilatedVcd::closePrev () {
@@ -321,7 +352,7 @@ void VerilatedVcd::bufferFlush () {
} else if (got < 0) {
if (errno != EAGAIN && errno != EINTR) {
// write failed, presume error (perhaps out of disk space)
std::string msg = (std::string)"VerilatedVcd::bufferFlush: "+strerror(errno);
std::string msg = std::string("VerilatedVcd::bufferFlush: ")+strerror(errno);
vl_fatal("",0,"",msg.c_str());
closeErr();
break;
@@ -349,7 +380,7 @@ void VerilatedVcd::set_time_resolution (const char* unitp) {
double VerilatedVcd::timescaleToDouble (const char* unitp) {
char* endp;
double value = strtod(unitp, &endp);
if (!value) value=1; // On error so we allow just "ns" to return 1e-9.
if (value==0.0 && endp==unitp) value=1; // On error so we allow just "ns" to return 1e-9.
unitp=endp;
while (*unitp && isspace(*unitp)) unitp++;
switch (*unitp) {
@@ -411,7 +442,7 @@ void VerilatedVcd::dumpHeader () {
// Print the signal names
const char* lastName = "";
for (NameMap::iterator it=m_namemapp->begin(); it!=m_namemapp->end(); ++it) {
for (NameMap::const_iterator it=m_namemapp->begin(); it!=m_namemapp->end(); ++it) {
const std::string& hiernamestr = it->first;
const std::string& decl = it->second;
@@ -566,7 +597,7 @@ void VerilatedVcd::declDouble (vluint32_t code, const char* name, int arraynum
void VerilatedVcd::fullDouble (vluint32_t code, const double newval) {
// cppcheck-suppress invalidPointerCast
(*((double*)&m_sigs_oldvalp[code])) = newval;
(*(reinterpret_cast<double*>(&m_sigs_oldvalp[code]))) = newval;
// Buffer can't overflow before sprintf; we sized during declaration
sprintf(m_writep, "r%.16g", newval);
m_writep += strlen(m_writep);
@@ -575,9 +606,9 @@ void VerilatedVcd::fullDouble (vluint32_t code, const double newval) {
}
void VerilatedVcd::fullFloat (vluint32_t code, const float newval) {
// cppcheck-suppress invalidPointerCast
(*((float*)&m_sigs_oldvalp[code])) = newval;
(*(reinterpret_cast<float*>(&m_sigs_oldvalp[code]))) = newval;
// Buffer can't overflow before sprintf; we sized during declaration
sprintf(m_writep, "r%.16g", (double)newval);
sprintf(m_writep, "r%.16g", static_cast<double>(newval));
m_writep += strlen(m_writep);
*m_writep++=' '; printCode(code); *m_writep++='\n';
bufferCheck();
@@ -591,7 +622,7 @@ void VerilatedVcd::addCallback (
void* userthis)
{
if (VL_UNLIKELY(isOpen())) {
std::string msg = (std::string)"Internal: "+__FILE__+"::"+__FUNCTION__+" called with already open file";
std::string msg = std::string("Internal: ")+__FILE__+"::"+__FUNCTION__+" called with already open file";
vl_fatal(__FILE__,__LINE__,"",msg.c_str());
}
VerilatedVcdCallInfo* vci = new VerilatedVcdCallInfo(initcb, fullcb, changecb, userthis, nextCode());
@@ -642,10 +673,7 @@ void VerilatedVcd::dumpDone () {
// Static members
void VerilatedVcd::flush_all() {
for (vluint32_t ent = 0; ent< singleton().s_vcdVecp.size(); ent++) {
VerilatedVcd* vcdp = singleton().s_vcdVecp[ent];
vcdp->flush();
}
VerilatedVcdSingleton::flush_all();
}
//======================================================================
+27 -31
View File
@@ -96,18 +96,14 @@ private:
vluint64_t m_wrChunkSize; ///< Output buffer size
vluint64_t m_wroteBytes; ///< Number of bytes written to this file
vluint32_t* m_sigs_oldvalp; ///< Pointer to old signal values
std::vector<VerilatedVcdSig> m_sigs; ///< Pointer to signal information
std::vector<VerilatedVcdCallInfo*> m_callbacks; ///< Routines to perform dumping
typedef std::map<std::string,std::string> NameMap;
vluint32_t* m_sigs_oldvalp; ///< Pointer to old signal values
typedef std::vector<VerilatedVcdSig> SigVec;
SigVec m_sigs; ///< Pointer to signal information
typedef std::vector<VerilatedVcdCallInfo*> CallbackVec;
CallbackVec m_callbacks; ///< Routines to perform dumping
typedef std::map<std::string,std::string> NameMap;
NameMap* m_namemapp; ///< List of names for the header
typedef std::vector<VerilatedVcd*> VcdVec;
struct Singleton {
VcdVec s_vcdVecp; ///< List of all created traces
};
static Singleton& singleton() { static Singleton s; return s; }
void bufferResize(vluint64_t minsize);
void bufferFlush();
inline void bufferCheck() {
@@ -135,17 +131,17 @@ private:
// cppcheck-suppress functionConst
void dumpDone ();
inline void printCode (vluint32_t code) {
if (code>=(94*94*94)) *m_writep++ = ((char)((code/94/94/94)%94+33));
if (code>=(94*94)) *m_writep++ = ((char)((code/94/94)%94+33));
if (code>=(94)) *m_writep++ = ((char)((code/94)%94+33));
*m_writep++ = ((char)((code)%94+33));
if (code>=(94*94*94)) *m_writep++ = static_cast<char>((code/94/94/94)%94+33);
if (code>=(94*94)) *m_writep++ = static_cast<char>((code/94/94)%94+33);
if (code>=(94)) *m_writep++ = static_cast<char>((code/94)%94+33);
*m_writep++ = static_cast<char>((code)%94+33);
}
static std::string stringCode (vluint32_t code) {
std::string out;
if (code>=(94*94*94)) out += ((char)((code/94/94/94)%94+33));
if (code>=(94*94)) out += ((char)((code/94/94)%94+33));
if (code>=(94)) out += ((char)((code/94)%94+33));
return out + ((char)((code)%94+33));
if (code>=(94*94*94)) out += static_cast<char>((code/94/94/94)%94+33);
if (code>=(94*94)) out += static_cast<char>((code/94/94)%94+33);
if (code>=(94)) out += static_cast<char>((code/94)%94+33);
return out + static_cast<char>((code)%94+33);
}
VerilatedVcd(const VerilatedVcd& ); ///< N/A, no copy constructor
@@ -190,7 +186,7 @@ public:
/// Inside dumping routines, called each cycle to make the dump
void dump (vluint64_t timeui);
/// Call dump with a absolute unscaled time in seconds
void dumpSeconds (double secs) { dump((vluint64_t)(secs * m_timeRes)); }
void dumpSeconds (double secs) { dump(static_cast<vluint64_t>(secs * m_timeRes)); }
/// Inside dumping routines, declare callbacks for tracings
void addCallback (VerilatedVcdCallback_t init, VerilatedVcdCallback_t full,
@@ -216,7 +212,7 @@ public:
void fullBit (vluint32_t code, const vluint32_t newval) {
// Note the &1, so we don't require clean input -- makes more common no change case faster
m_sigs_oldvalp[code] = newval;
*m_writep++=('0'+(char)(newval&1)); printCode(code); *m_writep++='\n';
*m_writep++=('0'+static_cast<char>(newval&1)); printCode(code); *m_writep++='\n';
bufferCheck();
}
void fullBus (vluint32_t code, const vluint32_t newval, int bits) {
@@ -229,7 +225,7 @@ public:
bufferCheck();
}
void fullQuad (vluint32_t code, const vluint64_t newval, int bits) {
(*((vluint64_t*)&m_sigs_oldvalp[code])) = newval;
(*(reinterpret_cast<vluint64_t*>(&m_sigs_oldvalp[code]))) = newval;
*m_writep++='b';
for (int bit=bits-1; bit>=0; --bit) {
*m_writep++=((newval&(1ULL<<bit))?'1':'0');
@@ -268,8 +264,8 @@ public:
bufferCheck();
}
void fullTriQuad (vluint32_t code, const vluint64_t newval, const vluint32_t newtri, int bits) {
(*((vluint64_t*)&m_sigs_oldvalp[code])) = newval;
(*((vluint64_t*)&m_sigs_oldvalp[code+1])) = newtri;
(*(reinterpret_cast<vluint64_t*>(&m_sigs_oldvalp[code]))) = newval;
(*(reinterpret_cast<vluint64_t*>(&m_sigs_oldvalp[code+1]))) = newtri;
*m_writep++='b';
for (int bit=bits-1; bit>=0; --bit) {
*m_writep++ = "01zz"[((newval >> bit)&1ULL)
@@ -333,7 +329,7 @@ public:
}
}
inline void chgQuad (vluint32_t code, const vluint64_t newval, int bits) {
vluint64_t diff = (*((vluint64_t*)&m_sigs_oldvalp[code])) ^ newval;
vluint64_t diff = (*(reinterpret_cast<vluint64_t*>(&m_sigs_oldvalp[code]))) ^ newval;
if (VL_UNLIKELY(diff)) {
if (VL_UNLIKELY(bits==64 || (diff & ((1ULL<<bits)-1) ))) {
fullQuad(code, newval, bits);
@@ -368,8 +364,8 @@ public:
}
}
inline void chgTriQuad (vluint32_t code, const vluint64_t newval, const vluint32_t newtri, int bits) {
vluint64_t diff = ( ((*((vluint64_t*)&m_sigs_oldvalp[code])) ^ newval)
| ((*((vluint64_t*)&m_sigs_oldvalp[code+1])) ^ newtri));
vluint64_t diff = ( ((*(reinterpret_cast<vluint64_t*>(&m_sigs_oldvalp[code]))) ^ newval)
| ((*(reinterpret_cast<vluint64_t*>(&m_sigs_oldvalp[code+1]))) ^ newtri));
if (VL_UNLIKELY(diff)) {
if (VL_UNLIKELY(bits==64 || (diff & ((1ULL<<bits)-1) ))) {
fullTriQuad(code, newval, newtri, bits);
@@ -387,13 +383,13 @@ public:
}
inline void chgDouble (vluint32_t code, const double newval) {
// cppcheck-suppress invalidPointerCast
if (VL_UNLIKELY((*((double*)&m_sigs_oldvalp[code])) != newval)) {
if (VL_UNLIKELY((*(reinterpret_cast<double*>(&m_sigs_oldvalp[code]))) != newval)) {
fullDouble (code, newval);
}
}
inline void chgFloat (vluint32_t code, const float newval) {
// cppcheck-suppress invalidPointerCast
if (VL_UNLIKELY((*((float*)&m_sigs_oldvalp[code])) != newval)) {
if (VL_UNLIKELY((*(reinterpret_cast<float*>(&m_sigs_oldvalp[code]))) != newval)) {
fullFloat (code, newval);
}
}
@@ -431,9 +427,9 @@ public:
void dump (vluint64_t timeui) { m_sptrace.dump(timeui); }
/// Write one cycle of dump data - backward compatible and to reduce
/// conversion warnings. It's better to use a vluint64_t time instead.
void dump (double timestamp) { dump((vluint64_t)timestamp); }
void dump (vluint32_t timestamp) { dump((vluint64_t)timestamp); }
void dump (int timestamp) { dump((vluint64_t)timestamp); }
void dump (double timestamp) { dump(static_cast<vluint64_t>(timestamp)); }
void dump (vluint32_t timestamp) { dump(static_cast<vluint64_t>(timestamp)); }
void dump (int timestamp) { dump(static_cast<vluint64_t>(timestamp)); }
/// Set time units (s/ms, defaults to ns)
/// See also VL_TIME_PRECISION, and VL_TIME_MULTIPLIER in verilated.h
void set_time_unit (const char* unit) { m_sptrace.set_time_unit(unit); }
+48 -44
View File
@@ -52,7 +52,7 @@ VerilatedVpiError* VerilatedVpi::error_info() {
// VerilatedVpiError Methods
const char* VerilatedVpiError::strFromVpiVal(PLI_INT32 vpiVal) {
static const char *names[] = {
static const char* const names[] = {
"*undefined*",
"vpiBinStrVal",
"vpiOctStrVal",
@@ -77,7 +77,7 @@ const char* VerilatedVpiError::strFromVpiVal(PLI_INT32 vpiVal) {
return names[(vpiVal<=vpiRawFourStateVal)?vpiVal:0];
}
const char* VerilatedVpiError::strFromVpiObjType(PLI_INT32 vpiVal) {
static const char *names[] = {
static const char* const names[] = {
"*undefined*",
"vpiAlways",
"vpiAssignStmt",
@@ -219,7 +219,7 @@ const char* VerilatedVpiError::strFromVpiObjType(PLI_INT32 vpiVal) {
return names[(vpiVal<=vpiGenVar)?vpiVal:0];
}
const char* VerilatedVpiError::strFromVpiMethod(PLI_INT32 vpiVal) {
static const char *names[] = {
static const char* const names[] = {
"vpiCondition",
"vpiDelay",
"vpiElseStmt",
@@ -262,7 +262,7 @@ const char* VerilatedVpiError::strFromVpiMethod(PLI_INT32 vpiVal) {
}
const char* VerilatedVpiError::strFromVpiCallbackReason(PLI_INT32 vpiVal) {
static const char *names[] = {
static const char* const names[] = {
"*undefined*",
"cbValueChange",
"cbStmt",
@@ -301,7 +301,7 @@ const char* VerilatedVpiError::strFromVpiCallbackReason(PLI_INT32 vpiVal) {
}
const char* VerilatedVpiError::strFromVpiProp(PLI_INT32 vpiVal) {
static const char *names[] = {
static const char* const names[] = {
"*undefined or other*",
"vpiType",
"vpiName",
@@ -721,9 +721,9 @@ void vpi_put_delays(vpiHandle object, p_vpi_delay delay_p) {
// value processing
void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
static VL_THREAD char outStr[1+VL_MULS_MAX_WORDS*32]; // Maximum required size is for binary string, one byte per bit plus null termination
static VL_THREAD_LOCAL char outStr[1+VL_MULS_MAX_WORDS*32]; // Maximum required size is for binary string, one byte per bit plus null termination
// cppcheck-suppress variableScope
static VL_THREAD int outStrSz = sizeof(outStr)-1;
static VL_THREAD_LOCAL int outStrSz = sizeof(outStr)-1;
VL_DEBUG_IF_PLI(VL_PRINTF("-vltVpi: vpi_get_value %p\n",object););
_VL_VPI_ERROR_RESET(); // reset vpi error status
if (VL_UNLIKELY(!value_p)) return;
@@ -733,19 +733,19 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
if (value_p->format == vpiVectorVal) {
// Vector pointer must come from our memory pool
// It only needs to persist until the next vpi_get_value
static VL_THREAD t_vpi_vecval out[VL_MULS_MAX_WORDS*2];
static VL_THREAD_LOCAL t_vpi_vecval out[VL_MULS_MAX_WORDS*2];
value_p->value.vector = out;
switch (vop->varp()->vltype()) {
case VLVT_UINT8:
out[0].aval = *((CData*)(vop->varDatap()));
out[0].aval = *(reinterpret_cast<CData*>(vop->varDatap()));
out[0].bval = 0;
return;
case VLVT_UINT16:
out[0].aval = *((SData*)(vop->varDatap()));
out[0].aval = *(reinterpret_cast<SData*>(vop->varDatap()));
out[0].bval = 0;
return;
case VLVT_UINT32:
out[0].aval = *((IData*)(vop->varDatap()));
out[0].aval = *(reinterpret_cast<IData*>(vop->varDatap()));
out[0].bval = 0;
return;
case VLVT_WDATA: {
@@ -753,7 +753,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
if (VL_UNLIKELY(words >= VL_MULS_MAX_WORDS)) {
vl_fatal(__FILE__,__LINE__,"", "vpi_get_value with more than VL_MULS_MAX_WORDS; increase and recompile");
}
WDataInP datap = ((IData*)(vop->varDatap()));
WDataInP datap = (reinterpret_cast<IData*>(vop->varDatap()));
for (int i=0; i<words; ++i) {
out[i].aval = datap[i];
out[i].bval = 0;
@@ -761,10 +761,10 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
return;
}
case VLVT_UINT64: {
QData data = *((QData*)(vop->varDatap()));
out[1].aval = (IData)(data>>VL_ULL(32));
QData data = *(reinterpret_cast<QData*>(vop->varDatap()));
out[1].aval = static_cast<IData>(data>>VL_ULL(32));
out[1].bval = 0;
out[0].aval = (IData)(data);
out[0].aval = static_cast<IData>(data);
out[0].bval = 0;
return;
}
@@ -783,7 +783,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
case VLVT_UINT64:
case VLVT_WDATA: {
int bits = vop->varp()->range().elements();
CData* datap = ((CData*)(vop->varDatap()));
CData* datap = (reinterpret_cast<CData*>(vop->varDatap()));
int i;
if (bits > outStrSz) {
// limit maximum size of output to size of buffer to prevent overrun.
@@ -813,7 +813,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
case VLVT_WDATA: {
int chars = (vop->varp()->range().elements()+2)/3;
int bytes = VL_BYTES_I(vop->varp()->range().elements());
CData* datap = ((CData*)(vop->varDatap()));
CData* datap = (reinterpret_cast<CData*>(vop->varDatap()));
int i;
if (chars > outStrSz) {
// limit maximum size of output to size of buffer to prevent overrun.
@@ -855,10 +855,14 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
value_p->value.str = outStr;
switch (vop->varp()->vltype()) {
// outStrSz does not include NULL termination so add one
case VLVT_UINT8 : VL_SNPRINTF(outStr, outStrSz+1, "%hhu", (unsigned char )*((CData*)(vop->varDatap()))); return;
case VLVT_UINT16: VL_SNPRINTF(outStr, outStrSz+1, "%hu", (unsigned short)*((SData*)(vop->varDatap()))); return;
case VLVT_UINT32: VL_SNPRINTF(outStr, outStrSz+1, "%u", (unsigned int )*((IData*)(vop->varDatap()))); return;
case VLVT_UINT64: VL_SNPRINTF(outStr, outStrSz+1, "%llu", (unsigned long long)*((QData*)(vop->varDatap()))); return;
case VLVT_UINT8 : VL_SNPRINTF(outStr, outStrSz+1, "%hhu",
static_cast<unsigned char>(*(reinterpret_cast<CData*>(vop->varDatap())))); return;
case VLVT_UINT16: VL_SNPRINTF(outStr, outStrSz+1, "%hu",
static_cast<unsigned short>(*(reinterpret_cast<SData*>(vop->varDatap())))); return;
case VLVT_UINT32: VL_SNPRINTF(outStr, outStrSz+1, "%u",
static_cast<unsigned int>(*(reinterpret_cast<IData*>(vop->varDatap())))); return;
case VLVT_UINT64: VL_SNPRINTF(outStr, outStrSz+1, "%llu",
static_cast<unsigned long long>(*(reinterpret_cast<QData*>(vop->varDatap())))); return;
default:
strcpy(outStr, "-1");
_VL_VPI_ERROR(__FILE__, __LINE__, "%s: Unsupported format (%s) for %s, maximum limit is 64 bits",
@@ -874,7 +878,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
case VLVT_UINT64:
case VLVT_WDATA: {
int chars = (vop->varp()->range().elements()+3)>>2;
CData* datap = ((CData*)(vop->varDatap()));
CData* datap = (reinterpret_cast<CData*>(vop->varDatap()));
int i;
if (chars > outStrSz) {
// limit maximum size of output to size of buffer to prevent overrun.
@@ -884,7 +888,6 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
}
for (i=0; i<chars; ++i) {
char val = (datap[i>>1]>>((i&1)<<2))&15;
static char hex[] = "0123456789abcdef";
if (i==(chars-1)) {
// most signifcant char, mask off non existant bits when vector
// size is not a multiple of 4
@@ -894,7 +897,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
val &= (1<<rem)-1;
}
}
outStr[chars-i-1] = hex[static_cast<int>(val)];
outStr[chars-i-1] = "0123456789abcdef"[static_cast<int>(val)];
}
outStr[i]=0; // NULL terminate
return;
@@ -913,7 +916,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
case VLVT_UINT64:
case VLVT_WDATA: {
int bytes = VL_BYTES_I(vop->varp()->range().elements());
CData* datap = ((CData*)(vop->varDatap()));
CData* datap = (reinterpret_cast<CData*>(vop->varDatap()));
int i;
if (bytes > outStrSz) {
// limit maximum size of output to size of buffer to prevent overrun.
@@ -938,13 +941,13 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
} else if (value_p->format == vpiIntVal) {
switch (vop->varp()->vltype()) {
case VLVT_UINT8:
value_p->value.integer = *((CData*)(vop->varDatap()));
value_p->value.integer = *(reinterpret_cast<CData*>(vop->varDatap()));
return;
case VLVT_UINT16:
value_p->value.integer = *((SData*)(vop->varDatap()));
value_p->value.integer = *(reinterpret_cast<SData*>(vop->varDatap()));
return;
case VLVT_UINT32:
value_p->value.integer = *((IData*)(vop->varDatap()));
value_p->value.integer = *(reinterpret_cast<IData*>(vop->varDatap()));
return;
case VLVT_WDATA: // FALLTHRU
case VLVT_UINT64: // FALLTHRU
@@ -995,17 +998,17 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p,
if (VL_UNLIKELY(!value_p->value.vector)) return NULL;
switch (vop->varp()->vltype()) {
case VLVT_UINT8:
*((CData*)(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask();
*(reinterpret_cast<CData*>(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask();
return object;
case VLVT_UINT16:
*((SData*)(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask();
*(reinterpret_cast<SData*>(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask();
return object;
case VLVT_UINT32:
*((IData*)(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask();
*(reinterpret_cast<IData*>(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask();
return object;
case VLVT_WDATA: {
int words = VL_WORDS_I(vop->varp()->range().elements());
WDataOutP datap = ((IData*)(vop->varDatap()));
WDataOutP datap = (reinterpret_cast<IData*>(vop->varDatap()));
for (int i=0; i<words; ++i) {
datap[i] = value_p->value.vector[i].aval;
if (i==(words-1)) {
@@ -1015,7 +1018,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p,
return object;
}
case VLVT_UINT64: {
*((QData*)(vop->varDatap())) = _VL_SET_QII(
*(reinterpret_cast<QData*>(vop->varDatap())) = _VL_SET_QII(
value_p->value.vector[1].aval & vop->mask(),
value_p->value.vector[0].aval);
return object;
@@ -1035,7 +1038,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p,
case VLVT_WDATA: {
int bits = vop->varp()->range().elements();
int len = strlen(value_p->value.str);
CData* datap = ((CData*)(vop->varDatap()));
CData* datap = (reinterpret_cast<CData*>(vop->varDatap()));
for (int i=0; i<bits; ++i) {
char set = (i < len)?(value_p->value.str[len-i-1]=='1'):0;
// zero bits 7:1 of byte when assigning to bit 0, else
@@ -1063,7 +1066,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p,
int chars = (vop->varp()->range().elements()+2)/3;
int bytes = VL_BYTES_I(vop->varp()->range().elements());
int len = strlen(value_p->value.str);
CData* datap = ((CData*)(vop->varDatap()));
CData* datap = (reinterpret_cast<CData*>(vop->varDatap()));
div_t idx;
datap[0] = 0; // reset zero'th byte
for (int i=0; i<chars; ++i) {
@@ -1128,10 +1131,11 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p,
VL_FUNC, remainder, value_p->value.str, VerilatedVpiError::strFromVpiVal(value_p->format), vop->fullname());
}
switch (vop->varp()->vltype()) {
case VLVT_UINT8 : *((CData*)(vop->varDatap())) = val & vop->mask(); break;
case VLVT_UINT16: *((SData*)(vop->varDatap())) = val & vop->mask(); break;
case VLVT_UINT32: *((IData*)(vop->varDatap())) = val & vop->mask(); break;
case VLVT_UINT64: *((QData*)(vop->varDatap())) = val; ((IData*)(vop->varDatap()))[1] &= vop->mask(); break;
case VLVT_UINT8 : *(reinterpret_cast<CData*>(vop->varDatap())) = val & vop->mask(); break;
case VLVT_UINT16: *(reinterpret_cast<SData*>(vop->varDatap())) = val & vop->mask(); break;
case VLVT_UINT32: *(reinterpret_cast<IData*>(vop->varDatap())) = val & vop->mask(); break;
case VLVT_UINT64: *(reinterpret_cast<QData*>(vop->varDatap())) = val;
(reinterpret_cast<IData*>(vop->varDatap()))[1] &= vop->mask(); break;
case VLVT_WDATA:
default:
_VL_VPI_ERROR(__FILE__, __LINE__, "%s: Unsupported format (%s) for %s, maximum limit is 64 bits",
@@ -1147,7 +1151,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p,
case VLVT_UINT64:
case VLVT_WDATA: {
int chars = (vop->varp()->range().elements()+3)>>2;
CData* datap = ((CData*)(vop->varDatap()));
CData* datap = (reinterpret_cast<CData*>(vop->varDatap()));
char* val = value_p->value.str;
// skip hex ident if one is detected at the start of the string
if (val[0] == '0' && (val[1] == 'x' || val[1] == 'X')) {
@@ -1195,7 +1199,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p,
case VLVT_WDATA: {
int bytes = VL_BYTES_I(vop->varp()->range().elements());
int len = strlen(value_p->value.str);
CData* datap = ((CData*)(vop->varDatap()));
CData* datap = (reinterpret_cast<CData*>(vop->varDatap()));
for (int i=0; i<bytes; ++i) {
datap[i] = (i < len)?value_p->value.str[len-i-1]:0; // prepend with 0 values before placing string the least signifcant bytes
}
@@ -1209,13 +1213,13 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p,
} else if (value_p->format == vpiIntVal) {
switch (vop->varp()->vltype()) {
case VLVT_UINT8:
*((CData*)(vop->varDatap())) = vop->mask() & value_p->value.integer;
*(reinterpret_cast<CData*>(vop->varDatap())) = vop->mask() & value_p->value.integer;
return object;
case VLVT_UINT16:
*((SData*)(vop->varDatap())) = vop->mask() & value_p->value.integer;
*(reinterpret_cast<SData*>(vop->varDatap())) = vop->mask() & value_p->value.integer;
return object;
case VLVT_UINT32:
*((IData*)(vop->varDatap())) = vop->mask() & value_p->value.integer;
*(reinterpret_cast<IData*>(vop->varDatap())) = vop->mask() & value_p->value.integer;
return object;
case VLVT_WDATA: // FALLTHRU
case VLVT_UINT64: // FALLTHRU
+28 -26
View File
@@ -83,7 +83,7 @@ public:
return newp+8;
} else {
// +8: 8 bytes for next
vluint8_t* newp = (vluint8_t*)(::operator new(chunk+8));
vluint8_t* newp = reinterpret_cast<vluint8_t*>(::operator new(chunk+8));
return newp+8;
}
}
@@ -94,12 +94,12 @@ public:
}
// MEMBERS
static inline VerilatedVpio* castp(vpiHandle h) { return dynamic_cast<VerilatedVpio*>((VerilatedVpio*)h); }
inline vpiHandle castVpiHandle() { return (vpiHandle)(this); }
inline vpiHandle castVpiHandle() { return reinterpret_cast<vpiHandle>(this); }
// ACCESSORS
virtual const char* name() { return "<null>"; }
virtual const char* fullname() { return "<null>"; }
virtual const char* defname() { return "<null>"; }
virtual vluint32_t type() { return 0; }
virtual const char* name() const { return "<null>"; }
virtual const char* fullname() const { return "<null>"; }
virtual const char* defname() const { return "<null>"; }
virtual vluint32_t type() const { return 0; }
virtual vluint32_t size() const { return 0; }
virtual const VerilatedRange* rangep() const { return NULL; }
virtual vpiHandle dovpi_scan() { return 0; }
@@ -120,7 +120,7 @@ public:
}
virtual ~VerilatedVpioCb() {}
static inline VerilatedVpioCb* castp(vpiHandle h) { return dynamic_cast<VerilatedVpioCb*>((VerilatedVpio*)h); }
virtual vluint32_t type() { return vpiCallback; }
virtual vluint32_t type() const { return vpiCallback; }
vluint32_t reason() const { return m_cbData.reason; }
VerilatedPliCb cb_rtnp() const { return m_cbData.cb_rtn; }
t_cb_data* cb_datap() { return &(m_cbData); }
@@ -133,7 +133,7 @@ public:
explicit VerilatedVpioConst(vlsint32_t num) : m_num(num) {}
virtual ~VerilatedVpioConst() {}
static inline VerilatedVpioConst* castp(vpiHandle h) { return dynamic_cast<VerilatedVpioConst*>((VerilatedVpio*)h); }
virtual vluint32_t type() { return vpiUndefined; }
virtual vluint32_t type() const { return vpiUndefined; }
vlsint32_t num() const { return m_num; }
};
@@ -144,7 +144,7 @@ public:
explicit VerilatedVpioRange(const VerilatedRange* range) : m_range(range), m_iteration(0) {}
virtual ~VerilatedVpioRange() {}
static inline VerilatedVpioRange* castp(vpiHandle h) { return dynamic_cast<VerilatedVpioRange*>((VerilatedVpio*)h); }
virtual vluint32_t type() { return vpiRange; }
virtual vluint32_t type() const { return vpiRange; }
virtual vluint32_t size() const { return m_range->elements(); }
virtual const VerilatedRange* rangep() const { return m_range; }
int iteration() const { return m_iteration; }
@@ -167,10 +167,10 @@ public:
: m_scopep(scopep) {}
virtual ~VerilatedVpioScope() {}
static inline VerilatedVpioScope* castp(vpiHandle h) { return dynamic_cast<VerilatedVpioScope*>((VerilatedVpio*)h); }
virtual vluint32_t type() { return vpiScope; }
virtual vluint32_t type() const { return vpiScope; }
const VerilatedScope* scopep() const { return m_scopep; }
virtual const char* name() { return m_scopep->name(); }
virtual const char* fullname() { return m_scopep->name(); }
virtual const char* name() const { return m_scopep->name(); }
virtual const char* fullname() const { return m_scopep->name(); }
};
class VerilatedVpioVar : public VerilatedVpio {
@@ -207,15 +207,15 @@ public:
vluint8_t mask_byte(int idx) { return m_mask.u8[idx & 3]; }
vluint32_t entSize() const { return m_entSize; }
vluint32_t index() { return m_index; }
virtual vluint32_t type() {
virtual vluint32_t type() const {
if (varp()->vldir() != vpiNoDirection) return vpiPort;
return (varp()->dims()>1) ? vpiMemory : vpiReg; /* but might be wire, logic */
}
virtual vluint32_t size() const { return get_range().elements(); }
virtual const VerilatedRange* rangep() const { return &get_range(); }
virtual const char* name() { return m_varp->name(); }
virtual const char* fullname() {
VL_STATIC_OR_THREAD std::string out;
virtual const char* name() const { return m_varp->name(); }
virtual const char* fullname() const {
static VL_THREAD_LOCAL std::string out;
out = std::string(m_scopep->name())+"."+name();
return out.c_str();
}
@@ -239,11 +239,11 @@ public:
}
virtual ~VerilatedVpioMemoryWord() {}
static inline VerilatedVpioMemoryWord* castp(vpiHandle h) { return dynamic_cast<VerilatedVpioMemoryWord*>((VerilatedVpio*)h); }
virtual vluint32_t type() { return vpiMemoryWord; }
virtual vluint32_t type() const { return vpiMemoryWord; }
virtual vluint32_t size() const { return varp()->range().elements(); }
virtual const VerilatedRange* rangep() const { return &(varp()->range()); }
virtual const char* fullname() {
VL_STATIC_OR_THREAD std::string out;
virtual const char* fullname() const {
static VL_THREAD_LOCAL std::string out;
char num[20]; sprintf(num,"%d",m_index);
out = std::string(scopep()->name())+"."+name()+"["+num+"]";
return out.c_str();
@@ -252,14 +252,14 @@ public:
class VerilatedVpioVarIter : public VerilatedVpio {
const VerilatedScope* m_scopep;
VerilatedVarNameMap::iterator m_it;
VerilatedVarNameMap::const_iterator m_it;
bool m_started;
public:
explicit VerilatedVpioVarIter(const VerilatedScope* scopep)
: m_scopep(scopep), m_started(false) { }
virtual ~VerilatedVpioVarIter() {}
static inline VerilatedVpioVarIter* castp(vpiHandle h) { return dynamic_cast<VerilatedVpioVarIter*>((VerilatedVpio*)h); }
virtual vluint32_t type() { return vpiIterator; }
virtual vluint32_t type() const { return vpiIterator; }
virtual vpiHandle dovpi_scan() {
if (VL_LIKELY(m_scopep->varsp())) {
VerilatedVarNameMap* varsp = m_scopep->varsp();
@@ -286,8 +286,10 @@ public:
: m_handle(handle), m_varp(varp), m_iteration(varp->array().right()), m_direction(VL_LIKELY(varp->array().left()>varp->array().right())?1:-1), m_done(false) { }
virtual ~VerilatedVpioMemoryWordIter() {}
static inline VerilatedVpioMemoryWordIter* castp(vpiHandle h) { return dynamic_cast<VerilatedVpioMemoryWordIter*>((VerilatedVpio*)h); }
virtual vluint32_t type() { return vpiIterator; }
void iterationInc() { if (!(m_done = (m_iteration == m_varp->array().left()))) m_iteration+=m_direction; }
virtual vluint32_t type() const { return vpiIterator; }
void iterationInc() {
if (!(m_done = (m_iteration == m_varp->array().left()))) m_iteration+=m_direction;
}
virtual vpiHandle dovpi_scan() {
vpiHandle result;
if (m_done) return 0;
@@ -368,7 +370,7 @@ public:
}
}
static QData cbNextDeadline() {
VpioTimedCbs::iterator it=s_s.m_timedCbs.begin();
VpioTimedCbs::const_iterator it=s_s.m_timedCbs.begin();
if (VL_LIKELY(it!=s_s.m_timedCbs.end())) {
return it->first;
} else {
@@ -412,7 +414,7 @@ public:
}
}
}
for (VpioVarSet::iterator it=update.begin(); it!=update.end(); ++it) {
for (VpioVarSet::const_iterator it=update.begin(); it!=update.end(); ++it) {
memcpy((*it)->prevDatap(), (*it)->varDatap(), (*it)->entSize());
}
}
@@ -464,7 +466,7 @@ public:
return this;
}
void setMessage(std::string file, PLI_INT32 line, std::string message, ...) {
static VL_THREAD std::string filehold;
static VL_THREAD_LOCAL std::string filehold;
_VL_VPI_ERROR_SET;
m_errorInfo.state = vpiPLI;
filehold = file;
+15 -9
View File
@@ -77,17 +77,18 @@
#ifdef VL_THREADED
# ifdef __GNUC__
# define VL_THREAD __thread ///< Storage class for thread-local storage
# if (__cplusplus < 201103L) && !defined(VL_THREADED_NO_C11_WARNING)
# error "VL_THREADED support plans to move to C++-11 and later only; use newer --std to be ready"
# endif
# else
# error "Unsupported compiler for VL_THREADED: No thread-local declarator"
# endif
# define VL_STATIC_OR_THREAD ///< Static if unthreaded, as some strings can be faster
// ///< if non-dynamic and can't do "static VL_THREAD string"
# define VL_THREAD_LOCAL thread_local ///< Use new C++ static local thread
#else
# define VL_THREAD ///< Storage class for thread-local storage
# define VL_STATIC_OR_THREAD static ///< Static if unthreaded, as some strings can be faster
// ///< if non-dynamic and can't do "static VL_THREAD string"
# define VL_THREAD_LOCAL ///< Use new C++ static local thread
#endif
#define VL_THREAD ///< Deprecated
#define VL_STATIC_OR_THREAD static ///< Deprecated
#ifdef _MSC_VER
# define VL_ULL(c) (c##ui64) ///< Add appropriate suffix to 64-bit constant
@@ -96,7 +97,7 @@
#endif
// This is not necessarily the same as #UL, depending on what the IData typedef is.
#define VL_UL(c) ((IData)(c##UL)) ///< Add appropriate suffix to 32-bit constant
#define VL_UL(c) (static_cast<IData>(c##UL)) ///< Add appropriate suffix to 32-bit constant
#if defined(VL_CPPCHECK) || defined(__clang_analyzer__)
# define VL_DANGLING(v)
@@ -109,9 +110,14 @@
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
# define VL_HAS_UNIQUE_PTR
# define VL_UNIQUE_PTR unique_ptr
# define VL_HAS_UNORDERED_MAP
# define VL_UNIQUE_PTR std::unique_ptr
# define VL_UNORDERED_MAP std::unordered_map
# define VL_INCLUDE_UNORDERED_MAP <unordered_map>
#else
# define VL_UNIQUE_PTR auto_ptr
# define VL_UNIQUE_PTR std::auto_ptr
# define VL_UNORDERED_MAP std::map
# define VL_INCLUDE_UNORDERED_MAP <map>
#endif
//=========================================================================
+2
View File
@@ -105,10 +105,12 @@ typedef unsigned char PLI_UBYTE8;
/* object is defined imported by the application */
#undef XXTERN
#define XXTERN PLI_EXTERN PLI_DLLISPEC
/* object is exported by the application */
#undef EETERN
#define EETERN PLI_EXTERN PLI_DLLESPEC
#endif
+8 -8
View File
@@ -237,10 +237,10 @@ implementation is not found, the system will look in turn for overloaded
implementations up the inheritance hierarchy. For example calling C<accept>
on C<AstIf> will look in turn for:
void visit (AstIf* nodep, AstNUser* vup)
void visit (AstNodeIf* nodep, AstNUser* vup)
void visit (AstNodeStmt* nodep, AstNUser* vup)
void visit (AstNode* nodep, AstNUser* vup)
void visit (AstIf* nodep)
void visit (AstNodeIf* nodep)
void visit (AstNodeStmt* nodep)
void visit (AstNode* nodep)
There are three ways data is passed between visitor functions.
@@ -485,10 +485,10 @@ be warning free.
=item --enable-longtests
In addition to the standard C, SystemC tests also run the tests in the
C<test_verilated> and C<test_regress> directories when using I<make test>.
This is disabled by default as SystemC installation problems would
otherwise falsely indicate a Verilator problem.
In addition to the standard C, SystemC examples, also run the tests in the
C<test_regress> directory when using I<make test>. This is disabled by
default as SystemC installation problems would otherwise falsely indicate a
Verilator problem.
=back
+7 -7
View File
@@ -48,25 +48,25 @@ obj_dbg:
.SUFFIXES:
.PHONY: ../verilator_bin ../verilator_bin_dbg ../verilator_coverage_bin_dbg
.PHONY: ../bin/verilator_bin ../bin/verilator_bin_dbg ../bin/verilator_coverage_bin_dbg
opt: ../verilator_bin
opt: ../bin/verilator_bin
ifeq ($(VERILATOR_NO_OPT_BUILD),1) # Faster laptop development... One build
../verilator_bin: ../verilator_bin_dbg
../bin/verilator_bin: ../bin/verilator_bin_dbg
-rm -rf $@ $@.exe
-cp -p $<$(EXEEXT) $@$(EXEEXT)
else
../verilator_bin: obj_opt prefiles
../bin/verilator_bin: obj_opt prefiles
cd obj_opt && $(MAKE) -j 1 TGT=../$@ -f ../Makefile_obj serial
cd obj_opt && $(MAKE) TGT=../$@ -f ../Makefile_obj
endif
dbg: ../verilator_bin_dbg ../verilator_coverage_bin_dbg
../verilator_bin_dbg: obj_dbg prefiles
dbg: ../bin/verilator_bin_dbg ../bin/verilator_coverage_bin_dbg
../bin/verilator_bin_dbg: obj_dbg prefiles
cd obj_dbg && $(MAKE) -j 1 TGT=../$@ VL_DEBUG=1 -f ../Makefile_obj serial
cd obj_dbg && $(MAKE) TGT=../$@ VL_DEBUG=1 -f ../Makefile_obj
../verilator_coverage_bin_dbg: obj_dbg prefiles
../bin/verilator_coverage_bin_dbg: obj_dbg prefiles
cd obj_dbg && $(MAKE) TGT=../$@ VL_DEBUG=1 VL_VLCOV=1 -f ../Makefile_obj serial_vlcov
cd obj_dbg && $(MAKE) TGT=../$@ VL_DEBUG=1 VL_VLCOV=1 -f ../Makefile_obj
+1 -1
View File
@@ -979,7 +979,7 @@ void AstNode::dumpTreeGdb() { // For GDB only
dumpTree(cout);
}
void AstNode::dumpTreeFileGdb(const char* filenamep) { // For GDB only
string filename = filenamep ? filenamep : v3Global.debugFilename("debug",98);
string filename = filenamep ? filenamep : v3Global.debugFilename("debug.tree",98);
v3Global.rootp()->dumpTreeFile(filename);
}
+17 -13
View File
@@ -82,7 +82,7 @@ public:
};
enum en m_e;
const char* ascii() const {
static const char* names[] = {
static const char* const names[] = {
"UNSIGNED","SIGNED","NOSIGN"
};
return names[m_e];
@@ -203,14 +203,14 @@ public:
return AstEdgeType::ET_ILLEGAL;
}
const char* ascii() const {
static const char* names[] = {
static const char* const names[] = {
"%E-edge", "ANY", "BOTH", "POS", "NEG", "HIGH", "LOW",
"COMBO","INITIAL","SETTLE","NEVER"
};
return names[m_e];
};
const char* verilogKwd() const {
static const char* names[] = {
static const char* const names[] = {
"%E-edge", "[any]", "edge", "posedge", "negedge", "[high]","[low]",
"*","[initial]","[settle]","[never]"
};
@@ -270,7 +270,7 @@ public:
};
enum en m_e;
const char* ascii() const {
static const char* names[] = {
static const char* const names[] = {
"%E-AT",
"DIM_BITS", "DIM_DIMENSIONS", "DIM_HIGH", "DIM_INCREMENT", "DIM_LEFT",
"DIM_LOW", "DIM_RIGHT", "DIM_SIZE", "DIM_UNPK_DIMENSIONS",
@@ -315,7 +315,7 @@ public:
};
enum en m_e;
const char* ascii() const {
static const char* names[] = {
static const char* const names[] = {
"%E-unk",
"bit", "byte", "chandle", "int", "integer", "logic", "longint",
"real", "shortint", "shortreal", "time",
@@ -328,7 +328,7 @@ public:
return names[m_e];
};
const char* dpiType() const {
static const char* names[] = {
static const char* const names[] = {
"%E-unk",
"unsigned char", "char", "void*", "int", "int", "svLogic", "long long",
"double", "short int", "float", "long long",
@@ -446,7 +446,7 @@ public:
explicit inline AstVarType (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
const char* ascii() const {
static const char* names[] = {
static const char* const names[] = {
"?","GPARAM","LPARAM","GENVAR",
"VAR","INPUT","OUTPUT","INOUT",
"SUPPLY0","SUPPLY1","WIRE","WREAL","IMPLICITWIRE",
@@ -489,7 +489,7 @@ public:
else return m_e;
}
const char* ascii() const {
static const char* names[] = {
static const char* const names[] = {
"","VL_LIKELY","VL_UNLIKELY"};
return names[m_e]; }
};
@@ -522,7 +522,7 @@ public:
else return m_e;
}
const char* ascii() const {
static const char* names[] = {
static const char* const names[] = {
"","clker","non_clker"};
return names[m_e]; }
};
@@ -548,7 +548,7 @@ public:
explicit inline VAlwaysKwd (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
const char* ascii() const {
static const char* names[] = {
static const char* const names[] = {
"always","always_ff","always_latch","always_comb"};
return names[m_e]; }
};
@@ -598,7 +598,7 @@ public:
bool addNewline() const { return m_e!=DT_WRITE; }
bool needScopeTracking() const { return m_e!=DT_DISPLAY && m_e!=DT_WRITE; }
const char* ascii() const {
static const char* names[] = {
static const char* const names[] = {
"display","write","info","error","warning","fatal"};
return names[m_e]; }
};
@@ -621,7 +621,7 @@ public:
explicit inline AstParseRefExp (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
const char* ascii() const {
static const char* names[] = {
static const char* const names[] = {
"","TEXT","PREDOT"};
return names[m_e]; }
};
@@ -734,6 +734,7 @@ class VNUser {
public:
VNUser() {}
// non-explicit:
// cppcheck-suppress noExplicitConstructor
VNUser(int i) { m_u.up = 0; m_u.ui = i; }
explicit VNUser(void* p) { m_u.up = p; }
~VNUser() {}
@@ -1087,6 +1088,8 @@ public:
// ACCESSORS
virtual string name() const { return ""; }
virtual void name(const string& name) { this->v3fatalSrc("name() called on object without name() method"); }
virtual void tag(const string& text) {}
virtual string tag() const { return ""; }
virtual string verilogKwd() const { return ""; }
string shortName() const; // Name with __PVT__ removed for concatenating scopes
static string dedotName(const string& namein); // Name with dots removed
@@ -1258,7 +1261,7 @@ public:
// METHODS - Iterate on a tree
AstNode* cloneTree(bool cloneNextLink);
bool gateTree() { return gateTreeIter(); } // Is tree gateOptimizable?
bool gateTree() { return gateTreeIter(); } // Is tree isGateOptimizable?
bool sameTree(AstNode* node2p); // Does tree of this == node2p?
bool sameGateTree(AstNode* node2p); // Does tree of this == node2p?, not allowing non-isGateOptimizable
void deleteTree(); // Always deletes the next link
@@ -1458,6 +1461,7 @@ public:
virtual bool sizeMattersLhs() { return false; } virtual bool sizeMattersRhs() { return false; }
virtual bool sizeMattersThs() { return false; }
virtual int instrCount() const { return instrCountBranch(); }
virtual AstNode* cloneType(AstNode* condp, AstNode* expr1p, AstNode* expr2p) = 0;
};
class AstNodePreSel : public AstNode {
-4
View File
@@ -763,10 +763,6 @@ void AstAlways::dump(ostream& str) {
if (keyword() != VAlwaysKwd::ALWAYS) str<<" ["<<keyword().ascii()<<"]";
}
void AstArraySel::dump(ostream& str) {
this->AstNode::dump(str);
str<<" [start:"<<start()<<"] [length:"<<length()<<"]";
}
void AstAttrOf::dump(ostream& str) {
this->AstNode::dump(str);
str<<" ["<<attrType().ascii()<<"]";
+14 -10
View File
@@ -610,6 +610,7 @@ class AstMemberDType : public AstNodeDType {
private:
AstNodeDType* m_refDTypep; // Elements of this type (after widthing)
string m_name; // Name of variable
string m_tag; // Holds the string of the verilator tag -- used in XML output.
int m_lsb; // Within this level's packed struct, the LSB of the first bit of the member
//UNSUP: int m_randType; // Randomization type (IEEE)
public:
@@ -650,6 +651,8 @@ public:
virtual int widthTotalBytes() const { return subDTypep()->widthTotalBytes(); } // (Slow) recurses - Width in bytes rounding up 1,2,4,8,12,...
// METHODS
virtual void name(const string& name) { m_name = name; }
virtual void tag(const string& text) { m_tag = text;}
virtual string tag() const { return m_tag; }
int lsb() const { return m_lsb; }
void lsb(int lsb) { m_lsb=lsb; }
};
@@ -766,8 +769,6 @@ class AstArraySel : public AstNodeSel {
// Parents: math|stmt
// Children: varref|arraysel, math
private:
unsigned m_start;
unsigned m_length;
void init(AstNode* fromp) {
if (fromp && fromp->dtypep()->skipRefp()->castNodeArrayDType()) {
// Strip off array to find what array references
@@ -776,11 +777,11 @@ private:
}
public:
AstArraySel(FileLine* fl, AstNode* fromp, AstNode* bitp)
:AstNodeSel(fl, fromp, bitp), m_start(0), m_length(1) {
:AstNodeSel(fl, fromp, bitp) {
init(fromp);
}
AstArraySel(FileLine* fl, AstNode* fromp, int bit)
:AstNodeSel(fl, fromp, new AstConst(fl,bit)), m_start(0), m_length(1) {
:AstNodeSel(fl, fromp, new AstConst(fl,bit)) {
init(fromp);
}
ASTNODE_NODE_FUNCS(ArraySel)
@@ -792,18 +793,13 @@ public:
virtual bool cleanOut() { return true; }
virtual bool cleanLhs() {return false;} virtual bool cleanRhs() {return true;}
virtual bool sizeMattersLhs() {return false;} virtual bool sizeMattersRhs() {return false;}
virtual bool isGateOptimizable() const { return false; }
virtual bool isGateOptimizable() const { return true; } // esp for V3Const::ifSameAssign
virtual bool isPredictOptimizable() const { return false; }
virtual V3Hash sameHash() const { return V3Hash(); }
virtual bool same(AstNode* samep) const { return true; }
virtual int instrCount() const { return widthInstrs(); }
unsigned length() const { return m_length; }
void length(unsigned length) { m_length = length; }
void start(unsigned start) { m_start = start; }
unsigned start() const { return m_start; }
// Special operators
static AstNode* baseFromp(AstNode* nodep); ///< What is the base variable (or const) this dereferences?
virtual void dump(ostream& str);
};
class AstWordSel : public AstNodeSel {
@@ -985,6 +981,7 @@ class AstVar : public AstNode {
private:
string m_name; // Name of variable
string m_origName; // Original name before dot addition
string m_tag; // Holds the string of the verilator tag -- used in XML output.
AstVarType m_varType; // Type of variable
bool m_input:1; // Input or inout
bool m_output:1; // Output or inout
@@ -1125,6 +1122,8 @@ public:
void trace(bool flag) { m_trace=flag; }
// METHODS
virtual void name(const string& name) { m_name = name; }
virtual void tag(const string& text) { m_tag = text;}
virtual string tag() const { return m_tag; }
virtual string directionName() const { return (isInout() ? "inout" : isInput() ? "input"
: isOutput() ? "output" : varType().ascii()); }
bool isInput() const { return m_input; }
@@ -1511,6 +1510,7 @@ public:
class AstPackageExportStarStar : public AstNode {
// A package export *::* declaration
public:
// cppcheck-suppress noExplicitConstructor
AstPackageExportStarStar(FileLine* fl)
: AstNode (fl) {}
ASTNODE_NODE_FUNCS(PackageExportStarStar)
@@ -2183,6 +2183,8 @@ public:
AstCond(FileLine* fl, AstNode* condp, AstNode* expr1p, AstNode* expr2p)
: AstNodeCond(fl, condp, expr1p, expr2p) {}
ASTNODE_NODE_FUNCS(Cond)
virtual AstNode* cloneType(AstNode* condp, AstNode* expr1p, AstNode* expr2p) {
return new AstCond(this->fileline(), condp, expr1p, expr2p); }
};
class AstCondBound : public AstNodeCond {
@@ -2193,6 +2195,8 @@ public:
AstCondBound(FileLine* fl, AstNode* condp, AstNode* expr1p, AstNode* expr2p)
: AstNodeCond(fl, condp, expr1p, expr2p) {}
ASTNODE_NODE_FUNCS(CondBound)
virtual AstNode* cloneType(AstNode* condp, AstNode* expr1p, AstNode* expr2p) {
return new AstCondBound(this->fileline(), condp, expr1p, expr2p); }
};
class AstCoverDecl : public AstNodeStmt {
+2 -2
View File
@@ -31,7 +31,7 @@
#include <cstdarg>
#include <unistd.h>
#include <algorithm>
#include <map>
#include VL_INCLUDE_UNORDERED_MAP
#include "V3Global.h"
#include "V3Broken.h"
@@ -47,7 +47,7 @@ class BrokenTable : public AstNVisitor {
private:
// MEMBERS
// For each node, we keep if it exists or not.
typedef map<const AstNode*,int> NodeMap;
typedef VL_UNORDERED_MAP<const AstNode*,int> NodeMap; // Performance matters (when --debug)
static NodeMap s_nodes; // Set of all nodes that exist
// BITMASK
enum { FLAG_ALLOCATED = 0x01 }; // new() and not delete()ed
+24 -17
View File
@@ -95,6 +95,8 @@ public:
m_modp->addStmtp(m_tlFuncp);
}
~V3CCtorsVisitor() {}
private:
explicit V3CCtorsVisitor(const V3CCtorsVisitor&); ///< N/A, no copy constructor
};
//######################################################################
@@ -102,22 +104,27 @@ public:
void V3CCtors::cctorsAll() {
UINFO(2,__FUNCTION__<<": "<<endl);
for (AstNodeModule* modp = v3Global.rootp()->modulesp(); modp; modp=modp->nextp()->castNodeModule()) {
// Process each module in turn
V3CCtorsVisitor var_reset (modp, "_ctor_var_reset");
V3CCtorsVisitor configure_coverage (modp, "_configure_coverage",
EmitCBaseVisitor::symClassVar()+ ", bool first", "vlSymsp, first",
"if (0 && vlSymsp && first) {} // Prevent unused\n");
for (AstNode* np = modp->stmtsp(); np; np = np->nextp()) {
AstVar* varp = np->castVar();
if (varp) var_reset.add(new AstCReset(varp->fileline(), new AstVarRef(varp->fileline(), varp, true)));
AstCoverDecl* coverp = np->castCoverDecl();
if (coverp) {
AstNode* backp = coverp->backp();
coverp->unlinkFrBack();
configure_coverage.add(coverp);
np = backp;
}
}
// Process each module in turn
{
V3CCtorsVisitor var_reset (modp, "_ctor_var_reset");
for (AstNode* np = modp->stmtsp(); np; np = np->nextp()) {
if (AstVar* varp = np->castVar()) {
var_reset.add(new AstCReset(varp->fileline(), new AstVarRef(varp->fileline(), varp, true)));
}
}
}
if (v3Global.opt.coverage()) {
V3CCtorsVisitor configure_coverage
(modp, "_configure_coverage", EmitCBaseVisitor::symClassVar()+ ", bool first", "vlSymsp, first",
"if (0 && vlSymsp && first) {} // Prevent unused\n");
for (AstNode* np = modp->stmtsp(); np; np = np->nextp()) {
if (AstCoverDecl* coverp = np->castCoverDecl()) {
AstNode* backp = coverp->backp();
coverp->unlinkFrBack();
configure_coverage.add(coverp);
np = backp;
}
}
}
}
}
+78 -17
View File
@@ -369,11 +369,11 @@ private:
return true;
}
bool operandBiExtendConst(AstNodeBiop* nodep) {
bool operandBiExtendConstShrink(AstNodeBiop* nodep) {
// Loop unrolling favors standalone compares
// EQ(const{width32}, EXTEND(xx{width3})) -> EQ(const{3}, xx{3})
// Beware that the constant must have zero bits (+ 1 if signed) or compare
// would be incorrect
// The constant must have zero bits (+ 1 if signed) or compare
// would be incorrect. See also operandBiExtendConst
AstExtend* extendp = nodep->rhsp()->castExtend();
if (!extendp) return false;
AstNode* smallerp = extendp->lhsp();
@@ -395,6 +395,19 @@ private:
if (debug()>=9) nodep->dumpTree(cout,"BI(EXTEND)-ou:");
return true;
}
bool operandBiExtendConstOver(AstNodeBiop* nodep) {
// EQ(const{width32}, EXTEND(xx{width3})) -> constant
// When the constant has non-zero bits above the extend it's a constant.
// Avoids compiler warning
AstExtend* extendp = nodep->rhsp()->castExtend();
if (!extendp) return false;
AstNode* smallerp = extendp->lhsp();
int subsize = smallerp->width();
AstConst* constp = nodep->lhsp()->castConst();
if (!constp) return false;
if (constp->num().isBitsZero(constp->width()-1, subsize)) return false;
return true;
}
AstNode* afterComment(AstNode* nodep) {
// Ignore comments, such as to determine if a AstIf is empty.
@@ -472,11 +485,7 @@ private:
if (!ifp || ifp->nextp()) return false; // Must be SINGLE statement
if (!elsep || elsep->nextp()) return false;
if (ifp->type() != elsep->type()) return false; // Can't mix an assigndly and an assign
AstVarRef* ifvarp = ifp->lhsp()->castVarRef();
AstVarRef* elsevarp = elsep->lhsp()->castVarRef();
if (!ifvarp || !elsevarp) return false;
if (ifvarp->isWide()) return false; // Would need temporaries, so not worth it
if (!ifvarp->sameGateTree(elsevarp)) return false;
if (!ifp->lhsp()->sameGateTree(elsep->lhsp())) return false;
if (!ifp->rhsp()->gateTree()) return false;
if (!elsep->rhsp()->gateTree()) return false;
return true;
@@ -1680,9 +1689,12 @@ private:
// But might be same name with different scopes
if (litemp->varrefp()->varScopep() < ritemp->varrefp()->varScopep()) return true;
if (litemp->varrefp()->varScopep() > ritemp->varrefp()->varScopep()) return false;
// Or rarely, different data types
if (litemp->varrefp()->dtypep() < ritemp->varrefp()->dtypep()) return true;
if (litemp->varrefp()->dtypep() > ritemp->varrefp()->dtypep()) return false;
}
// Sort by edge, AFTER variable, as we want multiple edges for same var adjacent
// note the SenTree optimizer requires this order (more general firsst, less general last)
// note the SenTree optimizer requires this order (more general first, less general last)
if (litemp->edgeType() < ritemp->edgeType()) return true;
if (litemp->edgeType() > ritemp->edgeType()) return false;
}
@@ -1893,7 +1905,7 @@ private:
}
else if (0 // Disabled, as vpm assertions are faster without due to short-circuiting
&& operandIfIf(nodep)) {
UINFO(0,"IF({a}) IF({b}) => IF({a} && {b})"<<endl);
UINFO(9,"IF({a}) IF({b}) => IF({a} && {b})"<<endl);
AstNodeIf* lowerIfp = nodep->ifsp()->castNodeIf();
AstNode* condp = nodep->condp()->unlinkFrBack();
AstNode* lowerIfsp = lowerIfp->ifsp()->unlinkFrBackWithNext();
@@ -1909,6 +1921,49 @@ private:
}
}
virtual void visit(AstDisplay* nodep) {
// DISPLAY(SFORMAT(text1)),DISPLAY(SFORMAT(text2)) -> DISPLAY(SFORMAT(text1+text2))
nodep->iterateChildren(*this);
if (stmtDisplayDisplay(nodep)) return;
}
bool stmtDisplayDisplay(AstDisplay* nodep) {
// DISPLAY(SFORMAT(text1)),DISPLAY(SFORMAT(text2)) -> DISPLAY(SFORMAT(text1+text2))
if (!m_modp) return false; // Don't optimize under single statement
if (!nodep->backp()) return false;
AstDisplay* prevp = nodep->backp()->castDisplay();
if (!prevp) return false;
if (!((prevp->displayType() == nodep->displayType())
|| (prevp->displayType() == AstDisplayType::DT_WRITE
&& nodep->displayType() == AstDisplayType::DT_DISPLAY)
|| (prevp->displayType() == AstDisplayType::DT_DISPLAY
&& nodep->displayType() == AstDisplayType::DT_WRITE)))
return false;
if ((prevp->filep() && !nodep->filep())
|| (!prevp->filep() && nodep->filep())
|| !prevp->filep()->sameTree(nodep->filep())) return false;
if (!prevp->fmtp() || prevp->fmtp()->nextp()
|| !nodep->fmtp() || nodep->fmtp()->nextp()) return false;
AstSFormatF* pformatp = prevp->fmtp();
if (!pformatp || pformatp->exprsp() || pformatp->scopeNamep()) return false;
AstSFormatF* nformatp = nodep->fmtp();
if (!nformatp || nformatp->exprsp() || nformatp->scopeNamep()) return false;
//
UINFO(9,"DISPLAY(SF({a})) DISPLAY(SF({b})) -> DISPLAY(SF({a}+{b}))"<<endl);
// Convert DT_DISPLAY to DT_WRITE as may allow later optimizations
if (prevp->displayType() == AstDisplayType::DT_DISPLAY) {
prevp->displayType(AstDisplayType::DT_WRITE);
pformatp->text(pformatp->text()+"\n");
}
// We can't replace prev() as the edit tracking iterators will get confused.
// So instead we edit the prev note itself.
if (prevp->addNewline()) pformatp->text(pformatp->text()+"\n");
pformatp->text(pformatp->text()+nformatp->text());
if (!prevp->addNewline() && nodep->addNewline()) {
pformatp->text(pformatp->text()+"\n");
}
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
return true;
}
virtual void visit(AstSFormatF* nodep) {
// Substitute constants into displays. The main point of this is to
// simplify assertion methodologies which call functions with display's.
@@ -1947,7 +2002,7 @@ private:
UINFO(9," DispConst: "<<fmt<<" -> "<<out<<" for "<<argp<<endl);
// fmt = out w/ replace % with %% as it must be literal.
fmt = VString::quotePercent(out);
argp->unlinkFrBack()->deleteTree();
argp->unlinkFrBack()->deleteTree(); VL_DANGLING(argp);
}
argp=nextp;
}
@@ -2216,12 +2271,18 @@ private:
TREEOP ("AstShiftR{operandShiftShift(nodep)}", "replaceShiftShift(nodep)");
TREEOP ("AstWordSel{operandWordOOB(nodep)}", "replaceZero(nodep)");
// Compress out EXTENDs to appease loop unroller
TREEOPV("AstEq {$rhsp.castExtend,operandBiExtendConst(nodep)}", "DONE");
TREEOPV("AstNeq {$rhsp.castExtend,operandBiExtendConst(nodep)}", "DONE");
TREEOPV("AstGt {$rhsp.castExtend,operandBiExtendConst(nodep)}", "DONE");
TREEOPV("AstGte {$rhsp.castExtend,operandBiExtendConst(nodep)}", "DONE");
TREEOPV("AstLt {$rhsp.castExtend,operandBiExtendConst(nodep)}", "DONE");
TREEOPV("AstLte {$rhsp.castExtend,operandBiExtendConst(nodep)}", "DONE");
TREEOPV("AstEq {$rhsp.castExtend,operandBiExtendConstShrink(nodep)}", "DONE");
TREEOPV("AstNeq {$rhsp.castExtend,operandBiExtendConstShrink(nodep)}", "DONE");
TREEOPV("AstGt {$rhsp.castExtend,operandBiExtendConstShrink(nodep)}", "DONE");
TREEOPV("AstGte {$rhsp.castExtend,operandBiExtendConstShrink(nodep)}", "DONE");
TREEOPV("AstLt {$rhsp.castExtend,operandBiExtendConstShrink(nodep)}", "DONE");
TREEOPV("AstLte {$rhsp.castExtend,operandBiExtendConstShrink(nodep)}", "DONE");
TREEOPV("AstEq {$rhsp.castExtend,operandBiExtendConstOver(nodep)}", "replaceZero(nodep)");
TREEOPV("AstNeq {$rhsp.castExtend,operandBiExtendConstOver(nodep)}", "replaceNum(nodep,1)");
TREEOPV("AstGt {$rhsp.castExtend,operandBiExtendConstOver(nodep)}", "replaceNum(nodep,1)");
TREEOPV("AstGte {$rhsp.castExtend,operandBiExtendConstOver(nodep)}", "replaceNum(nodep,1)");
TREEOPV("AstLt {$rhsp.castExtend,operandBiExtendConstOver(nodep)}", "replaceZero(nodep)");
TREEOPV("AstLte {$rhsp.castExtend,operandBiExtendConstOver(nodep)}", "replaceZero(nodep)");
// Identical operands on both sides
// AstLogAnd/AstLogOr already converted to AstAnd/AstOr for these rules
// AstAdd->ShiftL(#,1) but uncommon
+1
View File
@@ -168,6 +168,7 @@ private:
// Add signal to hold the old value
string newvarname = (string)"__Vtogcov__"+nodep->shortName();
AstVar* chgVarp = new AstVar (nodep->fileline(), AstVarType::MODULETEMP, newvarname, nodep);
chgVarp->fileline()->modifyWarnOff(V3ErrorCode::UNUSED, true);
m_modp->addStmtp(chgVarp);
// Create bucket for each dimension * bit.
+5 -5
View File
@@ -77,7 +77,6 @@ private:
// AstVarScope::user4p() -> AstAlwaysPost*. Post block for this variable
// AstVarScope::user5() -> VarUsage. Tracks delayed vs non-delayed usage
// AstVar::user2() -> bool. Set true if already made warning
// AstVar::user4() -> int. Vector number, for assignment creation
// AstVarRef::user2() -> bool. Set true if already processed
// AstAlwaysPost::user2() -> ActActive*. Points to activity block of signal (valid when AstAlwaysPost::user4p is valid)
// AstAlwaysPost::user4() -> AstIf*. Last IF (__Vdlyvset__) created under this AlwaysPost
@@ -102,7 +101,8 @@ private:
typedef std::map<pair<AstNodeModule*,string>,AstVar*> VarMap;
VarMap m_modVarMap; // Table of new var names created under module
V3Double0 m_statSharedSet;// Statistic tracking
typedef std::map<AstVarScope*,int> ScopeVecMap;
ScopeVecMap m_scopeVecMap; // Next var number for each scope
// METHODS
static int debug() {
@@ -195,7 +195,7 @@ private:
arrayselp = lhsp->castArraySel();
}
if (!arrayselp) nodep->v3fatalSrc("No arraysel under bitsel?");
if (arrayselp->length()!=1) nodep->v3fatalSrc("ArraySel with length!=1 should have been removed in V3Slice");
if (arrayselp->dtypep()->skipRefp()->castUnpackArrayDType()) nodep->v3fatalSrc("ArraySel with unpacked arrays should have been removed in V3Slice");
UINFO(4,"AssignDlyArray: "<<nodep<<endl);
//
@@ -211,7 +211,7 @@ private:
if (!varrefp->varScopep()) varrefp->v3fatalSrc("Var didn't get varscoped in V3Scope.cpp");
varrefp->unlinkFrBack();
AstVar* oldvarp = varrefp->varp();
int modVecNum = oldvarp->user4(); oldvarp->user4(modVecNum+1);
int modVecNum = m_scopeVecMap[varrefp->varScopep()]++;
//
deque<AstNode*> dimreadps; // Read value for each dimension of assignment
for (unsigned dimension=0; dimension<dimvalp.size(); dimension++) {
@@ -370,7 +370,7 @@ private:
&& nodep->lhsp()->castSel()->fromp()->castArraySel())) {
AstNode* lhsp = nodep->lhsp()->unlinkFrBack();
AstNode* newlhsp = createDlyArray(nodep, lhsp);
if (m_inLoop) nodep->v3warn(E_BLKLOOPINIT,"Unsupported: Delayed assignment to array inside for loops (non-delayed is ok - see docs)");
if (m_inLoop) nodep->v3warn(BLKLOOPINIT,"Unsupported: Delayed assignment to array inside for loops (non-delayed is ok - see docs)");
if (newlhsp) {
nodep->lhsp(newlhsp);
} else {
+93 -44
View File
@@ -53,7 +53,8 @@ private:
// STATE
AstNodeModule* m_modp; // Current module
AstScope* m_scopep; // Current scope
bool m_needThis; // Add thisp to function
bool m_modSingleton; // m_modp is only instanced once
bool m_needThis; // Make function non-static
FuncMmap m_modFuncs; // Name of public functions added
// METHODS
@@ -63,41 +64,91 @@ private:
return level;
}
string descopedName(AstScope* scopep, bool& hierThisr, AstVar* varp=NULL) {
static bool modIsSingleton(AstNodeModule* modp) {
// True iff there's exactly one instance of this module in the design.
int instances = 0;
for (AstNode* stmtp = modp->stmtsp(); stmtp; stmtp=stmtp->nextp()) {
if (stmtp->castScope()) {
if (++instances > 1) { return false; }
}
}
return (instances == 1);
}
// Construct the best prefix to reference an object in 'scopep'
// from a CFunc in 'm_scopep'. Result may be relative
// ("this->[...]") or absolute ("vlTOPp->[...]").
//
// Using relative references allows V3Combine'ing
// code across multiple instances of the same module.
//
// Sets 'hierThisr' true if the object is local to this scope
// (and could be made into a function-local later in V3Localize),
// false if the object is in another scope.
string descopedName(const AstScope* scopep, bool& hierThisr,
const AstVar* varp=NULL) {
UASSERT(scopep, "Var/Func not scoped\n");
hierThisr = true;
hierThisr = (scopep == m_scopep);
// It's possible to disable relative references. This is a concession
// to older compilers (gcc < 4.5.x) that don't understand __restrict__
// well and emit extra ld/st to guard against pointer aliasing
// when this-> and vlTOPp-> are mixed in the same function.
//
// "vlTOPp" is declared "restrict" so better compilers understand
// that it won't alias with "this".
bool relativeRefOk = v3Global.opt.relativeCFuncs();
// Use absolute refs in top-scoped routines, keep them static.
// The DPI callback registration depends on representing top-level
// static routines as plain function pointers. That breaks if those
// become true OO routines.
//
// V3Combine wouldn't likely be able to combine top-level
// routines anyway, so there's no harm in keeping these static.
if (m_modp->isTop()) {
relativeRefOk = false;
}
// Use absolute refs if this scope is the only instance of the module.
// Saves a bit of overhead on passing the 'this' pointer, and there's no
// need to be nice to V3Combine when we have only a single instance.
// The risk that this prevents combining identical logic from differently-
// named but identical modules seems low.
if (m_modSingleton) {
relativeRefOk = false;
}
if (varp && varp->isFuncLocal()) {
hierThisr = true;
return ""; // Relative to function, not in this
} else if (scopep == m_scopep && m_modp->isTop()) {
//return ""; // Reference to scope we're in, no need to HIER-> it
return "vlTOPp->";
} else if (scopep == m_scopep && !m_modp->isTop()
&& 0) { // We no longer thisp-> as still get ambiguation problems
m_needThis = true;
return "thisp->"; // this-> but with restricted aliasing
} else if (scopep->aboveScopep() && scopep->aboveScopep()==m_scopep
&& 0 // DISABLED: GCC considers the pointers ambiguous, so goes ld/store crazy
) {
// Reference to scope of cell directly under this module, can just "cell->"
string name = scopep->name();
string::size_type pos;
if ((pos = name.rfind(".")) != string::npos) {
name.erase(0,pos+1);
}
hierThisr = false;
return name+"->";
} else {
// Reference to something else, use global variable
UINFO(8," Descope "<<scopep<<endl);
UINFO(8," to "<<scopep->name()<<endl);
UINFO(8," under "<<m_scopep->name()<<endl);
hierThisr = false;
if (!scopep->aboveScopep()) { // Top
return "vlTOPp->"; // == "vlSymsp->TOPp->", but GCC would suspect aliases
} else {
return scopep->nameVlSym()+".";
}
}
} else if (relativeRefOk && scopep == m_scopep) {
m_needThis = true;
return "this->";
} else if (relativeRefOk && scopep->aboveScopep()
&& scopep->aboveScopep()==m_scopep) {
// Reference to scope of cell directly under this module, can just "cell->"
string name = scopep->name();
string::size_type pos;
if ((pos = name.rfind(".")) != string::npos) {
name.erase(0,pos+1);
}
m_needThis = true;
return name+"->";
} else {
// Reference to something elsewhere, or relative refences
// are disabled. Use global variable
UINFO(8," Descope "<<scopep<<endl);
UINFO(8," to "<<scopep->name()<<endl);
UINFO(8," under "<<m_scopep->name()<<endl);
if (!scopep->aboveScopep()) { // Top
// We could also return "vlSymsp->TOPp->" here, but GCC would
// suspect aliases.
return "vlTOPp->";
} else {
return scopep->nameVlSym()+".";
}
}
}
void makePublicFuncWrappers() {
@@ -166,7 +217,7 @@ private:
}
}
// Not really any way the user could do this, and we'd need to come up with some return value
//newfuncp->addStmtsp(new AstDisplay (newfuncp->fileline(), AstDisplayType::DT_DISPLAY,
//newfuncp->addStmtsp(new AstDisplay (newfuncp->fileline(), AstDisplayType::DT_WARNING,
// string("%%Error: ")+name+"() called with bad scope", NULL));
//newfuncp->addStmtsp(new AstStop (newfuncp->fileline()));
if (debug()>=9) newfuncp->dumpTree(cout," newfunc: ");
@@ -182,6 +233,7 @@ private:
virtual void visit(AstNodeModule* nodep) {
m_modp = nodep;
m_modFuncs.clear();
m_modSingleton = modIsSingleton(m_modp);
nodep->iterateChildren(*this);
makePublicFuncWrappers();
m_modp = NULL;
@@ -222,11 +274,7 @@ private:
nodep->iterateChildren(*this);
nodep->user1(true);
if (m_needThis) {
nodep->v3fatalSrc("old code");
// Really we should have more node types for backend optimization of this stuff
string text = v3Global.opt.modPrefix() + "_" + m_modp->name()
+"* thisp = &("+m_scopep->nameVlSym()+");\n";
nodep->addInitsp(new AstCStmt(nodep->fileline(), text));
nodep->isStatic(false);
}
// If it's under a scope, move it up to the top
if (m_scopep) {
@@ -248,11 +296,12 @@ private:
}
public:
// CONSTRUCTORS
explicit DescopeVisitor(AstNetlist* nodep) {
m_modp = NULL;
m_scopep = NULL;
m_needThis = false;
nodep->accept(*this);
explicit DescopeVisitor(AstNetlist* nodep)
: m_modp(NULL),
m_scopep(NULL),
m_modSingleton(false),
m_needThis(false) {
nodep->accept(*this);
}
virtual ~DescopeVisitor() {}
};
+4 -2
View File
@@ -1464,7 +1464,8 @@ void EmitCImp::emitVarReset(AstVar* varp) {
}
bool zeroit = (varp->attrFileDescr() // Zero it out, so we don't core dump if never call $fopen
|| (varp->basicp() && varp->basicp()->isZeroInit())
|| (varp->name().size()>=1 && varp->name()[0]=='_' && v3Global.opt.underlineZero()));
|| (varp->name().size()>=1 && varp->name()[0]=='_' && v3Global.opt.underlineZero())
|| (v3Global.opt.xInitial() == "fast" || v3Global.opt.xInitial() == "0"));
if (varp->isWide()) {
// DOCUMENT: We randomize everything. If the user wants a _var to be zero,
// there should be a initial statement. (Different from verilator2.)
@@ -1904,7 +1905,8 @@ void EmitCImp::emitInt(AstNodeModule* modp) {
bool did = false;
for (AstNode* nodep=modp->stmtsp(); nodep; nodep = nodep->nextp()) {
if (AstCell* cellp=nodep->castCell()) {
if (!did++) {
if (!did) {
did = true;
putsDecoration("// CELLS\n");
if (modp->isTop()) puts("// Public to allow access to /*verilator_public*/ items;\n");
if (modp->isTop()) puts("// otherwise the application code can consider these internals.\n");
+8 -2
View File
@@ -329,7 +329,10 @@ void EmitCSyms::emitSymHdr() {
{ // Scope names
bool did = false;
for (ScopeNames::iterator it = m_scopeNames.begin(); it != m_scopeNames.end(); ++it) {
if (!did++) puts("\n// SCOPE NAMES\n");
if (!did) {
did = true;
puts("\n// SCOPE NAMES\n");
}
puts("VerilatedScope __Vscope_"+it->second.m_symName+";\n");
}
}
@@ -432,7 +435,10 @@ void EmitCSyms::emitSymImp() {
{ // Setup scope names
bool did = false;
for (ScopeNames::iterator it = m_scopeNames.begin(); it != m_scopeNames.end(); ++it) {
if (!did++) puts("// Setup scope names\n");
if (!did) {
did = true;
puts("// Setup scope names\n");
}
puts("__Vscope_"+it->second.m_symName+".configure(this,name(),");
putsQuoted(it->second.m_prettyName);
puts(");\n");
+1
View File
@@ -68,6 +68,7 @@ class EmitXmlFileVisitor : public AstNVisitor {
if (tag=="") tag = VString::downcase(nodep->typeName());
puts("<"+tag+" "+nodep->fileline()->xml());
if (nodep->name()!="") { puts(" name="); putsQuoted(nodep->prettyName()); }
if (nodep->tag()!="") { puts(" tag="); putsQuoted(nodep->tag()); }
}
void outputChildrenEnd(AstNode* nodep, string tag) {
if (tag=="") tag = VString::downcase(nodep->typeName());
+2 -2
View File
@@ -85,7 +85,7 @@ string V3Error::lineStr (const char* filename, int lineno) {
const char* fnslashp = strrchr (filename, '/');
if (fnslashp) filename = fnslashp+1;
out<<filename<<":"<<dec<<lineno<<":";
const char* spaces = " ";
const char* const spaces = " ";
size_t numsp = out.str().length(); if (numsp>20) numsp = 20;
out<<(spaces + numsp);
return out.str();
@@ -215,7 +215,7 @@ void V3Error::v3errorEnd (ostringstream& sstr) {
}
#ifndef _V3ERROR_NO_GLOBAL_
if (debug()) {
v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("final",990));
v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("final.tree",990));
if (s_errorExitCb) s_errorExitCb();
V3Stats::statsFinalAll(v3Global.rootp());
V3Stats::statsReport();
+4 -3
View File
@@ -48,7 +48,6 @@ public:
I_LINT, // All lint messages
I_DEF_NETTYPE_WIRE, // `default_nettype is WIRE (false=NONE)
// Error codes:
E_BLKLOOPINIT, // Error: Delayed assignment to array inside for loops
E_DETECTARRAY, // Error: Unsupported: Can't detect changes on arrayed variable
E_MULTITOP, // Error: Multiple top level modules
E_TASKNSVAR, // Error: Task I/O not simple
@@ -60,6 +59,7 @@ public:
ASSIGNDLY, // Assignment delays
ASSIGNIN, // Assigning to input
BLKANDNBLK, // Blocked and non-blocking assignments to same variable
BLKLOOPINIT, // Delayed assignment to array inside for loops
BLKSEQ, // Blocking assignments in sequential block
CASEINCOMPLETE, // Case statement has missing values
CASEOVERLAP, // Case statements overlap
@@ -121,11 +121,11 @@ public:
// Boolean
" I_COVERAGE", " I_TRACING", " I_LINT", " I_DEF_NETTYPE_WIRE",
// Errors
"BLKLOOPINIT", "DETECTARRAY", "MULTITOP", "TASKNSVAR",
"DETECTARRAY", "MULTITOP", "TASKNSVAR",
// Warnings
" EC_FIRST_WARN",
"ALWCOMBORDER", "ASSIGNDLY", "ASSIGNIN",
"BLKANDNBLK", "BLKSEQ",
"BLKANDNBLK", "BLKLOOPINIT", "BLKSEQ",
"CASEINCOMPLETE", "CASEOVERLAP", "CASEWITHX", "CASEX", "CDCRSTLOGIC", "CLKDATA",
"CMPCONST", "COMBDLY", "DEFPARAM", "DECLFILENAME",
"ENDLABEL", "GENCLK",
@@ -150,6 +150,7 @@ public:
// Warnings we'll present to the user as errors
// Later -Werror- options may make more of these.
bool pretendError() const { return ( m_e==ASSIGNIN || m_e==BLKANDNBLK
|| m_e==BLKLOOPINIT
|| m_e==IMPURE || m_e==MODDUP); }
// Warnings to mention manual
bool mentionManual() const { return ( m_e==EC_FATALSRC || m_e==SYMRSVDWORD
+1 -1
View File
@@ -243,7 +243,7 @@ private:
}
bool expandWide (AstNodeAssign* nodep, AstArraySel* rhsp) {
UINFO(8," Wordize ASSIGN(ARRAYSEL) "<<nodep<<endl);
if (rhsp->length()!=1) nodep->v3fatalSrc("ArraySel with length!=1 should have been removed in V3Slice");
if (nodep->dtypep()->skipRefp()->castUnpackArrayDType()) nodep->v3fatalSrc("ArraySel with unpacked arrays should have been removed in V3Slice");
for (int w=0; w<nodep->widthWords(); w++) {
addWordAssign(nodep, w, newAstWordSelClone (rhsp, w));
}
+35 -9
View File
@@ -34,6 +34,14 @@
# define INFILTER_PIPE // Allow pipe filtering. Needs fork()
#endif
#ifdef HAVE_STAT_NSEC // i.e. Linux 2.6, from configure
# define VL_STAT_CTIME_NSEC(stat) ((stat).st_ctim.tv_nsec) // Nanoseconds
# define VL_STAT_MTIME_NSEC(stat) ((stat).st_mtim.tv_nsec) // Nanoseconds
#else
# define VL_STAT_CTIME_NSEC(stat) (0)
# define VL_STAT_MTIME_NSEC(stat) (0)
#endif
#ifdef INFILTER_PIPE
# include <sys/wait.h>
#endif
@@ -62,6 +70,7 @@ class V3FileDependImp {
public:
DependFile(const string& filename, bool target)
: m_target(target), m_filename(filename) {
m_stat.st_ctime = 0;
m_stat.st_mtime = 0;
}
~DependFile() {}
@@ -69,7 +78,10 @@ class V3FileDependImp {
bool target() const { return m_target; }
off_t size() const { return m_stat.st_size; }
ino_t ino() const { return m_stat.st_ino; }
time_t mtime() const { return m_stat.st_mtime; }
time_t cstime() const { return m_stat.st_ctime; } // Seconds
time_t cnstime() const { return VL_STAT_CTIME_NSEC(m_stat); } // Nanoseconds
time_t mstime() const { return m_stat.st_mtime; } // Seconds
time_t mnstime() const { return VL_STAT_MTIME_NSEC(m_stat); } // Nanoseconds
void loadStats() {
if (!m_stat.st_mtime) {
string fn = filename();
@@ -178,7 +190,10 @@ inline void V3FileDependImp::writeTimes(const string& filename, const string& cm
*ofp<<(iter->target()?"T":"S")<<" ";
*ofp<<" "<<setw(8)<<showSize;
*ofp<<" "<<setw(8)<<showIno;
*ofp<<" "<<setw(11)<<iter->mtime();
*ofp<<" "<<setw(11)<<iter->cstime();
*ofp<<" "<<setw(11)<<iter->cnstime();
*ofp<<" "<<setw(11)<<iter->mstime();
*ofp<<" "<<setw(11)<<iter->mnstime();
*ofp<<" \""<<iter->filename()<<"\"";
*ofp<<endl;
}
@@ -209,31 +224,42 @@ inline bool V3FileDependImp::checkTimes(const string& filename, const string& cm
off_t chkSize; *ifp>>chkSize;
ino_t chkIno; *ifp>>chkIno;
if (ifp->eof()) break; // Needed to read final whitespace before found eof
time_t chkMtime; *ifp>>chkMtime;
time_t chkCstime; *ifp>>chkCstime;
time_t chkCnstime; *ifp>>chkCnstime;
time_t chkMstime; *ifp>>chkMstime;
time_t chkMnstime; *ifp>>chkMnstime;
char quote; *ifp>>quote;
string chkFilename; getline(*ifp, chkFilename, '"');
//UINFO(9," got d="<<chkDir<<" s="<<chkSize<<" mt="<<chkMtime<<" fn = "<<chkFilename<<endl);
V3Options::fileNfsFlush(chkFilename);
struct stat chkStat;
int err = stat(chkFilename.c_str(), &chkStat);
if (err!=0) {
UINFO(2," --check-times failed: missing "<<chkFilename<<endl);
return false;
}
if (filename != chkFilename) { // See above; we were writing it at the time...
//UINFO(9," got d="<<chkDir<<" s="<<chkSize<<" ct="<<chkCstime<<"."<<chkCnstime<<" mt="<<chkMstime<<"."<<chkMnstime<<" fn = "<<chkFilename<<endl);
//UINFO(9," nowSt s="<<chkStat.st_size<<" mt="<<chkStat.st_mtime<<" ct="<<chkStat.st_ctime<<" fn = "<<chkFilename<<endl);
if (filename != chkFilename) { // Other then the .dat file itself, as we were writing it at the time...
// We'd like this rule:
//if (!(chkStat.st_size == chkSize
// && chkStat.st_mtime == chkMtime) {
// && chkStat.st_mtime == chkMstime) {
// However NFS messes us up, as there might be some data outstanding when
// we determined the original size. For safety, we know the creation time
// must be within a few second window... call it 20 sec.
if (!(chkStat.st_size >= chkSize
&& chkStat.st_ino == chkIno
&& chkStat.st_mtime >= chkMtime
&& chkStat.st_mtime <= (chkMtime + 20))) {
&& chkStat.st_ctime == chkCstime
&& VL_STAT_CTIME_NSEC(chkStat) == chkCnstime
&& chkStat.st_mtime <= (chkMstime + 20)
// Not comparing chkMnstime
)) {
UINFO(2," --check-times failed: out-of-date "<<chkFilename
<<"; "<<chkStat.st_size<<"=?"<<chkSize
<<" "<<chkStat.st_mtime<<"=?"<<chkMtime<<endl);
<<" "<<chkStat.st_ctime<<"."<<VL_STAT_CTIME_NSEC(chkStat)
<<"=?"<<chkCstime<<"."<<chkCnstime
<<" "<<chkStat.st_mtime<<"."<<VL_STAT_MTIME_NSEC(chkStat)
<<"=?"<<chkMstime<<"."<<chkMnstime<<endl);
return false;
}
}
+3
View File
@@ -864,6 +864,9 @@ void GateVisitor::optimizeElimVar(AstVarScope* varscp, AstNode* substp, AstNode*
// optimizing away this assignment, etc.
consumerp = V3Const::constifyEdit(consumerp);
if (debug()>=5) consumerp->dumpTree(cout,"\telimUseDne: ");
// Some previous input edges may have disappeared, perhaps all of them.
// If we remove the edges we can further optimize
// See e.g t_var_overzero.v.
}
}
+2 -2
View File
@@ -121,7 +121,7 @@ uint32_t V3GraphVertex::outHash() const {
ostream& operator<<(ostream& os, V3GraphVertex* vertexp) {
os<<" VERTEX="<<vertexp->name();
if (vertexp->rank()) os<<" r"<<vertexp->rank();
if (vertexp->fanout()) os<<" f"<<vertexp->fanout();
if (vertexp->fanout()!=0.0) os<<" f"<<vertexp->fanout();
if (vertexp->color()) os<<" c"<<vertexp->color();
return os;
}
@@ -327,7 +327,7 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) {
<<"\t[fontsize=8 "
<<"label=\""<<(vertexp->name()!="" ? vertexp->name() : "\\N");
if (vertexp->rank()) *logp<<" r"<<vertexp->rank();
if (vertexp->fanout()) *logp<<" f"<<vertexp->fanout();
if (vertexp->fanout()!=0.0) *logp<<" f"<<vertexp->fanout();
if (vertexp->color()) *logp<<"\\n c"<<vertexp->color();
*logp<<"\"";
*logp<<", color="<<vertexp->dotColor();
+88 -40
View File
@@ -53,22 +53,34 @@ private:
// NODE STATE
// Output
// AstNodeModule::user1() // OUTPUT: bool. User request to inline this module
// Entire netlist (can be cleared after this visit completes)
// Internal state (can be cleared after this visit completes)
// AstNodeModule::user2() // CIL_*. Allowed to automatically inline module
// AstNodeModule::user3() // int. Number of cells referencing this module
AstUser1InUse m_inuser1;
// AstNodeModule::user4() // int. Statements in module
AstUser2InUse m_inuser2;
AstUser3InUse m_inuser3;
AstUser4InUse m_inuser4;
enum {CIL_NOTHARD=0, // For user2, inline not supported
CIL_NOTSOFT, // For user2, don't inline unless user overrides
CIL_MAYBE}; // For user2, might inline
// For the user2 field:
enum {CIL_NOTHARD=0, // Inline not supported
CIL_NOTSOFT, // Don't inline unless user overrides
CIL_MAYBE, // Might inline
CIL_USER}; // Pragma suggests inlining
// STATE
AstNodeModule* m_modp; // Flattened cell's containing module
int m_stmtCnt; // Statements in module
AstNodeModule* m_modp; // Current module
V3Double0 m_statUnsup; // Statistic tracking
typedef vector<AstNodeModule*> ModVec;
ModVec m_allMods; // All modules, in top-down order.
// Within the context of a given module, LocalInstanceMap maps
// from child modules to the count of each child's local instantiations.
typedef map<AstNodeModule*, int> LocalInstanceMap;
// We keep a LocalInstanceMap for each module in the design
map<AstNodeModule*, LocalInstanceMap> m_instances;
// METHODS
static int debug() {
static int level = -1;
@@ -92,39 +104,23 @@ private:
// VISITORS
virtual void visit(AstNodeModule* nodep) {
m_stmtCnt = 0;
m_modp = nodep;
m_allMods.push_back(nodep);
m_modp->user2(CIL_MAYBE);
m_modp->user4(0); // statement count
if (m_modp->castIface()) {
// Inlining an interface means we no longer have a cell handle to resolve to.
// If inlining moves post-scope this can perhaps be relaxed.
cantInline("modIface",true);
}
if (m_modp->modPublic()) cantInline("modPublic",false);
//
nodep->iterateChildren(*this);
//
bool userinline = nodep->user1();
int allowed = nodep->user2();
int refs = nodep->user3();
// Should we automatically inline this module?
// inlineMult = 2000 by default. If a mod*#instances is < this # nodes, can inline it
bool doit = ((allowed == CIL_NOTSOFT || allowed == CIL_MAYBE)
&& (userinline
|| ((allowed == CIL_MAYBE)
&& (refs==1
|| m_stmtCnt < INLINE_MODS_SMALLER
|| v3Global.opt.inlineMult() < 1
|| refs*m_stmtCnt < v3Global.opt.inlineMult()))));
// Packages aren't really "under" anything so they confuse this algorithm
if (nodep->castPackage()) doit = false;
UINFO(4, " Inline="<<doit<<" Possible="<<allowed<<" Usr="<<userinline<<" Refs="<<refs<<" Stmts="<<m_stmtCnt
<<" "<<nodep<<endl);
nodep->user1(doit);
m_modp = NULL;
}
virtual void visit(AstCell* nodep) {
nodep->modp()->user3Inc();
nodep->modp()->user3Inc(); // Inc refs
m_instances[m_modp][nodep->modp()]++;
nodep->iterateChildren(*this);
}
virtual void visit(AstPragma* nodep) {
@@ -132,8 +128,9 @@ private:
//UINFO(0,"PRAG MARK "<<m_modp<<endl);
if (!m_modp) {
nodep->v3error("Inline pragma not under a module");
} else {
m_modp->user1(1);
} else if (m_modp->user2() == CIL_MAYBE
|| m_modp->user2() == CIL_NOTSOFT) {
m_modp->user2(CIL_USER);
}
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep); // Remove so don't propagate to upper cell...
} else if (nodep->pragType() == AstPragmaType::NO_INLINE_MODULE) {
@@ -156,30 +153,71 @@ private:
if (!nodep->packagep()) nodep->taskp(NULL);
nodep->iterateChildren(*this);
}
// Nop's to speed up the loop
virtual void visit(AstAlways* nodep) {
nodep->iterateChildren(*this);
m_stmtCnt++;
m_modp->user4Inc(); // statement count
}
virtual void visit(AstNodeAssign* nodep) {
// Don't count assignments, as they'll likely flatten out
// Still need to iterate though to nullify VarXRefs
int oldcnt = m_stmtCnt;
int oldcnt = m_modp->user4();
nodep->iterateChildren(*this);
m_stmtCnt = oldcnt;
m_modp->user4(oldcnt);
}
virtual void visit(AstNetlist* nodep) {
// Build user2, user3, and user4 for all modules.
// Also build m_allMods and m_instances.
nodep->iterateChildren(*this);
// Iterate through all modules in bottom-up order.
// Make a final inlining decision for each.
for (ModVec::reverse_iterator it=m_allMods.rbegin(); it!=m_allMods.rend(); ++it) {
AstNodeModule* modp = *it;
// If we're going to inline some modules into this one,
// update user4 (statement count) to reflect that:
int statements = modp->user4();
LocalInstanceMap& localsr = m_instances[modp];
for (LocalInstanceMap::iterator it = localsr.begin(); it != localsr.end(); ++it) {
AstNodeModule* childp = it->first;
if (childp->user1()) { // inlining child
statements += (childp->user4() * it->second);
}
}
modp->user4(statements);
int allowed = modp->user2();
int refs = modp->user3();
// Should we automatically inline this module?
// inlineMult = 2000 by default.
// If a mod*#refs is < this # nodes, can inline it
bool doit = ((allowed == CIL_USER)
|| ((allowed == CIL_MAYBE)
&& (refs==1
|| statements < INLINE_MODS_SMALLER
|| v3Global.opt.inlineMult() < 1
|| refs*statements < v3Global.opt.inlineMult())));
// Packages aren't really "under" anything so they confuse this algorithm
if (modp->castPackage()) doit = false;
UINFO(4, " Inline="<<doit<<" Possible="<<allowed
<<" Refs="<<refs<<" Stmts="<<statements<<" "<<modp<<endl);
modp->user1(doit);
}
}
//--------------------
// Default: Just iterate
virtual void visit(AstNode* nodep) {
nodep->iterateChildren(*this);
m_stmtCnt++;
if (m_modp) {
m_modp->user4Inc(); // Inc statement count
}
}
public:
// CONSTUCTORS
explicit InlineMarkVisitor(AstNode* nodep) {
m_modp = NULL;
m_stmtCnt = 0;
nodep->accept(*this);
}
virtual ~InlineMarkVisitor() {
@@ -187,6 +225,7 @@ public:
// Done with these, are not outputs
AstNode::user2ClearTree();
AstNode::user3ClearTree();
AstNode::user4ClearTree();
}
};
@@ -443,11 +482,13 @@ private:
// AstVar::user3() // bool Don't alias the user2, keep it as signal
// AstCell::user4 // AstCell* of the created clone
AstUser4InUse m_inuser4;
AstUser2InUse m_inuser2;
AstUser3InUse m_inuser3;
AstUser4InUse m_inuser4;
AstUser5InUse m_inuser5;
// STATE
AstNodeModule* m_modp; // Current module
AstNodeModule* m_modp; // Current module
V3Double0 m_statCells; // Statistic tracking
static int debug() {
@@ -575,8 +616,15 @@ public:
void V3Inline::inlineAll(AstNetlist* nodep) {
UINFO(2,__FUNCTION__<<": "<<endl);
InlineMarkVisitor mvisitor (nodep);
InlineVisitor visitor (nodep);
AstUser1InUse m_inuser1; // output of InlineMarkVisitor,
// input to InlineVisitor.
{
// Scoped to clean up temp userN's
InlineMarkVisitor mvisitor (nodep);
}
{
InlineVisitor visitor (nodep);
}
// Remove all modules that were inlined
// V3Dead will also clean them up, but if we have debug on, it's a good
// idea to avoid dumping the hugely exploded tree.
+1 -1
View File
@@ -46,7 +46,7 @@ public:
_ENUM_END
};
const char* ascii() const {
const char* names[] = {
const char* const names[] = {
// These must match the `begin_keywords values.
" ERROR",
"1364-1995",
+6 -6
View File
@@ -161,7 +161,7 @@ public:
if (!diddump && v3Global.opt.dumpTree()) {
diddump = true;
dump("linkdot-preerr",true);
v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("linkdot-preerr"));
v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("linkdot-preerr.tree"));
}
}
@@ -1482,7 +1482,7 @@ private:
m_unresolved = false; m_unlinkedScope = NULL;
}
string ascii() const {
static const char* names[] = { "NONE","PACKAGE","SCOPE","FINAL","MEMBER" };
static const char* const names[] = { "NONE","PACKAGE","SCOPE","FINAL","MEMBER" };
ostringstream sstr;
sstr<<"ds="<<names[m_dotPos];
sstr<<" dse"<<(void*)m_dotSymp;
@@ -2286,21 +2286,21 @@ public:
int V3LinkDot::debug() { return LinkDotState::debug(); }
void V3LinkDot::linkDotGuts(AstNetlist* rootp, VLinkDotStep step) {
if (LinkDotState::debug()>=5 || v3Global.opt.dumpTree()>=9) v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("prelinkdot"));
if (LinkDotState::debug()>=5 || v3Global.opt.dumpTree()>=9) v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("prelinkdot.tree"));
LinkDotState state (rootp, step);
LinkDotFindVisitor visitor(rootp,&state);
if (LinkDotState::debug()>=5 || v3Global.opt.dumpTree()>=9) v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("prelinkdot-find"));
if (LinkDotState::debug()>=5 || v3Global.opt.dumpTree()>=9) v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("prelinkdot-find.tree"));
if (step == LDS_PRIMARY || step == LDS_PARAMED) {
// Initial link stage, resolve parameters
LinkDotParamVisitor visitors(rootp,&state);
if (LinkDotState::debug()>=5 || v3Global.opt.dumpTree()>=9) v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("prelinkdot-param"));
if (LinkDotState::debug()>=5 || v3Global.opt.dumpTree()>=9) v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("prelinkdot-param.tree"));
}
else if (step == LDS_ARRAYED) {}
else if (step == LDS_SCOPED) {
// Well after the initial link when we're ready to operate on the flat design,
// process AstScope's. This needs to be separate pass after whole hierarchy graph created.
LinkDotScopeVisitor visitors(rootp,&state);
if (LinkDotState::debug()>=5 || v3Global.opt.dumpTree()>=9) v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("prelinkdot-scoped"));
if (LinkDotState::debug()>=5 || v3Global.opt.dumpTree()>=9) v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("prelinkdot-scoped.tree"));
}
else v3fatalSrc("Bad case");
state.dump();
+2 -2
View File
@@ -22,7 +22,7 @@
// VAR(BLOCKTEMP...
// if only referenced in a CFUNC, make it local to that CFUNC
// VAR(others
// if non-public, set before used, and in signle CFUNC, make it local
// if non-public, set before used, and in single CFUNC, make it local
//
//*************************************************************************
@@ -84,7 +84,7 @@ private:
virtual void visit(AstVarRef* nodep) {
VarFlags flags (nodep->varp());
if (flags.m_done) {
nodep->hiername(""); // Remove thisp->
nodep->hiername(""); // Remove this->
nodep->hierThis(true);
}
}
+38 -4
View File
@@ -410,6 +410,18 @@ V3LangCode V3Options::fileLanguage(const string &filename) {
//######################################################################
// Environment
string V3Options::getenvBuiltins(const string& var) {
if (var == "PERL") return getenvPERL();
else if (var == "SYSTEMC") return getenvSYSTEMC();
else if (var == "SYSTEMC_ARCH") return getenvSYSTEMC_ARCH();
else if (var == "SYSTEMC_INCLUDE") return getenvSYSTEMC_INCLUDE();
else if (var == "SYSTEMC_LIBDIR") return getenvSYSTEMC_LIBDIR();
else if (var == "VERILATOR_ROOT") return getenvVERILATOR_ROOT();
else {
return V3Os::getenvStr(var,"");
}
}
string V3Options::getenvPERL() {
return V3Os::getenvStr("PERL","perl");
}
@@ -665,8 +677,9 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char
else if ( onoff (sw, "-profile-cfuncs", flag/*ref*/) ) { m_profileCFuncs = flag; }
else if ( onoff (sw, "-public", flag/*ref*/) ) { m_public = flag; }
else if ( !strncmp(sw, "-pvalue+", strlen("-pvalue+"))) { addParameter(string(sw+strlen("-pvalue+")), false); }
else if ( onoff (sw, "-report-unoptflat", flag/*ref*/) ) { m_reportUnoptflat = flag; }
else if ( onoff (sw, "-relative-cfuncs", flag/*ref*/) ) { m_relativeCFuncs = flag; }
else if ( onoff (sw, "-relative-includes", flag/*ref*/) ) { m_relativeIncludes = flag; }
else if ( onoff (sw, "-report-unoptflat", flag/*ref*/) ) { m_reportUnoptflat = flag; }
else if ( onoff (sw, "-savable", flag/*ref*/) ) { m_savable = flag; }
else if ( !strcmp (sw, "-sc") ) { m_outFormatOk = true; m_systemC = true; }
else if ( onoff (sw, "-skip-identical", flag/*ref*/) ) { m_skipIdentical = flag; }
@@ -762,6 +775,11 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char
else if ( !strncmp (sw, "-G", strlen("-G"))) {
addParameter(string (sw+strlen("-G")), false);
}
else if ( !strcmp (sw, "-getenv") && (i+1)<argc ) {
shift;
cout<<V3Options::getenvBuiltins(argv[i])<<endl;
exit(0);
}
else if ( !strncmp (sw, "-I", 2)) {
addIncDirUser(parseFileArg(optdir, string (sw+strlen("-I"))));
}
@@ -910,8 +928,14 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char
}
else {
string msg = sw+strlen("-Wwarn-");
if (!(FileLine::globalWarnOff(msg, false))) {
fl->v3fatal("Unknown warning specified: "<<sw);
V3ErrorCode code (msg.c_str());
if (code == V3ErrorCode::EC_ERROR) {
if (!isFuture(msg)) {
fl->v3fatal("Unknown warning specified: "<<sw);
}
} else {
FileLine::globalWarnOff(code, false);
V3Error::pretendError(code, false);
}
}
}
@@ -976,6 +1000,15 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char
fl->v3fatal("Unknown setting for --x-assign: "<<argv[i]);
}
}
else if ( !strcmp (sw, "-x-initial") && (i+1)<argc) {
shift;
if (!strcmp (argv[i], "0")) { m_xInitial="0"; }
else if (!strcmp (argv[i], "fast")) { m_xInitial="fast"; }
else if (!strcmp (argv[i], "unique")) { m_xInitial="unique"; }
else {
fl->v3fatal("Unknown setting for --x-initial: "<<argv[i]);
}
}
else if ( !strcmp (sw, "-y") && (i+1)<argc ) {
shift; addIncDirUser (parseFileArg(optdir,string (argv[i])));
}
@@ -1177,8 +1210,9 @@ V3Options::V3Options() {
m_preprocOnly = false;
m_preprocNoLine = false;
m_public = false;
m_reportUnoptflat = false;
m_relativeCFuncs = true;
m_relativeIncludes = false;
m_reportUnoptflat = false;
m_savable = false;
m_skipIdentical = true;
m_stats = false;
+6 -2
View File
@@ -36,7 +36,6 @@
class V3OptionsImp;
class FileLine;
struct stat;
typedef vector<string> V3StringList;
typedef set<string> V3StringSet;
@@ -88,8 +87,9 @@ class V3Options {
bool m_pinsUint8; // main switch: --pins-uint8
bool m_profileCFuncs;// main switch: --profile-cfuncs
bool m_public; // main switch: --public
bool m_reportUnoptflat; // main switch: --report-unoptflat
bool m_relativeCFuncs; // main switch: --relative-cfuncs
bool m_relativeIncludes; // main switch: --relative-includes
bool m_reportUnoptflat; // main switch: --report-unoptflat
bool m_savable; // main switch: --savable
bool m_systemC; // main switch: --sc: System C instead of simple C++
bool m_skipIdentical;// main switch: --skip-identical
@@ -133,6 +133,7 @@ class V3Options {
string m_topModule; // main switch: --top-module
string m_unusedRegexp; // main switch: --unused-regexp
string m_xAssign; // main switch: --x-assign
string m_xInitial; // main switch: --x-initial
// Language is now held in FileLine, on a per-node basis. However we still
// have a concept of the default language at a global level.
@@ -243,6 +244,7 @@ class V3Options {
bool lintOnly() const { return m_lintOnly; }
bool ignc() const { return m_ignc; }
bool inhibitSim() const { return m_inhibitSim; }
bool relativeCFuncs() const { return m_relativeCFuncs; }
bool reportUnoptflat() const { return m_reportUnoptflat; }
bool vpi() const { return m_vpi; }
bool xInitialEdge() const { return m_xInitialEdge; }
@@ -274,6 +276,7 @@ class V3Options {
string topModule() const { return m_topModule; }
string unusedRegexp() const { return m_unusedRegexp; }
string xAssign() const { return m_xAssign; }
string xInitial() const { return m_xInitial; }
const V3StringSet& cppFiles() const { return m_cppFiles; }
const V3StringList& cFlags() const { return m_cFlags; }
@@ -329,6 +332,7 @@ class V3Options {
// Most of these may be built into the executable with --enable-defenv,
// see the README. If adding new variables, also see src/Makefile_obj.in
// Also add to V3Options::showVersion()
static string getenvBuiltins(const string& var);
static string getenvPERL();
static string getenvSYSTEMC();
static string getenvSYSTEMC_ARCH();
+2 -1
View File
@@ -1015,7 +1015,8 @@ public:
virtual ~OrderVisitor() {
// Stats
for (int type=0; type<OrderVEdgeType::_ENUM_END; type++) {
if (double count = double(m_statCut[type])) {
double count = double(m_statCut[type]);
if (count != 0.0) {
V3Stats::addStat(string("Order, cut, ")+OrderVEdgeType(type).ascii(), count);
}
}
+1 -1
View File
@@ -91,7 +91,7 @@ struct OrderVEdgeType {
_ENUM_END
};
const char* ascii() const {
static const char* names[] = {
static const char* const names[] = {
"%E-vedge", "VERTEX_INPUTS", "VERTEX_SETTLE", "VERTEX_LOGIC",
"VERTEX_VARSTD", "VERTEX_VARPRE", "VERTEX_VARPOST",
"VERTEX_VARPORD", "VERTEX_VARSETTLE", "VERTEX_LOOPBEGIN",
+3 -1
View File
@@ -206,7 +206,7 @@ uint64_t V3Os::memUsageBytes() {
return 0;
#else
// Highly unportable. Sorry
const char* statmFilename = "/proc/self/statm";
const char* const statmFilename = "/proc/self/statm";
FILE* fp = fopen(statmFilename,"r");
if (!fp) {
return 0;
@@ -215,8 +215,10 @@ uint64_t V3Os::memUsageBytes() {
if (7 != fscanf(fp, "%" VL_PRI64 "d %" VL_PRI64 "d %" VL_PRI64 "d %"
VL_PRI64 "d %" VL_PRI64 "d %" VL_PRI64 "d %" VL_PRI64 "d",
&size, &resident, &share, &text, &lib, &data, &dt)) {
fclose(fp);
return 0;
}
fclose(fp);
return (text + data) * getpagesize();
#endif
}
+1 -1
View File
@@ -744,7 +744,7 @@ void ParamVisitor::visitCell(AstCell* nodep) {
// Delete the parameters from the cell; they're not relevant any longer.
if (nodep->paramsp()) nodep->paramsp()->unlinkFrBackWithNext()->deleteTree();
UINFO(8," Done with "<<nodep<<endl);
//if (debug()>=10) v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("param-out"));
//if (debug()>=10) v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("param-out.tree"));
}
// Now remember to process the child module at the end of the module
+3 -1
View File
@@ -154,6 +154,8 @@ void V3ParseImp::parseFile(FileLine* fileline, const string& modfilename, bool i
// Parse it
if (!v3Global.opt.preprocOnly()) {
lexFile (modfilename);
} else {
m_ppBuffers.clear();
}
}
@@ -183,5 +185,5 @@ void V3Parse::parseFile(FileLine* fileline, const string& modname, bool inLibrar
m_impp->parseFile(fileline, modname, inLibrary, errmsg);
}
void V3Parse::ppPushText(V3ParseImp* impp, const string& text) {
impp->ppPushText(text);
if (text != "") impp->ppPushText(text);
}
+7
View File
@@ -119,6 +119,8 @@ class V3ParseImp {
deque<FileLine> m_lintState; // Current lint state for save/restore
deque<string> m_ppBuffers; // Preprocessor->lex buffer of characters to process
string m_tag; // Contents (if any) of current verilator tag
AstNode* m_tagNodep; // Points to the node to set to m_tag or NULL to not set.
public:
// Note these are an exception to using the filename as the debug type
static int debugBison() {
@@ -143,6 +145,10 @@ public:
void verilatorCmtLintSave();
void verilatorCmtLintRestore();
void verilatorCmtBad(const char* text);
void tag(const char* text);
void tagNodep(AstNode* nodep) { m_tagNodep = nodep; }
AstNode* tagNodep() const { return m_tagNodep;}
static double parseDouble(const char* text, size_t length, bool* successp = NULL);
void pushBeginKeywords(int state) { m_inBeginKwd++; m_lastVerilogState=state; }
bool popBeginKeywords() { if (m_inBeginKwd) { m_inBeginKwd--; return true; } else return false; }
@@ -218,6 +224,7 @@ public:
m_curBisonVal.token = 0;
m_prevBisonVal.token = 0;
// m_aheadVal not used as m_ahead = false
m_tagNodep = NULL;
}
~V3ParseImp();
void parserClear();
+1
View File
@@ -65,6 +65,7 @@ class V3PreProcImp;
#define VP_BACKQUOTE 311
#define VP_SYMBOL_JOIN 312
#define VP_DEFREF_JOIN 313
#define VP_JOIN 314
#define VP_PSL 350
+4
View File
@@ -126,6 +126,7 @@ drop [\032]
<STRIFY>{symbdef}`` { yyleng-=2; return (VP_SYMBOL_JOIN); }
<STRIFY>"`"{symbdef} { return (VP_DEFREF); }
<STRIFY>"`"{symbdef}`` { yyleng-=2; return (VP_DEFREF_JOIN); }
<STRIFY>`` { yyleng-=2; return (VP_JOIN); }
<STRIFY>{crnl} { linenoInc(); yytext=(char*)"\n"; yyleng=1; return(VP_WHITE); }
<STRIFY>{wsn}+ { return (VP_WHITE); }
<STRIFY>{drop} { }
@@ -229,6 +230,7 @@ drop [\032]
}}
<ARGMODE>"`"{symbdef} { appendDefValue(yytext,yyleng); } /* defref in defref - outer macro expands first */
<ARGMODE>"`"{symbdef}`` { appendDefValue(yytext,yyleng); } /* defref in defref - outer macro expands first */
<ARGMODE>`` { appendDefValue(yytext,yyleng); } /* defref in defref - outer macro expands first */
<ARGMODE>[^\/\*\n\r\\(,){}\[\]\"`]+ |
<ARGMODE>. { appendDefValue(yytext,yyleng); }
@@ -253,12 +255,14 @@ drop [\032]
/* symbdef prevents normal lex rules from making `\`"foo a symbol {`"foo} instead of a BACKQUOTE */
<INITIAL>"`"{symbdef} { return (VP_DEFREF); }
<INITIAL>"`"{symbdef}`` { yyleng-=2; return (VP_DEFREF_JOIN); }
<INITIAL>`` { yyleng-=2; return (VP_JOIN); }
/* Generics */
<INITIAL>{crnl} { linenoInc(); yytext=(char*)"\n"; yyleng=1; return(VP_WHITE); }
<INITIAL><<EOF>> { yyterminate(); } /* A "normal" EOF */
<INITIAL>{symb} { return (VP_SYMBOL); }
<INITIAL>{symb}`` { yyleng-=2; return (VP_SYMBOL_JOIN); }
<INITIAL>`` { yyleng-=2; return (VP_JOIN); }
<INITIAL>{wsn}+ { return (VP_WHITE); }
<INITIAL>{drop} { }
<INITIAL>[\r] { }
+71 -35
View File
@@ -204,6 +204,14 @@ private:
int getStateToken();
int getFinalToken(string& buf);
ProcState state() const { return m_states.top(); }
bool stateIsDefname() const {
return state()==ps_DEFNAME_UNDEF
|| state()==ps_DEFNAME_DEFINE
|| state()==ps_DEFNAME_IFDEF
|| state()==ps_DEFNAME_IFNDEF
|| state()==ps_DEFNAME_ELSIF;
}
void statePush(ProcState state) {
m_states.push(state);
}
@@ -477,6 +485,7 @@ const char* V3PreProcImp::tokenName(int tok) {
case VP_ERROR : return("ERROR");
case VP_IFDEF : return("IFDEF");
case VP_IFNDEF : return("IFNDEF");
case VP_JOIN : return("JOIN");
case VP_INCLUDE : return("INCLUDE");
case VP_LINE : return("LINE");
case VP_STRIFY : return("STRIFY");
@@ -643,7 +652,15 @@ string V3PreProcImp::defineSubst(V3DefineRef* refp) {
if (iter != argValueByName.end()) {
// Substitute
string subst = iter->second;
out += subst;
if (subst == "") {
// Normally `` is removed later, but with no token after, we're otherwise
// stuck, so remove proceeding ``
if (out.size()>=2 && out.substr(out.size()-2) == "``") {
out = out.substr(0, out.size()-2);
}
} else {
out += subst;
}
} else {
out += argName;
}
@@ -656,6 +673,7 @@ string V3PreProcImp::defineSubst(V3DefineRef* refp) {
// Don't put out the ``, we're forming an escape which will not expand further later
} else {
out += "``"; // `` must get removed later, as `FOO```BAR must pre-expand FOO and BAR
// See also removal in empty substitutes above
}
cp++;
continue;
@@ -806,7 +824,7 @@ int V3PreProcImp::getRawToken() {
yyourtext(rtncmt.c_str(), rtncmt.length());
m_lineCmt = "";
if (yyourleng()) m_rawAtBol = (yyourtext()[yyourleng()-1]=='\n');
if (m_states.top()==ps_DEFVALUE) {
if (state()==ps_DEFVALUE) {
V3PreLex::s_currentLexp->appendDefValue(yyourtext(),yyourleng());
goto next_tok;
} else {
@@ -839,7 +857,7 @@ void V3PreProcImp::debugToken(int tok, const char* cmtp) {
while ((pos=buf.find("\r")) != string::npos) { buf.replace(pos, 1, "\\r"); }
fprintf (stderr, "%d: %s %s %s(%d) dr%d: <%d>%-10s: %s\n",
m_lexp->m_tokFilelinep->lineno(), cmtp, m_off?"of":"on",
procStateName(m_states.top()), (int)m_states.size(), (int)m_defRefs.size(),
procStateName(state()), (int)m_states.size(), (int)m_defRefs.size(),
m_lexp->currentStartState(), tokenName(tok), buf.c_str());
}
}
@@ -853,11 +871,10 @@ int V3PreProcImp::getStateToken() {
next_tok:
if (isEof()) return VP_EOF;
int tok = getRawToken();
ProcState state = m_states.top();
// Most states emit white space and comments between tokens. (Unless collecting a string)
if (tok==VP_WHITE && state !=ps_STRIFY) return (tok);
if (tok==VP_BACKQUOTE && state !=ps_STRIFY) { tok = VP_TEXT; }
if (tok==VP_WHITE && state() !=ps_STRIFY) return (tok);
if (tok==VP_BACKQUOTE && state() !=ps_STRIFY) { tok = VP_TEXT; }
if (tok==VP_COMMENT) {
if (!m_off) {
if (m_lexp->m_keepComments == KEEPCMT_SUB) {
@@ -907,7 +924,7 @@ int V3PreProcImp::getStateToken() {
// FALLTHRU, handle as with VP_SYMBOL_JOIN
}
}
if (tok==VP_SYMBOL_JOIN || tok==VP_DEFREF_JOIN) { // not else if, can fallthru from above if()
if (tok==VP_SYMBOL_JOIN || tok==VP_DEFREF_JOIN || tok==VP_JOIN) { // not else if, can fallthru from above if()
// a`` -> string doesn't include the ``, so can just grab next and continue
string out (yyourtext(),yyourleng());
UINFO(5,"`` LHS:"<<out<<endl);
@@ -918,7 +935,7 @@ int V3PreProcImp::getStateToken() {
}
// Deal with some special parser states
switch (state) {
switch (state()) {
case ps_TOP: {
break;
}
@@ -929,17 +946,17 @@ int V3PreProcImp::getStateToken() {
case ps_DEFNAME_ELSIF: {
if (tok==VP_SYMBOL) {
m_lastSym.assign(yyourtext(),yyourleng());
if (state==ps_DEFNAME_IFDEF
|| state==ps_DEFNAME_IFNDEF) {
if (state()==ps_DEFNAME_IFDEF
|| state()==ps_DEFNAME_IFNDEF) {
bool enable = defExists(m_lastSym);
UINFO(4,"Ifdef "<<m_lastSym<<(enable?" ON":" OFF")<<endl);
if (state==ps_DEFNAME_IFNDEF) enable = !enable;
if (state()==ps_DEFNAME_IFNDEF) enable = !enable;
m_ifdefStack.push(VPreIfEntry(enable,false));
if (!enable) parsingOff();
statePop();
goto next_tok;
}
else if (state==ps_DEFNAME_ELSIF) {
else if (state()==ps_DEFNAME_ELSIF) {
if (m_ifdefStack.empty()) {
error("`elsif with no matching `if\n");
} else {
@@ -955,7 +972,7 @@ int V3PreProcImp::getStateToken() {
statePop();
goto next_tok;
}
else if (state==ps_DEFNAME_UNDEF) {
else if (state()==ps_DEFNAME_UNDEF) {
if (!m_off) {
UINFO(4,"Undef "<<m_lastSym<<endl);
undef(m_lastSym);
@@ -963,7 +980,7 @@ int V3PreProcImp::getStateToken() {
statePop();
goto next_tok;
}
else if (state==ps_DEFNAME_DEFINE) {
else if (state()==ps_DEFNAME_DEFINE) {
// m_lastSym already set.
stateChange(ps_DEFFORM);
m_lexp->pushStateDefForm();
@@ -1079,7 +1096,16 @@ int V3PreProcImp::getStateToken() {
m_defRefs.pop(); VL_DANGLING(refp);
if (m_defRefs.empty()) {
statePop();
if (state() == ps_JOIN) { // Handle {left}```FOO(ARG) where `FOO(ARG) might be empty
if (m_joinStack.empty()) fatalSrc("`` join stack empty, but in a ``");
string lhs = m_joinStack.top(); m_joinStack.pop();
out = lhs+out;
UINFO(5,"``-end-defarg Out:"<<out<<endl);
statePop();
}
if (!m_off) unputDefrefString(out);
// Prevent problem when EMPTY="" in `ifdef NEVER `define `EMPTY
else if (stateIsDefname()) unputDefrefString("__IF_OFF_IGNORED_DEFINE");
m_lexp->m_parenLevel = 0;
}
else { // Finished a defref inside a upper defref
@@ -1163,7 +1189,10 @@ int V3PreProcImp::getStateToken() {
statePop();
goto next_tok;
} else if (tok==VP_EOF || tok==VP_WHITE || tok == VP_COMMENT || tok==VP_STRING) {
error((string)"Expecting symbol to terminate ``; whitespace etc cannot follow ``. Found: "+tokenName(tok)+"\n");
// Other compilers just ignore this, so no warning
// "Expecting symbol to terminate ``; whitespace etc cannot follow ``. Found: "+tokenName(tok)+"\n"
string lhs = m_joinStack.top(); m_joinStack.pop();
unputString(lhs);
statePop();
goto next_tok;
} else {
@@ -1214,7 +1243,7 @@ int V3PreProcImp::getStateToken() {
case VP_INCLUDE:
if (!m_off) {
statePush(ps_INCNAME);
}
} // Else incname looks like normal text, that will be ignored
goto next_tok;
case VP_UNDEF:
statePush(ps_DEFNAME_UNDEF);
@@ -1278,27 +1307,34 @@ int V3PreProcImp::getStateToken() {
else {
string params = defParams(name);
if (params=="0" || params=="") { // Found, as simple substitution
if (m_off) {
goto next_tok;
}
else {
string out;
if (!m_off) {
V3DefineRef tempref(name, "");
string out = defineSubst(&tempref);
// Similar code in parenthesized define (Search for END_OF_DEFARG)
//NOP: out = m_preprocp->defSubstitute(out);
if (m_defRefs.empty()) {
// Just output the substitution
unputDefrefString(out);
} else {
// Inside another define.
// Can't subst now, or
// `define a x,y
// foo(`a,`b) would break because a contains comma
V3DefineRef* refp = &(m_defRefs.top());
refp->nextarg(refp->nextarg()+m_lexp->m_defValue+out); m_lexp->m_defValue="";
}
goto next_tok;
out = defineSubst(&tempref);
}
// Similar code in parenthesized define (Search for END_OF_DEFARG)
//NOP: out = m_preprocp->defSubstitute(out);
if (m_defRefs.empty()) {
// Just output the substitution
if (state() == ps_JOIN) { // Handle {left}```FOO where `FOO might be empty
if (m_joinStack.empty()) fatalSrc("`` join stack empty, but in a ``");
string lhs = m_joinStack.top(); m_joinStack.pop();
out = lhs+out;
UINFO(5,"``-end-defref Out:"<<out<<endl);
statePop();
}
if (!m_off) unputDefrefString(out);
// Prevent problem when EMPTY="" in `ifdef NEVER `define `EMPTY
else if (stateIsDefname()) unputDefrefString("__IF_OFF_IGNORED_DEFINE");
} else {
// Inside another define.
// Can't subst now, or
// `define a x,y
// foo(`a,`b) would break because a contains comma
V3DefineRef* refp = &(m_defRefs.top());
refp->nextarg(refp->nextarg()+m_lexp->m_defValue+out); m_lexp->m_defValue="";
}
goto next_tok;
}
else { // Found, with parameters
UINFO(4,"Defref `"<<name<<" => parameterized"<<endl);
+71 -388
View File
@@ -45,153 +45,6 @@
#include "V3Global.h"
#include "V3Slice.h"
#include "V3Ast.h"
#include <vector>
class SliceCloneVisitor : public AstNVisitor {
// NODE STATE
// Inputs:
// AstArraySel::user1p() -> AstVarRef. The VarRef that the final ArraySel points to
// AstNodeAssign::user2() -> int. The number of clones needed for this assign
// AstArraySel::user3() -> bool. Error detected
// STATE
vector<vector<unsigned> > m_selBits; // Indexes of the ArraySel we are expanding
int m_vecIdx; // Current vector index
unsigned m_depth; // Number of ArraySel's from the VarRef
AstVarRef* m_refp; // VarRef under this ArraySel
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
// VISITORS
virtual void visit(AstArraySel* nodep) {
if (!nodep->backp()->castArraySel()) {
// This is the top of an ArraySel, setup for iteration
m_refp = nodep->user1p()->castVarRef();
m_vecIdx += 1;
if (m_vecIdx == (int)m_selBits.size()) {
m_selBits.push_back(vector<unsigned>());
AstVar* varp = m_refp->varp();
pair<uint32_t,uint32_t> arrDim = varp->dtypep()->dimensions(false);
uint32_t dimensions = arrDim.second;
// for 3-dimensions we want m_selBits[m_vecIdx]=[0,0,0]
for (uint32_t i = 0; i < dimensions; ++i) {
m_selBits[m_vecIdx].push_back(0);
}
}
}
nodep->iterateChildren(*this);
if (nodep->fromp()->castVarRef()) {
m_depth = 0;
} else {
++m_depth;
}
// Check if m_selBits has overflowed
if (m_selBits[m_vecIdx][m_depth] >= nodep->length()) {
m_selBits[m_vecIdx][m_depth] = 0;
if (m_depth + 1 < m_selBits[m_vecIdx].size())
m_selBits[m_vecIdx][m_depth+1] += 1;
}
// Reassign the bitp()
if (nodep->length() > 1) {
if (AstConst* bitp = nodep->bitp()->castConst()) {
AstUnpackArrayDType* adtypep = nodep->fromp()->dtypep()->skipRefp()->castUnpackArrayDType();
if (!adtypep) nodep->v3fatalSrc("slice select tried to expand an array without an ArrayDType");
unsigned idx = nodep->start() + m_selBits[m_vecIdx][m_depth] - adtypep->lsb();
if (adtypep->rangep()->littleEndian()) { // Little must iterate backwards
idx = adtypep->rangep()->elementsConst() - 1 - idx;
}
AstNode* constp = new AstConst(bitp->fileline(), V3Number(bitp->fileline(), bitp->castConst()->num().width(), idx));
bitp->replaceWith(constp);
} else {
nodep->v3error("Unsupported: Only constants supported in slices");
}
}
if (!nodep->backp()->castArraySel()) {
// Top ArraySel, increment m_selBits
m_selBits[m_vecIdx][0] += 1;
}
nodep->length(1);
}
virtual void visit(AstNodeAssign* nodep) {
if (nodep->user2() < 2) return; // Don't need clones
m_selBits.clear();
UINFO(4, "Cloning "<<nodep->user2()<<" times: "<<nodep<<endl);
for (int i = 0; i < nodep->user2(); ++i) {
// Clone the node and iterate over the clone
m_vecIdx = -1;
AstNodeAssign* clonep = nodep->cloneTree(false)->castNodeAssign();
clonep->iterateChildren(*this);
nodep->addNextHere(clonep);
}
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
}
// Not all Uniop nodes should be cloned down to a single bit
void cloneUniop(AstNodeUniop* nodep) {
if (nodep->user2() < 2) return; // Don't need clones
m_selBits.clear();
UINFO(4, "Cloning "<<nodep->user2()<<" times: "<<nodep<<endl);
AstNode* lhsp = NULL;
for (int i = 0; i < nodep->user2(); ++i) {
// Clone the node and iterate over the clone
m_vecIdx = -1;
AstNodeUniop* clonep = nodep->cloneTree(false)->castNodeUniop();
clonep->iterateChildren(*this);
if (!lhsp) lhsp = clonep;
else {
switch (nodep->type()) {
case AstType::atRedOr:
lhsp = new AstOr(nodep->fileline(), lhsp, clonep);
break;
case AstType::atRedAnd:
lhsp = new AstAnd(nodep->fileline(), lhsp, clonep);
break;
case AstType::atRedXor:
lhsp = new AstXor(nodep->fileline(), lhsp, clonep);
break;
case AstType::atRedXnor:
lhsp = new AstXnor(nodep->fileline(), lhsp, clonep);
break;
default:
nodep->v3fatalSrc("Unsupported: Unary operation on multiple packed dimensions");
break;
}
}
}
nodep->replaceWith(lhsp);
nodep->deleteTree(); VL_DANGLING(nodep);
}
virtual void visit(AstRedOr* nodep) {
cloneUniop(nodep);
}
virtual void visit(AstRedAnd* nodep) {
cloneUniop(nodep);
}
virtual void visit(AstRedXor* nodep) {
cloneUniop(nodep);
}
virtual void visit(AstRedXnor* nodep) {
cloneUniop(nodep);
}
virtual void visit(AstNode* nodep) {
// Default: Just iterate
nodep->iterateChildren(*this);
}
public:
// CONSTUCTORS
explicit SliceCloneVisitor(AstNode* nodep) {
nodep->accept(*this);
}
virtual ~SliceCloneVisitor() {}
};
//*************************************************************************
@@ -201,18 +54,10 @@ class SliceVisitor : public AstNVisitor {
// AstNodeAssign::user1() -> bool. True if find is complete
// AstUniop::user1() -> bool. True if find is complete
// AstArraySel::user1p() -> AstVarRef. The VarRef that the final ArraySel points to
// AstNode::user2() -> int. The number of clones needed for this node
AstUser1InUse m_inuser1;
AstUser2InUse m_inuser2;
AstUser3InUse m_inuser3;
// TYPEDEFS
typedef pair<uint32_t, uint32_t> ArrayDimensions; // Array Dimensions (packed, unpacked)
// STATE
AstNode* m_assignp; // Assignment we are under
AstNodeVarRef* m_lhsVarRefp; // Var on the LHS
bool m_extend; // We have found an extend node
bool m_assignError; // True if the current assign already has an error
// METHODS
@@ -222,265 +67,103 @@ class SliceVisitor : public AstNVisitor {
return level;
}
unsigned explicitDimensions(AstArraySel* nodep) {
// Find out how many explicit dimensions are in a given ArraySel.
unsigned dim = 0;
AstNode* fromp = nodep;
AstArraySel* selp;
do {
selp = fromp->castArraySel();
if (!selp) {
nodep->user1p(fromp->castVarRef());
selp = NULL;
break;
} else {
fromp = selp->fromp();
if (fromp) ++dim;
}
} while (fromp && selp);
if (!nodep->user1p()) nodep->v3fatalSrc("Couldn't find VarRef under the ArraySel");
return dim;
}
int countClones(AstArraySel* nodep) {
// Count how many clones we need to make from this ArraySel
int clones = 1;
AstNode* fromp = nodep;
AstArraySel* selp;
do {
selp = fromp->castArraySel();
fromp = (selp) ? selp->fromp() : NULL;
if (fromp && selp) clones *= selp->length();
} while (fromp && selp);
return clones;
}
AstArraySel* insertImplicit(AstNode* nodep, unsigned startDim, unsigned numDimensions) {
// Insert any implicit slices as explicit slices (ArraySel nodes).
// Return a new pointer to replace nodep() in the ArraySel.
UINFO(9," insertImplicit (startDim="<<startDim<<",c="<<numDimensions<<") "<<nodep<<endl);
AstVarRef* refp = nodep->user1p()->castVarRef();
if (!refp) nodep->v3fatalSrc("No VarRef in user1 of node "<<nodep);
AstVar* varp = refp->varp();
AstNode* topp = nodep;
for (unsigned i = startDim; i < startDim + numDimensions; ++i) {
AstNodeDType* dtypep = varp->dtypep()->dtypeDimensionp(i-1);
AstUnpackArrayDType* adtypep = dtypep->castUnpackArrayDType();
if (!adtypep) nodep->v3fatalSrc("insertImplicit tried to expand an array without an ArrayDType");
vlsint32_t msb = adtypep->msb();
vlsint32_t lsb = adtypep->lsb();
if (lsb > msb) {
// Below code assumes big bit endian; just works out if we swap
int x = msb; msb = lsb; lsb = x;
}
UINFO(9," ArraySel-child: "<<topp<<endl);
AstArraySel* newp = new AstArraySel(nodep->fileline(), topp,
// Arrays are zero-based so index 0 is always lsb (e.g. lsb-lsb -> 0)
new AstConst(nodep->fileline(), 0));
if (!newp->dtypep()) {
newp->v3fatalSrc("ArraySel dtyping failed when resolving slice"); // see ArraySel constructor
}
newp->user1p(refp);
newp->start(lsb);
newp->length(msb - lsb + 1);
topp = newp;
}
return topp->castArraySel();
}
// VISITORS
virtual void visit(AstVarRef* nodep) {
// The LHS/RHS of an Assign may be to a Var that is an array. In this
// case we need to create a slice across the entire Var
if (m_assignp && !nodep->backp()->castArraySel()) {
pair<uint32_t,uint32_t> arrDim = nodep->varp()->dtypep()->dimensions(false);
uint32_t dimensions = arrDim.second; // unpacked only
if (dimensions > 0) {
AstVarRef* clonep = nodep->cloneTree(false);
clonep->user1p(nodep);
AstNode* newp = insertImplicit(clonep, 1, dimensions);
nodep->replaceWith(newp); VL_DANGLING(nodep);
newp->accept(*this);
}
}
}
virtual void visit(AstExtend* nodep) {
m_extend = true;
if (m_assignp && m_assignp->user2() > 1 && !m_assignError) {
m_assignp->v3error("Unsupported: Assignment between unpacked arrays of different dimensions");
AstNode* cloneAndSel(AstNode* nodep, int elements, int offset) {
// Insert an ArraySel, except for a few special cases
AstUnpackArrayDType* arrayp = nodep->dtypep()->skipRefp()->castUnpackArrayDType();
if (!arrayp) { // V3Width should have complained, but...
if (!m_assignError) nodep->v3error(nodep->prettyTypeName()<<" is not an unpacked array, but is in an unpacked array context");
m_assignError = true;
return nodep->cloneTree(false); // Likely will cause downstream errors
}
nodep->iterateChildren(*this);
}
virtual void visit(AstConst* nodep) {
m_extend = true;
if (m_assignp && m_assignp->user2() > 1 && !m_assignError) {
m_assignp->v3error("Unsupported: Assignment between a constant and an array slice");
if (arrayp->rangep()->elementsConst() != elements) {
if (!m_assignError) nodep->v3error("Slices of arrays in assignments have different unpacked dimensions, "
<<elements<<" versus "<<arrayp->rangep()->elementsConst());
m_assignError = true;
elements = 1; offset = 0;
}
}
virtual void visit(AstArraySel* nodep) {
if (!m_assignp) return;
if (nodep->user3()) return; // Prevent recursion on just created nodes
unsigned dim = explicitDimensions(nodep);
AstVarRef* refp = nodep->user1p()->castVarRef();
pair<uint32_t,uint32_t> arrDim = refp->varp()->dtypep()->dimensions(false);
uint32_t implicit = (arrDim.second) - dim;
if (implicit > 0) {
AstArraySel* newp = insertImplicit(nodep->cloneTree(false), dim+1, implicit);
nodep->replaceWith(newp); nodep = newp;
nodep->user3(true);
}
int clones = countClones(nodep);
if (m_assignp->user2() > 0 && m_assignp->user2() != clones) {
m_assignp->v3error("Slices of arrays in assignments must have the same unpacked dimensions");
} else if (!m_assignp->user2()) {
if (m_extend && clones > 1 && !m_assignError) {
m_assignp->v3error("Unsupported: Assignment between unpacked arrays of different dimensions");
m_assignError = true;
AstNode* newp;
if (AstInitArray* initp = nodep->castInitArray()) {
UINFO(9," cloneInitArray("<<elements<<","<<offset<<") "<<nodep<<endl);
AstNode* itemp = initp->initsp();
int leOffset = !arrayp->rangep()->littleEndian() ? arrayp->rangep()->elementsConst()-1-offset : offset;
for (int pos = 0; itemp && pos < leOffset; ++pos) {
itemp = itemp->nextp();
}
if (clones > 1 && !refp->lvalue() && refp->varp() == m_lhsVarRefp->varp()
&& !m_assignp->castAssignDly() && !m_assignError) {
// LHS Var != RHS Var for a non-delayed assignment
m_assignp->v3error("Unsupported: Slices in a non-delayed assignment with the same Var on both sides");
m_assignError = true;
if (!itemp) {
nodep->v3error("Array initialization has too few elements, need element "<<offset);
itemp = initp->initsp();
}
m_assignp->user2(clones);
newp = itemp->cloneTree(false);
}
}
virtual void visit(AstSel* nodep) {
m_extend = true;
if (m_assignp && m_assignp->user2() > 1 && !m_assignError) {
m_assignp->v3error("Unsupported: Assignment between unpacked arrays of different dimensions");
else if (AstNodeCond* snodep = nodep->castNodeCond()) {
UINFO(9," cloneCond("<<elements<<","<<offset<<") "<<nodep<<endl);
return snodep->cloneType(snodep->condp()->cloneTree(false),
cloneAndSel(snodep->expr1p(), elements, offset),
cloneAndSel(snodep->expr2p(), elements, offset));
}
else if (nodep->castArraySel()
|| nodep->castNodeVarRef()
|| nodep->castNodeSel()) {
UINFO(9," cloneSel("<<elements<<","<<offset<<") "<<nodep<<endl);
int leOffset = !arrayp->rangep()->littleEndian() ? arrayp->rangep()->elementsConst()-1-offset : offset;
newp = new AstArraySel(nodep->fileline(), nodep->cloneTree(false), leOffset);
}
else {
if (!m_assignError) nodep->v3error(nodep->prettyTypeName()<<" unexpected in assignment to unpacked array");
m_assignError = true;
newp = nodep->cloneTree(false); // Likely will cause downstream errors
}
nodep->iterateChildren(*this);
}
virtual void visit(AstNodeCond* nodep) {
// The conditional must be a single bit so only look at the expressions
nodep->expr1p()->accept(*this);
nodep->expr2p()->accept(*this);
// Downstream data type may have changed; propagate up
nodep->dtypeFrom(nodep->expr1p());
}
// Return the first AstVarRef under the node
AstVarRef* findVarRefRecurse(AstNode* nodep) {
AstVarRef* refp = nodep->castVarRef();
if (refp) return refp;
if (nodep->op1p()) {
refp = findVarRefRecurse(nodep->op1p());
if (refp) return refp;
}
if (nodep->op2p()) {
refp = findVarRefRecurse(nodep->op2p());
if (refp) return refp;
}
if (nodep->op3p()) {
refp = findVarRefRecurse(nodep->op3p());
if (refp) return refp;
}
if (nodep->op4p()) {
refp = findVarRefRecurse(nodep->op4p());
if (refp) return refp;
}
if (nodep->nextp()) {
refp = findVarRefRecurse(nodep->nextp());
if (refp) return refp;
}
return NULL;
}
void findImplicit(AstNodeAssign* nodep) {
if (m_assignp) nodep->v3fatalSrc("Found a NodeAssign under another NodeAssign");
m_assignp = nodep;
m_assignError = false;
m_extend = false;
nodep->user1(true);
// Record the LHS Var so we can check if the Var on the RHS is the same
m_lhsVarRefp = findVarRefRecurse(nodep->lhsp());
if (!m_lhsVarRefp) nodep->v3fatalSrc("Couldn't find a VarRef on the LHSP of an Assign");
// Iterate children looking for ArraySel nodes. From that we get the number of elements
// in the array so we know how many times we need to clone this assignment.
nodep->iterateChildren(*this);
if (nodep->user2() > 1) SliceCloneVisitor scv(nodep);
m_assignp = NULL;
return newp;
}
virtual void visit(AstNodeAssign* nodep) {
if (!nodep->user1()) {
// Cleanup initArrays
if (AstInitArray* initp = nodep->rhsp()->castInitArray()) {
//if (debug()>=9) nodep->dumpTree(cout, "-InitArrayIn: ");
AstNode* newp = NULL;
for (int pos = 0; AstNode* itemp=initp->initsp(); ++pos) {
int index = initp->posIndex(pos);
AstNode* lhsp = new AstArraySel(nodep->fileline(),
nodep->lhsp()->cloneTree(false),
index);
newp = AstNode::addNext(newp, nodep->cloneType(lhsp, itemp->unlinkFrBack()));
// Deleted from list of items without correcting posIndex, but that's ok as about
// to delete the entire InitArray
// Called recursively on newly created assignments
if (!nodep->user1()
&& !nodep->castAssignAlias()) {
nodep->user1(true);
m_assignError = false;
if (debug()>=9) { cout<<endl; nodep->dumpTree(cout," Deslice-In: "); }
AstNodeDType* dtp = nodep->lhsp()->dtypep()->skipRefp();
if (AstUnpackArrayDType* arrayp = dtp->castUnpackArrayDType()) {
// Left and right could have different msb/lsbs/endianness, but #elements is common
// and all variables are realigned to start at zero
// Assign of a little endian'ed slice to a big endian one must reverse the elements
AstNode* newlistp = NULL;
int elements = arrayp->rangep()->elementsConst();
for (int offset = 0; offset < elements; ++offset) {
AstNode* newp = nodep->cloneType // AstNodeAssign
(cloneAndSel(nodep->lhsp(), elements, offset),
cloneAndSel(nodep->rhsp(), elements, offset));
if (debug()>=9) { newp->dumpTree(cout,"-new "); }
newlistp = AstNode::addNextNull(newlistp, newp);
}
//if (debug()>=9) newp->dumpTreeAndNext(cout, "-InitArrayOut: ");
nodep->replaceWith(newp);
pushDeletep(nodep); VL_DANGLING(nodep);
return; // Will iterate in a moment
nodep->replaceWith(newlistp); nodep->deleteTree(); VL_DANGLING(nodep);
if (debug()>=9) { cout<<endl; nodep->dumpTree(cout," Deslice-Dn: "); }
// Normal edit iterator will now iterate on all of the expansion assignments
// This will potentially call this function again to resolve next level of slicing
return;
}
// Hasn't been searched for implicit slices yet
findImplicit(nodep);
m_assignp = nodep;
nodep->iterateChildren(*this);
m_assignp = NULL;
}
}
void expandUniOp(AstNodeUniop* nodep) {
if (!nodep->user1()) {
nodep->user1(true);
unsigned dim = 0;
if (AstArraySel* selp = nodep->lhsp()->castArraySel()) {
// We have explicit dimensions, either packed or unpacked
dim = explicitDimensions(selp);
}
if (dim == 0 && !nodep->lhsp()->castVarRef()) {
// No ArraySel nor VarRef, not something we can expand
nodep->iterateChildren(*this);
} else {
AstVarRef* refp = findVarRefRecurse(nodep->lhsp());
ArrayDimensions varDim = refp->varp()->dtypep()->dimensions(false);
if ((int)(dim - varDim.second) < 0) {
// Unpacked dimensions are referenced first, make sure we have them all
nodep->v3error("Unary operator used across unpacked dimensions");
}
}
virtual void visit(AstInitArray* nodep) {
if (m_assignp) {
nodep->v3fatalSrc("Array initialization should have been removed earlier");
}
}
virtual void visit(AstRedOr* nodep) {
expandUniOp(nodep);
}
virtual void visit(AstRedAnd* nodep) {
expandUniOp(nodep);
}
virtual void visit(AstRedXor* nodep) {
expandUniOp(nodep);
}
virtual void visit(AstRedXnor* nodep) {
expandUniOp(nodep);
}
void expandBiOp(AstNodeBiop* nodep) {
if (!nodep->user1()) {
nodep->user1(true);
// If it's a unpacked array, blow it up into comparing each element
// If it's an unpacked array, blow it up into comparing each element
AstNodeDType* fromDtp = nodep->lhsp()->dtypep()->skipRefp();
UINFO(9, " Bi-Eq/Neq expansion "<<nodep<<endl);
if (AstUnpackArrayDType* adtypep = fromDtp->castUnpackArrayDType()) {
AstNodeBiop* logp = NULL;
for (int index = adtypep->rangep()->lsbConst();
index <= adtypep->rangep()->msbConst(); ++index) {
for (int index = 0; index < adtypep->rangep()->elementsConst(); ++index) {
// EQ(a,b) -> LOGAND(EQ(ARRAYSEL(a,0), ARRAYSEL(b,0)), ...[1])
AstNodeBiop* clonep = nodep->cloneType
(new AstArraySel(nodep->fileline(),
@@ -536,7 +219,7 @@ public:
// CONSTUCTORS
explicit SliceVisitor(AstNetlist* rootp) {
m_assignp = NULL;
m_lhsVarRefp = NULL;
m_assignError = false;
rootp->accept(*this);
}
virtual ~SliceVisitor() {}
+9 -5
View File
@@ -217,11 +217,12 @@ public:
V3Stats::addStat(m_stage, "Vars, unpacked arrayed", m_statVarArray);
V3Stats::addStat(m_stage, "Vars, clock attribute", m_statVarClock);
V3Stats::addStat(m_stage, "Var space, non-arrays, bytes", m_statVarBytes);
if (m_statVarScpBytes) {
if (m_statVarScpBytes!=0.0) {
V3Stats::addStat(m_stage, "Var space, scoped, bytes", m_statVarScpBytes);
}
for (unsigned i=0; i<m_statVarWidths.size(); i++) {
if (double count = double(m_statVarWidths.at(i))) {
double count = double(m_statVarWidths.at(i));
if (count != 0.0) {
if (v3Global.opt.statsVars()) {
NameMap& nameMapr = m_statVarWidthNames.at(i);
for (NameMap::iterator it=nameMapr.begin(); it!=nameMapr.end(); ++it) {
@@ -236,20 +237,23 @@ public:
}
// Node types
for (int type=0; type<AstType::_ENUM_END; type++) {
if (double count = double(m_statTypeCount.at(type))) {
double count = double(m_statTypeCount.at(type));
if (count != 0.0) {
V3Stats::addStat(m_stage, string("Node count, ")+AstType(type).ascii(), count);
}
}
for (int type=0; type<AstType::_ENUM_END; type++) {
for (int type2=0; type2<AstType::_ENUM_END; type2++) {
if (double count = double(m_statAbove[type][type2])) {
double count = double(m_statAbove[type][type2]);
if (count != 0.0) {
V3Stats::addStat(m_stage, string("Node pairs, ")+AstType(type).ascii()+"_"+AstType(type2).ascii(), count);
}
}
}
// Branch pred
for (int type=0; type<AstBranchPred::_ENUM_END; type++) {
if (double count = double(m_statPred[type])) {
double count = double(m_statPred[type]);
if (count != 0.0) {
V3Stats::addStat(m_stage, string("Branch prediction, ")+AstBranchPred(type).ascii(), count);
}
}
+1 -1
View File
@@ -95,7 +95,7 @@ enum Determ {
ASSIGN // Assignment-like where sign comes from RHS only
};
ostream& operator<<(ostream& str, const Determ& rhs) {
static const char* s_det[] = {"SELF","CNTX","ASSN"};
static const char* const s_det[] = {"SELF","CNTX","ASSN"};
return str<<s_det[rhs];
}
-2
View File
@@ -305,8 +305,6 @@ private:
} else {
// TODO when unpacked arrays fully supported probably need new data type here
AstArraySel* newp = new AstArraySel (nodep->fileline(), fromp, lsbp);
newp->start(lsb);
newp->length((msb - lsb) + 1);
nodep->replaceWith(newp); pushDeletep(nodep); VL_DANGLING(nodep);
}
}
+1 -1
View File
@@ -74,7 +74,7 @@ public:
cout<<" Covered, Rank, RankPts, Filename"<<endl;
}
void dump(bool bucketsToo) {
if (testrun() || computrons()) {
if (testrun() || computrons()!=0.0) {
cout<<" "<<setw(8)<<setfill('0')<<testrun()
<<", "<<setw(7)<<setfill(' ')<<computrons()<<",";
}
+1 -1
View File
@@ -272,7 +272,7 @@ sub write_types {
printf $fh "\t_ENUM_END\n";
printf $fh " };\n";
printf $fh " const char* ascii() const {\n";
printf $fh " const char* names[] = {\n";
printf $fh " const char* const names[] = {\n";
foreach my $type (sort (keys %Classes)) {
next if $type =~ /^Node/;
print $fh "\t\"", uc $type, "\",\n";
+7 -2
View File
@@ -26,7 +26,7 @@
// Autoconf substitutes this with the strings from AC_INIT.
#define PACKAGE_STRING ""
#define DTVERSION PACKAGE_STRING
#define DTVERSION PACKAGE_STRING
//**********************************************************************
//**** Functions
@@ -68,8 +68,13 @@
using namespace std;
//**********************************************************************
//**** Configure-discovered library options
// Define if struct stat has st_mtim.tv_nsec (from configure)
#undef HAVE_STAT_NSEC
//**********************************************************************
//**** OS and compiler specifics
#include "verilatedos.h"
+1 -1
View File
@@ -30,7 +30,7 @@ if ($data =~ /Changed but not updated/i
$rev .= " (mod)";
}
print "static const char* DTVERSION_rev = \"$rev\";\n";
print "static const char* const DTVERSION_rev = \"$rev\";\n";
# Die after the print, so at least the header has good contents
$rev =~ /UNKNOWN/ and warn "%Warning: No git revision found,";
+11 -1
View File
@@ -102,6 +102,15 @@ void V3ParseImp::verilatorCmtBad(const char* textp) {
}
}
void V3ParseImp::tag(const char* text) {
if (m_tagNodep) {
string tmp = text + strlen("/*verilator tag ");
string::size_type pos;
if ((pos=tmp.rfind("*/")) != string::npos) { tmp.erase(pos); }
m_tagNodep->tag(tmp);
}
}
// See V3Read.cpp
//void V3ParseImp::statePop() { yy_pop_state(); }
@@ -109,7 +118,7 @@ void V3ParseImp::verilatorCmtBad(const char* textp) {
void yyerror(const char* errmsg) {
PARSEP->fileline()->v3error(errmsg);
static const char* colonmsg = "syntax error, unexpected ::, ";
static const char* const colonmsg = "syntax error, unexpected ::, ";
//tokens;
if (0==strncmp(errmsg, colonmsg, strlen(colonmsg))
&& PARSEP->prevBisonVal().token == yaID__ETC
@@ -702,6 +711,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5}
"/*verilator lint_on"[^*]*"*/" {PARSEP->verilatorCmtLint(yytext, false); }
"/*verilator lint_restore*/" {PARSEP->verilatorCmtLintRestore(); }
"/*verilator lint_save*/" {PARSEP->verilatorCmtLintSave(); }
"/*verilator tag"[^*]*"*/" {PARSEP->tag(yytext); }
"/**/" { }
"/*"[^*]+"*/" {PARSEP->verilatorCmtBad(yytext); }
+4 -1
View File
@@ -1425,7 +1425,9 @@ member_decl_assignment<memberp>: // Derived from IEEE: variable_decl_assignment
// // At present we allow only packed structures/unions. So this is different from variable_decl_assignment
id variable_dimensionListE
{ if ($2) $2->v3error("Unsupported: Unpacked array in packed struct/union");
$$ = new AstMemberDType($<fl>1, *$1, VFlagChildDType(), GRAMMARP->m_memDTypep->cloneTree(true)); }
$$ = new AstMemberDType($<fl>1, *$1, VFlagChildDType(), GRAMMARP->m_memDTypep->cloneTree(true));
PARSEP->tagNodep($$);
}
| id variable_dimensionListE '=' variable_declExpr
{ $4->v3error("Unsupported: Initial values in struct/union members."); }
| idSVKwd { $$ = NULL; }
@@ -3874,6 +3876,7 @@ AstVar* V3ParseGrammar::createVariable(FileLine* fileline, string name, AstRange
// Remember the last variable created, so we can attach attributes to it in later parsing
GRAMMARP->m_varAttrp = nodep;
PARSEP->tagNodep(GRAMMARP->m_varAttrp);
return nodep;
}
-66
View File
@@ -1,66 +0,0 @@
#*****************************************************************************
#
# DESCRIPTION: Verilator Example: Makefile for inside source directory
#
# This calls the object directory makefile. That allows the objects to
# be placed in the "current directory" which simplifies the Makefile.
#
# Copyright 2003-2017 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.
#
#****************************************************************************/
default: show_config test_default
# This must point to the root of the VERILATOR kit
VERILATOR_ROOT := $(shell pwd)/..
export VERILATOR_ROOT
# Pick up PERL and other variable settings
include $(VERILATOR_ROOT)/include/verilated.mk
DEBUG_QUIET = --debug --debugi 0 --gdbbt --no-dump-tree
DEBUG_ON = --debug --trace-dups --gdbbt
#DEBUG = $(DEBUG_ON)
VALGRIND_ON = $(DEBUG_ON) --gdb "valgrind -v --leak-check=yes"
######################################################################
test_default: prep compile run
test_debug: prep_dbg compile run
test_valgrind: prep_vg compile run
VERILATOR_FLAGS = --cc -f $(VERILATOR_ROOT)/test_v/input.vc top.v
VERILATOR_FLAGS += --trace
#show_config: Is the very first time we've executed Verilator after building
#so we make sure to run with --gdbbt, so if it dumps we'll get a trace.
show_config:
$(PERL) $(VERILATOR_ROOT)/bin/verilator $(DEBUG_QUIET) -V
#prep: Is the very first time we're running a Verilation
#so we make sure to run with --gdbbt, so if it dumps we'll get a trace.
prep:
$(PERL) $(VERILATOR_ROOT)/bin/verilator $(DEBUG_QUIET) $(VERILATOR_FLAGS)
prep_dbg:
$(PERL) $(VERILATOR_ROOT)/bin/verilator $(DEBUG_ON) $(VERILATOR_FLAGS)
prep_vg:
$(PERL) $(VERILATOR_ROOT)/bin/verilator $(VALGRIND_ON) $(VERILATOR_FLAGS)
compile:
cd obj_dir ; $(MAKE) -j 3 -f ../Makefile_obj
run:
obj_dir/simx
######################################################################
obj_dir:
mkdir $@
######################################################################
maintainer-copy::
clean mostlyclean distclean maintainer-clean::
-rm -rf obj_dir *.log *.dmp *.vpd core
-33
View File
@@ -1,33 +0,0 @@
# -*- Makefile -*-
#*****************************************************************************
#
# DESCRIPTION: Verilator Example: Makefile for inside object directory
#
# This is executed in the object directory, and called by ../Makefile
#
# Copyright 2003-2017 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.
#
#*****************************************************************************
default: simx
include Vtop.mk
#######################################################################
# Compile flags
CPPFLAGS += -DVL_DEBUG=1
ifeq ($(CFG_WITH_CCWARN),yes) # Local... Else don't burden users
CPPFLAGS += -DVL_THREADED=1
CPPFLAGS += -W -Werror -Wall
endif
#######################################################################
# Linking final exe -- presumes have a sim_main.cpp
simx: sim_main.o $(VK_GLOBAL_OBJS) $(VM_PREFIX)__ALL.a
$(LINK) $(LDFLAGS) -g $^ $(LOADLIBES) $(LDLIBS) -o $@ $(LIBS) 2>&1 | c++filt
sim_main.o: sim_main.cpp $(VM_PREFIX).h
-84
View File
@@ -1,84 +0,0 @@
// DESCRIPTION: Verilator Example: Top level main for invoking model
//
// Copyright 2003-2017 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.
#include <verilated.h> // Defines common routines
#include "Vtop.h" // From Verilating "top.v"
#if VM_TRACE
# include <verilated_vcd_c.h> // Trace file format header
#endif
Vtop *top; // Instantiation of module
vluint64_t main_time = 0; // Current simulation time (64-bit unsigned)
double sc_time_stamp () { // Called by $time in Verilog
return main_time; // Note does conversion to real, to match SystemC
}
int main(int argc, char **argv, char **env) {
if (0 && argc && argv && env) {} // Prevent unused variable warnings
top = new Vtop; // Create instance of module
Verilated::commandArgs(argc, argv);
Verilated::debug(0);
#if VM_TRACE // If verilator was invoked with --trace
Verilated::traceEverOn(true); // Verilator must compute traced signals
VL_PRINTF("Enabling waves...\n");
VerilatedVcdC* tfp = new VerilatedVcdC;
top->trace (tfp, 99); // Trace 99 levels of hierarchy
tfp->open ("vlt_dump.vcd"); // Open the dump file
#endif
top->reset_l = 1; // Set some inputs
top->fastclk = 0;
top->clk = 0;
top->passed = 0;
while (main_time < 60 && !top->passed && !Verilated::gotFinish()) {
if ((main_time % 10) == 3) { // Toggle clock
top->clk = 1;
}
if ((main_time % 10) == 8) {
top->clk = 0;
}
if (main_time > 10) {
top->reset_l = 1; // Deassert reset
} else if (main_time > 1) {
top->reset_l = 0; // Assert reset
}
top->eval(); // Evaluate model
#if VM_TRACE
if (tfp) tfp->dump (main_time); // Create waveform trace for this timestamp
#endif
// Read outputs
VL_PRINTF ("[%" VL_PRI64 "d] %x %x %x %x %x_%08x_%08x\n",
main_time, top->clk, top->reset_l, top->passed,
top->out_small, top->out_wide[2], top->out_wide[1], top->out_wide[0]);
top->fastclk = !top->fastclk;
main_time++; // Time passes...
}
top->final();
#if VM_TRACE
if (tfp) tfp->close();
#endif
if (!top->passed) {
VL_PRINTF ("A Test failed\n");
abort();
} else {
VL_PRINTF ("All Tests passed\n");
}
exit(0L);
}
+10
View File
@@ -35,6 +35,16 @@ CPPFLAGS += $(CPPFLAGS_DRIVER)
CPPFLAGS += $(CPPFLAGS_DRIVER2)
CPPFLAGS += $(CPPFLAGS_ADD)
ifeq ($(CFG_WITH_LONGTESTS),yes)
ifeq ($(DRIVER_STD),newest)
CPPFLAGS += $(CFG_CXXFLAGS_STD_NEWEST)
else ifeq ($(DRIVER_STD),oldest)
CPPFLAGS += $(CFG_CXXFLAGS_STD_OLDEST)
else ifneq ($(findstring VL_THREADED,$(CPPFLAGS)),)
CPPFLAGS += $(CFG_CXXFLAGS_STD_NEWEST)
endif
endif
#######################################################################
# Linking final exe
+23 -4
View File
@@ -1002,13 +1002,14 @@ sub _run {
if ($param{expect}) {
# Compare
my $quoted = quotemeta ($param{expect});
my $bad = ($wholefile ne $param{expect}
&& $wholefile !~ /$param{expect}/ms
&& $wholefile !~ /$quoted/ms);
if ($bad) {
my $ok = ($wholefile eq $param{expect}
|| _try_regex($wholefile, $param{expect}) == 1
|| $wholefile =~ /$quoted/ms);
if (!$ok) {
#print "**BAD $self->{name} $param{logfile} MT $moretry $try\n";
next if $moretry;
$self->error("Mismatch in output from $param{cmd}[0]\n");
$self->error("Might be error in regexp format\n") if $ok<1;
print "GOT:\n";
print $wholefile;
print "ENDGOT\n";
@@ -1025,6 +1026,24 @@ sub _run {
#######################################################################
# Little utilities
sub _try_regex {
# Try to eval a regexp
# Returns:
# 1 if $text ~= /$regex/ms
# 0 if no match
# -1 if $regex is invalid, doesn't compile
my ($text, $regex) = @_;
my $result;
{
local $@;
eval {
$result = ($text =~ /$regex/ms);
};
$result = -1 if $@;
}
return $result;
}
sub _make_main {
my $self = shift;
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 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.
# show-config: This test runs the very first time we've executed Verilator
# after building so we make sure to run with --gdbbt, so if it dumps we'll
# get a trace.
$DEBUG_QUIET = "--debug --debugi 0 --gdbbt --no-dump-tree";
$Self->run(cmd=>["perl", "../bin/verilator", $DEBUG_QUIET, "-V"]);
compile (
verilator_flags2 => [$DEBUG_QUIET, "--trace"],
);
execute (
check_finished=>1,
);
ok(1);
1;

Some files were not shown because too many files have changed in this diff Show More