Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace all asserts & assumes with macros from
assertions.svh
(#233)
* assertions: Rename defines for consistency * assertions: Enable in Verilator by default, disable with global ASSERTS_OFF * assertions: Allow overriding any defines that turn asserts off * assertions: Undefine helper macros at end of header * assertions: Add optional description msg arg to all assert macros * Include assertions.svh header in all sources using assertions Partially reproducible with the following sed command: sed -zi 's/\nmodule/\n`include "common_cells\/assertions.svh"\n\nmodule/g' `grep assert src/*.sv` Requires extensive cleanup. * Replace all named concurrent assertions with ASSERT macro Mainly reproducible with the following sed command: sed -zi 's/\([a-zA-Z_][a-zA-Z0-9_]*\)[ \t\r\n]*:[ \t\r\n]*assert *property[ \t\r\n]*([ \t\r\n]*@(posedge *\([a-zA-Z_][a-zA-Z0-9_]*\))[ \t\r\n]*disable *iff *([~!]\([^)]*\))[ \t\r\n]*\([^;]*\)[ \t\r\n]*)[ \t\r\n]*else[ \t\r\n]*\$fatal[ \t\r\n]*(1,[ \t\r\n]*\([^;]*\)[ \t\r\n]*);/`ASSERT(\1, \4, \2, !\3, \5)/g' src/*.sv Some manual cleanup required for one assertions without message, as well as removal of redundant parenthesis via: sed -i 's/`ASSERT(\([^,]*\), (\([^,]*\)),/`ASSERT(\1, \2,/g' src/*.sv * Replace unnamed concurrent assertions with ASSERT macro Mainly reproducible with the following sed command (as well as a similar variant that matches assertions with $error instead of $fatal): sed -zi 's/assert *property[ \t\r\n]*([ \t\r\n]*@(posedge *\([a-zA-Z_][a-zA-Z0-9_]*\))[ \t\r\n]*disable *iff *([~!]\([^)]*\))[ \t\r\n]*\([^;]*\)[ \t\r\n]*)[ \t\r\n]*else[ \t\r\n]*\$fatal[ \t\r\n]*(1,[ \t\r\n]*\([^;]*\)[ \t\r\n]*);/`ASSERT(NAME_ME, \3, \1, !\2, \4)/g' src/*.sv This needs to be followed by some manual cleanup. In particular, all NAME_ME occurences need to be replaced with a suitable assertion name. In addition, some assertions were not disabled during reset (and used $error instead of $fatal), which required a slightly modified sed command to match these: sed -zi 's/assert *property[ \t\r\n]*([ \t\r\n]*@(posedge *\([a-zA-Z_][a-zA-Z0-9_]*\))[ \t\r\n]*\([^;]*\)[ \t\r\n]*)[ \t\r\n]*else[ \t\r\n]*\$error[ \t\r\n]*([ \t\r\n]*\([^;]*\)[ \t\r\n]*);/`ASSERT(NAME_ME, \2, \1, !rst_ni, \3)/g' src/*.sv Again, some instances of redundant parenthesis could be replaced via: sed -i 's/`ASSERT(\([^,]*\), (\([^,]*\)),/`ASSERT(\1, \2,/g' src/*.sv * Replace concurrent assertions without message with ASSERT macro Partially reproducible with the following sed command: sed -zi 's/\([a-zA-Z_][a-zA-Z0-9_]*\)[ \t\r\n]*:[ \t\r\n]*assert *property[ \t\r\n]*([ \t\r\n]*@(posedge *\([a-zA-Z_][a-zA-Z0-9_]*\))[ \t\r\n]*disable *iff *([~!]\([^)]*\))[ \t\r\n]*\([^;]*\)[ \t\r\n]*);/`ASSERT(\1, \4, \2, !\3)/g' src/*.sv Additionally, the following sed command can be used for unnamed variants without a reset: sed -zi 's/assert *property[ \t\r\n]*([ \t\r\n]*@(posedge *\([a-zA-Z_][a-zA-Z0-9_]*\))[ \t\r\n]*\([^;]*\)[ \t\r\n]*);/`ASSERT(\NAME_ME, \2, \1, !rst_ni)/g' src/*.sv Requires cleanup. In particular, all occurences of NAME_ME need to be replaced with suitable names for the asserted properties. * Replace all concurrent assumes with ASSUME macro Reproducible with the following sed command for named assumes: sed -zi 's/\([a-zA-Z_][a-zA-Z0-9_]*\)[ \t\r\n]*:[ \t\r\n]*assume *property[ \t\r\n]*([ \t\r\n]*@(posedge *\([a-zA-Z_][a-zA-Z0-9_]*\))[ \t\r\n]*disable *iff *([~!]\([^)]*\))[ \t\r\n]*\([^;]*\)[ \t\r\n]*)[ \t\r\n]*else[ \t\r\n]*\$fatal[ \t\r\n]*(1,[ \t\r\n]*\([^;]*\)[ \t\r\n]*);/`ASSUME(\1, \4, \2, !\3, \5)/g' src/*.sv And the following sed command for unnamed assumes without reset and with $error instead of $fatal: sed -zi 's/assume *property[ \t\r\n]*([ \t\r\n]*@(posedge *\([a-zA-Z_][a-zA-Z0-9_]*\))[ \t\r\n]*\([^;]*\)[ \t\r\n]*)[ \t\r\n]*else[ \t\r\n]*\$error[ \t\r\n]*([ \t\r\n]*\([^;]*\)[ \t\r\n]*);/`ASSUME(NAME_ME, \2, \1, !rst_ni, \3)/g' src/*.sv Requires cleanup to replace NAME_ME with a suitable property name. Redundant parenthesis can be removed with the following command: sed -i 's/`ASSUME(\([^,]*\), (\([^,]*\)),/`ASSUME(\1, \2,/g' src/*.sv * Replace all immediate asserts in initial blocks with ASSERT_INIT macro Mainly reproducible with the following sequence of sed commands: sed -i '/initial begin/,/end/ s/ assert[ \t\r\n]*([ \t\r\n]*\(.*\))/`ASSERT_INIT(NAME_ME, \1, /g' src/*.sv sed -zi 's/`ASSERT_INIT(\([^,]*\), \([^,]*\),[ \t\r\n]*else[ \t\r\n]*\$fatal[ \t\r\n]*(1,[ \t\r\n]*\([^;]*\);/`ASSERT_INIT(\1, \2, \3/g' src/*.sv Requires some cleanup. In particular, all instances of NAME_ME must be replaced by sensible assertion names. * Replace final assertion with ASSERT_FINAL macro No sed magic here. This change was done manually. * Replace initial assertions with ASSERT_INIT macro Mainly reproducible with the following sed command: sed -i 's/initial assert(\([^;]*\));/`ASSERT_INIT(NAME_ME, \1)/g' src/*.sv Requires some cleanup. NAME_ME must be replaced with a sensible assertion name. * Replace all immediate assumes with ASSUME_I macro Again no sed magic, change applied manually. * Remove unnecessary ifndefs for SYNTHESIS around assertions Assertions are now disabled if SYNTHESIS is defined within the assertions.svh header. * spill_register_flushable: Promote flush+feed warning to error * Remove obsolete default disables for assertions * addr_decode_dync: Promote onehot assert warning to error * stream_omega_net: Use $sformatf() for assert msg Use $sformatf() to compose a formatted string before passing it as descriptive message to the assertions macros. * stream_xbar: Use $sformatf() for assert msg Use $sformatf() to compose a formatted string before passing it as descriptive message to the assertions macros. * Distribute ASSERT macros over multiple lines Avoid line-length lint warnings by distributing ASSERT macros over multiple lines, in particular moving log messages to the next line and shortening some of the messages. * stream_omega_net: Fix typo in assert name * mem_to_banks_detailed: Check power of 2 in a more sensible way * stream_intf: Replace non-existing reset with constant in asserts * stream_inft: Add missing include of assertions.svh
- Loading branch information