1 /* do not edit automatically generated by mc from StdIO. */
2 /* StdIO.mod provides general Read and Write procedures.
4 Copyright (C) 2001-2021 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
7 This file is part of GNU Modula-2.
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)
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.
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.
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/>. */
28 # if !defined (PROC_D)
30 typedef void (*PROC_t
) (void);
31 typedef struct { PROC_t proc
; } PROC
;
41 typedef struct StdIO_ProcWrite_p StdIO_ProcWrite
;
43 typedef struct StdIO_ProcRead_p StdIO_ProcRead
;
46 typedef struct StdIO__T1_a StdIO__T1
;
48 typedef struct StdIO__T2_a StdIO__T2
;
50 typedef void (*StdIO_ProcWrite_t
) (char);
51 struct StdIO_ProcWrite_p
{ StdIO_ProcWrite_t proc
; };
53 typedef void (*StdIO_ProcRead_t
) (char *);
54 struct StdIO_ProcRead_p
{ StdIO_ProcRead_t proc
; };
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
;
64 Read - is the generic procedure that all higher application layers
65 should use to receive a character.
68 extern "C" void StdIO_Read (char *ch
);
71 Write - is the generic procedure that all higher application layers
72 should use to emit a character.
75 extern "C" void StdIO_Write (char ch
);
78 PushOutput - pushes the current Write procedure onto a stack,
79 any future references to Write will actually invoke
83 extern "C" void StdIO_PushOutput (StdIO_ProcWrite p
);
86 PopOutput - restores Write to use the previous output procedure.
89 extern "C" void StdIO_PopOutput (void);
92 GetCurrentOutput - returns the current output procedure.
95 extern "C" StdIO_ProcWrite
StdIO_GetCurrentOutput (void);
98 PushInput - pushes the current Read procedure onto a stack,
99 any future references to Read will actually invoke
103 extern "C" void StdIO_PushInput (StdIO_ProcRead p
);
106 PopInput - restores Write to use the previous output procedure.
109 extern "C" void StdIO_PopInput (void);
112 GetCurrentInput - returns the current input procedure.
115 extern "C" StdIO_ProcRead
StdIO_GetCurrentInput (void);
119 Read - is the generic procedure that all higher application layers
120 should use to receive a character.
123 extern "C" void StdIO_Read (char *ch
)
125 (*StackR
.array
[StackRPtr
].proc
) (ch
);
130 Write - is the generic procedure that all higher application layers
131 should use to emit a character.
134 extern "C" void StdIO_Write (char ch
)
136 (*StackW
.array
[StackWPtr
].proc
) (ch
);
141 PushOutput - pushes the current Write procedure onto a stack,
142 any future references to Write will actually invoke
146 extern "C" void StdIO_PushOutput (StdIO_ProcWrite p
)
148 if (StackWPtr
== MaxStack
)
151 __builtin_unreachable ();
156 StackW
.array
[StackWPtr
] = p
;
162 PopOutput - restores Write to use the previous output procedure.
165 extern "C" void StdIO_PopOutput (void)
170 __builtin_unreachable ();
180 GetCurrentOutput - returns the current output procedure.
183 extern "C" StdIO_ProcWrite
StdIO_GetCurrentOutput (void)
187 return StackW
.array
[StackWPtr
];
192 __builtin_unreachable ();
194 ReturnException ("../../gcc-git-devel-modula2/gcc/m2/gm2-libs/StdIO.def", 25, 1);
195 __builtin_unreachable ();
200 PushInput - pushes the current Read procedure onto a stack,
201 any future references to Read will actually invoke
205 extern "C" void StdIO_PushInput (StdIO_ProcRead p
)
207 if (StackRPtr
== MaxStack
)
210 __builtin_unreachable ();
215 StackR
.array
[StackRPtr
] = p
;
221 PopInput - restores Write to use the previous output procedure.
224 extern "C" void StdIO_PopInput (void)
229 __builtin_unreachable ();
239 GetCurrentInput - returns the current input procedure.
242 extern "C" StdIO_ProcRead
StdIO_GetCurrentInput (void)
246 return StackR
.array
[StackRPtr
];
251 __builtin_unreachable ();
253 ReturnException ("../../gcc-git-devel-modula2/gcc/m2/gm2-libs/StdIO.def", 25, 1);
254 __builtin_unreachable ();
257 extern "C" void _M2_StdIO_init (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])
261 StdIO_PushOutput ((StdIO_ProcWrite
) {(StdIO_ProcWrite_t
) IO_Write
});
262 StdIO_PushInput ((StdIO_ProcRead
) {(StdIO_ProcRead_t
) IO_Read
});
265 extern "C" void _M2_StdIO_finish (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])