2 /* A Bison parser, made by GNU Bison 2.4.1. */
4 /* Skeleton implementation for Bison's Yacc-like parsers in C
6 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
7 Free Software Foundation, Inc.
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.
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.
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/>. */
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.
32 This special exception was added by the Free Software Foundation in
33 version 2.2 of Bison. */
35 /* C LALR(1) parser skeleton written by Richard Stallman, by
36 simplifying the original so-called "semantic" parser. */
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. */
45 /* Identify Bison output. */
49 #define YYBISON_VERSION "2.4.1"
52 #define YYSKELETON_NAME "yacc.c"
63 /* Using locations. */
64 #define YYLSP_NEEDED 0
68 /* Copy the first part of user declarations. */
72 * sconfig, coreboot device tree compiler
74 * Copyright (C) 2010 coresystems GmbH
75 * written by Patrick Georgi <patrick.georgi@coresystems.de>
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.
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.
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
94 #include <sys/types.h>
99 enum devtype { chip, device };
106 struct resource *next;
128 char *name_underscore;
134 struct device *parent;
137 struct device *nextdev;
138 struct device *children;
139 struct device *latestchild;
140 struct device *next_sibling;
141 struct device *sibling;
143 struct resource *res;
145 } *head, *lastdev, *cur_parent, *cur_bus, root;
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;
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))
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;
181 child = child->next_sibling;
189 void yyerror (char const *str)
191 fprintf (stderr, "%s\n", str);
196 /* Enabling traces. */
201 /* Enabling verbose error messages. */
202 #ifdef YYERROR_VERBOSE
203 # undef YYERROR_VERBOSE
204 # define YYERROR_VERBOSE 1
206 # define YYERROR_VERBOSE 0
209 /* Enabling the token table. */
210 #ifndef YYTOKEN_TABLE
211 # define YYTOKEN_TABLE 0
218 /* Put the tokens into the symbol table, so that GDB and other debuggers
246 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
247 typedef union YYSTYPE
251 struct device *device;
258 # define YYSTYPE_IS_TRIVIAL 1
259 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
260 # define YYSTYPE_IS_DECLARED 1
264 /* Copy the second part of user declarations. */
273 typedef YYTYPE_UINT8 yytype_uint8;
275 typedef unsigned char yytype_uint8;
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;
284 typedef short int yytype_int8;
288 typedef YYTYPE_UINT16 yytype_uint16;
290 typedef unsigned short int yytype_uint16;
294 typedef YYTYPE_INT16 yytype_int16;
296 typedef short int yytype_int16;
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
309 # define YYSIZE_T unsigned int
313 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
318 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
319 # define YY_(msgid) dgettext ("bison-runtime", msgid)
323 # define YY_(msgid) msgid
327 /* Suppress unused-variable warnings by "using" E. */
328 #if ! defined lint || defined __GNUC__
329 # define YYUSE(e) ((void) (e))
331 # define YYUSE(e) /* empty */
334 /* Identity function, used to suppress warnings about constant conditions. */
338 #if (defined __STDC__ || defined __C99__FUNC__ \
339 || defined __cplusplus || defined _MSC_VER)
352 #if ! defined yyoverflow || YYERROR_VERBOSE
354 /* The parser invokes alloca or malloc; define the necessary symbols. */
356 # ifdef YYSTACK_USE_ALLOCA
357 # if YYSTACK_USE_ALLOCA
359 # define YYSTACK_ALLOC __builtin_alloca
360 # elif defined __BUILTIN_VA_ARG_INCR
361 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
363 # define YYSTACK_ALLOC __alloca
364 # elif defined _MSC_VER
365 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
366 # define alloca _alloca
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 */
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 */
391 # define YYSTACK_ALLOC YYMALLOC
392 # define YYSTACK_FREE YYFREE
393 # ifndef YYSTACK_ALLOC_MAXIMUM
394 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
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 */
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 */
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 */
419 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
422 #if (! defined yyoverflow \
423 && (! defined __cplusplus \
424 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
426 /* A type that is properly aligned for any stack member. */
429 yytype_int16 yyss_alloc;
433 /* The size of the maximum gap between one aligned stack and the next. */
434 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
436 /* The size of an array large to enough to hold all stacks, each with
438 # define YYSTACK_BYTES(N) \
439 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
440 + YYSTACK_GAP_MAXIMUM)
442 /* Copy COUNT objects from FROM to TO. The source and destination do
445 # if defined __GNUC__ && 1 < __GNUC__
446 # define YYCOPY(To, From, Count) \
447 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
449 # define YYCOPY(To, From, Count) \
453 for (yyi = 0; yyi < (Count); yyi++) \
454 (To)[yyi] = (From)[yyi]; \
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
465 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
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); \
478 /* YYFINAL -- State number of the termination state. */
480 /* YYLAST -- Last index in YYTABLE. */
483 /* YYNTOKENS -- Number of terminals. */
485 /* YYNNTS -- Number of nonterminals. */
487 /* YYNRULES -- Number of rules. */
489 /* YYNRULES -- Number of states. */
492 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
494 #define YYMAXUTOK 277
496 #define YYTRANSLATE(YYX) \
497 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
499 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
500 static const yytype_uint8 yytranslate[] =
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
533 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
535 static const yytype_uint8 yyprhs[] =
537 0, 0, 3, 5, 7, 9, 12, 15, 16, 19,
538 22, 23, 24, 30, 31, 39, 44
541 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
542 static const yytype_int8 yyrhs[] =
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
551 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
552 static const yytype_uint16 yyrline[] =
554 0, 132, 132, 152, 152, 154, 154, 154, 156, 156,
555 156, 158, 158, 215, 215, 294, 312
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[] =
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
573 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
575 static const yytype_uint16 yytoknum[] =
577 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
578 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
583 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
584 static const yytype_uint8 yyr1[] =
586 0, 23, 24, 25, 25, 26, 26, 26, 27, 27,
587 27, 29, 28, 31, 30, 32, 33
590 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
591 static const yytype_uint8 yyr2[] =
593 0, 2, 1, 1, 1, 2, 2, 0, 2, 2,
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[] =
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
607 /* YYDEFGOTO[NTERM-NUM]. */
608 static const yytype_int8 yydefgoto[] =
610 -1, 3, 4, 12, 20, 5, 10, 6, 18, 25,
614 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
616 #define YYPACT_NINF -13
617 static const yytype_int8 yypact[] =
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
624 /* YYPGOTO[NTERM-NUM]. */
625 static const yytype_int8 yypgoto[] =
627 -13, -13, -12, -13, -13, -13, -13, -13, -13, -13,
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[] =
638 16, 1, 2, 14, 1, 2, 7, 15, 24, 22,
639 23, 1, 2, 8, 9, 11, 13, 19, 27, 21,
643 static const yytype_int8 yycheck[] =
645 12, 3, 4, 5, 3, 4, 12, 9, 20, 8,
646 9, 3, 4, 7, 0, 22, 6, 12, 22, 10,
650 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
651 symbol of state STATE-NUM. */
652 static const yytype_uint8 yystos[] =
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
659 #define yyerrok (yyerrstatus = 0)
660 #define yyclearin (yychar = YYEMPTY)
664 #define YYACCEPT goto yyacceptlab
665 #define YYABORT goto yyabortlab
666 #define YYERROR goto yyerrorlab
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. */
673 #define YYFAIL goto yyerrlab
675 #define YYRECOVERING() (!!yyerrstatus)
677 #define YYBACKUP(Token, Value) \
679 if (yychar == YYEMPTY && yylen == 1) \
683 yytoken = YYTRANSLATE (yychar); \
689 yyerror (YY_("syntax error: cannot back up")); \
696 #define YYERRCODE 256
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). */
703 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
704 #ifndef YYLLOC_DEFAULT
705 # define YYLLOC_DEFAULT(Current, Rhs, N) \
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; \
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; \
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. */
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)
736 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
741 /* YYLEX -- calling `yylex' with the right arguments. */
744 # define YYLEX yylex (YYLEX_PARAM)
746 # define YYLEX yylex ()
749 /* Enable debugging if requested. */
753 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
754 # define YYFPRINTF fprintf
757 # define YYDPRINTF(Args) \
763 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
767 YYFPRINTF (stderr, "%s ", Title); \
768 yy_symbol_print (stderr, \
770 YYFPRINTF (stderr, "\n"); \
775 /*--------------------------------.
776 | Print this symbol on YYOUTPUT. |
777 `--------------------------------*/
780 #if (defined __STDC__ || defined __C99__FUNC__ \
781 || defined __cplusplus || defined _MSC_VER)
783 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
786 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
789 YYSTYPE const * const yyvaluep;
795 if (yytype < YYNTOKENS)
796 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
808 /*--------------------------------.
809 | Print this symbol on YYOUTPUT. |
810 `--------------------------------*/
812 #if (defined __STDC__ || defined __C99__FUNC__ \
813 || defined __cplusplus || defined _MSC_VER)
815 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
818 yy_symbol_print (yyoutput, yytype, yyvaluep)
821 YYSTYPE const * const yyvaluep;
824 if (yytype < YYNTOKENS)
825 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
827 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
829 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
830 YYFPRINTF (yyoutput, ")");
833 /*------------------------------------------------------------------.
834 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
836 `------------------------------------------------------------------*/
838 #if (defined __STDC__ || defined __C99__FUNC__ \
839 || defined __cplusplus || defined _MSC_VER)
841 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
844 yy_stack_print (yybottom, yytop)
845 yytype_int16 *yybottom;
849 YYFPRINTF (stderr, "Stack now");
850 for (; yybottom <= yytop; yybottom++)
852 int yybot = *yybottom;
853 YYFPRINTF (stderr, " %d", yybot);
855 YYFPRINTF (stderr, "\n");
858 # define YY_STACK_PRINT(Bottom, Top) \
861 yy_stack_print ((Bottom), (Top)); \
865 /*------------------------------------------------.
866 | Report that the YYRULE is going to be reduced. |
867 `------------------------------------------------*/
869 #if (defined __STDC__ || defined __C99__FUNC__ \
870 || defined __cplusplus || defined _MSC_VER)
872 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
875 yy_reduce_print (yyvsp, yyrule)
880 int yynrhs = yyr2[yyrule];
882 unsigned long int yylno = yyrline[yyrule];
883 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
885 /* The symbols being reduced. */
886 for (yyi = 0; yyi < yynrhs; yyi++)
888 YYFPRINTF (stderr, " $%d = ", yyi + 1);
889 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
890 &(yyvsp[(yyi + 1) - (yynrhs)])
892 YYFPRINTF (stderr, "\n");
896 # define YY_REDUCE_PRINT(Rule) \
899 yy_reduce_print (yyvsp, Rule); \
902 /* Nonzero means print parse trace. It is left uninitialized so that
903 multiple parsers can coexist. */
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 */
913 /* YYINITDEPTH -- initial size of the parser's stacks. */
915 # define YYINITDEPTH 200
918 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
919 if the built-in stack extension method is used).
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. */
926 # define YYMAXDEPTH 10000
934 # if defined __GLIBC__ && defined _STRING_H
935 # define yystrlen strlen
937 /* Return the length of YYSTR. */
938 #if (defined __STDC__ || defined __C99__FUNC__ \
939 || defined __cplusplus || defined _MSC_VER)
941 yystrlen (const char *yystr)
949 for (yylen = 0; yystr[yylen]; yylen++)
957 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
958 # define yystpcpy stpcpy
960 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
962 #if (defined __STDC__ || defined __C99__FUNC__ \
963 || defined __cplusplus || defined _MSC_VER)
965 yystpcpy (char *yydest, const char *yysrc)
968 yystpcpy (yydest, yysrc)
974 const char *yys = yysrc;
976 while ((*yyd++ = *yys++) != '\0')
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
993 yytnamerr (char *yyres, const char *yystr)
998 char const *yyp = yystr;
1005 goto do_not_strip_quotes;
1009 goto do_not_strip_quotes;
1022 do_not_strip_quotes: ;
1026 return yystrlen (yystr);
1028 return yystpcpy (yyres, yystr) - yyres;
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. */
1040 yysyntax_error (char *yyresult, int yystate, int yychar)
1042 int yyn = yypact[yystate];
1044 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1048 int yytype = YYTRANSLATE (yychar);
1049 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1050 YYSIZE_T yysize = yysize0;
1052 int yysize_overflow = 0;
1053 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1054 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
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");
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;
1077 /* Start YYX at -YYN if negative to avoid negative indexes in
1079 int yyxbegin = yyn < 0 ? -yyn : 0;
1081 /* Stay within bounds of both yycheck and yytname. */
1082 int yychecklim = YYLAST - yyn + 1;
1083 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1086 yyarg[0] = yytname[yytype];
1087 yyfmt = yystpcpy (yyformat, yyunexpected);
1089 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1090 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1092 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1096 yyformat[sizeof yyunexpected - 1] = '\0';
1099 yyarg[yycount++] = yytname[yyx];
1100 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1101 yysize_overflow |= (yysize1 < yysize);
1103 yyfmt = yystpcpy (yyfmt, yyprefix);
1107 yyf = YY_(yyformat);
1108 yysize1 = yysize + yystrlen (yyf);
1109 yysize_overflow |= (yysize1 < yysize);
1112 if (yysize_overflow)
1113 return YYSIZE_MAXIMUM;
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;
1122 while ((*yyp = *yyf) != '\0')
1124 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1126 yyp += yytnamerr (yyp, yyarg[yyi++]);
1139 #endif /* YYERROR_VERBOSE */
1142 /*-----------------------------------------------.
1143 | Release the memory associated to this symbol. |
1144 `-----------------------------------------------*/
1147 #if (defined __STDC__ || defined __C99__FUNC__ \
1148 || defined __cplusplus || defined _MSC_VER)
1150 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1153 yydestruct (yymsg, yytype, yyvaluep)
1163 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1173 /* Prevent warnings from -Wmissing-prototypes. */
1174 #ifdef YYPARSE_PARAM
1175 #if defined __STDC__ || defined __cplusplus
1176 int yyparse (void *YYPARSE_PARAM);
1180 #else /* ! YYPARSE_PARAM */
1181 #if defined __STDC__ || defined __cplusplus
1186 #endif /* ! YYPARSE_PARAM */
1189 /* The lookahead symbol. */
1192 /* The semantic value of the lookahead symbol. */
1195 /* Number of syntax errors so far. */
1200 /*-------------------------.
1201 | yyparse or yypush_parse. |
1202 `-------------------------*/
1204 #ifdef YYPARSE_PARAM
1205 #if (defined __STDC__ || defined __C99__FUNC__ \
1206 || defined __cplusplus || defined _MSC_VER)
1208 yyparse (void *YYPARSE_PARAM)
1211 yyparse (YYPARSE_PARAM)
1212 void *YYPARSE_PARAM;
1214 #else /* ! YYPARSE_PARAM */
1215 #if (defined __STDC__ || defined __C99__FUNC__ \
1216 || defined __cplusplus || defined _MSC_VER)
1229 /* Number of tokens to shift before error messages enabled. */
1232 /* The stacks and their tools:
1233 `yyss': related to states.
1234 `yyvs': related to semantic values.
1236 Refer to the stacks thru separate pointers, to allow yyoverflow
1237 to reallocate them elsewhere. */
1239 /* The state stack. */
1240 yytype_int16 yyssa[YYINITDEPTH];
1242 yytype_int16 *yyssp;
1244 /* The semantic value stack. */
1245 YYSTYPE yyvsa[YYINITDEPTH];
1249 YYSIZE_T yystacksize;
1253 /* Lookahead token as an internal (translated) token number. */
1255 /* The variables used to return semantic value and location from the
1260 /* Buffer for error messages, and its allocated size. */
1262 char *yymsg = yymsgbuf;
1263 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1266 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1268 /* The number of symbols on the RHS of the reduced rule.
1269 Keep to zero when no symbol should be popped. */
1275 yystacksize = YYINITDEPTH;
1277 YYDPRINTF ((stderr, "Starting parse\n"));
1282 yychar = YYEMPTY; /* Cause a token to be read. */
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. */
1293 /*------------------------------------------------------------.
1294 | yynewstate -- Push a new state, which is found in yystate. |
1295 `------------------------------------------------------------*/
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. */
1304 if (yyss + yystacksize - 1 <= yyssp)
1306 /* Get the current used size of the three stacks, in elements. */
1307 YYSIZE_T yysize = yyssp - yyss + 1;
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
1314 YYSTYPE *yyvs1 = yyvs;
1315 yytype_int16 *yyss1 = yyss;
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),
1329 #else /* no yyoverflow */
1330 # ifndef YYSTACK_RELOCATE
1331 goto yyexhaustedlab;
1333 /* Extend the stack our own way. */
1334 if (YYMAXDEPTH <= yystacksize)
1335 goto yyexhaustedlab;
1337 if (YYMAXDEPTH < yystacksize)
1338 yystacksize = YYMAXDEPTH;
1341 yytype_int16 *yyss1 = yyss;
1342 union yyalloc *yyptr =
1343 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1345 goto yyexhaustedlab;
1346 YYSTACK_RELOCATE (yyss_alloc, yyss);
1347 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1348 # undef YYSTACK_RELOCATE
1350 YYSTACK_FREE (yyss1);
1353 #endif /* no yyoverflow */
1355 yyssp = yyss + yysize - 1;
1356 yyvsp = yyvs + yysize - 1;
1358 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1359 (unsigned long int) yystacksize));
1361 if (yyss + yystacksize - 1 <= yyssp)
1365 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1367 if (yystate == YYFINAL)
1377 /* Do appropriate processing given the current state. Read a
1378 lookahead token if we need one and don't already have one. */
1380 /* First try to decide what to do without reference to lookahead token. */
1381 yyn = yypact[yystate];
1382 if (yyn == YYPACT_NINF)
1385 /* Not known => get a lookahead token if don't already have one. */
1387 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1388 if (yychar == YYEMPTY)
1390 YYDPRINTF ((stderr, "Reading a token: "));
1394 if (yychar <= YYEOF)
1396 yychar = yytoken = YYEOF;
1397 YYDPRINTF ((stderr, "Now at end of input.\n"));
1401 yytoken = YYTRANSLATE (yychar);
1402 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1405 /* If the proper action on seeing token YYTOKEN is to reduce or to
1406 detect an error, take that action. */
1408 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1413 if (yyn == 0 || yyn == YYTABLE_NINF)
1419 /* Count tokens shifted since error; after three, turn off error
1424 /* Shift the lookahead token. */
1425 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1427 /* Discard the shifted token. */
1436 /*-----------------------------------------------------------.
1437 | yydefault -- do the default action for the current state. |
1438 `-----------------------------------------------------------*/
1440 yyn = yydefact[yystate];
1446 /*-----------------------------.
1447 | yyreduce -- Do a reduction. |
1448 `-----------------------------*/
1450 /* yyn is the number of a rule to reduce with. */
1453 /* If YYLEN is nonzero, implement the default value of the action:
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];
1464 YY_REDUCE_PRINT (yyn);
1470 root.next_sibling = root.children;
1471 root.next_sibling->next_sibling = root.next_sibling->children;
1473 struct device *dev = &root;
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;
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;
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);
1498 for (c = (yyval.device)->name_underscore; *c; c++) {
1499 if (*c == '/') *c = '_';
1500 if (*c == '-') *c = '_';
1502 (yyval.device)->type = chip;
1503 (yyval.device)->chip = (yyval.device);
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;
1511 if (cur_parent->latestchild) {
1512 cur_parent->latestchild->next_sibling = (yyval.device);
1513 cur_parent->latestchild->sibling = (yyval.device);
1515 cur_parent->latestchild = (yyval.device);
1516 if (!cur_parent->children)
1517 cur_parent->children = (yyval.device);
1519 cur_parent = (yyval.device);
1526 cur_parent = (yyvsp[(3) - (5)].device)->parent;
1528 fold_in((yyvsp[(3) - (5)].device));
1530 if ((yyvsp[(3) - (5)].device)->chiph_exists) {
1531 int include_exists = 0;
1532 struct header *h = &headers;
1534 int result = strcmp((yyvsp[(3) - (5)].device)->name, h->next->name);
1539 if (result < 0) break;
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;
1557 (yyval.device) = new_dev();
1558 (yyval.device)->bustype = (yyvsp[(2) - (4)].number);
1561 (yyval.device)->path_a = strtol(strdup((yyvsp[(3) - (4)].string)), &tmp, 16);
1564 (yyval.device)->path_b = strtol(tmp, NULL, 16);
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;
1575 if (cur_parent->latestchild) {
1576 cur_parent->latestchild->next_sibling = (yyval.device);
1577 cur_parent->latestchild->sibling = (yyval.device);
1579 cur_parent->latestchild = (yyval.device);
1580 if (!cur_parent->children)
1581 cur_parent->children = (yyval.device);
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)}}";
1588 if ((yyvsp[(2) - (4)].number) == PNP) {
1589 (yyval.device)->path = ".type=DEVICE_PATH_PNP,{.pnp={ .port = 0x%x, .device = 0x%x }}";
1591 if ((yyvsp[(2) - (4)].number) == I2C) {
1592 (yyval.device)->path = ".type=DEVICE_PATH_I2C,{.i2c={ .device = 0x%x }}";
1594 if ((yyvsp[(2) - (4)].number) == APIC) {
1595 (yyval.device)->path = ".type=DEVICE_PATH_APIC,{.apic={ .apic_id = 0x%x }}";
1597 if ((yyvsp[(2) - (4)].number) == APIC_CLUSTER) {
1598 (yyval.device)->path = ".type=DEVICE_PATH_APIC_CLUSTER,{.apic_cluster={ .cluster = 0x%x }}";
1600 if ((yyvsp[(2) - (4)].number) == PCI_DOMAIN) {
1601 (yyval.device)->path = ".type=DEVICE_PATH_PCI_DOMAIN,{.pci_domain={ .domain = 0x%x }}";
1603 cur_parent = (yyval.device);
1604 cur_bus = (yyval.device);
1611 cur_parent = (yyvsp[(5) - (7)].device)->parent;
1612 cur_bus = (yyvsp[(5) - (7)].device)->bus;
1614 fold_in((yyvsp[(5) - (7)].device));
1616 struct device *d = (yyvsp[(5) - (7)].device)->children;
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)) {
1625 cmp->aliased_name = malloc(12);
1626 sprintf(cmp->aliased_name, "_dev%d", cmp->id);
1628 cmp->name = d->name;
1633 cmp = cmp->next_sibling;
1635 d = d->next_sibling;
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;
1653 cur_parent->res = r;
1655 cur_parent->rescnt++;
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);
1671 printf("ERROR: duplicate 'register' key.\n");
1676 cur_parent->reg = r;
1678 while ((head->next) && (strcmp(head->next->key, r->key)<0)) head = head->next;
1679 r->next = head->next;
1683 cur_parent->reg = r;
1692 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1696 YY_STACK_PRINT (yyss, yyssp);
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. */
1706 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1707 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1708 yystate = yytable[yystate];
1710 yystate = yydefgoto[yyn - YYNTOKENS];
1715 /*------------------------------------.
1716 | yyerrlab -- here on detecting error |
1717 `------------------------------------*/
1719 /* If not already recovering from an error, report this error. */
1723 #if ! YYERROR_VERBOSE
1724 yyerror (YY_("syntax error"));
1727 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1728 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
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);
1737 yymsg_alloc = yyalloc;
1741 yymsg_alloc = sizeof yymsgbuf;
1745 if (0 < yysize && yysize <= yymsg_alloc)
1747 (void) yysyntax_error (yymsg, yystate, yychar);
1752 yyerror (YY_("syntax error"));
1754 goto yyexhaustedlab;
1762 if (yyerrstatus == 3)
1764 /* If just tried and failed to reuse lookahead token after an
1765 error, discard it. */
1767 if (yychar <= YYEOF)
1769 /* Return failure if at end of input. */
1770 if (yychar == YYEOF)
1775 yydestruct ("Error: discarding",
1781 /* Else will try to reuse lookahead token after shifting the error
1786 /*---------------------------------------------------.
1787 | yyerrorlab -- error raised explicitly by YYERROR. |
1788 `---------------------------------------------------*/
1791 /* Pacify compilers like GCC when the user code never invokes
1792 YYERROR and the label yyerrorlab therefore never appears in user
1794 if (/*CONSTCOND*/ 0)
1797 /* Do not reclaim the symbols of the rule which action triggered
1801 YY_STACK_PRINT (yyss, yyssp);
1806 /*-------------------------------------------------------------.
1807 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1808 `-------------------------------------------------------------*/
1810 yyerrstatus = 3; /* Each real token shifted decrements this. */
1814 yyn = yypact[yystate];
1815 if (yyn != YYPACT_NINF)
1818 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1826 /* Pop the current state because it cannot handle the error token. */
1831 yydestruct ("Error: popping",
1832 yystos[yystate], yyvsp);
1835 YY_STACK_PRINT (yyss, yyssp);
1841 /* Shift the error token. */
1842 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1848 /*-------------------------------------.
1849 | yyacceptlab -- YYACCEPT comes here. |
1850 `-------------------------------------*/
1855 /*-----------------------------------.
1856 | yyabortlab -- YYABORT comes here. |
1857 `-----------------------------------*/
1862 #if !defined(yyoverflow) || YYERROR_VERBOSE
1863 /*-------------------------------------------------.
1864 | yyexhaustedlab -- memory exhaustion comes here. |
1865 `-------------------------------------------------*/
1867 yyerror (YY_("memory exhausted"));
1873 if (yychar != YYEMPTY)
1874 yydestruct ("Cleanup: discarding lookahead",
1876 /* Do not reclaim the symbols of the rule which action triggered
1877 this YYABORT or YYACCEPT. */
1879 YY_STACK_PRINT (yyss, yyssp);
1880 while (yyssp != yyss)
1882 yydestruct ("Cleanup: popping",
1883 yystos[*yyssp], yyvsp);
1888 YYSTACK_FREE (yyss);
1891 if (yymsg != yymsgbuf)
1892 YYSTACK_FREE (yymsg);
1894 /* Make sure YYID is used. */
1895 return YYID (yyresult);
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);
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;
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);
1930 fprintf(fil, "\t },\n");
1933 fprintf(fil, "\t.link = {\n");
1934 if (ptr->multidev) {
1935 struct device *d = ptr;
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);
1942 fprintf(fil, "\t\t\t.children = &%s,\n", d->children->name);
1943 fprintf(fil, "\t\t},\n");
1946 d = d->next_sibling;
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");
1958 fprintf(fil, "\t},\n");
1959 fprintf(fil, "\t.links = %d,\n", link);
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);
1967 fprintf(fil, "\t.next=&%s\n", ptr->nextdev->name);
1968 fprintf(fil, "};\n");
1970 if ((ptr->type == chip) && (ptr->chiph_exists)) {
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;
1975 fprintf(fil, "\t.%s = %s,\n", r->key, r->value);
1978 fprintf(fil, "};\n\n");
1980 fprintf(fil, "struct %s_config %s_info_%d;\n", ptr->name_underscore, ptr->name_underscore, ptr->id);
1985 void walk_device_tree(FILE *fil, struct device *ptr, void (*func)(FILE *, struct device*), struct device *chips) {
1988 ptr = ptr->next_sibling;
1992 struct device mainboard = {
1993 .name = "mainboard",
1994 .name_underscore = "mainboard",
2002 struct device root = {
2004 .name_underscore = "dev_root",
2008 .path = " .type = DEVICE_PATH_ROOT ",
2009 .ops = "&default_dev_ops_root",
2015 int main(int argc, char** argv) {
2017 printf("usage: sconfig vendor/mainboard outputdir\n");
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);
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);
2032 FILE *filec = fopen(devtree, "r");
2035 FILE *staticc = fopen(outputc, "w");
2037 cur_bus = cur_parent = lastdev = head = &root;
2041 if ((head->type == chip) && (!head->chiph_exists)) {
2042 struct device *tmp = head;
2044 while (head->next != tmp) head = head->next;
2047 fprintf(staticc, "#include <device/device.h>\n");
2048 fprintf(staticc, "#include <device/pci.h>\n");
2049 struct header *h = &headers;
2052 fprintf(staticc, "#include \"%s/chip.h\"\n", h->name);
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);