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