Skip to content

Commit

Permalink
[slang] Fix bug with SignalEventControl iff clause emitting. (#1019)
Browse files Browse the repository at this point in the history
Add support for iffConfition serialize.

Co-authored-by: Yan Churkin <yan@ispras.ru>
  • Loading branch information
likeamahoney and Yan Churkin committed Jun 3, 2024
1 parent 04dedf0 commit 2d42130
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 1 deletion.
5 changes: 4 additions & 1 deletion source/ast/TimingControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ TimingControl& SignalEventControl::fromSyntax(Compilation& compilation,
SLANG_ASSERT(syntax.kind == SyntaxKind::IffPropertyExpr);

auto left = context.requireSimpleExpr(*syntax.left, diag::InvalidSyntaxInEventExpr);
auto right = context.requireSimpleExpr(*syntax.left, diag::InvalidSyntaxInEventExpr);
auto right = context.requireSimpleExpr(*syntax.right, diag::InvalidSyntaxInEventExpr);
if (!left || !right)
return badCtrl(compilation, nullptr);

Expand Down Expand Up @@ -353,6 +353,9 @@ TimingControl& SignalEventControl::fromExpr(Compilation& compilation, EdgeKind e
void SignalEventControl::serializeTo(ASTSerializer& serializer) const {
serializer.write("expr", expr);
serializer.write("edge", toString(edge));

if (iffCondition)
serializer.write("iff", *iffCondition);
}

static void collectEvents(const ASTContext& context, const SyntaxNode& expr,
Expand Down
217 changes: 217 additions & 0 deletions tests/unittests/ast/MemberTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2472,3 +2472,220 @@ endmodule
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}

TEST_CASE("JSON dump -- sequence with `iff` clause") {
auto tree = SyntaxTree::fromText(R"(
logic x, y;
sequence s (ev);
@(ev) x ##1 y;
endsequence
module m(input y1, input x1, input clk);
cover property (s(((x1 iff y1) or negedge clk)));
endmodule
)");

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

JsonWriter writer;
writer.setPrettyPrint(true);

ASTSerializer serializer(compilation, writer);
serializer.setIncludeAddresses(false);
serializer.serialize(compilation.getRoot());

std::string result = "\n"s + std::string(writer.view());
CHECK(result == R"(
{
"name": "$root",
"kind": "Root",
"members": [
{
"name": "",
"kind": "CompilationUnit",
"members": [
{
"name": "x",
"kind": "Variable",
"type": "logic",
"lifetime": "Static"
},
{
"name": "y",
"kind": "Variable",
"type": "logic",
"lifetime": "Static"
},
{
"name": "s",
"kind": "Sequence",
"members": [
{
"name": "ev",
"kind": "AssertionPort"
}
]
}
]
},
{
"name": "m",
"kind": "Instance",
"body": {
"name": "m",
"kind": "InstanceBody",
"members": [
{
"name": "y1",
"kind": "Port",
"type": "logic",
"direction": "In",
"internalSymbol": "y1"
},
{
"name": "y1",
"kind": "Net",
"type": "logic",
"netType": {
"name": "wire",
"kind": "NetType",
"type": "logic"
}
},
{
"name": "x1",
"kind": "Port",
"type": "logic",
"direction": "In",
"internalSymbol": "x1"
},
{
"name": "x1",
"kind": "Net",
"type": "logic",
"netType": {
"name": "wire",
"kind": "NetType",
"type": "logic"
}
},
{
"name": "clk",
"kind": "Port",
"type": "logic",
"direction": "In",
"internalSymbol": "clk"
},
{
"name": "clk",
"kind": "Net",
"type": "logic",
"netType": {
"name": "wire",
"kind": "NetType",
"type": "logic"
}
},
{
"name": "",
"kind": "ProceduralBlock",
"procedureKind": "Always",
"body": {
"kind": "ConcurrentAssertion",
"propertySpec": {
"kind": "Simple",
"expr": {
"kind": "AssertionInstance",
"type": "sequence",
"symbol": "s",
"body": {
"kind": "Clocking",
"clocking": {
"kind": "SignalEvent",
"expr": {
"kind": "ClockingEvent",
"type": "void",
"timingControl": {
"kind": "EventList",
"events": [
{
"kind": "SignalEvent",
"expr": {
"kind": "NamedValue",
"type": "logic",
"symbol": "x1"
},
"edge": "None",
"iff": {
"kind": "NamedValue",
"type": "logic",
"symbol": "y1"
}
},
{
"kind": "SignalEvent",
"expr": {
"kind": "NamedValue",
"type": "logic",
"symbol": "clk"
},
"edge": "NegEdge"
}
]
}
},
"edge": "None"
},
"expr": {
"kind": "SequenceConcat",
"elements": [
{
"sequence": {
"kind": "Simple",
"expr": {
"kind": "NamedValue",
"type": "logic",
"symbol": "x"
}
},
"min": 0,
"max": 0
},
{
"sequence": {
"kind": "Simple",
"expr": {
"kind": "NamedValue",
"type": "logic",
"symbol": "y"
}
},
"min": 1,
"max": 1
}
]
}
},
"isRecursiveProperty": false,
"localVars": [
]
}
},
"ifTrue": {
"kind": "Empty"
},
"assertionKind": "CoverProperty"
}
}
],
"definition": "m"
},
"connections": [
]
}
]
})");
}

0 comments on commit 2d42130

Please sign in to comment.