Skip to content

Commit

Permalink
[ImportVerilog] Support assignment patterns with integer type (#7646)
Browse files Browse the repository at this point in the history
Allow `'{...}` assignment patterns to be used to assign integer values.
Slang already computes the value for each element in the resulting type.
All that's needed is a concat with the right operand order.
  • Loading branch information
fabianschuiki authored Sep 28, 2024
1 parent 9edbc08 commit a7f1773
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/Conversion/ImportVerilog/Expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,13 @@ struct RvalueExprVisitor {
for (unsigned elementIdx = 0; elementIdx < elementCount; ++elementIdx)
elements.push_back(elements[elementIdx]);

// Handle integers.
if (auto intType = dyn_cast<moore::IntType>(type)) {
assert(intType.getWidth() == elements.size());
std::reverse(elements.begin(), elements.end());
return builder.create<moore::ConcatOp>(loc, intType, elements);
}

// Handle packed structs.
if (auto structType = dyn_cast<moore::StructType>(type)) {
assert(structType.getMembers().size() == elements.size());
Expand Down
9 changes: 9 additions & 0 deletions test/Conversion/ImportVerilog/basic.sv
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ module Expressions;
bit [1:0][31:0] arrayInt;
// CHECK: %uarrayInt = moore.variable : <uarray<2 x i32>>
bit [31:0] uarrayInt [2];
// CHECK: %m = moore.variable : <l4>
logic [3:0] m;

initial begin
// CHECK: moore.constant 0 : i32
Expand Down Expand Up @@ -1275,6 +1277,13 @@ module Expressions;
// CHECK: [[TMP3:%.+]] = moore.array_create [[TMP0]], [[TMP1]], [[TMP2]], [[TMP0]], [[TMP1]], [[TMP2]] : !moore.i4, !moore.i4, !moore.i4, !moore.i4, !moore.i4, !moore.i4 -> uarray<6 x i4>
// CHECK: moore.array_create [[TMP3]], [[TMP3]], [[TMP3]] : !moore.uarray<6 x i4>, !moore.uarray<6 x i4>, !moore.uarray<6 x i4> -> uarray<3 x uarray<6 x i4>>
arr = '{3{'{2{4'd1, 4'd2, 4'd3}}}};

// CHECK: [[TMP0:%.+]] = moore.constant 0 :
// CHECK: [[TMP1:%.+]] = moore.constant 0 :
// CHECK: [[TMP2:%.+]] = moore.constant 1 :
// CHECK: [[TMP3:%.+]] = moore.constant 0 :
// CHECK: moore.concat [[TMP3]], [[TMP2]], [[TMP1]], [[TMP0]] : (!moore.l1, !moore.l1, !moore.l1, !moore.l1) -> l4
m = '{default: '0, 2: '1};

//===------------------------------------------------------------------===//
// Builtin Functions
Expand Down

0 comments on commit a7f1773

Please sign in to comment.