Skip to content

Commit

Permalink
[FIRRTL] Parse Layer-Associated Probes
Browse files Browse the repository at this point in the history
Add support to the FIRRTL parse to handle probes associated with layers.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
  • Loading branch information
seldridge committed Jan 5, 2024
1 parent 79efb90 commit fad9d10
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
26 changes: 23 additions & 3 deletions lib/Dialect/FIRRTL/Import/FIRParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,10 +935,20 @@ ParseResult FIRParser::parseType(FIRRTLType &result, const Twine &message) {
auto loc = getToken().getLoc();
consumeToken();
FIRRTLType type;
SmallVector<StringRef> layers;

if (parseToken(FIRToken::less, "expected '<' in reference type") ||
parseType(type, "expected probe data type") ||
parseToken(FIRToken::greater, "expected '>' in reference type"))
parseType(type, "expected probe data type"))
return failure();
while (getToken().getKind() == FIRToken::identifier) {
StringRef layer;
if (parseId(layer, "expected layer name"))
return failure();
layers.push_back(layer);
if (getToken().getKind() == FIRToken::period)
consumeToken();
}
if (parseToken(FIRToken::greater, "expected '>' in reference type"))
return failure();

bool forceable = kind == FIRToken::kw_RWProbe;
Expand All @@ -953,7 +963,17 @@ ParseResult FIRParser::parseType(FIRRTLType &result, const Twine &message) {
if (forceable && innerType.containsConst())
return emitError(loc, "rwprobe cannot contain const");

result = RefType::get(innerType, forceable);
SymbolRefAttr layer;
if (!layers.empty()) {
auto nestedLayers =
llvm::map_range(ArrayRef(layers).drop_front(), [&](StringRef a) {
return FlatSymbolRefAttr::get(getContext(), a);
});
layer = SymbolRefAttr::get(getContext(), layers.front(),
llvm::to_vector(nestedLayers));
}

result = RefType::get(innerType, forceable, layer);
break;
}

Expand Down
6 changes: 5 additions & 1 deletion test/Dialect/FIRRTL/parse-basic.fir
Original file line number Diff line number Diff line change
Expand Up @@ -1671,9 +1671,13 @@ circuit Layers:
; CHECK-NEXT: }
; CHECK-NEXT: }

; CHECK: firrtl.module @Layers
; CHECK: firrtl.module @Layers
; CHECK-SAME: out %b: !firrtl.probe<uint<1>, @A>
; CHECK-SAME: out %c: !firrtl.rwprobe<uint<1>, @A::@B>
module Layers:
input a: UInt<1>
output b: Probe<UInt<1>, A>
output c: RWProbe<UInt<1>, A.B>

layerblock A:
node A_a = a
Expand Down

0 comments on commit fad9d10

Please sign in to comment.