-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_tb.vhdl
108 lines (75 loc) · 3.01 KB
/
write_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
-- write and company: writing to stdout.
library std;
use std.textio.all;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_textio.all; -- hwrite
entity write_tb is
end entity write_tb;
architecture behav of write_tb is
signal std_logic_vector_32 : std_logic_vector(31 downto 0) := X"00000004";
signal counter : integer := 1;
begin
process is
variable my_line : line;
begin
-- # write
-- Write string to a line variable or to stdout.
write(output, string'("write output") & lf);
-- TODO cannot write integer directly to stdout. Why?
-- cannot resolve overloading for subprogram call
--write(output, 1);
write(output, to_string(1) & lf);
write(my_line, string'("write to variable"));
writeline(output, my_line);
-- # writeline
-- Write line to stdout, and add a newline at the end.
-- Seems to convert the all newlines to the system specific newlines.
write(output, string'("hello world"));
writeline(output, my_line);
-- # swrite
-- VHDL 2008.
-- More practical than write for strings, as it dispenses the type.
swrite(my_line, "swrite");
writeline(output, my_line);
-- TODO nope. Why?
--swrite(output, "swrite");
-- How stuff prints under write.
-- I think `to_string` is called.
-- Numeric literals.
swrite(my_line, "1 = ");
write(my_line, 1);
writeline(output, my_line);
swrite(my_line, "1_1 = ");
write(my_line, 1_1);
writeline(output, my_line);
swrite(my_line, "1E1 = ");
write(my_line, 1E1);
writeline(output, my_line);
swrite(my_line, "1.1 = ");
write(my_line, 1.1);
writeline(output, my_line);
-- Write integer as hexadecimal.
--hwrite(my_line, std_logic_vector(to_unsigned(16,8)));
-- http://stackoverflow.com/questions/37879954/how-to-write-an-integer-to-stdout-as-hexadecimal-in-vhdl/37885828#37885828
write(output, string'("hexadecimal") & lf);
write(output, to_hstring(to_unsigned(16, 32)) & lf);
hwrite(my_line, std_logic_vector(to_unsigned(16, 32)));
writeline(output, my_line);
-- Time.
swrite(my_line, "1 ns = ");
write(my_line, 1 ns);
writeline(output, my_line);
swrite(my_line, "1 ms = ");
write(my_line, 1 ms);
writeline(output, my_line);
-- # hwrite
-- Formats std_logic_vector as hex.
-- VHDL 2008, previously Synopsys extension.
swrite(my_line, "std_logic_vector_32 = ");
hwrite(my_line, std_logic_vector_32);
writeline(output, my_line);
wait;
end process;
end architecture behav;