-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_tb.vhdl
60 lines (51 loc) · 1.29 KB
/
function_tb.vhdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- LIke a procedure, but:
-- - has a return value
-- - cannot have wait
entity function_tb is
function entity_is(x : integer)
return integer is
begin
return x + 1;
end entity_is;
end function_tb;
architecture behav of function_tb is
signal s0 : integer;
function inc(x : integer)
return integer is
begin
return x + 1;
end inc;
function wait_test(x : integer)
return integer is
begin
-- Not allowed in function.
--wait for 1 ns;
end wait_test;
-- No parenthesis on definition.
function no_args
return integer is
begin
return 1;
end no_args;
-- # pure function
-- TODO: how to make impure functions?
-- Pure functions have some language defined properties,
-- e.g. only pure functions can resolve types.
begin
process is
function proc_is(x : integer)
return integer is
begin
return x + 1;
end proc_is;
begin
assert inc(1) = 2;
-- Function definitions can go inside `process is` as well.
assert proc_is(1) = 2;
-- And `entity is`.
assert entity_is(1) = 2;
-- No parenthesis on call.
assert no_args = 1;
wait;
end process;
end behav;