1783af925Schristos %{
2783af925Schristos /******************************************************************************
3783af925Schristos *
4783af925Schristos * Module Name: dtcompilerparser.y - Bison input file for table compiler parser
5783af925Schristos *
6783af925Schristos *****************************************************************************/
7783af925Schristos
8783af925Schristos /*
9*2c7d7e3cSchristos * Copyright (C) 2000 - 2023, Intel Corp.
10783af925Schristos * All rights reserved.
11783af925Schristos *
12783af925Schristos * Redistribution and use in source and binary forms, with or without
13783af925Schristos * modification, are permitted provided that the following conditions
14783af925Schristos * are met:
15783af925Schristos * 1. Redistributions of source code must retain the above copyright
16783af925Schristos * notice, this list of conditions, and the following disclaimer,
17783af925Schristos * without modification.
18783af925Schristos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19783af925Schristos * substantially similar to the "NO WARRANTY" disclaimer below
20783af925Schristos * ("Disclaimer") and any redistribution must be conditioned upon
21783af925Schristos * including a substantially similar Disclaimer requirement for further
22783af925Schristos * binary redistribution.
23783af925Schristos * 3. Neither the names of the above-listed copyright holders nor the names
24783af925Schristos * of any contributors may be used to endorse or promote products derived
25783af925Schristos * from this software without specific prior written permission.
26783af925Schristos *
27783af925Schristos * Alternatively, this software may be distributed under the terms of the
28783af925Schristos * GNU General Public License ("GPL") version 2 as published by the Free
29783af925Schristos * Software Foundation.
30783af925Schristos *
31783af925Schristos * NO WARRANTY
32783af925Schristos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33783af925Schristos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3498244dcfSchristos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35783af925Schristos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36783af925Schristos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37783af925Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38783af925Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39783af925Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40783af925Schristos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41783af925Schristos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42783af925Schristos * POSSIBILITY OF SUCH DAMAGES.
43783af925Schristos */
44783af925Schristos
45783af925Schristos #include "aslcompiler.h"
46783af925Schristos
47783af925Schristos
48783af925Schristos #define _COMPONENT DT_COMPILER
49783af925Schristos ACPI_MODULE_NAME ("dtcompilerparser")
50783af925Schristos
51783af925Schristos void * AslLocalAllocate (unsigned int Size);
52783af925Schristos
53783af925Schristos /* Bison/yacc configuration */
54783af925Schristos
55783af925Schristos #undef alloca
56783af925Schristos #define alloca AslLocalAllocate
57783af925Schristos
58783af925Schristos int DtCompilerParserlex (void);
59783af925Schristos int DtCompilerParserparse (void);
601c663068Schristos #ifdef YYBYACC
611c663068Schristos struct YYLTYPE;
621c663068Schristos #endif
637ab6b89bSchristos void DtCompilerParsererror (
647ab6b89bSchristos #ifdef YYBYACC
651c663068Schristos struct YYLTYPE *loc,
667ab6b89bSchristos #endif
677ab6b89bSchristos char const *msg);
68783af925Schristos extern char *DtCompilerParsertext;
69783af925Schristos extern DT_FIELD *AslGbl_CurrentField;
70783af925Schristos
711c663068Schristos extern int DtLabelByteOffset;
72783af925Schristos extern UINT64 DtCompilerParserlineno; /* Current line number */
73783af925Schristos
741c663068Schristos extern UINT32 DtTokenFirstLine;
751c663068Schristos extern UINT32 DtTokenFirstColumn;
761c663068Schristos
77783af925Schristos /* Bison/yacc configuration */
78783af925Schristos
79783af925Schristos #define yytname DtCompilerParsername
80783af925Schristos #define YYDEBUG 1 /* Enable debug output */
81783af925Schristos #define YYERROR_VERBOSE 1 /* Verbose error messages */
82783af925Schristos #define YYFLAG -32768
83783af925Schristos
84783af925Schristos /* Define YYMALLOC/YYFREE to prevent redefinition errors */
85783af925Schristos
86783af925Schristos #define YYMALLOC malloc
87783af925Schristos #define YYFREE free
88783af925Schristos
89783af925Schristos %}
90783af925Schristos
91783af925Schristos
92783af925Schristos %union {
93783af925Schristos char *s;
94783af925Schristos DT_FIELD *f;
951c663068Schristos DT_TABLE_UNIT *u;
96783af925Schristos }
97783af925Schristos
98783af925Schristos
99783af925Schristos %type <f> Table
1001c663068Schristos %token <u> DT_PARSEOP_DATA
1011c663068Schristos %token <u> DT_PARSEOP_LABEL
1021c663068Schristos %token <u> DT_PARSEOP_STRING_DATA
1031c663068Schristos %token <u> DT_PARSEOP_LINE_CONTINUATION
1041c663068Schristos %type <u> Data
1051c663068Schristos %type <u> Datum
1061c663068Schristos %type <u> MultiLineData
1071c663068Schristos %type <u> MultiLineDataList
108783af925Schristos
109783af925Schristos
110783af925Schristos %%
111783af925Schristos
112783af925Schristos Table
113783af925Schristos :
1141c663068Schristos FieldList { }
115783af925Schristos ;
116783af925Schristos
117783af925Schristos FieldList
118783af925Schristos : Field FieldList
119783af925Schristos | Field
120783af925Schristos ;
121783af925Schristos
122783af925Schristos Field
1231c663068Schristos : DT_PARSEOP_LABEL ':' Data { DtCreateField ($1, $3, DtLabelByteOffset); }
124783af925Schristos ;
125783af925Schristos
126783af925Schristos Data
127783af925Schristos : MultiLineDataList { $$ = $1; }
128783af925Schristos | Datum { $$ = $1; }
129783af925Schristos | Datum MultiLineDataList { $$ = $1; } /* combine the string with strcat */
130783af925Schristos ;
131783af925Schristos
132783af925Schristos MultiLineDataList
1331c663068Schristos : MultiLineDataList MultiLineData { $$ = DtCreateTableUnit (AcpiUtStrcat(AcpiUtStrcat($1->Value, " "), $2->Value), $1->Line, $1->Column); } /* combine the strings with strcat */
134783af925Schristos | MultiLineData { $$ = $1; }
135783af925Schristos ;
136783af925Schristos
137783af925Schristos MultiLineData
138783af925Schristos : DT_PARSEOP_LINE_CONTINUATION Datum { DbgPrint (ASL_PARSE_OUTPUT, "line continuation detected\n"); $$ = $2; }
139783af925Schristos ;
140783af925Schristos
141783af925Schristos Datum
1421c663068Schristos : DT_PARSEOP_DATA {
1431c663068Schristos DbgPrint (ASL_PARSE_OUTPUT, "parser data: [%s]\n", DtCompilerParserlval.s);
1441c663068Schristos $$ = DtCreateTableUnit (AcpiUtStrdup(DtCompilerParserlval.s), DtTokenFirstLine, DtTokenFirstColumn);
1451c663068Schristos }
1461c663068Schristos | DT_PARSEOP_STRING_DATA {
1471c663068Schristos DbgPrint (ASL_PARSE_OUTPUT, "parser string data: [%s]\n", DtCompilerParserlval.s);
1481c663068Schristos $$ = DtCreateTableUnit (AcpiUtStrdup(DtCompilerParserlval.s), DtTokenFirstLine, DtTokenFirstColumn);
1491c663068Schristos }
150783af925Schristos ;
151783af925Schristos
152783af925Schristos
153783af925Schristos %%
154783af925Schristos
155783af925Schristos
156783af925Schristos /*
157783af925Schristos * Local support functions, including parser entry point
158783af925Schristos */
159783af925Schristos /******************************************************************************
160783af925Schristos *
161783af925Schristos * FUNCTION: DtCompilerParsererror
162783af925Schristos *
163783af925Schristos * PARAMETERS: Message - Parser-generated error message
164783af925Schristos *
165783af925Schristos * RETURN: None
166783af925Schristos *
167783af925Schristos * DESCRIPTION: Handler for parser errors
168783af925Schristos *
169783af925Schristos *****************************************************************************/
170783af925Schristos
171783af925Schristos void
172783af925Schristos DtCompilerParsererror (
1737ab6b89bSchristos #ifdef YYBYACC
1741c663068Schristos struct YYLTYPE *loc,
1757ab6b89bSchristos #endif
176783af925Schristos char const *Message)
177783af925Schristos {
178783af925Schristos DtError (ASL_ERROR, ASL_MSG_SYNTAX,
179783af925Schristos AslGbl_CurrentField, (char *) Message);
180783af925Schristos }
181783af925Schristos
182783af925Schristos int
DtCompilerParserwrap(void)183783af925Schristos DtCompilerParserwrap(void)
184783af925Schristos {
185783af925Schristos return (1);
186783af925Schristos }
187