1
2-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc
3
4-- This file is part of VESTs (Vhdl tESTs).
5
6-- VESTs is free software; you can redistribute it and/or modify it
7-- under the terms of the GNU General Public License as published by the
8-- Free Software Foundation; either version 2 of the License, or (at
9-- your option) any later version.
10
11-- VESTs is distributed in the hope that it will be useful, but WITHOUT
12-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13-- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14-- for more details.
15
16-- You should have received a copy of the GNU General Public License
17-- along with VESTs; if not, write to the Free Software Foundation,
18-- Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20-- ---------------------------------------------------------------------
21--
22-- $Id: ch_19_tkfifo-b.vhd,v 1.3 2001-10-26 16:29:36 paw Exp $
23-- $Revision: 1.3 $
24--
25-- ---------------------------------------------------------------------
26
27package body token_fifo_adt is
28
29  function new_fifo return fifo_type is
30  begin
31    return new fifo_record'( null, null );
32  end function new_fifo;
33
34
35  procedure test_empty ( variable fifo : in fifo_type;
36                         variable is_empty : out boolean ) is
37  begin
38    is_empty := fifo.head_entry = null;
39  end procedure test_empty;
40
41
42  procedure insert ( fifo : inout fifo_type;
43                     element : in element_type ) is
44
45    variable new_entry : fifo_entry
46      := new fifo_entry_record'( next_entry => null,
47                                 element => element );
48  begin
49    if fifo.tail_entry /= null then
50      fifo.tail_entry.next_entry := new_entry;
51    else
52      fifo.head_entry := new_entry;
53    end if;
54    fifo.tail_entry := new_entry;
55  end procedure insert;
56
57
58  procedure remove ( fifo : inout fifo_type;
59                     element : out element_type ) is
60    variable empty_fifo : boolean;
61    variable removed_entry : fifo_entry;
62  begin
63    test_empty(fifo, empty_fifo);
64    if empty_fifo then
65      report "remove from empty fifo" severity failure;
66    else
67      removed_entry := fifo.head_entry;
68      element := removed_entry.element;
69      fifo.head_entry := removed_entry.next_entry;
70      if fifo.head_entry = null then  -- fifo now empty
71        fifo.tail_entry := null;
72      end if;
73      deallocate(removed_entry);
74    end if;
75  end procedure remove;
76
77end package body token_fifo_adt;
78