From 13a87e551419a1e0b683ad42794980b53441bdbb Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 8 Apr 2023 15:04:42 -0400 Subject: [PATCH] Parse process class, and report runtime errors (#3612) --- include/verilated_std.sv | 41 ++++++++++++++++++++++++++ test_regress/driver.pl | 1 + test_regress/t/t_dist_warn_coverage.pl | 2 ++ test_regress/t/t_process.out | 27 ++--------------- test_regress/t/t_process.pl | 8 ++--- test_regress/t/t_process_bad.out | 18 +++++------ test_regress/t/t_process_std.out | 27 ++--------------- test_regress/t/t_process_std.pl | 8 ++--- 8 files changed, 67 insertions(+), 65 deletions(-) diff --git a/include/verilated_std.sv b/include/verilated_std.sv index 354901753..9a1153c76 100644 --- a/include/verilated_std.sv +++ b/include/verilated_std.sv @@ -115,4 +115,45 @@ package std; return 0; endfunction endclass + + class process; + typedef enum { FINISHED, RUNNING, WAITING, SUSPENDED, KILLED } state; + static process _s_global_process; + static function process self(); + // Unsupported, emulating with single process' state + if (!_s_global_process) _s_global_process = new; + return _s_global_process; + endfunction + function state status(); + // Unsupported, emulating with single process' state + return RUNNING; + endfunction + function void kill(); + $error("std::process::kill() not supported"); + endfunction + task await(); + $error("std::process::await() not supported"); + endtask + function void suspend(); + $error("std::process::suspend() not supported"); + endfunction + function void resume(); + $error("std::process::resume() not supported"); + endfunction + // When really implemented, srandom must operates on the process, but for + // now rely on the srandom() that is automatically generated for all + // classes. + // function void srandom(int seed); + // endfunction + function string get_randstate(); + // Could operate on all proceses for now + // No error, as harmless until set_randstate is called + return "NOT_SUPPORTED"; + endfunction + function void set_randstate(string randstate); + $error("std::process::set_randstate() not supported"); + // Could operate on all proceses for now + endfunction + endclass + endpackage diff --git a/test_regress/driver.pl b/test_regress/driver.pl index 2a1685e4e..6bf8240c8 100755 --- a/test_regress/driver.pl +++ b/test_regress/driver.pl @@ -2227,6 +2227,7 @@ sub files_identical { $l1[$l] =~ s/CPU Time: +[0-9.]+ seconds[^\n]+/CPU Time: ###/mig; $l1[$l] =~ s/\?v=[0-9.]+/?v=latest/mig; # warning URL $l1[$l] =~ s/_h[0-9a-f]{8}_/_h########_/mg; + $l1[$l] =~ s/ \/[^ ]+\/verilated_std.sv/ verilated_std.sv/mg; if ($l1[$l] =~ s/Exiting due to.*/Exiting due to/mig) { splice @l1, $l+1; # Trunc rest last; diff --git a/test_regress/t/t_dist_warn_coverage.pl b/test_regress/t/t_dist_warn_coverage.pl index 4646bb95e..234e2bce3 100755 --- a/test_regress/t/t_dist_warn_coverage.pl +++ b/test_regress/t/t_dist_warn_coverage.pl @@ -42,6 +42,7 @@ foreach my $s ( 'Assignment pattern with no members', 'Assignment pattern with too many elements', 'Attempted parameter setting of non-parameter: Param ', + 'Can\'t find typedef: ', 'Can\'t find varpin scope of ', 'Can\'t resolve module reference: \'', 'Cannot mix DPI import, DPI export, class methods, and/or public ', @@ -52,6 +53,7 @@ foreach my $s ( 'Exceeded limit of ', 'Extern declaration\'s scope is not a defined class', 'Format to $display-like function must have constant format string', + 'Forward typedef used as class/package does not resolve to class/package: ', 'Illegal +: or -: select; type already selected, or bad dimension: ', 'Illegal bit or array select; type already selected, or bad dimension: ', 'Illegal range select; type already selected, or bad dimension: ', diff --git a/test_regress/t/t_process.out b/test_regress/t/t_process.out index 74d069569..ab04bc4e8 100644 --- a/test_regress/t/t_process.out +++ b/test_regress/t/t_process.out @@ -1,24 +1,3 @@ -%Error: t/t_process.v:26:11: Forward typedef used as class/package does not resolve to class/package: 'process' - 26 | p = process::self(); - | ^~~~~~~ -%Error: t/t_process.v:27:25: Forward typedef used as class/package does not resolve to class/package: 'process' - 27 | if (p.status() != process::RUNNING) $stop; - | ^~~~~~~ -%Error: t/t_process.v:28:25: Forward typedef used as class/package does not resolve to class/package: 'process' - 28 | if (p.status() == process::WAITING) $stop; - | ^~~~~~~ -%Error: t/t_process.v:29:25: Forward typedef used as class/package does not resolve to class/package: 'process' - 29 | if (p.status() == process::SUSPENDED) $stop; - | ^~~~~~~ -%Error: t/t_process.v:30:25: Forward typedef used as class/package does not resolve to class/package: 'process' - 30 | if (p.status() == process::KILLED) $stop; - | ^~~~~~~ -%Error: t/t_process.v:31:25: Forward typedef used as class/package does not resolve to class/package: 'process' - 31 | if (p.status() == process::FINISHED) $stop; - | ^~~~~~~ -%Error: t/t_process.v:22:4: Can't find typedef: 'process' - 22 | process p; - | ^~~~~~~ -%Error: Internal Error: t/t_process.v:26:11: ../V3LinkDot.cpp:#: Bad package link - 26 | p = process::self(); - | ^~~~~~~ +[0] %Error: verilated_std.sv:154: Assertion failed in top.std.process.set_randstate: std::process::set_randstate() not supported +%Error: verilated_std.sv:154: Verilog $stop +Aborting... diff --git a/test_regress/t/t_process.pl b/test_regress/t/t_process.pl index 2ad4a887d..39ea187ff 100755 --- a/test_regress/t/t_process.pl +++ b/test_regress/t/t_process.pl @@ -11,13 +11,13 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di scenarios(simulator => 1); compile( - fails => $Self->{vlt_all}, - expect_filename => $Self->{golden_filename}, ); execute( - check_finished => 1, - ) if !$Self->{vlt_all}; + fails => $Self->{vlt_all}, + expect_filename => $Self->{golden_filename}, + check_finished => !$Self->{vlt_all}, + ); ok(1); 1; diff --git a/test_regress/t/t_process_bad.out b/test_regress/t/t_process_bad.out index 3e6f927d1..0c696d1d4 100644 --- a/test_regress/t/t_process_bad.out +++ b/test_regress/t/t_process_bad.out @@ -1,9 +1,9 @@ -%Error: t/t_process_bad.v:12:11: Forward typedef used as class/package does not resolve to class/package: 'process' - 12 | p = process::self(); - | ^~~~~~~ -%Error: t/t_process_bad.v:8:4: Can't find typedef: 'process' - 8 | process p; - | ^~~~~~~ -%Error: Internal Error: t/t_process_bad.v:12:11: ../V3LinkDot.cpp:#: Bad package link - 12 | p = process::self(); - | ^~~~~~~ +%Error: t/t_process_bad.v:13:13: Class method 'bad_method' not found in class 'process' + : ... In instance t + 13 | if (p.bad_method() != 0) $stop; + | ^~~~~~~~~~ +%Error: t/t_process_bad.v:15:9: Class method 'bad_method_2' not found in class 'process' + : ... In instance t + 15 | p.bad_method_2(); + | ^~~~~~~~~~~~ +%Error: Exiting due to diff --git a/test_regress/t/t_process_std.out b/test_regress/t/t_process_std.out index 74d069569..ab04bc4e8 100644 --- a/test_regress/t/t_process_std.out +++ b/test_regress/t/t_process_std.out @@ -1,24 +1,3 @@ -%Error: t/t_process.v:26:11: Forward typedef used as class/package does not resolve to class/package: 'process' - 26 | p = process::self(); - | ^~~~~~~ -%Error: t/t_process.v:27:25: Forward typedef used as class/package does not resolve to class/package: 'process' - 27 | if (p.status() != process::RUNNING) $stop; - | ^~~~~~~ -%Error: t/t_process.v:28:25: Forward typedef used as class/package does not resolve to class/package: 'process' - 28 | if (p.status() == process::WAITING) $stop; - | ^~~~~~~ -%Error: t/t_process.v:29:25: Forward typedef used as class/package does not resolve to class/package: 'process' - 29 | if (p.status() == process::SUSPENDED) $stop; - | ^~~~~~~ -%Error: t/t_process.v:30:25: Forward typedef used as class/package does not resolve to class/package: 'process' - 30 | if (p.status() == process::KILLED) $stop; - | ^~~~~~~ -%Error: t/t_process.v:31:25: Forward typedef used as class/package does not resolve to class/package: 'process' - 31 | if (p.status() == process::FINISHED) $stop; - | ^~~~~~~ -%Error: t/t_process.v:22:4: Can't find typedef: 'process' - 22 | process p; - | ^~~~~~~ -%Error: Internal Error: t/t_process.v:26:11: ../V3LinkDot.cpp:#: Bad package link - 26 | p = process::self(); - | ^~~~~~~ +[0] %Error: verilated_std.sv:154: Assertion failed in top.std.process.set_randstate: std::process::set_randstate() not supported +%Error: verilated_std.sv:154: Verilog $stop +Aborting... diff --git a/test_regress/t/t_process_std.pl b/test_regress/t/t_process_std.pl index 0c23347b2..64cabbccb 100755 --- a/test_regress/t/t_process_std.pl +++ b/test_regress/t/t_process_std.pl @@ -14,13 +14,13 @@ top_filename("t/t_process.v"); compile( v_flags2 => ["+define+T_PROCESS+std::process"], + ); + +execute( + check_finished => !$Self->{vlt_all}, fails => $Self->{vlt_all}, expect_filename => $Self->{golden_filename}, ); -execute( - check_finished => 1, - ) if !$Self->{vlt_all}; - ok(1); 1;