Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / util / sconfig / sconfig.tab.c_shipped
1
2 /* A Bison parser, made by GNU Bison 2.4.1.  */
3
4 /* Skeleton implementation for Bison's Yacc-like parsers in C
5
6       Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
7    Free Software Foundation, Inc.
8
9    This program 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 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21
22 /* As a special exception, you may create a larger work that contains
23    part or all of the Bison parser skeleton and distribute that work
24    under terms of your choice, so long as that work isn't itself a
25    parser generator using the skeleton or a modified version thereof
26    as a parser skeleton.  Alternatively, if you modify or redistribute
27    the parser skeleton itself, you may (at your option) remove this
28    special exception, which will cause the skeleton and the resulting
29    Bison output files to be licensed under the GNU General Public
30    License without this special exception.
31
32    This special exception was added by the Free Software Foundation in
33    version 2.2 of Bison.  */
34
35 /* C LALR(1) parser skeleton written by Richard Stallman, by
36    simplifying the original so-called "semantic" parser.  */
37
38 /* All symbols defined below should begin with yy or YY, to avoid
39    infringing on user name space.  This should be done even for local
40    variables, as they might otherwise be expanded by user macros.
41    There are some unavoidable exceptions within include files to
42    define necessary library symbols; they are noted "INFRINGES ON
43    USER NAME SPACE" below.  */
44
45 /* Identify Bison output.  */
46 #define YYBISON 1
47
48 /* Bison version.  */
49 #define YYBISON_VERSION "2.4.1"
50
51 /* Skeleton name.  */
52 #define YYSKELETON_NAME "yacc.c"
53
54 /* Pure parsers.  */
55 #define YYPURE 0
56
57 /* Push parsers.  */
58 #define YYPUSH 0
59
60 /* Pull parsers.  */
61 #define YYPULL 1
62
63 /* Using locations.  */
64 #define YYLSP_NEEDED 0
65
66
67
68 /* Copy the first part of user declarations.  */
69
70
71 /*
72  * sconfig, coreboot device tree compiler
73  *
74  * Copyright (C) 2010 coresystems GmbH
75  *                 written by Patrick Georgi <patrick.georgi@coresystems.de>
76  *
77  * This program is free software; you can redistribute it and/or modify
78  * it under the terms of the GNU General Public License as published by
79  * the Free Software Foundation; version 2 of the License.
80  *
81  * This program is distributed in the hope that it will be useful,
82  * but WITHOUT ANY WARRANTY; without even the implied warranty of
83  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
84  * GNU General Public License for more details.
85  *
86  * You should have received a copy of the GNU General Public License
87  * along with this program; if not, write to the Free Software
88  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
89  */
90
91 #include <stdio.h>
92 #include <stdlib.h>
93 #include <string.h>
94 #include <sys/types.h>
95 #include <sys/stat.h>
96 #include <unistd.h>
97 #include <errno.h>
98
99 enum devtype { chip, device };
100
101 struct resource;
102 struct resource {
103         int type;
104         int index;
105         int base;
106         struct resource *next;
107 };
108
109 struct reg;
110 struct reg {
111         char *key;
112         char *value;
113         struct reg *next;
114 };
115
116 struct device;
117 struct device {
118         int id;
119         int enabled;
120         int used;
121         int multidev;
122         int link;
123         int rescnt;
124         int chiph_exists;
125         char *ops;
126         char *name;
127         char *aliased_name;
128         char *name_underscore;
129         char *path;
130         int path_a;
131         int path_b;
132         int bustype;
133         enum devtype type;
134         struct device *parent;
135         struct device *bus;
136         struct device *next;
137         struct device *nextdev;
138         struct device *children;
139         struct device *latestchild;
140         struct device *next_sibling;
141         struct device *sibling;
142         struct device *chip;
143         struct resource *res;
144         struct reg *reg;
145 } *head, *lastdev, *cur_parent, *cur_bus, root;
146
147 struct header;
148 struct header {
149         char *name;
150         struct header *next;
151 } headers;
152
153 int devcount = 0;
154
155 struct device *new_dev() {
156         struct device *dev = malloc(sizeof(struct device));
157         memset(dev, 0, sizeof(struct device));
158         dev->id = ++devcount;
159         dev->parent = cur_parent;
160         dev->bus = cur_bus;
161         head->next = dev;
162         head = dev;
163         return dev;
164 }
165
166 int device_match(struct device *a, struct device *b) {
167         if ((a->bustype == b->bustype) && (a->bus == b->bus) && (a->path_a == b->path_a) && (a->path_b == b->path_b))
168                 return 1;
169         return 0;
170 }
171
172 void fold_in(struct device *parent) {
173         struct device *child = parent->children;
174         struct device *latest = 0;
175         while (child != latest) {
176                 if (child->children) {
177                         if (!latest) latest = child->children;
178                         parent->latestchild->next_sibling = child->children;
179                         parent->latestchild = child->latestchild;
180                 }
181                 child = child->next_sibling;
182         }
183 }
184
185 int yywrap(void) {
186         return 1;
187 }
188
189 void yyerror (char const *str)
190 {
191         fprintf (stderr, "%s\n", str);
192 }
193
194
195
196 /* Enabling traces.  */
197 #ifndef YYDEBUG
198 # define YYDEBUG 0
199 #endif
200
201 /* Enabling verbose error messages.  */
202 #ifdef YYERROR_VERBOSE
203 # undef YYERROR_VERBOSE
204 # define YYERROR_VERBOSE 1
205 #else
206 # define YYERROR_VERBOSE 0
207 #endif
208
209 /* Enabling the token table.  */
210 #ifndef YYTOKEN_TABLE
211 # define YYTOKEN_TABLE 0
212 #endif
213
214
215 /* Tokens.  */
216 #ifndef YYTOKENTYPE
217 # define YYTOKENTYPE
218    /* Put the tokens into the symbol table, so that GDB and other debuggers
219       know about them.  */
220    enum yytokentype {
221      CHIP = 258,
222      DEVICE = 259,
223      REGISTER = 260,
224      BOOL = 261,
225      BUS = 262,
226      RESOURCE = 263,
227      END = 264,
228      EQUALS = 265,
229      HEX = 266,
230      STRING = 267,
231      PCI = 268,
232      PNP = 269,
233      I2C = 270,
234      APIC = 271,
235      APIC_CLUSTER = 272,
236      PCI_DOMAIN = 273,
237      IRQ = 274,
238      DRQ = 275,
239      IO = 276,
240      NUMBER = 277
241    };
242 #endif
243
244
245
246 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
247 typedef union YYSTYPE
248 {
249
250
251         struct device *device;
252         char *string;
253         int number;
254
255
256
257 } YYSTYPE;
258 # define YYSTYPE_IS_TRIVIAL 1
259 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
260 # define YYSTYPE_IS_DECLARED 1
261 #endif
262
263
264 /* Copy the second part of user declarations.  */
265
266
267
268 #ifdef short
269 # undef short
270 #endif
271
272 #ifdef YYTYPE_UINT8
273 typedef YYTYPE_UINT8 yytype_uint8;
274 #else
275 typedef unsigned char yytype_uint8;
276 #endif
277
278 #ifdef YYTYPE_INT8
279 typedef YYTYPE_INT8 yytype_int8;
280 #elif (defined __STDC__ || defined __C99__FUNC__ \
281      || defined __cplusplus || defined _MSC_VER)
282 typedef signed char yytype_int8;
283 #else
284 typedef short int yytype_int8;
285 #endif
286
287 #ifdef YYTYPE_UINT16
288 typedef YYTYPE_UINT16 yytype_uint16;
289 #else
290 typedef unsigned short int yytype_uint16;
291 #endif
292
293 #ifdef YYTYPE_INT16
294 typedef YYTYPE_INT16 yytype_int16;
295 #else
296 typedef short int yytype_int16;
297 #endif
298
299 #ifndef YYSIZE_T
300 # ifdef __SIZE_TYPE__
301 #  define YYSIZE_T __SIZE_TYPE__
302 # elif defined size_t
303 #  define YYSIZE_T size_t
304 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
305      || defined __cplusplus || defined _MSC_VER)
306 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
307 #  define YYSIZE_T size_t
308 # else
309 #  define YYSIZE_T unsigned int
310 # endif
311 #endif
312
313 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
314
315 #ifndef YY_
316 # if YYENABLE_NLS
317 #  if ENABLE_NLS
318 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
319 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
320 #  endif
321 # endif
322 # ifndef YY_
323 #  define YY_(msgid) msgid
324 # endif
325 #endif
326
327 /* Suppress unused-variable warnings by "using" E.  */
328 #if ! defined lint || defined __GNUC__
329 # define YYUSE(e) ((void) (e))
330 #else
331 # define YYUSE(e) /* empty */
332 #endif
333
334 /* Identity function, used to suppress warnings about constant conditions.  */
335 #ifndef lint
336 # define YYID(n) (n)
337 #else
338 #if (defined __STDC__ || defined __C99__FUNC__ \
339      || defined __cplusplus || defined _MSC_VER)
340 static int
341 YYID (int yyi)
342 #else
343 static int
344 YYID (yyi)
345     int yyi;
346 #endif
347 {
348   return yyi;
349 }
350 #endif
351
352 #if ! defined yyoverflow || YYERROR_VERBOSE
353
354 /* The parser invokes alloca or malloc; define the necessary symbols.  */
355
356 # ifdef YYSTACK_USE_ALLOCA
357 #  if YYSTACK_USE_ALLOCA
358 #   ifdef __GNUC__
359 #    define YYSTACK_ALLOC __builtin_alloca
360 #   elif defined __BUILTIN_VA_ARG_INCR
361 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
362 #   elif defined _AIX
363 #    define YYSTACK_ALLOC __alloca
364 #   elif defined _MSC_VER
365 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
366 #    define alloca _alloca
367 #   else
368 #    define YYSTACK_ALLOC alloca
369 #    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
370      || defined __cplusplus || defined _MSC_VER)
371 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
372 #     ifndef _STDLIB_H
373 #      define _STDLIB_H 1
374 #     endif
375 #    endif
376 #   endif
377 #  endif
378 # endif
379
380 # ifdef YYSTACK_ALLOC
381    /* Pacify GCC's `empty if-body' warning.  */
382 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
383 #  ifndef YYSTACK_ALLOC_MAXIMUM
384     /* The OS might guarantee only one guard page at the bottom of the stack,
385        and a page size can be as small as 4096 bytes.  So we cannot safely
386        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
387        to allow for a few compiler-allocated temporary stack slots.  */
388 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
389 #  endif
390 # else
391 #  define YYSTACK_ALLOC YYMALLOC
392 #  define YYSTACK_FREE YYFREE
393 #  ifndef YYSTACK_ALLOC_MAXIMUM
394 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
395 #  endif
396 #  if (defined __cplusplus && ! defined _STDLIB_H \
397        && ! ((defined YYMALLOC || defined malloc) \
398              && (defined YYFREE || defined free)))
399 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
400 #   ifndef _STDLIB_H
401 #    define _STDLIB_H 1
402 #   endif
403 #  endif
404 #  ifndef YYMALLOC
405 #   define YYMALLOC malloc
406 #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
407      || defined __cplusplus || defined _MSC_VER)
408 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
409 #   endif
410 #  endif
411 #  ifndef YYFREE
412 #   define YYFREE free
413 #   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
414      || defined __cplusplus || defined _MSC_VER)
415 void free (void *); /* INFRINGES ON USER NAME SPACE */
416 #   endif
417 #  endif
418 # endif
419 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
420
421
422 #if (! defined yyoverflow \
423      && (! defined __cplusplus \
424          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
425
426 /* A type that is properly aligned for any stack member.  */
427 union yyalloc
428 {
429   yytype_int16 yyss_alloc;
430   YYSTYPE yyvs_alloc;
431 };
432
433 /* The size of the maximum gap between one aligned stack and the next.  */
434 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
435
436 /* The size of an array large to enough to hold all stacks, each with
437    N elements.  */
438 # define YYSTACK_BYTES(N) \
439      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
440       + YYSTACK_GAP_MAXIMUM)
441
442 /* Copy COUNT objects from FROM to TO.  The source and destination do
443    not overlap.  */
444 # ifndef YYCOPY
445 #  if defined __GNUC__ && 1 < __GNUC__
446 #   define YYCOPY(To, From, Count) \
447       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
448 #  else
449 #   define YYCOPY(To, From, Count)              \
450       do                                        \
451         {                                       \
452           YYSIZE_T yyi;                         \
453           for (yyi = 0; yyi < (Count); yyi++)   \
454             (To)[yyi] = (From)[yyi];            \
455         }                                       \
456       while (YYID (0))
457 #  endif
458 # endif
459
460 /* Relocate STACK from its old location to the new one.  The
461    local variables YYSIZE and YYSTACKSIZE give the old and new number of
462    elements in the stack, and YYPTR gives the new location of the
463    stack.  Advance YYPTR to a properly aligned location for the next
464    stack.  */
465 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
466     do                                                                  \
467       {                                                                 \
468         YYSIZE_T yynewbytes;                                            \
469         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
470         Stack = &yyptr->Stack_alloc;                                    \
471         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
472         yyptr += yynewbytes / sizeof (*yyptr);                          \
473       }                                                                 \
474     while (YYID (0))
475
476 #endif
477
478 /* YYFINAL -- State number of the termination state.  */
479 #define YYFINAL  9
480 /* YYLAST -- Last index in YYTABLE.  */
481 #define YYLAST   23
482
483 /* YYNTOKENS -- Number of terminals.  */
484 #define YYNTOKENS  23
485 /* YYNNTS -- Number of nonterminals.  */
486 #define YYNNTS  11
487 /* YYNRULES -- Number of rules.  */
488 #define YYNRULES  16
489 /* YYNRULES -- Number of states.  */
490 #define YYNSTATES  30
491
492 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
493 #define YYUNDEFTOK  2
494 #define YYMAXUTOK   277
495
496 #define YYTRANSLATE(YYX)                                                \
497   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
498
499 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
500 static const yytype_uint8 yytranslate[] =
501 {
502        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
503        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
504        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
505        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
506        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
507        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
508        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
509        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
510        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
511        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
512        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
513        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
514        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
515        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
516        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
517        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
518        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
519        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
520        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
521        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
522        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
523        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
524        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
525        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
526        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
527        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
528        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
529       15,    16,    17,    18,    19,    20,    21,    22
530 };
531
532 #if YYDEBUG
533 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
534    YYRHS.  */
535 static const yytype_uint8 yyprhs[] =
536 {
537        0,     0,     3,     5,     7,     9,    12,    15,    16,    19,
538       22,    23,    24,    30,    31,    39,    44
539 };
540
541 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
542 static const yytype_int8 yyrhs[] =
543 {
544       24,     0,    -1,    25,    -1,    28,    -1,    30,    -1,    26,
545       25,    -1,    26,    33,    -1,    -1,    27,    25,    -1,    27,
546       32,    -1,    -1,    -1,     3,    12,    29,    26,     9,    -1,
547       -1,     4,     7,    22,     6,    31,    27,     9,    -1,     8,
548       22,    10,    22,    -1,     5,    12,    10,    12,    -1
549 };
550
551 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
552 static const yytype_uint16 yyrline[] =
553 {
554        0,   132,   132,   152,   152,   154,   154,   154,   156,   156,
555      156,   158,   158,   215,   215,   294,   312
556 };
557 #endif
558
559 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
560 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
561    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
562 static const char *const yytname[] =
563 {
564   "$end", "error", "$undefined", "CHIP", "DEVICE", "REGISTER", "BOOL",
565   "BUS", "RESOURCE", "END", "EQUALS", "HEX", "STRING", "PCI", "PNP", "I2C",
566   "APIC", "APIC_CLUSTER", "PCI_DOMAIN", "IRQ", "DRQ", "IO", "NUMBER",
567   "$accept", "devtree", "devchip", "devices", "devicesorresources", "chip",
568   "@1", "device", "@2", "resource", "registers", 0
569 };
570 #endif
571
572 # ifdef YYPRINT
573 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
574    token YYLEX-NUM.  */
575 static const yytype_uint16 yytoknum[] =
576 {
577        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
578      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
579      275,   276,   277
580 };
581 # endif
582
583 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
584 static const yytype_uint8 yyr1[] =
585 {
586        0,    23,    24,    25,    25,    26,    26,    26,    27,    27,
587       27,    29,    28,    31,    30,    32,    33
588 };
589
590 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
591 static const yytype_uint8 yyr2[] =
592 {
593        0,     2,     1,     1,     1,     2,     2,     0,     2,     2,
594        0,     0,     5,     0,     7,     4,     4
595 };
596
597 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
598    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
599    means the default is an error.  */
600 static const yytype_uint8 yydefact[] =
601 {
602        0,     0,     0,     0,     2,     3,     4,    11,     0,     1,
603        7,     0,     0,    13,     0,    12,     5,     6,    10,     0,
604        0,     0,     0,    14,     8,     9,    16,     0,     0,    15
605 };
606
607 /* YYDEFGOTO[NTERM-NUM].  */
608 static const yytype_int8 yydefgoto[] =
609 {
610       -1,     3,     4,    12,    20,     5,    10,     6,    18,    25,
611       17
612 };
613
614 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
615    STATE-NUM.  */
616 #define YYPACT_NINF -13
617 static const yytype_int8 yypact[] =
618 {
619        8,    -6,     6,    14,   -13,   -13,   -13,   -13,    -7,   -13,
620      -13,    10,    -2,   -13,     5,   -13,   -13,   -13,   -13,     9,
621        1,    11,    -4,   -13,   -13,   -13,   -13,    12,    -1,   -13
622 };
623
624 /* YYPGOTO[NTERM-NUM].  */
625 static const yytype_int8 yypgoto[] =
626 {
627      -13,   -13,   -12,   -13,   -13,   -13,   -13,   -13,   -13,   -13,
628      -13
629 };
630
631 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
632    positive, shift that token.  If negative, reduce the rule which
633    number is the opposite.  If zero, do what YYDEFACT says.
634    If YYTABLE_NINF, syntax error.  */
635 #define YYTABLE_NINF -1
636 static const yytype_uint8 yytable[] =
637 {
638       16,     1,     2,    14,     1,     2,     7,    15,    24,    22,
639       23,     1,     2,     8,     9,    11,    13,    19,    27,    21,
640        0,    29,    28,    26
641 };
642
643 static const yytype_int8 yycheck[] =
644 {
645       12,     3,     4,     5,     3,     4,    12,     9,    20,     8,
646        9,     3,     4,     7,     0,    22,     6,    12,    22,    10,
647       -1,    22,    10,    12
648 };
649
650 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
651    symbol of state STATE-NUM.  */
652 static const yytype_uint8 yystos[] =
653 {
654        0,     3,     4,    24,    25,    28,    30,    12,     7,     0,
655       29,    22,    26,     6,     5,     9,    25,    33,    31,    12,
656       27,    10,     8,     9,    25,    32,    12,    22,    10,    22
657 };
658
659 #define yyerrok         (yyerrstatus = 0)
660 #define yyclearin       (yychar = YYEMPTY)
661 #define YYEMPTY         (-2)
662 #define YYEOF           0
663
664 #define YYACCEPT        goto yyacceptlab
665 #define YYABORT         goto yyabortlab
666 #define YYERROR         goto yyerrorlab
667
668
669 /* Like YYERROR except do call yyerror.  This remains here temporarily
670    to ease the transition to the new meaning of YYERROR, for GCC.
671    Once GCC version 2 has supplanted version 1, this can go.  */
672
673 #define YYFAIL          goto yyerrlab
674
675 #define YYRECOVERING()  (!!yyerrstatus)
676
677 #define YYBACKUP(Token, Value)                                  \
678 do                                                              \
679   if (yychar == YYEMPTY && yylen == 1)                          \
680     {                                                           \
681       yychar = (Token);                                         \
682       yylval = (Value);                                         \
683       yytoken = YYTRANSLATE (yychar);                           \
684       YYPOPSTACK (1);                                           \
685       goto yybackup;                                            \
686     }                                                           \
687   else                                                          \
688     {                                                           \
689       yyerror (YY_("syntax error: cannot back up")); \
690       YYERROR;                                                  \
691     }                                                           \
692 while (YYID (0))
693
694
695 #define YYTERROR        1
696 #define YYERRCODE       256
697
698
699 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
700    If N is 0, then set CURRENT to the empty location which ends
701    the previous symbol: RHS[0] (always defined).  */
702
703 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
704 #ifndef YYLLOC_DEFAULT
705 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
706     do                                                                  \
707       if (YYID (N))                                                    \
708         {                                                               \
709           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
710           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
711           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
712           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
713         }                                                               \
714       else                                                              \
715         {                                                               \
716           (Current).first_line   = (Current).last_line   =              \
717             YYRHSLOC (Rhs, 0).last_line;                                \
718           (Current).first_column = (Current).last_column =              \
719             YYRHSLOC (Rhs, 0).last_column;                              \
720         }                                                               \
721     while (YYID (0))
722 #endif
723
724
725 /* YY_LOCATION_PRINT -- Print the location on the stream.
726    This macro was not mandated originally: define only if we know
727    we won't break user code: when these are the locations we know.  */
728
729 #ifndef YY_LOCATION_PRINT
730 # if YYLTYPE_IS_TRIVIAL
731 #  define YY_LOCATION_PRINT(File, Loc)                  \
732      fprintf (File, "%d.%d-%d.%d",                      \
733               (Loc).first_line, (Loc).first_column,     \
734               (Loc).last_line,  (Loc).last_column)
735 # else
736 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
737 # endif
738 #endif
739
740
741 /* YYLEX -- calling `yylex' with the right arguments.  */
742
743 #ifdef YYLEX_PARAM
744 # define YYLEX yylex (YYLEX_PARAM)
745 #else
746 # define YYLEX yylex ()
747 #endif
748
749 /* Enable debugging if requested.  */
750 #if YYDEBUG
751
752 # ifndef YYFPRINTF
753 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
754 #  define YYFPRINTF fprintf
755 # endif
756
757 # define YYDPRINTF(Args)                        \
758 do {                                            \
759   if (yydebug)                                  \
760     YYFPRINTF Args;                             \
761 } while (YYID (0))
762
763 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
764 do {                                                                      \
765   if (yydebug)                                                            \
766     {                                                                     \
767       YYFPRINTF (stderr, "%s ", Title);                                   \
768       yy_symbol_print (stderr,                                            \
769                   Type, Value); \
770       YYFPRINTF (stderr, "\n");                                           \
771     }                                                                     \
772 } while (YYID (0))
773
774
775 /*--------------------------------.
776 | Print this symbol on YYOUTPUT.  |
777 `--------------------------------*/
778
779 /*ARGSUSED*/
780 #if (defined __STDC__ || defined __C99__FUNC__ \
781      || defined __cplusplus || defined _MSC_VER)
782 static void
783 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
784 #else
785 static void
786 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
787     FILE *yyoutput;
788     int yytype;
789     YYSTYPE const * const yyvaluep;
790 #endif
791 {
792   if (!yyvaluep)
793     return;
794 # ifdef YYPRINT
795   if (yytype < YYNTOKENS)
796     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
797 # else
798   YYUSE (yyoutput);
799 # endif
800   switch (yytype)
801     {
802       default:
803         break;
804     }
805 }
806
807
808 /*--------------------------------.
809 | Print this symbol on YYOUTPUT.  |
810 `--------------------------------*/
811
812 #if (defined __STDC__ || defined __C99__FUNC__ \
813      || defined __cplusplus || defined _MSC_VER)
814 static void
815 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
816 #else
817 static void
818 yy_symbol_print (yyoutput, yytype, yyvaluep)
819     FILE *yyoutput;
820     int yytype;
821     YYSTYPE const * const yyvaluep;
822 #endif
823 {
824   if (yytype < YYNTOKENS)
825     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
826   else
827     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
828
829   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
830   YYFPRINTF (yyoutput, ")");
831 }
832
833 /*------------------------------------------------------------------.
834 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
835 | TOP (included).                                                   |
836 `------------------------------------------------------------------*/
837
838 #if (defined __STDC__ || defined __C99__FUNC__ \
839      || defined __cplusplus || defined _MSC_VER)
840 static void
841 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
842 #else
843 static void
844 yy_stack_print (yybottom, yytop)
845     yytype_int16 *yybottom;
846     yytype_int16 *yytop;
847 #endif
848 {
849   YYFPRINTF (stderr, "Stack now");
850   for (; yybottom <= yytop; yybottom++)
851     {
852       int yybot = *yybottom;
853       YYFPRINTF (stderr, " %d", yybot);
854     }
855   YYFPRINTF (stderr, "\n");
856 }
857
858 # define YY_STACK_PRINT(Bottom, Top)                            \
859 do {                                                            \
860   if (yydebug)                                                  \
861     yy_stack_print ((Bottom), (Top));                           \
862 } while (YYID (0))
863
864
865 /*------------------------------------------------.
866 | Report that the YYRULE is going to be reduced.  |
867 `------------------------------------------------*/
868
869 #if (defined __STDC__ || defined __C99__FUNC__ \
870      || defined __cplusplus || defined _MSC_VER)
871 static void
872 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
873 #else
874 static void
875 yy_reduce_print (yyvsp, yyrule)
876     YYSTYPE *yyvsp;
877     int yyrule;
878 #endif
879 {
880   int yynrhs = yyr2[yyrule];
881   int yyi;
882   unsigned long int yylno = yyrline[yyrule];
883   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
884              yyrule - 1, yylno);
885   /* The symbols being reduced.  */
886   for (yyi = 0; yyi < yynrhs; yyi++)
887     {
888       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
889       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
890                        &(yyvsp[(yyi + 1) - (yynrhs)])
891                                        );
892       YYFPRINTF (stderr, "\n");
893     }
894 }
895
896 # define YY_REDUCE_PRINT(Rule)          \
897 do {                                    \
898   if (yydebug)                          \
899     yy_reduce_print (yyvsp, Rule); \
900 } while (YYID (0))
901
902 /* Nonzero means print parse trace.  It is left uninitialized so that
903    multiple parsers can coexist.  */
904 int yydebug;
905 #else /* !YYDEBUG */
906 # define YYDPRINTF(Args)
907 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
908 # define YY_STACK_PRINT(Bottom, Top)
909 # define YY_REDUCE_PRINT(Rule)
910 #endif /* !YYDEBUG */
911
912
913 /* YYINITDEPTH -- initial size of the parser's stacks.  */
914 #ifndef YYINITDEPTH
915 # define YYINITDEPTH 200
916 #endif
917
918 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
919    if the built-in stack extension method is used).
920
921    Do not make this value too large; the results are undefined if
922    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
923    evaluated with infinite-precision integer arithmetic.  */
924
925 #ifndef YYMAXDEPTH
926 # define YYMAXDEPTH 10000
927 #endif
928
929 \f
930
931 #if YYERROR_VERBOSE
932
933 # ifndef yystrlen
934 #  if defined __GLIBC__ && defined _STRING_H
935 #   define yystrlen strlen
936 #  else
937 /* Return the length of YYSTR.  */
938 #if (defined __STDC__ || defined __C99__FUNC__ \
939      || defined __cplusplus || defined _MSC_VER)
940 static YYSIZE_T
941 yystrlen (const char *yystr)
942 #else
943 static YYSIZE_T
944 yystrlen (yystr)
945     const char *yystr;
946 #endif
947 {
948   YYSIZE_T yylen;
949   for (yylen = 0; yystr[yylen]; yylen++)
950     continue;
951   return yylen;
952 }
953 #  endif
954 # endif
955
956 # ifndef yystpcpy
957 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
958 #   define yystpcpy stpcpy
959 #  else
960 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
961    YYDEST.  */
962 #if (defined __STDC__ || defined __C99__FUNC__ \
963      || defined __cplusplus || defined _MSC_VER)
964 static char *
965 yystpcpy (char *yydest, const char *yysrc)
966 #else
967 static char *
968 yystpcpy (yydest, yysrc)
969     char *yydest;
970     const char *yysrc;
971 #endif
972 {
973   char *yyd = yydest;
974   const char *yys = yysrc;
975
976   while ((*yyd++ = *yys++) != '\0')
977     continue;
978
979   return yyd - 1;
980 }
981 #  endif
982 # endif
983
984 # ifndef yytnamerr
985 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
986    quotes and backslashes, so that it's suitable for yyerror.  The
987    heuristic is that double-quoting is unnecessary unless the string
988    contains an apostrophe, a comma, or backslash (other than
989    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
990    null, do not copy; instead, return the length of what the result
991    would have been.  */
992 static YYSIZE_T
993 yytnamerr (char *yyres, const char *yystr)
994 {
995   if (*yystr == '"')
996     {
997       YYSIZE_T yyn = 0;
998       char const *yyp = yystr;
999
1000       for (;;)
1001         switch (*++yyp)
1002           {
1003           case '\'':
1004           case ',':
1005             goto do_not_strip_quotes;
1006
1007           case '\\':
1008             if (*++yyp != '\\')
1009               goto do_not_strip_quotes;
1010             /* Fall through.  */
1011           default:
1012             if (yyres)
1013               yyres[yyn] = *yyp;
1014             yyn++;
1015             break;
1016
1017           case '"':
1018             if (yyres)
1019               yyres[yyn] = '\0';
1020             return yyn;
1021           }
1022     do_not_strip_quotes: ;
1023     }
1024
1025   if (! yyres)
1026     return yystrlen (yystr);
1027
1028   return yystpcpy (yyres, yystr) - yyres;
1029 }
1030 # endif
1031
1032 /* Copy into YYRESULT an error message about the unexpected token
1033    YYCHAR while in state YYSTATE.  Return the number of bytes copied,
1034    including the terminating null byte.  If YYRESULT is null, do not
1035    copy anything; just return the number of bytes that would be
1036    copied.  As a special case, return 0 if an ordinary "syntax error"
1037    message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
1038    size calculation.  */
1039 static YYSIZE_T
1040 yysyntax_error (char *yyresult, int yystate, int yychar)
1041 {
1042   int yyn = yypact[yystate];
1043
1044   if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1045     return 0;
1046   else
1047     {
1048       int yytype = YYTRANSLATE (yychar);
1049       YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1050       YYSIZE_T yysize = yysize0;
1051       YYSIZE_T yysize1;
1052       int yysize_overflow = 0;
1053       enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1054       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1055       int yyx;
1056
1057 # if 0
1058       /* This is so xgettext sees the translatable formats that are
1059          constructed on the fly.  */
1060       YY_("syntax error, unexpected %s");
1061       YY_("syntax error, unexpected %s, expecting %s");
1062       YY_("syntax error, unexpected %s, expecting %s or %s");
1063       YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1064       YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1065 # endif
1066       char *yyfmt;
1067       char const *yyf;
1068       static char const yyunexpected[] = "syntax error, unexpected %s";
1069       static char const yyexpecting[] = ", expecting %s";
1070       static char const yyor[] = " or %s";
1071       char yyformat[sizeof yyunexpected
1072                     + sizeof yyexpecting - 1
1073                     + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1074                        * (sizeof yyor - 1))];
1075       char const *yyprefix = yyexpecting;
1076
1077       /* Start YYX at -YYN if negative to avoid negative indexes in
1078          YYCHECK.  */
1079       int yyxbegin = yyn < 0 ? -yyn : 0;
1080
1081       /* Stay within bounds of both yycheck and yytname.  */
1082       int yychecklim = YYLAST - yyn + 1;
1083       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1084       int yycount = 1;
1085
1086       yyarg[0] = yytname[yytype];
1087       yyfmt = yystpcpy (yyformat, yyunexpected);
1088
1089       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1090         if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1091           {
1092             if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1093               {
1094                 yycount = 1;
1095                 yysize = yysize0;
1096                 yyformat[sizeof yyunexpected - 1] = '\0';
1097                 break;
1098               }
1099             yyarg[yycount++] = yytname[yyx];
1100             yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1101             yysize_overflow |= (yysize1 < yysize);
1102             yysize = yysize1;
1103             yyfmt = yystpcpy (yyfmt, yyprefix);
1104             yyprefix = yyor;
1105           }
1106
1107       yyf = YY_(yyformat);
1108       yysize1 = yysize + yystrlen (yyf);
1109       yysize_overflow |= (yysize1 < yysize);
1110       yysize = yysize1;
1111
1112       if (yysize_overflow)
1113         return YYSIZE_MAXIMUM;
1114
1115       if (yyresult)
1116         {
1117           /* Avoid sprintf, as that infringes on the user's name space.
1118              Don't have undefined behavior even if the translation
1119              produced a string with the wrong number of "%s"s.  */
1120           char *yyp = yyresult;
1121           int yyi = 0;
1122           while ((*yyp = *yyf) != '\0')
1123             {
1124               if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1125                 {
1126                   yyp += yytnamerr (yyp, yyarg[yyi++]);
1127                   yyf += 2;
1128                 }
1129               else
1130                 {
1131                   yyp++;
1132                   yyf++;
1133                 }
1134             }
1135         }
1136       return yysize;
1137     }
1138 }
1139 #endif /* YYERROR_VERBOSE */
1140 \f
1141
1142 /*-----------------------------------------------.
1143 | Release the memory associated to this symbol.  |
1144 `-----------------------------------------------*/
1145
1146 /*ARGSUSED*/
1147 #if (defined __STDC__ || defined __C99__FUNC__ \
1148      || defined __cplusplus || defined _MSC_VER)
1149 static void
1150 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1151 #else
1152 static void
1153 yydestruct (yymsg, yytype, yyvaluep)
1154     const char *yymsg;
1155     int yytype;
1156     YYSTYPE *yyvaluep;
1157 #endif
1158 {
1159   YYUSE (yyvaluep);
1160
1161   if (!yymsg)
1162     yymsg = "Deleting";
1163   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1164
1165   switch (yytype)
1166     {
1167
1168       default:
1169         break;
1170     }
1171 }
1172
1173 /* Prevent warnings from -Wmissing-prototypes.  */
1174 #ifdef YYPARSE_PARAM
1175 #if defined __STDC__ || defined __cplusplus
1176 int yyparse (void *YYPARSE_PARAM);
1177 #else
1178 int yyparse ();
1179 #endif
1180 #else /* ! YYPARSE_PARAM */
1181 #if defined __STDC__ || defined __cplusplus
1182 int yyparse (void);
1183 #else
1184 int yyparse ();
1185 #endif
1186 #endif /* ! YYPARSE_PARAM */
1187
1188
1189 /* The lookahead symbol.  */
1190 int yychar;
1191
1192 /* The semantic value of the lookahead symbol.  */
1193 YYSTYPE yylval;
1194
1195 /* Number of syntax errors so far.  */
1196 int yynerrs;
1197
1198
1199
1200 /*-------------------------.
1201 | yyparse or yypush_parse.  |
1202 `-------------------------*/
1203
1204 #ifdef YYPARSE_PARAM
1205 #if (defined __STDC__ || defined __C99__FUNC__ \
1206      || defined __cplusplus || defined _MSC_VER)
1207 int
1208 yyparse (void *YYPARSE_PARAM)
1209 #else
1210 int
1211 yyparse (YYPARSE_PARAM)
1212     void *YYPARSE_PARAM;
1213 #endif
1214 #else /* ! YYPARSE_PARAM */
1215 #if (defined __STDC__ || defined __C99__FUNC__ \
1216      || defined __cplusplus || defined _MSC_VER)
1217 int
1218 yyparse (void)
1219 #else
1220 int
1221 yyparse ()
1222
1223 #endif
1224 #endif
1225 {
1226
1227
1228     int yystate;
1229     /* Number of tokens to shift before error messages enabled.  */
1230     int yyerrstatus;
1231
1232     /* The stacks and their tools:
1233        `yyss': related to states.
1234        `yyvs': related to semantic values.
1235
1236        Refer to the stacks thru separate pointers, to allow yyoverflow
1237        to reallocate them elsewhere.  */
1238
1239     /* The state stack.  */
1240     yytype_int16 yyssa[YYINITDEPTH];
1241     yytype_int16 *yyss;
1242     yytype_int16 *yyssp;
1243
1244     /* The semantic value stack.  */
1245     YYSTYPE yyvsa[YYINITDEPTH];
1246     YYSTYPE *yyvs;
1247     YYSTYPE *yyvsp;
1248
1249     YYSIZE_T yystacksize;
1250
1251   int yyn;
1252   int yyresult;
1253   /* Lookahead token as an internal (translated) token number.  */
1254   int yytoken;
1255   /* The variables used to return semantic value and location from the
1256      action routines.  */
1257   YYSTYPE yyval;
1258
1259 #if YYERROR_VERBOSE
1260   /* Buffer for error messages, and its allocated size.  */
1261   char yymsgbuf[128];
1262   char *yymsg = yymsgbuf;
1263   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1264 #endif
1265
1266 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1267
1268   /* The number of symbols on the RHS of the reduced rule.
1269      Keep to zero when no symbol should be popped.  */
1270   int yylen = 0;
1271
1272   yytoken = 0;
1273   yyss = yyssa;
1274   yyvs = yyvsa;
1275   yystacksize = YYINITDEPTH;
1276
1277   YYDPRINTF ((stderr, "Starting parse\n"));
1278
1279   yystate = 0;
1280   yyerrstatus = 0;
1281   yynerrs = 0;
1282   yychar = YYEMPTY; /* Cause a token to be read.  */
1283
1284   /* Initialize stack pointers.
1285      Waste one element of value and location stack
1286      so that they stay on the same level as the state stack.
1287      The wasted elements are never initialized.  */
1288   yyssp = yyss;
1289   yyvsp = yyvs;
1290
1291   goto yysetstate;
1292
1293 /*------------------------------------------------------------.
1294 | yynewstate -- Push a new state, which is found in yystate.  |
1295 `------------------------------------------------------------*/
1296  yynewstate:
1297   /* In all cases, when you get here, the value and location stacks
1298      have just been pushed.  So pushing a state here evens the stacks.  */
1299   yyssp++;
1300
1301  yysetstate:
1302   *yyssp = yystate;
1303
1304   if (yyss + yystacksize - 1 <= yyssp)
1305     {
1306       /* Get the current used size of the three stacks, in elements.  */
1307       YYSIZE_T yysize = yyssp - yyss + 1;
1308
1309 #ifdef yyoverflow
1310       {
1311         /* Give user a chance to reallocate the stack.  Use copies of
1312            these so that the &'s don't force the real ones into
1313            memory.  */
1314         YYSTYPE *yyvs1 = yyvs;
1315         yytype_int16 *yyss1 = yyss;
1316
1317         /* Each stack pointer address is followed by the size of the
1318            data in use in that stack, in bytes.  This used to be a
1319            conditional around just the two extra args, but that might
1320            be undefined if yyoverflow is a macro.  */
1321         yyoverflow (YY_("memory exhausted"),
1322                     &yyss1, yysize * sizeof (*yyssp),
1323                     &yyvs1, yysize * sizeof (*yyvsp),
1324                     &yystacksize);
1325
1326         yyss = yyss1;
1327         yyvs = yyvs1;
1328       }
1329 #else /* no yyoverflow */
1330 # ifndef YYSTACK_RELOCATE
1331       goto yyexhaustedlab;
1332 # else
1333       /* Extend the stack our own way.  */
1334       if (YYMAXDEPTH <= yystacksize)
1335         goto yyexhaustedlab;
1336       yystacksize *= 2;
1337       if (YYMAXDEPTH < yystacksize)
1338         yystacksize = YYMAXDEPTH;
1339
1340       {
1341         yytype_int16 *yyss1 = yyss;
1342         union yyalloc *yyptr =
1343           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1344         if (! yyptr)
1345           goto yyexhaustedlab;
1346         YYSTACK_RELOCATE (yyss_alloc, yyss);
1347         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1348 #  undef YYSTACK_RELOCATE
1349         if (yyss1 != yyssa)
1350           YYSTACK_FREE (yyss1);
1351       }
1352 # endif
1353 #endif /* no yyoverflow */
1354
1355       yyssp = yyss + yysize - 1;
1356       yyvsp = yyvs + yysize - 1;
1357
1358       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1359                   (unsigned long int) yystacksize));
1360
1361       if (yyss + yystacksize - 1 <= yyssp)
1362         YYABORT;
1363     }
1364
1365   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1366
1367   if (yystate == YYFINAL)
1368     YYACCEPT;
1369
1370   goto yybackup;
1371
1372 /*-----------.
1373 | yybackup.  |
1374 `-----------*/
1375 yybackup:
1376
1377   /* Do appropriate processing given the current state.  Read a
1378      lookahead token if we need one and don't already have one.  */
1379
1380   /* First try to decide what to do without reference to lookahead token.  */
1381   yyn = yypact[yystate];
1382   if (yyn == YYPACT_NINF)
1383     goto yydefault;
1384
1385   /* Not known => get a lookahead token if don't already have one.  */
1386
1387   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1388   if (yychar == YYEMPTY)
1389     {
1390       YYDPRINTF ((stderr, "Reading a token: "));
1391       yychar = YYLEX;
1392     }
1393
1394   if (yychar <= YYEOF)
1395     {
1396       yychar = yytoken = YYEOF;
1397       YYDPRINTF ((stderr, "Now at end of input.\n"));
1398     }
1399   else
1400     {
1401       yytoken = YYTRANSLATE (yychar);
1402       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1403     }
1404
1405   /* If the proper action on seeing token YYTOKEN is to reduce or to
1406      detect an error, take that action.  */
1407   yyn += yytoken;
1408   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1409     goto yydefault;
1410   yyn = yytable[yyn];
1411   if (yyn <= 0)
1412     {
1413       if (yyn == 0 || yyn == YYTABLE_NINF)
1414         goto yyerrlab;
1415       yyn = -yyn;
1416       goto yyreduce;
1417     }
1418
1419   /* Count tokens shifted since error; after three, turn off error
1420      status.  */
1421   if (yyerrstatus)
1422     yyerrstatus--;
1423
1424   /* Shift the lookahead token.  */
1425   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1426
1427   /* Discard the shifted token.  */
1428   yychar = YYEMPTY;
1429
1430   yystate = yyn;
1431   *++yyvsp = yylval;
1432
1433   goto yynewstate;
1434
1435
1436 /*-----------------------------------------------------------.
1437 | yydefault -- do the default action for the current state.  |
1438 `-----------------------------------------------------------*/
1439 yydefault:
1440   yyn = yydefact[yystate];
1441   if (yyn == 0)
1442     goto yyerrlab;
1443   goto yyreduce;
1444
1445
1446 /*-----------------------------.
1447 | yyreduce -- Do a reduction.  |
1448 `-----------------------------*/
1449 yyreduce:
1450   /* yyn is the number of a rule to reduce with.  */
1451   yylen = yyr2[yyn];
1452
1453   /* If YYLEN is nonzero, implement the default value of the action:
1454      `$$ = $1'.
1455
1456      Otherwise, the following line sets YYVAL to garbage.
1457      This behavior is undocumented and Bison
1458      users should not rely upon it.  Assigning to YYVAL
1459      unconditionally makes the parser a bit smaller, and it avoids a
1460      GCC warning that YYVAL may be used uninitialized.  */
1461   yyval = yyvsp[1-yylen];
1462
1463
1464   YY_REDUCE_PRINT (yyn);
1465   switch (yyn)
1466     {
1467         case 2:
1468
1469     {
1470         root.next_sibling = root.children;
1471         root.next_sibling->next_sibling = root.next_sibling->children;
1472
1473         struct device *dev = &root;
1474         while (dev) {
1475                 /* skip "chip" elements in children chain */
1476                 while (dev->children && (dev->children->type == chip)) dev->children = dev->children->children;
1477                 /* skip "chip" elements and functions of the same device in sibling chain */
1478                 while (dev->sibling && dev->sibling->used) dev->sibling = dev->sibling->sibling;
1479                 /* If end of chain, and parent is a chip, move on */
1480                 if (!dev->sibling && (dev->parent->type == chip)) dev->sibling = dev->parent->sibling;
1481                 /* skip chips */
1482                 while (dev->sibling && dev->sibling->type == chip) dev->sibling = dev->sibling->children;
1483                 /* skip duplicate function elements in nextdev chain */
1484                 while (dev->nextdev && dev->nextdev->used) dev->nextdev = dev->nextdev->nextdev;
1485                 dev = dev->next_sibling;
1486         }
1487         ;}
1488     break;
1489
1490   case 11:
1491
1492     {
1493         (yyval.device) = new_dev();
1494         (yyval.device)->chiph_exists = 1;
1495         (yyval.device)->name = (yyvsp[(2) - (2)].string);
1496         (yyval.device)->name_underscore = strdup((yyval.device)->name);
1497         char *c;
1498         for (c = (yyval.device)->name_underscore; *c; c++) {
1499                 if (*c == '/') *c = '_';
1500                 if (*c == '-') *c = '_';
1501         }
1502         (yyval.device)->type = chip;
1503         (yyval.device)->chip = (yyval.device);
1504
1505         struct stat st;
1506         char *chip_h = malloc(strlen((yyvsp[(2) - (2)].string))+12);
1507         sprintf(chip_h, "src/%s/chip.h", (yyvsp[(2) - (2)].string));
1508         if ((stat(chip_h, &st) == -1) && (errno == ENOENT))
1509                 (yyval.device)->chiph_exists = 0;
1510
1511         if (cur_parent->latestchild) {
1512                 cur_parent->latestchild->next_sibling = (yyval.device);
1513                 cur_parent->latestchild->sibling = (yyval.device);
1514         }
1515         cur_parent->latestchild = (yyval.device);
1516         if (!cur_parent->children)
1517                 cur_parent->children = (yyval.device);
1518
1519         cur_parent = (yyval.device);
1520 ;}
1521     break;
1522
1523   case 12:
1524
1525     {
1526         cur_parent = (yyvsp[(3) - (5)].device)->parent;
1527
1528         fold_in((yyvsp[(3) - (5)].device));
1529
1530         if ((yyvsp[(3) - (5)].device)->chiph_exists) {
1531                 int include_exists = 0;
1532                 struct header *h = &headers;
1533                 while (h->next) {
1534                         int result = strcmp((yyvsp[(3) - (5)].device)->name, h->next->name);
1535                         if (result == 0) {
1536                                 include_exists = 1;
1537                                 break;
1538                         }
1539                         if (result < 0) break;
1540                         h = h->next;
1541                 }
1542                 if (!include_exists) {
1543                         struct header *tmp = h->next;
1544                         h->next = malloc(sizeof(struct header));
1545                         memset(h->next, 0, sizeof(struct header));
1546                         h->next->name = (yyvsp[(3) - (5)].device)->name;
1547                         h->next->next = tmp;
1548                         break;
1549                 }
1550         }
1551 ;}
1552     break;
1553
1554   case 13:
1555
1556     {
1557         (yyval.device) = new_dev();
1558         (yyval.device)->bustype = (yyvsp[(2) - (4)].number);
1559
1560         char *tmp;
1561         (yyval.device)->path_a = strtol(strdup((yyvsp[(3) - (4)].string)), &tmp, 16);
1562         if (*tmp == '.') {
1563                 tmp++;
1564                 (yyval.device)->path_b = strtol(tmp, NULL, 16);
1565         }
1566
1567         char *name = malloc(10);
1568         sprintf(name, "_dev%d", (yyval.device)->id);
1569         (yyval.device)->name = name;
1570         (yyval.device)->name_underscore = name; // shouldn't be necessary, but avoid 0-ptr
1571         (yyval.device)->type = device;
1572         (yyval.device)->enabled = (yyvsp[(4) - (4)].number);
1573         (yyval.device)->chip = (yyval.device)->parent->chip;
1574
1575         if (cur_parent->latestchild) {
1576                 cur_parent->latestchild->next_sibling = (yyval.device);
1577                 cur_parent->latestchild->sibling = (yyval.device);
1578         }
1579         cur_parent->latestchild = (yyval.device);
1580         if (!cur_parent->children)
1581                 cur_parent->children = (yyval.device);
1582
1583         lastdev->nextdev = (yyval.device);
1584         lastdev = (yyval.device);
1585         if ((yyvsp[(2) - (4)].number) == PCI) {
1586                 (yyval.device)->path = ".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}";
1587         }
1588         if ((yyvsp[(2) - (4)].number) == PNP) {
1589                 (yyval.device)->path = ".type=DEVICE_PATH_PNP,{.pnp={ .port = 0x%x, .device = 0x%x }}";
1590         }
1591         if ((yyvsp[(2) - (4)].number) == I2C) {
1592                 (yyval.device)->path = ".type=DEVICE_PATH_I2C,{.i2c={ .device = 0x%x }}";
1593         }
1594         if ((yyvsp[(2) - (4)].number) == APIC) {
1595                 (yyval.device)->path = ".type=DEVICE_PATH_APIC,{.apic={ .apic_id = 0x%x }}";
1596         }
1597         if ((yyvsp[(2) - (4)].number) == APIC_CLUSTER) {
1598                 (yyval.device)->path = ".type=DEVICE_PATH_APIC_CLUSTER,{.apic_cluster={ .cluster = 0x%x }}";
1599         }
1600         if ((yyvsp[(2) - (4)].number) == PCI_DOMAIN) {
1601                 (yyval.device)->path = ".type=DEVICE_PATH_PCI_DOMAIN,{.pci_domain={ .domain = 0x%x }}";
1602         }
1603         cur_parent = (yyval.device);
1604         cur_bus = (yyval.device);
1605 ;}
1606     break;
1607
1608   case 14:
1609
1610     {
1611         cur_parent = (yyvsp[(5) - (7)].device)->parent;
1612         cur_bus = (yyvsp[(5) - (7)].device)->bus;
1613
1614         fold_in((yyvsp[(5) - (7)].device));
1615
1616         struct device *d = (yyvsp[(5) - (7)].device)->children;
1617         while (d) {
1618                 int link = 0;
1619                 struct device *cmp = d->next_sibling;
1620                 while (cmp && (cmp->bus == d->bus) && (cmp->path_a == d->path_a) && (cmp->path_b == d->path_b)) {
1621                         if (cmp->type==device && !cmp->used) {
1622                                 if (device_match(d, cmp)) {
1623                                         d->multidev = 1;
1624
1625                                         cmp->aliased_name = malloc(12);
1626                                         sprintf(cmp->aliased_name, "_dev%d", cmp->id);
1627                                         cmp->id = d->id;
1628                                         cmp->name = d->name;
1629                                         cmp->used = 1;
1630                                         cmp->link = ++link;
1631                                 }
1632                         }
1633                         cmp = cmp->next_sibling;
1634                 }
1635                 d = d->next_sibling;
1636         }
1637 ;}
1638     break;
1639
1640   case 15:
1641
1642     {
1643                 struct resource *r = malloc(sizeof(struct resource));
1644                 memset (r, 0, sizeof(struct resource));
1645                 r->type = (yyvsp[(1) - (4)].number);
1646                 r->index = strtol((yyvsp[(2) - (4)].string), NULL, 0);
1647                 r->base = strtol((yyvsp[(4) - (4)].string), NULL, 0);
1648                 if (cur_parent->res) {
1649                         struct resource *head = cur_parent->res;
1650                         while (head->next) head = head->next;
1651                         head->next = r;
1652                 } else {
1653                         cur_parent->res = r;
1654                 }
1655                 cur_parent->rescnt++;
1656         ;}
1657     break;
1658
1659   case 16:
1660
1661     {
1662                 struct reg *r = malloc(sizeof(struct reg));
1663                 memset (r, 0, sizeof(struct reg));
1664                 r->key = (yyvsp[(2) - (4)].string);
1665                 r->value = (yyvsp[(4) - (4)].string);
1666                 if (cur_parent->reg) {
1667                         struct reg *head = cur_parent->reg;
1668                         // sorting to be equal to sconfig's behaviour
1669                         int sort = strcmp(r->key, head->key);
1670                         if (sort == 0) {
1671                                 printf("ERROR: duplicate 'register' key.\n");
1672                                 exit(1);
1673                         }
1674                         if (sort<0) {
1675                                 r->next = head;
1676                                 cur_parent->reg = r;
1677                         } else {
1678                                 while ((head->next) && (strcmp(head->next->key, r->key)<0)) head = head->next;
1679                                 r->next = head->next;
1680                                 head->next = r;
1681                         }
1682                 } else {
1683                         cur_parent->reg = r;
1684                 }
1685         ;}
1686     break;
1687
1688
1689
1690       default: break;
1691     }
1692   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1693
1694   YYPOPSTACK (yylen);
1695   yylen = 0;
1696   YY_STACK_PRINT (yyss, yyssp);
1697
1698   *++yyvsp = yyval;
1699
1700   /* Now `shift' the result of the reduction.  Determine what state
1701      that goes to, based on the state we popped back to and the rule
1702      number reduced by.  */
1703
1704   yyn = yyr1[yyn];
1705
1706   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1707   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1708     yystate = yytable[yystate];
1709   else
1710     yystate = yydefgoto[yyn - YYNTOKENS];
1711
1712   goto yynewstate;
1713
1714
1715 /*------------------------------------.
1716 | yyerrlab -- here on detecting error |
1717 `------------------------------------*/
1718 yyerrlab:
1719   /* If not already recovering from an error, report this error.  */
1720   if (!yyerrstatus)
1721     {
1722       ++yynerrs;
1723 #if ! YYERROR_VERBOSE
1724       yyerror (YY_("syntax error"));
1725 #else
1726       {
1727         YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1728         if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
1729           {
1730             YYSIZE_T yyalloc = 2 * yysize;
1731             if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
1732               yyalloc = YYSTACK_ALLOC_MAXIMUM;
1733             if (yymsg != yymsgbuf)
1734               YYSTACK_FREE (yymsg);
1735             yymsg = (char *) YYSTACK_ALLOC (yyalloc);
1736             if (yymsg)
1737               yymsg_alloc = yyalloc;
1738             else
1739               {
1740                 yymsg = yymsgbuf;
1741                 yymsg_alloc = sizeof yymsgbuf;
1742               }
1743           }
1744
1745         if (0 < yysize && yysize <= yymsg_alloc)
1746           {
1747             (void) yysyntax_error (yymsg, yystate, yychar);
1748             yyerror (yymsg);
1749           }
1750         else
1751           {
1752             yyerror (YY_("syntax error"));
1753             if (yysize != 0)
1754               goto yyexhaustedlab;
1755           }
1756       }
1757 #endif
1758     }
1759
1760
1761
1762   if (yyerrstatus == 3)
1763     {
1764       /* If just tried and failed to reuse lookahead token after an
1765          error, discard it.  */
1766
1767       if (yychar <= YYEOF)
1768         {
1769           /* Return failure if at end of input.  */
1770           if (yychar == YYEOF)
1771             YYABORT;
1772         }
1773       else
1774         {
1775           yydestruct ("Error: discarding",
1776                       yytoken, &yylval);
1777           yychar = YYEMPTY;
1778         }
1779     }
1780
1781   /* Else will try to reuse lookahead token after shifting the error
1782      token.  */
1783   goto yyerrlab1;
1784
1785
1786 /*---------------------------------------------------.
1787 | yyerrorlab -- error raised explicitly by YYERROR.  |
1788 `---------------------------------------------------*/
1789 yyerrorlab:
1790
1791   /* Pacify compilers like GCC when the user code never invokes
1792      YYERROR and the label yyerrorlab therefore never appears in user
1793      code.  */
1794   if (/*CONSTCOND*/ 0)
1795      goto yyerrorlab;
1796
1797   /* Do not reclaim the symbols of the rule which action triggered
1798      this YYERROR.  */
1799   YYPOPSTACK (yylen);
1800   yylen = 0;
1801   YY_STACK_PRINT (yyss, yyssp);
1802   yystate = *yyssp;
1803   goto yyerrlab1;
1804
1805
1806 /*-------------------------------------------------------------.
1807 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1808 `-------------------------------------------------------------*/
1809 yyerrlab1:
1810   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
1811
1812   for (;;)
1813     {
1814       yyn = yypact[yystate];
1815       if (yyn != YYPACT_NINF)
1816         {
1817           yyn += YYTERROR;
1818           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1819             {
1820               yyn = yytable[yyn];
1821               if (0 < yyn)
1822                 break;
1823             }
1824         }
1825
1826       /* Pop the current state because it cannot handle the error token.  */
1827       if (yyssp == yyss)
1828         YYABORT;
1829
1830
1831       yydestruct ("Error: popping",
1832                   yystos[yystate], yyvsp);
1833       YYPOPSTACK (1);
1834       yystate = *yyssp;
1835       YY_STACK_PRINT (yyss, yyssp);
1836     }
1837
1838   *++yyvsp = yylval;
1839
1840
1841   /* Shift the error token.  */
1842   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1843
1844   yystate = yyn;
1845   goto yynewstate;
1846
1847
1848 /*-------------------------------------.
1849 | yyacceptlab -- YYACCEPT comes here.  |
1850 `-------------------------------------*/
1851 yyacceptlab:
1852   yyresult = 0;
1853   goto yyreturn;
1854
1855 /*-----------------------------------.
1856 | yyabortlab -- YYABORT comes here.  |
1857 `-----------------------------------*/
1858 yyabortlab:
1859   yyresult = 1;
1860   goto yyreturn;
1861
1862 #if !defined(yyoverflow) || YYERROR_VERBOSE
1863 /*-------------------------------------------------.
1864 | yyexhaustedlab -- memory exhaustion comes here.  |
1865 `-------------------------------------------------*/
1866 yyexhaustedlab:
1867   yyerror (YY_("memory exhausted"));
1868   yyresult = 2;
1869   /* Fall through.  */
1870 #endif
1871
1872 yyreturn:
1873   if (yychar != YYEMPTY)
1874      yydestruct ("Cleanup: discarding lookahead",
1875                  yytoken, &yylval);
1876   /* Do not reclaim the symbols of the rule which action triggered
1877      this YYABORT or YYACCEPT.  */
1878   YYPOPSTACK (yylen);
1879   YY_STACK_PRINT (yyss, yyssp);
1880   while (yyssp != yyss)
1881     {
1882       yydestruct ("Cleanup: popping",
1883                   yystos[*yyssp], yyvsp);
1884       YYPOPSTACK (1);
1885     }
1886 #ifndef yyoverflow
1887   if (yyss != yyssa)
1888     YYSTACK_FREE (yyss);
1889 #endif
1890 #if YYERROR_VERBOSE
1891   if (yymsg != yymsgbuf)
1892     YYSTACK_FREE (yymsg);
1893 #endif
1894   /* Make sure YYID is used.  */
1895   return YYID (yyresult);
1896 }
1897
1898
1899
1900
1901 void pass0(FILE *fil, struct device *ptr) {
1902         if ((ptr->type == device) && (ptr->id != 0) && (!ptr->used))
1903                 fprintf(fil, "struct device %s;\n", ptr->name);
1904         if ((ptr->type == device) && (ptr->id != 0) && ptr->used)
1905                 fprintf(fil, "struct device %s;\n", ptr->aliased_name);
1906 }
1907
1908 void pass1(FILE *fil, struct device *ptr) {
1909         if (!ptr->used && (ptr->type == device)) {
1910                 fprintf(fil, "struct device %s = {\n", ptr->name);
1911                 fprintf(fil, "\t.ops = %s,\n", (ptr->ops)?(ptr->ops):"0");
1912                 fprintf(fil, "\t.bus = &%s.link[%d],\n", ptr->bus->name, ptr->bus->link);
1913                 fprintf(fil, "\t.path = {");
1914                 fprintf(fil, ptr->path, ptr->path_a, ptr->path_b);
1915                 fprintf(fil, "},\n");
1916                 fprintf(fil, "\t.enabled = %d,\n", ptr->enabled);
1917                 fprintf(fil, "\t.on_mainboard = 1,\n");
1918                 if (ptr->rescnt > 0) {
1919                         fprintf(fil, "\t.resources = %d,\n", ptr->rescnt);
1920                         fprintf(fil, "\t.resource = {\n");
1921                         struct resource *r = ptr->res;
1922                         while (r) {
1923                                 fprintf(fil, "\t\t{ .flags=IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_");
1924                                 if (r->type == IRQ) fprintf(fil, "IRQ");
1925                                 if (r->type == DRQ) fprintf(fil, "DRQ");
1926                                 if (r->type == IO) fprintf(fil, "IO");
1927                                 fprintf(fil, ", .index=0x%x, .base=0x%x},\n", r->index, r->base);
1928                                 r = r->next;
1929                         }
1930                         fprintf(fil, "\t },\n");
1931                 }
1932                 int link = 0;
1933                 fprintf(fil, "\t.link = {\n");
1934                 if (ptr->multidev) {
1935                         struct device *d = ptr;
1936                         while (d) {
1937                                 if (device_match(d, ptr)) {
1938                                         fprintf(fil, "\t\t[%d] = {\n", d->link);
1939                                         fprintf(fil, "\t\t\t.link = %d,\n", d->link);
1940                                         fprintf(fil, "\t\t\t.dev = &%s,\n", d->name);
1941                                         if (d->children)
1942                                                 fprintf(fil, "\t\t\t.children = &%s,\n", d->children->name);
1943                                         fprintf(fil, "\t\t},\n");
1944                                         link++;
1945                                 }
1946                                 d = d->next_sibling;
1947                         }
1948                 } else {
1949                         if (ptr->children) {
1950                                 fprintf(fil, "\t\t[0] = {\n");
1951                                 fprintf(fil, "\t\t\t.link = 0,\n");
1952                                 fprintf(fil, "\t\t\t.dev = &%s,\n", ptr->name);
1953                                 fprintf(fil, "\t\t\t.children = &%s,\n", ptr->children->name);
1954                                 fprintf(fil, "\t\t},\n");
1955                                 link++;
1956                         }
1957                 }
1958                 fprintf(fil, "\t},\n");
1959                 fprintf(fil, "\t.links = %d,\n", link);
1960                 if (ptr->sibling)
1961                         fprintf(fil, "\t.sibling = &%s,\n", ptr->sibling->name);
1962                 if (ptr->chip->chiph_exists) {
1963                         fprintf(fil, "\t.chip_ops = &%s_ops,\n", ptr->chip->name_underscore);
1964                         fprintf(fil, "\t.chip_info = &%s_info_%d,\n", ptr->chip->name_underscore, ptr->chip->id);
1965                 }
1966                 if (ptr->nextdev)
1967                         fprintf(fil, "\t.next=&%s\n", ptr->nextdev->name);
1968                 fprintf(fil, "};\n");
1969         }
1970         if ((ptr->type == chip) && (ptr->chiph_exists)) {
1971                 if (ptr->reg) {
1972                         fprintf(fil, "struct %s_config %s_info_%d\t= {\n", ptr->name_underscore, ptr->name_underscore, ptr->id);
1973                         struct reg *r = ptr->reg;
1974                         while (r) {
1975                                 fprintf(fil, "\t.%s = %s,\n", r->key, r->value);
1976                                 r = r->next;
1977                         }
1978                         fprintf(fil, "};\n\n");
1979                 } else {
1980                         fprintf(fil, "struct %s_config %s_info_%d;\n", ptr->name_underscore, ptr->name_underscore, ptr->id);
1981                 }
1982         }
1983 }
1984
1985 void walk_device_tree(FILE *fil, struct device *ptr, void (*func)(FILE *, struct device*), struct device *chips) {
1986         do {
1987                 func(fil, ptr);
1988                 ptr = ptr->next_sibling;
1989         } while (ptr);
1990 }
1991
1992 struct device mainboard = {
1993         .name = "mainboard",
1994         .name_underscore = "mainboard",
1995         .id = 0,
1996         .chip = &mainboard,
1997         .type = chip,
1998         .chiph_exists = 1,
1999         .children = &root
2000 };
2001
2002 struct device root = {
2003         .name = "dev_root",
2004         .name_underscore = "dev_root",
2005         .id = 0,
2006         .chip = &mainboard,
2007         .type = device,
2008         .path = " .type = DEVICE_PATH_ROOT ",
2009         .ops = "&default_dev_ops_root",
2010         .parent = &root,
2011         .bus = &root,
2012         .enabled = 1
2013 };
2014
2015 int main(int argc, char** argv) {
2016         if (argc != 3) {
2017                 printf("usage: sconfig vendor/mainboard outputdir\n");
2018                 return 1;
2019         }
2020         char *mainboard=argv[1];
2021         char *outputdir=argv[2];
2022         char *devtree=malloc(strlen(mainboard)+30);
2023         char *outputc=malloc(strlen(outputdir)+10);
2024         sprintf(devtree, "src/mainboard/%s/devicetree.cb", mainboard);
2025         sprintf(outputc, "%s/static.c", outputdir);
2026
2027         headers.next = malloc(sizeof(struct header));
2028         headers.next->name = malloc(strlen(mainboard)+12);
2029         headers.next->next = 0;
2030         sprintf(headers.next->name, "mainboard/%s", mainboard);
2031
2032         FILE *filec = fopen(devtree, "r");
2033         yyrestart(filec);
2034
2035         FILE *staticc = fopen(outputc, "w");
2036
2037         cur_bus = cur_parent = lastdev = head = &root;
2038         yyparse();
2039         fclose(filec);
2040
2041         if ((head->type == chip) && (!head->chiph_exists)) {
2042                 struct device *tmp = head;
2043                 head = &root;
2044                 while (head->next != tmp) head = head->next;
2045         }
2046
2047         fprintf(staticc, "#include <device/device.h>\n");
2048         fprintf(staticc, "#include <device/pci.h>\n");
2049         struct header *h = &headers;
2050         while (h->next) {
2051                 h = h->next;
2052                 fprintf(staticc, "#include \"%s/chip.h\"\n", h->name);
2053         }
2054         fprintf(staticc, "\n/* pass 0 */\n");
2055         walk_device_tree(staticc, &root, pass0, NULL);
2056         fprintf(staticc, "\n/* pass 1 */\nstruct mainboard_config mainboard_info_0;\nstruct device **last_dev_p = &%s.next;\n", lastdev->name);
2057         walk_device_tree(staticc, &root, pass1, NULL);
2058
2059         fclose(staticc);
2060         return 0;
2061 }
2062