Debian Codegraph @

gcc/m2/mc-boot/GmcStack.cc

raw
1 /* do not edit automatically generated by mc from mcStack. */
2 /* This file is part of GNU Modula-2.
3
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.
8
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.
13
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/>. */
17
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
26
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
34
35 #include "GmcStack.h"
36 # include "GStorage.h"
37 # include "GIndexing.h"
38 # include "GM2RTS.h"
39
40 typedef struct mcStack__T1_r mcStack__T1;
41
42 typedef mcStack__T1 *mcStack_stack__opaque;
43
44 struct mcStack__T1_r {
45 Indexing_Index list;
46 unsigned int count;
47 };
48
49
50 /*
51 init - create and return a stack.
52 */
53
54 extern "C" mcStack_stack mcStack_init (void);
55
56 /*
57 kill - deletes stack, s.
58 */
59
60 extern "C" void mcStack_kill (mcStack_stack *s);
61
62 /*
63 push - an address, a, onto the stack, s.
64 It returns, a.
65 */
66
67 extern "C" void * mcStack_push (mcStack_stack s, void * a);
68
69 /*
70 pop - and return the top element from stack, s.
71 */
72
73 extern "C" void * mcStack_pop (mcStack_stack s);
74
75 /*
76 replace - performs a pop; push (a); return a.
77 */
78
79 extern "C" void * mcStack_replace (mcStack_stack s, void * a);
80
81 /*
82 depth - returns the depth of the stack.
83 */
84
85 extern "C" unsigned int mcStack_depth (mcStack_stack s);
86
87 /*
88 access - returns the, i, th stack element.
89 The top of stack is defined by:
90
91 access (s, depth (s)).
92 */
93
94 extern "C" void * mcStack_access (mcStack_stack s, unsigned int i);
95
96
97 /*
98 init - create and return a stack.
99 */
100
101 extern "C" mcStack_stack mcStack_init (void)
102 {
103 mcStack_stack__opaque s;
104
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 ();
111 }
112
113
114 /*
115 kill - deletes stack, s.
116 */
117
118 extern "C" void mcStack_kill (mcStack_stack *s)
119 {
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);
123 }
124
125
126 /*
127 push - an address, a, onto the stack, s.
128 It returns, a.
129 */
130
131 extern "C" void * mcStack_push (mcStack_stack s, void * a)
132 {
133 if (static_cast<mcStack_stack__opaque> (s)->count == 0)
134 {
135 Indexing_PutIndice (static_cast<mcStack_stack__opaque> (s)->list, Indexing_LowIndice (static_cast<mcStack_stack__opaque> (s)->list), a);
136 }
137 else
138 {
139 Indexing_PutIndice (static_cast<mcStack_stack__opaque> (s)->list, (Indexing_HighIndice (static_cast<mcStack_stack__opaque> (s)->list))+1, a);
140 }
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 ();
145 }
146
147
148 /*
149 pop - and return the top element from stack, s.
150 */
151
152 extern "C" void * mcStack_pop (mcStack_stack s)
153 {
154 void * a;
155
156 if (static_cast<mcStack_stack__opaque> (s)->count == 0)
157 {
158 M2RTS_HALT (-1);
159 __builtin_unreachable ();
160 }
161 else
162 {
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;
167 }
168 ReturnException ("../../gcc/m2/mc/mcStack.def", 20, 1);
169 __builtin_unreachable ();
170 }
171
172
173 /*
174 replace - performs a pop; push (a); return a.
175 */
176
177 extern "C" void * mcStack_replace (mcStack_stack s, void * a)
178 {
179 void * b;
180
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 ();
185 }
186
187
188 /*
189 depth - returns the depth of the stack.
190 */
191
192 extern "C" unsigned int mcStack_depth (mcStack_stack s)
193 {
194 return static_cast<mcStack_stack__opaque> (s)->count;
195 /* static analysis guarentees a RETURN statement will be used before here. */
196 __builtin_unreachable ();
197 }
198
199
200 /*
201 access - returns the, i, th stack element.
202 The top of stack is defined by:
203
204 access (s, depth (s)).
205 */
206
207 extern "C" void * mcStack_access (mcStack_stack s, unsigned int i)
208 {
209 if ((i > static_cast<mcStack_stack__opaque> (s)->count) || (i == 0))
210 {
211 M2RTS_HALT (-1);
212 __builtin_unreachable ();
213 }
214 else
215 {
216 return Indexing_GetIndice (static_cast<mcStack_stack__opaque> (s)->list, i);
217 }
218 ReturnException ("../../gcc/m2/mc/mcStack.def", 20, 1);
219 __builtin_unreachable ();
220 }
221
222 extern "C" void _M2_mcStack_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
223 {
224 }
225
226 extern "C" void _M2_mcStack_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
227 {
228 }