Skip to content

Commit

Permalink
Add basic tests for OutputDirAnnotation
Browse files Browse the repository at this point in the history
  • Loading branch information
rwy7 committed May 6, 2024
1 parent a4e35cc commit dcc6aac
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Dialect/FIRRTL/Transforms/LowerAnnotations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ static LogicalResult applyOutputDirAnno(const AnnoPathValue &target,
tryGetAs<StringAttr>(anno, anno, "dirname", loc, outputDirAnnoClass);
if (!dirname)
return failure();
if (dirname.empty())
return error() << "dirname must not be empty";

auto outputFile =
hw::OutputFileAttr::getAsDirectory(context, dirname.getValue());
Expand Down
16 changes: 16 additions & 0 deletions test/Dialect/FIRRTL/annotations-errors.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,19 @@ firrtl.circuit "Issue5947"
%mem = chirrtl.combmem : !chirrtl.cmemory<uint<1>, 2>
}
}

// -----
// An empty directory on an OutputDirAnnotation should fail.

// expected-error @below {{Unable to apply annotation: {class = "circt.OutputDirAnnotation", dirname = "", target = "~Top|Top"}}}
firrtl.circuit "Top" attributes {
rawAnnotations = [
{
class = "circt.OutputDirAnnotation",
dirname = "",
target = "~Top|Top"
}]
} {
// expected-error @below {{circt.OutputDirAnnotation dirname must not be empty}}
firrtl.module @Top() {}
}
16 changes: 16 additions & 0 deletions test/Dialect/FIRRTL/annotations.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -1905,3 +1905,19 @@ firrtl.circuit "Top" attributes {
firrtl.instance dut @DUT()
}
}

// -----

// CHECK-LABEL: firrtl.circuit "Top"
firrtl.circuit "Top" attributes {
rawAnnotations = [
{
class = "circt.OutputDirAnnotation",
dirname = "foobarbaz",
target = "~Top|Top"
}]
} {
// CHECK-LABEL: firrtl.module @Top
// CHECK-SAME: attributes {output_file = #hw.output_file<"foobarbaz/">}
firrtl.module @Top() {}
}

0 comments on commit dcc6aac

Please sign in to comment.