include: add macros to properly declare assembly functions/data
[hvf.git] / build / byacc / skeleton.c
blobdebd4fa19204063d98061b9a6f116c4f73a919f3
1 /* $Id: skeleton.c,v 1.31 2011/09/07 09:37:59 tom Exp $ */
3 #include "defs.h"
5 /* The #defines included with the banner are there because they are */
6 /* useful in subsequent code. The macros #defined in the header or */
7 /* the body either are not useful outside of semantic actions or */
8 /* are conditional. */
10 const char *const banner[] =
12 "#define YYBYACC 1",
13 CONCAT1("#define YYMAJOR ", YYMAJOR),
14 CONCAT1("#define YYMINOR ", YYMINOR),
15 #ifdef YYPATCH
16 CONCAT1("#define YYPATCH ", YYPATCH),
17 #endif
18 "",
19 "#define YYEMPTY (-1)",
20 "#define yyclearin (yychar = YYEMPTY)",
21 "#define yyerrok (yyerrflag = 0)",
22 "#define YYRECOVERING() (yyerrflag != 0)",
23 "",
27 const char *const xdecls[] =
29 "",
30 "extern int YYPARSE_DECL();",
34 const char *const tables[] =
36 "extern short yylhs[];",
37 "extern short yylen[];",
38 "extern short yydefred[];",
39 "extern short yydgoto[];",
40 "extern short yysindex[];",
41 "extern short yyrindex[];",
42 "extern short yygindex[];",
43 "extern short yytable[];",
44 "extern short yycheck[];",
45 "",
46 "#if YYDEBUG",
47 "extern char *yyname[];",
48 "extern char *yyrule[];",
49 "#endif",
53 const char *const global_vars[] =
55 "",
56 "int yydebug;",
57 "int yynerrs;",
61 const char *const impure_vars[] =
63 "",
64 "int yyerrflag;",
65 "int yychar;",
66 "YYSTYPE yyval;",
67 "YYSTYPE yylval;",
71 const char *const hdr_defs[] =
73 "",
74 "/* define the initial stack-sizes */",
75 "#ifdef YYSTACKSIZE",
76 "#undef YYMAXDEPTH",
77 "#define YYMAXDEPTH YYSTACKSIZE",
78 "#else",
79 "#ifdef YYMAXDEPTH",
80 "#define YYSTACKSIZE YYMAXDEPTH",
81 "#else",
82 "#define YYSTACKSIZE 500",
83 "#define YYMAXDEPTH 500",
84 "#endif",
85 "#endif",
86 "",
87 "#define YYINITSTACKSIZE 50",
88 "",
89 "typedef struct {",
90 " unsigned stacksize;",
91 " short *s_base;",
92 " short *s_mark;",
93 " short *s_last;",
94 " YYSTYPE *l_base;",
95 " YYSTYPE *l_mark;",
96 "} YYSTACKDATA;",
100 const char *const hdr_vars[] =
102 "/* variables for the parser stack */",
103 "static YYSTACKDATA yystack;",
107 const char *const body_vars[] =
109 " int yyerrflag;",
110 " int yychar;",
111 " YYSTYPE yyval;",
112 " YYSTYPE yylval;",
114 " /* variables for the parser stack */",
115 " YYSTACKDATA yystack;",
119 const char *const body_1[] =
122 "#if YYDEBUG",
123 "#include <stdio.h> /* needed for printf */",
124 "#endif",
126 "#include <parser.h>",
128 "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
129 "static int yygrowstack(struct parser *p, YYSTACKDATA *data)",
130 "{",
131 " int i;",
132 " unsigned newsize;",
133 " short *newss;",
134 " YYSTYPE *newvs;",
136 " if ((newsize = data->stacksize) == 0)",
137 " newsize = YYINITSTACKSIZE;",
138 " else if (newsize >= YYMAXDEPTH)",
139 " return -1;",
140 " else if ((newsize *= 2) > YYMAXDEPTH)",
141 " newsize = YYMAXDEPTH;",
143 " i = data->s_mark - data->s_base;",
144 " newss = (short *)p->realloc(data->s_base, newsize * sizeof(*newss));",
145 " if (newss == 0)",
146 " return -1;",
148 " data->s_base = newss;",
149 " data->s_mark = newss + i;",
151 " newvs = (YYSTYPE *)p->realloc(data->l_base, newsize * sizeof(*newvs));",
152 " if (newvs == 0)",
153 " return -1;",
155 " data->l_base = newvs;",
156 " data->l_mark = newvs + i;",
158 " data->stacksize = newsize;",
159 " data->s_last = data->s_base + newsize - 1;",
160 " return 0;",
161 "}",
163 "static void yyfreestack(struct parser *p, YYSTACKDATA *data)",
164 "{",
165 " p->free(data->s_base);",
166 " p->free(data->l_base);",
167 " memset(data, 0, sizeof(*data));",
168 "}",
170 "#define YYABORT goto yyabort",
171 "#define YYREJECT goto yyabort",
172 "#define YYACCEPT goto yyaccept",
173 "#define YYERROR goto yyerrlab",
175 "int",
176 "yyparse(struct parser *parser)",
177 "{",
181 const char *const body_2[] =
183 " int yym, yyn, yystate;",
184 "#if YYDEBUG",
185 " const char *yys;",
187 " if ((yys = getenv(\"YYDEBUG\")) != 0)",
188 " {",
189 " yyn = *yys;",
190 " if (yyn >= '0' && yyn <= '9')",
191 " yydebug = yyn - '0';",
192 " }",
193 "#endif",
195 " yynerrs = 0;",
196 " yyerrflag = 0;",
197 " yychar = YYEMPTY;",
198 " yystate = 0;",
200 "#if YYPURE",
201 " memset(&yystack, 0, sizeof(yystack));",
202 "#endif",
204 " if (yystack.s_base == NULL && yygrowstack(parser, &yystack)) goto yyoverflow;",
205 " yystack.s_mark = yystack.s_base;",
206 " yystack.l_mark = yystack.l_base;",
207 " yystate = 0;",
208 " *yystack.s_mark = 0;",
210 "yyloop:",
211 " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
212 " if (yychar < 0)",
213 " {",
214 " if ((yychar = YYLEX(parser)) < 0) yychar = 0;",
215 "#if YYDEBUG",
216 " if (yydebug)",
217 " {",
218 " yys = 0;",
219 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
220 " if (!yys) yys = \"illegal-symbol\";",
221 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
222 " YYPREFIX, yystate, yychar, yys);",
223 " }",
224 "#endif",
225 " }",
226 " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
227 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
228 " {",
229 "#if YYDEBUG",
230 " if (yydebug)",
231 " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
232 " YYPREFIX, yystate, yytable[yyn]);",
233 "#endif",
234 " if (yystack.s_mark >= yystack.s_last && yygrowstack(parser, &yystack))",
235 " {",
236 " goto yyoverflow;",
237 " }",
238 " yystate = yytable[yyn];",
239 " *++yystack.s_mark = yytable[yyn];",
240 " *++yystack.l_mark = yylval;",
241 " yychar = YYEMPTY;",
242 " if (yyerrflag > 0) --yyerrflag;",
243 " goto yyloop;",
244 " }",
245 " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
246 " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
247 " {",
248 " yyn = yytable[yyn];",
249 " goto yyreduce;",
250 " }",
251 " if (yyerrflag) goto yyinrecovery;",
256 const char *const body_3[] =
259 " goto yyerrlab;",
261 "yyerrlab:",
262 " ++yynerrs;",
264 "yyinrecovery:",
265 " if (yyerrflag < 3)",
266 " {",
267 " yyerrflag = 3;",
268 " for (;;)",
269 " {",
270 " if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&",
271 " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
272 " {",
273 "#if YYDEBUG",
274 " if (yydebug)",
275 " printf(\"%sdebug: state %d, error recovery shifting\\",
276 " to state %d\\n\", YYPREFIX, *yystack.s_mark, yytable[yyn]);",
277 "#endif",
278 " if (yystack.s_mark >= yystack.s_last && yygrowstack(parser, &yystack))",
279 " {",
280 " goto yyoverflow;",
281 " }",
282 " yystate = yytable[yyn];",
283 " *++yystack.s_mark = yytable[yyn];",
284 " *++yystack.l_mark = yylval;",
285 " goto yyloop;",
286 " }",
287 " else",
288 " {",
289 "#if YYDEBUG",
290 " if (yydebug)",
291 " printf(\"%sdebug: error recovery discarding state %d\
292 \\n\",",
293 " YYPREFIX, *yystack.s_mark);",
294 "#endif",
295 " if (yystack.s_mark <= yystack.s_base) goto yyabort;",
296 " --yystack.s_mark;",
297 " --yystack.l_mark;",
298 " }",
299 " }",
300 " }",
301 " else",
302 " {",
303 " if (yychar == 0) goto yyabort;",
304 "#if YYDEBUG",
305 " if (yydebug)",
306 " {",
307 " yys = 0;",
308 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
309 " if (!yys) yys = \"illegal-symbol\";",
310 " printf(\"%sdebug: state %d, error recovery discards token %d\
311 (%s)\\n\",",
312 " YYPREFIX, yystate, yychar, yys);",
313 " }",
314 "#endif",
315 " yychar = YYEMPTY;",
316 " goto yyloop;",
317 " }",
319 "yyreduce:",
320 "#if YYDEBUG",
321 " if (yydebug)",
322 " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
323 " YYPREFIX, yystate, yyn, yyrule[yyn]);",
324 "#endif",
325 " yym = yylen[yyn];",
326 " if (yym)",
327 " yyval = yystack.l_mark[1-yym];",
328 " else",
329 " memset(&yyval, 0, sizeof yyval);",
330 " switch (yyn)",
331 " {",
335 const char *const trailer[] =
337 " }",
338 " yystack.s_mark -= yym;",
339 " yystate = *yystack.s_mark;",
340 " yystack.l_mark -= yym;",
341 " yym = yylhs[yyn];",
342 " if (yystate == 0 && yym == 0)",
343 " {",
344 "#if YYDEBUG",
345 " if (yydebug)",
346 " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
347 " state %d\\n\", YYPREFIX, YYFINAL);",
348 "#endif",
349 " yystate = YYFINAL;",
350 " *++yystack.s_mark = YYFINAL;",
351 " *++yystack.l_mark = yyval;",
352 " if (yychar < 0)",
353 " {",
354 " if ((yychar = YYLEX(parser)) < 0) yychar = 0;",
355 "#if YYDEBUG",
356 " if (yydebug)",
357 " {",
358 " yys = 0;",
359 " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
360 " if (!yys) yys = \"illegal-symbol\";",
361 " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
362 " YYPREFIX, YYFINAL, yychar, yys);",
363 " }",
364 "#endif",
365 " }",
366 " if (yychar == 0) goto yyaccept;",
367 " goto yyloop;",
368 " }",
369 " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
370 " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
371 " yystate = yytable[yyn];",
372 " else",
373 " yystate = yydgoto[yym];",
374 "#if YYDEBUG",
375 " if (yydebug)",
376 " printf(\"%sdebug: after reduction, shifting from state %d \\",
377 "to state %d\\n\", YYPREFIX, *yystack.s_mark, yystate);",
378 "#endif",
379 " if (yystack.s_mark >= yystack.s_last && yygrowstack(parser, &yystack))",
380 " {",
381 " goto yyoverflow;",
382 " }",
383 " *++yystack.s_mark = (short) yystate;",
384 " *++yystack.l_mark = yyval;",
385 " goto yyloop;",
387 "yyoverflow:",
391 const char *const trailer_2[] =
394 "yyabort:",
395 " yyfreestack(parser, &yystack);",
396 " return (1);",
398 "yyaccept:",
399 " yyfreestack(parser, &yystack);",
400 " return (0);",
401 "}",
405 void
406 write_section(FILE * fp, const char *const section[])
408 int c;
409 int i;
410 const char *s;
412 for (i = 0; (s = section[i]) != 0; ++i)
414 while ((c = *s) != 0)
416 putc(c, fp);
417 ++s;
419 if (fp == code_file)
420 ++outline;
421 putc('\n', fp);