libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / m2 / mc-boot / GmcStack.cc
blob70f937b4299161810300f776a152506e5631e875
1 /* do not edit automatically generated by mc from mcStack. */
2 /* This file is part of GNU Modula-2.
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 3, or (at your option) any later
7 version.
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
14 You should have received a copy of the GNU General Public License
15 along with GCC; see the file COPYING3. If not see
16 <http://www.gnu.org/licenses/>. */
18 #include "config.h"
19 #include "system.h"
20 #include <stdbool.h>
21 # if !defined (PROC_D)
22 # define PROC_D
23 typedef void (*PROC_t) (void);
24 typedef struct { PROC_t proc; } PROC;
25 # endif
27 # include "GStorage.h"
28 # include "Gmcrts.h"
29 #if defined(__cplusplus)
30 # undef NULL
31 # define NULL 0
32 #endif
33 #define _mcStack_C
35 #include "GmcStack.h"
36 # include "GStorage.h"
37 # include "GIndexing.h"
38 # include "GM2RTS.h"
40 typedef struct mcStack__T1_r mcStack__T1;
42 typedef mcStack__T1 *mcStack_stack__opaque;
44 struct mcStack__T1_r {
45 Indexing_Index list;
46 unsigned int count;
51 init - create and return a stack.
54 extern "C" mcStack_stack mcStack_init (void);
57 kill - deletes stack, s.
60 extern "C" void mcStack_kill (mcStack_stack *s);
63 push - an address, a, onto the stack, s.
64 It returns, a.
67 extern "C" void * mcStack_push (mcStack_stack s, void * a);
70 pop - and return the top element from stack, s.
73 extern "C" void * mcStack_pop (mcStack_stack s);
76 replace - performs a pop; push (a); return a.
79 extern "C" void * mcStack_replace (mcStack_stack s, void * a);
82 depth - returns the depth of the stack.
85 extern "C" unsigned int mcStack_depth (mcStack_stack s);
88 access - returns the, i, th stack element.
89 The top of stack is defined by:
91 access (s, depth (s)).
94 extern "C" void * mcStack_access (mcStack_stack s, unsigned int i);
98 init - create and return a stack.
101 extern "C" mcStack_stack mcStack_init (void)
103 mcStack_stack__opaque s;
105 Storage_ALLOCATE ((void **) &s, sizeof (mcStack__T1));
106 s->list = Indexing_InitIndex (1);
107 s->count = 0;
108 return static_cast<mcStack_stack> (s);
109 /* static analysis guarentees a RETURN statement will be used before here. */
110 __builtin_unreachable ();
115 kill - deletes stack, s.
118 extern "C" void mcStack_kill (mcStack_stack *s)
120 static_cast<mcStack_stack__opaque> ((*s))->list = Indexing_KillIndex (static_cast<mcStack_stack__opaque> ((*s))->list);
121 Storage_DEALLOCATE ((void **) &(*s), sizeof (mcStack__T1));
122 (*s) = static_cast<mcStack_stack> (NULL);
127 push - an address, a, onto the stack, s.
128 It returns, a.
131 extern "C" void * mcStack_push (mcStack_stack s, void * a)
133 if (static_cast<mcStack_stack__opaque> (s)->count == 0)
135 Indexing_PutIndice (static_cast<mcStack_stack__opaque> (s)->list, Indexing_LowIndice (static_cast<mcStack_stack__opaque> (s)->list), a);
137 else
139 Indexing_PutIndice (static_cast<mcStack_stack__opaque> (s)->list, (Indexing_HighIndice (static_cast<mcStack_stack__opaque> (s)->list))+1, a);
141 static_cast<mcStack_stack__opaque> (s)->count += 1;
142 return a;
143 /* static analysis guarentees a RETURN statement will be used before here. */
144 __builtin_unreachable ();
149 pop - and return the top element from stack, s.
152 extern "C" void * mcStack_pop (mcStack_stack s)
154 void * a;
156 if (static_cast<mcStack_stack__opaque> (s)->count == 0)
158 M2RTS_HALT (-1);
159 __builtin_unreachable ();
161 else
163 static_cast<mcStack_stack__opaque> (s)->count -= 1;
164 a = Indexing_GetIndice (static_cast<mcStack_stack__opaque> (s)->list, Indexing_HighIndice (static_cast<mcStack_stack__opaque> (s)->list));
165 Indexing_DeleteIndice (static_cast<mcStack_stack__opaque> (s)->list, Indexing_HighIndice (static_cast<mcStack_stack__opaque> (s)->list));
166 return a;
168 ReturnException ("../../gcc/m2/mc/mcStack.def", 20, 1);
169 __builtin_unreachable ();
174 replace - performs a pop; push (a); return a.
177 extern "C" void * mcStack_replace (mcStack_stack s, void * a)
179 void * b;
181 b = mcStack_pop (s);
182 return mcStack_push (s, a);
183 /* static analysis guarentees a RETURN statement will be used before here. */
184 __builtin_unreachable ();
189 depth - returns the depth of the stack.
192 extern "C" unsigned int mcStack_depth (mcStack_stack s)
194 return static_cast<mcStack_stack__opaque> (s)->count;
195 /* static analysis guarentees a RETURN statement will be used before here. */
196 __builtin_unreachable ();
201 access - returns the, i, th stack element.
202 The top of stack is defined by:
204 access (s, depth (s)).
207 extern "C" void * mcStack_access (mcStack_stack s, unsigned int i)
209 if ((i > static_cast<mcStack_stack__opaque> (s)->count) || (i == 0))
211 M2RTS_HALT (-1);
212 __builtin_unreachable ();
214 else
216 return Indexing_GetIndice (static_cast<mcStack_stack__opaque> (s)->list, i);
218 ReturnException ("../../gcc/m2/mc/mcStack.def", 20, 1);
219 __builtin_unreachable ();
222 extern "C" void _M2_mcStack_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
226 extern "C" void _M2_mcStack_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])