Data Types 99
temp_elem.nxt := list_head; --line 16
list_head := temp_elem; --line 17
--read mode --line 18
ELSIF (r_wb = ‘ 1 ’) THEN
dout <= list_head.data; --line 19
temp_elem := list_head; --line 20
list_head := temp_elem.nxt; --line 21
DEALLOCATE (temp_elem); --line 22
ELSE
ASSERT FALSE
REPORT “read/write unknown while clock active”
SEVERITY WARNING; --line 23
END IF;
END IF;
last_clk := clk; --line 24
END PROCESS;
END stack;
This example implements a stack using access types. The package
stack_typesdeclares all of the types needed for the stack. In line 2, there
is a declaration of the incomplete type element_rec. The name of the type
is specified, but no specification of the type is present. The purpose of this
declaration is to reserve the name of the type and allow other types to
gain access to the type when it is fully specified. The full specification for
this incomplete type appears in lines 4 through 8.
The fundamental reason for the incomplete type is to allow self-
referencing structures as linked lists. Notice that type element_ptris
used in type element_recin line 6. To use a type, it must first be de-
fined. Notice also that, in the declaration for type element_ptrin line
3, type element_recis used. Because each type uses the other in its re-
spective declarations, neither type can be declared first without a spe-
cial way of handling this case. The incomplete type allows this scenario
to exist.
Lines 4 through 8 declare the record type element_rec. This record
type is used to store the data for the stack. The first field of the record is
the data field, and the second is an access type that points to the next
record in the stack.
The entity for stack declares port dinfor data input to the stack, a clk
input on which all operations are triggered, a doutport which transfers
data out of the stack, and, finally, a r_wbinput which causes a read oper-
ation when high and a write operation when low. The process for the stack
is only triggered when the clkinput has an event occur. It is not affected
by changes in r_wb.
Lines 9 through 11 declare some variables used to keep track of the
data for the stack. Variable list_headis the head of the linked list of