-
Notifications
You must be signed in to change notification settings - Fork 1k
Add warnings and errors to sim -r with VCD code path
#5701
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
Open
gussmith23
wants to merge
4
commits into
main
Choose a base branch
from
gus/sim-with-vcd-tuneup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−5
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| #include "kernel/yw.h" | ||
| #include "kernel/json.h" | ||
| #include "kernel/fmt.h" | ||
| #include "kernel/drivertools.h" | ||
|
|
||
| #include <ctime> | ||
|
|
||
|
|
@@ -125,6 +126,8 @@ struct SimShared | |
| bool serious_asserts = false; | ||
| bool fst_noinit = false; | ||
| bool initstate = true; | ||
| bool undriven_check = true; | ||
| bool undriven_warning = false; | ||
| }; | ||
|
|
||
| void zinit(Const &v) | ||
|
|
@@ -426,7 +429,7 @@ struct SimInstance | |
|
|
||
| Const value = builder.build(); | ||
| if (shared->debug) | ||
| log("[%s] get %s: %s\n", hiername(), log_signal(sig), log_signal(value)); | ||
| log("[%s] get %s: %s\n", hiername(), log_signal(sig, true), log_signal(value, true)); | ||
| return value; | ||
| } | ||
|
|
||
|
|
@@ -445,7 +448,7 @@ struct SimInstance | |
| } | ||
|
|
||
| if (shared->debug) | ||
| log("[%s] set %s: %s\n", hiername(), log_signal(sig), log_signal(value)); | ||
| log("[%s] set %s: %s\n", hiername(), log_signal(sig, true), log_signal(value, true)); | ||
| return did_something; | ||
| } | ||
|
|
||
|
|
@@ -1192,6 +1195,54 @@ struct SimInstance | |
| child.second->addAdditionalInputs(); | ||
| } | ||
|
|
||
| // Preconditions / assumptions: | ||
| // 1) fst_handles is populated for this instance (0 handle means not in trace). | ||
| // 2) fst_inputs is finalized (top-level inputs + addAdditionalInputs() for $anyseq). | ||
| // 3) module has no processes (sim enforces proc-lowered input before this point). | ||
| // 4) sigmap is valid for per-bit queries on this instance. | ||
| // 5) shared->fst is active, i.e. this is called from FST/VCD replay flow. | ||
| int checkUndrivenReplaySignals() | ||
| { | ||
| int issue_count = 0; | ||
| bool has_replay_candidates = false; | ||
|
|
||
| for (auto &item : fst_handles) | ||
| if (item.second != 0 && !fst_inputs.count(item.first)) { | ||
| has_replay_candidates = true; | ||
| break; | ||
| } | ||
|
|
||
| if (has_replay_candidates) { | ||
| DriverMap drivermap(module->design); | ||
| drivermap.add(module); | ||
|
|
||
| for (auto &item : fst_handles) { | ||
| Wire *wire = item.first; | ||
| if (item.second == 0 || fst_inputs.count(wire)) | ||
| continue; | ||
|
|
||
| SigSpec undriven; | ||
| for (auto bit : sigmap(wire)) | ||
| if (bit.wire != nullptr && drivermap(DriveBit(bit)).is_none()) | ||
| undriven.append(bit); | ||
|
|
||
| undriven.sort_and_unify(); | ||
| if (undriven.empty()) | ||
| continue; | ||
|
|
||
| issue_count++; | ||
| std::string wire_name = scope + "." + RTLIL::unescape_id(wire->name); | ||
| log_warning("Input trace contains undriven signal `%s` (%s); values for this signal are not replayed from FST/VCD input.\n", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too long message and it will repeat if there are multiple signals, maybe add a flag for having undriven signals in file and then just display one more warning at the and with something like |
||
| wire_name.c_str(), log_signal(undriven, true)); | ||
| } | ||
| } | ||
|
|
||
| for (auto child : children) | ||
| issue_count += child.second->checkUndrivenReplaySignals(); | ||
|
|
||
| return issue_count; | ||
| } | ||
|
|
||
| bool setInputs() | ||
| { | ||
| bool did_something = false; | ||
|
|
@@ -1248,22 +1299,22 @@ struct SimInstance | |
| } else if (shared->sim_mode == SimulationMode::gate && !fst_val.is_fully_def()) { // FST data contains X | ||
| for(int i=0;i<fst_val.size();i++) { | ||
| if (fst_val[i]!=State::Sx && fst_val[i]!=sim_val[i]) { | ||
| log_warning("Signal '%s.%s' in file %s in simulation %s\n", scope, log_id(item.first), log_signal(fst_val), log_signal(sim_val)); | ||
| log_warning("Signal '%s.%s' in file %s in simulation %s\n", scope, log_id(item.first), log_signal(fst_val, true), log_signal(sim_val, true)); | ||
| retVal = true; | ||
| break; | ||
| } | ||
| } | ||
| } else if (shared->sim_mode == SimulationMode::gold && !sim_val.is_fully_def()) { // sim data contains X | ||
| for(int i=0;i<sim_val.size();i++) { | ||
| if (sim_val[i]!=State::Sx && fst_val[i]!=sim_val[i]) { | ||
| log_warning("Signal '%s.%s' in file %s in simulation %s\n", scope, log_id(item.first), log_signal(fst_val), log_signal(sim_val)); | ||
| log_warning("Signal '%s.%s' in file %s in simulation %s\n", scope, log_id(item.first), log_signal(fst_val, true), log_signal(sim_val, true)); | ||
| retVal = true; | ||
| break; | ||
| } | ||
| } | ||
| } else { | ||
| if (fst_val!=sim_val) { | ||
| log_warning("Signal '%s.%s' in file %s in simulation '%s'\n", scope, log_id(item.first), log_signal(fst_val), log_signal(sim_val)); | ||
| log_warning("Signal '%s.%s' in file %s in simulation '%s'\n", scope, log_id(item.first), log_signal(fst_val, true), log_signal(sim_val, true)); | ||
| retVal = true; | ||
| } | ||
| } | ||
|
|
@@ -1498,6 +1549,12 @@ struct SimWorker : SimShared | |
| } | ||
|
|
||
| top->addAdditionalInputs(); | ||
| if (undriven_check) { | ||
| int issue_count = top->checkUndrivenReplaySignals(); | ||
| if (issue_count > 0 && !undriven_warning) | ||
| log_cmd_error("Found %d undriven signal%s in the replay trace. Use -undriven-warn to continue or -no-undriven-check to disable this check.\n", | ||
| issue_count, issue_count == 1 ? "" : "s"); | ||
| } | ||
|
|
||
| uint64_t startCount = 0; | ||
| uint64_t stopCount = 0; | ||
|
|
@@ -2624,8 +2681,15 @@ struct SimPass : public Pass { | |
| log(" -r <filename>\n"); | ||
| log(" read simulation or formal results file\n"); | ||
| log(" File formats supported: FST, VCD, AIW, WIT and .yw\n"); | ||
| log(" Yosys witness (.yw) replay is preferred when possible.\n"); | ||
| log(" VCD support requires vcd2fst external tool to be present\n"); | ||
| log("\n"); | ||
| log(" -no-undriven-check\n"); | ||
| log(" skip undriven-signal checks for FST/VCD replay (can be expensive for large designs)\n"); | ||
| log("\n"); | ||
| log(" -undriven-warn\n"); | ||
| log(" downgrade undriven-signal replay errors to warnings\n"); | ||
| log("\n"); | ||
| log(" -width <integer>\n"); | ||
| log(" cycle width in generated simulation output (must be divisible by 2).\n"); | ||
| log("\n"); | ||
|
|
@@ -2843,6 +2907,14 @@ struct SimPass : public Pass { | |
| worker.fst_noinit = true; | ||
| continue; | ||
| } | ||
| if (args[argidx] == "-no-undriven-check") { | ||
| worker.undriven_check = false; | ||
| continue; | ||
| } | ||
| if (args[argidx] == "-undriven-warn") { | ||
| worker.undriven_warning = true; | ||
| continue; | ||
| } | ||
| if (args[argidx] == "-x") { | ||
| worker.ignore_x = true; | ||
| continue; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module undriven_replay ( | ||
| input wire in, | ||
| output wire out, | ||
| output wire undrv | ||
| ); | ||
| assign out = in; | ||
| endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| $version Yosys $end | ||
| $scope module undriven_replay $end | ||
| $var wire 1 ! in $end | ||
| $var wire 1 " out $end | ||
| $var wire 1 # undrv $end | ||
| $upscope $end | ||
| $enddefinitions $end | ||
| #0 | ||
| b0 ! | ||
| b0 " | ||
| b1 # | ||
| #10 | ||
| b1 ! | ||
| b1 " | ||
| b0 # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| read_verilog undriven_replay.v | ||
| prep -top undriven_replay | ||
|
|
||
| logger -expect error "Found 1 undriven signal in the replay trace" 1 | ||
| sim -r undriven_replay.vcd -scope undriven_replay -q |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| read_verilog undriven_replay.v | ||
| prep -top undriven_replay | ||
|
|
||
| sim -r undriven_replay.vcd -scope undriven_replay -q -no-undriven-check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| read_verilog undriven_replay.v | ||
| prep -top undriven_replay | ||
|
|
||
| logger -expect warning "Input trace contains undriven signal" 1 | ||
| sim -r undriven_replay.vcd -scope undriven_replay -q -undriven-warn |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is adding
trueas second parameter forlog_signalaffecting results log output at all ? since this should affect only constants, if so do you have any example for that ?