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

[ImportVerilog] Distinguish the index up or down on the range selection. #7280

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions lib/Conversion/ImportVerilog/Expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,23 @@ struct RvalueExprVisitor {
<< slang::ast::toString(expr.getSelectionKind()) << "kind";
return {};
}
} else if (expr.getSelectionKind() ==
slang::ast::RangeSelectionKind::IndexedDown) {
// IndexedDown: arr[7-:8]. It's equivalent to arr[7:0] or arr[0:7]
// depending on little endian or bit endian. No matter which situation,
// the low bit must be "0".
auto minuend = context.convertRvalueExpression(expr.left());
auto minuendType = cast<moore::UnpackedType>(minuend.getType());
auto intType = moore::IntType::get(context.getContext(),
minuendType.getBitSize().value(),
minuendType.getDomain());
auto sliceWidth =
expr.right().constant->integer().as<uint64_t>().value() - 1;
hailongSun2000 marked this conversation as resolved.
Show resolved Hide resolved
auto subtraction =
builder.create<moore::ConstantOp>(loc, intType, sliceWidth);
lowBit = builder.create<moore::SubOp>(loc, minuend, subtraction);
} else
// IndexedUp: arr[0+:8]. "0" is the low bit, "8" is the bits slice width.
lowBit = context.convertRvalueExpression(expr.left());

if (!type || !value || !lowBit)
Expand Down Expand Up @@ -653,7 +669,23 @@ struct LvalueExprVisitor {
<< slang::ast::toString(expr.getSelectionKind()) << "kind";
return {};
}
} else if (expr.getSelectionKind() ==
slang::ast::RangeSelectionKind::IndexedDown) {
// IndexedDown: arr[7-:8]. It's equivalent to arr[7:0] or arr[0:7]
// depending on little endian or bit endian. No matter which situation,
// the low bit must be "0".
auto minuend = context.convertRvalueExpression(expr.left());
auto minuendType = cast<moore::UnpackedType>(minuend.getType());
auto intType = moore::IntType::get(context.getContext(),
minuendType.getBitSize().value(),
minuendType.getDomain());
auto sliceWidth =
expr.right().constant->integer().as<uint64_t>().value() - 1;
auto subtraction =
builder.create<moore::ConstantOp>(loc, intType, sliceWidth);
lowBit = builder.create<moore::SubOp>(loc, minuend, subtraction);
} else
// IndexedUp: arr[0+:8]. "0" is the low bit, "8" is the bits slice width.
lowBit = context.convertRvalueExpression(expr.left());

if (!type || !value || !lowBit)
Expand Down
10 changes: 9 additions & 1 deletion test/Conversion/ImportVerilog/basic.sv
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ module Expressions;
// CHECK: [[TMP2:%.+]] = moore.constant 1 : i32
// CHECK: [[TMP3:%.+]] = moore.read %a : i32
// CHECK: [[TMP4:%.+]] = moore.mul [[TMP2]], [[TMP3]] : i32
// CHECK: moore.extract [[TMP1]] from [[TMP4]] : l32, i32 -> l1
// CHECK: [[TMP5:%.+]] = moore.constant 0 : i32
// CHECK: [[TMP6:%.+]] = moore.sub [[TMP4]], [[TMP5]] : i32
// CHECK: moore.extract [[TMP1]] from [[TMP6]] : l32, i32 -> l1
c = vec_1[1*a-:1];
// CHECK: [[TMP1:%.+]] = moore.read %arr : uarray<3 x uarray<6 x i4>>
// CHECK: [[TMP2:%.+]] = moore.constant 3 : i32
Expand Down Expand Up @@ -504,6 +506,12 @@ module Expressions;
// CHECK: [[X_READ:%.+]] = moore.read %x : i1
// CHECK: moore.extract_ref %vec_1 from [[X_READ]] : <l32>, i1 -> <l1>
vec_1[x] = y;

// CHECK: [[CONST_15:%.+]] = moore.constant 15 : i32
// CHECK: [[CONST_2:%.+]] = moore.constant 2 : i32
// CHECK: [[SUB:%.+]] = moore.sub [[CONST_15]], [[CONST_2]] : i32
// CHECK: moore.extract_ref %vec_1 from [[SUB]] : <l32>, i32 -> <l3>
vec_1[15-:3] = y;

//===------------------------------------------------------------------===//
// Unary operators
Expand Down
Loading