aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/gna/issue406
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2017-09-04 04:21:19 +0200
committerTristan Gingold <tgingold@free.fr>2017-09-04 04:21:19 +0200
commitf170a6ec3514350323ad48f1c2190a0a8d60ccf7 (patch)
tree4f0cffc3bcdba0bd9acf104dfe382d07cd9957ed /testsuite/gna/issue406
parentaf4e05d11936bd40bfe98cf769c86887a77e1d5d (diff)
downloadghdl-f170a6ec3514350323ad48f1c2190a0a8d60ccf7.tar.gz
ghdl-f170a6ec3514350323ad48f1c2190a0a8d60ccf7.tar.bz2
ghdl-f170a6ec3514350323ad48f1c2190a0a8d60ccf7.zip
Add reproducer for #406
Diffstat (limited to 'testsuite/gna/issue406')
-rw-r--r--testsuite/gna/issue406/queuep.vhdl74
-rw-r--r--testsuite/gna/issue406/queuet.vhdl22
-rwxr-xr-xtestsuite/gna/issue406/testsuite.sh13
3 files changed, 109 insertions, 0 deletions
diff --git a/testsuite/gna/issue406/queuep.vhdl b/testsuite/gna/issue406/queuep.vhdl
new file mode 100644
index 000000000..97b485289
--- /dev/null
+++ b/testsuite/gna/issue406/queuep.vhdl
@@ -0,0 +1,74 @@
+library ieee;
+ use ieee.std_logic_1164.all;
+
+
+package QueueP is
+
+ generic (
+ type QUEUE_TYPE;
+ function to_string(d : in QUEUE_TYPE) return string
+ );
+
+ -- simple queue interface
+ type t_simple_queue is protected
+ procedure push (data : in QUEUE_TYPE);
+ procedure pop (data : out QUEUE_TYPE);
+ impure function is_empty return boolean;
+ impure function is_full return boolean;
+ end protected t_simple_queue;
+
+end package QueueP;
+
+
+package body QueueP is
+
+ -- simple queue implementation
+ -- inspired by noasic article http://noasic.com/blog/a-simple-fifo-using-vhdl-protected-types/
+ type t_simple_queue is protected body
+
+ constant C_QUEUE_DEPTH : natural := 64;
+
+ type t_queue_array is array (0 to C_QUEUE_DEPTH-1) of QUEUE_TYPE;
+
+ variable v_queue : t_queue_array;
+ variable v_count : natural range 0 to t_queue_array'length := 0;
+ variable v_head : natural range 0 to t_queue_array'high := 0;
+ variable v_tail : natural range 0 to t_queue_array'high := 0;
+
+ -- write one entry into queue
+ procedure push (data : in QUEUE_TYPE) is
+ begin
+ assert not(is_full)
+ report "push into full queue -> discarded"
+ severity failure;
+ v_queue(v_head) := data;
+ v_head := (v_head + 1) mod t_queue_array'length;
+ v_count := v_count + 1;
+ end procedure push;
+
+ -- read one entry from queue
+ procedure pop (data : out QUEUE_TYPE) is
+ begin
+ assert not(is_empty)
+ report "pop from empty queue -> discarded"
+ severity failure;
+ data := v_queue(v_tail);
+ v_tail := (v_tail + 1) mod t_queue_array'length;
+ v_count := v_count - 1;
+ end procedure pop;
+
+ -- returns true if queue is empty, false otherwise
+ impure function is_empty return boolean is
+ begin
+ return v_count = 0;
+ end function is_empty;
+
+ -- returns true if queue is full, false otherwise
+ impure function is_full return boolean is
+ begin
+ return v_count = t_queue_array'length;
+ end function is_full;
+
+ end protected body t_simple_queue;
+
+end package body QueueP;
diff --git a/testsuite/gna/issue406/queuet.vhdl b/testsuite/gna/issue406/queuet.vhdl
new file mode 100644
index 000000000..d16ceed2c
--- /dev/null
+++ b/testsuite/gna/issue406/queuet.vhdl
@@ -0,0 +1,22 @@
+library ieee;
+ use ieee.std_logic_1164.all;
+ use ieee.numeric_std.all;
+
+library libvhdl;
+
+
+entity QueueT is
+end entity QueueT;
+
+
+architecture sim of QueueT is
+
+ package SlvQueue is new libvhdl.QueueP
+ generic map (QUEUE_TYPE => std_logic_vector(63 downto 0),
+ to_string => to_string);
+
+-- shared variable sv_simple_queue : SlvQueue.t_simple_queue;
+
+begin
+
+end architecture sim;
diff --git a/testsuite/gna/issue406/testsuite.sh b/testsuite/gna/issue406/testsuite.sh
new file mode 100755
index 000000000..30c868145
--- /dev/null
+++ b/testsuite/gna/issue406/testsuite.sh
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+. ../../testenv.sh
+
+export GHDL_STD_FLAGS=--std=08
+analyze --work=libvhdl queuep.vhdl
+analyze queuet.vhdl
+elab_simulate queuet
+
+clean
+clean libvhdl
+
+echo "Test successful"