source: mainline/uspace/app/sbi/src/stree.c@ 09ababb7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 09ababb7 was 09ababb7, checked in by Jiri Svoboda <jiri@…>, 16 years ago

Add Sysel Bootstrap Interpreter (SBI) from Sysel repository rev. 53.

  • Property mode set to 100644
File size: 8.2 KB
Line 
1/*
2 * Copyright (c) 2010 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @file Stree (syntax tree) intermediate representation. */
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <assert.h>
34#include "list.h"
35#include "mytypes.h"
36
37#include "stree.h"
38
39stree_module_t *stree_module_new(void)
40{
41 stree_module_t *module;
42
43 module = calloc(1, sizeof(stree_module_t));
44 if (module == NULL) {
45 printf("Memory allocation failed.\n");
46 exit(1);
47 }
48
49 list_init(&module->members);
50 return module;
51}
52
53stree_modm_t *stree_modm_new(modm_class_t mc)
54{
55 stree_modm_t *modm;
56
57 modm = calloc(1, sizeof(stree_modm_t));
58 if (modm == NULL) {
59 printf("Memory allocation failed.\n");
60 exit(1);
61 }
62
63 modm->mc = mc;
64 return modm;
65}
66
67stree_csi_t *stree_csi_new(csi_class_t cc)
68{
69 stree_csi_t *csi;
70
71 csi = calloc(1, sizeof(stree_csi_t));
72 if (csi == NULL) {
73 printf("Memory allocation failed.\n");
74 exit(1);
75 }
76
77 csi->cc = cc;
78 csi->ancr_state = ws_unvisited;
79 csi->name = NULL;
80 csi->base_csi_ref = NULL;
81 list_init(&csi->members);
82 return csi;
83}
84
85stree_csimbr_t *stree_csimbr_new(csimbr_class_t cc)
86{
87 stree_csimbr_t *csimbr;
88
89 csimbr = calloc(1, sizeof(stree_csimbr_t));
90 if (csimbr == NULL) {
91 printf("Memory allocation failed.\n");
92 exit(1);
93 }
94
95 csimbr->cc = cc;
96 return csimbr;
97}
98
99stree_fun_t *stree_fun_new(void)
100{
101 stree_fun_t *fun;
102
103 fun = calloc(1, sizeof(stree_fun_t));
104 if (fun == NULL) {
105 printf("Memory allocation failed.\n");
106 exit(1);
107 }
108
109 return fun;
110}
111
112stree_var_t *stree_var_new(void)
113{
114 stree_var_t *var;
115
116 var = calloc(1, sizeof(stree_var_t));
117 if (var == NULL) {
118 printf("Memory allocation failed.\n");
119 exit(1);
120 }
121
122 return var;
123}
124
125stree_prop_t *stree_prop_new(void)
126{
127 stree_prop_t *prop;
128
129 prop = calloc(1, sizeof(stree_prop_t));
130 if (prop == NULL) {
131 printf("Memory allocation failed.\n");
132 exit(1);
133 }
134
135 return prop;
136}
137
138stree_fun_arg_t *stree_fun_arg_new(void)
139{
140 stree_fun_arg_t *fun_arg;
141
142 fun_arg = calloc(1, sizeof(stree_fun_arg_t));
143 if (fun_arg == NULL) {
144 printf("Memory allocation failed.\n");
145 exit(1);
146 }
147
148 return fun_arg;
149}
150
151stree_stat_t *stree_stat_new(stat_class_t sc)
152{
153 stree_stat_t *stat;
154
155 stat = calloc(1, sizeof(stree_stat_t));
156 if (stat == NULL) {
157 printf("Memory allocation failed.\n");
158 exit(1);
159 }
160
161 stat->sc = sc;
162 return stat;
163}
164
165stree_vdecl_t *stree_vdecl_new(void)
166{
167 stree_vdecl_t *vdecl_s;
168
169 vdecl_s = calloc(1, sizeof(stree_vdecl_t));
170 if (vdecl_s == NULL) {
171 printf("Memory allocation failed.\n");
172 exit(1);
173 }
174
175 return vdecl_s;
176}
177
178stree_if_t *stree_if_new(void)
179{
180 stree_if_t *if_s;
181
182 if_s = calloc(1, sizeof(stree_if_t));
183 if (if_s == NULL) {
184 printf("Memory allocation failed.\n");
185 exit(1);
186 }
187
188 return if_s;
189}
190
191stree_while_t *stree_while_new(void)
192{
193 stree_while_t *while_s;
194
195 while_s = calloc(1, sizeof(stree_while_t));
196 if (while_s == NULL) {
197 printf("Memory allocation failed.\n");
198 exit(1);
199 }
200
201 return while_s;
202}
203
204stree_for_t *stree_for_new(void)
205{
206 stree_for_t *for_s;
207
208 for_s = calloc(1, sizeof(stree_for_t));
209 if (for_s == NULL) {
210 printf("Memory allocation failed.\n");
211 exit(1);
212 }
213
214 return for_s;
215}
216
217stree_raise_t *stree_raise_new(void)
218{
219 stree_raise_t *raise_s;
220
221 raise_s = calloc(1, sizeof(stree_raise_t));
222 if (raise_s == NULL) {
223 printf("Memory allocation failed.\n");
224 exit(1);
225 }
226
227 return raise_s;
228}
229
230stree_wef_t *stree_wef_new(void)
231{
232 stree_wef_t *wef_s;
233
234 wef_s = calloc(1, sizeof(stree_wef_t));
235 if (wef_s == NULL) {
236 printf("Memory allocation failed.\n");
237 exit(1);
238 }
239
240 return wef_s;
241}
242
243stree_exps_t *stree_exps_new(void)
244{
245 stree_exps_t *exp_s;
246
247 exp_s = calloc(1, sizeof(stree_exps_t));
248 if (exp_s == NULL) {
249 printf("Memory allocation failed.\n");
250 exit(1);
251 }
252
253 return exp_s;
254}
255
256stree_block_t *stree_block_new(void)
257{
258 stree_block_t *block;
259
260 block = calloc(1, sizeof(stree_block_t));
261 if (block == NULL) {
262 printf("Memory allocation failed.\n");
263 exit(1);
264 }
265
266 return block;
267}
268
269stree_expr_t *stree_expr_new(expr_class_t ec)
270{
271 stree_expr_t *expr;
272
273 expr = calloc(1, sizeof(stree_expr_t));
274 if (expr == NULL) {
275 printf("Memory allocation failed.\n");
276 exit(1);
277 }
278
279 expr->ec = ec;
280 return expr;
281}
282
283stree_assign_t *stree_assign_new(assign_class_t ac)
284{
285 stree_assign_t *assign;
286
287 assign = calloc(1, sizeof(stree_assign_t));
288 if (assign == NULL) {
289 printf("Memory allocation failed.\n");
290 exit(1);
291 }
292
293 assign->ac = ac;
294 return assign;
295}
296
297stree_binop_t *stree_binop_new(binop_class_t bc)
298{
299 stree_binop_t *binop;
300
301 binop = calloc(1, sizeof(stree_binop_t));
302 if (binop == NULL) {
303 printf("Memory allocation failed.\n");
304 exit(1);
305 }
306
307 binop->bc = bc;
308 return binop;
309}
310
311stree_access_t *stree_access_new(void)
312{
313 stree_access_t *access;
314
315 access = calloc(1, sizeof(stree_access_t));
316 if (access == NULL) {
317 printf("Memory allocation failed.\n");
318 exit(1);
319 }
320
321 return access;
322}
323
324stree_call_t *stree_call_new(void)
325{
326 stree_call_t *call;
327
328 call = calloc(1, sizeof(stree_call_t));
329 if (call == NULL) {
330 printf("Memory allocation failed.\n");
331 exit(1);
332 }
333
334 return call;
335}
336
337stree_nameref_t *stree_nameref_new(void)
338{
339 stree_nameref_t *nameref;
340
341 nameref = calloc(1, sizeof(stree_nameref_t));
342 if (nameref == NULL) {
343 printf("Memory allocation failed.\n");
344 exit(1);
345 }
346
347 return nameref;
348}
349
350stree_ident_t *stree_ident_new(void)
351{
352 stree_ident_t *ident;
353
354 ident = calloc(1, sizeof(stree_ident_t));
355 if (ident == NULL) {
356 printf("Memory allocation failed.\n");
357 exit(1);
358 }
359
360 return ident;
361}
362
363stree_literal_t *stree_literal_new(literal_class_t ltc)
364{
365 stree_literal_t *literal;
366
367 literal = calloc(1, sizeof(stree_literal_t));
368 if (literal == NULL) {
369 printf("Memory allocation failed.\n");
370 exit(1);
371 }
372
373 literal->ltc = ltc;
374 return literal;
375}
376
377stree_texpr_t *stree_texpr_new(texpr_class_t tc)
378{
379 stree_texpr_t *texpr;
380
381 texpr = calloc(1, sizeof(stree_texpr_t));
382 if (texpr == NULL) {
383 printf("Memory allocation failed.\n");
384 exit(1);
385 }
386
387 texpr->tc = tc;
388 return texpr;
389}
390
391stree_tapply_t *stree_tapply_new(void)
392{
393 stree_tapply_t *tapply;
394
395 tapply = calloc(1, sizeof(stree_tapply_t));
396 if (tapply == NULL) {
397 printf("Memory allocation failed.\n");
398 exit(1);
399 }
400
401 return tapply;
402}
403
404stree_taccess_t *stree_taccess_new(void)
405{
406 stree_taccess_t *taccess;
407
408 taccess = calloc(1, sizeof(stree_taccess_t));
409 if (taccess == NULL) {
410 printf("Memory allocation failed.\n");
411 exit(1);
412 }
413
414 return taccess;
415}
416
417stree_tnameref_t *stree_tnameref_new(void)
418{
419 stree_tnameref_t *tnameref;
420
421 tnameref = calloc(1, sizeof(stree_tnameref_t));
422 if (tnameref == NULL) {
423 printf("Memory allocation failed.\n");
424 exit(1);
425 }
426
427 return tnameref;
428}
429
430stree_symbol_t *stree_symbol_new(symbol_class_t sc)
431{
432 stree_symbol_t *symbol;
433
434 symbol = calloc(1, sizeof(stree_symbol_t));
435 if (symbol == NULL) {
436 printf("Memory allocation failed.\n");
437 exit(1);
438 }
439
440 symbol->sc = sc;
441 return symbol;
442}
443
444stree_program_t *stree_program_new(void)
445{
446 stree_program_t *program;
447
448 program = calloc(1, sizeof(stree_program_t));
449 if (program == NULL) {
450 printf("Memory allocation failed.\n");
451 exit(1);
452 }
453
454 return program;
455}
Note: See TracBrowser for help on using the repository browser.