Debian Codegraph @

gcc/m2/mc-boot/Gvarargs.cc

raw
1 /* do not edit automatically generated by mc from varargs. */
2 /* varargs.mod provides a basic vararg facility for GNU Modula-2.
3
4 Copyright (C) 2015-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 You should have received a copy of the GNU General Public License
20 along with GNU Modula-2; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
22
23 #include "config.h"
24 #include "system.h"
25 #include <stdbool.h>
26 # if !defined (PROC_D)
27 # define PROC_D
28 typedef void (*PROC_t) (void);
29 typedef struct { PROC_t proc; } PROC;
30 # endif
31
32 # include "GStorage.h"
33 #if defined(__cplusplus)
34 # undef NULL
35 # define NULL 0
36 #endif
37 #define _varargs_C
38
39 #include "Gvarargs.h"
40 # include "GStorage.h"
41 # include "Glibc.h"
42 # include "GSYSTEM.h"
43 # include "GM2RTS.h"
44
45 # define MaxArg 4
46 typedef struct varargs_argDesc_r varargs_argDesc;
47
48 typedef struct varargs__T6_r varargs__T6;
49
50 typedef unsigned char *varargs_ptrToByte;
51
52 typedef struct varargs__T7_a varargs__T7;
53
54 typedef varargs__T6 *varargs_vararg__opaque;
55
56 struct varargs_argDesc_r {
57 void * ptr;
58 unsigned int len;
59 };
60
61 struct varargs__T7_a { varargs_argDesc array[MaxArg+1]; };
62 struct varargs__T6_r {
63 unsigned int nArgs;
64 unsigned int i;
65 void * contents;
66 unsigned int size;
67 varargs__T7 arg;
68 };
69
70
71 /*
72 nargs - returns the number of arguments wrapped in, v.
73 */
74
75 extern "C" unsigned int varargs_nargs (varargs_vararg v);
76
77 /*
78 arg - fills in, a, with the next argument. The size of, a, must be an exact
79 match with the original vararg parameter.
80 */
81
82 extern "C" void varargs_arg (varargs_vararg v, unsigned char *a, unsigned int _a_high);
83
84 /*
85 next - assigns the next arg to be collected as, i.
86 */
87
88 extern "C" void varargs_next (varargs_vararg v, unsigned int i);
89
90 /*
91 copy - returns a copy of, v.
92 */
93
94 extern "C" varargs_vararg varargs_copy (varargs_vararg v);
95
96 /*
97 replace - fills the next argument with, a. The size of, a,
98 must be an exact match with the original vararg
99 parameter.
100 */
101
102 extern "C" void varargs_replace (varargs_vararg v, unsigned char *a, unsigned int _a_high);
103
104 /*
105 end - destructor for vararg, v.
106 */
107
108 extern "C" void varargs_end (varargs_vararg *v);
109
110 /*
111 start1 - wraps up argument, a, into a vararg.
112 */
113
114 extern "C" varargs_vararg varargs_start1 (const unsigned char *a_, unsigned int _a_high);
115
116 /*
117 start2 - wraps up arguments, a, b, into a vararg.
118 */
119
120 extern "C" varargs_vararg varargs_start2 (const unsigned char *a_, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high);
121
122 /*
123 start3 - wraps up arguments, a, b, c, into a vararg.
124 */
125
126 extern "C" varargs_vararg varargs_start3 (const unsigned char *a_, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high, const unsigned char *c_, unsigned int _c_high);
127
128 /*
129 start4 - wraps up arguments, a, b, c, d, into a vararg.
130 */
131
132 extern "C" varargs_vararg varargs_start4 (const unsigned char *a_, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high, const unsigned char *c_, unsigned int _c_high, const unsigned char *d_, unsigned int _d_high);
133
134
135 /*
136 nargs - returns the number of arguments wrapped in, v.
137 */
138
139 extern "C" unsigned int varargs_nargs (varargs_vararg v)
140 {
141 return static_cast<varargs_vararg__opaque> (v)->nArgs;
142 /* static analysis guarentees a RETURN statement will be used before here. */
143 __builtin_unreachable ();
144 }
145
146
147 /*
148 arg - fills in, a, with the next argument. The size of, a, must be an exact
149 match with the original vararg parameter.
150 */
151
152 extern "C" void varargs_arg (varargs_vararg v, unsigned char *a, unsigned int _a_high)
153 {
154 typedef unsigned char *arg__T1;
155
156 arg__T1 p;
157 unsigned int j;
158
159 if (static_cast<varargs_vararg__opaque> (v)->i == static_cast<varargs_vararg__opaque> (v)->nArgs)
160 {
161 M2RTS_HALT (-1); /* too many calls to arg. */
162 __builtin_unreachable ();
163 }
164 else
165 {
166 if ((_a_high+1) == static_cast<varargs_vararg__opaque> (v)->arg.array[static_cast<varargs_vararg__opaque> (v)->i].len)
167 {
168 p = static_cast<arg__T1> (static_cast<varargs_vararg__opaque> (v)->arg.array[static_cast<varargs_vararg__opaque> (v)->i].ptr);
169 j = 0;
170 while (j <= _a_high)
171 {
172 const_cast<unsigned char *>(a)[j] = (*p);
173 p += 1;
174 j += 1;
175 }
176 }
177 else
178 {
179 M2RTS_HALT (-1); /* parameter mismatch. */
180 __builtin_unreachable ();
181 }
182 static_cast<varargs_vararg__opaque> (v)->i += 1;
183 }
184 }
185
186
187 /*
188 next - assigns the next arg to be collected as, i.
189 */
190
191 extern "C" void varargs_next (varargs_vararg v, unsigned int i)
192 {
193 static_cast<varargs_vararg__opaque> (v)->i = i;
194 }
195
196
197 /*
198 copy - returns a copy of, v.
199 */
200
201 extern "C" varargs_vararg varargs_copy (varargs_vararg v)
202 {
203 varargs_vararg__opaque c;
204 unsigned int j;
205 unsigned int offset;
206
207 Storage_ALLOCATE ((void **) &c, sizeof (varargs__T6));
208 c->i = static_cast<varargs_vararg__opaque> (v)->i;
209 c->nArgs = static_cast<varargs_vararg__opaque> (v)->nArgs;
210 c->size = static_cast<varargs_vararg__opaque> (v)->size;
211 Storage_ALLOCATE (&c->contents, c->size);
212 c->contents = libc_memcpy (c->contents, static_cast<varargs_vararg__opaque> (v)->contents, static_cast<size_t> (c->size));
213 for (j=0; j<=c->nArgs; j++)
214 {
215 offset = (unsigned int ) (((varargs_ptrToByte) (static_cast<varargs_vararg__opaque> (v)->contents))-((varargs_ptrToByte) (static_cast<varargs_vararg__opaque> (v)->arg.array[j].ptr)));
216 c->arg.array[j].ptr = static_cast<void *> ((varargs_ptrToByte) (c->contents));
217 c->arg.array[j].ptr = reinterpret_cast<void *> (reinterpret_cast<char *> (c->arg.array[j].ptr)+offset);
218 c->arg.array[j].len = static_cast<varargs_vararg__opaque> (v)->arg.array[j].len;
219 }
220 return static_cast<varargs_vararg> (c);
221 /* static analysis guarentees a RETURN statement will be used before here. */
222 __builtin_unreachable ();
223 }
224
225
226 /*
227 replace - fills the next argument with, a. The size of, a,
228 must be an exact match with the original vararg
229 parameter.
230 */
231
232 extern "C" void varargs_replace (varargs_vararg v, unsigned char *a, unsigned int _a_high)
233 {
234 typedef unsigned char *replace__T2;
235
236 replace__T2 p;
237 unsigned int j;
238
239 if (static_cast<varargs_vararg__opaque> (v)->i == static_cast<varargs_vararg__opaque> (v)->nArgs)
240 {
241 M2RTS_HALT (-1); /* too many calls to arg. */
242 __builtin_unreachable ();
243 }
244 else
245 {
246 if ((_a_high+1) == static_cast<varargs_vararg__opaque> (v)->arg.array[static_cast<varargs_vararg__opaque> (v)->i].len)
247 {
248 p = static_cast<replace__T2> (static_cast<varargs_vararg__opaque> (v)->arg.array[static_cast<varargs_vararg__opaque> (v)->i].ptr);
249 j = 0;
250 while (j <= _a_high)
251 {
252 (*p) = a[j];
253 p += 1;
254 j += 1;
255 }
256 }
257 else
258 {
259 M2RTS_HALT (-1); /* parameter mismatch. */
260 __builtin_unreachable ();
261 }
262 }
263 }
264
265
266 /*
267 end - destructor for vararg, v.
268 */
269
270 extern "C" void varargs_end (varargs_vararg *v)
271 {
272 if ((*v) != NULL)
273 {
274 Storage_DEALLOCATE (&static_cast<varargs_vararg__opaque> ((*v))->contents, sizeof (varargs_vararg));
275 Storage_DEALLOCATE ((void **) &(*v), sizeof (varargs__T6));
276 }
277 }
278
279
280 /*
281 start1 - wraps up argument, a, into a vararg.
282 */
283
284 extern "C" varargs_vararg varargs_start1 (const unsigned char *a_, unsigned int _a_high)
285 {
286 varargs_vararg__opaque v;
287 unsigned char a[_a_high+1];
288
289 /* make a local copy of each unbounded array. */
290 memcpy (a, a_, _a_high+1);
291
292 Storage_ALLOCATE ((void **) &v, sizeof (varargs__T6));
293 v->i = 0;
294 v->nArgs = 1;
295 v->size = _a_high+1;
296 Storage_ALLOCATE (&v->contents, v->size);
297 v->contents = libc_memcpy (v->contents, const_cast<void*> (static_cast<const void*>(a)), static_cast<size_t> (v->size));
298 v->arg.array[0].ptr = v->contents;
299 v->arg.array[0].len = v->size;
300 return static_cast<varargs_vararg> (v);
301 /* static analysis guarentees a RETURN statement will be used before here. */
302 __builtin_unreachable ();
303 }
304
305
306 /*
307 start2 - wraps up arguments, a, b, into a vararg.
308 */
309
310 extern "C" varargs_vararg varargs_start2 (const unsigned char *a_, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high)
311 {
312 typedef unsigned char *start2__T3;
313
314 varargs_vararg__opaque v;
315 start2__T3 p;
316 unsigned char a[_a_high+1];
317 unsigned char b[_b_high+1];
318
319 /* make a local copy of each unbounded array. */
320 memcpy (a, a_, _a_high+1);
321 memcpy (b, b_, _b_high+1);
322
323 Storage_ALLOCATE ((void **) &v, sizeof (varargs__T6));
324 v->i = 0;
325 v->nArgs = 2;
326 v->size = (_a_high+_b_high)+2;
327 Storage_ALLOCATE (&v->contents, v->size);
328 p = static_cast<start2__T3> (libc_memcpy (v->contents, const_cast<void*> (static_cast<const void*>(a)), static_cast<size_t> (_a_high+1)));
329 v->arg.array[0].ptr = static_cast<void *> (p);
330 v->arg.array[0].len = _a_high+1;
331 p += v->arg.array[0].len;
332 p = static_cast<start2__T3> (libc_memcpy (reinterpret_cast <void *> (p), const_cast<void*> (static_cast<const void*>(b)), static_cast<size_t> (_b_high+1)));
333 v->arg.array[1].ptr = static_cast<void *> (p);
334 v->arg.array[1].len = _b_high+1;
335 return static_cast<varargs_vararg> (v);
336 /* static analysis guarentees a RETURN statement will be used before here. */
337 __builtin_unreachable ();
338 }
339
340
341 /*
342 start3 - wraps up arguments, a, b, c, into a vararg.
343 */
344
345 extern "C" varargs_vararg varargs_start3 (const unsigned char *a_, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high, const unsigned char *c_, unsigned int _c_high)
346 {
347 typedef unsigned char *start3__T4;
348
349 varargs_vararg__opaque v;
350 start3__T4 p;
351 unsigned char a[_a_high+1];
352 unsigned char b[_b_high+1];
353 unsigned char c[_c_high+1];
354
355 /* make a local copy of each unbounded array. */
356 memcpy (a, a_, _a_high+1);
357 memcpy (b, b_, _b_high+1);
358 memcpy (c, c_, _c_high+1);
359
360 Storage_ALLOCATE ((void **) &v, sizeof (varargs__T6));
361 v->i = 0;
362 v->nArgs = 3;
363 v->size = ((_a_high+_b_high)+_c_high)+3;
364 Storage_ALLOCATE (&v->contents, v->size);
365 p = static_cast<start3__T4> (libc_memcpy (v->contents, const_cast<void*> (static_cast<const void*>(a)), static_cast<size_t> (_a_high+1)));
366 v->arg.array[0].ptr = static_cast<void *> (p);
367 v->arg.array[0].len = _a_high+1;
368 p += v->arg.array[0].len;
369 p = static_cast<start3__T4> (libc_memcpy (reinterpret_cast <void *> (p), const_cast<void*> (static_cast<const void*>(b)), static_cast<size_t> (_b_high+1)));
370 v->arg.array[1].ptr = static_cast<void *> (p);
371 v->arg.array[1].len = _b_high+1;
372 p += v->arg.array[1].len;
373 p = static_cast<start3__T4> (libc_memcpy (reinterpret_cast <void *> (p), const_cast<void*> (static_cast<const void*>(c)), static_cast<size_t> (_c_high+1)));
374 v->arg.array[2].ptr = static_cast<void *> (p);
375 v->arg.array[2].len = _c_high+1;
376 return static_cast<varargs_vararg> (v);
377 /* static analysis guarentees a RETURN statement will be used before here. */
378 __builtin_unreachable ();
379 }
380
381
382 /*
383 start4 - wraps up arguments, a, b, c, d, into a vararg.
384 */
385
386 extern "C" varargs_vararg varargs_start4 (const unsigned char *a_, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high, const unsigned char *c_, unsigned int _c_high, const unsigned char *d_, unsigned int _d_high)
387 {
388 typedef unsigned char *start4__T5;
389
390 varargs_vararg__opaque v;
391 start4__T5 p;
392 unsigned char a[_a_high+1];
393 unsigned char b[_b_high+1];
394 unsigned char c[_c_high+1];
395 unsigned char d[_d_high+1];
396
397 /* make a local copy of each unbounded array. */
398 memcpy (a, a_, _a_high+1);
399 memcpy (b, b_, _b_high+1);
400 memcpy (c, c_, _c_high+1);
401 memcpy (d, d_, _d_high+1);
402
403 Storage_ALLOCATE ((void **) &v, sizeof (varargs__T6));
404 v->i = 0;
405 v->nArgs = 4;
406 v->size = (((_a_high+_b_high)+_c_high)+_d_high)+4;
407 Storage_ALLOCATE (&v->contents, v->size);
408 p = static_cast<start4__T5> (libc_memcpy (v->contents, const_cast<void*> (static_cast<const void*>(a)), static_cast<size_t> (_a_high+1)));
409 v->arg.array[0].len = _a_high+1;
410 p += v->arg.array[0].len;
411 p = static_cast<start4__T5> (libc_memcpy (reinterpret_cast <void *> (p), const_cast<void*> (static_cast<const void*>(b)), static_cast<size_t> (_b_high+1)));
412 v->arg.array[1].ptr = static_cast<void *> (p);
413 v->arg.array[1].len = _b_high+1;
414 p += v->arg.array[1].len;
415 p = static_cast<start4__T5> (libc_memcpy (reinterpret_cast <void *> (p), const_cast<void*> (static_cast<const void*>(c)), static_cast<size_t> (_c_high+1)));
416 v->arg.array[2].ptr = static_cast<void *> (p);
417 v->arg.array[2].len = _c_high+1;
418 p += v->arg.array[2].len;
419 p = static_cast<start4__T5> (libc_memcpy (reinterpret_cast <void *> (p), const_cast<void*> (static_cast<const void*>(c)), static_cast<size_t> (_c_high+1)));
420 v->arg.array[3].ptr = static_cast<void *> (p);
421 v->arg.array[3].len = _c_high+1;
422 return static_cast<varargs_vararg> (v);
423 /* static analysis guarentees a RETURN statement will be used before here. */
424 __builtin_unreachable ();
425 }
426
427 extern "C" void _M2_varargs_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
428 {
429 }
430
431 extern "C" void _M2_varargs_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
432 {
433 }