1 /******************************************************************************
3 * Module Name: asltransform - Parse tree transforms
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "aslcompiler.h"
153 #include "aslcompiler.y.h"
155 #define _COMPONENT ACPI_COMPILER
156 ACPI_MODULE_NAME ("asltransform")
158 /* Local prototypes */
162 ACPI_PARSE_OBJECT
*Op
);
165 TrAmlGetNextTempName (
166 ACPI_PARSE_OBJECT
*Op
,
170 TrAmlInitLineNumbers (
171 ACPI_PARSE_OBJECT
*Op
,
172 ACPI_PARSE_OBJECT
*Neighbor
);
176 ACPI_PARSE_OBJECT
*Op
,
180 TrAmlSetSubtreeParent (
181 ACPI_PARSE_OBJECT
*Op
,
182 ACPI_PARSE_OBJECT
*Parent
);
186 ACPI_PARSE_OBJECT
*Op
,
187 ACPI_PARSE_OBJECT
*NewPeer
);
190 TrDoDefinitionBlock (
191 ACPI_PARSE_OBJECT
*Op
);
195 ACPI_PARSE_OBJECT
*StartNode
);
198 /*******************************************************************************
200 * FUNCTION: TrAmlGetNextTempName
202 * PARAMETERS: Op - Current parse op
203 * TempCount - Current temporary counter. Was originally
204 * per-module; Currently per method, could be
205 * expanded to per-scope.
207 * RETURN: A pointer to name (allocated here).
209 * DESCRIPTION: Generate an ACPI name of the form _T_x. These names are
210 * reserved for use by the ASL compiler. (_T_0 through _T_Z)
212 ******************************************************************************/
215 TrAmlGetNextTempName (
216 ACPI_PARSE_OBJECT
*Op
,
222 if (*TempCount
>= (10 + 26)) /* 0-35 valid: 0-9 and A-Z for TempName[3] */
226 AslError (ASL_ERROR
, ASL_MSG_TOO_MANY_TEMPS
, Op
, NULL
);
230 TempName
= UtLocalCalloc (5);
232 if (*TempCount
< 10) /* 0-9 */
234 TempName
[3] = (char) (*TempCount
+ '0');
236 else /* 10-35: A-Z */
238 TempName
[3] = (char) (*TempCount
+ ('A' - 10));
243 /* First three characters are always "_T_" */
253 /*******************************************************************************
255 * FUNCTION: TrAmlInitLineNumbers
257 * PARAMETERS: Op - Op to be initialized
258 * Neighbor - Op used for initialization values
262 * DESCRIPTION: Initialized the various line numbers for a parse node.
264 ******************************************************************************/
267 TrAmlInitLineNumbers (
268 ACPI_PARSE_OBJECT
*Op
,
269 ACPI_PARSE_OBJECT
*Neighbor
)
272 Op
->Asl
.EndLine
= Neighbor
->Asl
.EndLine
;
273 Op
->Asl
.EndLogicalLine
= Neighbor
->Asl
.EndLogicalLine
;
274 Op
->Asl
.LineNumber
= Neighbor
->Asl
.LineNumber
;
275 Op
->Asl
.LogicalByteOffset
= Neighbor
->Asl
.LogicalByteOffset
;
276 Op
->Asl
.LogicalLineNumber
= Neighbor
->Asl
.LogicalLineNumber
;
280 /*******************************************************************************
282 * FUNCTION: TrAmlInitNode
284 * PARAMETERS: Op - Op to be initialized
285 * ParseOpcode - Opcode for this node
289 * DESCRIPTION: Initialize a node with the parse opcode and opcode name.
291 ******************************************************************************/
295 ACPI_PARSE_OBJECT
*Op
,
299 Op
->Asl
.ParseOpcode
= ParseOpcode
;
300 UtSetParseOpName (Op
);
304 /*******************************************************************************
306 * FUNCTION: TrAmlSetSubtreeParent
308 * PARAMETERS: Op - First node in a list of peer nodes
309 * Parent - Parent of the subtree
313 * DESCRIPTION: Set the parent for all peer nodes in a subtree
315 ******************************************************************************/
318 TrAmlSetSubtreeParent (
319 ACPI_PARSE_OBJECT
*Op
,
320 ACPI_PARSE_OBJECT
*Parent
)
322 ACPI_PARSE_OBJECT
*Next
;
328 Next
->Asl
.Parent
= Parent
;
329 Next
= Next
->Asl
.Next
;
334 /*******************************************************************************
336 * FUNCTION: TrAmlInsertPeer
338 * PARAMETERS: Op - First node in a list of peer nodes
339 * NewPeer - Peer node to insert
343 * DESCRIPTION: Insert a new peer node into a list of peers.
345 ******************************************************************************/
349 ACPI_PARSE_OBJECT
*Op
,
350 ACPI_PARSE_OBJECT
*NewPeer
)
353 NewPeer
->Asl
.Next
= Op
->Asl
.Next
;
354 Op
->Asl
.Next
= NewPeer
;
358 /*******************************************************************************
360 * FUNCTION: TrAmlTransformWalkBegin
362 * PARAMETERS: ASL_WALK_CALLBACK
366 * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
369 ******************************************************************************/
372 TrAmlTransformWalkBegin (
373 ACPI_PARSE_OBJECT
*Op
,
378 TrTransformSubtree (Op
);
383 /*******************************************************************************
385 * FUNCTION: TrAmlTransformWalkEnd
387 * PARAMETERS: ASL_WALK_CALLBACK
391 * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
394 ******************************************************************************/
397 TrAmlTransformWalkEnd (
398 ACPI_PARSE_OBJECT
*Op
,
403 /* Save possible Externals list in the DefintionBlock Op */
405 if (Op
->Asl
.ParseOpcode
== PARSEOP_DEFINITION_BLOCK
)
407 Op
->Asl
.Value
.Arg
= AslGbl_ExternalsListHead
;
408 AslGbl_ExternalsListHead
= NULL
;
415 /*******************************************************************************
417 * FUNCTION: TrTransformSubtree
419 * PARAMETERS: Op - The parent parse node
423 * DESCRIPTION: Prepare nodes to be output as AML data and operands. The more
424 * complex AML opcodes require processing of the child nodes
425 * (arguments/operands).
427 ******************************************************************************/
431 ACPI_PARSE_OBJECT
*Op
)
433 ACPI_PARSE_OBJECT
*MethodOp
;
436 if (Op
->Asl
.AmlOpcode
== AML_RAW_DATA_BYTE
)
441 switch (Op
->Asl
.ParseOpcode
)
443 case PARSEOP_DEFINITION_BLOCK
:
445 TrDoDefinitionBlock (Op
);
455 * TBD: Zero the tempname (_T_x) count. Probably shouldn't be a global,
458 AslGbl_TempCount
= 0;
461 case PARSEOP_EXTERNAL
:
463 if (AslGbl_DoExternals
== TRUE
)
470 case PARSEOP___METHOD__
:
472 /* Transform to a string op containing the parent method name */
474 Op
->Asl
.ParseOpcode
= PARSEOP_STRING_LITERAL
;
475 UtSetParseOpName (Op
);
477 /* Find the parent control method op */
482 if (MethodOp
->Asl
.ParseOpcode
== PARSEOP_METHOD
)
484 /* First child contains the method name */
486 MethodOp
= MethodOp
->Asl
.Child
;
487 Op
->Asl
.Value
.String
= MethodOp
->Asl
.Value
.String
;
491 MethodOp
= MethodOp
->Asl
.Parent
;
494 /* At the root, invocation not within a control method */
496 Op
->Asl
.Value
.String
= "\\";
501 AslError (ASL_WARNING
, ASL_MSG_UNLOAD
, Op
, NULL
);
506 /* Nothing to do here for other opcodes */
513 /*******************************************************************************
515 * FUNCTION: TrDoDefinitionBlock
517 * PARAMETERS: Op - Parse node
521 * DESCRIPTION: Find the end of the definition block and set a global to this
522 * node. It is used by the compiler to insert compiler-generated
523 * names at the root level of the namespace.
525 ******************************************************************************/
528 TrDoDefinitionBlock (
529 ACPI_PARSE_OBJECT
*Op
)
531 ACPI_PARSE_OBJECT
*Next
;
535 /* Reset external list when starting a definition block */
537 AslGbl_ExternalsListHead
= NULL
;
539 Next
= Op
->Asl
.Child
;
540 for (i
= 0; i
< 5; i
++)
542 Next
= Next
->Asl
.Next
;
546 * This is the table signature. Only the DSDT can be assumed
547 * to be at the root of the namespace; Therefore, namepath
548 * optimization can only be performed on the DSDT.
550 if (!ACPI_COMPARE_NAME (Next
->Asl
.Value
.String
, ACPI_SIG_DSDT
))
552 AslGbl_ReferenceOptimizationFlag
= FALSE
;
557 AslGbl_FirstLevelInsertionNode
= Next
;
561 /*******************************************************************************
563 * FUNCTION: TrDoSwitch
565 * PARAMETERS: StartNode - Parse node for SWITCH
569 * DESCRIPTION: Translate ASL SWITCH statement to if/else pairs. There is
570 * no actual AML opcode for SWITCH -- it must be simulated.
572 ******************************************************************************/
576 ACPI_PARSE_OBJECT
*StartNode
)
578 ACPI_PARSE_OBJECT
*Next
;
579 ACPI_PARSE_OBJECT
*CaseOp
= NULL
;
580 ACPI_PARSE_OBJECT
*CaseBlock
= NULL
;
581 ACPI_PARSE_OBJECT
*DefaultOp
= NULL
;
582 ACPI_PARSE_OBJECT
*CurrentParentNode
;
583 ACPI_PARSE_OBJECT
*Conditional
= NULL
;
584 ACPI_PARSE_OBJECT
*Predicate
;
585 ACPI_PARSE_OBJECT
*Peer
;
586 ACPI_PARSE_OBJECT
*NewOp
;
587 ACPI_PARSE_OBJECT
*NewOp2
;
588 ACPI_PARSE_OBJECT
*MethodOp
;
589 ACPI_PARSE_OBJECT
*StoreOp
;
590 ACPI_PARSE_OBJECT
*BreakOp
;
591 ACPI_PARSE_OBJECT
*BufferOp
;
592 char *PredicateValueName
;
597 /* Start node is the Switch() node */
599 CurrentParentNode
= StartNode
;
601 /* Create a new temp name of the form _T_x */
603 PredicateValueName
= TrAmlGetNextTempName (StartNode
, &AslGbl_TempCount
);
604 if (!PredicateValueName
)
609 /* First child is the Switch() predicate */
611 Next
= StartNode
->Asl
.Child
;
614 * Examine the return type of the Switch Value -
615 * must be Integer/Buffer/String
617 Index
= (UINT16
) (Next
->Asl
.ParseOpcode
- ASL_PARSE_OPCODE_BASE
);
618 Btype
= AslKeywordMapping
[Index
].AcpiBtype
;
619 if ((Btype
!= ACPI_BTYPE_INTEGER
) &&
620 (Btype
!= ACPI_BTYPE_STRING
) &&
621 (Btype
!= ACPI_BTYPE_BUFFER
))
623 AslError (ASL_WARNING
, ASL_MSG_SWITCH_TYPE
, Next
, NULL
);
624 Btype
= ACPI_BTYPE_INTEGER
;
627 /* CASE statements start at next child */
629 Peer
= Next
->Asl
.Next
;
633 Peer
= Next
->Asl
.Next
;
635 if (Next
->Asl
.ParseOpcode
== PARSEOP_CASE
)
639 /* Add an ELSE to complete the previous CASE */
641 NewOp
= TrCreateLeafOp (PARSEOP_ELSE
);
642 NewOp
->Asl
.Parent
= Conditional
->Asl
.Parent
;
643 TrAmlInitLineNumbers (NewOp
, NewOp
->Asl
.Parent
);
645 /* Link ELSE node as a peer to the previous IF */
647 TrAmlInsertPeer (Conditional
, NewOp
);
648 CurrentParentNode
= NewOp
;
652 Conditional
= CaseOp
;
653 CaseBlock
= CaseOp
->Asl
.Child
->Asl
.Next
;
654 Conditional
->Asl
.Child
->Asl
.Next
= NULL
;
655 Predicate
= CaseOp
->Asl
.Child
;
657 if ((Predicate
->Asl
.ParseOpcode
== PARSEOP_PACKAGE
) ||
658 (Predicate
->Asl
.ParseOpcode
== PARSEOP_VAR_PACKAGE
))
661 * Convert the package declaration to this form:
663 * If (LNotEqual (Match (Package(<size>){<data>},
664 * MEQ, _T_x, MTR, Zero, Zero), Ones))
666 NewOp2
= TrCreateLeafOp (PARSEOP_MATCHTYPE_MEQ
);
667 Predicate
->Asl
.Next
= NewOp2
;
668 TrAmlInitLineNumbers (NewOp2
, Conditional
);
671 NewOp2
= TrCreateValuedLeafOp (PARSEOP_NAMESTRING
,
672 (UINT64
) ACPI_TO_INTEGER (PredicateValueName
));
673 NewOp
->Asl
.Next
= NewOp2
;
674 TrAmlInitLineNumbers (NewOp2
, Predicate
);
677 NewOp2
= TrCreateLeafOp (PARSEOP_MATCHTYPE_MTR
);
678 NewOp
->Asl
.Next
= NewOp2
;
679 TrAmlInitLineNumbers (NewOp2
, Predicate
);
682 NewOp2
= TrCreateLeafOp (PARSEOP_ZERO
);
683 NewOp
->Asl
.Next
= NewOp2
;
684 TrAmlInitLineNumbers (NewOp2
, Predicate
);
687 NewOp2
= TrCreateLeafOp (PARSEOP_ZERO
);
688 NewOp
->Asl
.Next
= NewOp2
;
689 TrAmlInitLineNumbers (NewOp2
, Predicate
);
691 NewOp2
= TrCreateLeafOp (PARSEOP_MATCH
);
692 NewOp2
->Asl
.Child
= Predicate
; /* PARSEOP_PACKAGE */
693 TrAmlInitLineNumbers (NewOp2
, Conditional
);
694 TrAmlSetSubtreeParent (Predicate
, NewOp2
);
697 NewOp2
= TrCreateLeafOp (PARSEOP_ONES
);
698 NewOp
->Asl
.Next
= NewOp2
;
699 TrAmlInitLineNumbers (NewOp2
, Conditional
);
701 NewOp2
= TrCreateLeafOp (PARSEOP_LEQUAL
);
702 NewOp2
->Asl
.Child
= NewOp
;
703 NewOp
->Asl
.Parent
= NewOp2
;
704 TrAmlInitLineNumbers (NewOp2
, Conditional
);
705 TrAmlSetSubtreeParent (NewOp
, NewOp2
);
708 NewOp2
= TrCreateLeafOp (PARSEOP_LNOT
);
709 NewOp2
->Asl
.Child
= NewOp
;
710 NewOp2
->Asl
.Parent
= Conditional
;
711 NewOp
->Asl
.Parent
= NewOp2
;
712 TrAmlInitLineNumbers (NewOp2
, Conditional
);
714 Conditional
->Asl
.Child
= NewOp2
;
715 NewOp2
->Asl
.Next
= CaseBlock
;
720 * Integer and Buffer case.
722 * Change CaseOp() to: If (LEqual (SwitchValue, CaseValue)) {...}
723 * Note: SwitchValue is first to allow the CaseValue to be implicitly
724 * converted to the type of SwitchValue if necessary.
726 * CaseOp->Child is the case value
727 * CaseOp->Child->Peer is the beginning of the case block
729 NewOp
= TrCreateValuedLeafOp (PARSEOP_NAMESTRING
,
730 (UINT64
) ACPI_TO_INTEGER (PredicateValueName
));
731 NewOp
->Asl
.Next
= Predicate
;
732 TrAmlInitLineNumbers (NewOp
, Predicate
);
734 NewOp2
= TrCreateLeafOp (PARSEOP_LEQUAL
);
735 NewOp2
->Asl
.Parent
= Conditional
;
736 NewOp2
->Asl
.Child
= NewOp
;
737 TrAmlInitLineNumbers (NewOp2
, Conditional
);
739 TrAmlSetSubtreeParent (NewOp
, NewOp2
);
742 Predicate
->Asl
.Next
= CaseBlock
;
744 TrAmlSetSubtreeParent (Predicate
, Conditional
);
745 Conditional
->Asl
.Child
= Predicate
;
748 /* Reinitialize the CASE node to an IF node */
750 TrAmlInitNode (Conditional
, PARSEOP_IF
);
753 * The first CASE(IF) is not nested under an ELSE.
754 * All other CASEs are children of a parent ELSE.
756 if (CurrentParentNode
== StartNode
)
758 Conditional
->Asl
.Next
= NULL
;
763 * The IF is a child of previous IF/ELSE. It
764 * is therefore without peer.
766 CurrentParentNode
->Asl
.Child
= Conditional
;
767 Conditional
->Asl
.Parent
= CurrentParentNode
;
768 Conditional
->Asl
.Next
= NULL
;
771 else if (Next
->Asl
.ParseOpcode
== PARSEOP_DEFAULT
)
776 * More than one Default
777 * (Parser does not catch this, must check here)
779 AslError (ASL_ERROR
, ASL_MSG_MULTIPLE_DEFAULT
, Next
, NULL
);
783 /* Save the DEFAULT node for later, after CASEs */
790 /* Unknown peer opcode */
792 AcpiOsPrintf ("Unknown parse opcode for switch statement: %s (%u)\n",
793 Next
->Asl
.ParseOpName
, Next
->Asl
.ParseOpcode
);
797 /* Add the default case at the end of the if/else construct */
801 /* If no CASE statements, this is an error - see below */
805 /* Convert the DEFAULT node to an ELSE */
807 TrAmlInitNode (DefaultOp
, PARSEOP_ELSE
);
808 DefaultOp
->Asl
.Parent
= Conditional
->Asl
.Parent
;
810 /* Link ELSE node as a peer to the previous IF */
812 TrAmlInsertPeer (Conditional
, DefaultOp
);
818 AslError (ASL_ERROR
, ASL_MSG_NO_CASES
, StartNode
, NULL
);
823 * Create a Name(_T_x, ...) statement. This statement must appear at the
824 * method level, in case a loop surrounds the switch statement and could
825 * cause the name to be created twice (error).
828 /* Create the Name node */
830 Predicate
= StartNode
->Asl
.Child
;
831 NewOp
= TrCreateLeafOp (PARSEOP_NAME
);
832 TrAmlInitLineNumbers (NewOp
, StartNode
);
834 /* Find the parent method */
837 while ((Next
->Asl
.ParseOpcode
!= PARSEOP_METHOD
) &&
838 (Next
->Asl
.ParseOpcode
!= PARSEOP_DEFINITION_BLOCK
))
840 Next
= Next
->Asl
.Parent
;
844 NewOp
->Asl
.CompileFlags
|= OP_COMPILER_EMITTED
;
845 NewOp
->Asl
.Parent
= Next
;
847 /* Insert name after the method name and arguments */
849 Next
= Next
->Asl
.Child
; /* Name */
850 Next
= Next
->Asl
.Next
; /* NumArgs */
851 Next
= Next
->Asl
.Next
; /* SerializeRule */
854 * If method is not Serialized, we must make is so, because of the way
855 * that Switch() must be implemented -- we cannot allow multiple threads
856 * to execute this method concurrently since we need to create local
859 if (Next
->Asl
.ParseOpcode
!= PARSEOP_SERIALIZERULE_SERIAL
)
861 AslError (ASL_REMARK
, ASL_MSG_SERIALIZED
, MethodOp
,
862 "Due to use of Switch operator");
863 Next
->Asl
.ParseOpcode
= PARSEOP_SERIALIZERULE_SERIAL
;
866 Next
= Next
->Asl
.Next
; /* SyncLevel */
867 Next
= Next
->Asl
.Next
; /* ReturnType */
868 Next
= Next
->Asl
.Next
; /* ParameterTypes */
870 TrAmlInsertPeer (Next
, NewOp
);
871 TrAmlInitLineNumbers (NewOp
, Next
);
873 /* Create the NameSeg child for the Name node */
875 NewOp2
= TrCreateValuedLeafOp (PARSEOP_NAMESEG
,
876 (UINT64
) ACPI_TO_INTEGER (PredicateValueName
));
877 TrAmlInitLineNumbers (NewOp2
, NewOp
);
878 NewOp2
->Asl
.CompileFlags
|= OP_IS_NAME_DECLARATION
;
879 NewOp
->Asl
.Child
= NewOp2
;
881 /* Create the initial value for the Name. Btype was already validated above */
885 case ACPI_BTYPE_INTEGER
:
887 NewOp2
->Asl
.Next
= TrCreateValuedLeafOp (PARSEOP_ZERO
,
889 TrAmlInitLineNumbers (NewOp2
->Asl
.Next
, NewOp
);
892 case ACPI_BTYPE_STRING
:
894 NewOp2
->Asl
.Next
= TrCreateValuedLeafOp (PARSEOP_STRING_LITERAL
,
895 (UINT64
) ACPI_TO_INTEGER (""));
896 TrAmlInitLineNumbers (NewOp2
->Asl
.Next
, NewOp
);
899 case ACPI_BTYPE_BUFFER
:
901 (void) TrLinkPeerOp (NewOp2
, TrCreateValuedLeafOp (PARSEOP_BUFFER
,
903 Next
= NewOp2
->Asl
.Next
;
904 TrAmlInitLineNumbers (Next
, NewOp2
);
906 (void) TrLinkOpChildren (Next
, 1, TrCreateValuedLeafOp (PARSEOP_ZERO
,
908 TrAmlInitLineNumbers (Next
->Asl
.Child
, Next
);
910 BufferOp
= TrCreateValuedLeafOp (PARSEOP_DEFAULT_ARG
, (UINT64
) 0);
911 TrAmlInitLineNumbers (BufferOp
, Next
->Asl
.Child
);
912 (void) TrLinkPeerOp (Next
->Asl
.Child
, BufferOp
);
914 TrAmlSetSubtreeParent (Next
->Asl
.Child
, Next
);
922 TrAmlSetSubtreeParent (NewOp2
, NewOp
);
925 * Transform the Switch() into a While(One)-Break node.
926 * And create a Store() node which will be used to save the
927 * Switch() value. The store is of the form: Store (Value, _T_x)
928 * where _T_x is the temp variable.
930 TrAmlInitNode (StartNode
, PARSEOP_WHILE
);
931 NewOp
= TrCreateLeafOp (PARSEOP_ONE
);
932 TrAmlInitLineNumbers (NewOp
, StartNode
);
933 NewOp
->Asl
.Next
= Predicate
->Asl
.Next
;
934 NewOp
->Asl
.Parent
= StartNode
;
935 StartNode
->Asl
.Child
= NewOp
;
937 /* Create a Store() node */
939 StoreOp
= TrCreateLeafOp (PARSEOP_STORE
);
940 TrAmlInitLineNumbers (StoreOp
, NewOp
);
941 StoreOp
->Asl
.Parent
= StartNode
;
942 TrAmlInsertPeer (NewOp
, StoreOp
);
944 /* Complete the Store subtree */
946 StoreOp
->Asl
.Child
= Predicate
;
947 Predicate
->Asl
.Parent
= StoreOp
;
949 NewOp
= TrCreateValuedLeafOp (PARSEOP_NAMESEG
,
950 (UINT64
) ACPI_TO_INTEGER (PredicateValueName
));
951 TrAmlInitLineNumbers (NewOp
, StoreOp
);
952 NewOp
->Asl
.Parent
= StoreOp
;
953 Predicate
->Asl
.Next
= NewOp
;
955 /* Create a Break() node and insert it into the end of While() */
957 Conditional
= StartNode
->Asl
.Child
;
958 while (Conditional
->Asl
.Next
)
960 Conditional
= Conditional
->Asl
.Next
;
963 BreakOp
= TrCreateLeafOp (PARSEOP_BREAK
);
964 TrAmlInitLineNumbers (BreakOp
, NewOp
);
965 BreakOp
->Asl
.Parent
= StartNode
;
966 TrAmlInsertPeer (Conditional
, BreakOp
);