Debian Codegraph @

gcc/m2/pge-boot/GStdIO.cc

raw
1 /* do not edit automatically generated by mc from StdIO. */
2 /* StdIO.mod provides general Read and Write procedures.
3
4 Copyright (C) 2001-2025 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <[email protected]>.
6
7 This file is part of GNU Modula-2.
8
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
13
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
22
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
27
28 #include <stdbool.h>
29 # if !defined (PROC_D)
30 # define PROC_D
31 typedef void (*PROC_t) (void);
32 typedef struct { PROC_t proc; } PROC;
33 # endif
34
35 # include "Gmcrts.h"
36 #define _StdIO_C
37
38 #include "GStdIO.h"
39 # include "GIO.h"
40 # include "GM2RTS.h"
41
42 typedef struct StdIO_ProcWrite_p StdIO_ProcWrite;
43
44 typedef struct StdIO_ProcRead_p StdIO_ProcRead;
45
46 # define MaxStack 40
47 typedef struct StdIO__T1_a StdIO__T1;
48
49 typedef struct StdIO__T2_a StdIO__T2;
50
51 struct StdIO__T1_a { StdIO_ProcWrite array[MaxStack+1]; };
52 struct StdIO__T2_a { StdIO_ProcRead array[MaxStack+1]; };
53 static StdIO__T1 StackW;
54 static unsigned int StackWPtr;
55 static StdIO__T2 StackR;
56 static unsigned int StackRPtr;
57
58 /*
59 Read - is the generic procedure that all higher application layers
60 should use to receive a character.
61 */
62
63 extern "C" void StdIO_Read (char *ch);
64
65 /*
66 Write - is the generic procedure that all higher application layers
67 should use to emit a character.
68 */
69
70 extern "C" void StdIO_Write (char ch);
71
72 /*
73 PushOutput - pushes the current Write procedure onto a stack,
74 any future references to Write will actually invoke
75 procedure, p.
76 */
77
78 extern "C" void StdIO_PushOutput (StdIO_ProcWrite p);
79
80 /*
81 PopOutput - restores Write to use the previous output procedure.
82 */
83
84 extern "C" void StdIO_PopOutput (void);
85
86 /*
87 GetCurrentOutput - returns the current output procedure.
88 */
89
90 extern "C" StdIO_ProcWrite StdIO_GetCurrentOutput (void);
91
92 /*
93 PushInput - pushes the current Read procedure onto a stack,
94 any future references to Read will actually invoke
95 procedure, p.
96 */
97
98 extern "C" void StdIO_PushInput (StdIO_ProcRead p);
99
100 /*
101 PopInput - restores Write to use the previous output procedure.
102 */
103
104 extern "C" void StdIO_PopInput (void);
105
106 /*
107 GetCurrentInput - returns the current input procedure.
108 */
109
110 extern "C" StdIO_ProcRead StdIO_GetCurrentInput (void);
111
112
113 /*
114 Read - is the generic procedure that all higher application layers
115 should use to receive a character.
116 */
117
118 extern "C" void StdIO_Read (char *ch)
119 {
120 (*StackR.array[StackRPtr].proc) (ch);
121 }
122
123
124 /*
125 Write - is the generic procedure that all higher application layers
126 should use to emit a character.
127 */
128
129 extern "C" void StdIO_Write (char ch)
130 {
131 (*StackW.array[StackWPtr].proc) (ch);
132 }
133
134
135 /*
136 PushOutput - pushes the current Write procedure onto a stack,
137 any future references to Write will actually invoke
138 procedure, p.
139 */
140
141 extern "C" void StdIO_PushOutput (StdIO_ProcWrite p)
142 {
143 if (StackWPtr == MaxStack)
144 {
145 M2RTS_HALT (-1);
146 __builtin_unreachable ();
147 }
148 else
149 {
150 StackWPtr += 1;
151 StackW.array[StackWPtr] = p;
152 }
153 }
154
155
156 /*
157 PopOutput - restores Write to use the previous output procedure.
158 */
159
160 extern "C" void StdIO_PopOutput (void)
161 {
162 if (StackWPtr == 1)
163 {
164 M2RTS_HALT (-1);
165 __builtin_unreachable ();
166 }
167 else
168 {
169 StackWPtr -= 1;
170 }
171 }
172
173
174 /*
175 GetCurrentOutput - returns the current output procedure.
176 */
177
178 extern "C" StdIO_ProcWrite StdIO_GetCurrentOutput (void)
179 {
180 if (StackWPtr > 0)
181 {
182 return StackW.array[StackWPtr];
183 }
184 else
185 {
186 M2RTS_HALT (-1);
187 __builtin_unreachable ();
188 }
189 ReturnException ("../../gcc/m2/gm2-libs/StdIO.def", 25, 1);
190 __builtin_unreachable ();
191 }
192
193
194 /*
195 PushInput - pushes the current Read procedure onto a stack,
196 any future references to Read will actually invoke
197 procedure, p.
198 */
199
200 extern "C" void StdIO_PushInput (StdIO_ProcRead p)
201 {
202 if (StackRPtr == MaxStack)
203 {
204 M2RTS_HALT (-1);
205 __builtin_unreachable ();
206 }
207 else
208 {
209 StackRPtr += 1;
210 StackR.array[StackRPtr] = p;
211 }
212 }
213
214
215 /*
216 PopInput - restores Write to use the previous output procedure.
217 */
218
219 extern "C" void StdIO_PopInput (void)
220 {
221 if (StackRPtr == 1)
222 {
223 M2RTS_HALT (-1);
224 __builtin_unreachable ();
225 }
226 else
227 {
228 StackRPtr -= 1;
229 }
230 }
231
232
233 /*
234 GetCurrentInput - returns the current input procedure.
235 */
236
237 extern "C" StdIO_ProcRead StdIO_GetCurrentInput (void)
238 {
239 if (StackRPtr > 0)
240 {
241 return StackR.array[StackRPtr];
242 }
243 else
244 {
245 M2RTS_HALT (-1);
246 __builtin_unreachable ();
247 }
248 ReturnException ("../../gcc/m2/gm2-libs/StdIO.def", 25, 1);
249 __builtin_unreachable ();
250 }
251
252 extern "C" void _M2_StdIO_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
253 {
254 StackWPtr = 0;
255 StackRPtr = 0;
256 StdIO_PushOutput ((StdIO_ProcWrite) {(StdIO_ProcWrite_t) IO_Write});
257 StdIO_PushInput ((StdIO_ProcRead) {(StdIO_ProcRead_t) IO_Read});
258 }
259
260 extern "C" void _M2_StdIO_fini (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
261 {
262 }