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 - 2017, 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>$ = TrLinkChildren (
169                                         TrCreateLeafNode (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>$ = TrCreateLeafNode (PARSEOP_DEFINITION_BLOCK); COMMENT_CAPTURE_OFF;}
196         String ','
197         String ','
198         ByteConst ','
199         String ','
200         String ','
201         DWordConst
202         PARSEOP_CLOSE_PAREN         {TrSetEndLineNumber ($<n>3); COMMENT_CAPTURE_ON;}
203             '{' TermList '}'        {$$ = TrLinkChildren ($<n>3,7,
204                                         $4,$6,$8,$10,$12,$14,$18);}
205     ;
206 
207 DefinitionBlockList
208     : DefinitionBlockTerm
209     | DefinitionBlockTerm
210         DefinitionBlockList         {$$ = TrLinkPeerNodes (2, $1,$2);}
211     ;
212 
213 
214 /******* Basic ASCII identifiers **************************************************/
215 
216 /* Allow IO, DMA, IRQ Resource macro and FOR macro names to also be used as identifiers */
217 
218 NameString
219     : NameSeg                       {}
220     | PARSEOP_NAMESTRING            {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) $1);}
221     | PARSEOP_IO                    {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "IO");}
222     | PARSEOP_DMA                   {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "DMA");}
223     | PARSEOP_IRQ                   {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "IRQ");}
224     | PARSEOP_FOR                   {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "FOR");}
225     ;
226 /*
227 NameSeg
228     : PARSEOP_NAMESEG               {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESEG, (ACPI_NATIVE_INT)
229                                         TrNormalizeNameSeg ($1));}
230     ;
231 */
232 
233 NameSeg
234     : PARSEOP_NAMESEG               {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESEG,
235                                         (ACPI_NATIVE_INT) AslCompilerlval.s);}
236     ;
237 
238 
239 /******* Fundamental argument/statement types ***********************************/
240 
241 Term
242     : Object                        {}
243     | Type1Opcode                   {}
244     | Type2Opcode                   {}
245     | Type2IntegerOpcode            {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
246     | Type2StringOpcode             {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
247     | Type2BufferOpcode             {}
248     | Type2BufferOrStringOpcode     {}
249     | error                         {$$ = AslDoError(); yyclearin;}
250     ;
251 
252 SuperName
253     : SimpleName                    {}
254     | DebugTerm                     {}
255     | Type6Opcode                   {}
256     ;
257 
258 Target
259     :                               {$$ = TrCreateNullTarget ();} /* Placeholder is a ZeroOp object */
260     | ','                           {$$ = TrCreateNullTarget ();} /* Placeholder is a ZeroOp object */
261     | ',' SuperName                 {$$ = TrSetNodeFlags ($2, NODE_IS_TARGET);}
262     ;
263 
264 RequiredTarget
265     : ',' SuperName                 {$$ = TrSetNodeFlags ($2, NODE_IS_TARGET);}
266     ;
267 
268 TermArg
269     : SimpleName                    {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
270     | Type2Opcode                   {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
271     | DataObject                    {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
272 /*
273     | PARSEOP_OPEN_PAREN
274         TermArg
275         PARSEOP_CLOSE_PAREN         {}
276 */
277     ;
278 
279 /*
280  NOTE: Removed from TermArg due to reduce/reduce conflicts:
281     | Type2IntegerOpcode            {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
282     | Type2StringOpcode             {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
283     | Type2BufferOpcode             {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
284     | Type2BufferOrStringOpcode     {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);}
285 
286 */
287 
288 MethodInvocationTerm
289     : NameString
290         PARSEOP_OPEN_PAREN          {TrUpdateNode (PARSEOP_METHODCALL, $1); COMMENT_CAPTURE_OFF;}
291         ArgList
292         PARSEOP_CLOSE_PAREN         {$$ = TrLinkChildNode ($1,$4); COMMENT_CAPTURE_ON;}
293     ;
294 
295 /* OptionalCount must appear before ByteList or an incorrect reduction will result */
296 
297 OptionalCount
298     :                               {$$ = TrCreateLeafNode (PARSEOP_ONES);}       /* Placeholder is a OnesOp object */
299     | ','                           {$$ = TrCreateLeafNode (PARSEOP_ONES);}       /* Placeholder is a OnesOp object */
300     | ',' TermArg                   {$$ = $2;}
301     ;
302 
303 /*
304  * Data count for buffers and packages (byte count for buffers,
305  * element count for packages).
306  */
307 OptionalDataCount
308 
309         /* Legacy ASL */
310     :                               {$$ = NULL;}
311     | PARSEOP_OPEN_PAREN
312         TermArg
313         PARSEOP_CLOSE_PAREN         {$$ = $2;}
314     | PARSEOP_OPEN_PAREN
315         PARSEOP_CLOSE_PAREN         {$$ = NULL;}
316 
317         /* C-style (ASL+) -- adds equals term */
318 
319     |  PARSEOP_EXP_EQUALS           {$$ = NULL;}
320 
321     | PARSEOP_OPEN_PAREN
322         TermArg
323         PARSEOP_CLOSE_PAREN
324         PARSEOP_EXP_EQUALS          {$$ = $2;}
325 
326     | PARSEOP_OPEN_PAREN
327         PARSEOP_CLOSE_PAREN
328         String
329         PARSEOP_EXP_EQUALS          {$$ = NULL;}
330     ;
331 
332 
333 /******* List Terms **************************************************/
334 
335     /* ACPI 3.0 -- allow semicolons between terms */
336 
337 TermList
338     :                               {$$ = NULL;}
339     | TermList Term                 {$$ = TrLinkPeerNode (
340                                         TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$2);}
341     | TermList Term ';'             {$$ = TrLinkPeerNode (
342                                         TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$2);}
343     | TermList ';' Term             {$$ = TrLinkPeerNode (
344                                         TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$3);}
345     | TermList ';' Term ';'         {$$ = TrLinkPeerNode (
346                                         TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$3);}
347     ;
348 
349 ArgList
350     :                               {$$ = NULL;}
351     | TermArg
352     | ArgList ','                   /* Allows a trailing comma at list end */
353     | ArgList ','
354         TermArg                     {$$ = TrLinkPeerNode ($1,$3);}
355     ;
356 
357 ByteList
358     :                               {$$ = NULL;}
359     | ByteConstExpr
360     | ByteList ','                  /* Allows a trailing comma at list end */
361     | ByteList ','
362         ByteConstExpr               {$$ = TrLinkPeerNode ($1,$3);}
363     ;
364 
365 DWordList
366     :                               {$$ = NULL;}
367     | DWordConstExpr
368     | DWordList ','                 /* Allows a trailing comma at list end */
369     | DWordList ','
370         DWordConstExpr              {$$ = TrLinkPeerNode ($1,$3);}
371     ;
372 
373 FieldUnitList
374     :                               {$$ = NULL;}
375     | FieldUnit
376     | FieldUnitList ','             /* Allows a trailing comma at list end */
377     | FieldUnitList ','
378         FieldUnit                   {$$ = TrLinkPeerNode ($1,$3);}
379     ;
380 
381 FieldUnit
382     : FieldUnitEntry                {}
383     | OffsetTerm                    {}
384     | AccessAsTerm                  {}
385     | ConnectionTerm                {}
386     ;
387 
388 FieldUnitEntry
389     : ',' AmlPackageLengthTerm      {$$ = TrCreateNode (PARSEOP_RESERVED_BYTES,1,$2);}
390     | NameSeg ','
391         AmlPackageLengthTerm        {$$ = TrLinkChildNode ($1,$3);}
392     ;
393 
394 Object
395     : CompilerDirective             {}
396     | NamedObject                   {}
397     | NameSpaceModifier             {}
398 //    | StructureTerm                 {}
399     ;
400 
401 PackageList
402     :                               {$$ = NULL;}
403     | PackageElement
404     | PackageList ','               /* Allows a trailing comma at list end */
405     | PackageList ','
406         PackageElement              {$$ = TrLinkPeerNode ($1,$3);}
407     ;
408 
409 PackageElement
410     : DataObject                    {}
411     | NameString                    {}
412     ;
413 
414     /* Rules for specifying the type of one method argument or return value */
415 
416 ParameterTypePackage
417     :                               {$$ = NULL;}
418     | ObjectTypeKeyword             {$$ = $1;}
419     | ParameterTypePackage ','
420         ObjectTypeKeyword           {$$ = TrLinkPeerNodes (2,$1,$3);}
421     ;
422 
423 ParameterTypePackageList
424     :                               {$$ = NULL;}
425     | ObjectTypeKeyword             {$$ = $1;}
426     | '{' ParameterTypePackage '}'  {$$ = $2;}
427     ;
428 
429 OptionalParameterTypePackage
430     :                               {$$ = TrCreateLeafNode (PARSEOP_DEFAULT_ARG);}
431     | ',' ParameterTypePackageList  {$$ = TrLinkChildren (
432                                         TrCreateLeafNode (PARSEOP_DEFAULT_ARG),1,$2);}
433     ;
434 
435     /* Rules for specifying the types for method arguments */
436 
437 ParameterTypesPackage
438     : ParameterTypePackageList      {$$ = $1;}
439     | ParameterTypesPackage ','
440         ParameterTypePackageList    {$$ = TrLinkPeerNodes (2,$1,$3);}
441     ;
442 
443 ParameterTypesPackageList
444     :                               {$$ = NULL;}
445     | ObjectTypeKeyword             {$$ = $1;}
446     | '{' ParameterTypesPackage '}' {$$ = $2;}
447     ;
448 
449 OptionalParameterTypesPackage
450     :                               {$$ = TrCreateLeafNode (PARSEOP_DEFAULT_ARG);}
451     | ',' ParameterTypesPackageList {$$ = TrLinkChildren (
452                                         TrCreateLeafNode (PARSEOP_DEFAULT_ARG),1,$2);}
453     ;
454 
455 /*
456  * Case-Default list; allow only one Default term and unlimited Case terms
457  */
458 CaseDefaultTermList
459     :                               {$$ = NULL;}
460     | CaseTerm                      {}
461     | DefaultTerm                   {}
462     | CaseDefaultTermList
463         CaseTerm                    {$$ = TrLinkPeerNode ($1,$2);}
464     | CaseDefaultTermList
465         DefaultTerm                 {$$ = TrLinkPeerNode ($1,$2);}
466 
467 /* Original - attempts to force zero or one default term within the switch */
468 
469 /*
470 CaseDefaultTermList
471     :                               {$$ = NULL;}
472     | CaseTermList
473         DefaultTerm
474         CaseTermList                {$$ = TrLinkPeerNode ($1,TrLinkPeerNode ($2, $3));}
475     | CaseTermList
476         CaseTerm                    {$$ = TrLinkPeerNode ($1,$2);}
477     ;
478 
479 CaseTermList
480     :                               {$$ = NULL;}
481     | CaseTerm                      {}
482     | CaseTermList
483         CaseTerm                    {$$ = TrLinkPeerNode ($1,$2);}
484     ;
485 */
486 
487 
488 /*******************************************************************************
489  *
490  * ASL Data and Constant Terms
491  *
492  ******************************************************************************/
493 
494 DataObject
495     : BufferData                    {}
496     | PackageData                   {}
497     | IntegerData                   {}
498     | StringData                    {}
499     ;
500 
501 BufferData
502     : Type5Opcode                   {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
503     | Type2BufferOrStringOpcode     {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
504     | Type2BufferOpcode             {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
505     | BufferTerm                    {}
506     ;
507 
508 PackageData
509     : PackageTerm                   {}
510     ;
511 
512 IntegerData
513     : Type2IntegerOpcode            {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
514     | Type3Opcode                   {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
515     | Integer                       {}
516     | ConstTerm                     {}
517     ;
518 
519 StringData
520     : Type2StringOpcode             {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);}
521     | String                        {}
522     ;
523 
524 ByteConst
525     : Integer                       {$$ = TrUpdateNode (PARSEOP_BYTECONST, $1);}
526     ;
527 
528 WordConst
529     : Integer                       {$$ = TrUpdateNode (PARSEOP_WORDCONST, $1);}
530     ;
531 
532 DWordConst
533     : Integer                       {$$ = TrUpdateNode (PARSEOP_DWORDCONST, $1);}
534     ;
535 
536 QWordConst
537     : Integer                       {$$ = TrUpdateNode (PARSEOP_QWORDCONST, $1);}
538     ;
539 
540 /*
541  * The NODE_COMPILE_TIME_CONST flag in the following constant expressions
542  * enables compile-time constant folding to reduce the Type3Opcodes/Type2IntegerOpcodes
543  * to simple integers. It is an error if these types of expressions cannot be
544  * reduced, since the AML grammar for ****ConstExpr requires a simple constant.
545  * Note: The required byte length of the constant is passed through to the
546  * constant folding code in the node AmlLength field.
547  */
548 ByteConstExpr
549     : Type3Opcode                   {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
550                                         TrSetNodeAmlLength ($1, 1);}
551     | Type2IntegerOpcode            {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
552                                         TrSetNodeAmlLength ($1, 1);}
553     | ConstExprTerm                 {$$ = TrUpdateNode (PARSEOP_BYTECONST, $1);}
554     | ByteConst                     {}
555     ;
556 
557 WordConstExpr
558     : Type3Opcode                   {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
559                                         TrSetNodeAmlLength ($1, 2);}
560     | Type2IntegerOpcode            {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
561                                         TrSetNodeAmlLength ($1, 2);}
562     | ConstExprTerm                 {$$ = TrUpdateNode (PARSEOP_WORDCONST, $1);}
563     | WordConst                     {}
564     ;
565 
566 DWordConstExpr
567     : Type3Opcode                   {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
568                                         TrSetNodeAmlLength ($1, 4);}
569     | Type2IntegerOpcode            {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
570                                         TrSetNodeAmlLength ($1, 4);}
571     | ConstExprTerm                 {$$ = TrUpdateNode (PARSEOP_DWORDCONST, $1);}
572     | DWordConst                    {}
573     ;
574 
575 QWordConstExpr
576     : Type3Opcode                   {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
577                                         TrSetNodeAmlLength ($1, 8);}
578     | Type2IntegerOpcode            {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);
579                                         TrSetNodeAmlLength ($1, 8);}
580     | ConstExprTerm                 {$$ = TrUpdateNode (PARSEOP_QWORDCONST, $1);}
581     | QWordConst                    {}
582     ;
583 
584 ConstTerm
585     : ConstExprTerm                 {}
586     | PARSEOP_REVISION              {$$ = TrCreateLeafNode (PARSEOP_REVISION);}
587     ;
588 
589 ConstExprTerm
590     : PARSEOP_ZERO                  {$$ = TrCreateValuedLeafNode (PARSEOP_ZERO, 0);}
591     | PARSEOP_ONE                   {$$ = TrCreateValuedLeafNode (PARSEOP_ONE, 1);}
592     | PARSEOP_ONES                  {$$ = TrCreateValuedLeafNode (PARSEOP_ONES, ACPI_UINT64_MAX);}
593     | PARSEOP___DATE__              {$$ = TrCreateConstantLeafNode (PARSEOP___DATE__);}
594     | PARSEOP___FILE__              {$$ = TrCreateConstantLeafNode (PARSEOP___FILE__);}
595     | PARSEOP___LINE__              {$$ = TrCreateConstantLeafNode (PARSEOP___LINE__);}
596     | PARSEOP___PATH__              {$$ = TrCreateConstantLeafNode (PARSEOP___PATH__);}
597     ;
598 
599 Integer
600     : PARSEOP_INTEGER               {$$ = TrCreateValuedLeafNode (PARSEOP_INTEGER,
601                                         AslCompilerlval.i);}
602     ;
603 
604 String
605     : PARSEOP_STRING_LITERAL        {$$ = TrCreateValuedLeafNode (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                    {$$ = TrSetNodeFlags ($1, NODE_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                    {$$ = TrSetNodeFlags ($1, NODE_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                       {$$ = TrUpdateNode (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     :                               {$$ = TrCreateLeafNode (PARSEOP_ZERO);}       /* Placeholder is a ZeroOp object */
859     | ','                           {$$ = TrCreateLeafNode (PARSEOP_ZERO);}       /* Placeholder is a ZeroOp object */
860     | ',' TermArg                   {$$ = $2;}
861     ;
862 
863 OptionalReturnArg
864     :                               {$$ = TrSetNodeFlags (TrCreateLeafNode (PARSEOP_ZERO),
865                                             NODE_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     :                               {$$ = TrCreateLeafNode (PARSEOP_DEFAULT_ARG);}
877     | TermArg                       {$$ = $1;}
878     ;
879 
880 OptionalWordConst
881     :                               {$$ = NULL;}
882     | WordConst                     {$$ = $1;}
883     ;
884