Skip to content

Commit

Permalink
Add a fir version check for colored probes
Browse files Browse the repository at this point in the history
  • Loading branch information
rwy7 committed Jan 24, 2024
1 parent ca10d33 commit d87caf0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
32 changes: 19 additions & 13 deletions lib/Dialect/FIRRTL/Import/FIRParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,25 +934,31 @@ ParseResult FIRParser::parseType(FIRRTLType &result, const Twine &message) {
auto kind = getToken().getKind();
auto loc = getToken().getLoc();
consumeToken();
FIRRTLType type;
SmallVector<StringRef> layers;

// Inner Type
FIRRTLType type;
if (parseToken(FIRToken::less, "expected '<' in reference type") ||
parseType(type, "expected probe data type"))
return failure();
while (getToken().getKind() == FIRToken::identifier) {
StringRef layer;
loc = getToken().getLoc();
(void)parseId(layer, "expected layer name");
layers.push_back(layer);
if (getToken().getKind() == FIRToken::period)
consumeToken();
}
if (!consumeIf(FIRToken::greater)) {
emitError(loc, "expected '>' to end reference type");
return failure();

// Probe Color
SmallVector<StringRef> layers;
if (getToken().getKind() == FIRToken::identifier) {
if (requireFeature({3, 2, 0}, "colored probes"))
return failure();
do {
StringRef layer;
loc = getToken().getLoc();
(void)parseId(layer, "expected layer name");
layers.push_back(layer);
if (getToken().getKind() == FIRToken::period)
consumeToken();
} while (getToken().getKind() == FIRToken::identifier);
}

if (!consumeIf(FIRToken::greater))
return emitError(loc, "expected '>' to end reference type");

bool forceable = kind == FIRToken::kw_RWProbe;

auto innerType = type_dyn_cast<FIRRTLBaseType>(type);
Expand Down
31 changes: 31 additions & 0 deletions test/Dialect/FIRRTL/parse-errors.fir
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,37 @@ circuit Foo:
FPGA
FPGA

;// -----
FIRRTL version 3.1.0
circuit Foo:

module Foo:
; expected-error @below {{colored probes are a FIRRTL 3.2.0+ feature, but the specified FIRRTL version was 3.1.0}}
output a: Probe<UInt<1>, A>

;// -----
FIRRTL version 4.0.0
circuit Foo:
layer A bind:
module Foo:
output a: Probe<
; expected-error @below {{expected probe data type}}
;// -----
FIRRTL version 4.0.0
circuit Foo:
layer A bind:
module Foo:
; expected-error @below {{expected '<' in reference type}}
output a: Probe X

;// -----
FIRRTL version 4.0.0
circuit Foo:
layer A bind:
module Foo:
; expected-error @below {{expected probe data type}}
output a: Probe<>

;// -----
FIRRTL version 4.0.0
circuit Foo:
Expand Down

0 comments on commit d87caf0

Please sign in to comment.