Skip to content

Commit

Permalink
[FIRRTL] Add parser version APIs that accept an SMLoc, NFC. (#6692)
Browse files Browse the repository at this point in the history
These currently default to calling emitError(), which uses the current
token's location. In some cases, the current token may have been
consumed by the time we wish to check versions and potentially emit
errors. This allows users to supply an SMLoc if necessary, and
otherwise defaults to the previous behavior.

None of our current parsing actually consumes a token before checking
versions, but I would like to add a version check to an existing
parser that will come after it has consumed the token.
  • Loading branch information
mikeurbach authored Feb 14, 2024
1 parent 6784f59 commit 6a5f2b6
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/Dialect/FIRRTL/Import/FIRParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,27 @@ struct FIRParser {
//===--------------------------------------------------------------------===//

ParseResult requireFeature(FIRVersion minimum, StringRef feature) {
return requireFeature(minimum, feature, getToken().getLoc());
}

ParseResult requireFeature(FIRVersion minimum, StringRef feature, SMLoc loc) {
if (version < minimum)
return emitError() << feature << " are a FIRRTL " << minimum
<< "+ feature, but the specified FIRRTL version was "
<< version;
return emitError(loc)
<< feature << " are a FIRRTL " << minimum
<< "+ feature, but the specified FIRRTL version was " << version;
return success();
}

ParseResult removedFeature(FIRVersion removedVersion, StringRef feature) {
return removedFeature(removedVersion, feature, getToken().getLoc());
}

ParseResult removedFeature(FIRVersion removedVersion, StringRef feature,
SMLoc loc) {
if (version >= removedVersion)
return emitError() << feature << " were removed in FIRRTL "
<< removedVersion
<< ", but the specified FIRRTL version was "
<< version;
return emitError(loc)
<< feature << " were removed in FIRRTL " << removedVersion
<< ", but the specified FIRRTL version was " << version;
return success();
}

Expand Down

0 comments on commit 6a5f2b6

Please sign in to comment.