Support disabling a fork from outside that fork (#6174)
This commit is contained in:
parent
2f199f20cf
commit
e2e5d9eaf1
|
|
@ -175,6 +175,14 @@ package std;
|
||||||
`endif
|
`endif
|
||||||
endtask
|
endtask
|
||||||
|
|
||||||
|
static task killQueue(ref process processQueue[$]);
|
||||||
|
`ifdef VERILATOR_TIMING
|
||||||
|
while (processQueue.size() > 0) begin
|
||||||
|
processQueue.pop_back().kill();
|
||||||
|
end
|
||||||
|
`endif
|
||||||
|
endtask
|
||||||
|
|
||||||
// Two process references are equal if the different classes' containing
|
// Two process references are equal if the different classes' containing
|
||||||
// m_process are equal. Can't yet use <=> as the base class template
|
// m_process are equal. Can't yet use <=> as the base class template
|
||||||
// comparisons doesn't define <=> as they don't yet require --timing and C++20.
|
// comparisons doesn't define <=> as they don't yet require --timing and C++20.
|
||||||
|
|
|
||||||
|
|
@ -1974,7 +1974,7 @@ class AstVar final : public AstNode {
|
||||||
bool m_isConst : 1; // Table contains constant data
|
bool m_isConst : 1; // Table contains constant data
|
||||||
bool m_isContinuously : 1; // Ever assigned continuously (for force/release)
|
bool m_isContinuously : 1; // Ever assigned continuously (for force/release)
|
||||||
bool m_hasStrengthAssignment : 1; // Is on LHS of assignment with strength specifier
|
bool m_hasStrengthAssignment : 1; // Is on LHS of assignment with strength specifier
|
||||||
bool m_isStatic : 1; // Static C variable (for Verilog see instead isAutomatic)
|
bool m_isStatic : 1; // Static C variable (for Verilog see instead lifetime())
|
||||||
bool m_isPulldown : 1; // Tri0
|
bool m_isPulldown : 1; // Tri0
|
||||||
bool m_isPullup : 1; // Tri1
|
bool m_isPullup : 1; // Tri1
|
||||||
bool m_isIfaceParent : 1; // dtype is reference to interface present in this module
|
bool m_isIfaceParent : 1; // dtype is reference to interface present in this module
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
#include "V3AstUserAllocator.h"
|
#include "V3AstUserAllocator.h"
|
||||||
#include "V3Error.h"
|
#include "V3Error.h"
|
||||||
|
#include "V3UniqueNames.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
@ -60,6 +61,8 @@ class LinkJumpVisitor final : public VNVisitor {
|
||||||
int m_modRepeatNum = 0; // Repeat counter
|
int m_modRepeatNum = 0; // Repeat counter
|
||||||
VOptionBool m_unrollFull; // Pragma full, disable, or default unrolling
|
VOptionBool m_unrollFull; // Pragma full, disable, or default unrolling
|
||||||
std::vector<AstNodeBlock*> m_blockStack; // All begin blocks above current node
|
std::vector<AstNodeBlock*> m_blockStack; // All begin blocks above current node
|
||||||
|
V3UniqueNames m_queueNames{
|
||||||
|
"__VprocessQueue"}; // Names for queues needed for 'disable' handling
|
||||||
|
|
||||||
// METHODS
|
// METHODS
|
||||||
AstJumpLabel* findAddLabel(AstNode* nodep, bool endOfIter) {
|
AstJumpLabel* findAddLabel(AstNode* nodep, bool endOfIter) {
|
||||||
|
|
@ -159,6 +162,29 @@ class LinkJumpVisitor final : public VNVisitor {
|
||||||
if (AstNode* const refp = nodep->op4p()) addPrefixToBlocksRecurse(prefix, refp);
|
if (AstNode* const refp = nodep->op4p()) addPrefixToBlocksRecurse(prefix, refp);
|
||||||
if (AstNode* const refp = nodep->nextp()) addPrefixToBlocksRecurse(prefix, refp);
|
if (AstNode* const refp = nodep->nextp()) addPrefixToBlocksRecurse(prefix, refp);
|
||||||
}
|
}
|
||||||
|
static AstNode* getMemberp(const AstNodeModule* const nodep, const std::string& name) {
|
||||||
|
for (AstNode* itemp = nodep->stmtsp(); itemp; itemp = itemp->nextp()) {
|
||||||
|
if (itemp->name() == name) return itemp;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
bool existsBlockAbove(const std::string& name) const {
|
||||||
|
for (const AstNodeBlock* const stackp : vlstd::reverse_view(m_blockStack)) {
|
||||||
|
if (stackp->name() == name) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
static AstStmtExpr* getQueuePushProcessSelfp(AstVarRef* const queueRefp) {
|
||||||
|
// Constructs queue.push_back(std::process::self()) statement
|
||||||
|
FileLine* const fl = queueRefp->fileline();
|
||||||
|
AstClass* const processClassp
|
||||||
|
= VN_AS(getMemberp(v3Global.rootp()->stdPackagep(), "process"), Class);
|
||||||
|
AstFunc* const selfMethodp = VN_AS(getMemberp(processClassp, "self"), Func);
|
||||||
|
AstFuncRef* const processSelfp = new AstFuncRef{fl, selfMethodp, nullptr};
|
||||||
|
processSelfp->classOrPackagep(processClassp);
|
||||||
|
return new AstStmtExpr{
|
||||||
|
fl, new AstMethodCall{fl, queueRefp, "push_back", new AstArg{fl, "", processSelfp}}};
|
||||||
|
}
|
||||||
|
|
||||||
// VISITORS
|
// VISITORS
|
||||||
void visit(AstNodeModule* nodep) override {
|
void visit(AstNodeModule* nodep) override {
|
||||||
|
|
@ -338,22 +364,65 @@ class LinkJumpVisitor final : public VNVisitor {
|
||||||
void visit(AstDisable* nodep) override {
|
void visit(AstDisable* nodep) override {
|
||||||
UINFO(8, " DISABLE " << nodep);
|
UINFO(8, " DISABLE " << nodep);
|
||||||
AstNode* const targetp = nodep->targetp();
|
AstNode* const targetp = nodep->targetp();
|
||||||
|
FileLine* const fl = nodep->fileline();
|
||||||
UASSERT_OBJ(targetp, nodep, "Unlinked disable statement");
|
UASSERT_OBJ(targetp, nodep, "Unlinked disable statement");
|
||||||
if (VN_IS(targetp, Task)) {
|
if (VN_IS(targetp, Task)) {
|
||||||
nodep->v3warn(E_UNSUPPORTED, "Unsupported: disabling task by name");
|
nodep->v3warn(E_UNSUPPORTED, "Unsupported: disabling task by name");
|
||||||
} else if (VN_IS(targetp, Fork)) {
|
} else if (AstFork* const forkp = VN_CAST(targetp, Fork)) {
|
||||||
nodep->v3warn(E_UNSUPPORTED, "Unsupported: disabling fork by name");
|
// The support is limited only to disabling a fork from outside that fork.
|
||||||
} else if (AstBegin* const beginp = VN_CAST(targetp, Begin)) {
|
// It utilizes the process::kill()` method. For each `disable` a queue of processes is
|
||||||
const std::string targetName = beginp->name();
|
// declared. At the beginning of each fork that can be disabled, its process handle is
|
||||||
bool aboveBlock = false;
|
// pushed to the queue. `disable` statement is replaced with calling `kill()` method on
|
||||||
for (AstNodeBlock* const stackp : vlstd::reverse_view(m_blockStack)) {
|
// each element of the queue.
|
||||||
UINFO(9, " UNDERBLK " << stackp);
|
if (existsBlockAbove(forkp->name())) {
|
||||||
if (stackp->name() == targetName) {
|
nodep->v3warn(E_UNSUPPORTED, "Unsupported: disabling fork from within same fork");
|
||||||
aboveBlock = true;
|
}
|
||||||
break;
|
if (m_ftaskp) {
|
||||||
|
nodep->v3warn(E_UNSUPPORTED, "Unsupported: disabling fork from task / function");
|
||||||
|
}
|
||||||
|
AstPackage* const topPkgp = v3Global.rootp()->dollarUnitPkgAddp();
|
||||||
|
AstClass* const processClassp
|
||||||
|
= VN_AS(getMemberp(v3Global.rootp()->stdPackagep(), "process"), Class);
|
||||||
|
// Declare queue of processes (as a global variable for simplicity)
|
||||||
|
AstVar* const processQueuep = new AstVar{
|
||||||
|
fl, VVarType::VAR, m_queueNames.get(forkp->name()), VFlagChildDType{},
|
||||||
|
new AstQueueDType{fl, VFlagChildDType{},
|
||||||
|
new AstClassRefDType{fl, processClassp, nullptr}, nullptr}};
|
||||||
|
processQueuep->lifetime(VLifetime::STATIC);
|
||||||
|
topPkgp->addStmtsp(processQueuep);
|
||||||
|
|
||||||
|
AstVarRef* const queueWriteRefp
|
||||||
|
= new AstVarRef{fl, topPkgp, processQueuep, VAccess::WRITE};
|
||||||
|
AstStmtExpr* const pushCurrentProcessp = getQueuePushProcessSelfp(queueWriteRefp);
|
||||||
|
|
||||||
|
for (AstNode* forkItemp = forkp->stmtsp(); forkItemp; forkItemp = forkItemp->nextp()) {
|
||||||
|
// Add push_back statement at the beginning of each fork.
|
||||||
|
// Wrap into begin block if needed
|
||||||
|
AstBegin* beginp = VN_CAST(forkItemp, Begin);
|
||||||
|
if (!beginp) {
|
||||||
|
beginp = new AstBegin{fl, "", nullptr};
|
||||||
|
forkItemp->replaceWith(beginp);
|
||||||
|
beginp->addStmtsp(forkItemp);
|
||||||
|
// In order to continue the iteration
|
||||||
|
forkItemp = beginp;
|
||||||
|
}
|
||||||
|
if (pushCurrentProcessp->backp()) {
|
||||||
|
beginp->stmtsp()->addHereThisAsNext(pushCurrentProcessp->cloneTree(false));
|
||||||
|
} else {
|
||||||
|
beginp->stmtsp()->addHereThisAsNext(pushCurrentProcessp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (aboveBlock) {
|
|
||||||
|
AstVarRef* const queueRefp
|
||||||
|
= new AstVarRef{fl, topPkgp, processQueuep, VAccess::READWRITE};
|
||||||
|
AstTaskRef* const killQueueCall
|
||||||
|
= new AstTaskRef{fl, VN_AS(getMemberp(processClassp, "killQueue"), Task),
|
||||||
|
new AstArg{fl, "", queueRefp}};
|
||||||
|
killQueueCall->classOrPackagep(processClassp);
|
||||||
|
nodep->addNextHere(new AstStmtExpr{fl, killQueueCall});
|
||||||
|
} else if (AstBegin* const beginp = VN_CAST(targetp, Begin)) {
|
||||||
|
const std::string targetName = beginp->name();
|
||||||
|
if (existsBlockAbove(targetName)) {
|
||||||
if (beginp->user3()) {
|
if (beginp->user3()) {
|
||||||
nodep->v3warn(E_UNSUPPORTED,
|
nodep->v3warn(E_UNSUPPORTED,
|
||||||
"Unsupported: disabling block that contains a fork");
|
"Unsupported: disabling block that contains a fork");
|
||||||
|
|
|
||||||
|
|
@ -293,12 +293,12 @@ public:
|
||||||
void dumpInputsFile() VL_MT_DISABLED;
|
void dumpInputsFile() VL_MT_DISABLED;
|
||||||
void dumpTokensAhead(int line) VL_MT_DISABLED;
|
void dumpTokensAhead(int line) VL_MT_DISABLED;
|
||||||
static void candidatePli(VSpellCheck* spellerp) VL_MT_DISABLED;
|
static void candidatePli(VSpellCheck* spellerp) VL_MT_DISABLED;
|
||||||
|
void importIfInStd(FileLine* fileline, const string& id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void preprocDumps(std::ostream& os);
|
void preprocDumps(std::ostream& os);
|
||||||
void lexFile(const string& modname) VL_MT_DISABLED;
|
void lexFile(const string& modname) VL_MT_DISABLED;
|
||||||
void yylexReadTok() VL_MT_DISABLED;
|
void yylexReadTok() VL_MT_DISABLED;
|
||||||
void importIfInStd(FileLine* fileline, const string& id);
|
|
||||||
void tokenPull() VL_MT_DISABLED;
|
void tokenPull() VL_MT_DISABLED;
|
||||||
void tokenPipeline() VL_MT_DISABLED; // Internal; called from tokenToBison
|
void tokenPipeline() VL_MT_DISABLED; // Internal; called from tokenToBison
|
||||||
int tokenPipelineId(int token) VL_MT_DISABLED;
|
int tokenPipelineId(int token) VL_MT_DISABLED;
|
||||||
|
|
|
||||||
|
|
@ -3754,7 +3754,9 @@ statement_item<nodep>: // IEEE: statement_item
|
||||||
// // IEEE: disable_statement
|
// // IEEE: disable_statement
|
||||||
| yDISABLE yFORK ';' { $$ = new AstDisableFork{$1}; }
|
| yDISABLE yFORK ';' { $$ = new AstDisableFork{$1}; }
|
||||||
| yDISABLE idDottedSel ';'
|
| yDISABLE idDottedSel ';'
|
||||||
{ $$ = new AstDisable{$1, $2}; }
|
{ $$ = new AstDisable{$1, $2};
|
||||||
|
PARSEP->importIfInStd($1, "process");
|
||||||
|
}
|
||||||
// // IEEE: event_trigger
|
// // IEEE: event_trigger
|
||||||
| yP_MINUSGT expr ';'
|
| yP_MINUSGT expr ';'
|
||||||
{ $$ = new AstFireEvent{$1, $2, false}; }
|
{ $$ = new AstFireEvent{$1, $2, false}; }
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
%Error-UNSUPPORTED: t/t_disable.v:11:10: Unsupported: disabling fork by name
|
%Error-UNSUPPORTED: t/t_disable.v:11:10: Unsupported: disabling fork from within same fork
|
||||||
11 | disable foo;
|
11 | disable foo;
|
||||||
| ^~~~~~~
|
| ^~~~~~~
|
||||||
... For error description see https://verilator.org/warn/UNSUPPORTED?v=latest
|
... For error description see https://verilator.org/warn/UNSUPPORTED?v=latest
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||||
|
#
|
||||||
|
# Copyright 2024 by Wilson Snyder. This program is free software; you
|
||||||
|
# can redistribute it and/or modify it under the terms of either the GNU
|
||||||
|
# Lesser General Public License Version 3 or the Perl Artistic License
|
||||||
|
# Version 2.0.
|
||||||
|
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||||
|
|
||||||
|
import vltest_bootstrap
|
||||||
|
|
||||||
|
test.scenarios('simulator')
|
||||||
|
|
||||||
|
test.compile(timing_loop=True, verilator_flags2=["--timing"])
|
||||||
|
|
||||||
|
test.execute()
|
||||||
|
|
||||||
|
test.passes()
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
// DESCRIPTION: Verilator: Verilog Test module
|
||||||
|
//
|
||||||
|
// This file ONLY is placed under the Creative Commons Public Domain, for
|
||||||
|
// any use, without warranty, 2025 by Antmicro.
|
||||||
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
|
module t (/*AUTOARG*/);
|
||||||
|
initial begin
|
||||||
|
begin : blk
|
||||||
|
int x = 0;
|
||||||
|
fork : fork_blk
|
||||||
|
begin
|
||||||
|
x = 1;
|
||||||
|
#2;
|
||||||
|
x = 2;
|
||||||
|
end
|
||||||
|
join_none
|
||||||
|
#1;
|
||||||
|
disable fork_blk;
|
||||||
|
#2;
|
||||||
|
if (x != 1) $stop;
|
||||||
|
$write("*-* All Finished *-*\n");
|
||||||
|
$finish;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||||
|
#
|
||||||
|
# Copyright 2024 by Wilson Snyder. This program is free software; you
|
||||||
|
# can redistribute it and/or modify it under the terms of either the GNU
|
||||||
|
# Lesser General Public License Version 3 or the Perl Artistic License
|
||||||
|
# Version 2.0.
|
||||||
|
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||||
|
|
||||||
|
import vltest_bootstrap
|
||||||
|
|
||||||
|
test.scenarios('simulator')
|
||||||
|
|
||||||
|
test.compile(timing_loop=True, verilator_flags2=["--timing"])
|
||||||
|
|
||||||
|
test.execute()
|
||||||
|
|
||||||
|
test.passes()
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
// DESCRIPTION: Verilator: Verilog Test module
|
||||||
|
//
|
||||||
|
// This file ONLY is placed under the Creative Commons Public Domain, for
|
||||||
|
// any use, without warranty, 2025 by Antmicro.
|
||||||
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
|
module t (/*AUTOARG*/);
|
||||||
|
initial begin
|
||||||
|
for (int i = 0; i < 3; i++) begin
|
||||||
|
begin : blk
|
||||||
|
int x = 0;
|
||||||
|
fork : fork_blk
|
||||||
|
begin
|
||||||
|
x = 1;
|
||||||
|
#2;
|
||||||
|
x = 2;
|
||||||
|
end
|
||||||
|
join_none
|
||||||
|
#1;
|
||||||
|
if (i < 2) disable fork_blk;
|
||||||
|
#2;
|
||||||
|
if (i < 2 && x != 1) $stop;
|
||||||
|
if (i == 2 && x != 2) $stop;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
$write("*-* All Finished *-*\n");
|
||||||
|
$finish;
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
%Error-UNSUPPORTED: t/t_disable_within_task_unsup.v:8:4: Unsupported: disabling fork from task / function
|
||||||
|
8 | disable t.init.fork_blk;
|
||||||
|
| ^~~~~~~
|
||||||
|
... For error description see https://verilator.org/warn/UNSUPPORTED?v=latest
|
||||||
|
%Error: Exiting due to
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||||
|
#
|
||||||
|
# Copyright 2024 by Wilson Snyder. This program is free software; you
|
||||||
|
# can redistribute it and/or modify it under the terms of either the GNU
|
||||||
|
# Lesser General Public License Version 3 or the Perl Artistic License
|
||||||
|
# Version 2.0.
|
||||||
|
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||||
|
|
||||||
|
import vltest_bootstrap
|
||||||
|
|
||||||
|
test.scenarios('simulator')
|
||||||
|
|
||||||
|
test.lint(verilator_flags2=['--timing'], fails=True, expect_filename=test.golden_filename)
|
||||||
|
|
||||||
|
test.passes()
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
// DESCRIPTION: Verilator: Verilog Test module
|
||||||
|
//
|
||||||
|
// This file ONLY is placed under the Creative Commons Public Domain, for
|
||||||
|
// any use, without warranty, 2025 by Antmicro.
|
||||||
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
|
task disable_fork_blk;
|
||||||
|
disable t.init.fork_blk;
|
||||||
|
endtask
|
||||||
|
|
||||||
|
module t(/*AUTOARG*/);
|
||||||
|
|
||||||
|
initial begin : init
|
||||||
|
int x = 0;
|
||||||
|
fork : fork_blk
|
||||||
|
begin
|
||||||
|
x = 1;
|
||||||
|
disable_fork_blk();
|
||||||
|
x = 2;
|
||||||
|
end
|
||||||
|
begin
|
||||||
|
#1;
|
||||||
|
x = 3;
|
||||||
|
end
|
||||||
|
join
|
||||||
|
if (x != 1) $stop;
|
||||||
|
$write("*-* All Finished *-*\n");
|
||||||
|
$finish;
|
||||||
|
end
|
||||||
|
|
||||||
|
endmodule
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue