This repository was archived by the owner on Oct 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathfileio.v93.vhdl
More file actions
144 lines (120 loc) · 4.67 KB
/
fileio.v93.vhdl
File metadata and controls
144 lines (120 loc) · 4.67 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
-- EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*-
-- vim: tabstop=2:shiftwidth=2:noexpandtab
-- kate: tab-width 2; replace-tabs off; indent-width 2;
-- =============================================================================
-- Authors: Patrick Lehmann
-- Thomas B. Preusser
--
-- Package: File I/O-related Functions.
--
-- Description:
-- -------------------------------------
-- Exploring the options for providing a more convenient API than std.textio.
-- Not yet recommended for adoption as it depends on the VHDL generation and
-- still is under discussion.
--
-- Open problems:
-- - verify that std.textio.write(text, string) is, indeed, specified and
-- that it does *not* print a trailing \newline
-- -> would help to eliminate line buffering in shared variables
-- - move C_LINEBREAK to my_config to keep platform dependency out?
--
-- License:
-- =============================================================================
-- Copyright 2007-2016 Technische Universitaet Dresden - Germany,
-- Chair of VLSI-Design, Diagnostics and Architecture
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- =============================================================================
use STD.TextIO.all;
library PoC;
use PoC.my_project.all;
use PoC.strings.all;
use PoC.utils.all;
package FileIO is
-- Constant declarations
constant C_LINEBREAK : string;
-- Log file
-- ===========================================================================
subtype T_LOGFILE_OPEN_KIND is FILE_OPEN_KIND range WRITE_MODE to APPEND_MODE;
procedure LogFile_Open(FileName : string; OpenKind : T_LOGFILE_OPEN_KIND := WRITE_MODE);
procedure LogFile_Open(Status : out FILE_OPEN_STATUS; FileName : string; OpenKind : T_LOGFILE_OPEN_KIND := WRITE_MODE);
impure function LogFile_IsOpen return boolean;
procedure LogFile_Print(str : string);
procedure LogFile_PrintLine(str : string := "");
procedure LogFile_Flush;
procedure LogFile_Close;
-- StdOut
-- ===========================================================================
procedure StdOut_Print(str : string);
procedure StdOut_PrintLine(str : string := "");
procedure StdOut_Flush;
end package;
package body FileIO is
constant C_LINEBREAK : string := ite(str_equal(MY_OPERATING_SYSTEM, "WINDOWS"), (CR & LF), (1 => LF));
-- ===========================================================================
file LogFile_FileHandle : TEXT;
shared variable LogFile_State_IsOpen : boolean := FALSE;
shared variable LogFile_LineBuffer : LINE;
procedure LogFile_Open(FileName : string; OpenKind : T_LOGFILE_OPEN_KIND := WRITE_MODE) is
variable OpenStatus : FILE_OPEN_STATUS;
begin
LogFile_Open(OpenStatus, FileName, OpenKind);
end procedure;
procedure LogFile_Open(Status : out FILE_OPEN_STATUS; FileName : string; OpenKind : T_LOGFILE_OPEN_KIND := WRITE_MODE) is
variable OpenStatus : FILE_OPEN_STATUS;
begin
file_open(OpenStatus, LogFile_FileHandle, FileName, OpenKind);
LogFile_State_IsOpen := OpenStatus = OPEN_OK;
Status := OpenStatus;
end procedure;
impure function LogFile_IsOpen return boolean is
begin
return LogFile_State_IsOpen;
end function;
procedure LogFile_Print(str : string) is
begin
write(LogFile_LineBuffer, str);
end procedure;
procedure LogFile_PrintLine(str : string := "") is
begin
write(LogFile_LineBuffer, str);
writeline(LogFile_FileHandle, LogFile_LineBuffer);
end procedure;
procedure LogFile_Flush is
begin
writeline(LogFile_FileHandle, LogFile_LineBuffer);
end procedure;
procedure LogFile_Close is
begin
if LogFile_State_IsOpen then
file_close(LogFile_FileHandle);
LogFile_State_IsOpen := FALSE;
end if;
end procedure;
-- ===========================================================================
shared variable StdOut_LineBuffer : line;
procedure StdOut_Print(str : string) is
begin
write(StdOut_LineBuffer, str);
end procedure;
procedure StdOut_PrintLine(str : string := "") is
begin
write(StdOut_LineBuffer, str);
writeline(OUTPUT, StdOut_LineBuffer);
end procedure;
procedure StdOut_Flush is
begin
writeline(OUTPUT, StdOut_LineBuffer);
end procedure;
end package body;