xref: /freebsd/sys/contrib/dev/acpica/compiler/aslrules.y (revision a7dea1671b87c07d2d266f836bfa8b58efc7c134)
1 NoEcho('
2 /******************************************************************************
3  *
4  * Module Name: aslrules.y - Main Bison/Yacc production rules
5  *                         - Keep this file synched with the
6  *                           CvParseOpBlockType function in cvcompiler.c
7  *
8  *****************************************************************************/
9 
10 /******************************************************************************
11  *
12  * 1. Copyright Notice
13  *
14  * Some or all of this work - Copyright (c) 1999 - 2020, Intel Corp.
15  * All rights reserved.
16  *
17  * 2. License
18  *
19  * 2.1. This is your license from Intel Corp. under its intellectual property
20  * rights. You may have additional license terms from the party that provided
21  * you this software, covering your right to use that party's intellectual
22  * property rights.
23  *
24  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
25  * copy of the source code appearing in this file ("Covered Code") an
26  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
27  * base code distributed originally by Intel ("Original Intel Code") to copy,
28  * make derivatives, distribute, use and display any portion of the Covered
29  * Code in any form, with the right to sublicense such rights; and
30  *
31  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
32  * license (with the right to sublicense), under only those claims of Intel
33  * patents that are infringed by the Original Intel Code, to make, use, sell,
34  * offer to sell, and import the Covered Code and derivative works thereof
35  * solely to the minimum extent necessary to exercise the above copyright
36  * license, and in no event shall the patent license extend to any additions
37  * to or modifications of the Original Intel Code. No other license or right
38  * is granted directly or by implication, estoppel or otherwise;
39  *
40  * The above copyright and patent license is granted only if the following
41  * conditions are met:
42  *
43  * 3. Conditions
44  *
45  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
46  * Redistribution of source code of any substantial portion of the Covered
47  * Code or modification with rights to further distribute source must include
48  * the above Copyright Notice, the above License, this list of Conditions,
49  * and the following Disclaimer and Export Compliance provision. In addition,
50  * Licensee must cause all Covered Code to which Licensee contributes to
51  * contain a file documenting the changes Licensee made to create that Covered
52  * Code and the date of any change. Licensee must include in that file the
53  * documentation of any changes made by any predecessor Licensee. Licensee
54  * must include a prominent statement that the modification is derived,
55  * directly or indirectly, from Original Intel Code.
56  *
57  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
58  * Redistribution of source code of any substantial portion of the Covered
59  * Code or modification without rights to further distribute source must
60  * include the following Disclaimer and Export Compliance provision in the
61  * documentation and/or other materials provided with distribution. In
62  * addition, Licensee may not authorize further sublicense of source of any
63  * portion of the Covered Code, and must include terms to the effect that the
64  * license from Licensee to its licensee is limited to the intellectual
65  * property embodied in the software Licensee provides to its licensee, and
66  * not to intellectual property embodied in modifications its licensee may
67  * make.
68  *
69  * 3.3. Redistribution of Executable. Redistribution in executable form of any
70  * substantial portion of the Covered Code or modification must reproduce the
71  * above Copyright Notice, and the following Disclaimer and Export Compliance
72  * provision in the documentation and/or other materials provided with the
73  * distribution.
74  *
75  * 3.4. Intel retains all right, title, and interest in and to the Original
76  * Intel Code.
77  *
78  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
79  * Intel shall be used in advertising or otherwise to promote the sale, use or
80  * other dealings in products derived from or relating to the Covered Code
81  * without prior written authorization from Intel.
82  *
83  * 4. Disclaimer and Export Compliance
84  *
85  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
86  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
87  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
88  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
89  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
90  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91  * PARTICULAR PURPOSE.
92  *
93  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
94  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
95  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
96  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
97  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
98  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
99  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100  * LIMITED REMEDY.
101  *
102  * 4.3. Licensee shall not export, either directly or indirectly, any of this
103  * software or system incorporating such software without first obtaining any
104  * required license or other approval from the U. S. Department of Commerce or
105  * any other agency or department of the United States Government. In the
106  * event Licensee exports any such software from the United States or
107  * re-exports any such software from a foreign destination, Licensee shall
108  * ensure that the distribution and export/re-export of the software is in
109  * compliance with all laws, regulations, orders, or other restrictions of the
110  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
111  * any of its subsidiaries will export/re-export any technical data, process,
112  * software, or service, directly or indirectly, to any country for which the
113  * United States government or any agency thereof requires an export license,
114  * other governmental approval, or letter of assurance, without first obtaining
115  * such license, approval or letter.
116  *
117  *****************************************************************************
118  *
119  * Alternatively, you may choose to be licensed under the terms of the
120  * following license:
121  *
122  * Redistribution and use in source and binary forms, with or without
123  * modification, are permitted provided that the following conditions
124  * are met:
125  * 1. Redistributions of source code must retain the above copyright
126  *    notice, this list of conditions, and the following disclaimer,
127  *    without modification.
128  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
129  *    substantially similar to the "NO WARRANTY" disclaimer below
130  *    ("Disclaimer") and any redistribution must be conditioned upon
131  *    including a substantially similar Disclaimer requirement for further
132  *    binary redistribution.
133  * 3. Neither the names of the above-listed copyright holders nor the names
134  *    of any contributors may be used to endorse or promote products derived
135  *    from this software without specific prior written permission.
136  *
137  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
138  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
139  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
140  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
141  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
142  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
143  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
144  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
145  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
146  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
147  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
148  *
149  * Alternatively, you may choose to be licensed under the terms of the
150  * GNU General Public License ("GPL") version 2 as published by the Free
151  * Software Foundation.
152  *
153  *****************************************************************************/
154 
155 ')
156 
157 /*******************************************************************************
158  *
159  * ASL Root and Secondary Terms
160  *
161  ******************************************************************************/
162 
163 /*
164  * Root term. Allow multiple #line directives before the definition block
165  * to handle output from preprocessors
166  */
167 AslCode
168     : DefinitionBlockList           {$<n>$ = TrLinkOpChildren (
169                                         TrCreateLeafOp (PARSEOP_ASL_CODE),1, $1);}
170     | error                         {YYABORT; $$ = NULL;}
171     ;
172 
173 
174 /*
175  * Note concerning support for "module-level code".
176  *
177  * ACPI 1.0 allowed Type1 and Type2 executable opcodes outside of control
178  * methods (the so-called module-level code.) This support was explicitly
179  * removed in ACPI 2.0, but this type of code continues to be created by
180  * BIOS vendors. In order to support the disassembly and recompilation of
181  * such code (and the porting of ASL code to iASL), iASL supports this
182  * code in violation of the current ACPI specification.
183  *
184  * The grammar change to support module-level code is to revert the
185  * {ObjectList} portion of the DefinitionBlockTerm in ACPI 2.0 to the
186  * original use of {TermList} instead (see below.) This allows the use
187  * of Type1 and Type2 opcodes at module level.
188  *
189  * 04/2016: The module-level code is now allowed in the following terms:
190  * DeviceTerm, PowerResTerm, ProcessorTerm, ScopeTerm, ThermalZoneTerm.
191  * The ObjectList term is obsolete and has been removed.
192  */
193 DefinitionBlockTerm
194     : PARSEOP_DEFINITION_BLOCK
195         PARSEOP_OPEN_PAREN          {$<n>$ = TrCreateLeafOp (PARSEOP_DEFINITION_BLOCK); COMMENT_CAPTURE_OFF;}
196         String ','
197         String ','
198         ByteConst ','
199         String ','
200         String ','
201         DWordConst
202         PARSEOP_CLOSE_PAREN         {TrSetOpIntegerWidth ($6,$8);
203                                         TrSetOpEndLineNumber ($<n>3); COMMENT_CAPTURE_ON;}
204             '{' TermList '}'        {$$ = TrLinkOpChildren ($<n>3,7,
205                                         $4,$6,$8,$10,$12,$14,$18);}
206     ;
207 
208 DefinitionBlockList
209     : DefinitionBlockTerm
210     | DefinitionBlockTerm
211         DefinitionBlockList         {$$ = TrLinkPeerOps (2, $1,$2);}
212     ;
213 
214 
215 /******* Basic ASCII identifiers **************************************************/
216 
217 /* Allow IO, DMA, IRQ Resource macro and FOR macro names to also be used as identifiers */
218 
219 NameString
220     : NameSeg                       {}
221     | PARSEOP_NAMESTRING            {$$ = TrCreateValuedLeafOp (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) $1);}
222     | PARSEOP_IO                    {$$ = TrCreateValuedLeafOp (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "IO");}
223     | PARSEOP_DMA                   {$$ = TrCreateValuedLeafOp (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "DMA");}
224     | PARSEOP_IRQ                   {$$ = TrCreateValuedLeafOp (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "IRQ");}
225     | PARSEOP_FOR                   {$$ = TrCreateValuedLeafOp (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "FOR");}
226     ;
227 /*
228 NameSeg
229     : PARSEOP_NAMESEG               {$$ = TrCreateValuedLeafOp (PARSEOP_NAMESEG, (ACPI_NATIVE_INT)
230                                         TrNormalizeNameSeg ($1));}
231     ;
232 */
233 
234 NameSeg
235     : PARSEOP_NAMESEG               {$$ = TrCreateValuedLeafOp (PARSEOP_NAMESEG,
236                                         (ACPI_NATIVE_INT) AslCompilerlval.s);}
237     ;
238 
239 
240 /******* Fundamental argument/statement types ***********************************/
241 
242 Term
243     : Object                        {}
244     | Type1Opcode                   {}
245     | Type2Opcode                   {}
246     | Type2IntegerOpcode            {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);}
247     | Type2StringOpcode             {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);}
248     | Type2BufferOpcode             {}
249     | Type2BufferOrStringOpcode     {}
250     | error                         {$$ = AslDoError(); yyclearin;}
251     ;
252 
253 SuperName
254     : SimpleName                    {}
255     | DebugTerm                     {}
256     | Type6Opcode                   {}
257     ;
258 
259 Target
260     :                               {$$ = TrCreateNullTargetOp ();} /* Placeholder is a ZeroOp object */
261     | ','                           {$$ = TrCreateNullTargetOp ();} /* Placeholder is a ZeroOp object */
262     | ',' SuperName                 {$$ = TrSetOpFlags ($2, OP_IS_TARGET);}
263     ;
264 
265 RequiredTarget
266     : ',' SuperName                 {$$ = TrSetOpFlags ($2, OP_IS_TARGET);}
267     ;
268 
269 TermArg
270     : SimpleName                    {$$ = TrSetOpFlags ($1, OP_IS_TERM_ARG);}
271     | Type2Opcode                   {$$ = TrSetOpFlags ($1, OP_IS_TERM_ARG);}
272     | DataObject                    {$$ = TrSetOpFlags ($1, OP_IS_TERM_ARG);}
273     | PARSEOP_OPEN_PAREN
274         TermArg
275         PARSEOP_CLOSE_PAREN         {$$ = TrSetOpFlags ($2, OP_IS_TERM_ARG);}
276     ;
277 
278 /*
279  NOTE: Removed from TermArg due to reduce/reduce conflicts:
280     | Type2IntegerOpcode            {$$ = TrSetOpFlags ($1, OP_IS_TERM_ARG);}
281     | Type2StringOpcode             {$$ = TrSetOpFlags ($1, OP_IS_TERM_ARG);}
282     | Type2BufferOpcode             {$$ = TrSetOpFlags ($1, OP_IS_TERM_ARG);}
283     | Type2BufferOrStringOpcode     {$$ = TrSetOpFlags ($1, OP_IS_TERM_ARG);}
284 
285 */
286 
287 MethodInvocationTerm
288     : NameString
289         PARSEOP_OPEN_PAREN          {TrSetOpIntegerValue (PARSEOP_METHODCALL, $1); COMMENT_CAPTURE_OFF;}
290         ArgList
291         PARSEOP_CLOSE_PAREN         {$$ = TrLinkChildOp ($1,$4); COMMENT_CAPTURE_ON;}
292     ;
293 
294 /* OptionalCount must appear before ByteList or an incorrect reduction will result */
295 
296 OptionalCount
297     :                               {$$ = TrCreateLeafOp (PARSEOP_ONES);}       /* Placeholder is a OnesOp object */
298     | ','                           {$$ = TrCreateLeafOp (PARSEOP_ONES);}       /* Placeholder is a OnesOp object */
299     | ',' TermArg                   {$$ = $2;}
300     ;
301 
302 /*
303  * Data count for buffers and packages (byte count for buffers,
304  * element count for packages).
305  */
306 OptionalDataCount
307 
308         /* Legacy ASL */
309     :                               {$$ = NULL;}
310     | PARSEOP_OPEN_PAREN
311         TermArg
312         PARSEOP_CLOSE_PAREN         {$$ = $2;}
313     | PARSEOP_OPEN_PAREN
314         PARSEOP_CLOSE_PAREN         {$$ = NULL;}
315 
316         /* C-style (ASL+) -- adds equals term */
317 
318     |  PARSEOP_EXP_EQUALS           {$$ = NULL;}
319 
320     | PARSEOP_OPEN_PAREN
321         TermArg
322         PARSEOP_CLOSE_PAREN
323         PARSEOP_EXP_EQUALS          {$$ = $2;}
324 
325     | PARSEOP_OPEN_PAREN
326         PARSEOP_CLOSE_PAREN
327         String
328         PARSEOP_EXP_EQUALS          {$$ = NULL;}
329     ;
330 
331 
332 /******* List Terms **************************************************/
333 
334     /* ACPI 3.0 -- allow semicolons between terms */
335 
336 TermList
337     :                               {$$ = NULL;}
338     | TermList Term                 {$$ = TrLinkPeerOp (
339                                         TrSetOpFlags ($1, OP_RESULT_NOT_USED),$2);}
340     | TermList Term ';'             {$$ = TrLinkPeerOp (
341                                         TrSetOpFlags ($1, OP_RESULT_NOT_USED),$2);}
342     | TermList ';' Term             {$$ = TrLinkPeerOp (
343                                         TrSetOpFlags ($1, OP_RESULT_NOT_USED),$3);}
344     | TermList ';' Term ';'         {$$ = TrLinkPeerOp (
345                                         TrSetOpFlags ($1, OP_RESULT_NOT_USED),$3);}
346     ;
347 
348 ArgList
349     :                               {$$ = NULL;}
350     | TermArg
351     | ArgList ','                   /* Allows a trailing comma at list end */
352     | ArgList ','
353         TermArg                     {$$ = TrLinkPeerOp ($1,$3);}
354     ;
355 
356 ByteList
357     :                               {$$ = NULL;}
358     | ByteConstExpr
359     | ByteList ','                  /* Allows a trailing comma at list end */
360     | ByteList ','
361         ByteConstExpr               {$$ = TrLinkPeerOp ($1,$3);}
362     ;
363 
364 DWordList
365     :                               {$$ = NULL;}
366     | DWordConstExpr
367     | DWordList ','                 /* Allows a trailing comma at list end */
368     | DWordList ','
369         DWordConstExpr              {$$ = TrLinkPeerOp ($1,$3);}
370     ;
371 
372 FieldUnitList
373     :                               {$$ = NULL;}
374     | FieldUnit
375     | FieldUnitList ','             /* Allows a trailing comma at list end */
376     | FieldUnitList ','
377         FieldUnit                   {$$ = TrLinkPeerOp ($1,$3);}
378     ;
379 
380 FieldUnit
381     : FieldUnitEntry                {}
382     | OffsetTerm                    {}
383     | AccessAsTerm                  {}
384     | ConnectionTerm                {}
385     ;
386 
387 FieldUnitEntry
388     : ',' AmlPackageLengthTerm      {$$ = TrCreateOp (PARSEOP_RESERVED_BYTES,1,$2);}
389     | NameSeg ','
390         AmlPackageLengthTerm        {$$ = TrLinkChildOp ($1,$3);}
391     ;
392 
393 Object
394     : CompilerDirective             {}
395     | NamedObject                   {}
396     | NameSpaceModifier             {}
397 /*    | StructureTerm                 {} */
398     ;
399 
400 PackageList
401     :                               {$$ = NULL;}
402     | PackageElement
403     | PackageList ','               /* Allows a trailing comma at list end */
404     | PackageList ','
405         PackageElement              {$$ = TrLinkPeerOp ($1,$3);}
406     ;
407 
408 PackageElement
409     : DataObject                    {}
410     | NameString                    {}
411     ;
412 
413     /* Rules for specifying the type of one method argument or return value */
414 
415 ParameterTypePackage
416     :                               {$$ = NULL;}
417     | ObjectTypeKeyword             {$$ = $1;}
418     | ParameterTypePackage ','
419         ObjectTypeKeyword           {$$ = TrLinkPeerOps (2,$1,$3);}
420     ;
421 
422 ParameterTypePackageList
423     :                               {$$ = NULL;}
424     | ObjectTypeKeyword             {$$ = $1;}
425     | '{' ParameterTypePackage '}'  {$$ = $2;}
426     ;
427 
428 OptionalParameterTypePackage
429     :                               {$$ = TrCreateLeafOp (PARSEOP_DEFAULT_ARG);}
430     | ',' ParameterTypePackageList  {$$ = TrLinkOpChildren (
431                                         TrCreateLeafOp (PARSEOP_DEFAULT_ARG),1,$2);}
432     ;
433 
434     /* Rules for specifying the types for method arguments */
435 
436 ParameterTypesPackage
437     : ParameterTypePackageList      {$$ = $1;}
438     | ParameterTypesPackage ','
439         ParameterTypePackageList    {$$ = TrLinkPeerOps (2,$1,$3);}
440     ;
441 
442 ParameterTypesPackageList
443     :                               {$$ = NULL;}
444     | ObjectTypeKeyword             {$$ = $1;}
445     | '{' ParameterTypesPackage '}' {$$ = $2;}
446     ;
447 
448 OptionalParameterTypesPackage
449     :                               {$$ = TrCreateLeafOp (PARSEOP_DEFAULT_ARG);}
450     | ',' ParameterTypesPackageList {$$ = TrLinkOpChildren (
451                                         TrCreateLeafOp (PARSEOP_DEFAULT_ARG),1,$2);}
452     ;
453 
454 /*
455  * Case-Default list; allow only one Default term and unlimited Case terms
456  */
457 CaseDefaultTermList
458     :                               {$$ = NULL;}
459     | CaseTerm                      {}
460     | DefaultTerm                   {}
461     | CaseDefaultTermList
462         CaseTerm                    {$$ = TrLinkPeerOp ($1,$2);}
463     | CaseDefaultTermList
464         DefaultTerm                 {$$ = TrLinkPeerOp ($1,$2);}
465 
466 /* Original - attempts to force zero or one default term within the switch */
467 
468 /*
469 CaseDefaultTermList
470     :                               {$$ = NULL;}
471     | CaseTermList
472         DefaultTerm
473         CaseTermList                {$$ = TrLinkPeerOp ($1,TrLinkPeerOp ($2, $3));}
474     | CaseTermList
475         CaseTerm                    {$$ = TrLinkPeerOp ($1,$2);}
476     ;
477 
478 CaseTermList
479     :                               {$$ = NULL;}
480     | CaseTerm                      {}
481     | CaseTermList
482         CaseTerm                    {$$ = TrLinkPeerOp ($1,$2);}
483     ;
484 */
485 
486 
487 /*******************************************************************************
488  *
489  * ASL Data and Constant Terms
490  *
491  ******************************************************************************/
492 
493 DataObject
494     : BufferData                    {}
495     | PackageData                   {}
496     | IntegerData                   {}
497     | StringData                    {}
498     ;
499 
500 BufferData
501     : Type5Opcode                   {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);}
502     | Type2BufferOrStringOpcode     {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);}
503     | Type2BufferOpcode             {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);}
504     | BufferTerm                    {}
505     ;
506 
507 PackageData
508     : PackageTerm                   {}
509     ;
510 
511 IntegerData
512     : Type2IntegerOpcode            {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);}
513     | Type3Opcode                   {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);}
514     | Integer                       {}
515     | ConstTerm                     {}
516     ;
517 
518 StringData
519     : Type2StringOpcode             {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);}
520     | String                        {}
521     ;
522 
523 ByteConst
524     : Integer                       {$$ = TrSetOpIntegerValue (PARSEOP_BYTECONST, $1);}
525     ;
526 
527 WordConst
528     : Integer                       {$$ = TrSetOpIntegerValue (PARSEOP_WORDCONST, $1);}
529     ;
530 
531 DWordConst
532     : Integer                       {$$ = TrSetOpIntegerValue (PARSEOP_DWORDCONST, $1);}
533     ;
534 
535 QWordConst
536     : Integer                       {$$ = TrSetOpIntegerValue (PARSEOP_QWORDCONST, $1);}
537     ;
538 
539 /*
540  * The OP_COMPILE_TIME_CONST flag in the following constant expressions
541  * enables compile-time constant folding to reduce the Type3Opcodes/Type2IntegerOpcodes
542  * to simple integers. It is an error if these types of expressions cannot be
543  * reduced, since the AML grammar for ****ConstExpr requires a simple constant.
544  * Note: The required byte length of the constant is passed through to the
545  * constant folding code in the node AmlLength field.
546  */
547 ByteConstExpr
548     : Type3Opcode                   {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);
549                                         TrSetOpAmlLength ($1, 1);}
550     | Type2IntegerOpcode            {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);
551                                         TrSetOpAmlLength ($1, 1);}
552     | ConstExprTerm                 {$$ = TrSetOpIntegerValue (PARSEOP_BYTECONST, $1);}
553     | ByteConst                     {}
554     ;
555 
556 WordConstExpr
557     : Type3Opcode                   {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);
558                                         TrSetOpAmlLength ($1, 2);}
559     | Type2IntegerOpcode            {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);
560                                         TrSetOpAmlLength ($1, 2);}
561     | ConstExprTerm                 {$$ = TrSetOpIntegerValue (PARSEOP_WORDCONST, $1);}
562     | WordConst                     {}
563     ;
564 
565 DWordConstExpr
566     : Type3Opcode                   {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);
567                                         TrSetOpAmlLength ($1, 4);}
568     | Type2IntegerOpcode            {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);
569                                         TrSetOpAmlLength ($1, 4);}
570     | ConstExprTerm                 {$$ = TrSetOpIntegerValue (PARSEOP_DWORDCONST, $1);}
571     | DWordConst                    {}
572     ;
573 
574 QWordConstExpr
575     : Type3Opcode                   {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);
576                                         TrSetOpAmlLength ($1, 8);}
577     | Type2IntegerOpcode            {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);
578                                         TrSetOpAmlLength ($1, 8);}
579     | ConstExprTerm                 {$$ = TrSetOpIntegerValue (PARSEOP_QWORDCONST, $1);}
580     | QWordConst                    {}
581     ;
582 
583 ConstTerm
584     : ConstExprTerm                 {}
585     | PARSEOP_REVISION              {$$ = TrCreateLeafOp (PARSEOP_REVISION);}
586     ;
587 
588 ConstExprTerm
589     : PARSEOP_ZERO                  {$$ = TrCreateValuedLeafOp (PARSEOP_ZERO, 0);}
590     | PARSEOP_ONE                   {$$ = TrCreateValuedLeafOp (PARSEOP_ONE, 1);}
591     | PARSEOP_ONES                  {$$ = TrCreateValuedLeafOp (PARSEOP_ONES, ACPI_UINT64_MAX);}
592     | PARSEOP___DATE__              {$$ = TrCreateConstantLeafOp (PARSEOP___DATE__);}
593     | PARSEOP___FILE__              {$$ = TrCreateConstantLeafOp (PARSEOP___FILE__);}
594     | PARSEOP___LINE__              {$$ = TrCreateConstantLeafOp (PARSEOP___LINE__);}
595     | PARSEOP___PATH__              {$$ = TrCreateConstantLeafOp (PARSEOP___PATH__);}
596     | PARSEOP___METHOD__            {$$ = TrCreateConstantLeafOp (PARSEOP___METHOD__);}
597     ;
598 
599 Integer
600     : PARSEOP_INTEGER               {$$ = TrCreateValuedLeafOp (PARSEOP_INTEGER,
601                                         AslCompilerlval.i);}
602     ;
603 
604 String
605     : PARSEOP_STRING_LITERAL        {$$ = TrCreateValuedLeafOp (PARSEOP_STRING_LITERAL,
606                                         (ACPI_NATIVE_INT) AslCompilerlval.s);}
607     ;
608 
609 
610 /*******************************************************************************
611  *
612  * ASL Opcode Terms
613  *
614  ******************************************************************************/
615 
616 CompilerDirective
617     : IncludeTerm                   {}
618     | IncludeEndTerm                {}
619     | ExternalTerm                  {}
620     ;
621 
622 NamedObject
623     : BankFieldTerm                 {}
624     | CreateBitFieldTerm            {}
625     | CreateByteFieldTerm           {}
626     | CreateDWordFieldTerm          {}
627     | CreateFieldTerm               {}
628     | CreateQWordFieldTerm          {}
629     | CreateWordFieldTerm           {}
630     | DataRegionTerm                {}
631     | DeviceTerm                    {}
632     | EventTerm                     {}
633     | FieldTerm                     {}
634     | FunctionTerm                  {}
635     | IndexFieldTerm                {}
636     | MethodTerm                    {}
637     | MutexTerm                     {}
638     | OpRegionTerm                  {}
639     | PowerResTerm                  {}
640     | ProcessorTerm                 {}
641     | ThermalZoneTerm               {}
642     ;
643 
644 NameSpaceModifier
645     : AliasTerm                     {}
646     | NameTerm                      {}
647 /*    | NameTermAslPlus               {} */
648     | ScopeTerm                     {}
649     ;
650 
651 SimpleName
652     : NameString                    {}
653     | LocalTerm                     {}
654     | ArgTerm                       {}
655     ;
656 
657 /* For ObjectType(), SuperName except for MethodInvocationTerm */
658 
659 ObjectTypeSource
660     : SimpleName                    {}
661     | DebugTerm                     {}
662     | RefOfTerm                     {}
663     | DerefOfTerm                   {}
664     | IndexTerm                     {}
665     | IndexExpTerm                  {}
666     ;
667 
668 /* For DeRefOf(), SuperName except for DerefOf and Debug */
669 
670 DerefOfSource
671     : SimpleName                    {}
672     | RefOfTerm                     {}
673     | DerefOfTerm                   {}
674     | IndexTerm                     {}
675     | IndexExpTerm                  {}
676     | StoreTerm                     {}
677     | EqualsTerm                    {}
678     | MethodInvocationTerm          {}
679     ;
680 
681 /* For RefOf(), SuperName except for RefOf and MethodInvocationTerm */
682 
683 RefOfSource
684     : SimpleName                    {}
685     | DebugTerm                     {}
686     | DerefOfTerm                   {}
687     | IndexTerm                     {}
688     | IndexExpTerm                  {}
689     ;
690 
691 /* For CondRefOf(), SuperName except for RefOf and MethodInvocationTerm */
692 
693 CondRefOfSource
694     : SimpleName                    {}
695     | DebugTerm                     {}
696     | DerefOfTerm                   {}
697     | IndexTerm                     {}
698     | IndexExpTerm                  {}
699     ;
700 
701 /*
702  * Opcode types, as defined in the ACPI specification
703  */
704 Type1Opcode
705     : BreakTerm                     {}
706     | BreakPointTerm                {}
707     | ContinueTerm                  {}
708     | FatalTerm                     {}
709     | ForTerm                       {}
710     | ElseIfTerm                    {}
711     | LoadTerm                      {}
712     | NoOpTerm                      {}
713     | NotifyTerm                    {}
714     | ReleaseTerm                   {}
715     | ResetTerm                     {}
716     | ReturnTerm                    {}
717     | SignalTerm                    {}
718     | SleepTerm                     {}
719     | StallTerm                     {}
720     | SwitchTerm                    {}
721     | UnloadTerm                    {}
722     | WhileTerm                     {}
723     ;
724 
725 Type2Opcode
726     : AcquireTerm                   {}
727     | CondRefOfTerm                 {}
728     | CopyObjectTerm                {}
729     | DerefOfTerm                   {}
730     | ObjectTypeTerm                {}
731     | RefOfTerm                     {}
732     | SizeOfTerm                    {}
733     | StoreTerm                     {}
734     | EqualsTerm                    {}
735     | TimerTerm                     {}
736     | WaitTerm                      {}
737     | MethodInvocationTerm          {}
738     ;
739 
740 /*
741  * Type 3/4/5 opcodes
742  */
743 Type2IntegerOpcode                  /* "Type3" opcodes */
744     : Expression                    {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);}
745     | AddTerm                       {}
746     | AndTerm                       {}
747     | DecTerm                       {}
748     | DivideTerm                    {}
749     | FindSetLeftBitTerm            {}
750     | FindSetRightBitTerm           {}
751     | FromBCDTerm                   {}
752     | IncTerm                       {}
753     | IndexTerm                     {}
754 /*    | StructureIndexTerm            {} */
755 /*    | StructurePointerTerm          {} */
756     | LAndTerm                      {}
757     | LEqualTerm                    {}
758     | LGreaterTerm                  {}
759     | LGreaterEqualTerm             {}
760     | LLessTerm                     {}
761     | LLessEqualTerm                {}
762     | LNotTerm                      {}
763     | LNotEqualTerm                 {}
764     | LoadTableTerm                 {}
765     | LOrTerm                       {}
766     | MatchTerm                     {}
767     | ModTerm                       {}
768     | MultiplyTerm                  {}
769     | NAndTerm                      {}
770     | NOrTerm                       {}
771     | NotTerm                       {}
772     | OrTerm                        {}
773     | ShiftLeftTerm                 {}
774     | ShiftRightTerm                {}
775     | SubtractTerm                  {}
776     | ToBCDTerm                     {}
777     | ToIntegerTerm                 {}
778     | XOrTerm                       {}
779     ;
780 
781 Type2StringOpcode                   /* "Type4" Opcodes */
782     : ToDecimalStringTerm           {}
783     | ToHexStringTerm               {}
784     | ToStringTerm                  {}
785     ;
786 
787 Type2BufferOpcode                   /* "Type5" Opcodes */
788     : ToBufferTerm                  {}
789     | ConcatResTerm                 {}
790     ;
791 
792 Type2BufferOrStringOpcode
793     : ConcatTerm                    {$$ = TrSetOpFlags ($1, OP_COMPILE_TIME_CONST);}
794     | PrintfTerm                    {}
795     | FprintfTerm                   {}
796     | MidTerm                       {}
797     ;
798 
799 /*
800  * A type 3 opcode evaluates to an Integer and cannot have a destination operand
801  */
802 Type3Opcode
803     : EISAIDTerm                    {}
804     ;
805 
806 /* Obsolete
807 Type4Opcode
808     : ConcatTerm                    {}
809     | ToDecimalStringTerm           {}
810     | ToHexStringTerm               {}
811     | MidTerm                       {}
812     | ToStringTerm                  {}
813     ;
814 */
815 
816 /* Type 5 opcodes are a subset of Type2 opcodes, and return a constant */
817 
818 Type5Opcode
819     : ResourceTemplateTerm          {}
820     | UnicodeTerm                   {}
821     | ToPLDTerm                     {}
822     | ToUUIDTerm                    {}
823     ;
824 
825 Type6Opcode
826     : RefOfTerm                     {}
827     | DerefOfTerm                   {}
828     | IndexTerm                     {}
829     | IndexExpTerm                  {}
830 /*    | StructureIndexTerm            {} */
831 /*    | StructurePointerTerm          {} */
832     | MethodInvocationTerm          {}
833     ;
834 
835 
836 /*******************************************************************************
837  *
838  * ASL Helper Terms
839  *
840  ******************************************************************************/
841 
842 AmlPackageLengthTerm
843     : Integer                       {$$ = TrSetOpIntegerValue (PARSEOP_PACKAGE_LENGTH,
844                                         (ACPI_PARSE_OBJECT *) $1);}
845     ;
846 
847 NameStringItem
848     : ',' NameString                {$$ = $2;}
849     | ',' error                     {$$ = AslDoError (); yyclearin;}
850     ;
851 
852 TermArgItem
853     : ',' TermArg                   {$$ = $2;}
854     | ',' error                     {$$ = AslDoError (); yyclearin;}
855     ;
856 
857 OptionalReference
858     :                               {$$ = TrCreateLeafOp (PARSEOP_ZERO);}       /* Placeholder is a ZeroOp object */
859     | ','                           {$$ = TrCreateLeafOp (PARSEOP_ZERO);}       /* Placeholder is a ZeroOp object */
860     | ',' TermArg                   {$$ = $2;}
861     ;
862 
863 OptionalReturnArg
864     :                               {$$ = TrSetOpFlags (TrCreateLeafOp (PARSEOP_ZERO),
865                                             OP_IS_NULL_RETURN);}       /* Placeholder is a ZeroOp object */
866     | TermArg                       {$$ = $1;}
867     ;
868 
869 OptionalSerializeRuleKeyword
870     :                               {$$ = NULL;}
871     | ','                           {$$ = NULL;}
872     | ',' SerializeRuleKeyword      {$$ = $2;}
873     ;
874 
875 OptionalTermArg
876     :                               {$$ = TrCreateLeafOp (PARSEOP_DEFAULT_ARG);}
877     | TermArg                       {$$ = $1;}
878     ;
879 
880 OptionalWordConst
881     :                               {$$ = NULL;}
882     | WordConst                     {$$ = $1;}
883     ;
884