chipsalliance/Surelog

Comparison of `$bits` return value with scoped name of a parameter sometimes gives wrong result

Closed this issue · 3 comments

mglb commented

See comments in a.sv to see the problem. The problem is not present in Surelog bf13c83

assert.sv:

`ifndef ASSERT_SV
`define ASSERT_SV

`define ASSERT_STATIC_IN_PACKAGE(__name, __prop)              \
  function automatic bit assert_static_in_package_``__name(); \
    bit unused_bit [((__prop) ? 1 : -1)];                     \
    unused_bit = '{default: 1'b0};                            \
    return unused_bit[0];                                     \
  endfunction

`endif // ASSERT_SV

b.sv

package pkg_b;
  parameter int ParameterIntEqual4 = 4;
endpackage : pkg_b

a.sv:

`include "assert.sv"
package pkg_a;
  // Comment line 1
  // Comment line 2
  // Comment line 3
  // Comment line 4
  // Comment line 5
  // Comment line 6
  parameter int ParameterIntInPkgA = 4;
  //// The two following lines do not raise any error when uncommented:
  // `ASSERT_STATIC_IN_PACKAGE(ThisNameDoesNotMatter, 32 == $bits(pkg_b::ParameterIntEqual4))
  // `ASSERT_STATIC_IN_PACKAGE(ThisNameDoesNotMatter, $bits(ParameterIntInPkgA) == 32)
  //// This one does fail:
  `ASSERT_STATIC_IN_PACKAGE(ThisNameDoesNotMatter, $bits(ParameterIntInPkgA) == $bits(pkg_b::ParameterIntEqual4))
endpackage : pkg_a

Command: surelog -parse -synth -sv -elabuhdm b.sv a.sv

Result:

[INF:CM0023] Creating log file /home/user/p/data/illegalzerotestcase/slpp_all/surelog.log.

[WRN:PA0205] /home/user/p/data/illegalzerotestcase/b.sv:1:1: No timescale set for "pkg_b".

[WRN:PA0205] /home/user/p/data/illegalzerotestcase/a.sv:2:1: No timescale set for "pkg_a".

[INF:CP0300] Compilation...

[INF:CP0301] /home/user/p/data/illegalzerotestcase/b.sv:1:1: Compile package "pkg_b".

[INF:CP0301] /home/user/p/data/illegalzerotestcase/a.sv:2:1: Compile package "pkg_a".

[INF:CP0302] Compile class "work@mailbox".

[INF:CP0302] Compile class "work@process".

[INF:CP0302] Compile class "work@semaphore".

[ERR:EL0536] /home/user/p/data/illegalzerotestcase/a.sv:6:21: Illegal Zero or negative size "pkg_a"
             text:   // Comment line 4
             value: INT:-1.

[INF:EL0526] Design Elaboration...

[NTE:EL0508] Nb Top level modules: 0.

[NTE:EL0509] Max instance depth: 0.

[NTE:EL0510] Nb instances: 0.

[NTE:EL0511] Nb leaf instances: 0.

[INF:UH0706] Creating UHDM Model...

[INF:UH0707] Elaborating UHDM...

[INF:UH0708] Writing UHDM DB: /home/user/p/data/illegalzerotestcase/slpp_all/surelog.uhdm ...

[  FATAL] : 0
[ SYNTAX] : 0
[  ERROR] : 1
[WARNING] : 2
[   NOTE] : 4

Note: Error's line (6) should refer to a line in assert.sv, not a.sv as reported.

Fixed by #3774

mglb commented

This still does not work. The test added in a fix works because ThisNameDoesNotMatter in https://github.com/alainmarcel/Surelog/blob/d349b7659922473a78fc47a05d9aecc0fd379ebe/tests/AllPackageSignal/dut.sv#L30-L33 does not matter only if it is used only once (i.e. there is only one assert with the name). Poor naming on my side.

When the lines are changed to:

  //// The two following lines do not raise any error when uncommented:
  `ASSERT_STATIC_IN_PACKAGE(ThisNameDoesNotMatter3, 32 == $bits(pkg_b::ParameterIntEqual4))
  `ASSERT_STATIC_IN_PACKAGE(ThisNameDoesNotMatter2, $bits(ParameterIntInPkgA) == 32)
  //// This one does fail:
  `ASSERT_STATIC_IN_PACKAGE(ThisNameDoesNotMatter1, $bits(ParameterIntInPkgA) == $bits(pkg_b::ParameterIntEqual4))

or:

  //// This one does fail:
  `ASSERT_STATIC_IN_PACKAGE(ThisNameDoesNotMatter, $bits(ParameterIntInPkgA) == $bits(pkg_b::ParameterIntEqual4))

the error comes back.

Re fixed by #3777