]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/pge-boot/GStdIO.c
Merge modula-2 front end onto gcc.
[thirdparty/gcc.git] / gcc / m2 / pge-boot / GStdIO.c
1 /* do not edit automatically generated by mc from StdIO. */
2 /* StdIO.mod provides general Read and Write procedures.
3
4 Copyright (C) 2001-2021 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
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 # if !defined (PROC_D)
29 # define PROC_D
30 typedef void (*PROC_t) (void);
31 typedef struct { PROC_t proc; } PROC;
32 # endif
33
34 # include "Gmcrts.h"
35 #define _StdIO_H
36 #define _StdIO_C
37
38 # include "GIO.h"
39 # include "GM2RTS.h"
40
41 typedef struct StdIO_ProcWrite_p StdIO_ProcWrite;
42
43 typedef struct StdIO_ProcRead_p StdIO_ProcRead;
44
45 # define MaxStack 40
46 typedef struct StdIO__T1_a StdIO__T1;
47
48 typedef struct StdIO__T2_a StdIO__T2;
49
50 typedef void (*StdIO_ProcWrite_t) (char);
51 struct StdIO_ProcWrite_p { StdIO_ProcWrite_t proc; };
52
53 typedef void (*StdIO_ProcRead_t) (char *);
54 struct StdIO_ProcRead_p { StdIO_ProcRead_t proc; };
55
56 struct StdIO__T1_a { StdIO_ProcWrite array[MaxStack+1]; };
57 struct StdIO__T2_a { StdIO_ProcRead array[MaxStack+1]; };
58 static StdIO__T1 StackW;
59 static unsigned int StackWPtr;
60 static StdIO__T2 StackR;
61 static unsigned int StackRPtr;
62
63 /*
64 Read - is the generic procedure that all higher application layers
65 should use to receive a character.
66 */
67
68 extern "C" void StdIO_Read (char *ch);
69
70 /*
71 Write - is the generic procedure that all higher application layers
72 should use to emit a character.
73 */
74
75 extern "C" void StdIO_Write (char ch);
76
77 /*
78 PushOutput - pushes the current Write procedure onto a stack,
79 any future references to Write will actually invoke
80 procedure, p.
81 */
82
83 extern "C" void StdIO_PushOutput (StdIO_ProcWrite p);
84
85 /*
86 PopOutput - restores Write to use the previous output procedure.
87 */
88
89 extern "C" void StdIO_PopOutput (void);
90
91 /*
92 GetCurrentOutput - returns the current output procedure.
93 */
94
95 extern "C" StdIO_ProcWrite StdIO_GetCurrentOutput (void);
96
97 /*
98 PushInput - pushes the current Read procedure onto a stack,
99 any future references to Read will actually invoke
100 procedure, p.
101 */
102
103 extern "C" void StdIO_PushInput (StdIO_ProcRead p);
104
105 /*
106 PopInput - restores Write to use the previous output procedure.
107 */
108
109 extern "C" void StdIO_PopInput (void);
110
111 /*
112 GetCurrentInput - returns the current input procedure.
113 */
114
115 extern "C" StdIO_ProcRead StdIO_GetCurrentInput (void);
116
117
118 /*
119 Read - is the generic procedure that all higher application layers
120 should use to receive a character.
121 */
122
123 extern "C" void StdIO_Read (char *ch)
124 {
125 (*StackR.array[StackRPtr].proc) (ch);
126 }
127
128
129 /*
130 Write - is the generic procedure that all higher application layers
131 should use to emit a character.
132 */
133
134 extern "C" void StdIO_Write (char ch)
135 {
136 (*StackW.array[StackWPtr].proc) (ch);
137 }
138
139
140 /*
141 PushOutput - pushes the current Write procedure onto a stack,
142 any future references to Write will actually invoke
143 procedure, p.
144 */
145
146 extern "C" void StdIO_PushOutput (StdIO_ProcWrite p)
147 {
148 if (StackWPtr == MaxStack)
149 {
150 M2RTS_HALT (-1);
151 __builtin_unreachable ();
152 }
153 else
154 {
155 StackWPtr += 1;
156 StackW.array[StackWPtr] = p;
157 }
158 }
159
160
161 /*
162 PopOutput - restores Write to use the previous output procedure.
163 */
164
165 extern "C" void StdIO_PopOutput (void)
166 {
167 if (StackWPtr == 1)
168 {
169 M2RTS_HALT (-1);
170 __builtin_unreachable ();
171 }
172 else
173 {
174 StackWPtr -= 1;
175 }
176 }
177
178
179 /*
180 GetCurrentOutput - returns the current output procedure.
181 */
182
183 extern "C" StdIO_ProcWrite StdIO_GetCurrentOutput (void)
184 {
185 if (StackWPtr > 0)
186 {
187 return StackW.array[StackWPtr];
188 }
189 else
190 {
191 M2RTS_HALT (-1);
192 __builtin_unreachable ();
193 }
194 ReturnException ("../../gcc-git-devel-modula2/gcc/m2/gm2-libs/StdIO.def", 25, 1);
195 __builtin_unreachable ();
196 }
197
198
199 /*
200 PushInput - pushes the current Read procedure onto a stack,
201 any future references to Read will actually invoke
202 procedure, p.
203 */
204
205 extern "C" void StdIO_PushInput (StdIO_ProcRead p)
206 {
207 if (StackRPtr == MaxStack)
208 {
209 M2RTS_HALT (-1);
210 __builtin_unreachable ();
211 }
212 else
213 {
214 StackRPtr += 1;
215 StackR.array[StackRPtr] = p;
216 }
217 }
218
219
220 /*
221 PopInput - restores Write to use the previous output procedure.
222 */
223
224 extern "C" void StdIO_PopInput (void)
225 {
226 if (StackRPtr == 1)
227 {
228 M2RTS_HALT (-1);
229 __builtin_unreachable ();
230 }
231 else
232 {
233 StackRPtr -= 1;
234 }
235 }
236
237
238 /*
239 GetCurrentInput - returns the current input procedure.
240 */
241
242 extern "C" StdIO_ProcRead StdIO_GetCurrentInput (void)
243 {
244 if (StackRPtr > 0)
245 {
246 return StackR.array[StackRPtr];
247 }
248 else
249 {
250 M2RTS_HALT (-1);
251 __builtin_unreachable ();
252 }
253 ReturnException ("../../gcc-git-devel-modula2/gcc/m2/gm2-libs/StdIO.def", 25, 1);
254 __builtin_unreachable ();
255 }
256
257 extern "C" void _M2_StdIO_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
258 {
259 StackWPtr = 0;
260 StackRPtr = 0;
261 StdIO_PushOutput ((StdIO_ProcWrite) {(StdIO_ProcWrite_t) IO_Write});
262 StdIO_PushInput ((StdIO_ProcRead) {(StdIO_ProcRead_t) IO_Read});
263 }
264
265 extern "C" void _M2_StdIO_finish (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
266 {
267 }