Compare commits

..
98 Commits
Author SHA1 Message Date
Wilson Snyder eb072da81c Version bump 2009-03-28 10:30:35 -04:00
Wilson Snyder 38669d0a10 Add SYSTEMPERL_INCLUDE envvar to assist RPM builds. 2009-03-28 10:18:53 -04:00
Wilson Snyder 202a8bc3bb Internals: Use common wrapper for setenv 2009-03-28 09:15:13 -04:00
Wilson Snyder 45e8ed6b49 Internals: Cleanup what symbol lookups need to recurse up vs not. 2009-03-24 09:22:58 -04:00
Wilson Snyder 96692e8a5b Report errors when duplicate labels are used, bug72. 2009-03-23 14:57:15 -04:00
Wilson Snyder ecb08b0cf3 Internals: V3Link uses new common func to make symbol table 2009-03-23 13:52:36 -04:00
Wilson Snyder 71bdfd9710 Fix ASSIGN_SI errors with new --pins-bv 1 option 2009-03-13 22:58:55 -04:00
Wilson Snyder 193dcf38f4 Add --pins-bv option to use sc_bv for all ports. 2009-03-13 14:17:30 -04:00
Wilson Snyder 09091781cf Fix the SC_MODULE name() to not include __PVT__, for nicer coverage. 2009-03-12 14:07:38 -04:00
Wilson Snyder 023519c8f6 Version bump 2009-02-26 07:44:00 -05:00
Wilson Snyder d60d0a60c7 Support repeat and forever statements. 2009-02-25 22:06:59 -05:00
Wilson Snyder 8fe0c3dd84 Commentary in parser to match Verilog-Perl 2009-02-25 17:16:51 -05:00
Wilson Snyder 85419f01a9 Fix left associativity for ?: operators. 2009-02-07 20:54:09 -05:00
Wilson Snyder a199f4a849 Update Bison parser to track Verilog-Perl 3.110. No functional change 2009-01-28 15:27:41 -05:00
Wilson Snyder 290795a76b Commentary 2009-01-28 14:28:55 -05:00
Wilson Snyder c2cf2bc0ba Commentary 2009-01-26 18:36:59 -05:00
Wilson Snyder 2224918730 Fix error messages to consistently go to stderr. 2009-01-26 07:57:59 -05:00
Wilson Snyder c4e69daecd Add IEEE grammar comments; sync with Verilator-Perl parser 2009-01-24 21:36:14 -05:00
Wilson Snyder 9162e68d82 Commentary 2009-01-24 21:35:08 -05:00
Wilson Snyder 08f736ae33 bisonpre: Reconsile Verilog-Perl and Verilator bisonpre 2009-01-24 16:44:03 -05:00
Wilson Snyder 81092edab4 Commentary 2009-01-21 16:59:42 -05:00
Wilson Snyder 21b5a4e9e4 Add --debugi-<srcfile> option. 2009-01-21 16:56:50 -05:00
Wilson Snyder 057928b079 Fix VL_RANDom to better randomize bits. 2009-01-21 13:52:51 -05:00
Wilson Snyder 4beaa45199 Clock_enable is past experimental; bug50. 2009-01-20 07:24:57 -05:00
Wilson Snyder 8f88fa45f1 Make grammer names more closely track IEEE. No functional change. 2009-01-15 13:58:43 -05:00
Wilson Snyder 13e8176884 Fix compile issues with GCC 4.3, bug47. 2009-01-09 11:28:50 -05:00
Wilson Snyder aac0130613 Version bump 2009-01-08 10:52:37 -05:00
Wilson Snyder 0877f44cb5 Fix creating parameterized modules when no parameter values are changed. 2009-01-08 09:22:31 -05:00
Wilson Snyder 59159b4811 Clock gating optimization, currently disabled. Merge from branch 2009-01-07 09:37:59 -05:00
Wilson Snyder 12bd12e112 Support bufif0, bufif1, notif0, notif1 2009-01-06 11:57:25 -05:00
Lane Brooks 0e4f9170fa Tristate support; merge from branch. 2009-01-06 11:03:57 -05:00
Lane Brooks 6f81a9cb1e Added *~ to .gitignore to exclude emacs backup files. 2009-01-06 09:25:47 -05:00
Wilson Snyder 41555e5aa3 Coverage of each parametarized module is counted separately. 2009-01-05 14:16:09 -05:00
Wilson Snyder 3d06720628 Copyright year update 2009-01-02 11:47:39 -05:00
Wilson Snyder c1d2b98386 Fix wrong result for read of delayed FSM signal, bug46. 2008-12-30 17:11:25 -05:00
Wilson Snyder 1a60723d77 Fix internal error on "output x; reg x = y;" 2008-12-30 14:34:01 -05:00
Wilson Snyder cc31ab84d7 Add synmul test 2008-12-23 11:43:11 -05:00
Wilson Snyder a07a234761 Fix compile error on Ubuntu 8.10. 2008-12-22 11:28:42 -05:00
Wilson Snyder 0bb4ccd7cd Fix coverage module names including parameter values 2008-12-12 17:28:27 -05:00
Wilson Snyder 74cf205bcf Move coverage type field into page field, and add module name 2008-12-12 16:04:56 -05:00
Wilson Snyder 77405ddded Add toggle coverage 2008-12-12 15:34:02 -05:00
Wilson Snyder 6b46da0240 Create /*verilator coverage_on/off*/ instead of coverage_module_off.
This allows finer grained bracketing of sections of interest.
Convert tracing_on/off to use the same general scheme.
2008-12-11 16:01:41 -05:00
Wilson Snyder 0815812546 Internals: Flip state of FileLine warning array, in prep for next change 2008-12-11 15:23:44 -05:00
Wilson Snyder 0fed1d34d1 Add /*verilator coverage_module_off*/ 2008-12-10 17:10:03 -05:00
Wilson Snyder a1e091cff7 Internals: Last commit showed that V3LinkLevel is mostly redundant with V3LinkCells 2008-12-09 21:05:47 -05:00
Wilson Snyder adebc99e49 Fix certain generate-if cells causing clone error. 2008-12-09 20:59:22 -05:00
Wilson Snyder d3d1291d5a Fix line coverage of public functions.
Line coverage now aggregates by hierarchy automatically.
Previously this would be done inside SystemPerl, which was slower.
2008-12-05 10:54:14 -05:00
Wilson Snyder de61015e08 Internal: V3Order should only use user4 for short period to support future clock gating 2008-12-03 10:27:56 -05:00
Wilson Snyder 9d856ec1bf Fix SystemC 2.2 deprecated warnings about sensitive() and sc_start(). 2008-12-03 10:11:28 -05:00
Wilson Snyder ad19d32a66 Fix SystemC 2.2 deprecated warnings about sensitive() and sc_start(). 2008-12-02 15:33:49 -05:00
Wilson Snyder 5bdb8674ed Internals: Rename AstNode::userp to user1p for easier searching
and to disambiguate from the vertex/edge-> userp.
2008-11-25 09:03:49 -05:00
Wilson Snyder 5563c9666c Internals: Smaller AstNode to save space/time 2008-11-25 08:10:41 -05:00
Wilson Snyder 30ad20be52 Internals: Eliminate user5 for smaller AstNode/better runtime 2008-11-25 07:57:02 -05:00
Wilson Snyder 314c9de845 Make test_regress now places each test result in unique obj_dir 2008-11-24 21:38:45 -05:00
Wilson Snyder 41dbfc9e1c Support posedge of bit-selected signals, bug45. 2008-11-22 21:10:20 -05:00
Wilson Snyder b07dd622fa Commentary: Debugging and some astgen code cleanup.
No functional change.
2008-11-22 17:37:20 -05:00
Wilson Snyder 6ad21b3b3b Internals: Move V3Const to user4 to reduce future collisions 2008-11-22 17:27:55 -05:00
Wilson Snyder a242c1019d Internal speedups: Skip iterator for Termop or VarRefs.
Fix AstUCFunc being mis-labeled as a Termop.
2008-11-22 15:28:29 -05:00
Wilson Snyder c595d67311 Speed up Verilator itself by prefetching pointer-chase 2008-11-22 14:59:22 -05:00
Wilson Snyder 8b77379e2c Internal coding: Assert that user#() don't overlap.
Any use of a user() must now be declared, generally in the Visitor class with
    AstUser#InUse   arbitrary_object
This lets the code track if there's another request for the same user(),
preventing nasty hard to debug cases where they overlap.  This will also
call user#ClearTree(), so a bunch of those were removed, though many
extranious ones still remain.
2008-11-21 15:50:33 -05:00
Wilson Snyder 7ad29c6329 Test driver: Add benchmark option 2008-11-21 14:38:12 -05:00
Wilson Snyder 14756fa131 Internals: Make graph sorting usable in other visitors, in prep for future
changes.  No functional change.
2008-11-20 09:04:29 -05:00
Wilson Snyder ddbfc176b6 Internals: Create AstNodeSelItem in prep for future commits.
No real functional change, outside of minor debug dump differences.
2008-11-20 07:55:54 -05:00
Wilson Snyder ab668b066f Internal cleanup: no functional change.
Add cloneTree to each node type so cast not required after use.
Standardize declaring common AstNode functions via a macro.
2008-11-19 20:15:05 -05:00
Wilson Snyder a4bcb3de4a Test driver: Use __ to prevent conflicts between similar named tests 2008-11-19 16:44:51 -05:00
Wilson Snyder 211894cb3e Fix arrayed variables under function not compiling, bug44. 2008-11-19 09:43:03 -05:00
Wilson Snyder 7565b1f4f2 Allow test driver to support tests with longer sim_time 2008-11-18 19:37:26 -05:00
Wilson Snyder b75ff3652c Fix internal signal names containing control characters (broke in 3.680).
Internally this means for signal names use __0{xdigit}{xdigit} and avoid
__0 in other cases.
2008-11-17 21:02:10 -05:00
Wilson Snyder 13f6c5a934 Fix --output-split-cfuncs to also split trace code. 2008-11-17 17:13:57 -05:00
Wilson Snyder 2e0f6e2b13 Optimize two-level shift and and/or trees. 2008-11-17 11:36:01 -05:00
Wilson Snyder c5d41ee2d9 Optimize constants up across sub expressions 2008-11-17 10:40:58 -05:00
Wilson Snyder 5f70c1aa68 Add debug dumps of V3Hash state 2008-11-16 20:39:49 -05:00
Wilson Snyder d2105ba390 Commentary 2008-11-16 20:30:22 -05:00
Wilson Snyder e46e7bbf99 Fix 'bad select range' warning missing some cases, bug43. 2008-11-12 20:54:58 -05:00
Wilson Snyder 4eeeb72dd5 Version bump 2008-11-12 15:32:22 -05:00
Wilson Snyder adefa45fb4 After module, clear m_modp as not relevant any longer 2008-11-12 15:32:09 -05:00
Wilson Snyder cfc06ab2a7 Fix tests to work with binary SpCoverage files 2008-11-12 15:29:44 -05:00
Wilson Snyder f3a4752799 Fix MSVC compile error; bug42. 2008-11-05 10:52:23 -05:00
Wilson Snyder 3d788b4b93 Fix "Missing coverage in PSL" due to "cover property $stop" statements.
"cover property" reported hierarchy now includes named begin blocks.
2008-11-05 10:23:03 -05:00
Wilson Snyder 5d2675e38a Repair of last 2 checkins; dots in wrong place when 2 level deep inline 2008-11-05 09:14:49 -05:00
Wilson Snyder 288d7bd9dc Commentary 2008-11-05 08:55:52 -05:00
Wilson Snyder 3e8cf26c1a Fix coverage hierarchy being backwards with inlining. 2008-11-04 17:19:59 -05:00
Wilson Snyder ce212722ad Fix 'for' under 'generate-for' causing error; bug38. 2008-10-28 21:38:01 -04:00
Wilson Snyder 5c127daeb4 Fix wrong version for some changes; docs only 2008-10-28 21:09:45 -04:00
Wilson Snyder e49fc945df Fix GCC 4.3 compile error; bug35 2008-10-15 10:49:05 -04:00
Wilson Snyder 384807ebbd Ignore SystemVerilog timeunit and timeprecision 2008-10-14 14:49:54 -04:00
Wilson Snyder ac619ef3d8 Include Verilog file's directory name in coverage reports. 2008-10-14 14:27:11 -04:00
Wilson Snyder a348bd3458 Add unique and parallel case 2008-10-10 19:02:27 -04:00
Wilson Snyder bcc7045fc9 Version bump 2008-10-08 17:08:47 -04:00
Wilson Snyder 3b1929259a Support negative bit indexes.
Allow arbitrary characters in symbols (to make '-' work.)
Final merge from negative_lsb branch.
2008-10-06 09:59:22 -04:00
Wilson Snyder cdd6ea8e60 Fix genvars causing link error when using --public. 2008-09-30 08:58:07 -04:00
Wilson Snyder 4b8927af75 Expand environment variables in -f input files. 2008-09-29 15:51:45 -04:00
Wilson Snyder 0fba25c1b3 Commentary 2008-09-29 15:07:27 -04:00
Wilson Snyder f19ba9d54d Support negative bit indexes.
Tracing negative indexes requires latest Verilog-Perl and SystemPerl.
(Merged from negative_lsb branch.)
2008-09-24 07:43:08 -04:00
Wilson Snyder 8e9a0121ac Update test driver.pl: Allow -j auto determination, make logfile, don't require cd 2008-09-23 10:02:31 -04:00
Wilson Snyder bd6e8d808c Report error if port declaration is missing; bug32. 2008-09-23 09:35:00 -04:00
Wilson Snyder 11b9a631d4 Remove mis-committed debug print 2008-09-22 20:10:10 -04:00
Wilson Snyder f197dd29cb Suppress width warnings between constant strings and wider vectors. 2008-09-22 19:36:08 -04:00
547 changed files with 13104 additions and 3340 deletions
+1
View File
@@ -1,3 +1,4 @@
*~
*.old
*.gz
*.gz.uu
+100 -1
View File
@@ -3,6 +3,105 @@ Revision history for Verilator
The contributors that suggested a given feature are shown in []. [by ...]
indicates the contributor was also the author of the fix; Thanks!
* Verilator 3.702 2009/03/28
*** Add --pins-bv option to use sc_bv for all ports. [Brian Small]
*** Add SYSTEMPERL_INCLUDE envvar to assist RPM builds. [Chitlesh Goorah]
**** Report errors when duplicate labels are used, bug72. [Vasu Kandadi]
**** Fix the SC_MODULE name() to not include __PVT__. [Bob Fredieu]
* Verilator 3.701 2009/02/26
** Support repeat and forever statements. [Jeremy Bennett]
*** Add --debugi-<srcfile> option, for internal debugging. [Dennis Muhlestein]
**** Fix compile issues with GCC 4.3, bug47. [Lane Brooks]
**** Fix VL_RANDom to better randomize bits. [Art Stamness]
**** Fix error messages to consistently go to stderr. [Jeremy Bennett]
**** Fix left associativity for ?: operators.
* Verilator 3.700 2009/01/08
** Add limited support for tristate inouts. Written by Lane Brooks,
under support by Ubixum Inc. This allows common pad ring and
tristate-mux structures to be Verilated. See the documentation for
more information on supported constructs.
** Add --coverage_toggle for toggle coverage analysis.
Running coverage now requires SystemPerl 1.301 or newer.
*** Add /*verilator coverage_on/_off */ to bracket coverage regions.
*** Optimize two-level shift and and/or trees, +23% on one test.
*** Support posedge of bit-selected signals, bug45. [Rodney Sinclair]
*** Line coverage now aggregates by hierarchy automatically.
Previously this would be done inside SystemPerl, which was slower.
**** Minor performance improvements of Verilator compiler runtime.
**** Coverage of each parametarized module is counted separately. [Bob Fredieu]
**** Fix creating parameterized modules when no parameter values are changed.
**** Fix certain generate-if cells causing "clone" error. [Stephane Laurent]
**** Fix line coverage of public functions. [Soon Koh]
**** Fix SystemC 2.2 deprecated warnings about sensitive() and sc_start().
**** Fix arrayed variables under function not compiling, bug44. [Ralf Karge]
**** Fix --output-split-cfuncs to also split trace code. [Niranjan Prabhu]
**** Fix 'bad select range' warning missing some cases, bug43. [Lane Brooks]
**** Fix internal signal names containing control characters (broke in 3.680).
**** Fix compile error on Ubuntu 8.10. [Christopher Boumenot]
**** Fix internal error on "output x; reg x = y;".
**** Fix wrong result for read of delayed FSM signal, bug46. [Rodney Sinclair]
* Verilator 3.681 2008/11/12
*** Add SystemVerilog unique and priority case.
**** Include Verilog file's directory name in coverage reports.
**** Fix 'for' under 'generate-for' causing error; bug38. [Rafael Shirakawa]
**** Fix coverage hierarchy being backwards with inlining. [Vasu Arasanipalai]
**** Fix GCC 4.3 compile error; bug35. [Lane Brooks]
**** Fix MSVC compile error; bug42. [John Stroebel]
* Verilator 3.680 2008/10/08
** Support negative bit indexes. [Stephane Laurent]
Tracing negative indexes requires latest Verilog-Perl and SystemPerl.
*** Suppress width warnings between constant strings and wider vectors.
[Rodney Sinclair]
**** Ignore SystemVerilog timeunit and timeprecision.
**** Expand environment variables in -f input files. [Lawrence Butcher]
**** Report error if port declaration is missing; bug32. [Guy-Armand Kamendje]
**** Fix genvars causing link error when using --public. [Chris Candler]
* Verilator 3.671 2008/09/19
** SystemC uint64_t pins are now the default instead of sc_bv<64>.
@@ -1304,7 +1403,7 @@ of input ports exists for tracing.
This uses outline mode in Emacs. See C-h m [M-x describe-mode].
Copyright 2001-2008 by Wilson Snyder. This program is free software;
Copyright 2001-2009 by Wilson Snyder. This program is free software;
you can redistribute it and/or modify it under the terms of either the GNU
General Public License or the Perl Artistic License.
+2 -2
View File
@@ -9,7 +9,7 @@
#
#*****************************************************************************
#
# Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
# Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# General Public License or the Perl Artistic License.
#
@@ -111,7 +111,7 @@ DISTFILES_INC = $(INFOS) .gitignore COPYING *.in *.ac \
include/.*ignore \
.*attributes */.*attributes */*/.*attributes \
src/.*ignore src/*.in src/*.cpp src/*.[chly] src/astgen src/bisonpre src/*fix \
src/*.pl \
src/*.pl src/*.pod \
test_*/.*ignore test_*/Makefile* test_*/*.cpp \
test_*/*.pl test_*/*.v test_*/*.vc test_*/vlint \
test_verilated/vgen*.pl \
+2 -1
View File
@@ -1,6 +1,6 @@
// DESCRIPTION: Verilator: List of To Do issues.
//
// Copyright 2004-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2004-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
@@ -54,6 +54,7 @@ Usability:
Internal Code:
Eliminate the AstNUser* passed to all visitors; its only needed in V3Width,
and removing it will speed up and simplify all the other code.
V3Graph should be templated container type, taking in Vertex + Edge types
Performance:
Constant propagation
+197 -54
View File
@@ -3,7 +3,7 @@ eval 'exec perl -wS $0 ${1+"$@"}'
if 0;
######################################################################
#
# Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
# Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# General Public License or the Perl Artistic License.
#
@@ -183,10 +183,13 @@ descriptions in the next sections for more information.
--compiler <compiler-name> Tune for specified C++ compiler
--coverage Enable all coverage
--coverage-line Enable line coverage
--coverage-toggle Enable toggle coverage
--coverage-user Enable PSL/SVL user coverage
-D<var>[=<value>] Set preprocessor define
--debug Enable debugging
--debug-check Enable debugging assertions
--debugi <level> Enable debugging at a specified level
--debugi-<srcfile> <level> Enable debugging a source file at a level
--dump-tree Enable dumping .tree files
-E Preprocess, but do not compile
--error-limit <value> Abort after this number of errors
@@ -209,6 +212,7 @@ descriptions in the next sections for more information.
-O<optimization-letter> Selectable optimizations
--output-split <bytes> Split .cpp files into pieces
--output-split-cfuncs <statements> Split .ccp functions
--pins-bv <bits> Specify types for top level ports
--prefix <topname> Name of top level class
--profile-cfuncs Name functions for profiling
--private Debugging; see docs
@@ -241,7 +245,7 @@ descriptions in the next sections for more information.
Specifies the Verilog file containing the top module to be Verilated.
=item {file.c/cc/cpp}
=item {file.c/.cc/.cpp/.cxx}
Specifies optional C++ files to be linked in with the Verilog code. If any
C++ files are specified in this way, Verilator will include a make rule
@@ -296,7 +300,8 @@ functions to avoid error C1061.
=item --coverage
Enables all forms of coverage, alias for --coverage-line, --coverage-user.
Enables all forms of coverage, alias for "--coverage-line --coverage-toggle
--coverage-user".
=item --coverage-line
@@ -311,12 +316,46 @@ corresponding to each counter are written into logs/coverage.pl.
Verilator automatically disables coverage of branches that have a $stop in
them, as it is assumed $stop branches contain an error check that should
not occur. A /*verilator coverage_block_off*/ comment will perform a
similar function on any code in that block or below.
similar function on any code in that block or below, or /*verilator
coverage_on/coverage_off*/ will disable coverage around lines of code.
Note Verilator may over-count combinatorial (non-clocked) blocks when those
blocks receive signals which have had the UNOPTFLAT warning disabled; for
most accurate results do not disable this warning when using coverage.
=item --coverage-toggle
Specifies signal toggle coverage analysis code should be inserted.
Every bit of every signal in a module has a counter inserted. The counter
will increment on every edge change of the corresponding bit.
Signals that are part of tasks or begin/end blocks are considered local
variables and are not covered. Signals that begin with underscores, are
integers, or are very wide (>256 bits total storage across all dimensions)
are also not covered.
Hierarchy is compressed, such that if a module is instantiated multiple
times, coverage will be summed for that bit across ALL instantiations of
that module with the same parameter set. A module instantiated with
different parameter values is considered a different module, and will get
counted separately.
Verilator makes a minimally-intelligent decision about what clock domain
the signal goes to, and only looks for edges in that clock domain. This
means that edges may be ignored if it is known that the edge could never be
seen by the receiving logic. This algorithm may improve in the future.
The net result is coverage may be lower than what would be seen by looking
at traces, but the coverage is a more accurate representation of the
quality of stimulus into the design.
There may be edges counted near time zero while the model stabilizes. It's
a good practice to zero all coverage just before releasing reset to prevent
counting such behavior.
A /*verilator coverage_off/on */ comment pair can be used around signals
that do not need toggle analysis, such as RAMs and register files.
=item --coverage-user
Enables user inserted functional coverage. Currently, all functional
@@ -339,6 +378,12 @@ internal assertions, debugging messages, and intermediate form dump files.
Rarely needed. Enable internal debugging assertion checks, without
changing debug verbosity. Enabled automatically when --debug specified.
=item --debugi <level>
=item --debugi-<srcfile> <level>
Rarely needed - for developer use. Set internal debugging level globally
or on the specified source file to the specified level.
=item --dump-tree
Rarely needed. Enable writing .tree debug files. This is enabled with
@@ -415,9 +460,7 @@ the same as --prefix.
=item --no-pins64
Specifies SystemC outputs of 33-64 bits wide should use sc_bv's instead of
uint64_t's. Uint64's are faster, but sc_bvs were the default until
Verilator 3.671.
Backward compatible alias for "--pins-bv 33".
=item --no-skip-identical
@@ -445,20 +488,34 @@ mappings of optimizations to -O letters.
Enables splitting the output .cpp/.sp files into multiple outputs. When a
C++ file exceeds the specified number of operations, a new file will be
created. In addition, any slow routines will be placed into __Slow files.
This accelerates compilation by as optimization can be disabled on the slow
routines, and the remaining files can be compiled on parallel machines.
Using --output-split should have only a trivial impact on performance.
With GCC 3.3 on a 2GHz Opteron, --output-split 20000 will result in
splitting into approximately one-minute-compile chunks.
created at the next function boundary. In addition, any slow routines will
be placed into __Slow files. This accelerates compilation by as
optimization can be disabled on the slow routines, and the remaining files
can be compiled on parallel machines. Using --output-split should have
only a trivial impact on performance. With GCC 3.3 on a 2GHz Opteron,
--output-split 20000 will result in splitting into approximately
one-minute-compile chunks.
=item --output-split-cfuncs I<statements>
Enables splitting functions in the output .cpp/.sp files into multiple
functions. When a generated function exceeds the specified number of
operations, a new function will be created. With --output-split, this will
enable GCC to compile faster, at a small loss in performance that increases
with smaller statement values.
enable GCC to compile faster, at a small loss in performance that gets
worse with decreasing split values. Note that this option is stronger than
--output-split in the sense that --output-split will not split inside a
function.
=item --pins64
Backward compatible alias for "--pins-bv 65". Note that's a 65, not a 64.
=item --pins-bv I<width>
Specifies SystemC outputs of greater than or equal to I<width> bits wide
should use sc_bv's instead of uint32/uint64_t's. The default is "--pins-bv
65". Versions before Verilator 3.671 defaulted to "--pins-bv 33". The
more sc_bv is used, the worse for performance.
=item --prefix I<topname>
@@ -594,6 +651,12 @@ will call a function to determine the value, this allows randomization of
all Xs to find reset bugs and is the slowest, but safest for finding reset
bugs in code.
If using -x-assign unique, you may want to seed your random number
generator such that each regression run gets a different randomization
sequence. Use the system's srand48() or for Windows srand() function to do
this. You'll probably also want to print any seeds selected, and code to
enable rerunning with that same seed so you can reproduce bugs.
=back
=head1 VERILOG ARGUMENTS
@@ -717,7 +780,7 @@ This is an example similar to the above, but using SystemPerl.
Vour* top;
top = new Vour("top"); // SP_CELL (top, Vour);
top->clk(clk); // SP_PIN (top, clk, clk);
while (!Verilated::gotFinish()) { sc_start(1); }
while (!Verilated::gotFinish()) { sc_start(1, SC_NS); }
exit(0);
}
EOF
@@ -890,10 +953,18 @@ building the SystemC model.
=item SYSTEMPERL
Specifies the directory containing the Verilog-Perl distribution kit. This
is used to find the Verilog-Perl library and include files. If not
Specifies the directory containing the SystemPerl distribution kit. This
is used to find the SystemPerl library and include files. If not
specified, it will come from a default optionally specified at configure
time (before Verilator was compiled).
time (before Verilator was compiled). See also SYSTEMPERL_INCLUDE.
=item SYSTEMPERL_INCLUDE
Specifies the directory containing the Verilog-Perl include .cpp files,
from the src/ directory of the SystemPerl kit. If not specified, it will
be computed from the SYSTEMPERL environment variable if it is set, and if
SYSTEMPERL is not set SYSTEMPERL_INCLUDE will come from a default
optionally specified at configure time (before Verilator was compiled).
=item VCS_HOME
@@ -974,11 +1045,10 @@ Verilator will convert the top level module to a SC_MODULE. This module
will plug directly into a SystemC netlist.
The SC_MODULE gets the same pinout as the Verilog module, with the
following type conversions: Pins of a single bit become bool, unless they
are marked with `systemc_clock, in which case they become sc_clock's (for
SystemC 1.2, not needed in SystemC 2.0). Pins 2-32 bits wide become
uint32_t's. Pins 33-64 bits wide become sc_bv's or uint64_t's depending on
the --no-pins64 switch. Wider pins become sc_bv's.
following type conversions: Pins of a single bit become bool. Pins 2-32
bits wide become uint32_t's. Pins 33-64 bits wide become sc_bv's or
uint64_t's depending on the --no-pins64 switch. Wider pins become sc_bv's.
(Uints simulate the fastest so are used where possible.)
Lower modules are not pure SystemC code. This is a feature, as using the
SystemC pin interconnect scheme everywhere would reduce performance by an
@@ -1039,7 +1109,8 @@ including function call-like preprocessor defines.
Verilator supports ==? and !=? operators, $bits, $countones, $error,
$fatal, $info, $isunknown, $onehot, $onehot0, $warning, always_comb,
always_ff, always_latch, do-while, and final.
always_ff, always_latch, do-while, final, priority case/if, and unique
case/if.
It also supports .name and .* interconnection.
@@ -1085,6 +1156,10 @@ formally prove the directive to be true, or failing that, will insert the
appropriate code to detect failing cases at runtime and print an "Assertion
failed" error message.
Verilator likewise also asserts any "unique" or "priority" SystemVerilog
keywords on case statements. However, "unique if" and "priority if" are
currently simply ignored.
=head1 LANGUAGE EXTENSIONS
The following additional constructs are the extensions Verilator supports
@@ -1206,15 +1281,27 @@ The Verilog code returns to the last language mode specified with
=item /*verilator clock_enable*/
Experimental use only. Used after a signal declaration to indicate the
signal is used to gate a clock, and the user takes responsibility for
insuring there are no races related to it. (Typically by adding a latch,
and running static timing analysis.) This will cause the clock gate to be
ignored in the scheduling algorithm, improving performance.
Used after a signal declaration to indicate the signal is used to gate a
clock, and the user takes responsibility for insuring there are no races
related to it. (Typically by adding a latch, and running static timing
analysis.) This will cause the clock gate to be ignored in the scheduling
algorithm, improving performance.
=item /*verilator coverage_block_off*/
Specifies the entire begin/end block should be ignored for coverage analysis.
Specifies the entire begin/end block should be ignored for coverage
analysis purposes.
=item /*verilator coverage_off*/
Specifies that following lines of code should have coverage disabled.
Often used to ignore an entire module for coverage analysis purposes.
=item /*verilator coverage_on*/
Specifies that following lines of code should have coverage reenabled (if
appropriate --coverage flags are passed) after being disabled earlier with
/*verilator coverage_off*/.
=item /*verilator inline_module*/
@@ -1235,6 +1322,7 @@ this to the signal causing a false loop may clear up the problem.
IE, with the following
reg splitme /* verilator isolate_assignments*/;
// Note the placement of the semicolon above
always @* begin
if (....) begin
splitme = ....;
@@ -1341,7 +1429,9 @@ using the --public switch.
=item /*verilator sc_clock*/
Used after a input declaration to indicate the signal should be declared in
SystemC as a sc_clock instead of a bool.
SystemC as a sc_clock instead of a bool. This was needed in SystemC 1.1
and 1.2 only; versions 2.0 and later do not require clock pins to be
sc_clocks and this is no longer needed.
=item /*verilator tracing_off*/
@@ -1438,9 +1528,25 @@ all variables to one at startup finds most problems.
=head2 Tri/Inout
As a 2 state compiler, tristate and inouts are not supported.
Traditionally only chip "cores" are Verilated, the pad rings have been
written by hand in C++.
Verilator converts some simple tristate structures into two state. An assignment
of the form:
inout driver;
wire driver = (enable) ? output_value : 1'bz;
Will be converted to
input driver__in; // Value being driven in from "external" drivers
output driver__en; // True if driven from this module
output driver__enout; // Value being driven from this module
Pullup, pulldown, bufif0, bufif1, notif0, notif1 are also supported.
External logic will be needed to combine these signals with any external
drivers.
Tristate drivers are not supported inside functions and tasks; a inout
there will be considered a two state variable that is read and written
instead of a four state variable.
=head2 Functions & Tasks
@@ -1544,10 +1650,19 @@ while, wire, xnor, xor
Generally supported.
=item priority if, unique if
Priority and unique if's are treated as normal ifs and not asserted to be
full nor unique.
=item specify specparam
All specify blocks and timing checks are ignored.
=item timeunit, timeprecision
All timing control statements are ignored.
=item uwire
Verilator does not perform warning checking on uwires, it treats the uwire
@@ -2019,9 +2134,9 @@ Visual C++ Version 7 or newer, but this is not tested by the author.
=item Can you provide binaries?
Verilator is available as a RPM for SuSE and perhaps other systems; this is
done by porters and may slightly lag the primary distribution. If there
isn't a binary build for your distribution, how about you set one up?
Verilator is available as a RPM for SuSE, Redhat and perhaps other systems;
this is done by porters and may slightly lag the primary distribution. If
there isn't a binary build for your distribution, how about you set one up?
Please contact the authors for assistance.
Note people sometimes request binaries when they are having problems with
@@ -2061,7 +2176,7 @@ using --debug), see if your machine is paging; most likely you need to run
it on a machine with more memory. Verilator is a full 64 bit application
and may use more than 4GB, but about 1GB is the maximum typically needed.
=item How do I generate waveforms (traces) in C++ or SystemC?
=item How do I generate waveforms (traces) in C++?
See the next question for tracing in SystemPerl mode.
@@ -2080,7 +2195,7 @@ distribution.
You also need to compile SpTraceVcdC.cpp and add it to your link. This is
done for you if using the Verilator --exe flag.
=item How do I generate waveforms (traces) in SystemPerl?
=item How do I generate waveforms (traces) in SystemC/SystemPerl?
Add the --trace switch to Verilator, and make sure the SystemPerl package
is installed.
@@ -2090,12 +2205,31 @@ create a SpTraceFile object as you would create a normal SystemC trace
file. For an example, see the call to SpTraceFile in the
test_sp/sc_main.cpp file of the distribution.
Alternatively you may use the C++ trace mechanism described in the previous
question, however the timescale and timeprecision will not inherited from
your SystemC settings.
=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.
=item How do I reduce the size of large waveform (trace) files?
First, instead of calling SpTraceVcdCFile->open at the beginning of time,
delay calling it until the time stamp where you want to tracing to begin.
Likewise you can also call SpTraceVcdCFile->open before the end of time
(perhaps a short period after you detect a verification error.)
Next, add /*verilator tracing_off*/ to any very low level modules you never
want to trace (such as perhaps library cells). Finally, use the
--trace-depth option to limit the depth of tracing, for example
--trace-depth 1 to see only the top level signals.
Also be sure you write your trace files to a local disk, instead of to a
network disk. Network disks are generally far slower.
=item How do I do coverage analysis?
Verilator supports both block (line) coverage and user inserted functional
@@ -2252,7 +2386,8 @@ strips array bound checks where it believes them to be unnecessary.)
In the SYSTEMC example above, if you had in our.v:
input clk /*verilator public*/;
input clk /*verilator public*/;
// Note the placement of the semicolon above
From the sc_main.cpp file, you'd then:
@@ -2345,27 +2480,35 @@ faster than many popular commercial simulators.
Many people have provided ideas and other assistance with Verilator.
The major corporate sponsors of Verilator, by providing funds or equipment
grants, are Compaq Corporation, Digital Equipment Corporation, Maker
Communications, Sun Microsystems, Nauticus Networks, and SiCortex.
grants include Compaq Corporation, Digital Equipment Corporation, Intel
Corporation, Maker Communications, MicroTune Inc., Sun Microsystems,
Nauticus Networks, and SiCortex Inc.
The people who have contributed code or other major functionality are Paul
Wasson, Duane Galbi, and Wilson Snyder. Major testers include Jeff Dutton,
Ralf Karge, David Hewson, Wim Michiels, and Gene Weber.
The people who have contributed code or other major functionality are Lane
Brooks, Duane Galbi, Paul Wasson, and Wilson Snyder. Major testers include
Jeff Dutton, Ralf Karge, David Hewson, Wim Michiels, and Gene Weber.
Some of the people who have provided ideas and feedback for Verilator
include Hans Van Antwerpen, Jens Arm, David Black, Gregg Bouchard, Chris
Boumenot, John Brownlee, Lauren Carlson, Robert A. Clark, John Deroo, Danny
Ding, Jeff Dutton, Eugen Fekete, Sam Gladstone, Thomas Hawkins, Mike Kagen,
Ralf Karge, Dan Katz, Sol Katzman, Gernot Koch, Steve Kolecki, Steve Lang,
Charlie Lind, Dan Lussier, Fred Ma, Wim Michiels, John Murphy, Richard
Myers, Paul Nitza, Lisa Noack, Renga Sundararajan, Shawn Wang, Greg Waters,
Eugene Weber, Leon Wildman, and Mat Zeno.
include David Addison, Hans Van Antwerpen, Vasu Arasanipalai, Jens Arm,
Jeremy Bennett, David Black, Gregg Bouchard, Chris Boumenot, Bryan Brady,
Lane Brooks, John Brownlee, Lauren Carlson, Robert A. Clark, Allan
Cochrane, Gunter Dannoritzer, Bernard Deadman, John Deroo, John Dickol,
Danny Ding, Jeff Dutton, Robert Farrell, Eugen Fekete, Sam Gladstone,
Thomas Hawkins, David Hewson, Jae Hossell, Ben Jackson, Mike Kagen,
Patricio Kaplan, Ralf Karge, Dan Katz, Sol Katzman, Jonathan Kimmitt,
Gernot Koch, Steve Kolecki, Steve Lang, Stephane Laurent, Charlie Lind, Dan
Lussier, Fred Ma, Wim Michiels, John Murphy, Richard Myers, Paul Nitza,
Lisa Noack, Mark Nodine, Niranjan Prabhu, Oleg Rodionov, Mike Shinkarovsky,
Rafael Shirakawa, Rodney Sinclair, John Stroebel, Emerson Suguimoto, Renga
Sundararajan, Stefan Thiede, Steve Tong, Holger Waechtler, Shawn Wang, Greg
Waters, Eugene Weber, Leon Wildman, Gerald Williams, Johan Wouters, and
Ding Xiaoliang.
=head1 DISTRIBUTION
The latest version is available from L<http://www.veripool.org/>.
Copyright 2003-2008 by Wilson Snyder. Verilator is free software; you can
Copyright 2003-2009 by Wilson Snyder. Verilator is free software; you can
redistribute it and/or modify it under the terms of either the GNU Lesser
General Public License or the Perl Artistic License.
+13 -17
View File
@@ -1,18 +1,7 @@
: # -*-Mode: perl;-*- use perl, wherever it is
eval 'exec perl -wS $0 ${1+"$@"}'
if 0;
######################################################################
#
# Copyright 2005-2008 by Wilson Snyder <[email protected]>. This
# program is free software; you can redistribute it and/or modify it under
# the terms of either the GNU Lesser General Public License or the Perl
# Artistic License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# See copyright, etc in below POD section.
######################################################################
require 5.006_001;
@@ -32,14 +21,16 @@ use vars qw ($Debug);
$Debug = 0;
my $Opt_A;
my $Opt_B;
my $Opt_Lineno = 1;
autoflush STDOUT 1;
autoflush STDERR 1;
Getopt::Long::config ("no_auto_abbrev");
if (! GetOptions (
"help" => \&usage,
"debug" => \&debug,
"<>" => \&parameter,
)) {
"help" => \&usage,
"debug" => \&debug,
"<>" => \&parameter,
"lineno!" => \$Opt_Lineno,
)) {
die "%Error: Bad usage, try 'verilator_difftree --help'\n";
}
@@ -105,6 +96,7 @@ sub filter {
next if $line =~ / This=/;
$line =~ s/0x[a-f0-9]+/0x/g;
$line =~ s/<e[0-9]+\#?>/<e>/g;
$line =~ s/{\d+}/{}/g if !$Opt_Lineno;
print $f2 $line;
}
$f1->close;
@@ -172,13 +164,17 @@ directories, ignoring irrelevant pointer differences.
Displays this message and program version and exits.
=item --nolineno
Do not show differences in line numbering.
=back
=head1 DISTRIBUTION
The latest version is available from L<http://www.veripool.org/verilator>.
Copyright 2005-2008 by Wilson Snyder. This package is free software; you
Copyright 2005-2009 by Wilson Snyder. This package is free software; you
can redistribute it and/or modify it under the terms of either the GNU
Lesser General Public License or the Perl Artistic License.
+1 -1
View File
@@ -3,7 +3,7 @@ eval 'exec perl -wS $0 ${1+"$@"}'
if 0;
# DESCRIPTION: Print include statements for each ARGV
#
# Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
# Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# General Public License or the Perl Artistic License.
######################################################################
+2 -2
View File
@@ -107,7 +107,7 @@ sub profcfunc {
}
}
if ($vfunc =~ /__PROF__([a-zA-Z_0-9]+)__([0-9]+)\(/) {
if ($vfunc =~ /__PROF__([a-zA-Z_0-9]+)__l?([0-9]+)\(/) {
$vfunc = sprintf("VBlock %s:%d", $1, $2);
$groups{type}{"Verilog Blocks under $design"} += $pct;
$groups{design}{$design} += $pct;
@@ -208,7 +208,7 @@ Displays this message and program version and exits.
The latest version is available from L<http://www.veripool.org/>.
Copyright 2007-2008 by Wilson Snyder. This package is free software; you
Copyright 2007-2009 by Wilson Snyder. This package is free software; you
can redistribute it and/or modify it under the terms of either the GNU
Lesser General Public License or the Perl Artistic License.
+1 -1
View File
@@ -1,5 +1,5 @@
dnl DESCRIPTION: Process this file with autoconf to produce a configure script.
dnl Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
dnl Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
dnl redistribute it and/or modify it under the terms of either the GNU
dnl General Public License or the Perl Artistic License.
+8 -4
View File
@@ -1,7 +1,7 @@
// -*- C++ -*-
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 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 or the Perl Artistic License.
//
@@ -73,9 +73,9 @@ void vl_fatal (const char* filename, int linenum, const char* hier, const char*
IData VL_RAND32() {
#if defined(_WIN32) && !defined(__CYGWIN__)
// Windows doesn't have lrand48(), although Cygwin does.
return (rand()<<16) | rand();
return (rand()<<16) ^ rand();
#else
return (lrand48()<<16) | lrand48();
return (lrand48()<<16) ^ lrand48();
#endif
}
@@ -539,7 +539,11 @@ IData VL_FGETS_IXQ(int obits, void* destp, QData fpq) {
// any read data. This means we can't know in what location the first
// character will finally live, so we need to copy. Yuk.
IData bytes = VL_BYTES_I(obits);
char buffer[bytes];
char buffer[VL_TO_STRING_MAX_WORDS*VL_WORDSIZE+1];
// V3Emit has static check that bytes < VL_TO_STRING_MAX_WORDS, but be safe
if (VL_UNLIKELY(bytes > VL_TO_STRING_MAX_WORDS*VL_WORDSIZE)) {
vl_fatal(__FILE__,__LINE__,"","Internal: fgets buffer overrun");
}
// We don't use fgets, as we must read \0s.
IData got = 0;
+27 -17
View File
@@ -1,7 +1,7 @@
// -*- C++ -*-
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 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 or the Perl Artistic License.
//
@@ -359,35 +359,45 @@ static inline void VL_ASSIGNBIT_WO(int, int bit, WDataOutP owp, IData) {
//===================================================================
// SYSTEMC OPERATORS
// Copying verilog format to/from systemc integers and bit vectors.
#define VL_ASSIGN_IS(obits,vvar,svar) { (vvar) = VL_CLEAN_II((obits),(obits),(svar).read()); }
#define VL_ASSIGN_SI(obits,svar,vvar) { (svar).write(vvar); }
// Copying verilog format to systemc integers and bit vectors.
#define VL_ASSIGN_ISI(obits,vvar,svar) { (vvar) = VL_CLEAN_II((obits),(obits),(svar).read()); }
#define VL_ASSIGN_QSQ(obits,vvar,svar) { (vvar) = VL_CLEAN_QQ((obits),(obits),(svar).read()); }
#define VL_ASSIGN_ISW(obits,od,svar) { \
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); \
}
#define VL_ASSIGN_WSW(obits,owp,svar) { \
int words = VL_WORDS_I(obits); \
for (int i=0; i < words; i++) owp[i] = svar.read().get_word(i); \
owp[words-1] &= VL_MASK_I(obits); \
}
// Copying verilog format from systemc integers and bit vectors.
#define VL_ASSIGN_SII(obits,svar,vvar) { (svar).write(vvar); }
#define VL_ASSIGN_SQQ(obits,svar,vvar) { (svar).write(vvar); }
#define VL_ASSIGN_SQ(obits,svar,rd) { \
#define VL_ASSIGN_SWI(obits,svar,rd) { \
sc_bv<obits> _bvtemp; \
_bvtemp.set_word(0,rd); \
svar.write(_bvtemp); \
}
#define VL_ASSIGN_SWQ(obits,svar,rd) { \
sc_bv<obits> _bvtemp; \
_bvtemp.set_word(0,rd); \
_bvtemp.set_word(1,rd>>VL_WORDSIZE); \
svar.write(_bvtemp); \
}
#define VL_ASSIGN_QS(obits,od,svar) { \
od = (((QData)svar.read().get_word(1))<<VL_WORDSIZE | svar.read().get_word(0)) \
& VL_MASK_Q(obits); \
}
#define VL_ASSIGN_SW(obits,svar,rwp) { \
#define VL_ASSIGN_SWW(obits,svar,rwp) { \
sc_bv<obits> _bvtemp; \
for (int i=0; i < VL_WORDS_I(obits); i++) _bvtemp.set_word(i,rwp[i]); \
svar.write(_bvtemp); \
}
#define VL_ASSIGN_WS(obits,owp,svar) { \
int words = VL_WORDS_I(obits); \
for (int i=0; i < words; i++) owp[i] = svar.read().get_word(i); \
owp[words-1] &= VL_MASK_I(obits); \
}
//===================================================================
// Extending sizes
+7 -7
View File
@@ -2,7 +2,7 @@
######################################################################
# DESCRIPTION: Makefile commands for all verilated target files
#
# Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
# Copyright 2003-2009 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 or the Perl Artistic License.
######################################################################
@@ -89,8 +89,8 @@ endif
##### SystemPerl builds
ifeq ($(VM_SP),1)
CPPFLAGS += -I$(SYSTEMPERL)/src -DSYSTEMPERL
VPATH += $(SYSTEMPERL)/src
CPPFLAGS += -I$(SYSTEMPERL_INCLUDE) -DSYSTEMPERL
VPATH += $(SYSTEMPERL_INCLUDE)
LIBS += -lm -lstdc++
VK_CLASSES_SP = $(addsuffix .sp, $(VM_CLASSES))
@@ -110,8 +110,8 @@ endif
ifeq ($(VM_SC),1)
LIBS += -lm -lstdc++
ifeq ($(VM_TRACE),1)
CPPFLAGS += -I$(SYSTEMPERL)/src
VPATH += $(SYSTEMPERL)/src
CPPFLAGS += -I$(SYSTEMPERL_INCLUDE)
VPATH += $(SYSTEMPERL_INCLUDE)
endif
endif
@@ -121,8 +121,8 @@ endif
ifeq ($(VM_PCLI),1)
LIBS += -lm -lstdc++
ifeq ($(VM_TRACE),1)
CPPFLAGS += -I$(SYSTEMPERL)/src
VPATH += $(SYSTEMPERL)/src
CPPFLAGS += -I$(SYSTEMPERL_INCLUDE)
VPATH += $(SYSTEMPERL_INCLUDE)
endif
endif
+1 -1
View File
@@ -5,7 +5,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 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 or the Perl Artistic License.
//
+3 -3
View File
@@ -1,7 +1,7 @@
// -*- C++ -*-
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 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 or the Perl Artistic License.
//
@@ -86,10 +86,10 @@ typedef long vlsint32_t; ///< 32-bit signed type
typedef unsigned long vluint32_t; ///< 32-bit unsigned type
typedef long long vlsint64_t; ///< 64-bit signed type
typedef unsigned long long vluint64_t; ///< 64-bit unsigned type
#elif defined(_WIN32) && !defined(__MINGW32__)
#elif defined(_WIN32) && defined(_MSC_VER)
typedef unsigned char uint8_t; ///< 8-bit unsigned type (backward compatibility)
typedef unsigned short int uint16_t; ///< 16-bit unsigned type (backward compatibility)
typedef unsigned long uint32_t; ///< 32-bit unsigned type (backward compatibility)
typedef unsigned int uint32_t; ///< 32-bit unsigned type (backward compatibility)
typedef unsigned char vluint8_t; ///< 8-bit unsigned type
typedef unsigned short int vluint16_t; ///< 16-bit unsigned type
typedef int vlsint32_t; ///< 32-bit signed type
+73
View File
@@ -0,0 +1,73 @@
#!/usr/bin/perl -w
######################################################################
#
# Copyright 2007-2009 by Wilson Snyder.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of either the GNU General Public License or the
# Perl Artistic License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the Perl Artistic License
# along with this module; see the file COPYING. If not, see
# www.cpan.org
#
######################################################################
# DESCRIPTION: Diff bison files
use IO::File;
use strict;
my $Debug;
diff($ARGV[0],$ARGV[1]);
sub diff {
my $a=shift;
my $b=shift;
my $ta = "/tmp/bisondiff.$$.a";
my $tb = "/tmp/bisondiff.$$.b";
prep($a,$ta);
prep($b,$tb);
system("diff -u -w $ta $tb");
}
sub prep {
my $filename = shift;
my $wfilename = shift;
my $fh = IO::File->new("<$filename") or die "%Error: $! $filename";
my $fho = IO::File->new(">$wfilename") or die "%Error: $! writing $wfilename";
my %declared;
my %used;
my $body = 0;
my $rule = "";
my $skip = 1;
while (defined(my $line = $fh->getline)) {
if ($skip == 1) {
next if $line !~ /%token/;
$skip = 2;
}
# %type<foo>
$line =~ s/^(%\S+)<(\S+)>/$1/;
# rule<foo>
$line =~ s/^([a-zA-Z0-9_]+)<\S+>:/$1:/;
# Productions
$line =~ s/[ \t]{[^}]*?}/\t{}/g;
$fho->print($line);
}
}
# Local Variables:
# compile-command: "./bisondiff $WUP/Verilog/Parser/VParseBison.y ../src/verilog.y"
# End:
+4 -4
View File
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
######################################################################
#
# Copyright 2007-2008 by Wilson Snyder.
# Copyright 2007-2009 by Wilson Snyder.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of either the GNU General Public License or the
@@ -42,8 +42,8 @@ foreach my $line (<STDIN>) {
$rule .= $line;
if ($line =~ m!^\s*;\s*$!) {
#print "Rule: $rule\n";
($rule =~ /^([a-zA-Z0-9_]+):(.*)$/) or die "%Error: No rule name: $1\n";
my $rulename = $1; my $preaction = $2;
($rule =~ /^([a-zA-Z0-9_]+)(<\S+>)?:(.*)$/) or die "%Error: No rule name: $1\n";
my $rulename = $1; my $preaction = $3;
$declared{$rulename} = $lineno;
$preaction =~ s/\{[^\}]*\}/ /g;
#print "RULEN $rulename PA $preaction\n" if $Debug;
@@ -62,5 +62,5 @@ foreach my $line (<STDIN>) {
}
# Local Variables:
# compile-command: "./bisonreader < verilog.y"
# compile-command: "./bisonreader < ../src/verilog.y"
# End:
+1 -1
View File
@@ -143,7 +143,7 @@ Displays this message and program version and exits.
=head1 DISTRIBUTION
Copyright 2005-2008 by Wilson Snyder. This package is free software; you
Copyright 2005-2009 by Wilson Snyder. This package is free software; you
can redistribute it and/or modify it under the terms of either the GNU
Lesser General Public License or the Perl Artistic License.
+1 -1
View File
@@ -184,7 +184,7 @@ Displays this message and program version and exits.
=head1 DISTRIBUTION
Copyright 2005-2008 by Wilson Snyder. This package is free software; you
Copyright 2005-2009 by Wilson Snyder. This package is free software; you
can redistribute it and/or modify it under the terms of either the GNU
Lesser General Public License or the Perl Artistic License.
+1 -1
View File
@@ -40,7 +40,7 @@ invoke_iccr - Invoke tool under "modules" command
=head1 DISTRIBUTION
Copyright 2007-2008 by Wilson Snyder. This package is free software; you
Copyright 2007-2009 by Wilson Snyder. This package is free software; you
can redistribute it and/or modify it under the terms of either the GNU
Lesser General Public License or the Perl Artistic License.
+1 -1
View File
@@ -40,7 +40,7 @@ invoke_ncverilog - Invoke tool under "modules" command
=head1 DISTRIBUTION
Copyright 2007-2008 by Wilson Snyder. This package is free software; you
Copyright 2007-2009 by Wilson Snyder. This package is free software; you
can redistribute it and/or modify it under the terms of either the GNU
Lesser General Public License or the Perl Artistic License.
+1 -1
View File
@@ -331,7 +331,7 @@ Displays this message and program version and exits.
=head1 DISTRIBUTION
Copyright 2005-2008 by Wilson Snyder. This package is free software; you
Copyright 2005-2009 by Wilson Snyder. This package is free software; you
can redistribute it and/or modify it under the terms of either the GNU
Lesser General Public License or the Perl Artistic License.
+6 -5
View File
@@ -26,7 +26,7 @@ This is the Verilator Package.
@node Copyright, Description, Top, Top
@section Copyright
This package is Copyright 2003-2008 by Wilson Snyder @email{wsnyder@@wsnyder.org}.
This package is Copyright 2003-2009 by Wilson Snyder @email{wsnyder@@wsnyder.org}.
You may distribute under the terms of either the GNU General Public License
or the Artistic License, as specified in the Perl README file.
@@ -116,8 +116,9 @@ If you will be using SystemC, download and install Verilog-Perl,
If you will be using SystemC, download and install System-Perl,
@url{http://search.cpan.org/search?module=SystemC::Netlist}. Note
you'll need to set a @samp{SYSTEMPERL} environment variable to point
to the downloaded kit (not the installed files.) Also, make sure to
do a @code{make sc_patch}.
to the downloaded kit. Optionally also set @samp{SYSTEMPERL_INCLUDE}
to point to the installed headers. Also, make sure to do a @code{make
sc_patch}.
@item
@code{cd} to the Verilator directory containing this README.
@@ -128,8 +129,8 @@ Type @samp{./configure} to configure Verilator for your system.
If you are configuring Verilator to be part of a RPM or other
distribution package system, you may want to use the --enable-defenv
configure flag. This will take the current value of VERILATOR_ROOT,
SYSTEMC, SYSTEMC_ARCH, and SYSTEMPERL and build them as defaults into
the executable.
SYSTEMC, SYSTEMC_ARCH, SYSTEMPERL, and SYSTEMPERL_INCLUDE and build
them as defaults into the executable.
@item
Type @samp{make} to compile Verilator.
+1
View File
@@ -1,3 +1,4 @@
*~
*.old
config_build.h
Makefile
+70
View File
@@ -0,0 +1,70 @@
=pod
=head1 NAME
Verilator Source Code Notes
=head1 INTRODUCTION
See also the Verilator internals presentation at http://www.veripool.org.
=head1 VISITOR FUNCTIONS
=head2 Passing Variables
There's three ways data is passed between visitor functions.
1. A visitor-class member variable. This is generally for passing "parent"
information down to children. m_modp is a common example. It's set to
NULL in the constructor, where that node (AstModule visitor) sets it, then
the children are iterated, then it's cleared. Children under an AstModule
will see it set, while nodes elsewhere will see it clear. If there can be
nested items (for example an AstFor under an AstFor) the variable needs to
be save-set-restored in the AstFor visitor, otherwise exiting the lower for
will loose the upper for's setting.
2. User() attributes. Each node has 4 ->user() number or ->userp() pointer
utility values (a common technique lifted from graph traversal packages).
A visitor first clears the one it wants to use by calling
AstNode::user#ClearTree(), then it can mark any node's user() with whatever
data it wants. Readers just call nodep->user(), but may need to cast
appropriately, so you'll often see nodep->userp()->castSOMETYPE(). At the
top of each visitor are comments describing how the user() stuff applies to
that visitor class. For example:
// NODE STATE
// Cleared entire netlist
// AstModule::user1p() // bool. True to inline this module
This says that at the AstNetlist user1ClearTree() is called. Each
AstModule's is user1() is used to indicate if we're going to inline it.
These comments are important to make sure a user#() on a given AstNode type
is never being used for two different purposes.
Note that calling user#ClearTree is fast, it doesn't walk the tree, so it's
ok to call fairly often. For example, it's commonly called on every
module.
3. Parameters can be passed between the visitors in close to the "normal"
function caller to callee way. This is the second "vup" parameter that is
ignored on most of the visitor functions. V3Width does this, but it proved
more messy than the above and is deprecated. (V3Width was nearly the first
module written. Someday this scheme may be removed, as it slows the
program down to have to pass vup everywhere.)
=head1 DEBUGGING WITH GDB
The test_regress/driver.pl script accepts --gdb to start Verilator under
gdb.
To break at a specific edit number which changed a node (presumably to find
what made a <e####> line in the tree dumps):
watch AstNode::s_editCntGbl==####
=head1 DISTRIBUTION
Copyright 2008-2009 by Wilson Snyder. This program is free software; you
can redistribute it and/or modify it under the terms of either the GNU
General Public License or the Perl Artistic License.
+1 -1
View File
@@ -7,7 +7,7 @@
#
#*****************************************************************************
#
# Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
# Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# General Public License or the Perl Artistic License.
#
+12 -3
View File
@@ -7,7 +7,7 @@
#
#*****************************************************************************
#
# Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
# Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# General Public License or the Perl Artistic License.
#
@@ -81,12 +81,19 @@ CPPFLAGS += -W -Wall -Wno-unused-parameter -Wno-char-subscripts -Werror
#CPPFLAGS += -pedantic-errors
endif
ifneq ($(SYSTEMPERL),) # Intuit SYSTEMPERL_INCLUDE as it's new
SYSTEMPERL_INCLUDE ?= $(SYSTEMPERL)/src
#else if set, leave as-is.
#else if SYSTEMPERL="" don't set _INCLUDE so source will figure it out
endif
# Allow RPM builds to specify hardcoded data directories
# To do this:
ifeq ($(CFG_WITH_DEFENV),yes)
CPPFLAGS += -DDEFENV_SYSTEMC=\"$(SYSTEMC)\"
CPPFLAGS += -DDEFENV_SYSTEMC_ARCH=\"$(SYSTEMC_ARCH)\"
CPPFLAGS += -DDEFENV_SYSTEMPERL=\"$(SYSTEMPERL)\"
CPPFLAGS += -DDEFENV_SYSTEMPERL_INCLUDE=\"$(SYSTEMPERL_INCLUDE)\"
ifeq ($(VERILATOR_ROOT),) # Use what we're given, or intuit
CPPFLAGS += -DDEFENV_VERILATOR_ROOT=\"$(pkgdatadir)\"
else
@@ -136,10 +143,12 @@ RAW_OBJS = \
V3Cast.o \
V3Changed.o \
V3Clean.o \
V3ClkGater.o \
V3Clock.o \
V3Combine.o \
V3Const__gen.o \
V3Coverage.o \
V3CoverageJoin.o \
V3Dead.o \
V3Delayed.o \
V3Depth.o \
@@ -191,6 +200,7 @@ RAW_OBJS = \
V3Task.o \
V3Trace.o \
V3TraceDecl.o \
V3Tristate.o \
V3Unknown.o \
V3Unroll.o \
V3Width.o \
@@ -226,7 +236,7 @@ V3Number_test: V3Number_test.o
#### Modules
%__gen.cpp: %.cpp $(ASTGEN)
%__gen.cpp: %.cpp $(ASTGEN) V3Ast.h V3AstNodes.h
$(PERL) $(ASTGEN) -I$(srcdir) $*.cpp
%.o: %.cpp
@@ -277,4 +287,3 @@ DEPS := $(wildcard *.d)
ifneq ($(DEPS),)
include $(DEPS)
endif
+61 -24
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -43,6 +43,7 @@
#include "V3Active.h"
#include "V3Ast.h"
#include "V3EmitCBase.h"
#include "V3Const.h"
//***** See below for main transformation engine
@@ -51,7 +52,11 @@
class ActiveBaseVisitor : public AstNVisitor {
protected:
//int debug() { return 9; }
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
};
class ActiveNamer : public ActiveBaseVisitor {
@@ -77,8 +82,8 @@ private:
// Don't clear scopep, the namer persists beyond this visit
}
virtual void visit(AstSenTree* nodep, AstNUser*) {
// Sort sensitivity list
nodep->sortSenses();
// Simplify sensitivity list
V3Const::constifyTreeExpensive(nodep);
}
// Empty visitors, speed things up
virtual void visit(AstNodeStmt* nodep, AstNUser*) { }
@@ -129,7 +134,7 @@ public:
found:
// Not found, form a new one
if (!activep) {
AstSenTree* newsenp = sensesp->cloneTree(false)->castSenTree();
AstSenTree* newsenp = sensesp->cloneTree(false);
activep = new AstActive(fl, "sequent", newsenp);
activep->sensesStorep(activep->sensesp());
UINFO(8," New ACTIVE "<<activep<<endl);
@@ -185,10 +190,15 @@ public:
class ActiveVisitor : public ActiveBaseVisitor {
private:
// NODE STATE
// Each call to V3Const::constify
// AstNode::user4() Used by V3Const::constify, called below
// STATE
ActiveNamer m_namer; // Tracking of active names
AstCFunc* m_scopeFinalp; // Final function for this scope
AstAlways* m_alwaysp; // Under always
bool m_itemCombo; // Found a SenItem combo
bool m_itemSequent; // Found a SenItem sequential
// VISITORS
virtual void visit(AstScope* nodep, AstNUser*) {
@@ -223,6 +233,13 @@ private:
nodep->unlinkFrBack();
wantactivep->addStmtsp(nodep);
}
virtual void visit(AstCoverToggle* nodep, AstNUser*) {
// Relink to CACTIVE, unless already under it
UINFO(4," COVERTOGGLE "<<nodep<<endl);
AstActive* wantactivep = m_namer.getCActive(nodep->fileline());
nodep->unlinkFrBack();
wantactivep->addStmtsp(nodep);
}
virtual void visit(AstFinal* nodep, AstNUser*) {
// Relink to CFUNC for the final
UINFO(4," FINAL "<<nodep<<endl);
@@ -245,6 +262,7 @@ private:
nodep->deleteTree(); nodep = NULL;
}
// METHODS
virtual void visit(AstAlways* nodep, AstNUser*) {
// Move always to appropriate ACTIVE based on its sense list
UINFO(4," ALW "<<nodep<<endl);
@@ -255,7 +273,10 @@ private:
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
return;
}
if (nodep->sensesp() && nodep->sensesp()->sensesp() && nodep->sensesp()->sensesp()->isNever()) {
if (nodep->sensesp()
&& nodep->sensesp()->sensesp()
&& nodep->sensesp()->sensesp()->castSenItem()
&& nodep->sensesp()->sensesp()->castSenItem()->isNever()) {
// Never executing. Kill it.
if (nodep->sensesp()->sensesp()->nextp()) nodep->v3fatalSrc("Never senitem should be alone, else the never should be eliminated.");
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
@@ -263,24 +284,14 @@ private:
}
// Read sensitivitues
bool combo = false;
bool sequent = false;
if (nodep->sensesp()) {
for (AstSenItem* nextp, *senp = nodep->sensesp()->sensesp(); senp; senp=nextp) {
nextp = senp->nextp()->castSenItem();
if (senp->edgeType() == AstEdgeType::ANYEDGE) {
combo = true;
// Delete the sensitivity
// We'll add it as a generic COMBO SenItem in a moment.
senp->unlinkFrBack()->deleteTree(); senp=NULL;
} else if (senp->varrefp()) {
if (senp->varrefp()->width()>1) senp->v3error("Unsupported: Non-single bit wide signal pos/negedge sensitivity: "
<<senp->varrefp()->prettyName());
sequent = true;
senp->varrefp()->varp()->usedClock(true);
}
}
}
m_alwaysp = nodep;
m_itemCombo = false;
m_itemSequent = false;
nodep->sensesp()->iterateAndNext(*this);
m_alwaysp = NULL;
bool combo = m_itemCombo;
bool sequent = m_itemSequent;
if (!combo && !sequent) combo=true; // If no list, Verilog 2000: always @ (*)
#ifndef NEW_ORDERING
if (combo && sequent) {
@@ -319,6 +330,29 @@ private:
ActiveDlyVisitor dlyvisitor (nodep);
}
}
virtual void visit(AstSenGate* nodep, AstNUser*) {
AstSenItem* subitemp = nodep->sensesp();
if (subitemp->edgeType() != AstEdgeType::ANYEDGE
&& subitemp->edgeType() != AstEdgeType::POSEDGE
&& subitemp->edgeType() != AstEdgeType::NEGEDGE) {
nodep->v3fatalSrc("Strange activity type under SenGate");
}
nodep->iterateChildren(*this);
}
virtual void visit(AstSenItem* nodep, AstNUser*) {
if (nodep->edgeType() == AstEdgeType::ANYEDGE) {
m_itemCombo = true;
// Delete the sensitivity
// We'll add it as a generic COMBO SenItem in a moment.
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
} else if (nodep->varrefp()) {
// V3LinkResolve should have cleaned most of these up
if (nodep->varrefp()->width()>1) nodep->v3error("Unsupported: Non-single bit wide signal pos/negedge sensitivity: "
<<nodep->varrefp()->prettyName());
m_itemSequent = true;
nodep->varrefp()->varp()->usedClock(true);
}
}
// Empty visitors, speed things up
virtual void visit(AstNodeMath* nodep, AstNUser*) {}
@@ -331,6 +365,9 @@ public:
// CONSTUCTORS
ActiveVisitor(AstNode* nodep) {
m_scopeFinalp = NULL;
m_alwaysp = NULL;
m_itemCombo = false;
m_itemSequent = false;
nodep->accept(*this);
}
virtual ~ActiveVisitor() {}
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+17 -5
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -39,6 +39,7 @@
#include "V3ActiveTop.h"
#include "V3Ast.h"
#include "V3SenTree.h"
#include "V3Const.h"
//######################################################################
// Active class functions
@@ -48,10 +49,20 @@ private:
// NODE STATE
// Entire netlist
// AstNode::user() bool. True if processed
// Each call to V3Const::constify
// AstNode::user4() Used by V3Const::constify, called below
AstUser1InUse m_inuser1;
// STATE
AstTopScope* m_topscopep; // Top scope for adding sentrees under
SenTreeFinder m_finder; // Find global sentree's and add them
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
// VISITORS
virtual void visit(AstTopScope* nodep, AstNUser*) {
@@ -70,8 +81,10 @@ private:
UINFO(4," ACTIVE "<<nodep<<endl);
AstSenTree* sensesp = nodep->sensesp();
if (!sensesp) nodep->v3fatalSrc("NULL");
sensesp->sortSenses(); // Remove duplicate clocks and such
if (sensesp->sensesp() && sensesp->sensesp()->isNever()) {
V3Const::constifyTreeExpensive(nodep); // Remove duplicate clocks and such
if (sensesp->sensesp()
&& sensesp->sensesp()->castSenItem()
&& sensesp->sensesp()->castSenItem()->isNever()) {
// Never executing. Kill it.
if (sensesp->sensesp()->nextp()) nodep->v3fatalSrc("Never senitem should be alone, else the never should be eliminated.");
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
@@ -133,7 +146,6 @@ public:
// CONSTUCTORS
ActiveTopVisitor(AstNetlist* nodep) {
m_topscopep = NULL;
AstNode::userClearTree();
nodep->accept(*this);
}
virtual ~ActiveTopVisitor() {}
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+5 -5
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2005-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2005-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -40,6 +40,7 @@ private:
// NODE STATE/TYPES
// Cleared on netlist
// AstNode::user() -> bool. True if processed
AstUser1InUse m_inuser1;
// STATE
AstModule* m_modp; // Last module
@@ -115,7 +116,7 @@ private:
} else {
// V3Coverage assigned us a bucket to increment.
AstCoverInc* covincp = snodep->coverincp()->castCoverInc();
if (!covincp) snodep->v3fatalSrc("Missing coverage in PSL");
if (!covincp) snodep->v3fatalSrc("Missing AstCoverInc under assertion");
covincp->unlinkFrBack();
if (message!="") covincp->declp()->comment(message);
bodysp = covincp;
@@ -175,8 +176,8 @@ private:
// VISITORS //========== Case assertions
virtual void visit(AstCase* nodep, AstNUser*) {
nodep->iterateChildren(*this);
if (!nodep->user()) {
nodep->user(true);
if (!nodep->user1()) {
nodep->user1(true);
bool has_default=false;
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=itemp->nextp()->castCaseItem()) {
if (itemp->isDefault()) has_default=true;
@@ -288,7 +289,6 @@ public:
m_beginp = NULL;
m_modp = NULL;
// Process
AstNode::userClearTree(); // userp() used on entire tree
nodep->accept(*this);
}
virtual ~AssertVisitor() {
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2005-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2005-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+10 -6
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2005-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2005-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -44,18 +44,22 @@ private:
// NODE STATE/TYPES
// STATE
// Reset each module:
AstSenItem* m_seniDefaultp; // Default sensitivity (from AstDefClock)
AstNodeSenItem* m_seniDefaultp; // Default sensitivity (from AstDefClock)
// Reset each assertion:
AstSenItem* m_senip; // Last sensitivity
int debug() { return 0; }
AstNodeSenItem* m_senip; // Last sensitivity
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
AstSenTree* newSenTree(AstNode* nodep) {
// Create sentree based on clocked or default clock
// Return NULL for always
AstSenTree* newp = NULL;
AstSenItem* senip = m_senip ? m_senip : m_seniDefaultp;
AstNodeSenItem* senip = m_senip ? m_senip : m_seniDefaultp;
if (!senip) {
nodep->v3error("Unsupported: Unclocked assertion");
newp = new AstSenTree(nodep->fileline(), NULL);
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2005-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2005-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+71 -42
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -39,11 +39,15 @@ vluint64_t AstNode::s_editCntLast=0;
// along with each userp, and thus by bumping this count we can make it look
// as if we iterated across the entire tree to set all the userp's to null.
int AstNode::s_cloneCntGbl=0;
int AstNode::s_userCntGbl=0;
int AstNode::s_user2CntGbl=0;
int AstNode::s_user3CntGbl=0;
int AstNode::s_user4CntGbl=0;
int AstNode::s_user5CntGbl=0;
uint32_t AstUser1InUse::s_userCntGbl=0; // Hot cache line, leave adjacent
uint32_t AstUser2InUse::s_userCntGbl=0; // Hot cache line, leave adjacent
uint32_t AstUser3InUse::s_userCntGbl=0; // Hot cache line, leave adjacent
uint32_t AstUser4InUse::s_userCntGbl=0; // Hot cache line, leave adjacent
bool AstUser1InUse::s_userBusy=false;
bool AstUser2InUse::s_userBusy=false;
bool AstUser3InUse::s_userBusy=false;
bool AstUser4InUse::s_userBusy=false;
//######################################################################
// V3AstType
@@ -70,16 +74,14 @@ void AstNode::init() {
m_signed = false;
m_width = 0;
m_widthMin = 0;
m_userp = NULL;
m_userCnt = 0;
m_user1p = NULL;
m_user1Cnt = 0;
m_user2p = NULL;
m_user2Cnt = 0;
m_user3p = NULL;
m_user3Cnt = 0;
m_user4p = NULL;
m_user4Cnt = 0;
m_user5p = NULL;
m_user5Cnt = 0;
}
string AstNode::encodeName(const string& namein) {
@@ -92,7 +94,7 @@ string AstNode::encodeName(const string& namein) {
out += pos[0];
} else if (pos[0]=='_') {
if (pos[1]=='_') {
out += "_"; out += "__5F"; // hex(_) = 0x5F
out += "_"; out += "__05F"; // hex(_) = 0x5F
pos++;
} else {
out += pos[0];
@@ -104,13 +106,23 @@ string AstNode::encodeName(const string& namein) {
} else if (pos[0]==']') {
out += "__KET__";
} else {
// Need the leading 0 so this will never collide with
// a user identifier nor a temp we create in Verilator.
char hex[10]; sprintf(hex,"%02X",pos[0]);
out += "__"; out += hex;
out += "__0"; out += hex;
}
}
return out;
}
string AstNode::encodeNumber(vlsint64_t num) {
if (num < 0) {
return "__02D"+cvtToStr(-num); // 2D=-
} else {
return cvtToStr(num);
}
}
string AstNode::shortName() const {
string pretty = name();
string::size_type pos;
@@ -151,12 +163,13 @@ string AstNode::prettyName(const string& namein) {
pretty += "";
pos += 7;
}
else if (pos[0]=='_' && pos[1]=='_' && isxdigit(pos[2]) && isxdigit(pos[3])) {
else if (pos[0]=='_' && pos[1]=='_' && pos[2]=='0'
&& isxdigit(pos[3]) && isxdigit(pos[4])) {
char value = 0;
value += 16*(isdigit(pos[2]) ? (pos[2]-'0') : (tolower(pos[2])-'a'+10));
value += (isdigit(pos[3]) ? (pos[3]-'0') : (tolower(pos[3])-'a'+10));
value += 16*(isdigit(pos[3]) ? (pos[3]-'0') : (tolower(pos[3])-'a'+10));
value += (isdigit(pos[4]) ? (pos[4]-'0') : (tolower(pos[4])-'a'+10));
pretty += value;
pos += 4;
pos += 5;
}
else {
pretty += pos[0];
@@ -663,11 +676,38 @@ void AstNode::operator delete(void* objp, size_t size) {
// Iterators
void AstNode::iterateChildren(AstNVisitor& v, AstNUser* vup) {
// This is a very hot function
if (!this) return;
m_op1p->iterateAndNext(v, vup);
m_op2p->iterateAndNext(v, vup);
m_op3p->iterateAndNext(v, vup);
m_op4p->iterateAndNext(v, vup);
ASTNODE_PREFETCH(m_op1p);
ASTNODE_PREFETCH(m_op2p);
ASTNODE_PREFETCH(m_op3p);
ASTNODE_PREFETCH(m_op4p);
// if () not needed since iterateAndNext accepts null this, but faster with it.
if (m_op1p) m_op1p->iterateAndNext(v, vup);
if (m_op2p) m_op2p->iterateAndNext(v, vup);
if (m_op3p) m_op3p->iterateAndNext(v, vup);
if (m_op4p) m_op4p->iterateAndNext(v, vup);
}
void AstNode::iterateAndNext(AstNVisitor& v, AstNUser* vup) {
// This is a very hot function
// IMPORTANT: If you replace a node that's the target of this iterator,
// then the NEW node will be iterated on next, it isn't skipped!
// if (!this) return; // Part of for()
for (AstNode* nodep=this; nodep;) {
AstNode* niterp = nodep;
ASTNODE_PREFETCH(nodep->m_nextp);
niterp->m_iterpp = &niterp;
niterp->accept(v, vup);
// accept may do a replaceNode and change niterp on us...
if (!niterp) return;
niterp->m_iterpp = NULL;
if (niterp!=nodep) { // Edited it
nodep = niterp;
} else { // Same node, just loop
nodep = niterp->m_nextp;
}
}
}
void AstNode::iterateListBackwards(AstNVisitor& v, AstNUser* vup) {
@@ -690,25 +730,6 @@ void AstNode::iterateChildrenBackwards(AstNVisitor& v, AstNUser* vup) {
this->op4p()->iterateListBackwards(v,vup);
}
void AstNode::iterateAndNext(AstNVisitor& v, AstNUser* vup) {
// IMPORTANT: If you replace a node that's the target of this iterator,
// then the NEW node will be iterated on next, it isn't skipped!
// if (!this) return; // Part of for()
for (AstNode* nodep=this; nodep;) {
AstNode* niterp = nodep;
niterp->m_iterpp = &niterp;
niterp->accept(v, vup);
// accept may do a replaceNode and change niterp on us...
if (!niterp) return;
niterp->m_iterpp = NULL;
if (niterp!=nodep) { // Edited it
nodep = niterp;
} else { // Same node, just loop
nodep = niterp->m_nextp;
}
}
}
void AstNode::iterateAndNextIgnoreEdit(AstNVisitor& v, AstNUser* vup) {
// Keep following the current list even if edits change it
if (!this) return;
@@ -779,6 +800,11 @@ void AstNode::checkTreeIter(AstNode* backp) {
if (backp != this->backp()) {
this->v3fatalSrc("Back node inconsistent");
}
if (castNodeTermop() || castNodeVarRef()) {
// Termops have a short-circuited iterateChildren, so check usage
if (op1p()||op2p()||op3p()||op4p())
this->v3fatalSrc("Terminal operation with non-terminals");
}
if (op1p()) op1p()->checkTreeIterList(this);
if (op2p()) op2p()->checkTreeIterList(this);
if (op3p()) op3p()->checkTreeIterList(this);
@@ -821,7 +847,10 @@ void AstNode::dumpPtrs(ostream& os) {
if (op2p()) os<<" op2p="<<(void*)op2p();
if (op3p()) os<<" op3p="<<(void*)op3p();
if (op4p()) os<<" op4p="<<(void*)op4p();
if (userp()) os<<" user="<<(void*)userp();
if (user1p()) os<<" user1p="<<(void*)user1p();
if (user2p()) os<<" user2p="<<(void*)user2p();
if (user3p()) os<<" user3p="<<(void*)user3p();
if (user4p()) os<<" user4p="<<(void*)user4p();
if (m_iterpp) {
os<<" iterpp="<<(void*)m_iterpp;
os<<"*="<<(void*)*m_iterpp;
@@ -857,7 +886,7 @@ void AstNode::dumpTreeFile(const string& filename, bool append) {
if (logsp->fail()) v3fatalSrc("Can't write "<<filename);
*logsp<<"Tree Dump from <e"<<dec<<editCountLast()<<">";
*logsp<<" to <e"<<dec<<editCountGbl()<<">"<<endl;
if (editCountGbl()==editCountLast() && 1) { // Off, as messes up tree diffing
if (editCountGbl()==editCountLast()) {
*logsp<<endl;
*logsp<<"No changes since last dump!\n";
} else {
@@ -876,7 +905,7 @@ void AstNode::dumpTreeFile(const string& filename, bool append) {
editCountSetLast();
}
void AstNode::v3errorEnd(ostringstream& str) {
void AstNode::v3errorEnd(ostringstream& str) const {
if (this && m_fileline) {
ostringstream nsstr;
nsstr<<str.str();
+181 -71
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -79,14 +79,21 @@ public:
enum en {
NORMAL,
TRACE_INIT,
TRACE_INIT_SUB,
TRACE_FULL,
TRACE_CHANGE
TRACE_FULL_SUB,
TRACE_CHANGE,
TRACE_CHANGE_SUB
};
enum en m_e;
inline AstCFuncType () {};
inline AstCFuncType (en _e) : m_e(_e) {};
explicit inline AstCFuncType (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
// METHODS
bool isTrace() const { return (m_e==TRACE_INIT || m_e==TRACE_INIT_SUB
|| m_e==TRACE_FULL || m_e==TRACE_FULL_SUB
|| m_e==TRACE_CHANGE || m_e==TRACE_CHANGE_SUB); }
};
inline bool operator== (AstCFuncType lhs, AstCFuncType rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (AstCFuncType lhs, AstCFuncType::en rhs) { return (lhs.m_e == rhs); }
@@ -98,7 +105,7 @@ class AstEdgeType {
public:
// REMEMBER to edit the strings below too
enum en {
// These must be in general -> most specific order, as we sort by it in AstSenTree::sortSenses()
// These must be in general -> most specific order, as we sort by it in V3Const::visit AstSenTre
ILLEGAL,
// Involving a variable
ANYEDGE, // Default for sensitivities; rip them out
@@ -142,8 +149,8 @@ public:
};
const char* verilogKwd() const {
static const char* names[] = {
"%E-edge", "", "[both]", "posedge", "negedge", "[high]","[low]",
"/*AS*/","[initial]","[settle]","[never]"
"%E-edge", "[any]", "[both]", "posedge", "negedge", "[high]","[low]",
"*","[initial]","[settle]","[never]"
};
return names[m_e];
};
@@ -355,6 +362,83 @@ struct AstNUser {
}
};
//######################################################################
// AstUserResource - Generic pointer base class for tracking usage of user()
//
// Where AstNode->user2() is going to be used, for example, you write:
//
// AstUser2InUse m_userres;
//
// This will clear the tree, and prevent another visitor from clobering
// user2. When the member goes out of scope it will be automagically
// freed up.
class AstUserInUseBase {
protected:
static void allocate(uint32_t& cntGblRef, bool& userBusyRef) {
// Perhaps there's still a AstUserInUse in scope for this?
UASSERT_STATIC(!userBusyRef, "Conflicting user use; AstUser*InUse request when under another AstUserInUse");
userBusyRef = true;
clearcnt(cntGblRef, userBusyRef);
}
static void free(uint32_t& cntGblRef, bool& userBusyRef) {
UASSERT_STATIC(userBusyRef, "Free of User*() not under AstUserInUse");
clearcnt(cntGblRef, userBusyRef); // Includes a checkUse for us
userBusyRef = false;
}
static void clearcnt(uint32_t& cntGblRef, bool& userBusyRef) {
UASSERT_STATIC(userBusyRef, "Clear of User*() not under AstUserInUse");
// If this really fires and is real (after 2^32 edits???)
// we could just walk the tree and clear manually
++cntGblRef;
UASSERT_STATIC(cntGblRef, "User*() overflowed!");
}
};
// For each user() declare the in use structure
// We let AstNode peek into here, because when under low optimization even
// an accessor would be way too slow.
class AstUser1InUse : AstUserInUseBase {
protected:
friend class AstNode;
static uint32_t s_userCntGbl; // Count of which usage of userp() this is
static bool s_userBusy; // Count is in use
public:
AstUser1InUse() { allocate(s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
~AstUser1InUse() { free (s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
static void clear() { clearcnt(s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
};
class AstUser2InUse : AstUserInUseBase {
protected:
friend class AstNode;
static uint32_t s_userCntGbl; // Count of which usage of userp() this is
static bool s_userBusy; // Count is in use
public:
AstUser2InUse() { allocate(s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
~AstUser2InUse() { free (s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
static void clear() { clearcnt(s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
};
class AstUser3InUse : AstUserInUseBase {
protected:
friend class AstNode;
static uint32_t s_userCntGbl; // Count of which usage of userp() this is
static bool s_userBusy; // Count is in use
public:
AstUser3InUse() { allocate(s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
~AstUser3InUse() { free (s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
static void clear() { clearcnt(s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
};
class AstUser4InUse : AstUserInUseBase {
protected:
friend class AstNode;
static uint32_t s_userCntGbl; // Count of which usage of userp() this is
static bool s_userBusy; // Count is in use
public:
AstUser4InUse() { allocate(s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
~AstUser4InUse() { free (s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
static void clear() { clearcnt(s_userCntGbl/*ref*/, s_userBusy/*ref*/); }
};
//######################################################################
// AstNVisitor -- Allows new functions to be called on each node
// type without changing the base classes. See "Modern C++ Design".
@@ -422,6 +506,7 @@ public:
uint32_t hshval() const { return m_both & M24; }
// OPERATORS
inline bool operator== (const V3Hash& rh) const { return m_both==rh.m_both; };
inline bool operator!= (const V3Hash& rh) const { return m_both!=rh.m_both; };
inline bool operator< (const V3Hash& rh) const { return m_both<rh.m_both; };
// CREATORS
class Illegal {}; // for creator type-overload selection
@@ -435,13 +520,7 @@ public:
// Creating from raw data (sameHash functions)
V3Hash() { setBoth(1,0); }
V3Hash(uint32_t val) { setBoth(1,val); }
V3Hash(void* vp) {
// It's just a hash, so we can shove a 64 bit pointer into a 32 bit bucket
// On 32 bit systems, lower is always 0, but who cares?
union { void* up; struct {uint32_t upper; uint32_t lower;} l;} u;
u.l.upper=0; u.l.lower=0; u.up=vp;
setBoth(1,u.l.upper^u.l.lower);
}
V3Hash(void* vp) { setBoth(1,cvtToHash(vp)); }
V3Hash(const string& name);
V3Hash(V3Hash lh, V3Hash rh) {
setBoth(1,lh.hshval()*31+rh.hshval());
@@ -452,45 +531,46 @@ ostream& operator<<(ostream& os, V3Hash rhs);
//######################################################################
// AstNode -- Base type of all Ast types
// Prefetch a node.
// The if() makes it faster, even though prefetch won't fault on null pointers
#define ASTNODE_PREFETCH(nodep) \
{ if (nodep) { VL_PREFETCH_RD(&(nodep->m_nextp)); VL_PREFETCH_RD(&(nodep->m_iterpp)); }}
class AstNode {
private:
// v ASTNODE_PREFETCH depends on below ordering of members
AstNode* m_nextp; // Next peer in the parent's list
AstNode* m_backp; // Node that points to this one (via next/op1/op2/...)
AstNode* m_headtailp; // When at begin/end of list, the opposite end of the list
AstNode* m_op1p; // Generic pointer 1
AstNode* m_op2p; // Generic pointer 2
AstNode* m_op3p; // Generic pointer 3
AstNode* m_op4p; // Generic pointer 4
AstNode** m_iterpp; // Pointer to node iterating on, change it if we replace this node.
// ^ ASTNODE_PREFETCH depends on above ordering of members
AstNode* m_clonep; // Pointer to clone of/ source of this module (for *LAST* cloneTree() ONLY)
int m_cloneCnt; // Mark of when userp was set
static int s_cloneCntGbl; // Count of which userp is set
AstNode* m_headtailp; // When at begin/end of list, the opposite end of the list
FileLine* m_fileline; // Where it was declared
vluint64_t m_editCount; // When it was last edited
static vluint64_t s_editCntGbl; // Global edit counter
static vluint64_t s_editCntLast;// Global edit counter, last value for printing * near node #s
AstNode* m_clonep; // Pointer to clone of/ source of this module (for *LAST* cloneTree() ONLY)
int m_cloneCnt; // Mark of when userp was set
static int s_cloneCntGbl; // Count of which userp is set
// Attributes
bool m_signed; // Node is signed
int m_width; // Bit width of operation
int m_widthMin; // If unsized, bitwidth of minimum implementation
AstNUser* m_userp; // Pointer to any information the user iteration routine wants
int m_userCnt; // Mark of when userp was set
static int s_userCntGbl; // Count of which userp is set
// This member ordering both allows 64 bit alignment and puts associated data together
AstNUser* m_user1p; // Pointer to any information the user iteration routine wants
uint32_t m_user1Cnt; // Mark of when userp was set
uint32_t m_user2Cnt; // Mark of when userp was set
AstNUser* m_user2p; // Pointer to any information the user iteration routine wants
int m_user2Cnt; // Mark of when userp was set
static int s_user2CntGbl; // Count of which userp is set
AstNUser* m_user3p; // Pointer to any information the user iteration routine wants
int m_user3Cnt; // Mark of when userp was set
static int s_user3CntGbl; // Count of which userp is set
uint32_t m_user3Cnt; // Mark of when userp was set
uint32_t m_user4Cnt; // Mark of when userp was set
AstNUser* m_user4p; // Pointer to any information the user iteration routine wants
int m_user4Cnt; // Mark of when userp was set
static int s_user4CntGbl; // Count of which userp is set
AstNUser* m_user5p; // Pointer to any information the user iteration routine wants
int m_user5Cnt; // Mark of when userp was set
static int s_user5CntGbl; // Count of which userp is set
// METHODS
void op1p(AstNode* nodep) { m_op1p = nodep; if (nodep) nodep->m_backp = this; }
@@ -514,7 +594,7 @@ protected:
// CONSTUCTORS
AstNode() {init(); }
AstNode(FileLine* fileline) {init(); m_fileline = fileline; }
virtual AstNode* clone() = 0; // Generally, cloneTree/cloneNode is what you want
virtual AstNode* clone() = 0; // Generally, cloneTree is what you want instead
virtual void cloneRelink() {}
void cloneRelinkTree();
@@ -579,6 +659,7 @@ public:
static string dedotName(const string& namein); // Name with dots removed
static string prettyName(const string& namein); // Name for printing out to the user
static string encodeName(const string& namein); // Encode user name into internal C representation
static string encodeNumber(vlsint64_t numin); // Encode number into internal C representation
string prettyName() const { return prettyName(name()); }
FileLine* fileline() const { return m_fileline; }
int width() const { return m_width; }
@@ -597,34 +678,42 @@ public:
bool isQuad() const { return (width()>VL_WORDSIZE && width()<=VL_QUADSIZE); }
bool isWide() const { return (width()>VL_QUADSIZE); }
int user() const { return userp()->castInt(); }
AstNUser* userp() const { return ((m_userCnt==s_userCntGbl)?m_userp:NULL); }
void userp(void* userp) { m_userp=(AstNUser*)(userp); m_userCnt=s_userCntGbl; }
void user(int val) { userp(AstNUser::fromInt(val)); }
static void userClearTree() { s_userCntGbl++; UASSERT_STATIC(s_userCntGbl,"Rollover"); } // Clear userp()'s across the entire tree
AstNUser* user1p() const {
// Slows things down measurably, so disabled by default
//UASSERT_STATIC(AstUser1InUse::s_userBusy, "userp set w/o busy");
return ((m_user1Cnt==AstUser1InUse::s_userCntGbl)?m_user1p:NULL);
}
void user1p(void* userp) { m_user1p=(AstNUser*)(userp); m_user1Cnt=AstUser1InUse::s_userCntGbl; }
int user1() const { return user1p()->castInt(); }
void user1(int val) { user1p(AstNUser::fromInt(val)); }
static void user1ClearTree() { AstUser1InUse::clear(); } // Clear userp()'s across the entire tree
AstNUser* user2p() const {
//UASSERT_STATIC(AstUser2InUse::s_userBusy, "user2p set w/o busy");
return ((m_user2Cnt==AstUser2InUse::s_userCntGbl)?m_user2p:NULL); }
void user2p(void* userp) { m_user2p=(AstNUser*)(userp); m_user2Cnt=AstUser2InUse::s_userCntGbl; }
int user2() const { return user2p()->castInt(); }
AstNUser* user2p() const { return ((m_user2Cnt==s_user2CntGbl)?m_user2p:NULL); }
void user2p(void* userp) { m_user2p=(AstNUser*)(userp); m_user2Cnt=s_user2CntGbl; }
void user2(int val) { user2p(AstNUser::fromInt(val)); }
static void user2ClearTree() { s_user2CntGbl++; } // Clear userp()'s across the entire tree
static void user2ClearTree() { AstUser2InUse::clear(); }
AstNUser* user3p() const {
//UASSERT_STATIC(AstUser3InUse::s_userBusy, "user3p set w/o busy");
return ((m_user3Cnt==AstUser3InUse::s_userCntGbl)?m_user3p:NULL); }
void user3p(void* userp) { m_user3p=(AstNUser*)(userp); m_user3Cnt=AstUser3InUse::s_userCntGbl; }
int user3() const { return user3p()->castInt(); }
AstNUser* user3p() const { return ((m_user3Cnt==s_user3CntGbl)?m_user3p:NULL); }
void user3p(void* userp) { m_user3p=(AstNUser*)(userp); m_user3Cnt=s_user3CntGbl; }
void user3(int val) { user3p(AstNUser::fromInt(val)); }
static void user3ClearTree() { s_user3CntGbl++; } // Clear userp()'s across the entire tree
static void user3ClearTree() { AstUser3InUse::clear(); }
AstNUser* user4p() const {
//UASSERT_STATIC(AstUser4InUse::s_userBusy, "user4p set w/o busy");
return ((m_user4Cnt==AstUser4InUse::s_userCntGbl)?m_user4p:NULL); }
void user4p(void* userp) { m_user4p=(AstNUser*)(userp); m_user4Cnt=AstUser4InUse::s_userCntGbl; }
int user4() const { return user4p()->castInt(); }
AstNUser* user4p() const { return ((m_user4Cnt==s_user4CntGbl)?m_user4p:NULL); }
void user4p(void* userp) { m_user4p=(AstNUser*)(userp); m_user4Cnt=s_user4CntGbl; }
void user4(int val) { user4p(AstNUser::fromInt(val)); }
static void user4ClearTree() { s_user4CntGbl++; } // Clear userp()'s across the entire tree
int user5() const { return user5p()->castInt(); }
AstNUser* user5p() const { return ((m_user5Cnt==s_user5CntGbl)?m_user5p:NULL); }
void user5p(void* userp) { m_user5p=(AstNUser*)(userp); m_user5Cnt=s_user5CntGbl; }
void user5(int val) { user5p(AstNUser::fromInt(val)); }
static void user5ClearTree() { s_user5CntGbl++; } // Clear userp()'s across the entire tree
static void user4ClearTree() { AstUser4InUse::clear(); }
vluint64_t editCount() const { return m_editCount; }
void editCountInc() { m_editCount = s_editCntGbl++; }
void editCountInc() { m_editCount = ++s_editCntGbl; }
static vluint64_t editCountLast() { return s_editCntLast; }
static vluint64_t editCountGbl() { return s_editCntGbl; }
static void editCountSetLast() { s_editCntLast = editCountGbl(); }
@@ -642,7 +731,7 @@ public:
AstNode* addNextNull(AstNode* newp); // Returns this, adds to end of list, NULL is OK
void addNextHere(AstNode* newp); // Adds after speced node
void replaceWith(AstNode* newp); // Replace current node in tree with new node
void v3errorEnd(ostringstream& str);
void v3errorEnd(ostringstream& str) const;
virtual void dump(ostream& str=cout);
AstNode* unlinkFrBack(AstNRelinker* linkerp=NULL); // Unlink this from whoever points to it.
AstNode* unlinkFrBackWithNext(AstNRelinker* linkerp=NULL); // Unlink this from whoever points to it, keep entire next list with unlinked node
@@ -694,11 +783,15 @@ inline void AstNRelinker::relink(AstNode* newp) { newp->AstNode::relink(this); }
//######################################################################
//=== AstNode* : Derived generic node types
#define ASTNODE_BASE_FUNCS(name) \
virtual ~Ast ##name() {} \
Ast ##name * cloneTree(bool cloneNext) { return AstNode::cloneTree(cloneNext)->cast ##name(); }
struct AstNodeMath : public AstNode {
// Math -- anything that's part of an expression tree
AstNodeMath(FileLine* fl)
: AstNode(fl) {}
virtual ~AstNodeMath() {}
ASTNODE_BASE_FUNCS(NodeMath)
// METHODS
virtual string emitVerilog() = 0; /// Format string for verilog writing; see V3EmitV
virtual string emitC() = 0;
@@ -710,7 +803,10 @@ struct AstNodeTermop : public AstNodeMath {
// Terminal operator -- a operator with no "inputs"
AstNodeTermop(FileLine* fl)
: AstNodeMath(fl) {}
virtual ~AstNodeTermop() {}
ASTNODE_BASE_FUNCS(NodeTermop)
// Know no children, and hot function, so skip iterator for speed
// See checkTreeIter also that asserts no children
void iterateChildren(AstNVisitor& v, AstNUser* vup=NULL) { }
};
struct AstNodeUniop : public AstNodeMath {
@@ -719,7 +815,7 @@ struct AstNodeUniop : public AstNodeMath {
: AstNodeMath(fl) {
if (lhsp) widthSignedFrom(lhsp);
setOp1p(lhsp); }
virtual ~AstNodeUniop() {}
ASTNODE_BASE_FUNCS(NodeUniop)
AstNode* lhsp() const { return op1p()->castNode(); }
// METHODS
virtual void numberOperate(V3Number& out, const V3Number& lhs) = 0; // Set out to evaluation of a AstConst'ed lhs
@@ -735,7 +831,7 @@ struct AstNodeBiop : public AstNodeMath {
AstNodeBiop(FileLine* fl, AstNode* lhs, AstNode* rhs)
: AstNodeMath(fl) {
setOp1p(lhs); setOp2p(rhs); }
virtual ~AstNodeBiop() {}
ASTNODE_BASE_FUNCS(NodeBiop)
AstNode* lhsp() const { return op1p()->castNode(); }
AstNode* rhsp() const { return op2p()->castNode(); }
void lhsp(AstNode* nodep) { return setOp1p(nodep); }
@@ -757,7 +853,7 @@ struct AstNodeTriop : public AstNodeMath {
AstNodeTriop(FileLine* fl, AstNode* lhs, AstNode* rhs, AstNode* ths)
: AstNodeMath(fl) {
setOp1p(lhs); setOp2p(rhs); setOp3p(ths); }
virtual ~AstNodeTriop() {}
ASTNODE_BASE_FUNCS(NodeTriop)
AstNode* lhsp() const { return op1p()->castNode(); }
AstNode* rhsp() const { return op2p()->castNode(); }
AstNode* thsp() const { return op3p()->castNode(); }
@@ -781,14 +877,14 @@ struct AstNodeBiCom : public AstNodeBiop {
// Binary math with commutative properties
AstNodeBiCom(FileLine* fl, AstNode* lhs, AstNode* rhs)
: AstNodeBiop(fl, lhs, rhs) {}
virtual ~AstNodeBiCom() {}
ASTNODE_BASE_FUNCS(NodeBiCom)
};
struct AstNodeBiComAsv : public AstNodeBiCom {
// Binary math with commutative & associative properties
AstNodeBiComAsv(FileLine* fl, AstNode* lhs, AstNode* rhs)
: AstNodeBiCom(fl, lhs, rhs) {}
virtual ~AstNodeBiComAsv() {}
ASTNODE_BASE_FUNCS(NodeBiComAsv)
};
struct AstNodeCond : public AstNodeTriop {
AstNodeCond(FileLine* fl, AstNode* condp, AstNode* expr1p, AstNode* expr2p)
@@ -796,7 +892,7 @@ struct AstNodeCond : public AstNodeTriop {
if (expr1p) widthSignedFrom(expr1p);
else if (expr2p) widthSignedFrom(expr2p);
}
virtual ~AstNodeCond() {}
ASTNODE_BASE_FUNCS(NodeCond)
virtual void numberOperate(V3Number& out, const V3Number& lhs, const V3Number& rhs, const V3Number& ths) {
if (lhs.isNeqZero()) out.opAssign(rhs); else out.opAssign(ths); }
AstNode* condp() const { return op1p()->castNode(); } // op1 = Condition
@@ -817,7 +913,7 @@ struct AstNodePreSel : public AstNode {
AstNodePreSel(FileLine* fl, AstNode* lhs, AstNode* rhs, AstNode* ths)
: AstNode(fl) {
setOp1p(lhs); setOp2p(rhs); setNOp3p(ths); }
virtual ~AstNodePreSel() {}
ASTNODE_BASE_FUNCS(NodePreSel)
AstNode* lhsp() const { return op1p()->castNode(); }
AstNode* rhsp() const { return op2p()->castNode(); }
AstNode* thsp() const { return op3p()->castNode(); }
@@ -833,7 +929,7 @@ struct AstNodeStmt : public AstNode {
// Statement -- anything that's directly under a function
AstNodeStmt(FileLine* fl)
: AstNode(fl) {}
virtual ~AstNodeStmt() {}
ASTNODE_BASE_FUNCS(NodeStmt)
// METHODS
};
@@ -843,7 +939,7 @@ struct AstNodeAssign : public AstNodeStmt {
setOp1p(rhsp); setOp2p(lhsp);
if (lhsp) widthSignedFrom(lhsp);
}
virtual ~AstNodeAssign() {}
ASTNODE_BASE_FUNCS(NodeAssign)
virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp)=0; // Clone single node, just get same type back.
// So iteration hits the RHS which is "earlier" in execution order, it's op1, not op2
AstNode* rhsp() const { return op1p()->castNode(); } // op1 = Assign from
@@ -862,7 +958,7 @@ struct AstNodeFor : public AstNodeStmt {
: AstNodeStmt(fileline) {
addNOp1p(initsp); setOp2p(condp); addNOp3p(incsp); addNOp4p(bodysp);
}
virtual ~AstNodeFor() {}
ASTNODE_BASE_FUNCS(NodeFor)
AstNode* initsp() const { return op1p()->castNode(); } // op1= initial statements
AstNode* condp() const { return op2p()->castNode(); } // op2= condition to continue
AstNode* incsp() const { return op3p()->castNode(); } // op3= increment statements
@@ -882,7 +978,7 @@ public:
: AstNodeStmt(fl) {
setOp1p(condp); addNOp2p(ifsp); addNOp3p(elsesp);
}
virtual ~AstNodeIf() {}
ASTNODE_BASE_FUNCS(NodeIf)
AstNode* condp() const { return op1p(); } // op1 = condition
AstNode* ifsp() const { return op2p(); } // op2 = list of true statements
AstNode* elsesp() const { return op3p(); } // op3 = list of false statements
@@ -902,7 +998,7 @@ struct AstNodeCase : public AstNodeStmt {
: AstNodeStmt(fl) {
setOp1p(exprp); addNOp2p(casesp);
}
virtual ~AstNodeCase() {}
ASTNODE_BASE_FUNCS(NodeCase)
virtual int instrCount() const { return instrCountBranch(); }
AstNode* exprp() const { return op1p()->castNode(); } // op1 = case condition <expression>
AstCaseItem* itemsp() const { return op2p()->castCaseItem(); } // op2 = list of case expressions
@@ -911,8 +1007,19 @@ struct AstNodeCase : public AstNodeStmt {
void addNotParallelp(AstNode* nodep) { setOp3p(nodep); }
};
struct AstNodeSenItem : public AstNode {
// An AstSenItem or AstSenGate
AstNodeSenItem(FileLine* fl) : AstNode(fl) {}
ASTNODE_BASE_FUNCS(NodeSenItem)
virtual bool isClocked() const = 0;
virtual bool isCombo() const = 0;
virtual bool isInitial() const = 0;
virtual bool isSettle() const = 0;
virtual bool isNever() const = 0;
};
class AstNodeVarRef : public AstNodeMath {
// A AstVarRef or AstVarXRef
// An AstVarRef or AstVarXRef
private:
bool m_lvalue; // Left hand side assignment
AstVar* m_varp; // [AfterLink] Pointer to variable itself
@@ -931,7 +1038,7 @@ public:
// May have varp==NULL
if (m_varp) widthSignedFrom((AstNode*)m_varp);
}
virtual ~AstNodeVarRef() {}
ASTNODE_BASE_FUNCS(NodeVarRef)
virtual bool broken() const;
virtual int instrCount() const { return widthInstrs(); }
virtual void cloneRelink();
@@ -947,6 +1054,9 @@ public:
void hiername(const string& hn) { m_hiername = hn; }
bool hierThis() const { return m_hierThis; }
void hierThis(bool flag) { m_hierThis = flag; }
// Know no children, and hot function, so skip iterator for speed
// See checkTreeIter also that asserts no children
void iterateChildren(AstNVisitor& v, AstNUser* vup=NULL) { }
};
class AstNodePli : public AstNodeStmt {
@@ -955,7 +1065,7 @@ public:
AstNodePli(FileLine* fl, const string& text, AstNode* exprsp)
: AstNodeStmt(fl), m_text(text) {
addNOp1p(exprsp); }
virtual ~AstNodePli() {}
ASTNODE_BASE_FUNCS(NodePli)
virtual string name() const { return m_text; }
virtual int instrCount() const { return instrCountPli(); }
void exprsp(AstNode* nodep) { addOp1p(nodep); } // op1 = Expressions to output
@@ -974,7 +1084,7 @@ public:
: AstNode(fileline) {
m_text = textp; // Copy it
}
virtual ~AstNodeText() {}
ASTNODE_BASE_FUNCS(NodeText)
const string& text() const { return m_text; }
virtual V3Hash sameHash() const { return V3Hash(text()); }
virtual bool same(AstNode* samep) const {
@@ -1004,7 +1114,7 @@ public:
, m_name(name), m_taskPublic(false) {
addNOp3p(stmtsp);
}
virtual ~AstNodeFTask() {}
ASTNODE_BASE_FUNCS(NodeFTask)
virtual void dump(ostream& str=cout);
virtual string name() const { return m_name; } // * = Var name
virtual bool maybePointedTo() const { return true; }
@@ -1030,7 +1140,7 @@ public:
, m_taskp(NULL) {
setOp1p(namep); addNOp2p(pinsp);
}
virtual ~AstNodeFTaskRef() {}
ASTNODE_BASE_FUNCS(NodeFTaskRef)
virtual bool broken() const { return m_taskp && !m_taskp->brokeExists(); }
virtual void cloneRelink() { if (m_taskp && m_taskp->clonep()) {
m_taskp = m_taskp->clonep()->castNodeFTask();
+20 -97
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -43,19 +43,19 @@ void AstNodeVarRef::cloneRelink() {
}
int AstNodeSel::bitConst() const {
AstConst* constp=bitp()->castConst(); return (constp?constp->asInt():0);
AstConst* constp=bitp()->castConst(); return (constp?constp->toSInt():0);
}
bool AstVar::isSigPublic() const {
return (m_sigPublic || (v3Global.opt.allPublic() && !isTemp()));
return (m_sigPublic || (v3Global.opt.allPublic() && !isTemp() && !isGenVar()));
}
bool AstVar::isScQuad() const {
return (isSc()&&isQuad()&&v3Global.opt.pins64());
return (isSc() && isQuad() && !isScBv());
}
bool AstVar::isScWide() const {
return (isWide() || isSc()&&isQuad()&&!v3Global.opt.pins64());
bool AstVar::isScBv() const {
return (isSc() && width() >= v3Global.opt.pinsBv());
}
void AstVar::combineType(AstVarType type) {
@@ -108,7 +108,7 @@ string AstVar::cType() const {
return "bool";
} else if (widthMin() <= VL_WORDSIZE) {
return "uint32_t";
} else if (isScWide()) {
} else if (isWide()) {
return "uint32_t"; // []'s added later
} else {
return "uint64_t";
@@ -116,12 +116,12 @@ string AstVar::cType() const {
}
string AstVar::scType() const {
if (widthMin() == 1) {
if (isScBv()) {
return (string("sc_bv<")+cvtToStr(widthMin())+"> "); // Keep the space so don't get >>
} else if (widthMin() == 1) {
return "bool";
} else if (widthMin() <= VL_WORDSIZE) {
return "uint32_t";
} else if (isScWide()) {
return (string("sc_bv<")+cvtToStr(widthMin())+"> "); // Keep the space so don't get >>
} else {
return "uint64_t";
}
@@ -163,113 +163,30 @@ string AstScope::nameDotless() const {
return dotless;
}
struct AstSenItemCmp {
inline bool operator () (const AstSenItem* lhsp, const AstSenItem* rhsp) const {
// Looks visually better if we keep sorted by name
if (lhsp->edgeType() < rhsp->edgeType()) return true;
if (lhsp->edgeType() > rhsp->edgeType()) return false;
if (!lhsp->varrefp() && rhsp->varrefp()) return true;
if ( lhsp->varrefp() && !rhsp->varrefp()) return false;
if (lhsp->varrefp() && rhsp->varrefp()) {
if (lhsp->varrefp()->name() < rhsp->varrefp()->name()) return true;
if (lhsp->varrefp()->name() > rhsp->varrefp()->name()) return false;
// But might be same name with different scopes
if (lhsp->varrefp()->varScopep() < rhsp->varrefp()->varScopep()) return true;
if (lhsp->varrefp()->varScopep() > rhsp->varrefp()->varScopep()) return false;
}
return false;
}
};
void AstSenTree::sortSenses() {
// Sort the sensitivity names so "posedge a or b" and "posedge b or a" end up together.
// Also, remove duplicate assignments, and fold POS&NEGs into ANYEDGEs
//cout<<endl; this->dumpTree(cout,"ssin: ");
AstSenItem* nextp;
// Make things a little faster; check first if we need a sort
for (AstSenItem* senp = sensesp(); senp; senp=senp->nextp()->castSenItem()) {
nextp=senp->nextp()->castSenItem();
AstSenItemCmp cmp;
if (nextp && !cmp(senp, nextp)) {
// Something's out of order, sort it
senp = NULL;
vector<AstSenItem*> vec;
for (AstSenItem* senp = sensesp(); senp; senp=senp->nextp()->castSenItem()) {
vec.push_back(senp);
}
sort(vec.begin(), vec.end(), AstSenItemCmp());
for (vector<AstSenItem*>::iterator it=vec.begin(); it!=vec.end(); ++it) {
(*it)->unlinkFrBack();
}
for (vector<AstSenItem*>::iterator it=vec.begin(); it!=vec.end(); ++it) {
this->addSensesp(*it);
}
break;
}
}
// Pass2, remove dup edges
for (AstSenItem* senp = sensesp(); senp; senp=nextp) {
nextp=senp->nextp()->castSenItem();
AstSenItem* cmpp = nextp;
if (cmpp
&& ((senp->varrefp() && cmpp->varrefp() && senp->varrefp()->sameTree(cmpp->varrefp()))
|| (!senp->varrefp() && !cmpp->varrefp()))) {
// We've sorted in the order ANY, BOTH, POS, NEG, so we don't need to try opposite orders
if (( senp->edgeType()==AstEdgeType::ANYEDGE) // ANY or {BOTH|POS|NEG} -> ANY
|| (senp->edgeType()==AstEdgeType::BOTHEDGE) // BOTH or {POS|NEG} -> BOTH
|| (senp->edgeType()==AstEdgeType::POSEDGE // POS or NEG -> BOTH
&& cmpp->edgeType()==AstEdgeType::NEGEDGE)
|| (senp->edgeType()==cmpp->edgeType()) // Identical edges
) {
// Fix edge of old node
if (senp->edgeType()==AstEdgeType::POSEDGE
&& cmpp->edgeType()==AstEdgeType::NEGEDGE)
senp->edgeType(AstEdgeType::BOTHEDGE);
// Remove redundant node
cmpp->unlinkFrBack()->deleteTree(); cmpp=NULL;
// Try to collapse again
nextp=senp;
}
}
}
// Pass3, remove nevers
if (sensesp()->nextp()) { // Else only one never, can't remove it
for (AstSenItem* senp = sensesp(); senp; senp=nextp) {
nextp=senp->nextp()->castSenItem();
if (senp->isNever()) {
senp->unlinkFrBack()->deleteTree(); senp=NULL;
}
}
}
//this->dumpTree(cout,"ssou: ");
}
bool AstSenTree::hasClocked() {
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
for (AstSenItem* senp = sensesp(); senp; senp=senp->nextp()->castSenItem()) {
for (AstNodeSenItem* senp = sensesp(); senp; senp=senp->nextp()->castNodeSenItem()) {
if (senp->isClocked()) return true;
}
return false;
}
bool AstSenTree::hasSettle() {
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
for (AstSenItem* senp = sensesp(); senp; senp=senp->nextp()->castSenItem()) {
for (AstNodeSenItem* senp = sensesp(); senp; senp=senp->nextp()->castNodeSenItem()) {
if (senp->isSettle()) return true;
}
return false;
}
bool AstSenTree::hasInitial() {
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
for (AstSenItem* senp = sensesp(); senp; senp=senp->nextp()->castSenItem()) {
for (AstNodeSenItem* senp = sensesp(); senp; senp=senp->nextp()->castNodeSenItem()) {
if (senp->isInitial()) return true;
}
return false;
}
bool AstSenTree::hasCombo() {
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
for (AstSenItem* senp = sensesp(); senp; senp=senp->nextp()->castSenItem()) {
for (AstNodeSenItem* senp = sensesp(); senp; senp=senp->nextp()->castNodeSenItem()) {
if (senp->isCombo()) return true;
}
return false;
@@ -392,6 +309,12 @@ void AstNodeFTask::dump(ostream& str) {
}
void AstCoverDecl::dump(ostream& str) {
this->AstNode::dump(str);
if (this->dataDeclNullp()) {
str<<" -> ";
this->dataDeclNullp()->dump(str);
} else {
if (binNum()) { str<<" bin"<<dec<<binNum(); }
}
}
void AstCoverInc::dump(ostream& str) {
this->AstNode::dump(str);
+321 -673
View File
File diff suppressed because it is too large Load Diff
+48 -3
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -31,7 +31,6 @@
#include <cstdio>
#include <cstdarg>
#include <unistd.h>
#include <cstring>
#include <algorithm>
#include <vector>
@@ -48,11 +47,19 @@ private:
AstModule* m_modp; // Current module
AstNodeFTask* m_ftaskp; // Current function/task
string m_beginScope; // Name of begin blocks above us
//int debug() { return 9; }
int m_repeatNum; // Repeat counter
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
// VISITORS
virtual void visit(AstModule* nodep, AstNUser*) {
m_modp = nodep;
m_repeatNum = 0;
nodep->iterateChildren(*this);
m_modp = NULL;
}
@@ -131,6 +138,38 @@ private:
nodep->replaceWith(newp);
nodep->deleteTree(); nodep=NULL;
}
virtual void visit(AstRepeat* nodep, AstNUser*) {
// So later optimizations don't need to deal with them,
// REPEAT(count,body) -> loop=count,WHILE(loop>0) { body, loop-- }
// Note var can be signed or unsigned based on original number.
AstNode* countp = nodep->countp()->unlinkFrBackWithNext();
string name = string("__Vrepeat")+cvtToStr(m_repeatNum++);
AstVar* varp = new AstVar(nodep->fileline(), AstVarType::BLOCKTEMP, name,
new AstRange(nodep->fileline(), countp->width()-1, 0));
m_modp->addStmtp(varp);
AstNode* initsp = new AstAssign(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, true),
countp);
AstNode* decp = new AstAssign(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, true),
new AstSub(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, false),
new AstConst(nodep->fileline(), 1)));
AstNode* condp;
if (countp->isSigned()) {
condp = new AstGtS(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, false),
new AstConst(nodep->fileline(), 0));
} else {
condp = new AstGt (nodep->fileline(), new AstVarRef(nodep->fileline(), varp, false),
new AstConst(nodep->fileline(), 0));
}
AstNode* bodysp = nodep->bodysp(); if (bodysp) bodysp->unlinkFrBackWithNext();
bodysp = bodysp->addNext(decp);
AstNode* newp = new AstWhile(nodep->fileline(),
condp,
bodysp);
initsp = initsp->addNext(newp);
newp = initsp;
nodep->replaceWith(newp);
nodep->deleteTree(); nodep=NULL;
}
virtual void visit(AstScopeName* nodep, AstNUser*) {
// If there's a %m in the display text, we add a special node that will contain the name()
// Similar code in V3Inline
@@ -143,6 +182,11 @@ private:
}
nodep->iterateChildren(*this);
}
virtual void visit(AstCoverDecl* nodep, AstNUser*) {
// Don't need to fix path in coverage statements, they're not under
// any BEGINs, but V3Coverage adds them all under the module itself.
nodep->iterateChildren(*this);
}
virtual void visit(AstNode* nodep, AstNUser*) {
nodep->iterateChildren(*this);
}
@@ -151,6 +195,7 @@ public:
BeginVisitor(AstNetlist* nodep) {
m_modp = NULL;
m_ftaskp = NULL;
m_repeatNum = 0;
nodep->accept(*this);
}
virtual ~BeginVisitor() {}
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+7 -2
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -43,9 +43,14 @@ private:
// STATE
int m_likely; // Excuses for branch likely taken
int m_unlikely; // Excuses for branch likely not taken
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
void reset() {
m_likely = false;
m_unlikely = false;
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+4 -4
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -129,9 +129,9 @@ public:
// Use only AstNode::dump instead of the virtual one, as there
// may be varp() and other cross links that are bad.
if (debug()) {
cout<<"%Error: LeakedNode"<<(it->first->backp()?"Back: ":": ");
((AstNode*)(it->first))->AstNode::dump(cout);
cout<<endl;
cerr<<"%Error: LeakedNode"<<(it->first->backp()?"Back: ":": ");
((AstNode*)(it->first))->AstNode::dump(cerr);
cerr<<endl;
V3Error::incErrors();
}
it->second |= FLAG_LEAKED;
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+14 -4
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -58,7 +58,12 @@
class CaseLintVisitor : public AstNVisitor {
private:
AstNodeCase* m_caseExprp; // Under a CASE value node, if so the relevant case statement
//int debug() { return 9; }
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
virtual void visit(AstNodeCase* nodep, AstNUser*) {
// Detect multiple defaults
@@ -118,6 +123,7 @@ private:
// NODE STATE
// Cleared each Case
// AstIf::user3() -> bool. Set true to indicate clone not needed
AstUser3InUse m_inuser3;
// STATE
V3Double0 m_statCaseFast; // Statistic tracking
@@ -129,9 +135,13 @@ private:
int m_caseNoOverlapsAllCovered; // Proven to be synopsys parallel_case compliant
AstNode* m_valueItem[1<<CASE_OVERLAP_WIDTH]; // For each possible value, the case branch we need
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
bool isCaseTreeFast(AstCase* nodep) {
int width = 0;
m_caseItems = 0;
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+20 -15
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2004-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2004-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -60,11 +60,17 @@ private:
// NODE STATE
// Entire netlist:
// AstNode::user() // bool. Indicates node is of known size
AstUser1InUse m_inuser1;
// STATE
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
void insertCast(AstNode* nodep, int needsize) { // We'll insert ABOVE passed node
UINFO(4," NeedCast "<<nodep<<endl);
AstNRelinker relinkHandle;
@@ -76,7 +82,7 @@ private:
//if (debug()>8) castp->dumpTree(cout,"-castins: ");
//
insureLower32Cast(castp);
nodep->user(1); // Now must be of known size
nodep->user1(1); // Now must be of known size
}
int castSize (AstNode* nodep) {
if (nodep->isQuad()) return VL_QUADSIZE;
@@ -86,7 +92,7 @@ private:
}
void insureCast(AstNode* nodep) {
if (castSize(nodep->backp()) != castSize(nodep)
|| !nodep->user()) {
|| !nodep->user1()) {
insertCast(nodep, castSize(nodep->backp()));
}
}
@@ -104,21 +110,21 @@ private:
// VISITORS
virtual void visit(AstNodeUniop* nodep, AstNUser*) {
nodep->iterateChildren(*this);
nodep->user(nodep->lhsp()->user());
nodep->user1(nodep->lhsp()->user1());
if (nodep->sizeMattersLhs()) insureCast(nodep->lhsp());
}
virtual void visit(AstNodeBiop* nodep, AstNUser*) {
nodep->iterateChildren(*this);
nodep->user(nodep->lhsp()->user()
| nodep->rhsp()->user());
nodep->user1(nodep->lhsp()->user1()
| nodep->rhsp()->user1());
if (nodep->sizeMattersLhs()) insureCast(nodep->lhsp());
if (nodep->sizeMattersRhs()) insureCast(nodep->rhsp());
}
virtual void visit(AstNodeTriop* nodep, AstNUser*) {
nodep->iterateChildren(*this);
nodep->user(nodep->lhsp()->user()
| nodep->rhsp()->user()
| nodep->thsp()->user());
nodep->user1(nodep->lhsp()->user1()
| nodep->rhsp()->user1()
| nodep->thsp()->user1());
if (nodep->sizeMattersLhs()) insureCast(nodep->lhsp());
if (nodep->sizeMattersRhs()) insureCast(nodep->rhsp());
if (nodep->sizeMattersThs()) insureCast(nodep->thsp());
@@ -126,11 +132,11 @@ private:
virtual void visit(AstCast* nodep, AstNUser*) {
nodep->iterateChildren(*this);
insureLower32Cast(nodep);
nodep->user(1);
nodep->user1(1);
}
virtual void visit(AstUnaryMin* nodep, AstNUser*) {
nodep->iterateChildren(*this);
nodep->user(nodep->lhsp()->user());
nodep->user1(nodep->lhsp()->user1());
if (nodep->lhsp()->widthMin()==1) {
// We want to avoid a GCC "converting of negative value" warning
// from our expansion of
@@ -150,13 +156,13 @@ private:
// CData x=3; out = (QData)(x<<30);
insertCast (nodep, castSize(nodep));
}
nodep->user(1);
nodep->user1(1);
}
virtual void visit(AstConst* nodep, AstNUser*) {
// Constants are of unknown size if smaller than 33 bits, becase
// we're too lazy to wrap every constant in the universe in
// ((IData)#).
nodep->user(nodep->isQuad() || nodep->isWide());
nodep->user1(nodep->isQuad() || nodep->isWide());
}
// NOPs
@@ -171,7 +177,6 @@ private:
public:
// CONSTUCTORS
CastVisitor(AstNetlist* nodep) {
AstNode::userClearTree();
nodep->accept(*this);
}
virtual ~CastVisitor() {}
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2004-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2004-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+13 -6
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -50,14 +50,21 @@ class ChangedVisitor : public AstNVisitor {
private:
// NODE STATE
// Entire netlist:
// AstVarScope::user() -> bool. True indicates processed
// AstVarScope::user1() -> bool. True indicates processed
AstUser1InUse m_inuser1;
// STATE
AstModule* m_topModp; // Top module
AstScope* m_scopetopp; // Scope under TOPSCOPE
AstCFunc* m_chgFuncp; // Change function we're building
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
void genChangeDet(AstVarScope* vscp) {
#ifdef NEW_ORDERING
vscp->v3fatalSrc("Not applicable\n");
@@ -101,7 +108,7 @@ private:
virtual void visit(AstTopScope* nodep, AstNUser*) {
UINFO(4," TS "<<nodep<<endl);
// Clearing
AstNode::userClearTree();
AstNode::user1ClearTree();
// Create the change detection function
AstScope* scopep = nodep->scopep();
if (!scopep) nodep->v3fatalSrc("No scope found on top level, perhaps you have no statements?\n");
@@ -120,8 +127,8 @@ private:
virtual void visit(AstVarScope* nodep, AstNUser*) {
if (nodep->isCircular()) {
UINFO(8," CIRC "<<nodep<<endl);
if (!nodep->user()) {
nodep->user(true);
if (!nodep->user1()) {
nodep->user1(true);
genChangeDet(nodep);
}
}
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+15 -9
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -47,15 +47,22 @@ private:
// Entire netlist:
// AstNode::user() -> CleanState. For this node, 0==UNKNOWN
// AstNode::user2() -> bool. True indicates minWidth has been propagated
AstUser1InUse m_inuser1;
AstUser2InUse m_inuser2;
// TYPES
enum CleanState { UNKNOWN, CLEAN, DIRTY };
// STATE
AstModule* m_modp;
//int debug() { return 9; }
// ENUMS
enum CleanState { UNKNOWN, CLEAN, DIRTY };
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
// Width resetting
int cppWidth(AstNode* nodep) {
if (nodep->width()<=VL_WORDSIZE) return VL_WORDSIZE;
@@ -78,10 +85,10 @@ private:
// Store the clean state in the userp on each node
void setCleanState(AstNode* nodep, CleanState clean) {
nodep->user(clean);
nodep->user1(clean);
}
CleanState getCleanState(AstNode* nodep) {
return ((CleanState)nodep->user());
return ((CleanState)nodep->user1());
}
bool isClean(AstNode* nodep) {
CleanState clstate = getCleanState(nodep);
@@ -155,6 +162,7 @@ private:
virtual void visit(AstModule* nodep, AstNUser*) {
m_modp = nodep;
nodep->iterateChildren(*this);
m_modp = NULL;
}
virtual void visit(AstNodeUniop* nodep, AstNUser*) {
nodep->iterateChildren(*this);
@@ -256,8 +264,6 @@ public:
CleanVisitor() {}
virtual ~CleanVisitor() {}
void main(AstNetlist* nodep) {
AstNode::userClearTree(); // userp() used on entire tree
AstNode::user2ClearTree(); // userp() used on entire tree
nodep->accept(*this);
}
};
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+917
View File
@@ -0,0 +1,917 @@
// -*- C++ -*-
//*************************************************************************
// DESCRIPTION: Verilator: Break always into sensitivity active domains
//
// Code available from: http://www.veripool.org/verilator
//
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
//
//*************************************************************************
//
// Copyright 2008-2008 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
// Verilator is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//*************************************************************************
// V3ClkGater's Transformations:
//
// Look for clock gaters
// Note there's overlap between this process and V3Split's
// ALWAYS: Build graph
// IF: Form vertex pointing to any IFs or ALWAYS above
// VARREF: Form vertex pointing to IFs it is under
// ASSIGN: If under normal assignment, disable optimization
// FUTURE OPTIMIZE: If signal is set to itself, consider that OK for gating.
// !splitable: Mark all VARREFs in this statement as comming from it
// Optimize graph so if signal is referenced under multiple IF branches it moves up
// Make ALWAYS for each new gating term, and move statements there
//*************************************************************************
#include "config_build.h"
#include "verilatedos.h"
#include <cstdio>
#include <cstdarg>
#include <unistd.h>
#include <map>
#include <algorithm>
#include <vector>
#include "V3Global.h"
#include "V3Ast.h"
#include "V3Stats.h"
#include "V3Graph.h"
#include "V3ClkGater.h"
//######################################################################
// Base for debug
class GaterBaseVisitor : public AstNVisitor {
protected:
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
};
//######################################################################
// Support classes
class GaterVarVertex;
class GaterVertex : public V3GraphVertex {
static uint32_t s_rankNum;
public:
GaterVertex(V3Graph* graphp)
: V3GraphVertex(graphp) {
s_rankNum++; rank(s_rankNum);
}
virtual ~GaterVertex() {}
virtual int typeNum() const = 0;
static void clearRank() { s_rankNum=0; }
virtual int sortCmp(const V3GraphVertex* rhsp) const;
};
uint32_t GaterVertex::s_rankNum = 0;
class GaterHeadVertex : public GaterVertex {
public:
GaterHeadVertex(V3Graph* graphp)
: GaterVertex(graphp) {}
virtual ~GaterHeadVertex() {}
virtual int typeNum() const { return __LINE__; } // C++ typeof() equivelent
virtual string name() const { return "*HEAD*"; }
virtual string dotColor() const { return "green"; }
};
class GaterPliVertex : public GaterVertex {
public:
GaterPliVertex(V3Graph* graphp)
: GaterVertex(graphp) {}
virtual ~GaterPliVertex() {}
virtual int typeNum() const { return __LINE__; } // C++ typeof() equivelent
virtual string name() const { return "*PLI*"; }
virtual string dotColor() const { return "red"; }
};
class GaterIfVertex : public GaterVertex {
AstNodeIf* m_nodep;
public:
AstNodeIf* nodep() const { return m_nodep; }
GaterIfVertex(V3Graph* graphp, AstNodeIf* nodep)
: GaterVertex(graphp), m_nodep(nodep) { }
virtual ~GaterIfVertex() {}
virtual int typeNum() const { return __LINE__; } // C++ typeof() equivelent
virtual string name() const { return cvtToStr((void*)m_nodep)+" {"+cvtToStr(m_nodep->fileline()->lineno())+"}"; }
};
class GaterVarVertex : public GaterVertex {
AstVarScope* m_nodep;
public:
AstVarScope* nodep() const { return m_nodep; }
GaterVarVertex(V3Graph* graphp, AstVarScope* nodep)
: GaterVertex(graphp), m_nodep(nodep) { }
virtual ~GaterVarVertex() {}
virtual int typeNum() const { return __LINE__; } // C++ typeof() equivelent
virtual string name() const { return nodep()->name(); }
virtual string dotColor() const { return "skyblue"; }
};
//######################################################################
// Edge types
class GaterEdge : public V3GraphEdge {
uint32_t m_ifelse; // True branch of if
public:
// These are used as shift amounts into node's user()
#define VU_DEFINE enum VarUsage { VU_NONE=0, VU_IF=1, VU_ELSE=2, VU_PLI=4, VU_MADE=8}
VU_DEFINE;
uint32_t ifelse() const { return m_ifelse; }
bool ifelseTrue() const { return m_ifelse & VU_IF; }
bool ifelseFalse() const { return m_ifelse & VU_ELSE; }
bool ifelseBoth() const { return ifelseTrue() && ifelseFalse(); }
GaterEdge(V3Graph* graphp, V3GraphVertex* fromp, V3GraphVertex* top, uint32_t ifelse)
: V3GraphEdge(graphp, fromp, top, 10, false), m_ifelse(ifelse) {}
virtual ~GaterEdge() {}
virtual string dotColor() const { return ((ifelse() & VU_PLI) ? "red"
: (ifelseBoth() ? "blue"
: (ifelseTrue() ? "green"
: "darkgreen"))); }
virtual int sortCmp(const V3GraphEdge* rEdgep) const {
// Our master sort sorts by edges first, so we don't want to
// consider the upstream vertex::sortCmp when sorting by edges.
// We do want to order by something though; rank works
if (fromp()->rank() < rEdgep->fromp()->rank()) return -1;
if (fromp()->rank() > rEdgep->fromp()->rank()) return 1;
// If same, resolve by ifelse
const GaterEdge* crEdgep = static_cast<const GaterEdge*>(rEdgep);
if (m_ifelse < crEdgep->m_ifelse) return -1;
if (m_ifelse > crEdgep->m_ifelse) return 1;
return 0;
}
};
int GaterVertex::sortCmp(const V3GraphVertex* rhsp) const {
const GaterVertex* crhsp = static_cast<const GaterVertex*>(rhsp);
// We really only care about ordering Var's together, but...
// First put same type together
if (typeNum() < crhsp->typeNum()) return -1;
if (typeNum() > crhsp->typeNum()) return 1;
// If variable, group by same input fanin
// (know they're the same type based on above compare)
if (dynamic_cast<const GaterVarVertex*>(this)) {
// We've already sorted by edges, so just see if same tree
// If this gets too slow, we could compute a hash up front
V3GraphEdge* lEdgep = this->inBeginp();
V3GraphEdge* rEdgep = rhsp->inBeginp();
while (lEdgep && rEdgep) {
const GaterEdge* clEdgep = static_cast<const GaterEdge*>(lEdgep);
const GaterEdge* crEdgep = static_cast<const GaterEdge*>(rEdgep);
if (lEdgep->fromp()->rank() < rEdgep->fromp()->rank()) return -1;
if (lEdgep->fromp()->rank() > rEdgep->fromp()->rank()) return 1;
if (clEdgep->ifelse() < crEdgep->ifelse()) return -1;
if (clEdgep->ifelse() > crEdgep->ifelse()) return 1;
lEdgep = lEdgep->inNextp();
rEdgep = rEdgep->inNextp();
}
if (!lEdgep && !rEdgep) return 0;
return lEdgep ? -1 : 1;
}
// Finally by rank of this vertex
if (rank() < rhsp->rank()) return -1;
if (rank() > rhsp->rank()) return 1;
return 0;
}
//######################################################################
// Check for non-simple gating equations
class GaterCondVisitor : public GaterBaseVisitor {
private:
// RETURN STATE
bool m_isSimple; // Set false when we know it isn't simple
// METHODS
inline void okIterate(AstNode* nodep) {
if (m_isSimple) nodep->iterateChildren(*this);
}
// VISITORS
virtual void visit(AstOr* nodep, AstNUser*) { okIterate(nodep); }
virtual void visit(AstAnd* nodep, AstNUser*) { okIterate(nodep); }
virtual void visit(AstNot* nodep, AstNUser*) { okIterate(nodep); }
virtual void visit(AstLogOr* nodep, AstNUser*) { okIterate(nodep); }
virtual void visit(AstLogAnd* nodep, AstNUser*) { okIterate(nodep); }
virtual void visit(AstLogNot* nodep, AstNUser*) { okIterate(nodep); }
virtual void visit(AstVarRef* nodep, AstNUser*) { okIterate(nodep); }
// Other possibilities are equals, etc
// But, we don't want to get too complicated or it will take too much
// effort to calculate the gater
virtual void visit(AstNode* nodep, AstNUser*) {
m_isSimple = false;
//nodep->iterateChildren(*this);
}
public:
// CONSTUCTORS
GaterCondVisitor(AstNode* nodep) {
m_isSimple = true;
nodep->accept(*this);
}
virtual ~GaterCondVisitor() {}
// PUBLIC METHODS
bool isSimple() const { return m_isSimple; }
};
//######################################################################
// Check for non-simple gating equations
class GaterBodyVisitor : public GaterBaseVisitor {
// NODE STATE
// Input state
// AstVarScope::user2p() -> AstAlways* moving this variable to
enum State {
// This is used as a bitmask
STATE_UNKNOWN=0,
STATE_KEEP=1, // Seen a variable we need, keep this statement
STATE_DELETE=2 // Seen a variable we need, delete this statement
// 3=keep & delete
};
bool m_original; // Deleting original statements, vs deleting new var statements
AstNode* m_exprp; // New gater expression we are building
bool m_cloning; // Clone this object 0=not sure yet, 1=do
uint32_t m_state; // Parsing state
// VISITORS
virtual void visit(AstVarRef* nodep, AstNUser*) {
if (nodep->lvalue()) {
AstVarScope* vscp = nodep->varScopep();
if (vscp->user2p()->castNode() == m_exprp) {
// This variable's block needs to move to the new always
if (m_original) {
UINFO(9," VARREF delete in old: "<<nodep<<endl);
m_state |= STATE_DELETE;
} else {
UINFO(9," VARREF stays in new: "<<nodep<<endl);
m_state |= STATE_KEEP;
}
} else {
if (m_original) {
UINFO(9," VARREF other stays in old\n");
m_state |= STATE_KEEP;
} else {
UINFO(9," VARREF other delete in new\n");
m_state |= STATE_DELETE;
}
}
}
}
//virtual void visit(AstNodeIf* nodep, AstNUser*) { ... }
// Not needed, it's the same handling as any other statement. Cool, huh?
// (We may get empty IFs but the constant propagater will rip them up for us)
virtual void visit(AstNodeStmt* nodep, AstNUser*) {
uint32_t oldstate = m_state;
// Find if children want to delete this or not.
// Note children may bicker, and want to both keep and delete (branches on a if)
uint32_t childstate;
{
m_state = STATE_UNKNOWN;
nodep->iterateChildren(*this);
childstate = m_state;
}
m_state = oldstate;
UINFO(9," Did state="<<childstate<<" "<<nodep<<endl);
// Indeterminate (statement with no lvalue), so keep only in original
if (childstate == STATE_UNKNOWN) {
if (m_original) childstate |= STATE_KEEP;
else childstate |= STATE_DELETE;
}
if ((childstate & STATE_DELETE) && !(childstate & STATE_KEEP)) {
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
// Pass upwards we did delete
m_state |= STATE_DELETE;
} else {
// Pass upwards we must keep
m_state |= STATE_KEEP;
}
}
virtual void visit(AstNode* nodep, AstNUser*) {
nodep->iterateChildren(*this);
}
public:
// CONSTUCTORS
GaterBodyVisitor(AstAlways* nodep, AstNode* exprp, bool original) {
m_exprp = exprp;
m_original = original;
m_state = STATE_UNKNOWN;
if (debug()>=9) nodep->dumpTree(cout," GateBodyIn: ");
nodep->bodysp()->iterateAndNext(*this);
if (debug()>=9) nodep->dumpTree(cout," GateBodyOut: ");
// If there's no statements we shouldn't have had a resulting graph
// vertex asking for this creation
}
virtual ~GaterBodyVisitor() {}
};
//######################################################################
// Create clock gaters
class GaterVisitor : public GaterBaseVisitor {
// NODE STATE
// Cleared on Always
// AstVarScope::user1p() -> GaterVarVertex*
// AstAlways::user4() -> bool. True indicates processed
// Cleared on each new Always
// AstVarScope::user2p() -> AstAlways* moving this variable to
AstUser1InUse m_inuser1;
AstUser2InUse m_inuser2;
AstUser4InUse m_inuser4;
// GRAPH STATE
// Cleared on simplify
// Vertex::user() -> VarUsage: Mark of which if/else edges are hit
// TYPES
VU_DEFINE;
enum MiscConsts {
IF_DEPTH_MAX = 4, // IFs deep we bother to analyze
DOMAINS_MAX = 32 // Clock domains before avoiding O(N^2) blowup
};
// MEMBERS
string m_nonopt; // Reason block is not optimizable
V3Double0 m_statGaters; // Statistic tracking
V3Double0 m_statBits; // Statistic tracking
bool m_directlyUnderAlw; // Immediately under Always or If
int m_ifDepth; // Depth of IF statements
int m_numIfs; // Number of IF statements
V3Graph m_graph; // Scoreboard of var usages/dependencies
GaterPliVertex* m_pliVertexp; // Element specifying PLI ordering
GaterHeadVertex* m_headVertexp; // Top vertex
V3GraphVertex* m_aboveVertexp; // Vertex above this point in tree
uint32_t m_aboveTrue; // Vertex above this point is true branch
AstVarScope* m_stmtVscp; // Current statement had variable assigned
bool m_stmtInPli; // Current statement has PLI
// METHODS
void nonOptimizable(AstNode* nodep, const char* reasonp) {
if (m_nonopt=="") {
UINFO(9," Nonopt: "<<reasonp<<": "<<nodep<<endl);
m_nonopt = reasonp;
}
}
void scoreboardPli(AstNode* nodep) {
// Order all PLI statements with other PLI statements
// This insures $display's and such remain in proper order
// We don't prevent splitting out other non-pli statements, however,
// because it is common to have $uasserts sprinkled about.
if (!m_pliVertexp) {
m_pliVertexp = new GaterPliVertex(&m_graph);
}
if (m_stmtVscp) { // Already saw a variable, be sure to mark it!
GaterVarVertex* varVtxp = (GaterVarVertex*)(m_stmtVscp->user1p());
new GaterEdge(&m_graph, m_pliVertexp, varVtxp, VU_PLI);
}
m_stmtInPli = true; // Mark all followon variables too
}
// METHODS -- GRAPH stuff
void simplifyGraph() {
if (debug()>=9) m_graph.dumpDotFilePrefixed("gater_init", false);
// We now have all PLI variables with edges FROM the pli vertex
simplifyPli();
if (debug()>=9) m_graph.dumpDotFilePrefixed("gater_pli", false);
// Any vertex that points along both true & false path to variable
// can be simplfied so parent points to that vertex. Any vertex
// that points to a (great...) grandparent of a variable can just
// point to the edge.
m_graph.userClearVertices(); // user() will contain VarUsage
simplifyIfElseRecurse(m_headVertexp);
if (debug()>=9) m_graph.dumpDotFilePrefixed("gater_ifelse", false);
m_graph.userClearVertices(); // user() will contain VarUsage
simplifyGrandRecurse(m_headVertexp, 1);
if (debug()>=9) m_graph.dumpDotFilePrefixed("gater_grand", false);
simplifyRemoveUngated(m_headVertexp);
// Give all signals with same gating term same color
graphColorSameFeeder();
if (debug()>=9) m_graph.dumpDotFilePrefixed("gater_done", false);
}
void simplifyPli() {
// For now, we'll not gate any logic with PLI lvariables in it. In
// the future we may move PLI statements. One way to do so is to
// all below pli VARs to go IfVertex -> PliVertex -> VarVertex then
// they all must get colored the same. There may be a lot of
// duplicated edges to the PLI; they'll need cleanup. All of the
// later optimizations need to deal, and the GaterBodyVisitor needs
// to know how to move them.
if (m_pliVertexp) {
// Follow PLI out edges to find all relevant variables
for (V3GraphEdge* nextp,* edgep = m_pliVertexp->outBeginp(); edgep; edgep = nextp) {
nextp = edgep->outNextp(); // We may edit the list
if (GaterVarVertex* vVxp = dynamic_cast<GaterVarVertex*>(edgep->top())) {
vVxp->unlinkDelete(&m_graph); vVxp=NULL; edgep=NULL;
} else {
m_graph.dump();
v3fatalSrc("PLI vertex points to non-signal");
}
}
m_pliVertexp->unlinkDelete(&m_graph); m_pliVertexp = NULL;
}
}
void simplifyIfElseRecurse(V3GraphVertex* vertexp) {
// From bottom-up, propagate duplicate IF/ELSE branches to grandparent
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
simplifyIfElseRecurse(edgep->top());
}
//UINFO(9,"IERecurse "<<vertexp<<endl);
if (dynamic_cast<GaterIfVertex*>(vertexp)) {
// Clear indications
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
edgep->top()->user(VU_NONE);
}
// Mark nodes on to/from side
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
V3GraphVertex* toVxp = edgep->top();
GaterEdge* cedgep = static_cast<GaterEdge*>(edgep);
// We may mark this twice in one pass - if so it's duplicated; no worries
if (cedgep->ifelseTrue()) toVxp->user(toVxp->user() | VU_IF);
if (cedgep->ifelseFalse()) toVxp->user(toVxp->user() | VU_ELSE);
//UINFO(9," mark "<<edgep<<" "<<toVxp<<endl);
}
// Any with both IF & ELSE mark get removal mark, and new parent edge
for (V3GraphEdge* nextp,* edgep = vertexp->outBeginp(); edgep; edgep = nextp) {
nextp = edgep->outNextp(); // We may edit the list
V3GraphVertex* toVxp = edgep->top();
//UINFO(9," to "<<toVxp->user()<<" "<<toVxp<<endl);
if ((toVxp->user() & VU_IF) && (toVxp->user() & VU_ELSE)) {
edgep->unlinkDelete(); edgep = NULL;
if (!(toVxp->user() & VU_MADE)) { // Make an edge only once
toVxp->user(toVxp->user() | VU_MADE);
GaterEdge* inedgep = static_cast<GaterEdge*>(vertexp->inBeginp());
V3GraphVertex* grandparent = inedgep->fromp();
new GaterEdge(&m_graph, grandparent, toVxp, inedgep->ifelse());
}
}
}
}
}
void simplifyGrandRecurse(V3GraphVertex* vertexp, uint32_t depth) {
// From top-down delete any vars that grandparents source
// IE A -> B -> C -> VAR
// \----------^
//UINFO(9,"GRecurse "<<depth<<" "<<vertexp<<endl);
// Mark all variables to be swept
for (V3GraphEdge *nextp, *edgep = vertexp->outBeginp(); edgep; edgep=nextp) {
nextp = edgep->outNextp(); // We may edit the list
if (GaterVarVertex* toVxp = dynamic_cast<GaterVarVertex*>(edgep->top())) {
if (toVxp->user() && toVxp->user() < depth) {
// A recursion "above" us marked it,
// Remove this edge, it's redundant with the upper edge
edgep->unlinkDelete(); edgep=NULL;
} else {
GaterEdge* cedgep = static_cast<GaterEdge*>(edgep);
if (cedgep->ifelseBoth()) {
toVxp->user(depth);
}
}
}
}
// Recurse
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
simplifyGrandRecurse(edgep->top(), depth+1);
}
// Clean our marks
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
V3GraphVertex* toVxp = edgep->top();
if (toVxp->user() && toVxp->user() < depth) { // A recursion "above" us marked it; don't mess with it
} else {
toVxp->user(0); // We marked it originally, so unmark now
}
}
// Delete any If nodes with no children
// Last, as want bottom-up cleanup
for (V3GraphEdge *nextp, *edgep = vertexp->outBeginp(); edgep; edgep=nextp) {
nextp = edgep->outNextp(); // We may edit the list
if (GaterIfVertex* toVxp = dynamic_cast<GaterIfVertex*>(edgep->top())) {
if (!toVxp->outBeginp()) {
if (!nextp || nextp->top() != edgep->top()) { // Else next would disappear; we'll do it next loop
toVxp->unlinkDelete(&m_graph); toVxp=NULL; edgep=NULL;
}
}
}
}
}
void simplifyRemoveUngated(V3GraphVertex* vertexp) {
// Remove variables that are ungated
// At this point, any variable under the head is ungated
for (V3GraphEdge *nextp, *edgep = vertexp->outBeginp(); edgep; edgep=nextp) {
nextp = edgep->outNextp(); // We may edit the list
if (GaterVarVertex* toVxp = dynamic_cast<GaterVarVertex*>(edgep->top())) {
if (!nextp || nextp->top() != edgep->top()) { // Else next would disappear; we'll do it next loop
toVxp->unlinkDelete(&m_graph); toVxp=NULL; edgep=NULL;
}
}
}
}
void graphColorSameFeeder() {
// Assign same color to all destination vertices that have same
// subgraph feeding into them
// (I.E. all "from" nodes are common within each color)
// We could hash, but instead it's faster to sort edges, so we know
// the same edge list is always adjacent. The result is a
// O(vertices*edges) loop, but we'd need that to hash too.
if (debug()>9) { cout<<"PreColor:\n"; m_graph.dump(); }
m_graph.sortEdges();
// Now sort vertices, so same inbound edge set ends up adjacent
m_graph.sortVertices();
// Now walk and assign colors; same color is adjacent
m_graph.clearColors();
m_graph.userClearEdges(); // Used by newExprFromGraph
uint32_t color = 1;
GaterVarVertex* lastVxp = NULL;
for (V3GraphVertex* vertexp = m_graph.verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
if (GaterVarVertex* vVxp = dynamic_cast<GaterVarVertex*>(vertexp)) {
if (!vVxp->inBeginp()) {
// At this point, any variable not linked is an error
// (It should have at least landed under the Head node)
vVxp->nodep()->v3fatalSrc("Variable became stranded in clk gate detection\n");
}
if (!lastVxp || vVxp->sortCmp(lastVxp)) {
// Different sources for this new node
color++;
}
vVxp->color(color);
lastVxp = vVxp;
}
}
if (debug()>9) { cout<<"PostColor:\n"; m_graph.dump(); }
}
AstNode* newExprFromGraph(GaterVarVertex* vertexp) {
// Recurse backwards, then form equation on return path
// We could use user()!=0, but zeroing it is slow, so instead we'll mark with a generation
// We get equations like "a | (!a & b)" which obviously could be reduced here,
// instead out of generality, there's a V3Const::matchOrAndNot that'll clean it up
static uint32_t s_generation = 0;
++s_generation;
nafgMarkRecurse(vertexp, s_generation);
AstNode* nodep = nafgCreateRecurse(m_headVertexp, s_generation);
if (debug()>=9) nodep->dumpTree(cout," GateExpr: ");
return nodep;
}
void nafgMarkRecurse(V3GraphVertex* vertexp, uint32_t generation) {
// Backwards mark user() on the path we recurse
//UINFO(9," nafgMark: v "<<(void*)(vertexp)<<" "<<vertexp->name()<<endl);
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) {
//UINFO(9," nafgMark: "<<(void*)(edgep)<<" "<<edgep->name()<<endl);
edgep->user(generation);
nafgMarkRecurse(edgep->fromp(), generation);
}
}
AstNode* nafgCreateRecurse(V3GraphVertex* vertexp, uint32_t generation) {
// Forewards follow user() marked previously and build tree
AstNode* nodep = NULL;
// OR across all edges found at this level
//UINFO(9," nafgEnter: v "<<(void*)(vertexp)<<" "<<vertexp->name()<<endl);
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp()) {
if (edgep->user() == generation) {
GaterEdge* cedgep = static_cast<GaterEdge*>(edgep);
AstNode* eqnp = NULL;
//UINFO(9," nafgFollow: "<<(void*)(edgep)<<" "<<edgep->name()<<endl);
if (dynamic_cast<GaterHeadVertex*>(edgep->fromp())) {
// Just OR in all lower terms
eqnp = nafgCreateRecurse(edgep->top(), generation);
} else if (GaterIfVertex* cVxp = dynamic_cast<GaterIfVertex*>(edgep->fromp())) {
// Edges from IFs represent a real IF branch in the equation tree
//UINFO(9," ifver "<<(void*)(edgep)<<" cc"<<edgep->dotColor()<<endl);
eqnp = cVxp->nodep()->condp()->cloneTree(true);
if (eqnp && cedgep->ifelseFalse()) {
eqnp = new AstNot(eqnp->fileline(),eqnp);
}
// We need to AND this term onto whatever was found below it
AstNode* belowp = nafgCreateRecurse(edgep->top(), generation);
if (belowp) eqnp = new AstAnd(eqnp->fileline(),eqnp,belowp);
}
// Top level we could choose to make multiple gaters, or ORs under the gater
// Right now we'll put OR lower down and let other optimizations deal
if (nodep) nodep = new AstOr(eqnp->fileline(),nodep,eqnp);
else nodep = eqnp;
//if (debug()>=9) nodep->dumpTree(cout," followExpr: ");
}
}
//UINFO(9," nafgExit: "<<(void*)(vertexp)<<" "<<vertexp->name()<<endl);
return nodep;
}
void newAlwaysTrees(AstAlways* nodep) {
// Across all variables we're moving
uint32_t lastColor = 0;
AstNode* lastExprp = NULL;
for (V3GraphVertex* vertexp = m_graph.verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
if (GaterVarVertex* vVxp = dynamic_cast<GaterVarVertex*>(vertexp)) {
if (!lastExprp || lastColor != vVxp->color()) {
lastColor = vVxp->color();
// Create the block we've just finished
if (lastExprp) newAlwaysTree(nodep, lastExprp); // Duplicate below
// New expression for this color
lastExprp = newExprFromGraph(vVxp);
}
// Mark variable to move
if (vVxp->nodep()->user2p()) vVxp->nodep()->v3fatalSrc("One variable got marked under two gaters");
vVxp->nodep()->user2p(lastExprp);
m_statBits += vVxp->nodep()->width(); // Moving a wide bus counts more!
// There shouldn't be two possibilities we want to
// move to, IE {A,B} <= Z because we marked such
// things as unoptimizable
}
}
// Create the final block we've just finished
if (lastExprp) newAlwaysTree(nodep, lastExprp); // Duplicate above
}
void newAlwaysTree(AstAlways* nodep, AstNode* exprp) {
// Create new always with specified gating expression
// Relevant vars are already marked with user2p
// Should we put the gater under the always itself,
// or make a new signal?
// New signal: May cause replicated logic until we can combine
// Need way to toggle signal on complicated pos/negedge
// Under Always: More complicated, may not propagate logic with gateer
// Untill we get better gate optimization, we'll go this route.
//#define GATER_NOP
#ifdef GATER_NOP
// For testing only, don't clock gate but still make new always
AstSenTree* sensesp = nodep->sensesp()->cloneTree(true);
#else
// Make a SenGate
AstSenItem* oldsenitemsp = nodep->sensesp()->sensesp()->castSenItem();
if (!oldsenitemsp) nodep->v3fatalSrc("SenTree doesn't have any SenItem under it");
AstSenTree* sensesp = new AstSenTree(nodep->fileline(),
new AstSenGate(nodep->fileline(),
oldsenitemsp->cloneTree(true),
exprp));
#endif
// Make new body; note clone will preserve user2p() indicating moving vars
AstNode* bodyp = nodep->bodysp()->cloneTree(true);
AstAlways* alwp = new AstAlways(nodep->fileline(),
sensesp,
bodyp);
alwp->user4(1); // No need to process the new always again!
nodep->addNextHere(alwp);
// Blow moved statements from old body
GaterBodyVisitor(nodep,exprp,true);
// Blow old statements from new body
GaterBodyVisitor(alwp,exprp,false);
m_statGaters++;
if (debug()>=9) alwp->dumpTree(cout," new: ");
}
// VISITORS
virtual void visit(AstAlways* nodep, AstNUser*) {
if (debug()>=9) cout<<endl<<endl<<endl;
UINFO(5, "Gater: ALWAYS: "<<nodep<<endl);
if (nodep->user4()) return;
nodep->user4(1);
clear();
if (debug()>=9) nodep->dumpTree(cout," Alwin: ");
// Look for constructs we can't optimize
// Form graph with Vertices at each IF, and each Variable
m_aboveTrue = VU_IF | VU_ELSE;
iterateChildrenAlw(nodep, true);
// Other reasons to not optimize
if (!m_numIfs) nonOptimizable(nodep, "No if statements");
// Something to optimize, oh my!
if (m_nonopt!="") {
UINFO(5, " Gater non-opt: "<<m_nonopt<<endl);
} else {
// Process it
simplifyGraph();
// See how much moves
uint32_t lastColor = 0;
for (V3GraphVertex* vertexp = m_graph.verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
if (GaterVarVertex* vVxp = dynamic_cast<GaterVarVertex*>(vertexp)) {
if (lastColor < vVxp->color()) {
lastColor = vVxp->color();
}
}
}
if (lastColor == 0) { // Nothing we moved!
nonOptimizable(nodep, "Nothing moved");
}
else if (lastColor > DOMAINS_MAX) {
// Our move algorithm is fairly slow and if we're splitting
// up too much it'll get really nasty. It's probably a bad
// move for performance to split too much, anyhow, as the
// number of gaters will result in calling many small c functions.
nonOptimizable(nodep, "Too much moved");
}
if (m_nonopt=="") {
newAlwaysTrees(nodep);
if (debug()>=9) nodep->dumpTree(cout," Gaterout: ");
}
}
UINFO(5, " Gater done"<<endl);
}
virtual void visit(AstVarRef* nodep, AstNUser*) {
if (nodep->lvalue()) {
AstVarScope* vscp = nodep->varScopep();
if (nodep->varp()->isSigPublic()) {
// Public signals shouldn't be changed, pli code might be messing with them
scoreboardPli(nodep);
}
// If another lvalue in this node, give up optimizing.
// We could just not optimize this variable, but we've already marked the
// other variable as optimizable, so we can instead pretend it's a PLI node.
if (m_stmtVscp) {
UINFO(5, " Multiple lvalues in one statement: "<<nodep<<endl);
scoreboardPli(nodep); // This will set m_stmtInPli
}
m_stmtVscp = vscp;
// Find, or make new Vertex
GaterVarVertex* vertexp = (GaterVarVertex*)(vscp->user1p());
if (!vertexp) {
vertexp = new GaterVarVertex(&m_graph, vscp);
vscp->user1p(vertexp);
}
new GaterEdge(&m_graph, m_aboveVertexp, vertexp, m_aboveTrue);
if (m_stmtInPli) {
new GaterEdge(&m_graph, m_pliVertexp, vertexp, VU_PLI);
}
}
}
virtual void visit(AstNodeIf* nodep, AstNUser*) {
m_ifDepth++;
bool allowGater = m_directlyUnderAlw && m_ifDepth <= IF_DEPTH_MAX;
if (allowGater) {
GaterCondVisitor condVisitor(nodep->condp());
if (!condVisitor.isSimple()) {
// Don't clear optimization, simply drop this IF as part of the gating
UINFO(5," IFnon-simple-condition: "<<nodep<<endl);
allowGater = false;
}
}
if (!allowGater) {
// IF burried under something complicated
iterateChildrenAlw(nodep, true);
} else {
UINFO(5, " IF: "<<nodep<<endl);
m_numIfs++;
// Recurse to next level of if.
V3GraphVertex* lastabovep = m_aboveVertexp;
uint32_t lasttrue = m_aboveTrue;
GaterIfVertex* vertexp = new GaterIfVertex(&m_graph, nodep);
new GaterEdge(&m_graph, m_aboveVertexp, vertexp, m_aboveTrue);
{
nodep->condp()->iterateAndNext(*this); // directlyUnder stays as-is
}
{
m_aboveVertexp = vertexp; // Vars will point at this edge
m_aboveTrue = VU_IF;
nodep->ifsp()->iterateAndNext(*this); // directlyUnder stays as-is (true)
}
{
m_aboveVertexp = vertexp; // Vars will point at this edge
m_aboveTrue = VU_ELSE;
nodep->elsesp()->iterateAndNext(*this); // directlyUnder stays as-is (true)
}
m_aboveVertexp = lastabovep;
m_aboveTrue = lasttrue;
}
m_ifDepth--;
}
virtual void visit(AstAssignDly* nodep, AstNUser*) {
// iterateChildrenAlw will detect this is a statement for us
iterateChildrenAlw(nodep, false);
}
virtual void visit(AstNodeAssign* nodep, AstNUser*) {
// Note NOT AssignDly; handled above, We'll just mark this block as
// not optimizable.
//
// A future alternative is to look for any lvalues that are also
// variables in the sensitivity list, or rvalues in this block. If
// any hit, disable optimization. Unlikely to be useful (For loops
// being an exception, but they're already unrolled.)
nonOptimizable(nodep, "Non-delayed assignment");
// No reason to iterate.
}
virtual void visit(AstSenItem* nodep, AstNUser*) {
if (!nodep->isClocked()) {
nonOptimizable(nodep, "Non-clocked sensitivity");
}
iterateChildrenAlw(nodep, false);
}
//--------------------
virtual void visit(AstNode* nodep, AstNUser*) {
if (m_nonopt=="") { // Else accelerate
iterateChildrenAlw(nodep, false);
}
}
inline void iterateChildrenAlw(AstNode* nodep, bool under) {
// **** USE THIS INSTEAD OF iterateChildren!
// Note If visitor doesn't call here; does it its own way
bool lastdua = m_directlyUnderAlw;
AstVarScope* lastvscp = m_stmtVscp;
bool lastpli = m_stmtInPli;
m_directlyUnderAlw = under;
if (nodep->castNodeStmt()) { // Restored below
UINFO(9," Stmt: "<<nodep<<endl);
m_stmtVscp = NULL;
m_stmtInPli = false;
}
if (!nodep->isSplittable()) {
// May also be a new statement (above if); if so we mark it immediately
UINFO(9," NotSplittable "<<nodep<<endl);
scoreboardPli(nodep);
}
{
nodep->iterateChildren(*this);
}
m_directlyUnderAlw = lastdua;
if (nodep->castNodeStmt()) { // Reset what set above; else propagate up to above statement
m_stmtVscp = lastvscp;
m_stmtInPli = lastpli;
}
}
public:
// CONSTUCTORS
GaterVisitor(AstNode* nodep) {
// AstAlways visitor does the real work, so most zeroing needs to be in clear()
clear();
nodep->accept(*this);
}
void clear() {
m_nonopt = "";
m_directlyUnderAlw = false;
m_ifDepth = 0;
m_numIfs = 0;
AstNode::user1ClearTree();
AstNode::user2ClearTree();
// Prepare graph
m_graph.clear();
GaterVertex::clearRank();
m_pliVertexp = NULL;
m_headVertexp = new GaterHeadVertex(&m_graph);
m_aboveVertexp = m_headVertexp;
m_aboveTrue = false;
m_stmtVscp = NULL;
m_stmtInPli = false;
}
virtual ~GaterVisitor() {
V3Stats::addStat("Optimizations, Gaters inserted", m_statGaters);
V3Stats::addStat("Optimizations, Gaters impacted bits", m_statBits);
}
};
//######################################################################
// Active class functions
void V3ClkGater::clkGaterAll(AstNetlist* nodep) {
UINFO(2,__FUNCTION__<<": "<<endl);
// While the gater does well at some modules, it seems to slow down many others
UINFO(5,"ClkGater is disabled due to performance issues\n");
//GaterVisitor visitor (nodep);
}
+36
View File
@@ -0,0 +1,36 @@
// -*- C++ -*-
//*************************************************************************
// DESCRIPTION: Verilator: Break always into clock gated blocks
//
// Code available from: http://www.veripool.org/verilator
//
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
// Verilator is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//*************************************************************************
#ifndef _V3CLKGATER_H_
#define _V3CLKGATER_H_ 1
#include "config_build.h"
#include "verilatedos.h"
#include "V3Error.h"
#include "V3Ast.h"
//============================================================================
class V3ClkGater {
public:
static void clkGaterAll(AstNetlist* nodep);
};
#endif // Guard
+93 -54
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -50,8 +50,10 @@ class ClockVisitor : public AstNVisitor {
private:
// NODE STATE
// Cleared each Module:
// AstVarScope::userp() -> AstVarScope*. Temporary signal that was created.
// AstVarScope::user1p() -> AstVarScope*. Temporary signal that was created.
// AstVarScope::user2p() -> AstVarScope*. Temporary signal for change detects
AstUser1InUse m_inuser1;
AstUser2InUse m_inuser2;
// TYPES
enum { DOUBLE_OR_RATE = 10 }; // How many | per ||, Determined experimentally as best
@@ -69,11 +71,16 @@ private:
AstSenTree* m_lastSenp; // Last sensitivity match, so we can detect duplicates.
AstIf* m_lastIfp; // Last sensitivity if active to add more under
int m_stableNum; // Number of each untilstable
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
AstVarScope* getCreateLastClk(AstVarScope* vscp) {
if (vscp->userp()) return ((AstVarScope*)vscp->userp());
if (vscp->user1p()) return ((AstVarScope*)vscp->user1p());
AstVar* varp = vscp->varp();
if (varp->width()!=1) varp->v3error("Unsupported: Clock edge on non-single bit signal: "<<varp->prettyName());
string newvarname = ((string)"__Vclklast__"+vscp->scopep()->nameDotless()+"__"+varp->shortName());
@@ -82,7 +89,7 @@ private:
newvarp->width(1,1);
m_modp->addStmtp(newvarp);
AstVarScope* newvscp = new AstVarScope(vscp->fileline(), m_scopep, newvarp);
vscp->userp(newvscp);
vscp->user1p(newvscp);
m_scopep->addVarp(newvscp);
// At bottom, assign them
AstAssign* finalp
@@ -106,48 +113,66 @@ private:
m_scopep->addVarp(newvscp);
return newvscp;
}
AstNode* createSenseEquation(AstSenTree* nodep) {
AstNode* createSenItemEquation(AstSenItem* nodep) {
// We know the var is clean, and one bit, so we use binary ops
// for speed instead of logical ops.
// POSEDGE: var & ~var_last
// NEGEDGE: ~var & var_last
// BOTHEDGE: var ^ var_last
// HIGHEDGE: var
// LOWEDGE: ~var
AstNode* newp = NULL;
AstVarScope* clkvscp = nodep->varrefp()->varScopep();
if (nodep->edgeType()==AstEdgeType::POSEDGE) {
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
newp = new AstAnd(nodep->fileline(),
new AstVarRef(nodep->fileline(),
nodep->varrefp()->varScopep(), false),
new AstNot(nodep->fileline(),
new AstVarRef(nodep->fileline(),
lastVscp, false)));
} else if (nodep->edgeType()==AstEdgeType::NEGEDGE) {
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
newp = new AstAnd(nodep->fileline(),
new AstNot(nodep->fileline(),
new AstVarRef(nodep->fileline(),
nodep->varrefp()->varScopep(), false)),
new AstVarRef(nodep->fileline(), lastVscp, false));
} else if (nodep->edgeType()==AstEdgeType::BOTHEDGE) {
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
newp = new AstXor(nodep->fileline(),
new AstVarRef(nodep->fileline(),
nodep->varrefp()->varScopep(), false),
new AstVarRef(nodep->fileline(), lastVscp, false));
} else if (nodep->edgeType()==AstEdgeType::HIGHEDGE) {
newp = new AstVarRef(nodep->fileline(),
clkvscp, false);
} else if (nodep->edgeType()==AstEdgeType::LOWEDGE) {
newp = new AstNot(nodep->fileline(),
new AstVarRef(nodep->fileline(),
clkvscp, false));
} else {
nodep->v3fatalSrc("Bad edge type");
}
return newp;
}
AstNode* createSenGateEquation(AstSenGate* nodep) {
AstNode* newp = new AstAnd(nodep->fileline(),
createSenseEquation(nodep->sensesp()),
nodep->rhsp()->cloneTree(true));
return newp;
}
AstNode* createSenseEquation(AstNodeSenItem* nodesp) {
// Nodep may be a list of elements; we need to walk it
AstNode* senEqnp = NULL;
for (AstSenItem* senp = nodep->sensesp(); senp; senp=senp->nextp()->castSenItem()) {
// We know the var is clean, and one bit, so we use binary ops
// for speed instead of logical ops.
// POSEDGE: var & ~var_last
// NEGEDGE: ~var & var_last
// BOTHEDGE: var ^ var_last
// HIGHEDGE: var
// LOWEDGE: ~var
AstVarScope* lastVscp = senp->varrefp()->varScopep()->userp()->castNode()->castVarScope();
for (AstNodeSenItem* senp = nodesp; senp; senp=senp->nextp()->castNodeSenItem()) {
AstNode* senOnep = NULL;
if (senp->edgeType()==AstEdgeType::POSEDGE) {
if (!lastVscp) senp->v3fatalSrc("No last var ptr?\n");
senOnep = new AstAnd(senp->fileline(),
new AstVarRef(senp->fileline(),
senp->varrefp()->varScopep(), false),
new AstNot(senp->fileline(),
new AstVarRef(senp->fileline(),
lastVscp, false)));
} else if (senp->edgeType()==AstEdgeType::NEGEDGE) {
if (!lastVscp) senp->v3fatalSrc("No last var ptr?\n");
senOnep = new AstAnd(senp->fileline(),
new AstNot(senp->fileline(),
new AstVarRef(senp->fileline(),
senp->varrefp()->varScopep(), false)),
new AstVarRef(senp->fileline(), lastVscp, false));
} else if (senp->edgeType()==AstEdgeType::BOTHEDGE) {
if (!lastVscp) senp->v3fatalSrc("No last var ptr?\n");
senOnep = new AstXor(senp->fileline(),
new AstVarRef(senp->fileline(),
senp->varrefp()->varScopep(), false),
new AstVarRef(senp->fileline(), lastVscp, false));
} else if (senp->edgeType()==AstEdgeType::HIGHEDGE) {
senOnep = new AstVarRef(senp->fileline(),
senp->varrefp()->varScopep(), false);
} else if (senp->edgeType()==AstEdgeType::LOWEDGE) {
senOnep = new AstNot(senp->fileline(),
new AstVarRef(senp->fileline(),
senp->varrefp()->varScopep(), false));
if (AstSenItem* itemp = senp->castSenItem()) {
senOnep = createSenItemEquation(itemp);
} else if (AstSenGate* itemp = senp->castSenGate()) {
senOnep = createSenGateEquation(itemp);
} else {
senp->v3fatalSrc("Bad edge type");
senp->v3fatalSrc("Strange node under sentree");
}
if (senEqnp) {
// Add new OR to the sensitivity list equation
@@ -159,14 +184,7 @@ private:
return senEqnp;
}
AstIf* makeActiveIf(AstSenTree* sensesp) {
for (AstSenItem* senp = sensesp->sensesp(); senp; senp=senp->nextp()->castSenItem()) {
if (senp->edgeType() != AstEdgeType::HIGHEDGE
&& senp->varrefp()) {
AstVarScope* oldvscp = senp->varrefp()->varScopep();
getCreateLastClk(oldvscp);
}
}
AstNode* senEqnp = createSenseEquation(sensesp);
AstNode* senEqnp = createSenseEquation(sensesp->sensesp());
if (!senEqnp) sensesp->v3fatalSrc("No sense equation, shouldn't be in sequent activation.");
AstIf* newifp = new AstIf (sensesp->fileline(),
senEqnp, NULL, NULL);
@@ -183,8 +201,8 @@ private:
m_topScopep=nodep;
m_scopep = nodep->scopep();
if (!m_scopep) nodep->v3fatalSrc("No scope found on top level, perhaps you have no statements?\n");
//VV***** We reset all userp()
AstNode::userClearTree();
//VV***** We reset all user1p()
AstNode::user1ClearTree();
// Make top functions
{
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "_eval", m_scopep);
@@ -245,6 +263,7 @@ private:
m_modp = nodep;
m_stableNum = 0;
nodep->iterateChildren(*this);
m_modp= NULL;
}
virtual void visit(AstScope* nodep, AstNUser*) {
//UINFO(4," SCOPE "<<nodep<<endl);
@@ -277,6 +296,26 @@ private:
}
nodep->deleteTree(); nodep = NULL;
}
virtual void visit(AstCoverToggle* nodep, AstNUser*) {
//nodep->dumpTree(cout,"ct:");
//COVERTOGGLE(INC, ORIG, CHANGE) ->
// IF(ORIG ^ CHANGE) { INC; CHANGE = ORIG; }
AstNode* incp = nodep->incp()->unlinkFrBack();
AstNode* origp = nodep->origp()->unlinkFrBack();
AstNode* changep = nodep->changep()->unlinkFrBack();
AstIf* newp = new AstIf(nodep->fileline(),
new AstXor(nodep->fileline(),
origp,
changep),
incp, NULL);
// We could add another IF to detect posedges, and only increment if so.
// It's another whole branch though verus a potential memory miss.
// We'll go with the miss.
newp->addIfsp(new AstAssign(nodep->fileline(),
changep->cloneTree(false),
origp->cloneTree(false)));
nodep->replaceWith(newp); nodep->deleteTree(); nodep=NULL;
}
virtual void visit(AstInitial* nodep, AstNUser*) {
AstNode* cmtp = new AstComment(nodep->fileline(), nodep->typeName());
nodep->replaceWith(cmtp);
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+21 -9
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -58,8 +58,14 @@
class CombBaseVisitor : public AstNVisitor {
protected:
// STATE
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
virtual ~CombBaseVisitor() {}
//***** optimization levels
@@ -174,6 +180,9 @@ private:
// AstCFunc::user3p() -> AstCFunc*, If set, replace ccalls to this func with new func
// AstNodeStmt::user3() -> AstNode*. True if to ignore this cell
// AstNodeStmt::user4() -> V3Hashed::V3Hash. Hash value of this node (hash of 0 is illegal)
AstUser1InUse m_inuser1;
AstUser3InUse m_inuser3;
//AstUser4InUse part of V3Hashed
// STATE
typedef enum {STATE_IDLE, STATE_HASH, STATE_DUP} CombineState;
@@ -186,7 +195,7 @@ private:
int m_modNFuncs; // Number of functions made
AstNode* m_walkLast1p; // Final node that is the same in duplicate list
AstNode* m_walkLast2p; // Final node that is the same in duplicate list
V3Hashed m_hashed; // Hash for every node
V3Hashed m_hashed; // Hash for every node in module
// METHODS
void hashStatement(AstNode* nodep) {
@@ -279,7 +288,7 @@ private:
if (node1p==node2p) continue;
//
// We need to mark iteration to prevent matching code inside code (abab matching in ababab)
AstNode::userClearTree(); // userp() used on entire tree
AstNode::user1ClearTree(); // user1p() used on entire tree
m_walkLast1p = NULL;
m_walkLast2p = NULL;
int depth = walkDupCodeNext(node1p, node2p, 1);
@@ -305,7 +314,7 @@ private:
int walkDupCodeNext(AstNode* node1p, AstNode* node2p, int level) {
// Find number of common statements between the two node1p_nextp's...
if (node1p->userp() || node2p->userp()) return 0; // Already iterated
if (node1p->user1p() || node2p->user1p()) return 0; // Already iterated
if (node1p->user3p() || node2p->user3p()) return 0; // Already merged
if (!m_hashed.sameNodes(node1p,node2p)) return 0; // walk of tree has same comparison
V3Hash hashval(node1p->user4p());
@@ -313,8 +322,8 @@ private:
//UINFO(9," wdup2 "<<level<<" "<<V3Hash(node2p->user4p())<<" "<<node2p<<endl);
m_walkLast1p = node1p;
m_walkLast2p = node2p;
node1p->user(true);
node2p->user(true);
node1p->user1(true);
node2p->user1(true);
if (node1p->nextp() && node2p->nextp()) {
return hashval.depth()+walkDupCodeNext(node1p->nextp(), node2p->nextp(), level+1);
}
@@ -378,8 +387,7 @@ private:
// Track all callers of each function
m_call.main(nodep);
//
AstNode::user3ClearTree(); // userp() used on entire tree
//In V3Hashed AstNode::user4ClearTree(); // userp() used on entire tree
//In V3Hashed AstNode::user4ClearTree(); // user4p() used on entire tree
// Iterate modules backwards, in bottom-up order.
// Required so that a module instantiating another can benefit from collapsing.
nodep->iterateChildrenBackwards(*this);
@@ -393,6 +401,9 @@ private:
m_state = STATE_HASH;
nodep->iterateChildren(*this);
m_state = STATE_IDLE;
if (debug()>=9) {
m_hashed.dumpFilePrefixed("combine");
}
// Walk the hashes removing empty functions
if (emptyFunctionDeletion()) {
walkEmptyFuncs();
@@ -407,6 +418,7 @@ private:
nodep->iterateChildren(*this);
m_state = STATE_IDLE;
}
m_modp = NULL;
}
virtual void visit(AstCFunc* nodep, AstNUser*) {
m_funcp = nodep;
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+376 -38
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -30,6 +30,7 @@
#include <cstdarg>
#include <unistd.h>
#include <map>
#include <algorithm>
#include "V3Global.h"
#include "V3Const.h"
@@ -43,11 +44,11 @@
class ConstVarMarkVisitor : public AstNVisitor {
// NODE STATE
// AstVar::userp -> bool, Var marked, 0=not set yet
// AstVar::user4p -> bool, Var marked, 0=not set yet
private:
// VISITORS
virtual void visit(AstVarRef* nodep, AstNUser*) {
if (nodep->varp()) nodep->varp()->user(1);
if (nodep->varp()) nodep->varp()->user4(1);
}
virtual void visit(AstNode* nodep, AstNUser*) {
nodep->iterateChildren(*this);
@@ -55,7 +56,7 @@ private:
public:
// CONSTUCTORS
ConstVarMarkVisitor(AstNode* nodep) {
AstNode::userClearTree();
AstNode::user4ClearTree(); // Check marked InUse before we're called
nodep->iterateAndNext(*this, NULL);
}
virtual ~ConstVarMarkVisitor() {}
@@ -63,13 +64,13 @@ public:
class ConstVarFindVisitor : public AstNVisitor {
// NODE STATE
// AstVar::userp -> bool, input from ConstVarMarkVisitor
// AstVar::user4p -> bool, input from ConstVarMarkVisitor
// MEMBERS
bool m_found;
private:
// VISITORS
virtual void visit(AstVarRef* nodep, AstNUser*) {
if (nodep->varp() && nodep->varp()->user()) m_found = true;
if (nodep->varp() && nodep->varp()->user4()) m_found = true;
}
virtual void visit(AstNode* nodep, AstNUser*) {
nodep->iterateChildren(*this);
@@ -91,9 +92,9 @@ public:
class ConstVisitor : public AstNVisitor {
private:
// NODE STATE
// ** only when m_warn is set. If state is needed other times,
// ** only when m_warn/m_expensive is set. If state is needed other times,
// ** must track down everywhere V3Const is called and make sure no overlaps.
// AstVar::userp -> Used by ConstVarMarkVisitor/ConstVarFindVisitor
// AstVar::user4p -> Used by ConstVarMarkVisitor/ConstVarFindVisitor
// STATE
bool m_params; // If true, propogate parameterized and true numbers only
@@ -101,11 +102,17 @@ private:
bool m_wremove; // Inside scope, no assignw removal
bool m_warn; // Output warnings
bool m_cpp; // C++ conversions only
bool m_expensive; // Enable computationally expensive optimizations
AstModule* m_modp; // Current module
AstNode* m_scopep; // Current scope
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
bool operandConst (AstNode* nodep) {
return (nodep->castConst());
}
@@ -132,13 +139,98 @@ private:
if (rnodep->width() != bnodep->width()) return false;
return operandsSame(bnodep->lhsp(), rnodep->lhsp());
}
bool operandAsvLUp (AstNode* nodep) {
// BIASV(BIASV(CONSTll,lr),r) -> BIASV(CONSTll,BIASV(lr,r))
//
// Example of how this is useful:
// BIASV(BIASV(CONSTa,b...),BIASV(CONSTc,d...)) // hits operandAsvUp
// BIASV(CONSTa,BIASV(b...,BIASV(CONSTc,d...))) // hits operandAsvUp
// BIASV(CONSTa,BIASV(CONSTc,BIASV(c...,d...))) // hits operandAsvConst
// BIASV(BIASV(CONSTa,CONSTc),BIASV(c...,d...))) // hits normal constant propagation
// BIASV(CONST_a_c,BIASV(c...,d...)))
//
// Idea for the future: All BiComAsvs could be lists, sorted by if they're constant
AstNodeBiComAsv* bnodep = nodep->castNodeBiComAsv();
if (!bnodep) return false;
AstNodeBiComAsv* lnodep = bnodep->lhsp()->castNodeBiComAsv();
if (!lnodep) return false;
if (lnodep->type() != bnodep->type()) return false;
if (lnodep->width() != bnodep->width()) return false;
return lnodep->lhsp()->castConst();
}
bool operandAsvRUp (AstNode* nodep) {
// BIASV(l,BIASV(CONSTrl,rr)) -> BIASV(CONSTrl,BIASV(l,rr))
AstNodeBiComAsv* bnodep = nodep->castNodeBiComAsv();
if (!bnodep) return false;
AstNodeBiComAsv* rnodep = bnodep->rhsp()->castNodeBiComAsv();
if (!rnodep) return false;
if (rnodep->type() != bnodep->type()) return false;
if (rnodep->width() != bnodep->width()) return false;
return rnodep->lhsp()->castConst();
}
static bool operandAndOrSame(AstNode* nodep) {
AstNodeBiop* np = nodep->castNodeBiop();
AstNodeBiop* lp = np->lhsp()->castNodeBiop();
AstNodeBiop* rp = np->rhsp()->castNodeBiop();
return (lp && rp
&& lp->width()==rp->width()
&& lp->type()==rp->type()
&& operandsSame(lp->lhsp(),rp->lhsp()));
}
static bool matchOrAndNot(AstNodeBiop* nodep) {
// AstOr{$a, AstAnd{AstNot{$b}, $c}} if $a.width1, $a==$b => AstOr{$a,$c}
// Someday we'll sort the biops completely and this can be simplified
// This often results from our simplified clock generation:
// if (rst) ... else if (enable)... -> OR(rst,AND(!rst,enable))
AstNode* ap;
AstNodeBiop* andp;
if (nodep->lhsp()->castAnd()) { andp=nodep->lhsp()->castAnd(); ap=nodep->rhsp(); }
else if (nodep->rhsp()->castAnd()) { andp=nodep->rhsp()->castAnd(); ap=nodep->lhsp(); }
else return false;
AstNodeUniop* notp;
AstNode* cp;
if (andp->lhsp()->castNot()) { notp=andp->lhsp()->castNot(); cp=andp->rhsp(); }
else if (andp->rhsp()->castNot()) { notp=andp->rhsp()->castNot(); cp=andp->lhsp(); }
else return false;
AstNode* bp = notp->lhsp();
if (!operandsSame(ap, bp)) return false;
// Do it
cp->unlinkFrBack();
andp->unlinkFrBack()->deleteTree(); andp=NULL; notp=NULL;
// Replace whichever branch is now dangling
if (nodep->rhsp()) nodep->lhsp(cp);
else nodep->rhsp(cp);
return true;
}
static bool operandShiftSame(AstNode* nodep) {
AstNodeBiop* np = nodep->castNodeBiop();
{
AstShiftL* lp = np->lhsp()->castShiftL();
AstShiftL* rp = np->rhsp()->castShiftL();
if (lp && rp) {
return (lp->width() == rp->width()
&& lp->lhsp()->width() == rp->lhsp()->width()
&& operandsSame(lp->rhsp(), rp->rhsp()));
}
}
{
AstShiftR* lp = np->lhsp()->castShiftR();
AstShiftR* rp = np->rhsp()->castShiftR();
if (lp && rp) {
return (lp->width() == rp->width()
&& lp->lhsp()->width() == rp->lhsp()->width()
&& operandsSame(lp->rhsp(), rp->rhsp()));
}
}
return false;
}
bool operandHugeShiftL(AstNodeBiop* nodep) {
return (nodep->rhsp()->castConst()
&& nodep->rhsp()->castConst()->asInt() >= (uint32_t)(nodep->width()));
&& nodep->rhsp()->castConst()->toUInt() >= (uint32_t)(nodep->width()));
}
bool operandHugeShiftR(AstNodeBiop* nodep) {
return (nodep->rhsp()->castConst()
&& nodep->rhsp()->castConst()->asInt() >= (uint32_t)(nodep->lhsp()->width()));
&& nodep->rhsp()->castConst()->toUInt() >= (uint32_t)(nodep->lhsp()->width()));
}
bool operandIsTwo(AstNode* nodep) {
return (nodep->castConst()
@@ -215,15 +307,19 @@ private:
bool warnSelect(AstSel* nodep) {
AstNode* basefromp = AstArraySel::baseFromp(nodep->fromp());
if (AstNodeVarRef* varrefp = basefromp->castNodeVarRef()) {
AstVar* varp = varrefp->varp();
if (m_warn
&& nodep->lsbp()->castConst()
&& nodep->widthp()->castConst()
&& (!varrefp->varp()->rangep() || varrefp->varp()->msb()) // else it's non-resolvable parameterized
&& ( ( (nodep->msbConst() > varrefp->varp()->msb())
|| (nodep->lsbConst() > varrefp->varp()->msb())))) {
&& (!varp->rangep() || varp->msb()) // else it's non-resolvable parameterized
&& ( ( (nodep->msbConst() > varp->msbMaxSelect())
|| (nodep->lsbConst() > varp->msbMaxSelect())))) {
// See also warning in V3Width
nodep->v3error("Selection index out of range: "
<<nodep->msbConst()<<":"<<nodep->lsbConst()
<<" outside "<<varrefp->varp()->msb()<<":0");
<<" outside "<<varp->msbMaxSelect()<<":0"
<<(varp->lsb()>=0 ? ""
:" (adjusted +"+cvtToStr(-varp->lsb())+" to account for negative lsb)"));
}
}
return false; // Not a transform, so NOP
@@ -364,6 +460,66 @@ private:
if (rp->lhsp()->castConst() && rp->rhsp()->castConst()) replaceConst(rp);
//nodep->dumpTree(cout, " repAsvConst_new: ");
}
void replaceAsvLUp (AstNodeBiop* nodep) {
// BIASV(BIASV(CONSTll,lr),r) -> BIASV(CONSTll,BIASV(lr,r))
AstNodeBiop* lp = nodep->lhsp()->unlinkFrBack()->castNodeBiop();
AstNode* llp = lp->lhsp()->unlinkFrBack();
AstNode* lrp = lp->rhsp()->unlinkFrBack();
AstNode* rp = nodep->rhsp()->unlinkFrBack();
nodep->lhsp(llp);
nodep->rhsp(lp);
lp->lhsp(lrp);
lp->rhsp(rp);
//nodep->dumpTree(cout, " repAsvLUp_new: ");
}
void replaceAsvRUp (AstNodeBiop* nodep) {
// BIASV(l,BIASV(CONSTrl,rr)) -> BIASV(CONSTrl,BIASV(l,rr))
AstNode* lp = nodep->lhsp()->unlinkFrBack();
AstNodeBiop* rp = nodep->rhsp()->unlinkFrBack()->castNodeBiop();
AstNode* rlp = rp->lhsp()->unlinkFrBack();
AstNode* rrp = rp->rhsp()->unlinkFrBack();
nodep->lhsp(rlp);
nodep->rhsp(rp);
rp->lhsp(lp);
rp->rhsp(rrp);
//nodep->dumpTree(cout, " repAsvRUp_new: ");
}
void replaceAndOr (AstNodeBiop* nodep) {
// Or(And(CONSTll,lr),And(CONSTrl==ll,rr)) -> And(CONSTll,Or(lr,rr))
// (Or/And may also be reversed)
AstNodeBiop* lp = nodep->lhsp()->unlinkFrBack()->castNodeBiop();
AstNode* llp = lp->lhsp()->unlinkFrBack();
AstNode* lrp = lp->rhsp()->unlinkFrBack();
AstNodeBiop* rp = nodep->rhsp()->unlinkFrBack()->castNodeBiop();
AstNode* rlp = rp->lhsp()->unlinkFrBack();
AstNode* rrp = rp->rhsp()->unlinkFrBack();
nodep->replaceWith(lp);
lp->lhsp(llp);
lp->rhsp(nodep);
nodep->lhsp(lrp);
nodep->rhsp(rrp);
rp->deleteTree();
rlp->deleteTree();
//nodep->dumpTree(cout, " repAndOr_new: ");
}
void replaceShiftSame (AstNodeBiop* nodep) {
// Or(Shift(ll,CONSTlr),Shift(rl,CONSTrr==lr)) -> Shift(Or(ll,rl),CONSTlr)
// (Or/And may also be reversed)
AstNodeBiop* lp = nodep->lhsp()->unlinkFrBack()->castNodeBiop();
AstNode* llp = lp->lhsp()->unlinkFrBack();
AstNode* lrp = lp->rhsp()->unlinkFrBack();
AstNodeBiop* rp = nodep->rhsp()->unlinkFrBack()->castNodeBiop();
AstNode* rlp = rp->lhsp()->unlinkFrBack();
AstNode* rrp = rp->rhsp()->unlinkFrBack();
nodep->replaceWith(lp);
lp->lhsp(nodep);
lp->rhsp(lrp);
nodep->lhsp(llp);
nodep->rhsp(rlp);
rp->deleteTree();
rrp->deleteTree();
//nodep->dumpTree(cout, " repShiftSame_new: ");
}
void replaceExtend (AstNode* nodep, AstNode* arg0p) {
// -> EXTEND(nodep)
// like a AstExtend{$rhsp}, but we need to set the width correctly from base node
@@ -411,7 +567,7 @@ private:
AstNode* ap = lhsp->lhsp()->unlinkFrBack();
AstNode* bp = lhsp->rhsp()->unlinkFrBack();
AstNodeBiop* shift1p = nodep;
AstNodeBiop* shift2p = nodep->cloneTree(true)->castNodeBiop();
AstNodeBiop* shift2p = nodep->cloneTree(true);
shift1p->lhsp(ap); shift1p->rhsp(shiftp->cloneTree(true));
shift2p->lhsp(bp); shift2p->rhsp(shiftp);
AstNodeBiop* newp = lhsp;
@@ -432,8 +588,8 @@ private:
nodep->accept(*this); // Further reduce, either node may have more reductions.
} else {
// We know shift amounts are constant, but might be a mixed left/right shift
int shift1 = shift1p->castConst()->asInt(); if (lhsp->castShiftR()) shift1=-shift1;
int shift2 = shift2p->castConst()->asInt(); if (nodep->castShiftR()) shift2=-shift2;
int shift1 = shift1p->castConst()->toUInt(); if (lhsp->castShiftR()) shift1=-shift1;
int shift2 = shift2p->castConst()->toUInt(); if (nodep->castShiftR()) shift2=-shift2;
int newshift = shift1+shift2;
shift1p->deleteTree(); shift1p=NULL;
shift2p->deleteTree(); shift1p=NULL;
@@ -490,9 +646,9 @@ private:
if (!varNotReferenced(nodep->rhsp(), varref1p->varp())) return false;
if (!varNotReferenced(nextp->rhsp(), varref2p->varp())) return false;
// Swap?
if (( con1p->asInt() != con2p->asInt() + sel2p->width())
&&(con2p->asInt() != con1p->asInt() + sel1p->width())) return false;
bool lsbFirstAssign = (con1p->asInt() < con2p->asInt());
if (( con1p->toSInt() != con2p->toSInt() + sel2p->width())
&&(con2p->toSInt() != con1p->toSInt() + sel1p->width())) return false;
bool lsbFirstAssign = (con1p->toUInt() < con2p->toUInt());
// If the user already has nice 32-bit divisions, keep them to aid later subdivision
//if (VL_BITBIT_I(con1p->toUInt()) == 0) return false;
UINFO(4,"replaceAssignMultiSel "<<nodep<<endl);
@@ -547,6 +703,9 @@ private:
else if (!m_cpp && nodep->lhsp()->castConcat()) {
bool need_temp = false;
if (m_warn && !nodep->castAssignDly()) { // Is same var on LHS and RHS?
// Note only do this (need user4) when m_warn, which is
// done as unique visitor
AstUser4InUse m_inuser4;
ConstVarMarkVisitor mark(nodep->lhsp());
ConstVarFindVisitor find(nodep->rhsp());
if (find.found()) need_temp = true;
@@ -596,8 +755,8 @@ private:
if (!m_modp) nodep->v3fatalSrc("Not under module");
// We could create just one temp variable, but we'll get better optimization
// if we make one per term.
string name1 = ((string)"__Vconcswap__"+cvtToStr(m_modp->varNumGetInc()));
string name2 = ((string)"__Vconcswap__"+cvtToStr(m_modp->varNumGetInc()));
string name1 = ((string)"__Vconcswap"+cvtToStr(m_modp->varNumGetInc()));
string name2 = ((string)"__Vconcswap"+cvtToStr(m_modp->varNumGetInc()));
AstVar* temp1p = new AstVar(sel1p->fileline(), AstVarType::BLOCKTEMP, name1,
new AstRange(sel1p->fileline(), msb1-lsb1, 0));
AstVar* temp2p = new AstVar(sel2p->fileline(), AstVarType::BLOCKTEMP, name2,
@@ -648,7 +807,7 @@ private:
if (!nodep->castAnd()->rhsp()->castShiftR()) return false;
AstShiftR* shiftp = nodep->castAnd()->rhsp()->castShiftR();
if (!shiftp->rhsp()->castConst()) return false;
if ((uint32_t)(nodep->width()) <= shiftp->rhsp()->castConst()->asInt()) return false;
if ((uint32_t)(nodep->width()) <= shiftp->rhsp()->castConst()->toUInt()) return false;
return true;
}
void replaceBoolShift(AstNode* nodep) {
@@ -784,7 +943,7 @@ private:
AstNode* newlsbp;
if (lsb1p->castConst() && lsb2p->castConst()) {
newlsbp = new AstConst(lsb1p->fileline(),
lsb1p->castConst()->asInt() + lsb2p->castConst()->asInt());
lsb1p->castConst()->toUInt() + lsb2p->castConst()->toUInt());
lsb1p->deleteTree(); lsb1p=NULL;
lsb2p->deleteTree(); lsb2p=NULL;
} else {
@@ -851,7 +1010,7 @@ private:
AstNode* widthp = nodep->widthp()->unlinkFrBack();
AstSel* newp = new AstSel(nodep->fileline(),
fromp,
new AstConst(lsbp->fileline(), lsbp->asInt() % fromp->width()),
new AstConst(lsbp->fileline(), lsbp->toUInt() % fromp->width()),
widthp);
newp->widthSignedFrom(nodep);
nodep->replaceWith(newp); nodep->deleteTree(); nodep=NULL;
@@ -907,19 +1066,26 @@ private:
} else nodep->v3fatalSrc("Missing ATTR type case\n");
}
}
bool onlySenItemInSenTree(AstNodeSenItem* nodep) {
// Only one if it's not in a list
return (!nodep->nextp() && nodep->backp()->nextp() != nodep);
}
virtual void visit(AstSenItem* nodep, AstNUser*) {
nodep->iterateChildren(*this);
if (nodep->sensp()->castConst()
|| (nodep->varrefp() && nodep->varrefp()->varp()->isParam())) {
// Constants in sensitivity lists may be removed (we'll simplify later)
AstSenItem* newp;
if (nodep->isClocked()) { // A constant can never get a pos/negexge
newp = new AstSenItem(nodep->fileline(), AstSenItem::Never());
if (onlySenItemInSenTree(nodep)) {
nodep->replaceWith(new AstSenItem(nodep->fileline(), AstSenItem::Never()));
nodep->deleteTree(); nodep=NULL;
} else {
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
}
} else { // Otherwise it may compute a result that needs to settle out
newp = new AstSenItem(nodep->fileline(), AstSenItem::Combo());
nodep->replaceWith(new AstSenItem(nodep->fileline(), AstSenItem::Combo()));
nodep->deleteTree(); nodep=NULL;
}
nodep->replaceWith(newp);
nodep->deleteTree(); nodep=NULL;
} else if (nodep->sensp()->castNot()) {
// V3Gate may propagate NOTs into clocks... Just deal with it
AstNode* sensp = nodep->sensp();
@@ -939,6 +1105,150 @@ private:
if (nodep->hasVar() && !nodep->varrefp()) nodep->v3fatalSrc("Null sensitivity variable");
}
}
virtual void visit(AstSenGate* nodep, AstNUser*) {
nodep->iterateChildren(*this);
if (AstConst* constp = nodep->rhsp()->castConst()) {
if (constp->isZero()) {
UINFO(4,"SENGATE(...,0)->NEVER"<<endl);
if (onlySenItemInSenTree(nodep)) {
nodep->replaceWith(new AstSenItem(nodep->fileline(), AstSenItem::Never()));
nodep->deleteTree(); nodep=NULL;
} else {
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
}
} else {
UINFO(4,"SENGATE(SENITEM,0)->ALWAYS SENITEM"<<endl);
AstNode* senitemp = nodep->sensesp()->unlinkFrBack();
nodep->replaceWith(senitemp);
nodep->deleteTree(); nodep=NULL;
}
}
}
struct SenItemCmp {
inline bool operator () (AstNodeSenItem* lhsp, AstNodeSenItem* rhsp) const {
if (lhsp->type() < rhsp->type()) return true;
if (lhsp->type() > rhsp->type()) return false;
const AstSenItem* litemp = lhsp->castSenItem();
const AstSenItem* ritemp = rhsp->castSenItem();
if (litemp && ritemp) {
// Looks visually better if we keep sorted by name
if (litemp->edgeType() < ritemp->edgeType()) return true;
if (litemp->edgeType() > ritemp->edgeType()) return false;
if (!litemp->varrefp() && ritemp->varrefp()) return true;
if ( litemp->varrefp() && !ritemp->varrefp()) return false;
if (litemp->varrefp() && ritemp->varrefp()) {
if (litemp->varrefp()->name() < ritemp->varrefp()->name()) return true;
if (litemp->varrefp()->name() > ritemp->varrefp()->name()) return false;
// 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;
}
}
return false;
}
};
virtual void visit(AstSenTree* nodep, AstNUser*) {
nodep->iterateChildren(*this);
if (m_expensive) {
//cout<<endl; nodep->dumpTree(cout,"ssin: ");
// Optimize ideas for the future:
// SENTREE(... SENGATE(x,a), SENGATE(SENITEM(x),b) ...) => SENGATE(x,OR(a,b))
// SENTREE(... SENITEM(x), SENGATE(SENITEM(x),*) ...) => SENITEM(x)
// Do we need the SENITEM's to be identical? No because we're
// ORing between them; we just need to insure that the result is at
// least as frequently activating. So we simply
// SENGATE(SENITEM(x)) -> SENITEM(x), then let it collapse with the
// other SENITEM(x).
{
AstUser4InUse m_inuse4;
// Mark x in SENITEM(x)
for (AstNodeSenItem* senp = nodep->sensesp()->castNodeSenItem();
senp; senp=senp->nextp()->castNodeSenItem()) {
if (AstSenItem* itemp = senp->castSenItem()) {
if (itemp->varrefp() && itemp->varrefp()->varScopep()) {
itemp->varrefp()->varScopep()->user4(1);
}
}
}
// Find x in SENTREE(SENITEM(x))
for (AstNodeSenItem* nextp, * senp = nodep->sensesp()->castNodeSenItem();
senp; senp=nextp) {
nextp=senp->nextp()->castNodeSenItem();
if (AstSenGate* gatep = senp->castSenGate()) {
if (AstSenItem* itemp = gatep->sensesp()->castSenItem()) {
if (itemp->varrefp() && itemp->varrefp()->varScopep()) {
if (itemp->varrefp()->varScopep()->user4()) {
// Found, push this item up to the top
itemp->unlinkFrBack();
nodep->addSensesp(itemp);
gatep->unlinkFrBack()->deleteTree(); gatep=NULL; senp=NULL;
}
}
}
}
}
}
// Sort the sensitivity names so "posedge a or b" and "posedge b or a" end up together.
// Also, remove duplicate assignments, and fold POS&NEGs into ANYEDGEs
// Make things a little faster; check first if we need a sort
for (AstNodeSenItem* nextp, * senp = nodep->sensesp()->castNodeSenItem();
senp; senp=nextp) {
nextp=senp->nextp()->castNodeSenItem();
SenItemCmp cmp;
if (nextp && !cmp(senp, nextp)) {
// Something's out of order, sort it
senp = NULL;
vector<AstNodeSenItem*> vec;
for (AstNodeSenItem* senp = nodep->sensesp()->castNodeSenItem(); senp; senp=senp->nextp()->castNodeSenItem()) {
vec.push_back(senp);
}
sort(vec.begin(), vec.end(), SenItemCmp());
for (vector<AstNodeSenItem*>::iterator it=vec.begin(); it!=vec.end(); ++it) {
(*it)->unlinkFrBack();
}
for (vector<AstNodeSenItem*>::iterator it=vec.begin(); it!=vec.end(); ++it) {
nodep->addSensesp(*it);
}
break;
}
}
// Pass2, remove dup edges
for (AstNodeSenItem* nextp, * senp = nodep->sensesp()->castNodeSenItem();
senp; senp=nextp) {
nextp=senp->nextp()->castNodeSenItem();
AstNodeSenItem* cmpp = nextp;
AstSenItem* litemp = senp->castSenItem();
AstSenItem* ritemp = cmpp->castSenItem();
if (litemp && ritemp) {
if (litemp->varrefp() && ritemp->varrefp() && litemp->varrefp()->sameTree(ritemp->varrefp())
|| (!litemp->varrefp() && !ritemp->varrefp())) {
// We've sorted in the order ANY, BOTH, POS, NEG, so we don't need to try opposite orders
if (( litemp->edgeType()==AstEdgeType::ANYEDGE) // ANY or {BOTH|POS|NEG} -> ANY
|| (litemp->edgeType()==AstEdgeType::BOTHEDGE) // BOTH or {POS|NEG} -> BOTH
|| (litemp->edgeType()==AstEdgeType::POSEDGE // POS or NEG -> BOTH
&& ritemp->edgeType()==AstEdgeType::NEGEDGE)
|| (litemp->edgeType()==ritemp->edgeType()) // Identical edges
) {
// Fix edge of old node
if (litemp->edgeType()==AstEdgeType::POSEDGE
&& ritemp->edgeType()==AstEdgeType::NEGEDGE)
litemp->edgeType(AstEdgeType::BOTHEDGE);
// Remove redundant node
ritemp->unlinkFrBack()->deleteTree(); ritemp=NULL; cmpp=NULL;
// Try to collapse again
nextp=litemp;
}
}
}
}
//nodep->dumpTree(cout,"ssou: ");
}
}
//-----
// Zero elimination
@@ -1128,9 +1438,18 @@ private:
// $accessor_name, ...
// # ,, gets replaced with a , rather than &&
// }" # bracket not paren
// ,"function to call"
// or ,"AstREPLACEMENT_TYPE{ $accessor }"
// or ,"! # Print line number when matches, so can see operations
// ,"what to call"
//
// Where "what_to_call" is:
// "function to call"
// "AstREPLACEMENT_TYPE{ $accessor }"
// "! # Print line number when matches, so can see operations
// "NEVER" # Print error message
// "DONE" # Process of matching did the transform already
// In the future maybe support more complicated match & replace:
// ("AstOr {%a, AstAnd{AstNot{%b}, %c}} if %a.width1 if %a==%b", "AstOr{%a,%c}; %b.delete");
// Lhs/rhs would be implied; for non math operations you'd need $lhsp etc.
// Lint Checks
// v--- *1* These ops are always first, as we warn before replacing
@@ -1204,6 +1523,8 @@ private:
TREEOP("AstNodeBiCom{!$lhsp.castConst, $rhsp.castConst}", "swapSides(nodep)");
TREEOP("AstNodeBiComAsv{operandAsvConst(nodep)}", "replaceAsv(nodep)");
TREEOP("AstNodeBiComAsv{operandAsvSame(nodep)}", "replaceAsv(nodep)");
TREEOP("AstNodeBiComAsv{operandAsvLUp(nodep)}", "replaceAsvLUp(nodep)");
TREEOP("AstNodeBiComAsv{operandAsvRUp(nodep)}", "replaceAsvRUp(nodep)");
// v--- *1* as These ops are always first, as we warn before replacing
TREEOP1("AstLt {$lhsp, $rhsp.isZero}", "replaceNumSigned(nodep,0)");
TREEOP1("AstGte {$lhsp, $rhsp.isZero}", "replaceNumSigned(nodep,1)");
@@ -1315,6 +1636,14 @@ private:
// CONCAT({const},CONCAT({const},{c})) -> CONCAT((constifiedCONC{const|const},{c}))
TREEOPV("AstConcat{operandConcatMove(nodep)}", "moveConcat(nodep)");
TREEOPV("AstConcat{$lhsp.isZero, $rhsp}", "replaceExtend(nodep, nodep->rhsp())");
// Common two-level operations that can be simplified
TREEOP ("AstAnd {$lhsp.castOr, $rhsp.castOr, operandAndOrSame(nodep)}", "replaceAndOr(nodep)");
TREEOP ("AstOr {$lhsp.castAnd,$rhsp.castAnd,operandAndOrSame(nodep)}", "replaceAndOr(nodep)");
TREEOP ("AstOr {matchOrAndNot(nodep)}", "DONE");
TREEOP ("AstAnd {operandShiftSame(nodep)}", "replaceShiftSame(nodep)");
TREEOP ("AstOr {operandShiftSame(nodep)}", "replaceShiftSame(nodep)");
TREEOP ("AstXor {operandShiftSame(nodep)}", "replaceShiftSame(nodep)");
TREEOP ("AstXnor{operandShiftSame(nodep)}", "replaceShiftSame(nodep)");
// Note can't simplify a extend{extends}, extends{extend}, as the sign bits end up in the wrong places
TREEOPV("AstExtend {$lhsp.castExtend}", "replaceExtend(nodep, nodep->lhsp()->castExtend()->lhsp())");
TREEOPV("AstExtendS{$lhsp.castExtendS}", "replaceExtend(nodep, nodep->lhsp()->castExtendS()->lhsp())");
@@ -1358,8 +1687,11 @@ private:
public:
// CONSTUCTORS
ConstVisitor(bool params, bool required, bool warn, bool cpp) {
m_params = params; m_required = required; m_warn=warn; m_cpp=cpp;
ConstVisitor(bool params, bool expensive, bool warn, bool cpp) {
m_params = params; m_required = params;
m_expensive = expensive;
m_warn = warn;
m_cpp = cpp;
m_wremove = true;
m_modp = NULL;
m_scopep = NULL;
@@ -1380,19 +1712,21 @@ void V3Const::constifyParam(AstNode* nodep) {
V3Width::widthParams(nodep);
V3Signed::signedParams(nodep);
}
ConstVisitor visitor (true,true,false,false);
ConstVisitor visitor (true,false,false,false);
visitor.main(nodep);
// Because we do edits, nodep links may get trashed and core dump this.
//if (debug()>0) nodep->dumpTree(cout," forceConDONE: ");
}
void V3Const::constifyAll(AstNetlist* nodep) {
// Only call from Verilator.cpp, as it uses user#'s
UINFO(2,__FUNCTION__<<": "<<endl);
ConstVisitor visitor (false,false,false,false);
ConstVisitor visitor (false,true,false,false);
visitor.main(nodep);
}
void V3Const::constifyAllLint(AstNetlist* nodep) {
// Only call from Verilator.cpp, as it uses user#'s
UINFO(2,__FUNCTION__<<": "<<endl);
ConstVisitor visitor (false,false,true,false);
visitor.main(nodep);
@@ -1409,3 +1743,7 @@ void V3Const::constifyTree(AstNode* nodep) {
visitor.main(nodep);
}
void V3Const::constifyTreeExpensive(AstNode* nodep) {
ConstVisitor visitor (false,true,false,false);
visitor.main(nodep);
}
+3 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -40,6 +40,8 @@ public:
static void constifyCpp(AstNetlist* nodep);
// Only the current node and lower
static void constifyTree(AstNode* nodep);
// Only the current node and lower, with special SenTree optimization
static void constifyTreeExpensive(AstNode* nodep);
};
#endif // Guard
+183 -19
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -38,7 +38,6 @@
#include "V3Global.h"
#include "V3Coverage.h"
#include "V3Ast.h"
#include "V3Const.h"
//######################################################################
// Coverage state, as a visitor of each AstNode
@@ -46,59 +45,198 @@
class CoverageVisitor : public AstNVisitor {
private:
// TYPES
typedef map<FileLine*,int> FileMap;
typedef map<string,int> FileMap;
// STATE
bool m_checkBlock; // Should this block get covered?
AstModule* m_modp; // Current module to add statement to
bool m_inToggleOff; // In function/task etc
FileMap m_fileps; // Column counts for each fileline
//int debug() { return 9; }
string m_beginHier; // AstBegin hier name for user coverage points
// METHODS
AstCoverInc* newCoverInc(FileLine* fl, const string& type, const string& comment) {
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
const char* varIgnoreToggle(AstVar* nodep) {
// Return true if this shouldn't be traced
// See also similar rule in V3TraceDecl::varIgnoreTrace
string prettyName = nodep->prettyName();
if (!nodep->isToggleCoverable())
return "Not relevant signal type";
if (prettyName.c_str()[0] == '_')
return "Leading underscore";
if (prettyName.find("._") != string::npos)
return "Inlined leading underscore";
if ((nodep->width()*nodep->arrayElements()) > 256) return "Wide bus/array > 256 bits";
// We allow this, though tracing doesn't
// if (nodep->arrayp(1)) return "Unsupported: Multi-dimensional array";
return NULL;
}
AstCoverInc* newCoverInc(FileLine* fl, const string& hier,
const string& page_prefix, const string& comment) {
// For line coverage, we may have multiple if's on one line, so disambiguate if
// everything is otherwise identical
// (Don't set column otherwise as it may result in making bins not match up with
// different types of coverage enabled.)
string key = fl->filename()+"\001"+cvtToStr(fl->lineno())+"\001"+hier+"\001"+page_prefix+"\001"+comment;
int column = 0;
FileMap::iterator it = m_fileps.find(fl);
FileMap::iterator it = m_fileps.find(key);
if (it == m_fileps.end()) {
m_fileps.insert(make_pair(fl,column+1));
m_fileps.insert(make_pair(key,column+1));
} else {
column = (it->second)++;
}
AstCoverDecl* declp = new AstCoverDecl(fl, column, type, comment);
// We could use the basename of the filename to the page, but seems better for code
// from an include file to be listed under the module using it rather than the include file.
// Note the module name could have parameters appended, we'll consider this
// a feature as it allows for each parameterized block to be counted separately.
// Someday the user might be allowed to specify a different page suffix
string page = page_prefix + "/" + m_modp->prettyName();
AstCoverDecl* declp = new AstCoverDecl(fl, column, page, comment);
declp->hier(hier);
m_modp->addStmtp(declp);
return new AstCoverInc(fl, declp);
}
// VISITORS
// VISITORS - BOTH
virtual void visit(AstModule* nodep, AstNUser*) {
m_modp = nodep;
m_fileps.clear();
nodep->iterateChildren(*this);
m_modp = NULL;
}
// VISITORS - TOGGLE COVERAGE
virtual void visit(AstNodeFTask* nodep, AstNUser*) {
bool oldtog = m_inToggleOff;
{
m_inToggleOff = true;
nodep->iterateChildren(*this);
}
m_inToggleOff = oldtog;
}
virtual void visit(AstVar* nodep, AstNUser*) {
nodep->iterateChildren(*this);
if (m_modp && !m_inToggleOff
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageToggle()) {
const char* disablep = varIgnoreToggle(nodep);
if (disablep) {
UINFO(4, " Disable Toggle: "<<disablep<<" "<<nodep<<endl);
} else {
UINFO(4, " Toggle: "<<nodep<<endl);
// There's several overall ways to approach this
// Treat like tracing, where a end-of-timestamp action sees all changes
// Works ok, but would be quite slow as need to reform vectors before the calls
// Convert to "always @ (posedge signal[#]) coverinc"
// Would mark many signals as clocks, precluding many later optimizations
// Convert to "if (x & !lastx) CoverInc"
// OK, but we couldn't later detect them to schedule where the IFs get called
// Convert to "AstCoverInc(CoverInc...)"
// We'll do this, and make the if(...) coverinc later.
// Compute size of the problem
int dimensions = 0;
for (AstRange* arrayp=nodep->arraysp(); arrayp; arrayp = arrayp->nextp()->castRange()) {
dimensions++;
}
// Add signal to hold the old value
string newvarname = (string)"__Vtogcov__"+nodep->shortName();
AstVar* chgVarp = new AstVar (nodep->fileline(), AstVarType::MODULETEMP, newvarname, nodep);
m_modp->addStmtp(chgVarp);
// Create bucket for each dimension * bit.
// This is necessarily an O(n^2) expansion, which is why
// we limit coverage to signals with < 256 bits.
vector<int> selects_docs; selects_docs.resize(dimensions);
vector<int> selects_code; selects_code.resize(dimensions);
toggleVarRecurse(nodep, chgVarp, nodep->arraysp(),
0, selects_docs, selects_code );
}
}
}
void toggleVarRecurse(AstVar* nodep, AstVar* chgVarp, AstRange* arrayp,
int dimension, vector<int>& selects_docs, vector<int>& selects_code) {
if (arrayp) {
for (int index=arrayp->lsbConst(); index<=arrayp->msbConst()+1; index++) {
// Handle the next dimension, if any
selects_docs[dimension] = index;
selects_code[dimension] = index - arrayp->lsbConst();
toggleVarRecurse(nodep, chgVarp, arrayp->nextp()->castRange(),
dimension+1, selects_docs, selects_code);
}
} else { // No more arraying - just each bit in the width
if (nodep->rangep()) {
for (int bitindex_docs=nodep->lsb(); bitindex_docs<nodep->msb()+1; bitindex_docs++) {
toggleVarBottom(nodep, chgVarp,
dimension, selects_docs, selects_code,
true, bitindex_docs);
}
} else {
toggleVarBottom(nodep, chgVarp,
dimension, selects_docs, selects_code,
false, 0);
}
}
}
void toggleVarBottom(AstVar* nodep, AstVar* chgVarp,
int dimension, vector<int>& selects_docs, vector<int>& selects_code,
bool bitsel, int bitindex_docs) {
string comment = nodep->name();
AstNode* varRefp = new AstVarRef(nodep->fileline(), nodep, false);
AstNode* chgRefp = new AstVarRef(nodep->fileline(), chgVarp, true);
// Now determine the name of, and how to get to the bit of this slice
for (int dim=0; dim<dimension; dim++) {
// Comments are strings, not symbols, so we don't need __BRA__ __KET__
comment += "["+cvtToStr(selects_docs[dim])+"]";
varRefp = new AstArraySel(nodep->fileline(), varRefp, selects_code[dim]);
chgRefp = new AstArraySel(nodep->fileline(), chgRefp, selects_code[dim]);
}
if (bitsel) {
comment += "["+cvtToStr(bitindex_docs)+"]";
int bitindex_code = bitindex_docs - nodep->lsb();
varRefp = new AstSel(nodep->fileline(), varRefp, bitindex_code, 1);
chgRefp = new AstSel(nodep->fileline(), chgRefp, bitindex_code, 1);
}
AstCoverToggle* newp = new AstCoverToggle (nodep->fileline(),
newCoverInc(nodep->fileline(), "", "v_toggle", comment),
varRefp, chgRefp);
m_modp->addStmtp(newp);
}
// VISITORS - LINE COVERAGE
virtual void visit(AstIf* nodep, AstNUser*) {
UINFO(4," IF: "<<nodep<<endl);
if (m_checkBlock) {
nodep->ifsp()->iterateAndNext(*this);
if (m_checkBlock && v3Global.opt.coverageLine()) { // if a "if" branch didn't disable it
if (m_checkBlock
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageLine()) { // if a "if" branch didn't disable it
if (!nodep->backp()->castIf()
|| nodep->backp()->castIf()->elsesp()!=nodep) { // Ignore if else; did earlier
UINFO(4," COVER: "<<nodep<<endl);
nodep->addIfsp(newCoverInc(nodep->fileline(), "block", "if"));
nodep->addIfsp(newCoverInc(nodep->fileline(), "", "v_line", "if"));
}
}
// Don't do empty else's, only empty if/case's
if (nodep->elsesp()) {
m_checkBlock = true;
nodep->elsesp()->iterateAndNext(*this);
if (m_checkBlock && v3Global.opt.coverageLine()) { // if a "else" branch didn't disable it
if (m_checkBlock
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageLine()) { // if a "else" branch didn't disable it
UINFO(4," COVER: "<<nodep<<endl);
if (nodep->elsesp()->castIf()) {
nodep->addElsesp(newCoverInc(nodep->elsesp()->fileline(), "block", "elsif"));
nodep->addElsesp(newCoverInc(nodep->elsesp()->fileline(), "", "v_line", "elsif"));
} else {
nodep->addElsesp(newCoverInc(nodep->elsesp()->fileline(), "block", "else"));
nodep->addElsesp(newCoverInc(nodep->elsesp()->fileline(), "", "v_line", "else"));
}
}
}
@@ -107,22 +245,25 @@ private:
}
virtual void visit(AstCaseItem* nodep, AstNUser*) {
UINFO(4," CASEI: "<<nodep<<endl);
if (m_checkBlock && v3Global.opt.coverageLine()) {
if (m_checkBlock
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageLine()) {
nodep->bodysp()->iterateAndNext(*this);
if (m_checkBlock) { // if the case body didn't disable it
UINFO(4," COVER: "<<nodep<<endl);
nodep->addBodysp(newCoverInc(nodep->fileline(), "block", "case"));
nodep->addBodysp(newCoverInc(nodep->fileline(), "", "v_line", "case"));
}
m_checkBlock = true; // Reset as a child may have cleared it
}
}
virtual void visit(AstPslCover* nodep, AstNUser*) {
UINFO(4," PSLCOVER: "<<nodep<<endl);
m_checkBlock = true; // Always do cover blocks, even if there's a $stop
nodep->iterateChildren(*this);
if (!nodep->coverincp()) {
// Note the name may be overridden by V3Assert processing
nodep->coverincp(newCoverInc(nodep->fileline(), "psl_cover", "cover"));
nodep->coverincp(newCoverInc(nodep->fileline(), m_beginHier, "v_user", "cover"));
}
m_checkBlock = true; // Reset as a child may have cleared it
}
virtual void visit(AstStop* nodep, AstNUser*) {
UINFO(4," STOP: "<<nodep<<endl);
@@ -134,9 +275,30 @@ private:
UINFO(4," OFF: "<<nodep<<endl);
m_checkBlock = false;
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
} else {
if (m_checkBlock) nodep->iterateChildren(*this);
}
if (m_checkBlock) nodep->iterateChildren(*this);
}
virtual void visit(AstBegin* nodep, AstNUser*) {
// Record the hiearchy of any named begins, so we can apply to user
// coverage points. This is because there may be cov points inside
// generate blocks; each point should get separate consideration.
// (Currently ignored for line coverage, since any generate iteration
// covers the code in that line.)
string oldHier = m_beginHier;
bool oldtog = m_inToggleOff;
{
m_inToggleOff = true;
if (nodep->name()!="") {
m_beginHier = m_beginHier + (m_beginHier!=""?".":"") + nodep->name();
}
nodep->iterateChildren(*this);
}
m_beginHier = oldHier;
m_inToggleOff = oldtog;
}
// VISITORS - BOTH
virtual void visit(AstNode* nodep, AstNUser*) {
// Default: Just iterate
if (m_checkBlock) {
@@ -150,6 +312,8 @@ public:
CoverageVisitor(AstNetlist* rootp) {
// Operate on all modules
m_checkBlock = true;
m_beginHier = "";
m_inToggleOff = false;
rootp->iterateChildren(*this);
}
virtual ~CoverageVisitor() {}
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+138
View File
@@ -0,0 +1,138 @@
//*************************************************************************
// DESCRIPTION: Verilator: Netlist (top level) functions
//
// Code available from: http://www.veripool.org/verilator
//
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
//
//*************************************************************************
//
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
// Verilator is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//*************************************************************************
// COVERAGEJOIN TRANSFORMATIONS:
// If two COVERTOGGLEs have same VARSCOPE, combine them
//*************************************************************************
#include "config_build.h"
#include "verilatedos.h"
#include <cstdio>
#include <cstdarg>
#include <unistd.h>
#include <vector>
#include "V3Global.h"
#include "V3CoverageJoin.h"
#include "V3Hashed.h"
#include "V3Stats.h"
//######################################################################
// CoverageJoin state, as a visitor of each AstNode
class CoverageJoinVisitor : public AstNVisitor {
private:
// NODE STATE
// V3Hashed
// AstCoverToggle->VarRef::user4() // V3Hashed calculation
//AstUser4InUse In V3Hashed
// TYPES
typedef vector<AstCoverToggle*> ToggleList;
// STATE
ToggleList m_toggleps; // List of of all AstCoverToggle's
V3Double0 m_statToggleJoins; // Statistic tracking
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
void detectDuplicates() {
UINFO(9,"Finding duplicates\n");
// Note uses user4
V3Hashed hashed; // Duplicate code detection
// Hash all of the original signals we toggle cover
for (ToggleList::iterator it = m_toggleps.begin(); it != m_toggleps.end(); ++it) {
AstCoverToggle* nodep = *it;
hashed.hashAndInsert(nodep->origp());
}
// Find if there are any duplicates
for (ToggleList::iterator it = m_toggleps.begin(); it != m_toggleps.end(); ++it) {
AstCoverToggle* nodep = *it;
if (nodep->backp()) { // nodep->backp() is null if we already detected it's a duplicate and unlinked it
// Want to choose a base node, and keep finding duplicates that are identical
// This prevents making chains where a->b, then c->d, then b->c, as we'll find a->b, a->c, a->d directly.
while (1) {
V3Hashed::iterator dupit = hashed.findDuplicate(nodep->origp());
if (dupit == hashed.end()) break;
//
AstNode* duporigp = hashed.iteratorNodep(dupit);
// Note hashed will point to the original variable (what's duplicated), not the covertoggle,
// but we need to get back to the covertoggle which is immediately above, so:
AstCoverToggle* removep = duporigp->backp()->castCoverToggle();
if (!removep) nodep->v3fatalSrc("CoverageJoin duplicate of wrong type");
UINFO(8," Orig "<<nodep<<" -->> "<<nodep->incp()->declp()<<endl);
UINFO(8," dup "<<removep<<" -->> "<<removep->incp()->declp()<<endl);
// The CoverDecl the duplicate pointed to now needs to point to the original's data
// IE the duplicate will get the coverage number from the non-duplicate
AstCoverDecl* datadeclp = nodep->incp()->declp()->dataDeclThisp();
removep->incp()->declp()->dataDeclp (datadeclp);
UINFO(8," new "<<removep->incp()->declp()<<endl);
// Mark the found node as a duplicate of the first node
// (Not vice-versa as we have the iterator for the found node)
removep->unlinkFrBack(); pushDeletep(removep); removep=NULL;
// Remove node from comparison so don't hit it again
hashed.erase(dupit);
m_statToggleJoins++;
}
}
}
}
// VISITORS
virtual void visit(AstNetlist* nodep, AstNUser*) {
// Find all Coverage's
nodep->iterateChildren(*this);
// Simplify
detectDuplicates();
}
virtual void visit(AstCoverToggle* nodep, AstNUser*) {
m_toggleps.push_back(nodep);
nodep->iterateChildren(*this);
}
//--------------------
virtual void visit(AstNodeMath* nodep, AstNUser*) {} // Accelerate
virtual void visit(AstNode* nodep, AstNUser*) {
nodep->iterateChildren(*this);
}
public:
// CONSTUCTORS
CoverageJoinVisitor(AstNetlist* nodep) {
nodep->accept(*this);
}
virtual ~CoverageJoinVisitor() {
V3Stats::addStat("Coverage, Toggle points joined", m_statToggleJoins);
}
};
//######################################################################
// Coverage class functions
void V3CoverageJoin::coverageJoin(AstNetlist* rootp) {
UINFO(2,__FUNCTION__<<": "<<endl);
CoverageJoinVisitor visitor (rootp);
}
+37
View File
@@ -0,0 +1,37 @@
// -*- C++ -*-
//*************************************************************************
// DESCRIPTION: Verilator: Coverage modules/signals together
//
// Code available from: http://www.veripool.org/verilator
//
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
//
//*************************************************************************
//
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
// Verilator is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//*************************************************************************
#ifndef _V3COVERAGEJOIN_H_
#define _V3COVERAGEJOIN_H_ 1
#include "config_build.h"
#include "verilatedos.h"
#include "V3Error.h"
#include "V3Ast.h"
//============================================================================
class V3CoverageJoin {
public:
// CREATORS
static void coverageJoin(AstNetlist* rootp);
};
#endif // Guard
+15 -11
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -45,7 +45,7 @@ private:
// VISITORS
virtual void visit(AstCell* nodep, AstNUser*) {
nodep->iterateChildren(*this);
nodep->modp()->user(nodep->modp()->user() - 1);
nodep->modp()->user1(nodep->modp()->user1() - 1);
}
//-----
virtual void visit(AstNodeMath* nodep, AstNUser*) {} // Accelerate
@@ -70,6 +70,7 @@ private:
// AstModule::user() -> int. Count of number of cells referencing this module.
// AstVar::user() -> int. Count of number of references
// AstVarScope::user() -> int. Count of number of references
AstUser1InUse m_inuser1;
// TYPES
typedef multimap<AstVarScope*,AstNodeAssign*> AssignMap;
@@ -80,23 +81,27 @@ private:
AssignMap m_assignMap; // List of all simple assignments for each variable
bool m_elimUserVars; // Allow removal of user's vars
bool m_sideEffect; // Side effects discovered in assign RHS
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
// VISITORS
virtual void visit(AstCell* nodep, AstNUser*) {
nodep->iterateChildren(*this);
nodep->modp()->user(nodep->modp()->user() + 1);
nodep->modp()->user1(nodep->modp()->user1() + 1);
}
virtual void visit(AstNodeVarRef* nodep, AstNUser*) {
nodep->iterateChildren(*this);
if (nodep->varScopep()) {
nodep->varScopep()->user(nodep->varScopep()->user() + 1);
nodep->varScopep()->varp()->user(nodep->varScopep()->varp()->user() + 1);
nodep->varScopep()->user1(nodep->varScopep()->user1() + 1);
nodep->varScopep()->varp()->user1(nodep->varScopep()->varp()->user1() + 1);
}
if (nodep->varp()) {
nodep->varp()->user(nodep->varp()->user() + 1);
nodep->varp()->user1(nodep->varp()->user1() + 1);
}
}
virtual void visit(AstVarScope* nodep, AstNUser*) {
@@ -142,7 +147,7 @@ private:
AstModule* nextmodp;
for (AstModule* modp = v3Global.rootp()->modulesp(); modp; modp=nextmodp) {
nextmodp = modp->nextp()->castModule();
if (modp->level()>2 && modp->user()==0) {
if (modp->level()>2 && modp->user1()==0) {
// > 2 because L1 is the wrapper, L2 is the top user module
UINFO(4," Dead module "<<modp<<endl);
// And its children may now be killable too; correct counts
@@ -163,7 +168,7 @@ private:
// Delete any unused varscopes
for (vector<AstVarScope*>::iterator it = m_vscsp.begin(); it!=m_vscsp.end(); ++it) {
AstVarScope* vscp = *it;
if (vscp->user() == 0 && canElim(vscp->varp())) {
if (vscp->user1() == 0 && canElim(vscp->varp())) {
UINFO(4," Dead "<<vscp<<endl);
pair <AssignMap::iterator,AssignMap::iterator> eqrange = m_assignMap.equal_range(vscp);
for (AssignMap::iterator it = eqrange.first; it != eqrange.second; ++it) {
@@ -175,7 +180,7 @@ private:
}
}
for (vector<AstVar*>::iterator it = m_varsp.begin(); it!=m_varsp.end(); ++it) {
if ((*it)->user() == 0 && canElim((*it))) {
if ((*it)->user1() == 0 && canElim((*it))) {
UINFO(4," Dead "<<(*it)<<endl);
(*it)->unlinkFrBack()->deleteTree(); (*it)=NULL;
}
@@ -188,7 +193,6 @@ public:
m_elimUserVars = elimUserVars;
m_sideEffect = false;
// Operate on whole netlist
AstNode::userClearTree(); // userp() used on entire tree
nodep->accept(*this);
deadCheckVar();
// Modules after vars, because might be vars we delete inside a mod we delete
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+33 -28
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -72,17 +72,21 @@ class DelayedVisitor : public AstNVisitor {
private:
// NODE STATE
// Cleared each module:
// AstVarScope::userp() -> AstVarScope*. Points to temp var created.
// AstVarScope::user1p() -> AstVarScope*. Points to temp var created.
// AstVarScope::user2p() -> AstActive*. Points to activity block of signal
// AstVarScope::user4p() -> AstAlwaysPost*. Post block for this variable
// AstVar::user1() -> VarUsage. Tracks delayed vs non-delayed usage
// AstVar::user2() -> bool. Set true if already made warning
// AstVar::user3() -> VarUsage. Tracks delayed vs non-delayed usage
// AstVar::user4() -> int. Vector number, for assignment creation
// AstVarRef::user2() -> bool. Set true if already processed
// AstAlwaysPost::user4() -> AstIf*. Last IF (__Vdlyvset__) created under this AlwaysPost
// Cleared each scope:
// AstAssignDly::user5() -> AstVarScope*. __Vdlyvset__ created for this assign
// AstAlwaysPost::user5() -> AstVarScope*. __Vdlyvset__ last referenced in IF
// AstAssignDly::user3() -> AstVarScope*. __Vdlyvset__ created for this assign
// AstAlwaysPost::user3() -> AstVarScope*. __Vdlyvset__ last referenced in IF
AstUser1InUse m_inuser1;
AstUser2InUse m_inuser2;
AstUser3InUse m_inuser3;
AstUser4InUse m_inuser4;
enum VarUsage { VU_NONE=0, VU_DLY=1, VU_NONDLY=2 };
@@ -97,13 +101,18 @@ private:
VarMap m_modVarMap; // Table of new var names created under module
V3Double0 m_statSharedSet;// Statistic tracking
//static int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
void markVarUsage(AstVar* nodep, uint32_t flags) {
//UINFO(4," MVU "<<flags<<" "<<nodep<<endl);
nodep->user3( nodep->user3() | flags );
if ((nodep->user3() & VU_DLY) && (nodep->user3() & VU_NONDLY)) {
nodep->user1( nodep->user1() | flags );
if ((nodep->user1() & VU_DLY) && (nodep->user1() & VU_NONDLY)) {
nodep->v3warn(BLKANDNBLK,"Unsupported: Blocked and non-blocking assignments to same variable: "<<nodep->prettyName());
}
}
@@ -179,7 +188,7 @@ private:
dimreadps.push_front(dimp);
} else {
string bitvarname = (string("__Vdlyvdim")+cvtToStr(dimension)
+"__"+oldvarp->shortName()+"__"+cvtToStr(modVecNum));
+"__"+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
AstVarScope* bitvscp = createVarSc(varrefp->varScopep(), bitvarname, dimp->width());
AstAssign* bitassignp
= new AstAssign (nodep->fileline(),
@@ -197,7 +206,7 @@ private:
if (bitselp->fromp()->castConst()) {// vlsb = constant, can just push constant into where we use it
bitreadp = lsbvaluep;
} else {
string bitvarname = (string("__Vdlyvlsb__")+oldvarp->shortName()+"__"+cvtToStr(modVecNum));
string bitvarname = (string("__Vdlyvlsb__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
AstVarScope* bitvscp = createVarSc(varrefp->varScopep(), bitvarname, lsbvaluep->width());
AstAssign* bitassignp = new AstAssign (nodep->fileline(),
new AstVarRef(nodep->fileline(), bitvscp, true),
@@ -212,7 +221,7 @@ private:
if (nodep->rhsp()->castConst()) { // vval = constant, can just push constant into where we use it
valreadp = nodep->rhsp()->unlinkFrBack();
} else {
string valvarname = (string("__Vdlyvval__")+oldvarp->shortName()+"__"+cvtToStr(modVecNum));
string valvarname = (string("__Vdlyvval__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
AstVarScope* valvscp = createVarSc(varrefp->varScopep(), valvarname, nodep->rhsp()->width());
newlhsp = new AstVarRef(nodep->fileline(), valvscp, true);
valreadp = new AstVarRef(nodep->fileline(), valvscp, false);
@@ -222,16 +231,16 @@ private:
bool sharedVset = false;
AstVarScope* setvscp;
if (nodep->user5p()) {
if (nodep->user3p()) {
// Simplistic optimization. If the previous statement in same scope was also a =>,
// then we told this nodep->user5 we can use its Vdlyvset rather than making a new one.
// then we told this nodep->user3 we can use its Vdlyvset rather than making a new one.
// This is good for code like:
// for (i=0; i<5; i++) vector[i] <= something;
sharedVset = true;
setvscp = nodep->user5p()->castNode()->castVarScope();
setvscp = nodep->user3p()->castNode()->castVarScope();
m_statSharedSet++;
} else { // Create new one
string setvarname = (string("__Vdlyvset__")+oldvarp->shortName()+"__"+cvtToStr(modVecNum));
string setvarname = (string("__Vdlyvset__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
setvscp = createVarSc(varrefp->varScopep(), setvarname, 1);
AstAssignPre* setinitp
= new AstAssignPre (nodep->fileline(),
@@ -246,7 +255,7 @@ private:
nodep->addNextHere(setassignp);
}
if (m_nextDlyp) { // Tell next assigndly it can share the variable
m_nextDlyp->user5p(setvscp);
m_nextDlyp->user3p(setvscp);
}
//
// Create ALWAYSPOST for delayed variable
@@ -273,7 +282,7 @@ private:
varrefp->varScopep()->user4p(finalp);
}
AstIf* postLogicp;
if (finalp->user5p()->castNode() == setvscp) {
if (finalp->user3p()->castNode() == setvscp) {
// Optimize as above; if sharing Vdlyvset *ON SAME VARIABLE*,
// we can share the IF statement too
postLogicp = finalp->user4p()->castNode()->castIf();
@@ -285,7 +294,7 @@ private:
NULL);
UINFO(9," Created "<<postLogicp<<endl);
finalp->addBodysp(postLogicp);
finalp->user5p(setvscp); // Remember IF's vset variable
finalp->user3p(setvscp); // Remember IF's vset variable
finalp->user4p(postLogicp); // and the associated IF, as we may be able to reuse it
}
postLogicp->addIfsp(new AstAssign(nodep->fileline(), selectsp, valreadp));
@@ -297,15 +306,11 @@ private:
virtual void visit(AstNetlist* nodep, AstNUser*) {
//VV***** We reset all userp() on the netlist
m_modVarMap.clear();
AstNode::userClearTree();
AstNode::user2ClearTree();
AstNode::user3ClearTree();
AstNode::user4ClearTree();
nodep->iterateChildren(*this);
}
virtual void visit(AstScope* nodep, AstNUser*) {
UINFO(4," MOD "<<nodep<<endl);
AstNode::user5ClearTree();
AstNode::user3ClearTree();
nodep->iterateChildren(*this);
}
virtual void visit(AstCFunc* nodep, AstNUser*) {
@@ -354,7 +359,7 @@ private:
if (!m_activep->hasClocked()) nodep->v3error("Internal: Blocking <= assignment in non-clocked block, should have converted in V3Active");
AstVarScope* oldvscp = nodep->varScopep();
if (!oldvscp) nodep->v3fatalSrc("Var didn't get varscoped in V3Scope.cpp\n");
AstVarScope* dlyvscp = oldvscp->userp()->castNode()->castVarScope();
AstVarScope* dlyvscp = oldvscp->user1p()->castNode()->castVarScope();
if (dlyvscp) { // Multiple use of delayed variable
AstActive* oldactivep = dlyvscp->user2p()->castNode()->castActive();
if (!oldactivep) nodep->v3fatalSrc("<= old dly assignment not put under sensitivity block");
@@ -370,8 +375,8 @@ private:
UINFO(4," Act: "<<m_activep<<endl);
UINFO(4," Act: "<<oldactivep<<endl);
// Make a new sensitivity list, which is the combination of both blocks
AstSenItem* sena = m_activep->sensesp()->sensesp()->cloneTree(true)->castSenItem();
AstSenItem* senb = oldactivep->sensesp()->sensesp()->cloneTree(true)->castSenItem();
AstNodeSenItem* sena = m_activep->sensesp()->sensesp()->cloneTree(true);
AstNodeSenItem* senb = oldactivep->sensesp()->sensesp()->cloneTree(true);
AstSenTree* treep = new AstSenTree(m_activep->fileline(), sena);
if (senb) treep->addSensesp(senb);
if (AstSenTree* storep = oldactivep->sensesStorep()) {
@@ -394,7 +399,7 @@ private:
new AstVarRef(nodep->fileline(), oldvscp, true),
new AstVarRef(nodep->fileline(), dlyvscp, false));
postp->lhsp()->user2(true); // Don't detect this assignment
oldvscp->userp(dlyvscp); // So we can find it later
oldvscp->user1p(dlyvscp); // So we can find it later
// Make new ACTIVE with identical sensitivity tree
AstActive* newactp = new AstActive (nodep->fileline(), "sequentdly",
m_activep->sensesp());
@@ -417,7 +422,7 @@ private:
}
virtual void visit(AstNodeFor* nodep, AstNUser*) {
nodep->v3fatalSrc("For statements should have been converted to while statements in V3Unroll\n");
nodep->v3fatalSrc("For statements should have been converted to while statements in V3Begin\n");
}
virtual void visit(AstWhile* nodep, AstNUser*) {
bool oldloop = m_inLoop;
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+9 -10
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -51,14 +51,18 @@ private:
int m_depth; // How deep in an expression
int m_maxdepth; // Maximum depth in an expression
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
void createDeepTemp(AstNode* nodep) {
UINFO(6," Deep "<<nodep<<endl);
//if (debug()>=9) nodep->dumpTree(cout,"deep:");
string newvarname = ((string)"__Vdeeptemp__"+cvtToStr(m_modp->varNumGetInc()));
string newvarname = ((string)"__Vdeeptemp"+cvtToStr(m_modp->varNumGetInc()));
AstVar* varp = new AstVar (nodep->fileline(), AstVarType::STMTTEMP, newvarname,
// Width, not widthMin, as we may be in middle of BITSEL expression which
// though it's one bit wide, needs the mask in the upper bits.
@@ -85,6 +89,7 @@ private:
m_modp = nodep;
m_funcp = NULL;
nodep->iterateChildren(*this);
m_modp = NULL;
}
virtual void visit(AstCFunc* nodep, AstNUser*) {
m_funcp = nodep;
@@ -132,11 +137,6 @@ private:
m_funcp->isStatic(false);
}
}
virtual void visit(AstCoverInc* nodep, AstNUser*) {
// OPTIMIZE: For now this needs this->__Vcoverage, but could be globalized
needNonStaticFunc(nodep);
visitStmt(nodep);
}
virtual void visit(AstUCFunc* nodep, AstNUser*) {
needNonStaticFunc(nodep);
nodep->iterateChildren(*this);
@@ -162,7 +162,6 @@ public:
m_depth=0;
m_maxdepth=0;
//
AstNode::userClearTree(); // userp() used on entire tree
nodep->accept(*this);
}
virtual ~DepthVisitor() {}
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+8 -3
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -48,9 +48,13 @@ private:
int m_depth; // How deep in an expression
int m_deepNum; // How many functions made
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
AstCFunc* createDeepFunc(AstNode* nodep) {
AstNRelinker relinkHandle;
nodep->unlinkFrBack(&relinkHandle);
@@ -77,6 +81,7 @@ private:
m_modp = nodep;
m_deepNum = 0;
nodep->iterateChildren(*this);
m_modp = NULL;
}
virtual void visit(AstCFunc* nodep, AstNUser*) {
// We recurse into this.
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+12 -6
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -45,6 +45,7 @@ private:
// NODE STATE
// Cleared entire netlist
// AstCFunc::user() // bool. Indicates processing completed
AstUser1InUse m_inuser1;
// TYPES
typedef multimap<string,AstCFunc*> FuncMmap;
@@ -54,9 +55,14 @@ private:
AstScope* m_scopep; // Current scope
bool m_needThis; // Add thisp to function
FuncMmap m_modFuncs; // Name of public functions added
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
string descopedName(AstScope* scopep, bool& hierThisr, AstVar* varp=NULL) {
UASSERT(scopep, "Var/Func not scoped\n");
hierThisr = true;
@@ -106,7 +112,7 @@ private:
if (moreOfSame1) {
// Multiple functions under this name, need a wrapper function
UINFO(6," Wrapping "<<name<<" multifuncs\n");
AstCFunc* newfuncp = topFuncp->cloneTree(false)->castCFunc();
AstCFunc* newfuncp = topFuncp->cloneTree(false);
if (newfuncp->initsp()) newfuncp->initsp()->unlinkFrBackWithNext()->deleteTree();
if (newfuncp->stmtsp()) newfuncp->stmtsp()->unlinkFrBackWithNext()->deleteTree();
if (newfuncp->finalsp()) newfuncp->finalsp()->unlinkFrBackWithNext()->deleteTree();
@@ -177,6 +183,7 @@ private:
m_modFuncs.clear();
nodep->iterateChildren(*this);
makePublicFuncWrappers();
m_modp = NULL;
}
virtual void visit(AstScope* nodep, AstNUser*) {
m_scopep = nodep;
@@ -209,10 +216,10 @@ private:
// nodep->funcp()->scopep(NULL);
}
virtual void visit(AstCFunc* nodep, AstNUser*) {
if (!nodep->user()) {
if (!nodep->user1()) {
m_needThis = false;
nodep->iterateChildren(*this);
nodep->user(true);
nodep->user1(true);
if (m_needThis) {
nodep->v3fatalSrc("old code");
// Really we should have more node types for backend optimization of this stuff
@@ -244,7 +251,6 @@ public:
m_modp = NULL;
m_scopep = NULL;
m_needThis = false;
AstNode::userClearTree();
nodep->accept(*this);
}
virtual ~DescopeVisitor() {}
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+120 -122
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -34,36 +34,6 @@
#define VL_VALUE_STRING_MAX_WIDTH 1024 // We use a static char array in VL_VALUE_STRING
//######################################################################
// Coverage ID tracking
class EmitCoverIds {
// TYPES
typedef map<AstCoverDecl*,int> CoverIdMap;
// MEMBERS
CoverIdMap m_coverIds; // Remapping of coverage IDs to per-module value
int m_coverIdsSize; // Size of m_coverIds (to avoid O(n^2) insert)
// METHODS
public:
void clear() {
m_coverIds.clear();
m_coverIdsSize = 0;
}
int size() const { return m_coverIdsSize; }
int remap(AstCoverDecl* declp) {
// Make cover ID for this point, unique on this module
CoverIdMap::iterator it = m_coverIds.find(declp);
if (it == m_coverIds.end()) {
m_coverIds.insert(make_pair(declp,m_coverIdsSize++)); // Remapping of coverage IDs to per-module value
return m_coverIdsSize-1;
} else {
return it->second;
}
}
EmitCoverIds() : m_coverIdsSize(0) {}
~EmitCoverIds() {}
};
//######################################################################
// Emit statements and math operators
@@ -72,10 +42,24 @@ private:
bool m_suppressSemi;
AstVarRef* m_wideTempRefp; // Variable that _WW macros should be setting
vector<AstVar*> m_ctorVarsVec; // All variables in constructor order
int m_splitSize; // # of cfunc nodes placed into output file
int m_splitFilenum; // File number being created, 0 = primary
public:
EmitCoverIds m_coverIds; // Coverage ID remapping
public:
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
// ACCESSORS
int splitFilenum() { return m_splitFilenum; }
int splitFilenumInc() { m_splitSize = 0; return ++m_splitFilenum; }
int splitSize() { return m_splitSize; }
void splitSizeInc(AstNode* nodep) { m_splitSize += EmitCBaseCounterVisitor(nodep).count(); }
bool splitNeeded() { return (splitSize() && v3Global.opt.outputSplit() > 1
&& v3Global.opt.outputSplit() < splitSize()); }
// METHODS
void displayNode(AstNode* nodep, const string& vformat, AstNode* exprsp, bool isScan);
@@ -91,6 +75,9 @@ public:
void emitIQW(AstNode* nodep) {
puts (nodep->isWide()?"W":(nodep->isQuad()?"Q":"I"));
}
void emitScIQW(AstVar* nodep) {
puts (nodep->isScBv()?"SW":(nodep->isScQuad()?"SQ":"SI"));
}
void emitOpName(AstNode* nodep, const string& format,
AstNode* lhsp, AstNode* rhsp, AstNode* thsp);
@@ -146,8 +133,7 @@ public:
} else if (nodep->lhsp()->castVarRef()
&& nodep->lhsp()->castVarRef()->varp()->isSc()) {
putbs("VL_ASSIGN_"); // Set a systemC variable
if (nodep->lhsp()->castVarRef()->varp()->isScQuad()) puts("SQ");
else puts("S");
emitScIQW(nodep->lhsp()->castVarRef()->varp());
emitIQW(nodep);
puts("(");
puts(cvtToStr(nodep->widthMin())+",");
@@ -156,8 +142,8 @@ public:
&& nodep->rhsp()->castVarRef()->varp()->isSc()) {
putbs("VL_ASSIGN_"); // Get a systemC variable
emitIQW(nodep);
if (nodep->rhsp()->castVarRef()->varp()->isScQuad()) puts("SQ(");
else puts("S(");
emitScIQW(nodep->rhsp()->castVarRef()->varp());
puts("(");
puts(cvtToStr(nodep->widthMin())+",");
nodep->lhsp()->iterateAndNext(*this); puts(", ");
} else if (nodep->isWide()
@@ -212,19 +198,26 @@ public:
}
virtual void visit(AstCoverDecl* nodep, AstNUser*) {
puts("__vlCoverInsert("); // As Declared in emitCoverageDecl
puts("&__Vcoverage[");
puts(cvtToStr(m_coverIds.remap(nodep))); puts("]");
puts(", \""); puts(nodep->fileline()->filebasename()); puts("\"");
puts("&(vlSymsp->__Vcoverage[");
puts(cvtToStr(nodep->dataDeclThisp()->binNum())); puts("])");
// If this isn't the first instantiation of this module under this
// design, don't really count the bucket, and rely on SystemPerl to
// aggregate counts. This is because Verilator combines all
// hiearchies itself, and if SystemPerl also did it, you'd end up
// with (number-of-instant) times too many counts in this bin.
puts(", first"); // Enable, passed from __Vconfigure parameter
puts(", \""); puts(nodep->fileline()->filename()); puts("\"");
puts(", "); puts(cvtToStr(nodep->fileline()->lineno()));
puts(", "); puts(cvtToStr(nodep->column()));
puts(", \""); puts(nodep->hier()); puts("\"");
puts(", \""); puts(nodep->typeText()); puts("\"");
puts(", \""); puts((nodep->hier()!=""?".":"")+nodep->hier()); puts("\"");
puts(", \""); puts(nodep->page()); puts("\"");
puts(", \""); puts(nodep->comment()); puts("\"");
puts(");\n");
}
virtual void visit(AstCoverInc* nodep, AstNUser*) {
puts("++this->__Vcoverage[");
puts(cvtToStr(m_coverIds.remap(nodep->declp()))); puts("];\n");
puts("++(vlSymsp->__Vcoverage[");
puts(cvtToStr(nodep->declp()->dataDeclThisp()->binNum()));
puts("]);\n");
}
virtual void visit(AstCReturn* nodep, AstNUser*) {
puts("return (");
@@ -242,6 +235,10 @@ public:
virtual void visit(AstSScanF* nodep, AstNUser*) {
displayNode(nodep, nodep->text(), nodep->exprsp(), true);
}
virtual void visit(AstFGetS* nodep, AstNUser*) {
checkMaxWords(nodep);
emitOpName(nodep, nodep->emitC(), nodep->lhsp(), nodep->rhsp(), NULL);
}
void checkMaxWords(AstNode* nodep) {
if (nodep->widthWords() > VL_TO_STRING_MAX_WORDS) {
@@ -538,6 +535,8 @@ public:
EmitCStmts() {
m_suppressSemi = false;
m_wideTempRefp = NULL;
m_splitSize = 0;
m_splitFilenum = 0;
}
virtual ~EmitCStmts() {}
};
@@ -551,8 +550,6 @@ class EmitCImp : EmitCStmts {
vector<AstChangeDet*> m_blkChangeDetVec; // All encountered changes in block
bool m_slow; // Creating __Slow file
bool m_fast; // Creating non __Slow file (or both)
int m_splitSize; // # of cfunc nodes placed into output file
int m_splitFilenum; // File number being created, 0 = primary
//---------------------------------------
// METHODS
@@ -624,16 +621,14 @@ class EmitCImp : EmitCStmts {
//---------------------------------------
// VISITORS
virtual void visit(AstCFunc* nodep, AstNUser*) {
if (nodep->funcType() == AstCFuncType::TRACE_INIT
|| nodep->funcType() == AstCFuncType::TRACE_FULL
|| nodep->funcType() == AstCFuncType::TRACE_CHANGE) {
return; // Handled specially
if (nodep->funcType().isTrace()) {
return; // TRACE_* handled specially
}
if (!(nodep->slow() ? m_slow : m_fast)) return;
m_blkChangeDetVec.clear();
m_splitSize += EmitCBaseCounterVisitor(nodep).count();
splitSizeInc(nodep);
puts("\n");
puts(nodep->rtnTypeVoid()); puts(" ");
@@ -707,7 +702,7 @@ class EmitCImp : EmitCStmts {
varname = ": "+nodep->lhsp()->castVarRef()->varp()->prettyName();
}
puts(")) cout<<\"\tCHANGE: "+nodep->fileline()->ascii()
+varname+"\"<<endl; );");
+varname+"\"<<endl; );\n");
}
}
}
@@ -735,7 +730,6 @@ class EmitCImp : EmitCStmts {
void emitIntFuncDecls(AstModule* modp);
// High level
void emitImp(AstModule* modp);
void emitImpBottom(AstModule* modp);
void emitStaticDecl(AstModule* modp);
void emitWrapEval(AstModule* modp);
void emitInt(AstModule* modp);
@@ -744,15 +738,12 @@ class EmitCImp : EmitCStmts {
public:
EmitCImp() {
m_modp = NULL;
m_splitSize = 0;
m_splitFilenum = 0;
}
virtual ~EmitCImp() {}
void main(AstModule* modp, bool slow, bool fast);
void mainDoFunc(AstCFunc* nodep) {
nodep->accept(*this);
}
int splitSize() { return m_splitSize; }
};
//######################################################################
@@ -1213,19 +1204,11 @@ void EmitCImp::emitVarResets(AstModule* modp) {
}
void EmitCImp::emitCoverageDecl(AstModule* modp) {
m_coverIds.clear();
for (AstNode* nodep=modp->stmtsp(); nodep; nodep = nodep->nextp()) {
if (AstCoverDecl* declp = nodep->castCoverDecl()) {
m_coverIds.remap(declp);
}
}
if (m_coverIds.size()) {
if (v3Global.opt.coverage()) {
ofp()->putsPrivate(true);
puts("// Coverage\n");
puts("SpZeroed<uint32_t>\t__Vcoverage["); puts(cvtToStr(m_coverIds.size())); puts("];\n");
ofp()->putAlign(V3OutFile::AL_AUTO, sizeof(uint32_t)*m_coverIds.size());
puts("void __vlCoverInsert(SpZeroed<uint32_t>* countp, const char* filename, int lineno, int column,\n");
puts( "const char* hier, const char* type, const char* comment);\n");
puts("void __vlCoverInsert(uint32_t* countp, bool enable, const char* filenamep, int lineno, int column,\n");
puts( "const char* hierp, const char* pagep, const char* commentp);\n");
}
}
@@ -1250,8 +1233,9 @@ void EmitCImp::emitCtorImp(AstModule* modp) {
}
void EmitCImp::emitConfigureImp(AstModule* modp) {
puts("\nvoid "+modClassName(modp)+"::__Vconfigure("+symClassName()+"* symsp) {\n");
puts( "__VlSymsp = symsp;\n"); // First, as later stuff needs it.
puts("\nvoid "+modClassName(modp)+"::__Vconfigure("+symClassName()+"* vlSymsp, bool first) {\n");
puts( "if (0 && first) {} // Prevent unused\n");
puts( "this->__VlSymsp = vlSymsp;\n"); // First, as later stuff needs it.
bool first=true;
for (AstNode* nodep=modp->stmtsp(); nodep; nodep = nodep->nextp()) {
if (nodep->castCoverDecl()) {
@@ -1266,20 +1250,25 @@ void EmitCImp::emitConfigureImp(AstModule* modp) {
}
void EmitCImp::emitCoverageImp(AstModule* modp) {
if (m_coverIds.size()) {
if (v3Global.opt.coverage() ) {
puts("\n// Coverage\n");
// Rather than putting out SP_COVER_INSERT calls directly, we do it via this function
// This gets around gcc slowness constructing all of the template arguments
puts("void "+modClassName(m_modp)+"::__vlCoverInsert(SpZeroed<uint32_t>* countp, const char* filename, int lineno, int column,\n");
puts( "const char* hier, const char* type, const char* comment) {\n");
// SystemPerl 1.301 is much faster, but it's nice to remain back
// compatible, and have a common wrapper.
puts("void "+modClassName(m_modp)+"::__vlCoverInsert(uint32_t* countp, bool enable, const char* filenamep, int lineno, int column,\n");
puts( "const char* hierp, const char* pagep, const char* commentp) {\n");
puts( "static uint32_t fake_zero_count = 0;\n");
puts( "if (!enable) countp = &fake_zero_count;\n"); // Used for second++ instantiation of identical bin
puts( "*countp = 0;\n");
puts( "SP_COVER_INSERT(countp,");
puts( " \"filename\",filename,");
puts( " \"filename\",filenamep,");
puts( " \"lineno\",lineno,");
puts( " \"column\",column,\n");
//puts( "\"hier\",string(__VlSymsp->name())+hier,"); // Need to move hier into scopes and back out if do this
puts( "\"hier\",string(name())+hier,");
puts( " \"type\",type,");
puts( " \"comment\",comment);\n");
//puts( "\"hier\",string(__VlSymsp->name())+hierp,"); // Need to move hier into scopes and back out if do this
puts( "\"hier\",string(name())+hierp,");
puts( " \"page\",pagep,");
puts( " \"comment\",commentp);\n");
puts("}\n");
}
}
@@ -1343,7 +1332,7 @@ void EmitCImp::emitSensitives() {
for (AstNode* nodep=m_modp->stmtsp(); nodep; nodep = nodep->nextp()) {
if (AstVar* varp = nodep->castVar()) {
if (varp->isInput() && (varp->isScSensitive() || varp->isUsedClock())) {
puts("sensitive("+varp->name()+");\n");
puts("sensitive << "+varp->name()+";\n");
}
}
}
@@ -1425,7 +1414,7 @@ void EmitCStmts::emitVarList(AstNode* firstp, EisWhich which, const string& pref
int sigbytes = varp->widthAlignBytes();
if (varp->isUsedClock() && varp->widthMin()==1) sigbytes = 0;
else if (varp->arraysp()) sigbytes=7;
else if (varp->isScWide()) sigbytes=6;
else if (varp->isScBv()) sigbytes=6;
else if (sigbytes==8) sigbytes=5;
else if (sigbytes==4) sigbytes=4;
else if (sigbytes==2) sigbytes=2;
@@ -1557,7 +1546,7 @@ void EmitCImp::emitInt(AstModule* modp) {
if (!varp->initp()) nodep->v3fatalSrc("No init for a param?");
// These should be static const values, however microsloth VC++ doesn't
// support them. They also cause problems with GDB under GCC2.95.
if (varp->isScWide()) { // Unsupported for output
if (varp->isWide()) { // Unsupported for output
puts("// enum WData "+varp->name()+" //wide");
} else if (!varp->initp()->castConst()) { // Unsupported for output
puts("// enum IData "+varp->name()+" //not simple value");
@@ -1594,7 +1583,7 @@ void EmitCImp::emitInt(AstModule* modp) {
if (v3Global.opt.trace() && !optSystemPerl()) {
puts("void\ttrace (SpTraceVcdCFile* tfp, int levels, int options=0);\n");
}
puts("void\t__Vconfigure("+symClassName()+"* symsp);\n");
puts("void\t__Vconfigure("+symClassName()+"* symsp, bool first);\n");
if (optSystemPerl()) puts("/*AUTOMETHODS*/\n");
emitTextSection(AstType::SCINT);
@@ -1642,25 +1631,25 @@ void EmitCImp::emitImp(AstModule* modp) {
// Us
puts("#include \""+ symClassName() +".h\"\n");
if (optSystemPerl() && (m_splitFilenum || !m_fast)) {
if (optSystemPerl() && (splitFilenum() || !m_fast)) {
puts("\n");
puts("SP_MODULE_CONTINUED("+modClassName(modp)+");\n");
}
emitTextSection(AstType::SCIMPHDR);
if (m_slow && m_splitFilenum==0) {
if (m_slow && splitFilenum()==0) {
puts("\n//--------------------\n");
puts("// STATIC VARIABLES\n\n");
emitVarList(modp->stmtsp(), EVL_ALL, modClassName(modp));
}
if (m_fast && m_splitFilenum==0) {
if (m_fast && splitFilenum()==0) {
emitTextSection(AstType::SCIMP);
emitStaticDecl(modp);
}
if (m_slow && m_splitFilenum==0) {
if (m_slow && splitFilenum()==0) {
puts("\n//--------------------\n");
emitCtorImp(modp);
emitConfigureImp(modp);
@@ -1668,7 +1657,7 @@ void EmitCImp::emitImp(AstModule* modp) {
emitCoverageImp(modp);
}
if (m_fast && m_splitFilenum==0) {
if (m_fast && splitFilenum()==0) {
if (modp->isTop()) {
emitStaticDecl(modp);
puts("\n//--------------------\n");
@@ -1677,7 +1666,7 @@ void EmitCImp::emitImp(AstModule* modp) {
}
}
if (m_fast && m_splitFilenum==0) {
if (m_fast && splitFilenum()==0) {
if (v3Global.opt.trace() && optSystemPerl() && m_modp->isTop()) {
puts("\n");
puts("\n/*AUTOTRACE(__MODULE__,recurse,activity,exists)*/\n\n");
@@ -1689,9 +1678,6 @@ void EmitCImp::emitImp(AstModule* modp) {
puts("// Internal Methods\n");
}
void EmitCImp::emitImpBottom(AstModule* modp) {
}
//######################################################################
void EmitCImp::main(AstModule* modp, bool slow, bool fast) {
@@ -1702,8 +1688,7 @@ void EmitCImp::main(AstModule* modp, bool slow, bool fast) {
string filenameNoExt = v3Global.opt.makeDir()+"/"+ modClassName(modp)+(m_fast ? "" : "__Slow");
if (debug()>=5) {
for (int i=0;i<modp->level();i++) { cout<<" "; }
UINFONL(0," Emitting "<<modClassName(modp)<<endl);
UINFO(0," Emitting "<<modClassName(modp)<<endl);
}
if (optSystemPerl()) {
@@ -1737,22 +1722,17 @@ void EmitCImp::main(AstModule* modp, bool slow, bool fast) {
for (AstNode* nodep=modp->stmtsp(); nodep; nodep = nodep->nextp()) {
if (AstCFunc* funcp = nodep->castCFunc()) {
if (v3Global.opt.outputSplit() > 1 && splitSize()
&& v3Global.opt.outputSplit() < splitSize()) {
if (splitNeeded()) {
// Close old file
emitImpBottom (modp);
delete m_ofp; m_ofp=NULL;
// Open a new file
m_splitSize = 0;
m_ofp = newOutCFile (modp, !m_fast, true/*source*/, ++m_splitFilenum);
m_ofp = newOutCFile (modp, !m_fast, true/*source*/, splitFilenumInc());
emitImp (modp);
}
mainDoFunc(funcp);
}
}
emitImpBottom (modp);
delete m_ofp; m_ofp=NULL;
}
@@ -1762,7 +1742,24 @@ void EmitCImp::main(AstModule* modp, bool slow, bool fast) {
class EmitCTrace : EmitCStmts {
AstCFunc* m_funcp; // Function we're in now
bool m_slow; // Making slow file
// METHODS
void newOutCFile(int filenum) {
string filename = (v3Global.opt.makeDir()+"/"+ topClassName()
+ (m_slow?"__Trace__Slow":"__Trace"));
if (filenum) filename += "__"+cvtToStr(filenum);
filename += ".cpp";
AstCFile* cfilep = newCFile(filename, m_slow, true/*source*/);
cfilep->support(true);
if (m_ofp) v3fatalSrc("Previous file not closed");
m_ofp = new V3OutCFile (filename);
m_ofp->putsHeader();
emitTraceHeader();
}
void emitTraceHeader() {
// Includes
if (optSystemPerl()) {
@@ -1821,11 +1818,11 @@ class EmitCTrace : EmitCStmts {
puts("\n//======================\n\n");
}
bool emitTraceIsScWide(AstTraceInc* nodep) {
bool emitTraceIsScBv(AstTraceInc* nodep) {
AstVarRef* varrefp = nodep->valuep()->castVarRef();
if (!varrefp) return false;
AstVar* varp = varrefp->varp();
return varp->isSc() && varp->isScWide();
return varp->isSc() && varp->isScBv();
}
void emitTraceInitOne(AstTraceDecl* nodep) {
if (nodep->isWide()) {
@@ -1853,8 +1850,10 @@ class EmitCTrace : EmitCStmts {
void emitTraceChangeOne(AstTraceInc* nodep, int arrayindex) {
nodep->precondsp()->iterateAndNext(*this);
string full = (m_funcp->funcType() == AstCFuncType::TRACE_FULL) ? "full":"chg";
if (nodep->isWide() || emitTraceIsScWide(nodep)) {
string full = ((m_funcp->funcType() == AstCFuncType::TRACE_FULL
|| m_funcp->funcType() == AstCFuncType::TRACE_FULL_SUB)
? "full":"chg");
if (nodep->isWide() || emitTraceIsScBv(nodep)) {
puts("vcdp->"+full+"Array");
} else if (nodep->isQuad()) {
puts("vcdp->"+full+"Quad ");
@@ -1876,7 +1875,7 @@ class EmitCTrace : EmitCStmts {
if (nodep->valuep()->castVarRef()) {
AstVarRef* varrefp = nodep->valuep()->castVarRef();
AstVar* varp = varrefp->varp();
if (emitTraceIsScWide(nodep)) puts("(uint32_t*)");
if (emitTraceIsScBv(nodep)) puts("(uint32_t*)");
puts("(");
varrefp->iterate(*this); // Put var name out
if (varp->arraysp()) {
@@ -1885,7 +1884,7 @@ class EmitCTrace : EmitCStmts {
else puts("["+cvtToStr(arrayindex)+"]");
}
if (varp->isSc()) puts(".read()");
if (emitTraceIsScWide(nodep)) puts(".get_datap()");
if (emitTraceIsScBv(nodep)) puts(".get_datap()");
puts(")");
} else {
puts("(");
@@ -1904,11 +1903,18 @@ class EmitCTrace : EmitCStmts {
}
virtual void visit(AstCFunc* nodep, AstNUser*) {
if (nodep->slow() != m_slow) return;
if (nodep->funcType() == AstCFuncType::TRACE_INIT
|| nodep->funcType() == AstCFuncType::TRACE_FULL
|| nodep->funcType() == AstCFuncType::TRACE_CHANGE) {
if (nodep->funcType().isTrace()) { // TRACE_*
m_funcp = nodep;
if (splitNeeded()) {
// Close old file
delete m_ofp; m_ofp=NULL;
// Open a new file
newOutCFile (splitFilenumInc());
}
splitSizeInc(nodep);
puts("\n");
puts(nodep->rtnTypeVoid()); puts(" ");
puts(topClassName()+"::"+nodep->name()
@@ -1920,8 +1926,11 @@ class EmitCTrace : EmitCStmts {
puts("if (0 && vcdp && c) {} // Prevent unused\n");
if (nodep->funcType() == AstCFuncType::TRACE_INIT) {
puts("vcdp->module(vlSymsp->name()); // Setup signal names\n");
} else if (nodep->funcType() == AstCFuncType::TRACE_INIT_SUB) {
} else if (nodep->funcType() == AstCFuncType::TRACE_FULL) {
} else if (nodep->funcType() == AstCFuncType::TRACE_FULL_SUB) {
} else if (nodep->funcType() == AstCFuncType::TRACE_CHANGE) {
} else if (nodep->funcType() == AstCFuncType::TRACE_CHANGE_SUB) {
} else nodep->v3fatalSrc("Bad Case");
if (nodep->initsp()) puts("// Variables\n");
@@ -1931,8 +1940,6 @@ class EmitCTrace : EmitCStmts {
puts("// Body\n");
puts("{\n");
// Do the statements Note not from this node, but the TRACE_INIT's.
// That saved us from having 3 copies of all of the TRACEs
nodep->stmtsp()->iterateAndNext(*this);
puts("}\n");
if (nodep->finalsp()) puts("// Final\n");
@@ -1974,23 +1981,14 @@ public:
virtual ~EmitCTrace() {}
void main() {
// Put out the file
string filename = (v3Global.opt.makeDir()+"/"+ topClassName()
+ (m_slow?"__Trace__Slow.cpp":"__Trace.cpp"));
AstCFile* cfilep = newCFile(filename, m_slow, true/*source*/);
cfilep->support(true);
V3OutCFile of (filename);
of.putsHeader();
m_ofp = &of;
emitTraceHeader();
newOutCFile(0);
if (m_slow) emitTraceSlow();
else emitTraceFast();
v3Global.rootp()->accept(*this);
m_ofp = NULL;
delete m_ofp; m_ofp=NULL;
}
};
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+4 -4
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -78,9 +78,9 @@ public:
virtual void putsIntTopInclude() { puts("#include \"systemperl.h\"\n"); }
};
class V3OutVFile : public V3OutCFile {
class V3OutVFile : public V3OutFile {
public:
V3OutVFile(const string& filename) : V3OutCFile(filename) {}
V3OutVFile(const string& filename) : V3OutFile(filename) {}
virtual ~V3OutVFile() {};
virtual void putsHeader() { puts("// Verilated -*- Verilog -*-\n"); }
};
@@ -137,7 +137,7 @@ public:
};
//######################################################################
// Fileize state, as a visitor of each AstNode
// Count operations under the given node, as a visitor of each AstNode
class EmitCBaseCounterVisitor : public AstNVisitor {
private:
+1 -1
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+30 -6
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -38,11 +38,17 @@
// Symbol table emitting
class EmitCSyms : EmitCBaseVisitor {
// NODE STATE
// Cleared on Netlist
// AstModule::user1() -> bool. Set true __Vconfigure called
AstUser1InUse m_inuser1;
// STATE
AstModule* m_modp; // Current module
typedef pair<AstScope*,AstModule*> ScopeModPair;
vector<ScopeModPair> m_scopes; // Every scope by module
V3LanguageWords m_words; // Reserved word detector
int m_coverBins; // Coverage bin number
// METHODS
void emitInt();
@@ -70,6 +76,7 @@ class EmitCSyms : EmitCBaseVisitor {
// Sort m_scopes by scope name
sort(m_scopes.begin(), m_scopes.end(), CmpName());
// Output
emitInt();
emitImp();
@@ -78,11 +85,18 @@ class EmitCSyms : EmitCBaseVisitor {
nameCheck(nodep);
m_modp = nodep;
nodep->iterateChildren(*this);
m_modp = NULL;
}
virtual void visit(AstScope* nodep, AstNUser*) {
nameCheck(nodep);
m_scopes.push_back(make_pair(nodep, m_modp));
}
virtual void visit(AstCoverDecl* nodep, AstNUser*) {
// Assign numbers to all bins, so we know how big of an array to use
if (!nodep->dataDeclNullp()) { // else duplicate we don't need code for
nodep->binNum(m_coverBins++);
}
}
// NOPs
virtual void visit(AstNodeStmt*, AstNUser*) {}
virtual void visit(AstConst*, AstNUser*) {}
@@ -96,6 +110,7 @@ class EmitCSyms : EmitCBaseVisitor {
public:
EmitCSyms(AstNetlist* nodep) {
m_modp = NULL;
m_coverBins = 0;
nodep->accept(*this);
}
};
@@ -145,6 +160,12 @@ void EmitCSyms::emitInt() {
}
}
puts("\n// COVERAGE\n");
if (m_coverBins) {
ofp()->putAlign(V3OutFile::AL_AUTO, sizeof(uint32_t));
puts("uint32_t\t__Vcoverage["); puts(cvtToStr(m_coverBins)); puts("];\n");
}
puts("\n// CREATORS\n");
puts(symClassName()+"("+topClassName()+"* topp, const char* namep);\n");
puts((string)"~"+symClassName()+"() {};\n");
@@ -186,11 +207,9 @@ void EmitCSyms::emitImp() {
AstScope* scopep = it->first; AstModule* modp = it->second;
if (modp->isTop()) {
} else {
string arrow = scopep->name();
if (arrow.substr(0,4) == "TOP.") arrow.replace(0,4,".");
ofp()->printf("\t%c %-30s ", comma, scopep->nameDotless().c_str());
puts("(Verilated::catName(topp->name(),\"");
puts(arrow);
puts("."+scopep->prettyName());
puts("\"))\n");
comma=',';
}
@@ -215,11 +234,16 @@ void EmitCSyms::emitImp() {
}
}
puts("// Setup each module's pointer back to symbol table (for public functions)\n");
puts("TOPp->__Vconfigure(this);\n");
puts("TOPp->__Vconfigure(this, true);\n");
for (vector<ScopeModPair>::iterator it = m_scopes.begin(); it != m_scopes.end(); ++it) {
AstScope* scopep = it->first; AstModule* modp = it->second;
if (!modp->isTop()) {
puts(scopep->nameDotless()+".__Vconfigure(this);\n");
// first is used by AstCoverDecl's call to __vlCoverInsert
bool first = !modp->user1();
modp->user1(true);
puts(scopep->nameDotless()+".__Vconfigure(this, "
+(first?"true":"false")
+");\n");
}
}
+8 -2
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2004-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2004-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -37,9 +37,14 @@
class EmitMkVisitor : public EmitCBaseVisitor {
public:
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
void emitClassMake() {
// Generate the makefile
V3OutMkFile of (v3Global.opt.makeDir()+"/"+ v3Global.opt.prefix() + "_classes.mk");
@@ -82,6 +87,7 @@ public:
of.puts("PERL = "+V3Options::getenvPERL()+"\n");
of.puts("VERILATOR_ROOT = "+V3Options::getenvVERILATOR_ROOT()+"\n");
of.puts("SYSTEMPERL = "+V3Options::getenvSYSTEMPERL()+"\n");
of.puts("SYSTEMPERL_INCLUDE = "+V3Options::getenvSYSTEMPERL_INCLUDE()+"\n");
of.puts("\n# Switches...\n");
of.puts(string("VM_SP = ")+(v3Global.opt.systemPerl()?"1":"0")+"\n");
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+84 -38
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2004-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2004-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -35,21 +35,26 @@
//######################################################################
// Emit statements and math operators
class EmitVImp : public EmitCBaseVisitor {
private:
class EmitVBaseVisitor : public EmitCBaseVisitor {
// MEMBERS
bool m_suppressSemi;
AstModule* m_modp;
public:
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
virtual void puts(const string& str) = 0;
virtual void putbs(const string& str) = 0;
virtual void putsNoTracking(const string& str) = 0;
// VISITORS
virtual void visit(AstNetlist* nodep, AstNUser*) {
nodep->iterateChildren(*this);
}
virtual void visit(AstModule* nodep, AstNUser*) {
m_modp = nodep;
putbs("module "+modClassName(nodep)+";\n");
nodep->iterateChildren(*this);
puts("endmodule\n");
@@ -86,7 +91,7 @@ public:
virtual void visit(AstAlways* nodep, AstNUser*) {
putbs("always ");
nodep->sensesp()->iterateAndNext(*this);
putbs("begin\n");
putbs(" begin\n");
nodep->bodysp()->iterateAndNext(*this);
puts("end\n");
}
@@ -117,17 +122,22 @@ public:
if (!m_suppressSemi) puts(";\n");
}
virtual void visit(AstSenTree* nodep, AstNUser*) {
// AstSenItem is called for dumping in isolation by V3Order
putbs("@(");
nodep->iterateChildren(*this);
puts(") ");
for (AstNode* expp=nodep->sensesp(); expp; expp = expp->nextp()) {
nodep->iterateChildren(*this);
if (expp->nextp()) puts(" or ");
}
puts(")");
}
virtual void visit(AstSenGate* nodep, AstNUser*) {
emitVerilogFormat(nodep, nodep->emitVerilog(), nodep->sensesp(), nodep->rhsp());
}
virtual void visit(AstSenItem* nodep, AstNUser*) {
putbs("");
if (nodep->backp()->castSenItem()) puts(" or ");
puts(nodep->edgeType().verilogKwd());
puts(" ");
if (nodep->sensp()) puts(" ");
nodep->iterateChildren(*this);
puts(" ");
}
virtual void visit(AstNodeCase* nodep, AstNUser*) {
putbs(nodep->verilogKwd());
@@ -157,19 +167,16 @@ public:
puts((string)"// "+nodep->name()+"\n");
nodep->iterateChildren(*this);
}
virtual void visit(AstCoverDecl*, AstNUser*) {
// N/A
}
virtual void visit(AstCoverInc*, AstNUser*) {
// N/A
}
virtual void visit(AstCoverDecl*, AstNUser*) {} // N/A
virtual void visit(AstCoverInc*, AstNUser*) {} // N/A
virtual void visit(AstCoverToggle*, AstNUser*) {} // N/A
void visitNodeDisplay(AstNode* nodep, AstNode* filep, const string& text, AstNode* exprsp) {
putbs(nodep->verilogKwd());
putbs(" (");
if (filep) { filep->iterateAndNext(*this); putbs(","); }
puts("\"");
ofp()->putsNoTracking(text);
putsNoTracking(text);
puts("\"");
for (AstNode* expp=exprsp; expp; expp = expp->nextp()) {
puts(",");
@@ -232,6 +239,13 @@ public:
nodep->bodysp()->iterateAndNext(*this);
puts("}\n");
}
virtual void visit(AstRepeat* nodep, AstNUser*) {
puts("repeat (");
nodep->countp()->iterateAndNext(*this);
puts(") {\n");
nodep->bodysp()->iterateAndNext(*this);
puts("}\n");
}
virtual void visit(AstWhile* nodep, AstNUser*) {
nodep->precondsp()->iterateAndNext(*this);
puts("while (");
@@ -260,7 +274,7 @@ public:
putbs("$finish;\n");
}
virtual void visit(AstText* nodep, AstNUser*) {
ofp()->putsNoTracking(nodep->text());
putsNoTracking(nodep->text());
}
virtual void visit(AstScopeName* nodep, AstNUser*) {
}
@@ -362,11 +376,11 @@ public:
if (nodep->widthp()->isOne()) {
nodep->lsbp()->iterateAndNext(*this);
} else {
puts(cvtToStr(nodep->lsbp()->castConst()->asInt()
+nodep->widthp()->castConst()->asInt()
puts(cvtToStr(nodep->lsbp()->castConst()->toSInt()
+nodep->widthp()->castConst()->toSInt()
-1));
puts(":");
nodep->lsbp()->iterateAndNext(*this);
puts(cvtToStr(nodep->lsbp()->castConst()->toSInt()));
}
} else {
nodep->lsbp()->iterateAndNext(*this); puts("+:");
@@ -433,21 +447,50 @@ public:
}
public:
EmitVImp() {
EmitVBaseVisitor() {
m_suppressSemi = false;
m_modp = NULL;
}
void main(AstNode* nodep, V3OutCFile* ofp);
virtual ~EmitVImp() {}
virtual ~EmitVBaseVisitor() {}
};
//######################################################################
// Emit to an output file
void EmitVImp::main(AstNode* modp, V3OutCFile* ofp) {
// Output a module, or overall netlist
m_ofp = ofp;
modp->accept(*this);
}
class EmitVFileVisitor : public EmitVBaseVisitor {
// MEMBERS
V3OutFile* m_ofp;
// METHODS
V3OutFile* ofp() const { return m_ofp; };
void puts(const string& str) { ofp()->puts(str); }
void putbs(const string& str) { ofp()->putbs(str); }
void putsNoTracking(const string& str) { ofp()->putsNoTracking(str); }
public:
EmitVFileVisitor(AstNode* nodep, V3OutFile* ofp) {
m_ofp = ofp;
nodep->accept(*this);
}
virtual ~EmitVFileVisitor() {}
};
//######################################################################
// Emit to a stream (perhaps stringstream)
class EmitVStreamVisitor : public EmitVBaseVisitor {
// MEMBERS
ostream& m_os;
// METHODS
void puts(const string& str) { m_os<<str; }
void putbs(const string& str) { m_os<<str; }
void putsNoTracking(const string& str) { m_os<<str; }
public:
EmitVStreamVisitor(AstNode* nodep, ostream& os)
: m_os(os) {
nodep->accept(*this);
}
virtual ~EmitVStreamVisitor() {}
};
//######################################################################
// EmitV class functions
@@ -458,15 +501,18 @@ void V3EmitV::emitv() {
// All-in-one file
V3OutVFile of (v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"__Vout.v");
of.putsHeader();
EmitVImp imp;
imp.main(v3Global.rootp(), &of);
EmitVFileVisitor visitor (v3Global.rootp(), &of);
} else {
// Process each module in turn
for (AstModule* modp = v3Global.rootp()->modulesp(); modp; modp=modp->nextp()->castModule()) {
EmitVImp imp;
V3OutVFile of (v3Global.opt.makeDir()+"/"+imp.modClassName(modp)+"__Vout.v");
V3OutVFile of (v3Global.opt.makeDir()
+"/"+EmitCBaseVisitor::modClassName(modp)+"__Vout.v");
of.putsHeader();
imp.main(modp, &of);
EmitVFileVisitor visitor (modp, &of);
}
}
}
void V3EmitV::verilogForTree(AstNode* nodep, ostream& os) {
EmitVStreamVisitor(nodep, os);
}
+2 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -31,6 +31,7 @@
class V3EmitV {
public:
static void emitv();
static void verilogForTree(AstNode* nodep, ostream& os=cout);
};
#endif // Guard
+7 -7
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -69,10 +69,10 @@ FileLine::FileLine(FileLine::EmptySecret) {
m_lineno=0;
m_filename="COMMAND_LINE";
m_warnOff=0;
for (int codei=V3ErrorCode::FIRST_WARN; codei<V3ErrorCode::MAX; codei++) {
m_warnOn=0;
for (int codei=V3ErrorCode::MIN; codei<V3ErrorCode::MAX; codei++) {
V3ErrorCode code = (V3ErrorCode)codei;
if (code.defaultsOff()) warnOff(code, true);
warnOff(code, code.defaultsOff());
}
}
@@ -152,7 +152,7 @@ const string FileLine::profileFuncname() const {
!= string::npos) {
name.replace(pos, 1, "_");
}
name += "__"+cvtToStr(lineno());
name += "__l"+cvtToStr(lineno());
return name;
}
@@ -165,9 +165,9 @@ ostream& operator<<(ostream& os, FileLine* fileline) {
}
bool FileLine::warnIsOff(V3ErrorCode code) const {
if (m_warnOff.test(code)) return true;
if (!m_warnOn.test(code)) return true;
// UNOPTFLAT implies UNOPT
if (code==V3ErrorCode::UNOPT && m_warnOff.test(V3ErrorCode::UNOPTFLAT)) return true;
if (code==V3ErrorCode::UNOPT && !m_warnOn.test(V3ErrorCode::UNOPTFLAT)) return true;
return false;
}
+33 -9
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -33,10 +33,15 @@
class V3ErrorCode {
public:
enum en {
MIN=0, // Keep first
//
SUPPRESS, // Warning suppressed by user
INFO, // General information out
FATAL, // Kill the program
ERROR, // General error out, can't suppress
// Boolean information we track per-line, but aren't errors
I_COVERAGE, // Coverage is on/off from /*verilator coverage_on/off*/
I_TRACING, // Tracing is on/off from /*verilator tracing_on/off*/
// Error codes:
MULTITOP, // Error: Multiple top level modules
TASKNSVAR, // Error: Task I/O not simple
@@ -77,8 +82,12 @@ public:
const char* ascii() const {
const char* names[] = {
// Leading spaces indicate it can't be disabled.
" SUPPRESS", " INFO", " FATAL", " ERROR",
"MULTITOP", "TASKNSVAR",
" MIN", " SUPPRESS", " INFO", " FATAL", " ERROR",
// Boolean
" I_COVERAGE", " I_TRACING",
// Errors
"MULTITOP", "TASKNSVAR",
// Warnings
" FIRST_WARN",
"BLKANDNBLK",
"CASEINCOMPLETE", "CASEOVERLAP", "CASEWITHX", "CASEX", "CMPCONST",
@@ -178,7 +187,7 @@ inline void v3errorEnd(ostringstream& sstr) { V3Error::v3errorEnd(sstr); }
#define UDEBUGONLY(stmts) {stmts}
#define UASSERT(condition,stmsg) { if (!(condition)) { v3fatalSrc(stmsg); }}
// For use in V3Ast static functions only
#define UASSERT_STATIC(condition,stmsg) { if (!(condition)) { cerr<<"Internal Error: "<<__FILE__<<":"<<dec<<__LINE__<<(stmsg)<<endl; abort(); } }
#define UASSERT_STATIC(condition,stmsg) { if (!(condition)) { cerr<<"Internal Error: "<<__FILE__<<":"<<dec<<__LINE__<<":"<<(stmsg)<<endl; abort(); } }
#define V3ERROR_NA v3error("Internal: Unexpected Call")
@@ -188,13 +197,21 @@ template< class T> std::string cvtToStr (const T& t) {
ostringstream os; os<<t; return os.str();
}
inline uint32_t cvtToHash(void* vp) {
// We can shove a 64 bit pointer into a 32 bit bucket
// On 32 bit systems, lower is always 0, but who cares?
union { void* up; struct {uint32_t upper; uint32_t lower;} l;} u;
u.l.upper=0; u.l.lower=0; u.up=vp;
return u.l.upper^u.l.lower;
}
//######################################################################
class FileLine {
// File and line number of an object, mostly for error reporting
int m_lineno;
string m_filename;
bitset<V3ErrorCode::MAX> m_warnOff;
bitset<V3ErrorCode::MAX> m_warnOn;
static FileLine s_defaultFileLine;
struct EmptySecret {};
protected:
@@ -208,8 +225,8 @@ protected:
void incLineno() { m_lineno++; }
FileLine* copyOrSameFileLine();
public:
FileLine (const string& filename, int lineno) { m_lineno=lineno; m_filename = filename; m_warnOff=s_defaultFileLine.m_warnOff; }
FileLine (FileLine* fromp) { m_lineno=fromp->lineno(); m_filename = fromp->filename(); m_warnOff=fromp->m_warnOff; }
FileLine (const string& filename, int lineno) { m_lineno=lineno; m_filename = filename; m_warnOn=s_defaultFileLine.m_warnOn; }
FileLine (FileLine* fromp) { m_lineno=fromp->lineno(); m_filename = fromp->filename(); m_warnOn=fromp->m_warnOn; }
FileLine (EmptySecret);
~FileLine() { }
#ifdef VL_LEAK_CHECKS
@@ -223,14 +240,21 @@ public:
const string filebasename () const;
const char* cfilename () const { return m_filename.c_str(); }
const string profileFuncname() const;
void warnOff(V3ErrorCode code, bool flag) { m_warnOff.set(code,flag); } // Turn on/off warning messages on this line.
void warnOff(V3ErrorCode code, bool flag) { m_warnOn.set(code,!flag); } // Turn on/off warning messages on this line.
bool warnOff(const string& code, bool flag); // Returns 1 if ok
bool warnIsOff(V3ErrorCode code) const;
void warnLintOff(bool flag);
void warnStateFrom(const FileLine& from) { m_warnOff=from.m_warnOff; }
void warnStateFrom(const FileLine& from) { m_warnOn=from.m_warnOn; }
void warnStateInherit(const FileLine& from);
void warnResetDefault() { warnStateFrom(s_defaultFileLine); }
// Boolean ACCESSORS/METHODS
bool coverageOn() const { return m_warnOn.test(V3ErrorCode::I_COVERAGE); }
void coverageOn(bool flag) { m_warnOn.set(V3ErrorCode::I_COVERAGE,flag); }
bool tracingOn() const { return m_warnOn.test(V3ErrorCode::I_TRACING); }
void tracingOn(bool flag) { m_warnOn.set(V3ErrorCode::I_TRACING,flag); }
// METHODS
void v3errorEnd(ostringstream& str);
inline bool operator==(FileLine rhs) { return (m_lineno==rhs.m_lineno && m_filename==rhs.m_filename); }
+9 -6
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2004-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2004-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -50,9 +50,13 @@ private:
// STATE
AstNode* m_stmtp; // Current statement
//int debug() { return 9; }
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
int longOrQuadWidth (AstNode* nodep) {
// Return 32 or 64...
return (nodep->width()+(VL_WORDSIZE-1)) & ~(VL_WORDSIZE-1);
@@ -172,7 +176,7 @@ private:
// Return equation to get the VL_BITWORD of a constant or non-constant
if (lsbp->castConst()) {
return new AstConst (lsbp->fileline(),
wordAdder + VL_BITWORD_I(lsbp->castConst()->asInt()));
wordAdder + VL_BITWORD_I(lsbp->castConst()->toUInt()));
} else {
AstNode* shiftp = new AstShiftR (lsbp->fileline(),
lsbp->cloneTree(true),
@@ -203,7 +207,7 @@ private:
// Return equation to get the VL_BITBIT of a constant or non-constant
if (lsbp->castConst()) {
return new AstConst (lsbp->fileline(),
VL_BITBIT_I(lsbp->castConst()->asInt()));
VL_BITBIT_I(lsbp->castConst()->toUInt()));
} else {
return new AstAnd (lsbp->fileline(),
new AstConst(lsbp->fileline(), VL_WORDSIZE-1),
@@ -905,7 +909,6 @@ public:
}
virtual ~ExpandVisitor() {}
void main(AstNode* nodep) {
AstNode::userClearTree(); // userp() used on entire tree
nodep->accept(*this);
}
};
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+1 -1
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+29 -11
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -48,7 +48,11 @@ typedef list<AstNodeVarRef*> GateVarRefList;
class GateBaseVisitor : public AstNVisitor {
public:
//int debug() { return 9; }
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
};
//######################################################################
@@ -229,8 +233,9 @@ class GateVisitor : public GateBaseVisitor {
private:
// NODE STATE
//Entire netlist:
// AstVarScope::userp -> GateVarVertex* for usage var, 0=not set yet
// {statement}Node::userp -> GateLogicVertex* for this statement
// AstVarScope::user1p -> GateVarVertex* for usage var, 0=not set yet
// {statement}Node::user1p -> GateLogicVertex* for this statement
AstUser1InUse m_inuser1;
// STATE
V3Graph m_graph; // Scoreboard of var usages/dependencies
@@ -262,11 +267,11 @@ private:
}
GateVarVertex* makeVarVertex(AstVarScope* varscp) {
GateVarVertex* vertexp = (GateVarVertex*)(varscp->userp());
GateVarVertex* vertexp = (GateVarVertex*)(varscp->user1p());
if (!vertexp) {
UINFO(6,"New vertex "<<varscp<<endl);
vertexp = new GateVarVertex(&m_graph, m_scopep, varscp);
varscp->userp(vertexp);
varscp->user1p(vertexp);
if (varscp->varp()->isSigPublic()) {
// Public signals shouldn't be changed, pli code might be messing with them
vertexp->clearReducible("SigPublic");
@@ -293,8 +298,6 @@ private:
// VISITORS
virtual void visit(AstNetlist* nodep, AstNUser*) {
//VV***** We reset userp() and user2p
AstNode::userClearTree();
nodep->iterateChildren(*this);
//if (debug()>6) m_graph.dump();
if (debug()>6) m_graph.dumpDotFilePrefixed("gate_pre");
@@ -316,6 +319,7 @@ private:
m_modp = nodep;
m_activeReducible = true;
nodep->iterateChildren(*this);
m_modp = NULL;
}
virtual void visit(AstScope* nodep, AstNUser*) {
UINFO(4," SCOPE "<<nodep<<endl);
@@ -356,10 +360,21 @@ private:
iterateNewStmt(nodep, "User C Function", "User C Function");
}
virtual void visit(AstSenItem* nodep, AstNUser*) {
// Note we look at only AstSenItems, not AstSenGate's
// The gating term of a AstSenGate is normal logic
m_inSenItem = true;
iterateNewStmt(nodep, NULL, NULL);
if (m_logicVertexp) { // Already under logic; presumably a SenGate
nodep->iterateChildren(*this);
} else { // Standalone item, probably right under a SenTree
iterateNewStmt(nodep, NULL, NULL);
}
m_inSenItem = false;
}
virtual void visit(AstSenGate* nodep, AstNUser*) {
// First handle the clock part will be handled in a minute by visit AstSenItem
// The logic gating term is delt with as logic
iterateNewStmt(nodep, "Clock gater", "Clock gater");
}
virtual void visit(AstInitial* nodep, AstNUser*) {
bool lastslow = m_inSlow;
m_inSlow = true;
@@ -372,6 +387,9 @@ private:
virtual void visit(AstAssignW* nodep, AstNUser*) {
iterateNewStmt(nodep, NULL, NULL);
}
virtual void visit(AstCoverToggle* nodep, AstNUser*) {
iterateNewStmt(nodep, "CoverToggle", "CoverToggle");
}
virtual void visit(AstTraceInc* nodep, AstNUser*) {
bool lastslow = m_inSlow;
m_inSlow = true;
@@ -420,7 +438,7 @@ void GateVisitor::optimizeSignals(bool allowMultiIn) {
if (!vvertexp->isTop() // Ok if top inputs are driverless
&& !vvertexp->varScp()->varp()->initp()
&& !vvertexp->varScp()->varp()->isSigPublic()) {
UINFO(1, "No drivers "<<vvertexp->varScp()<<endl);
UINFO(4, "No drivers "<<vvertexp->varScp()<<endl);
if (0) {
// If we warned here after constant propagation, what the user considered
// reasonable logic may have disappeared. Issuing a warning would
@@ -564,7 +582,7 @@ void GateVisitor::replaceAssigns() {
//if (debug()>9) {vscp->dumpTree(cout, "-vscDone: "); cout<<endl;}
if (!vscp->valuep()->castNodeMath()
|| vscp->valuep()->nextp()) {
vscp->dumpTree(cout, "vscStrange: ");
vscp->dumpTree(cerr, "vscStrange: ");
vscp->v3fatalSrc("Value of varscope not mathematical\n");
}
}
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+13 -6
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -38,7 +38,11 @@
class GenClkBaseVisitor : public AstNVisitor {
protected:
//static int debug() { return 9; }
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
};
//######################################################################
@@ -50,6 +54,8 @@ private:
// Cleared on top scope
// AstVarScope::user2() -> AstVarScope*. Signal replacing activation with
// AstVarRef::user3() -> bool. Signal is replaced activation (already done)
AstUser2InUse m_inuser2;
AstUser3InUse m_inuser3;
// STATE
AstActive* m_activep; // Inside activate statement
@@ -82,7 +88,7 @@ private:
// VISITORS
virtual void visit(AstTopScope* nodep, AstNUser*) {
AstNode::user2ClearTree(); // userp() used on entire tree
AstNode::user2ClearTree(); // user2p() used on entire tree
AstScope* scopep = nodep->scopep();
if (!scopep) nodep->v3fatalSrc("No scope found on top level");
@@ -140,6 +146,7 @@ private:
// NODE STATE
// Cleared on top scope
// AstVarScope::user() -> bool. Set when the var has been used as clock
AstUser1InUse m_inuser1;
// STATE
AstActive* m_activep; // Inside activate statement
@@ -148,7 +155,7 @@ private:
// VISITORS
virtual void visit(AstTopScope* nodep, AstNUser*) {
AstNode::userClearTree(); // userp() used on entire tree
AstNode::user1ClearTree(); // user1p() used on entire tree
nodep->iterateChildren(*this);
{
// Make the new clock signals and replace any activate references
@@ -176,9 +183,9 @@ private:
if (!vscp) nodep->v3fatalSrc("Scope not assigned");
if (m_activep) {
UINFO(8," VarAct "<<nodep<<endl);
vscp->user(true);
vscp->user1(true);
}
if (m_assignp && nodep->lvalue() && vscp->user()) {
if (m_assignp && nodep->lvalue() && vscp->user1()) {
// Variable was previously used as a clock, and is now being set
// Thus a unordered generated clock...
UINFO(8," VarSetAct "<<nodep<<endl);
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+27 -5
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -94,6 +94,26 @@ bool V3GraphVertex::outSize1() const {
return !outEmpty() && outBeginp()->outNextp()==NULL;
}
uint32_t V3GraphVertex::inHash() const {
// We want the same hash ignoring the order of edges.
// So we need an associative operator, like XOR.
// However with XOR multiple edges to the same source will cancel out,
// so we use ADD. (Generally call this only after removing duplicates though)
uint32_t hash=0;
for (V3GraphEdge* edgep = this->inBeginp(); edgep; edgep=edgep->inNextp()) {
hash += cvtToHash(edgep->fromp());
}
return hash;
}
uint32_t V3GraphVertex::outHash() const {
uint32_t hash=0;
for (V3GraphEdge* edgep = this->outBeginp(); edgep; edgep=edgep->outNextp()) {
hash += cvtToHash(edgep->top());
}
return hash;
}
ostream& operator<<(ostream& os, V3GraphVertex* vertexp) {
os<<" VERTEX="<<vertexp->name();
if (vertexp->rank()) os<<" r"<<vertexp->rank();
@@ -176,8 +196,10 @@ void V3Graph::clear() {
void V3Graph::userClearVertices() {
// Clear user() in all of tree
// We may use the userCnt trick in V3Ast later... For now we don't call this often, and
// the extra code on each read of user() would probably slow things down more than help.
// We may use the userCnt trick in V3Ast later... (but gblCnt would be
// in V3Graph instead of static) For now we don't call this often, and
// the extra code on each read of user() would probably slow things
// down more than help.
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
vertexp->user(0);
vertexp->userp(NULL); // Its a union, but might be different size than user()
@@ -206,7 +228,7 @@ void V3Graph::clearColors() {
void V3Graph::loopsVertexCb(V3GraphVertex* vertexp) {
// Needed here as V3GraphVertex<< isn't defined until later in header
cout<<"-Info-Loop: "<<(void*)(vertexp)<<" "<<vertexp<<endl;
cerr<<"-Info-Loop: "<<(void*)(vertexp)<<" "<<vertexp<<endl;
}
void V3Graph::dump(ostream& os) {
@@ -254,7 +276,7 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) {
// Header
*logp<<"digraph v3graph {\n";
*logp<<"\trankdir="<<dotRankDir()<<"\n";
*logp<<"\tsize="<<"\"7.5,10\""<<"\n";
*logp<<"\t//size="<<"\"7.5,10\""<<"\n";
*logp<<"\tnTITLE\t[fontsize=20 label=\""<<filename<<"\", shape=box, style=bold, color=black];\n";
*logp<<"\n";
+33 -8
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -31,7 +31,6 @@
class V3Graph;
class V3GraphVertex;
class V3GraphEdge;
class GraphOrder;
class GraphAcycEdge;
class OrderEitherVertex;
class OrderLogicVertex;
@@ -70,9 +69,12 @@ public:
// METHODS
void clear(); // Empty it of all vertices/edges, as if making a new object
void clearColors();
V3GraphVertex* verticesBeginp() const { return m_vertices.begin(); }
// METHODS - ALGORITHMS
/// Assign same color to all vertices in the same weakly connected component
/// Thus different color if there's no edges between the two subgraphs
void weaklyConnected(V3EdgeFuncP edgeFuncp);
@@ -82,11 +84,22 @@ public:
/// (I.E. all loops will occur within each color, not between them.)
void stronglyConnected(V3EdgeFuncP edgeFuncp);
/// Assign same color to all destination vertices that have same
/// subgraph feeding into them
/// (I.E. all "from" nodes are common within each color)
/// See V3ClkGater if this is needed again; it got specialized
/// Assign a ordering number to all vertexes in a tree.
/// All nodes with no inputs will get rank 1
void rank(V3EdgeFuncP edgeFuncp);
void rank();
/// Sort all vertices and edges using the V3GraphVertex::sortCmp() function
void sortVertices();
/// Sort all edges and edges using the V3GraphEdge::sortCmp() function
void sortEdges();
/// Order all vertices by rank and fanout, lowest first
/// Sort all vertices by rank and fanout, lowest first
/// Sort all edges by weight, lowest first
void order();
@@ -116,8 +129,7 @@ public:
void userClearVertices();
void userClearEdges();
static void test();
//
V3GraphVertex* verticesBeginp() const { return m_vertices.begin(); }
// CALLBACKS
virtual void loopsMessageCb(V3GraphVertex* vertexp) { v3fatalSrc("Loops detected in graph: "<<vertexp); }
virtual void loopsVertexCb(V3GraphVertex* vertexp);
@@ -129,7 +141,6 @@ class V3GraphVertex : public AstNUser {
// Vertices may be a 'gate'/wire statement OR a variable
protected:
friend class V3Graph; friend class V3GraphEdge;
friend class GraphOrderEdgeCmp; friend class GraphOrderVertexCmp;
friend class GraphAcyc; friend class GraphAlgRank;
V3ListEnt<V3GraphVertex*> m_vertices;// All vertices, linked list
V3List<V3GraphEdge*> m_outs; // Outbound edges,linked list
@@ -146,7 +157,8 @@ protected:
// ACCESSORS
void fanout(double fanout) { m_fanout = fanout; }
void rank(uint32_t rank) { m_rank = rank; }
void outUnlink() { m_outs.reset(); }
void inUnlink() { m_ins.reset(); } // Low level; normally unlinkDelete is what you want
void outUnlink() { m_outs.reset(); } // Low level; normally unlinkDelete is what you want
public:
// CONSTRUCTION
V3GraphVertex(V3Graph* graphp);
@@ -159,6 +171,14 @@ public:
virtual string dotShape() const { return ""; }
virtual string dotStyle() const { return ""; }
virtual string dotName() const { return ""; }
virtual int sortCmp(const V3GraphVertex* rhsp) const {
// LHS goes first if of lower rank, or lower fanout
if (m_rank < rhsp->m_rank) return -1;
if (m_rank > rhsp->m_rank) return 1;
if (m_fanout < rhsp->m_fanout) return -1;
if (m_fanout > rhsp->m_fanout) return 1;
return 0;
}
uint32_t color() const { return m_color; }
void color(uint32_t color) { m_color = color; }
uint32_t rank() const { return m_rank; }
@@ -172,9 +192,11 @@ public:
V3GraphEdge* inBeginp() const { return m_ins.begin(); }
bool inEmpty() const { return inBeginp()==NULL; }
bool inSize1() const;
uint32_t inHash() const;
V3GraphEdge* outBeginp() const { return m_outs.begin(); }
bool outEmpty() const { return outBeginp()==NULL; }
bool outSize1() const;
uint32_t outHash() const;
// METHODS
void rerouteEdges(V3Graph* graphp); ///< Edges are routed around this vertex to point from "from" directly to "to"
};
@@ -187,7 +209,6 @@ class V3GraphEdge {
// Wires/variables aren't edges. Edges have only a single to/from vertex
protected:
friend class V3Graph; friend class V3GraphVertex;
friend class GraphOrderEdgeCmp; friend class GraphOrderVertexCmp;
friend class GraphAcyc; friend class GraphAcycEdge;
V3ListEnt<V3GraphEdge*> m_outs; // Next Outbound edge for same vertex (linked list)
V3ListEnt<V3GraphEdge*> m_ins; // Next Inbound edge for same vertex (linked list)
@@ -216,6 +237,10 @@ public:
virtual string dotLabel() const { return ""; }
virtual string dotColor() const { return cutable()?"yellowGreen":"red"; }
virtual string dotStyle() const { return cutable()?"dashed":""; }
virtual int sortCmp(const V3GraphEdge* rhsp) const {
if (!m_weight || !rhsp->m_weight) return 0;
return top()->sortCmp(rhsp->top());
}
void unlinkDelete();
// ACCESSORS
int weight() const { return m_weight; }
+2 -2
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -106,7 +106,7 @@ private:
V3EdgeFuncP m_origEdgeFuncp; // Function that says we follow this edge (in original graph)
uint32_t m_placeStep; // Number that user() must be equal to to indicate processing
int debug() { return V3Graph::debug(); }
static int debug() { return V3Graph::debug(); }
// METHODS
void buildGraph (V3Graph* origGraphp);
+55 -47
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
@@ -390,6 +390,57 @@ void V3Graph::makeEdgesNonCutable(V3EdgeFuncP edgeFuncp) {
}
}
//######################################################################
//######################################################################
// Algorithms - sorting
struct GraphSortVertexCmp {
inline bool operator () (const V3GraphVertex* lhsp, const V3GraphVertex* rhsp) const {
return lhsp->sortCmp(rhsp) < 0;
}
};
struct GraphSortEdgeCmp {
inline bool operator () (const V3GraphEdge* lhsp, const V3GraphEdge* rhsp) const {
return lhsp->sortCmp(rhsp) < 0;
}
};
void V3Graph::sortVertices() {
// Sort list of vertices by rank, then fanout
vector<V3GraphVertex*> vertices;
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
vertices.push_back(vertexp);
}
std::sort(vertices.begin(), vertices.end(), GraphSortVertexCmp());
this->verticesUnlink();
for (vector<V3GraphVertex*>::iterator it = vertices.begin(); it!=vertices.end(); ++it) {
(*it)->verticesPushBack(this);
}
}
void V3Graph::sortEdges() {
// Sort edges by rank then fanout of node they point to
vector<V3GraphEdge*> edges;
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
// Make a vector
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp()) {
edges.push_back(edgep);
}
// Sort
std::sort(edges.begin(), edges.end(), GraphSortEdgeCmp());
// Relink edges in specified order
// We know the vector contains all of the edges that were
// there originally (didn't delete or add)
vertexp->outUnlink();
for (vector<V3GraphEdge*>::const_iterator it = edges.begin(); it!=edges.end(); ++it) {
(*it)->outPushBack();
}
// Prep for next
edges.clear();
}
}
//######################################################################
//######################################################################
// Algorithms - ordering
@@ -398,24 +449,6 @@ void V3Graph::makeEdgesNonCutable(V3EdgeFuncP edgeFuncp) {
// Visit edges and assign ranks to keep minimal crossings
// (Results in better dcache packing.)
struct GraphOrderVertexCmp {
inline bool operator () (const V3GraphVertex* lhsp, const V3GraphVertex* rhsp) const {
// LHS goes first if of lower rank, or lower fanout
if (lhsp->m_rank < rhsp->m_rank) return 1;
if (lhsp->m_rank > rhsp->m_rank) return 0;
return (lhsp->m_fanout < rhsp->m_fanout);
}
};
struct GraphOrderEdgeCmp {
inline bool operator () (const V3GraphEdge* lhsp, const V3GraphEdge* rhsp) const {
if (!lhsp->m_weight || !rhsp->m_weight) return 0;
GraphOrderVertexCmp cmp;
return (cmp(lhsp->m_top, rhsp->m_top));
}
};
//--------------------------------------------------------------------
void V3Graph::order() {
UINFO(2,"Order:\n");
@@ -430,36 +463,11 @@ void V3Graph::order() {
orderDFSIterate(vertexp);
}
}
// Speed up subsequent accesses.
{ // Sort list of vertices by rank, then fanout
vector<V3GraphVertex*> vertices;
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
vertices.push_back(vertexp);
}
sort(vertices.begin(), vertices.end(), GraphOrderVertexCmp());
this->verticesUnlink();
for (vector<V3GraphVertex*>::iterator it = vertices.begin(); it!=vertices.end(); ++it) {
(*it)->verticesPushBack(this);
}
}
// Sort list of vertices by rank, then fanout
sortVertices();
// Sort edges by rank then fanout of node they point to
vector<V3GraphEdge*> edges;
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
// Make a vector
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp()) {
edges.push_back(edgep);
}
// Sort
sort(edges.begin(), edges.end(), GraphOrderEdgeCmp());
// Extract
vertexp->outUnlink();
for (vector<V3GraphEdge*>::iterator it = edges.begin(); it!=edges.end(); ++it) {
(*it)->outPushBack();
}
// Prep for next
edges.clear();
}
sortEdges();
}
double V3Graph::orderDFSIterate(V3GraphVertex* vertexp) {
+1 -1
View File
@@ -8,7 +8,7 @@
//
//*************************************************************************
//
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
+1 -1
View File
@@ -7,7 +7,7 @@
//
//*************************************************************************
//
// Copyright 2005-2008 by Wilson Snyder. This program is free software; you can
// Copyright 2005-2009 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//

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