Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter initialization with array assignment pattern containing default produces invalid elaborated UHDM #3803

Closed
mglb opened this issue Aug 22, 2023 · 8 comments
Assignees

Comments

@mglb
Copy link

mglb commented Aug 22, 2023

Problematic test case

module test #(
  parameter int BobaCount = 2,
  parameter int unsigned NumBobaDrinkers[BobaCount] = '{default: '1}
)();
endmodule

UHDM:

|uhdmtopModules:
\_module_inst: work@test (work@test), file:/home/user/p/repos/yosys-systemverilog/test1.sv, line:1:1, endln:5:10
  ...
  |vpiParamAssign:
  \_param_assign: , line:3:26, endln:3:69
    |vpiParent:
    \_module_inst: work@test (work@test), file:/home/user/p/repos/yosys-systemverilog/test1.sv, line:1:1, endln:5:10
    |vpiRhs:
    \_array_expr:
      |vpiParent:
      \_param_assign: , line:3:26, endln:3:69
      |vpiTypespec:
      \_array_typespec: , line:3:13, endln:3:52
      |vpiExpr:
      \_constant:
        |vpiDecompile:1
        |UINT:1
        |vpiConstType:9
      |vpiExpr:
      \_constant:
    |vpiLhs:
    \_parameter: ([email protected]), line:3:26, endln:3:41

Issue: last constant and array_typespec are empty

Similar test case that works (1)

module test #(
  parameter int BobaCount = 2,
  parameter int unsigned NumBobaDrinkers[BobaCount] = '{'1, '1}
)();
endmodule

UHDM:

|uhdmtopModules:
\_module_inst: work@test (work@test), file:/home/user/p/repos/yosys-systemverilog/test2.sv, line:1:1, endln:5:10
  ...
  |vpiParamAssign:
  \_param_assign: , line:3:26, endln:3:64
    |vpiParent:
    \_module_inst: work@test (work@test), file:/home/user/p/repos/yosys-systemverilog/test2.sv, line:1:1, endln:5:10
    |vpiRhs:
    \_operation: , line:3:55, endln:3:64
      |vpiParent:
      \_param_assign: , line:3:26, endln:3:64
      |vpiTypespec:
      \_array_typespec: , line:3:13, endln:3:52
        |vpiParent:
        \_operation: , line:3:55, endln:3:64
        |vpiRange:
        \_range: , line:3:42, endln:3:51
          |vpiParent:
          \_array_typespec: , line:3:13, endln:3:52
          |vpiLeftRange:
          \_constant:
            |vpiParent:
            \_range: , line:3:42, endln:3:51
            |vpiDecompile:0
            |vpiSize:64
            |UINT:0
            |vpiConstType:9
          |vpiRightRange:
          \_operation: , line:3:42, endln:3:51
            |vpiParent:
            \_range: , line:3:42, endln:3:51
            |vpiOpType:11
            |vpiOperand:
            \_ref_obj: ([email protected]), line:3:42, endln:3:51
              |vpiParent:
              \_operation: , line:3:42, endln:3:51
              |vpiName:BobaCount
              |vpiFullName:[email protected]
              |vpiActual:
              \_parameter: ([email protected]), line:2:17, endln:2:26
            |vpiOperand:
            \_constant:
              |vpiParent:
              \_operation: , line:3:42, endln:3:51
              |vpiSize:64
              |INT:1
              |vpiConstType:7
        |vpiElemTypespec:
        \_int_typespec: , line:3:13, endln:3:25
          |vpiParent:
          \_array_typespec: , line:3:13, endln:3:52
      |vpiOpType:75
      |vpiOperand:
      \_constant: , line:3:57, endln:3:59
        |vpiParent:
        \_operation: , line:3:55, endln:3:64
        |vpiDecompile:'1
        |vpiSize:32
        |BIN:1
        |vpiConstType:3
      |vpiOperand:
      \_constant: , line:3:61, endln:3:63
        |vpiParent:
        \_operation: , line:3:55, endln:3:64
        |vpiDecompile:'1
        |vpiSize:32
        |BIN:1
        |vpiConstType:3
    |vpiLhs:
    \_parameter: ([email protected]), line:3:26, endln:3:41

Similar test case that works (2)

module test #(
  parameter int BobaCount = 2,
  parameter int unsigned NumBobaDrinkers[BobaCount] = '{BobaCount{'1}}
)();
endmodule

UHDM:

|uhdmtopModules:
\_module_inst: work@test (work@test), file:/home/user/p/repos/yosys-systemverilog/test2.sv, line:1:1, endln:5:10
  ...
  |vpiParamAssign:
  \_param_assign: , line:2:17, endln:2:30
    |vpiParent:
    \_module_inst: work@test (work@test), file:/home/user/p/repos/yosys-systemverilog/test2.sv, line:1:1, endln:5:10
    |vpiRhs:
    \_constant: , line:2:29, endln:2:30
      |vpiParent:
      \_param_assign: , line:2:17, endln:2:30
      |vpiDecompile:2
      |vpiSize:32
      |UINT:2
      |vpiTypespec:
      \_int_typespec: , line:2:13, endln:2:16
      |vpiConstType:9
    |vpiLhs:
    \_parameter: ([email protected]), line:2:17, endln:2:26
  |vpiParamAssign:
  \_param_assign: , line:3:26, endln:3:71
    |vpiParent:
    \_module_inst: work@test (work@test), file:/home/user/p/repos/yosys-systemverilog/test2.sv, line:1:1, endln:5:10
    |vpiRhs:
    \_operation: , line:3:55, endln:3:71
      |vpiParent:
      \_param_assign: , line:3:26, endln:3:71
      |vpiOpType:76
      |vpiOperand:
      \_ref_obj: ([email protected]), line:3:57, endln:3:66
        |vpiParent:
        \_operation: , line:3:55, endln:3:71
        |vpiName:BobaCount
        |vpiFullName:[email protected]
        |vpiActual:
        \_parameter: ([email protected]), line:2:17, endln:2:26
      |vpiOperand:
      \_operation: , line:3:67, endln:3:69
        |vpiParent:
        \_operation: , line:3:55, endln:3:71
        |vpiOpType:33
        |vpiOperand:
        \_constant: , line:3:67, endln:3:69
          |vpiParent:
          \_operation: , line:3:67, endln:3:69
          |vpiDecompile:'1
          |vpiSize:-1
          |BIN:1
          |vpiConstType:3
    |vpiLhs:
    \_parameter: ([email protected]), line:3:26, endln:3:41

Ref: chipsalliance/yosys-f4pga-plugins#539

@Thomasb81
Copy link
Collaborator

In this context '{default: '1} is "short" hand notation for '{'1, '1}. According to me when a structure initialization is using default keyword ; Surelog should elaborate the complete structure initialization depending of the right assignment expression...

But that's going to work only for elaborated data model : if BobaCount is override with a value different than 2 since systemVerilog data model does not record default information, there will be uninitialized index while source code explicitly specify a default initialization value.

@alaindargelas
Copy link
Collaborator

All the tests generate wrong UHDM. They all need to expand the const to 2^32-1

@alaindargelas
Copy link
Collaborator

#3805 fixes the case: parameter int unsigned NumBobaDrinkers[BobaCount] = '{'1, '1}

@alaindargelas
Copy link
Collaborator

alaindargelas commented Aug 24, 2023

#3806 fixes the main case: parameter int unsigned NumBobaDrinkers[BobaCount] = '{default: '1}
@mglb @tgorochowik , you can update the plugin for @QuantamHD. The last case is not that important.

@alaindargelas
Copy link
Collaborator

#3807 fixes parameter int unsigned NumBobaDrinkers[BobaCount] = '{BobaCount{'1}}

@mglb
Copy link
Author

mglb commented Aug 29, 2023

There's still an empty typespec:

      |vpiTypespec:
      \_array_typespec: , line:3:13, endln:3:52

The "Similar test case that works (1)" has full typespec.

@tgorochowik tgorochowik reopened this Aug 29, 2023
@alaindargelas
Copy link
Collaborator

alaindargelas commented Aug 30, 2023

It is not an empty typespec.
Print with the IDs: surelog ...... -d uhdm -d vpi_ids

In the case "that works", the typespec is cloned which makes it print in the -d uhdm, in the main case, it is not cloned, so the uhdm printer does not print it again, but it points to the correct typespec object. It is strictly the same.

id:12 typespec in the elaborated tree points to the declaration in the non-elaborated tree with the same ID.

 \_array_typespec: , id:12, line:3:14, endln:3:53
      |vpiParent:
      \_parameter: ([email protected]), id:6, line:3:27, endln:3:42
      |vpiRange:
      \_range: , id:7, line:3:43, endln:3:52
        |vpiParent:
        \_parameter: ([email protected]), id:6, line:3:27, endln:3:42
        |vpiLeftRange:
        \_constant: , id:8
          |vpiParent:
          \_range: , id:7, line:3:43, endln:3:52
          |vpiDecompile:0
          |vpiSize:64
          |UINT:0
          |vpiConstType:9
        |vpiRightRange:
        \_operation: , id:10, line:3:43, endln:3:52
          |vpiParent:
          \_range: , id:7, line:3:43, endln:3:52
          |vpiOpType:11
          |vpiOperand:
          \_ref_obj: ([email protected]), id:9, line:3:43, endln:3:52
            |vpiParent:
            \_operation: , id:10, line:3:43, endln:3:52
            |vpiName:BobaCount
            |vpiFullName:[email protected]
            |vpiActual:
            \_parameter: ([email protected]), id:35, line:2:18, endln:2:27
          |vpiOperand:
          \_constant: , id:11
            |vpiSize:64
            |INT:1
            |vpiConstType:7
      |vpiElemTypespec:
      \_int_typespec: , id:5, line:3:14, endln:3:26
====== UHDM =======
design: (work@test), id:32
|vpiElaborated:1
|vpiName:work@test
|uhdmallModules:
\_module_inst: work@test (work@test), id:33, file:/home/alain/Surelog/tests/ScratchPad.sv, line:1:1, endln:5:11
  |vpiParent:
  \_design: (work@test), id:32
  |vpiFullName:work@test
  |vpiParameter:
  \_parameter: ([email protected]), id:2, line:2:18, endln:2:27
    |vpiParent:
    \_module_inst: work@test (work@test), id:33, file:/home/alain/Surelog/tests/ScratchPad.sv, line:1:1, endln:5:11
    |UINT:2
    |vpiTypespec:
    \_int_typespec: , id:1, line:2:14, endln:2:17
      |vpiParent:
      \_parameter: ([email protected]), id:2, line:2:18, endln:2:27
      |vpiSigned:1
    |vpiSigned:1
    |vpiName:BobaCount
    |vpiFullName:[email protected]
  |vpiParameter:
  \_parameter: ([email protected]), id:6, line:3:27, endln:3:42
    |vpiParent:
    \_module_inst: work@test (work@test), id:33, file:/home/alain/Surelog/tests/ScratchPad.sv, line:1:1, endln:5:11
    |vpiSize:1
    |vpiTypespec:
    \_array_typespec: , id:12, line:3:14, endln:3:53
      |vpiParent:
      \_parameter: ([email protected]), id:6, line:3:27, endln:3:42
      |vpiRange:
      \_range: , id:7, line:3:43, endln:3:52
        |vpiParent:
        \_parameter: ([email protected]), id:6, line:3:27, endln:3:42
        |vpiLeftRange:
        \_constant: , id:8
          |vpiParent:
          \_range: , id:7, line:3:43, endln:3:52
          |vpiDecompile:0
          |vpiSize:64
          |UINT:0
          |vpiConstType:9
        |vpiRightRange:
        \_operation: , id:10, line:3:43, endln:3:52
          |vpiParent:
          \_range: , id:7, line:3:43, endln:3:52
          |vpiOpType:11
          |vpiOperand:
          \_ref_obj: ([email protected]), id:9, line:3:43, endln:3:52
            |vpiParent:
            \_operation: , id:10, line:3:43, endln:3:52
            |vpiName:BobaCount
            |vpiFullName:[email protected]
            |vpiActual:
            \_parameter: ([email protected]), id:35, line:2:18, endln:2:27
          |vpiOperand:
          \_constant: , id:11
            |vpiSize:64
            |INT:1
            |vpiConstType:7
      |vpiElemTypespec:
      \_int_typespec: , id:5, line:3:14, endln:3:26
    |vpiRange:
    \_range: , id:7, line:3:43, endln:3:52
    |vpiName:NumBobaDrinkers
    |vpiFullName:[email protected]
  |vpiParamAssign:
  \_param_assign: , id:3, line:2:18, endln:2:31
    |vpiParent:
    \_module_inst: work@test (work@test), id:33, file:/home/alain/Surelog/tests/ScratchPad.sv, line:1:1, endln:5:11
    |vpiRhs:
    \_constant: , id:4, line:2:30, endln:2:31
      |vpiParent:
      \_param_assign: , id:3, line:2:18, endln:2:31
      |vpiDecompile:2
      |vpiSize:64
      |UINT:2
      |vpiTypespec:
      \_int_typespec: , id:1, line:2:14, endln:2:17
      |vpiConstType:9
    |vpiLhs:
    \_parameter: ([email protected]), id:2, line:2:18, endln:2:27
  |vpiParamAssign:
  \_param_assign: , id:13, line:3:27, endln:3:70
    |vpiParent:
    \_module_inst: work@test (work@test), id:33, file:/home/alain/Surelog/tests/ScratchPad.sv, line:1:1, endln:5:11
    |vpiRhs:
    \_operation: , id:14, line:3:56, endln:3:70
      |vpiParent:
      \_param_assign: , id:13, line:3:27, endln:3:70
      |vpiOpType:75
      |vpiOperand:
      \_tagged_pattern: , id:16, line:3:67, endln:3:69
        |vpiParent:
        \_operation: , id:14, line:3:56, endln:3:70
        |vpiPattern:
        \_constant: , id:15, line:3:67, endln:3:69
          |vpiDecompile:'1
          |vpiSize:-1
          |BIN:1
          |vpiConstType:3
        |vpiTypespec:
        \_string_typespec: (default), id:17, line:3:58, endln:3:65
          |vpiParent:
          \_tagged_pattern: , id:16, line:3:67, endln:3:69
          |vpiName:default
    |vpiLhs:
    \_parameter: ([email protected]), id:6, line:3:27, endln:3:42
  |vpiDefName:work@test
|uhdmtopModules:
\_module_inst: work@test (work@test), id:34, file:/home/alain/Surelog/tests/ScratchPad.sv, line:1:1, endln:5:11
  |vpiName:work@test
  |vpiParameter:
  \_parameter: ([email protected]), id:35, line:2:18, endln:2:27
    |vpiParent:
    \_module_inst: work@test (work@test), id:34, file:/home/alain/Surelog/tests/ScratchPad.sv, line:1:1, endln:5:11
    |UINT:2
    |vpiTypespec:
    \_int_typespec: , id:36, line:2:14, endln:2:17
      |vpiParent:
      \_parameter: ([email protected]), id:35, line:2:18, endln:2:27
      |vpiSigned:1
    |vpiSigned:1
    |vpiName:BobaCount
    |vpiFullName:[email protected]
  |vpiParameter:
  \_parameter: ([email protected]), id:37, line:3:27, endln:3:42
    |vpiParent:
    \_module_inst: work@test (work@test), id:34, file:/home/alain/Surelog/tests/ScratchPad.sv, line:1:1, endln:5:11
    |vpiSize:1
    |vpiTypespec:
    \_array_typespec: , id:38, line:3:14, endln:3:53
      |vpiParent:
      \_parameter: ([email protected]), id:37, line:3:27, endln:3:42
      |vpiRange:
      \_range: , id:39, line:3:43, endln:3:52
        |vpiParent:
        \_array_typespec: , id:38, line:3:14, endln:3:53
        |vpiLeftRange:
        \_constant: , id:40
          |vpiParent:
          \_range: , id:39, line:3:43, endln:3:52
          |vpiDecompile:0
          |vpiSize:64
          |UINT:0
          |vpiConstType:9
        |vpiRightRange:
        \_operation: , id:41, line:3:43, endln:3:52
          |vpiParent:
          \_range: , id:39, line:3:43, endln:3:52
          |vpiOpType:11
          |vpiOperand:
          \_ref_obj: ([email protected]), id:42, line:3:43, endln:3:52
            |vpiParent:
            \_operation: , id:41, line:3:43, endln:3:52
            |vpiName:BobaCount
            |vpiFullName:[email protected]
            |vpiActual:
            \_parameter: ([email protected]), id:35, line:2:18, endln:2:27
          |vpiOperand:
          \_constant: , id:43
            |vpiParent:
            \_operation: , id:41, line:3:43, endln:3:52
            |vpiSize:64
            |INT:1
            |vpiConstType:7
      |vpiElemTypespec:
      \_int_typespec: , id:44, line:3:14, endln:3:26
        |vpiParent:
        \_array_typespec: , id:38, line:3:14, endln:3:53
    |vpiRange:
    \_range: , id:45, line:3:43, endln:3:52
      |vpiParent:
      \_parameter: ([email protected]), id:37, line:3:27, endln:3:42
      |vpiLeftRange:
      \_constant: , id:46
        |vpiParent:
        \_range: , id:45, line:3:43, endln:3:52
        |vpiDecompile:0
        |vpiSize:64
        |UINT:0
        |vpiConstType:9
      |vpiRightRange:
      \_operation: , id:47, line:3:43, endln:3:52
        |vpiParent:
        \_range: , id:45, line:3:43, endln:3:52
        |vpiOpType:11
        |vpiOperand:
        \_ref_obj: ([email protected]), id:48, line:3:43, endln:3:52
          |vpiParent:
          \_operation: , id:47, line:3:43, endln:3:52
          |vpiName:BobaCount
          |vpiFullName:[email protected]
          |vpiActual:
          \_parameter: ([email protected]), id:35, line:2:18, endln:2:27
        |vpiOperand:
        \_constant: , id:49
          |vpiParent:
          \_operation: , id:47, line:3:43, endln:3:52
          |vpiSize:64
          |INT:1
          |vpiConstType:7
    |vpiName:NumBobaDrinkers
    |vpiFullName:[email protected]
  |vpiParamAssign:
  \_param_assign: , id:28, line:2:18, endln:2:31
    |vpiParent:
    \_module_inst: work@test (work@test), id:34, file:/home/alain/Surelog/tests/ScratchPad.sv, line:1:1, endln:5:11
    |vpiRhs:
    \_constant: , id:29, line:2:30, endln:2:31
      |vpiParent:
      \_param_assign: , id:28, line:2:18, endln:2:31
      |vpiDecompile:2
      |vpiSize:32
      |UINT:2
      |vpiTypespec:
      \_int_typespec: , id:1, line:2:14, endln:2:17
      |vpiConstType:9
    |vpiLhs:
    \_parameter: ([email protected]), id:35, line:2:18, endln:2:27
  |vpiParamAssign:
  \_param_assign: , id:31, line:3:27, endln:3:70
    |vpiParent:
    \_module_inst: work@test (work@test), id:34, file:/home/alain/Surelog/tests/ScratchPad.sv, line:1:1, endln:5:11
    |vpiRhs:
    \_array_expr: , id:27
      |vpiParent:
      \_param_assign: , id:31, line:3:27, endln:3:70
      |vpiTypespec:
      \_array_typespec: , id:12, line:3:14, endln:3:53
      |vpiExpr:
      \_constant: , id:21, line:3:67, endln:3:69
        |vpiDecompile:4294967295
        |vpiSize:32
        |UINT:4294967295
        |vpiConstType:9
      |vpiExpr:
      \_constant: , id:21, line:3:67, endln:3:69
    |vpiLhs:
    \_parameter: ([email protected]), id:37, line:3:27, endln:3:42
  |vpiDefName:work@test
  |vpiTop:1
  |vpiTopModule:1

@alaindargelas
Copy link
Collaborator

@mglb can you confirm your are unblocked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants