iverilog/vvp/examples/disable.vvp

78 lines
2.4 KiB
Plaintext

:ivl_version "12.0" "vec4-stack";
:vpi_module "system";
; Copyright (c) 2001-2015 Stephen Williams (steve@icarus.com)
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License along
; with this program; if not, write to the Free Software Foundation, Inc.,
; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
; This example is similar to the following Verilog code. The idea is
; to test the disable statement. The task creates a scope (called test)
; that is a hook for the disable statement to get at the thread that
; threatens to fail the test. If the disable statement works properly,
; the test task will be disabled before the #5 delay expires.
;
; module main;
; task test;
; begin
; #5 $display("FAILED...");
; $finish;
; end
; endtask
;
; initial begin
; fork
; test;
; #1 disable test;
; join
; $display("PASSED");
; end
; endmodule
;
S_main .scope module, "main" "main" 0 0;
S_test .scope task, "test" "test" 0 0, 0 0 0, S_main;
; This code in the implementation of the thread that goes into the
; test scope. The idea is to disable this thread before it does its
; job and prints a failure.
.scope S_test;
T_0/1 ;
%delay 5, 0;
%vpi_call 0 0 "$display", "FAILED -- thread wasn't disabled" {0 0 0};
%vpi_call 0 0 "$finish" {0 0 0};
%end;
; This is the main thread. Fork the thread under test, delay for a
; moment to let it run, then %disable the test thread. If I don't
; disable the test thread in time, then the child will print an error
; message and exit.
.scope S_main;
T_0 ;
%fork T_0/1, S_test;
%delay 1, 0;
%disable S_test ; This is the statement that I'm testing.
%join;
%vpi_call 0 0 "$display", "PASSED" {0 0 0};
%end;
.thread T_0;
:file_names 2;
"N/A";
"<interactive>";