libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / m2 / mc-boot / GFpuIO.cc
blob09fd4fb95cdffb6373e1c32b17cfd8477f4a3276
1 /* do not edit automatically generated by mc from FpuIO. */
2 /* FpuIO.mod implements a fixed format input/output for REAL/LONGREAL.
4 Copyright (C) 2001-2024 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)
12 any later version.
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 #include "config.h"
29 #include "system.h"
30 #include <stdbool.h>
31 # if !defined (PROC_D)
32 # define PROC_D
33 typedef void (*PROC_t) (void);
34 typedef struct { PROC_t proc; } PROC;
35 # endif
37 # if !defined (TRUE)
38 # define TRUE (1==1)
39 # endif
41 # if !defined (FALSE)
42 # define FALSE (1==0)
43 # endif
45 #define _FpuIO_C
47 #include "GFpuIO.h"
48 # include "GStrIO.h"
49 # include "GStrLib.h"
50 # include "GASCII.h"
51 # include "GDynamicStrings.h"
52 # include "GStringConvert.h"
54 # define MaxLineLength 100
55 extern "C" void FpuIO_ReadReal (double *x);
58 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
59 FractionWidth into, string, a.
62 extern "C" void FpuIO_WriteReal (double x, unsigned int TotalWidth, unsigned int FractionWidth);
65 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
66 FractionWidth into, string, a.
69 extern "C" void FpuIO_StrToReal (const char *a_, unsigned int _a_high, double *x);
72 RealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
73 FractionWidth into a string.
76 extern "C" void FpuIO_RealToStr (double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high);
77 extern "C" void FpuIO_ReadLongReal (long double *x);
80 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
81 FractionWidth into a string.
84 extern "C" void FpuIO_WriteLongReal (long double x, unsigned int TotalWidth, unsigned int FractionWidth);
87 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
88 FractionWidth into a string.
91 extern "C" void FpuIO_StrToLongReal (const char *a_, unsigned int _a_high, long double *x);
94 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
95 FractionWidth into a string.
98 extern "C" void FpuIO_LongRealToStr (long double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high);
101 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
102 FractionWidth into a string.
105 extern "C" void FpuIO_ReadLongInt (long int *x);
108 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
109 FractionWidth into a string.
112 extern "C" void FpuIO_WriteLongInt (long int x, unsigned int n);
115 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
116 FractionWidth into a string.
119 extern "C" void FpuIO_StrToLongInt (const char *a_, unsigned int _a_high, long int *x);
122 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
123 FractionWidth into a string.
126 extern "C" void FpuIO_LongIntToStr (long int x, unsigned int n, char *a, unsigned int _a_high);
128 extern "C" void FpuIO_ReadReal (double *x)
130 typedef struct ReadReal__T1_a ReadReal__T1;
132 struct ReadReal__T1_a { char array[MaxLineLength+1]; };
133 ReadReal__T1 a;
136 #undef GM2_DEBUG_FPUIO
137 if defined(GM2_DEBUG_FPUIO)
138 # define InitString(X) InitStringDB(X, __FILE__, __LINE__)
139 # define InitStringCharStar(X) InitStringCharStarDB(X, __FILE__, __LINE__)
140 # define InitStringChar(X) InitStringCharDB(X, __FILE__, __LINE__)
141 # define Mult(X,Y) MultDB(X, Y, __FILE__, __LINE__)
142 # define Dup(X) DupDB(X, __FILE__, __LINE__)
143 # define Slice(X,Y,Z) SliceDB(X, Y, Z, __FILE__, __LINE__)
144 #endif
146 StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
147 FpuIO_StrToReal ((const char *) &a.array[0], MaxLineLength, x);
152 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
153 FractionWidth into, string, a.
156 extern "C" void FpuIO_WriteReal (double x, unsigned int TotalWidth, unsigned int FractionWidth)
158 typedef struct WriteReal__T2_a WriteReal__T2;
160 struct WriteReal__T2_a { char array[MaxLineLength+1]; };
161 WriteReal__T2 a;
163 FpuIO_RealToStr (x, TotalWidth, FractionWidth, (char *) &a.array[0], MaxLineLength);
164 StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
169 WriteReal - converts a REAL number, x, which has a, TotalWidth, and
170 FractionWidth into, string, a.
173 extern "C" void FpuIO_StrToReal (const char *a_, unsigned int _a_high, double *x)
175 long double lr;
176 char a[_a_high+1];
178 /* make a local copy of each unbounded array. */
179 memcpy (a, a_, _a_high+1);
181 FpuIO_StrToLongReal ((const char *) a, _a_high, &lr); /* let StrToLongReal do the work and we convert the result back to REAL */
182 (*x) = (double ) (lr); /* let StrToLongReal do the work and we convert the result back to REAL */
187 RealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
188 FractionWidth into a string.
191 extern "C" void FpuIO_RealToStr (double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high)
193 long double lr;
195 lr = (long double ) (x);
196 FpuIO_LongRealToStr (lr, TotalWidth, FractionWidth, (char *) a, _a_high);
199 extern "C" void FpuIO_ReadLongReal (long double *x)
201 typedef struct ReadLongReal__T3_a ReadLongReal__T3;
203 struct ReadLongReal__T3_a { char array[MaxLineLength+1]; };
204 ReadLongReal__T3 a;
206 StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
207 FpuIO_StrToLongReal ((const char *) &a.array[0], MaxLineLength, x);
212 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
213 FractionWidth into a string.
216 extern "C" void FpuIO_WriteLongReal (long double x, unsigned int TotalWidth, unsigned int FractionWidth)
218 typedef struct WriteLongReal__T4_a WriteLongReal__T4;
220 struct WriteLongReal__T4_a { char array[MaxLineLength+1]; };
221 WriteLongReal__T4 a;
223 FpuIO_LongRealToStr (x, TotalWidth, FractionWidth, (char *) &a.array[0], MaxLineLength);
224 StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
229 WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
230 FractionWidth into a string.
233 extern "C" void FpuIO_StrToLongReal (const char *a_, unsigned int _a_high, long double *x)
235 bool found;
236 DynamicStrings_String s;
237 char a[_a_high+1];
239 /* make a local copy of each unbounded array. */
240 memcpy (a, a_, _a_high+1);
242 s = DynamicStrings_InitString ((const char *) a, _a_high);
243 (*x) = StringConvert_StringToLongreal (s, &found);
244 s = DynamicStrings_KillString (s);
249 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
250 FractionWidth into a string.
253 extern "C" void FpuIO_LongRealToStr (long double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high)
255 DynamicStrings_String s;
257 s = StringConvert_LongrealToString (x, TotalWidth, FractionWidth);
258 DynamicStrings_CopyOut ((char *) a, _a_high, s);
259 s = DynamicStrings_KillString (s);
264 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
265 FractionWidth into a string.
268 extern "C" void FpuIO_ReadLongInt (long int *x)
270 typedef struct ReadLongInt__T5_a ReadLongInt__T5;
272 struct ReadLongInt__T5_a { char array[MaxLineLength+1]; };
273 ReadLongInt__T5 a;
275 StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
276 FpuIO_StrToLongInt ((const char *) &a.array[0], MaxLineLength, x);
281 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
282 FractionWidth into a string.
285 extern "C" void FpuIO_WriteLongInt (long int x, unsigned int n)
287 typedef struct WriteLongInt__T6_a WriteLongInt__T6;
289 struct WriteLongInt__T6_a { char array[MaxLineLength+1]; };
290 WriteLongInt__T6 a;
292 FpuIO_LongIntToStr (x, n, (char *) &a.array[0], MaxLineLength);
293 StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
298 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
299 FractionWidth into a string.
302 extern "C" void FpuIO_StrToLongInt (const char *a_, unsigned int _a_high, long int *x)
304 DynamicStrings_String s;
305 bool found;
306 char a[_a_high+1];
308 /* make a local copy of each unbounded array. */
309 memcpy (a, a_, _a_high+1);
311 s = DynamicStrings_InitString ((const char *) a, _a_high);
312 (*x) = StringConvert_StringToLongInteger (s, 10, &found);
313 s = DynamicStrings_KillString (s);
318 LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
319 FractionWidth into a string.
322 extern "C" void FpuIO_LongIntToStr (long int x, unsigned int n, char *a, unsigned int _a_high)
324 DynamicStrings_String s;
326 s = StringConvert_LongIntegerToString (x, n, ' ', false, 10, true);
327 DynamicStrings_CopyOut ((char *) a, _a_high, s);
328 s = DynamicStrings_KillString (s);
331 extern "C" void _M2_FpuIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
335 extern "C" void _M2_FpuIO_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])