From dcc6aacbafa9fcd75f2770f6dd34aab9330d24e3 Mon Sep 17 00:00:00 2001 From: Robert Young Date: Mon, 6 May 2024 12:41:15 -0700 Subject: [PATCH] Add basic tests for OutputDirAnnotation --- .../FIRRTL/Transforms/LowerAnnotations.cpp | 2 ++ test/Dialect/FIRRTL/annotations-errors.mlir | 16 ++++++++++++++++ test/Dialect/FIRRTL/annotations.mlir | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/lib/Dialect/FIRRTL/Transforms/LowerAnnotations.cpp b/lib/Dialect/FIRRTL/Transforms/LowerAnnotations.cpp index d46a3cc9b879..33e5d3677d4f 100644 --- a/lib/Dialect/FIRRTL/Transforms/LowerAnnotations.cpp +++ b/lib/Dialect/FIRRTL/Transforms/LowerAnnotations.cpp @@ -409,6 +409,8 @@ static LogicalResult applyOutputDirAnno(const AnnoPathValue &target, tryGetAs(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()); diff --git a/test/Dialect/FIRRTL/annotations-errors.mlir b/test/Dialect/FIRRTL/annotations-errors.mlir index 67c8696a436b..80dfdd4c3e7b 100644 --- a/test/Dialect/FIRRTL/annotations-errors.mlir +++ b/test/Dialect/FIRRTL/annotations-errors.mlir @@ -417,3 +417,19 @@ firrtl.circuit "Issue5947" %mem = chirrtl.combmem : !chirrtl.cmemory, 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() {} +} diff --git a/test/Dialect/FIRRTL/annotations.mlir b/test/Dialect/FIRRTL/annotations.mlir index c636d3d5544d..d638a02f765c 100644 --- a/test/Dialect/FIRRTL/annotations.mlir +++ b/test/Dialect/FIRRTL/annotations.mlir @@ -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() {} +}