Skip to content

Commit

Permalink
Error if virtual interface assignment has a config rule applied
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Dec 24, 2024
1 parent f6d65c8 commit 63e08c1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/slang/ast/symbols/CompilationUnitSymbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ struct SLANG_EXPORT ResolvedConfig {
/// A list of libraries to use to look up definitions.
std::span<const SourceLibrary* const> liblist;

/// The original rule that led to this resolved configuration.
const ConfigRule* configRule = nullptr;

ResolvedConfig(const ConfigBlockSymbol& useConfig, const InstanceSymbol& rootInstance);
};

Expand Down
1 change: 1 addition & 0 deletions scripts/diagnostics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ error InvalidExtendsDefault "constructor must use 'default' in its argument list
error NonblockingDynamicAssign "nonblocking assignments to elements of dynamically sized arrays are not allowed"
error VoidAssignment "expression of type 'void' cannot be used in assignments"
error VirtualIfaceDefparam "interface instance cannot be assigned to a virtual interface because it is the target of a defparam or bind directive"
error VirtualIfaceConfigRule "interface instance cannot be assigned to a virtual interface because it is the target of config rule"
error MultipleDefaultDistWeight "'default' cannot be used more than once in dist item list"
error DistRealRangeWeight "'dist' for a range of real values must include an explicit weight and must use the ':/' operator"
warning ignored-slice IgnoredSlice "slice size ignored for left-to-right streaming operator"
Expand Down
10 changes: 10 additions & 0 deletions source/ast/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,16 @@ Expression* Expression::tryBindInterfaceRef(const ASTContext& context,
diag.addNote(diag::NoteDeclarationHere, source->sourceRange());
}

if (iface->parentInstance && iface->parentInstance->resolvedConfig) {
auto& diag = context.addDiag(diag::VirtualIfaceConfigRule, sourceRange);

auto rc = iface->parentInstance->resolvedConfig;
if (rc->configRule)
diag.addNote(diag::NoteConfigRule, rc->configRule->syntax->sourceRange());
else
diag.addNote(diag::NoteConfigRule, rc->useConfig.location);
}

if (!arrayModportName.empty()) {
if (modport) {
// If we connected via an interface port that itself has a modport restriction,
Expand Down
4 changes: 4 additions & 0 deletions source/ast/symbols/InstanceSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ InstanceSymbol& InstanceSymbol::createDefault(Compilation& comp, const Definitio

if (configBlock) {
auto rc = comp.emplace<ResolvedConfig>(*configBlock, result);
rc->configRule = configRule;

if (configRule) {
configRule->isUsed = true;
if (configRule->liblist)
Expand Down Expand Up @@ -669,6 +671,8 @@ void InstanceSymbol::fromSyntax(Compilation& comp, const HierarchyInstantiationS
if (confRule) {
SLANG_ASSERT(resolvedConfig);
auto rc = comp.emplace<ResolvedConfig>(*resolvedConfig);
rc->configRule = confRule;

confRule->isUsed = true;
if (confRule->liblist)
rc->liblist = *confRule->liblist;
Expand Down
27 changes: 27 additions & 0 deletions tests/unittests/ast/ConfigTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,3 +1243,30 @@ endmodule : cmp
NO_COMPILATION_ERRORS;
}
}

TEST_CASE("Configs with virtual interfaces") {
auto tree = SyntaxTree::fromText(R"(
config cfg1;
design top;
instance top.i use J;
cell I use J;
endconfig
interface J;
endinterface
module top;
I i();
virtual I vi = i;
endmodule
)");
CompilationOptions options;
options.topModules.emplace("cfg1");

Compilation compilation(options);
compilation.addSyntaxTree(tree);

auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::VirtualIfaceConfigRule);
}

0 comments on commit 63e08c1

Please sign in to comment.