Skip to content

Commit

Permalink
[NFC][Seq] Fix the parsing of seq.firreg presets
Browse files Browse the repository at this point in the history
  • Loading branch information
nandor committed Nov 15, 2023
1 parent dac8f0b commit f124fb0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
23 changes: 14 additions & 9 deletions lib/Dialect/Seq/SeqOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,20 +434,25 @@ ParseResult FirRegOp::parse(OpAsmParser &parser, OperationState &result) {
return failure();
}

Type ty;
std::optional<int64_t> presetValue;
if (succeeded(parser.parseOptionalKeyword("preset"))) {
IntegerAttr preset;
if (parser.parseAttribute(preset, "preset", result.attributes) ||
parser.parseOptionalAttrDict(result.attributes))
return failure();
ty = preset.getType();
} else {
if (parser.parseOptionalAttrDict(result.attributes) ||
parser.parseColon() || parser.parseType(ty))
int64_t presetInt;
if (parser.parseInteger(presetInt))
return failure();
presetValue = presetInt;
}

Type ty;
if (parser.parseOptionalAttrDict(result.attributes) || parser.parseColon() ||
parser.parseType(ty))
return failure();
result.addTypes({ty});

if (presetValue) {
result.addAttribute("preset",
parser.getBuilder().getIntegerAttr(ty, *presetValue));
}

setNameFromResult(parser, result);

if (parser.resolveOperand(next, ty, result.operands))
Expand Down
6 changes: 4 additions & 2 deletions test/Dialect/Seq/round-trip.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ hw.module @fifo2(in %clk : !seq.clock, in %rst : i1, in %in : i32, in %rdEn : i1


hw.module @preset(in %clock : !seq.clock, in %reset : i1, in %next : i32) {
// CHECK: %reg = seq.firreg %next clock %clock preset 0 : i32
%reg = seq.firreg %next clock %clock preset 0 : i32
// CHECK: %a = seq.firreg %next clock %clock preset 0 : i32
%a = seq.firreg %next clock %clock preset 0 : i32
// CHECK: %b = seq.firreg %next clock %clock preset 0 {sv.namehint = "x"} : i32
%b = seq.firreg %next clock %clock preset 0 {sv.namehint = "x"} : i32
}

hw.module @clock_dividers(in %clock: !seq.clock) {
Expand Down

0 comments on commit f124fb0

Please sign in to comment.