Parser: Test and handle semaphore, mailbox and process.

This commit is contained in:
Wilson Snyder 2020-07-09 20:04:10 -04:00
parent 1632160fb1
commit 0674267333
13 changed files with 343 additions and 0 deletions

View File

@ -515,6 +515,12 @@ void V3ParseImp::tokenPipelineSym() {
token = yaID__ETC;
}
}
} else if ((token == yaID__LEX || token == yaID__CC)
&& (*(yylval.strp) == "mailbox" // IEEE-standard class
|| *(yylval.strp) == "process" // IEEE-standard class
|| *(yylval.strp) == "semaphore")) { // IEEE-standard class
yylval.scp = NULL;
if (token == yaID__LEX) token = yaID__aTYPE;
} else { // Not found
yylval.scp = NULL;
if (token == yaID__CC) {

View File

@ -0,0 +1,4 @@
%Error: t/t_mailbox.v:20:4: Can't find typedef: 'mailbox'
20 | mailbox m;
| ^~~~~~~
%Error: Exiting due to

23
test_regress/t/t_mailbox.pl Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2020 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
scenarios(simulator => 1);
compile(
fails => $Self->{vlt_all},
expect_filename => $Self->{golden_filename},
);
#execute(
# check_finished => 1,
# );
ok(1);
1;

View File

@ -0,0 +1,86 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2020 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
// Methods defined by IEEE:
// class mailbox #(type T = dynamic_singular_type) ;
// function new(int bound = 0);
// function int num();
// task put( T message);
// function int try_put( T message);
// task get( ref T message );
// function int try_get( ref T message );
// task peek( ref T message );
// function int try_peek( ref T message );
// endclass
module t(/*AUTOARG*/);
mailbox m;
int msg;
int out;
initial begin
m = new(4);
if (m.num() != 0) $stop;
if (m.try_get(msg) > 0) $stop;
msg = 123;
m.put(msg);
msg = 0;
if (m.num() != 1) $stop;
if (m.try_peek(out) <= 0) $stop;
if (out != 123) $stop;
if (m.num() != 0) $stop;
out = 0;
if (m.try_peek(out) <= 0) $stop;
if (out != 123) $stop;
out = 0;
if (m.try_get(out) <= 0) $stop;
if (out != 123) $stop;
if (m.num() != 0) $stop;
msg = 124;
m.put(msg);
out = 0;
m.get(out);
if (out != 124) $stop;
msg = 125;
m.put(msg);
m.put(msg);
m.try_put(msg);
m.try_put(msg);
if (m.num() != 4) $stop;
if (m.try_put(msg) != 0) $stop;
if (m.num() != 4) $stop;
m.get(out);
m.get(out);
m.get(out);
m.get(out);
if (m.num() != 0) $stop;
fork
begin
#10; // So later then get() starts below
msg = 130;
m.put(msg);
msg = 131;
m.put(msg);
end
begin
if (m.try_get(msg) != 0) $stop;
out = 0;
m.get(out); // Blocks until put
if (out != 130) $stop;
out = 0;
m.get(out);
if (out != 131) $stop;
end
join
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -0,0 +1,20 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 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
scenarios(vlt => 1);
top_filename("t_mailbox.v");
lint(
verilator_flags2 => ["--debug-exit-parse"],
);
ok(1);
1;

View File

@ -0,0 +1,22 @@
%Error: t/t_process.v:22:4: Can't find typedef: 'process'
22 | process p;
| ^~~~~~~
%Error: t/t_process.v:26:20: Can't find definition of task/function: 'self'
26 | p = process::self();
| ^~~~
%Error: t/t_process.v:27:34: Can't find definition of variable: 'RUNNING'
27 | if (p.status() != process::RUNNING) $stop;
| ^~~~~~~
%Error: t/t_process.v:28:34: Can't find definition of variable: 'WAITING'
28 | if (p.status() == process::WAITING) $stop;
| ^~~~~~~
%Error: t/t_process.v:29:34: Can't find definition of variable: 'SUSPENDED'
29 | if (p.status() == process::SUSPENDED) $stop;
| ^~~~~~~~~
%Error: t/t_process.v:30:34: Can't find definition of variable: 'KILLED'
30 | if (p.status() == process::KILLED) $stop;
| ^~~~~~
%Error: t/t_process.v:31:34: Can't find definition of variable: 'FINISHED'
31 | if (p.status() == process::FINISHED) $stop;
| ^~~~~~~~
%Error: Exiting due to

23
test_regress/t/t_process.pl Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2020 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
scenarios(simulator => 1);
compile(
fails => $Self->{vlt_all},
expect_filename => $Self->{golden_filename},
);
#execute(
# check_finished => 1,
# );
ok(1);
1;

View File

@ -0,0 +1,43 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2020 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
// Methods defined by IEEE:
// class process;
// enum state { FINISHED, RUNNING, WAITING, SUSPENDED, KILLED };
// static function process self();
// function state status();
// function void kill();
// task await(); // Warn as unsupported (no UVM library use)
// function void suspend(); // Warn as unsupported (no UVM library use)
// function void resume(); // Warn as unsupported (no UVM library use)
// function void srandom( int seed ); // Just ignore?
// function string get_randstate(); // Just ignore?
// function void set_randstate( string state ); // Just ignore?
// endclass
module t(/*AUTOARG*/);
process p;
initial begin
if (p != null) $stop;
p = process::self();
if (p.status() != process::RUNNING) $stop;
if (p.status() == process::WAITING) $stop;
if (p.status() == process::SUSPENDED) $stop;
if (p.status() == process::KILLED) $stop;
if (p.status() == process::FINISHED) $stop;
if (0) p.kill();
if (0) p.await();
if (0) p.suspend();
if (0) p.resume();
p.srandom(0);
p.set_randstate(p.get_randstate());
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -0,0 +1,20 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 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
scenarios(vlt => 1);
top_filename("t_process.v");
lint(
verilator_flags2 => ["--debug-exit-parse"],
);
ok(1);
1;

View File

@ -0,0 +1,4 @@
%Error: t/t_semaphore.v:17:4: Can't find typedef: 'semaphore'
17 | semaphore s;
| ^~~~~~~~~
%Error: Exiting due to

23
test_regress/t/t_semaphore.pl Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2020 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
scenarios(simulator => 1);
compile(
fails => $Self->{vlt_all},
expect_filename => $Self->{golden_filename},
);
#execute(
# check_finished => 1,
# );
ok(1);
1;

View File

@ -0,0 +1,49 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2020 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
// Methods defined by IEEE:
// class semaphore;
// function new(int keyCount = 0);
// function void put(int keyCount = 1);
// task get(int keyCount = 1);
// function int try_get(int keyCount = 1);
// endclass
module t(/*AUTOARG*/);
//From UVM:
semaphore s;
int msg;
initial begin
s = new(4);
if (s.try_get() != 0) $stop;
s.put();
s.get();
s.put(2);
s.get(2);
s.put(2);
if (s.try_get(2) <= 0) $stop;
fork
begin
#10; // So later then get() starts below
s.put(1);
s.put(1);
end
begin
if (s.try_get(1) != 0) $stop;
s.get(); // Blocks until put
s.get();
end
join
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -0,0 +1,20 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 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
scenarios(vlt => 1);
top_filename("t_semaphore.v");
lint(
verilator_flags2 => ["--debug-exit-parse"],
);
ok(1);
1;