Skip to content

Commit

Permalink
updated signature for getNInputs
Browse files Browse the repository at this point in the history
  • Loading branch information
dobios committed Jun 18, 2024
1 parent 0fc549b commit 39239b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions include/circt/Dialect/FIRRTL/FIRRTLIntrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ struct GenericIntrinsic {
// Input checking
//===--------------------------------------------------------------------===//

ParseResult hasNInputs(unsigned n);
ParseResult hasNInputs(unsigned n, unsigned m);
ParseResult hasNInputs(unsigned n, unsigned c);
unsigned getNumInputs();

template <typename C>
Expand Down
26 changes: 12 additions & 14 deletions lib/Dialect/FIRRTL/FIRRTLIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@ using namespace firrtl;
// GenericIntrinsic
//===----------------------------------------------------------------------===//

ParseResult GenericIntrinsic::hasNInputs(unsigned n) {
if (op.getNumOperands() != n)
return emitError() << " has " << op.getNumOperands()
<< " inputs instead of " << n;
return success();
}

// Checks for a number of operands between n and m (allows for (n-m) optional
// parameters)
ParseResult GenericIntrinsic::hasNInputs(unsigned n, unsigned m) {
// Checks for a number of operands between n and n+c (allows for c optional
// inputs)
ParseResult GenericIntrinsic::hasNInputs(unsigned n, unsigned c = 0U) {
auto numOps = op.getNumOperands();
if (!(n <= numOps && numOps <= m))
return emitError() << " has " << op.getNumOperands()
<< " inputs, which is not within [" << n << ", " << m
<< "]";
unsigned m = n + c;
if (!(n <= numOps && numOps <= m)) {
auto err = emitError() << " has " << numOps << " inputs instead of ";
if (c == 0)
err << n;
else
err << " between " << n << " and " << m;
return failure();
}
return success();
}

Expand Down

0 comments on commit 39239b4

Please sign in to comment.