Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] Add verifier of single MarkDUTAnnotation #7633

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/Dialect/FIRRTL/FIRRTLOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "circt/Dialect/FIRRTL/FIRRTLOps.h"
#include "circt/Dialect/FIRRTL/AnnotationDetails.h"
#include "circt/Dialect/FIRRTL/CHIRRTLDialect.h"
#include "circt/Dialect/FIRRTL/FIRRTLAnnotations.h"
#include "circt/Dialect/FIRRTL/FIRRTLAttributes.h"
Expand Down Expand Up @@ -627,14 +628,32 @@ LogicalResult CircuitOp::verifyRegions() {
return success();
};

SmallVector<FModuleOp, 1> dutModules;
for (auto &op : *getBodyBlock()) {
// Verify modules.
if (auto moduleOp = dyn_cast<FModuleOp>(op)) {
if (AnnotationSet(moduleOp).hasAnnotation(dutAnnoClass))
dutModules.push_back(moduleOp);
continue;
}

// Verify external modules.
if (auto extModule = dyn_cast<FExtModuleOp>(op)) {
if (verifyExtModule(extModule).failed())
return failure();
}
}

// Error if there is more than one design-under-test.
if (dutModules.size() > 1) {
auto diag = dutModules[0]->emitOpError()
<< "is annotated as the design-under-test (DUT), but other "
"modules are also annotated";
for (auto moduleOp : ArrayRef(dutModules).drop_front())
diag.attachNote(moduleOp.getLoc()) << "is also annotated as the DUT";
return failure();
}

return success();
}

Expand Down
30 changes: 30 additions & 0 deletions test/Dialect/FIRRTL/errors.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2561,3 +2561,33 @@ firrtl.circuit "MainNotModule" {
return
}
}

// -----

firrtl.circuit "MultipleDUTModules" {
firrtl.module @MultipleDUTModules() {}
// expected-error @below {{is annotated as the design-under-test}}
firrtl.module @Foo() attributes {
annotations = [
{
class = "sifive.enterprise.firrtl.MarkDUTAnnotation"
}
]
} {}
// expected-note @below {{is also annotated as the DUT}}
firrtl.module @Bar() attributes {
annotations = [
{
class = "sifive.enterprise.firrtl.MarkDUTAnnotation"
}
]
} {}
// expected-note @below {{is also annotated as the DUT}}
firrtl.module @Baz() attributes {
annotations = [
{
class = "sifive.enterprise.firrtl.MarkDUTAnnotation"
}
]
} {}
}
Loading