Skip to content

Commit

Permalink
Add support CaseStatementCondition::Inside
Browse files Browse the repository at this point in the history
  • Loading branch information
ankolesn committed Dec 1, 2024
1 parent 515ce89 commit 9c679a1
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/Conversion/ImportVerilog/Statements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,32 @@ struct StmtVisitor {
cond = builder.create<moore::CaseZEqOp>(itemLoc, caseExpr, value);
break;
case CaseStatementCondition::Inside:
mlir::emitError(loc, "unsupported set membership case statement");
return failure();
std::vector<Value> values;
values.reserve(item.expressions.size());
for (const auto *expr : item.expressions) {
auto value = context.convertRvalueExpression(*expr);
if (!value)
return failure();
values.push_back(value);
}

if (values.empty()) {
mlir::emitError(loc, "empty set in inside case statement");
return failure();
}

if (values.size() == 1) {
cond = builder.create<moore::CaseEqOp>(
loc, caseExpr, values.front());
} else {
cond = builder.create<moore::CaseEqOp>(loc, caseExpr, values[0]);
for (size_t i = 1; i < values.size(); ++i) {
auto nextCond = builder.create<moore::CaseEqOp>(
loc, caseExpr, values[i]);
cond = builder.create<mlir::arith::OrIOp>(loc, builder.getI1Type(), cond,
nextCond);
}
}
}
cond = builder.create<moore::ConversionOp>(itemLoc, builder.getI1Type(),
cond);
Expand Down

0 comments on commit 9c679a1

Please sign in to comment.