Update ACPI build wrappers to use new ACPICA(20050309) code.
[dragonfly.git] / sys / contrib / dev / acpica-unix-20050211 / compiler / asltransform.c
1
2 /******************************************************************************
3  *
4  * Module Name: asltransform - Parse tree transforms
5  *              $Revision: 29 $
6  *
7  *****************************************************************************/
8
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14  * All rights reserved.
15  *
16  * 2. License
17  *
18  * 2.1. This is your license from Intel Corp. under its intellectual property
19  * rights.  You may have additional license terms from the party that provided
20  * you this software, covering your right to use that party's intellectual
21  * property rights.
22  *
23  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24  * copy of the source code appearing in this file ("Covered Code") an
25  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26  * base code distributed originally by Intel ("Original Intel Code") to copy,
27  * make derivatives, distribute, use and display any portion of the Covered
28  * Code in any form, with the right to sublicense such rights; and
29  *
30  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31  * license (with the right to sublicense), under only those claims of Intel
32  * patents that are infringed by the Original Intel Code, to make, use, sell,
33  * offer to sell, and import the Covered Code and derivative works thereof
34  * solely to the minimum extent necessary to exercise the above copyright
35  * license, and in no event shall the patent license extend to any additions
36  * to or modifications of the Original Intel Code.  No other license or right
37  * is granted directly or by implication, estoppel or otherwise;
38  *
39  * The above copyright and patent license is granted only if the following
40  * conditions are met:
41  *
42  * 3. Conditions
43  *
44  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45  * Redistribution of source code of any substantial portion of the Covered
46  * Code or modification with rights to further distribute source must include
47  * the above Copyright Notice, the above License, this list of Conditions,
48  * and the following Disclaimer and Export Compliance provision.  In addition,
49  * Licensee must cause all Covered Code to which Licensee contributes to
50  * contain a file documenting the changes Licensee made to create that Covered
51  * Code and the date of any change.  Licensee must include in that file the
52  * documentation of any changes made by any predecessor Licensee.  Licensee
53  * must include a prominent statement that the modification is derived,
54  * directly or indirectly, from Original Intel Code.
55  *
56  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57  * Redistribution of source code of any substantial portion of the Covered
58  * Code or modification without rights to further distribute source must
59  * include the following Disclaimer and Export Compliance provision in the
60  * documentation and/or other materials provided with distribution.  In
61  * addition, Licensee may not authorize further sublicense of source of any
62  * portion of the Covered Code, and must include terms to the effect that the
63  * license from Licensee to its licensee is limited to the intellectual
64  * property embodied in the software Licensee provides to its licensee, and
65  * not to intellectual property embodied in modifications its licensee may
66  * make.
67  *
68  * 3.3. Redistribution of Executable. Redistribution in executable form of any
69  * substantial portion of the Covered Code or modification must reproduce the
70  * above Copyright Notice, and the following Disclaimer and Export Compliance
71  * provision in the documentation and/or other materials provided with the
72  * distribution.
73  *
74  * 3.4. Intel retains all right, title, and interest in and to the Original
75  * Intel Code.
76  *
77  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78  * Intel shall be used in advertising or otherwise to promote the sale, use or
79  * other dealings in products derived from or relating to the Covered Code
80  * without prior written authorization from Intel.
81  *
82  * 4. Disclaimer and Export Compliance
83  *
84  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90  * PARTICULAR PURPOSE.
91  *
92  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99  * LIMITED REMEDY.
100  *
101  * 4.3. Licensee shall not export, either directly or indirectly, any of this
102  * software or system incorporating such software without first obtaining any
103  * required license or other approval from the U. S. Department of Commerce or
104  * any other agency or department of the United States Government.  In the
105  * event Licensee exports any such software from the United States or
106  * re-exports any such software from a foreign destination, Licensee shall
107  * ensure that the distribution and export/re-export of the software is in
108  * compliance with all laws, regulations, orders, or other restrictions of the
109  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110  * any of its subsidiaries will export/re-export any technical data, process,
111  * software, or service, directly or indirectly, to any country for which the
112  * United States government or any agency thereof requires an export license,
113  * other governmental approval, or letter of assurance, without first obtaining
114  * such license, approval or letter.
115  *
116  *****************************************************************************/
117
118
119 #include "aslcompiler.h"
120 #include "aslcompiler.y.h"
121
122 #define _COMPONENT          ACPI_COMPILER
123         ACPI_MODULE_NAME    ("asltransform")
124
125
126 /*******************************************************************************
127  *
128  * FUNCTION:    TrAmlGetNextTempName
129  *
130  * PARAMETERS:  TempCount       - Current temporary counter. Was originally
131  *                                per-module; Currently per method, could be 
132  *                                expanded to per-scope.
133  *
134  * RETURN:      A pointer to name (allocated here).
135  *
136  * DESCRIPTION: Generate an ACPI name of the form _T_x.  These names are
137  *              reserved for use by the ASL compiler. (_T_0 through _T_Z)
138  *
139  ******************************************************************************/
140
141 char *
142 TrAmlGetNextTempName (
143     ACPI_PARSE_OBJECT       *Op,
144     UINT8                   *TempCount)
145 {
146     char                    *TempName;
147
148
149     if (*TempCount >= (10+26))  /* 0-35 valid: 0-9 and A-Z for TempName[3] */
150     {
151         /* Too many temps */
152
153         AslError (ASL_ERROR, ASL_MSG_TOO_MANY_TEMPS, Op, NULL);
154         return (NULL);
155     }
156
157     TempName = UtLocalCalloc (5);
158
159     if (*TempCount < 10)    /* 0-9 */
160     {
161         TempName[3] = (char) (*TempCount + '0');
162     }
163     else                    /* 10-35: A-Z */
164     {
165         TempName[3] = (char) (*TempCount + ('A' - 10));
166     }
167     (*TempCount)++;
168
169     /* First three characters are always "_T_" */
170
171     TempName[0] = '_';
172     TempName[1] = 'T';
173     TempName[2] = '_';
174
175     return (TempName);
176 }
177
178
179 /*******************************************************************************
180  *
181  * FUNCTION:    TrAmlInitLineNumbers
182  *
183  * PARAMETERS:  Op              - Op to be initialized
184  *              Neighbor        - Op used for initialization values
185  *
186  * RETURN:      None
187  *
188  * DESCRIPTION: Initialized the various line numbers for a parse node.
189  *
190  ******************************************************************************/
191
192 void
193 TrAmlInitLineNumbers (
194     ACPI_PARSE_OBJECT       *Op,
195     ACPI_PARSE_OBJECT       *Neighbor)
196 {
197
198     Op->Asl.EndLine           = Neighbor->Asl.EndLine;
199     Op->Asl.EndLogicalLine    = Neighbor->Asl.EndLogicalLine;
200     Op->Asl.LineNumber        = Neighbor->Asl.LineNumber;
201     Op->Asl.LogicalByteOffset = Neighbor->Asl.LogicalByteOffset;
202     Op->Asl.LogicalLineNumber = Neighbor->Asl.LogicalLineNumber;
203 }
204
205
206 /*******************************************************************************
207  *
208  * FUNCTION:    TrAmlInitNode
209  *
210  * PARAMETERS:  Op              - Op to be initialized
211  *              ParseOpcode     - Opcode for this node
212  *
213  * RETURN:      None
214  *
215  * DESCRIPTION: Initialize a node with the parse opcode and opcode name.
216  *
217  ******************************************************************************/
218
219 void
220 TrAmlInitNode (
221     ACPI_PARSE_OBJECT       *Op,
222     UINT16                  ParseOpcode)
223 {
224
225     Op->Asl.ParseOpcode = ParseOpcode;
226     UtSetParseOpName (Op);
227 }
228
229
230 /*******************************************************************************
231  *
232  * FUNCTION:    TrAmlSetSubtreeParent
233  *
234  * PARAMETERS:  Op              - First node in a list of peer nodes
235  *              Parent          - Parent of the subtree
236  *
237  * RETURN:      None
238  *
239  * DESCRIPTION: Set the parent for all peer nodes in a subtree
240  *
241  ******************************************************************************/
242
243 void
244 TrAmlSetSubtreeParent (
245     ACPI_PARSE_OBJECT       *Op,
246     ACPI_PARSE_OBJECT       *Parent)
247 {
248     ACPI_PARSE_OBJECT       *Next;
249
250
251     Next = Op;
252     while (Next)
253     {
254         Next->Asl.Parent = Parent;
255         Next             = Next->Asl.Next;
256     }
257 }
258
259
260 /*******************************************************************************
261  *
262  * FUNCTION:    TrAmlInsertPeer
263  *
264  * PARAMETERS:  Op              - First node in a list of peer nodes
265  *              NewPeer         - Peer node to insert
266  *
267  * RETURN:      None
268  *
269  * DESCRIPTION: Insert a new peer node into a list of peers.
270  *
271  ******************************************************************************/
272
273 void
274 TrAmlInsertPeer (
275     ACPI_PARSE_OBJECT       *Op,
276     ACPI_PARSE_OBJECT       *NewPeer)
277 {
278
279     NewPeer->Asl.Next = Op->Asl.Next;
280     Op->Asl.Next      = NewPeer;
281 }
282
283
284 /*******************************************************************************
285  *
286  * FUNCTION:    TrAmlTransformWalk
287  *
288  * PARAMETERS:  ASL_WALK_CALLBACK
289  *
290  * RETURN:      None
291  *
292  * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
293  *              operands.
294  *
295  ******************************************************************************/
296
297 ACPI_STATUS
298 TrAmlTransformWalk (
299     ACPI_PARSE_OBJECT       *Op,
300     UINT32                  Level,
301     void                    *Context)
302 {
303
304     TrTransformSubtree (Op);
305     return (AE_OK);
306 }
307
308
309 /*******************************************************************************
310  *
311  * FUNCTION:    TrTransformSubtree
312  *
313  * PARAMETERS:  Op        - The parent parse node
314  *
315  * RETURN:      None
316  *
317  * DESCRIPTION: Prepare nodes to be output as AML data and operands.  The more
318  *              complex AML opcodes require processing of the child nodes
319  *              (arguments/operands).
320  *
321  ******************************************************************************/
322
323 void
324 TrTransformSubtree (
325     ACPI_PARSE_OBJECT           *Op)
326 {
327
328     if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
329     {
330         return;
331     }
332
333     switch (Op->Asl.ParseOpcode)
334     {
335     case PARSEOP_DEFINITIONBLOCK:
336         TrDoDefinitionBlock (Op);
337         break;
338
339     case PARSEOP_SWITCH:
340         TrDoSwitch (Op);
341         break;
342
343     case PARSEOP_METHOD:
344
345         /* Zero the tempname (_T_x) count. Probably shouldn't be a global, however */
346
347         Gbl_TempCount = 0;
348         break;
349
350     default:
351         /* Nothing to do here for other opcodes */
352         break;
353     }
354 }
355
356
357 /*******************************************************************************
358  *
359  * FUNCTION:    TrDoDefinitionBlock
360  *
361  * PARAMETERS:  Op        - Parse node
362  *
363  * RETURN:      None
364  *
365  * DESCRIPTION: Find the end of the definition block and set a global to this
366  *              node.  It is used by the compiler to insert compiler-generated
367  *              names at the root level of the namespace.
368  *
369  ******************************************************************************/
370
371 void
372 TrDoDefinitionBlock (
373     ACPI_PARSE_OBJECT       *Op)
374 {
375     ACPI_PARSE_OBJECT       *Next;
376     UINT32                  i;
377
378
379     Next = Op->Asl.Child;
380     for (i = 0; i < 5; i++)
381     {
382         Next = Next->Asl.Next;
383     }
384
385     Gbl_FirstLevelInsertionNode = Next;
386 }
387
388
389 /*******************************************************************************
390  *
391  * FUNCTION:    TrDoSwitch
392  *
393  * PARAMETERS:  StartNode        - Parse node for SWITCH
394  *
395  * RETURN:      None
396  *
397  *
398  * DESCRIPTION: Translate ASL SWITCH statement to if/else pairs.  There is
399  *              no actual AML opcode for SWITCH -- it must be simulated.
400  *
401  ******************************************************************************/
402
403 void
404 TrDoSwitch (
405     ACPI_PARSE_OBJECT       *StartNode)
406 {
407     ACPI_PARSE_OBJECT       *Next;
408     ACPI_PARSE_OBJECT       *CaseOp = NULL;
409     ACPI_PARSE_OBJECT       *CaseBlock = NULL;
410     ACPI_PARSE_OBJECT       *DefaultOp = NULL;
411     ACPI_PARSE_OBJECT       *CurrentParentNode;
412     ACPI_PARSE_OBJECT       *Conditional = NULL;
413     ACPI_PARSE_OBJECT       *Predicate;
414     ACPI_PARSE_OBJECT       *Peer;
415     ACPI_PARSE_OBJECT       *NewOp;
416     ACPI_PARSE_OBJECT       *NewOp2;
417     char                    *PredicateValueName;
418     UINT16                  Index;
419     UINT32                  Btype;
420
421
422     /* Start node is the Switch() node */
423
424     CurrentParentNode  = StartNode;
425
426     /* Create a new temp name of the form _T_x */
427
428     PredicateValueName = TrAmlGetNextTempName (StartNode, &Gbl_TempCount);
429     if (!PredicateValueName)
430     {
431         return;
432     }
433
434     /* First child is the Switch() predicate */
435
436     Next = StartNode->Asl.Child;
437
438     /* Examine the return type of the Switch Value - must be Integer/Buffer/String */
439
440     Index = (UINT16) (Next->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE);
441     Btype = AslKeywordMapping[Index].AcpiBtype;
442     if ((Btype != ACPI_BTYPE_INTEGER) &&
443         (Btype != ACPI_BTYPE_STRING)  &&
444         (Btype != ACPI_BTYPE_BUFFER))
445     {
446         AslError (ASL_WARNING, ASL_MSG_SWITCH_TYPE, Next, NULL);
447         Btype = ACPI_BTYPE_INTEGER;
448     }
449
450     /* CASE statements start at next child */
451
452     Peer = Next->Asl.Next;
453     while (Peer)
454     {
455         Next = Peer;
456         Peer = Next->Asl.Next;
457
458         if (Next->Asl.ParseOpcode == PARSEOP_CASE)
459         {
460             if (CaseOp)
461             {
462                 /* Add an ELSE to complete the previous CASE */
463
464                 NewOp             = TrCreateLeafNode (PARSEOP_ELSE);
465                 NewOp->Asl.Parent = Conditional->Asl.Parent;
466                 TrAmlInitLineNumbers (NewOp, NewOp->Asl.Parent);
467
468                 /* Link ELSE node as a peer to the previous IF */
469
470                 TrAmlInsertPeer (Conditional, NewOp);
471                 CurrentParentNode = NewOp;
472             }
473
474             CaseOp      = Next;
475             Conditional = CaseOp;
476             CaseBlock   = CaseOp->Asl.Child->Asl.Next;
477             Conditional->Asl.Child->Asl.Next = NULL;
478             Predicate = CaseOp->Asl.Child;
479
480             if (Predicate->Asl.ParseOpcode == PARSEOP_PACKAGE)
481             {
482                 /*
483                  * Convert the package declaration to this form:
484                  *
485                  * If (LNotEqual (Match (Package(<size>){<data>}, MEQ, _T_x, MTR, Zero, Zero), Ones))
486                  */
487                 NewOp2              = TrCreateLeafNode (PARSEOP_MATCHTYPE_MEQ);
488                 Predicate->Asl.Next = NewOp2;
489                 TrAmlInitLineNumbers (NewOp2, Conditional);
490
491                 NewOp               = NewOp2;
492                 NewOp2              = TrCreateValuedLeafNode (PARSEOP_NAMESTRING,
493                                         (ACPI_INTEGER) ACPI_TO_INTEGER (PredicateValueName));
494                 NewOp->Asl.Next     = NewOp2;
495                 TrAmlInitLineNumbers (NewOp2, Predicate);
496
497                 NewOp               = NewOp2;
498                 NewOp2              = TrCreateLeafNode (PARSEOP_MATCHTYPE_MTR);
499                 NewOp->Asl.Next     = NewOp2;
500                 TrAmlInitLineNumbers (NewOp2, Predicate);
501
502                 NewOp               = NewOp2;
503                 NewOp2              = TrCreateLeafNode (PARSEOP_ZERO);
504                 NewOp->Asl.Next     = NewOp2;
505                 TrAmlInitLineNumbers (NewOp2, Predicate);
506
507                 NewOp               = NewOp2;
508                 NewOp2              = TrCreateLeafNode (PARSEOP_ZERO);
509                 NewOp->Asl.Next     = NewOp2;
510                 TrAmlInitLineNumbers (NewOp2, Predicate);
511
512                 NewOp2              = TrCreateLeafNode (PARSEOP_MATCH);
513                 NewOp2->Asl.Child   = Predicate;  /* PARSEOP_PACKAGE */
514                 TrAmlInitLineNumbers (NewOp2, Conditional);
515                 TrAmlSetSubtreeParent (Predicate, NewOp2);
516
517                 NewOp               = NewOp2;
518                 NewOp2              = TrCreateLeafNode (PARSEOP_ONES);
519                 NewOp->Asl.Next     = NewOp2;
520                 TrAmlInitLineNumbers (NewOp2, Conditional);
521
522                 NewOp2              = TrCreateLeafNode (PARSEOP_LEQUAL);
523                 NewOp2->Asl.Child   = NewOp;
524                 NewOp->Asl.Parent   = NewOp2;
525                 TrAmlInitLineNumbers (NewOp2, Conditional);
526                 TrAmlSetSubtreeParent (NewOp, NewOp2);
527
528                 NewOp               = NewOp2;
529                 NewOp2              = TrCreateLeafNode (PARSEOP_LNOT);
530                 NewOp2->Asl.Child   = NewOp;
531                 NewOp2->Asl.Parent  = Conditional;
532                 NewOp->Asl.Parent   = NewOp2;
533                 TrAmlInitLineNumbers (NewOp2, Conditional);
534
535                 Conditional->Asl.Child = NewOp2;
536                 NewOp2->Asl.Next = CaseBlock;
537             }
538             else
539             {
540                 /*
541                  * Integer and Buffer case.
542                  *
543                  * Change CaseOp() to:  If (LEqual (SwitchValue, CaseValue)) {...}
544                  * Note: SwitchValue is first to allow the CaseValue to be implicitly
545                  * converted to the type of SwitchValue if necessary.
546                  *
547                  * CaseOp->Child is the case value
548                  * CaseOp->Child->Peer is the beginning of the case block
549                  */
550                 NewOp = TrCreateValuedLeafNode (PARSEOP_NAMESTRING,
551                                 (ACPI_INTEGER) ACPI_TO_INTEGER (PredicateValueName));
552                 NewOp->Asl.Next = Predicate;
553                 TrAmlInitLineNumbers (NewOp, Predicate);
554
555                 NewOp2              = TrCreateLeafNode (PARSEOP_LEQUAL);
556                 NewOp2->Asl.Parent  = Conditional;
557                 NewOp2->Asl.Child   = NewOp;
558                 TrAmlInitLineNumbers (NewOp2, Conditional);
559
560                 TrAmlSetSubtreeParent (NewOp, NewOp2);
561
562                 Predicate           = NewOp2;
563                 Predicate->Asl.Next = CaseBlock;
564
565                 TrAmlSetSubtreeParent (Predicate, Conditional);
566                 Conditional->Asl.Child = Predicate;
567             }
568
569             /* Reinitialize the CASE node to an IF node */
570
571             TrAmlInitNode (Conditional, PARSEOP_IF);
572
573             /*
574              * The first CASE(IF) is not nested under an ELSE.
575              * All other CASEs are children of a parent ELSE.
576              */
577             if (CurrentParentNode == StartNode)
578             {
579                 Conditional->Asl.Parent = CurrentParentNode->Asl.Parent;
580
581                 /* Link IF into the peer list */
582
583                 TrAmlInsertPeer (CurrentParentNode, Conditional);
584             }
585             else
586             {
587                 /*
588                  * The IF is a child of previous IF/ELSE.  It
589                  * is therefore without peer.
590                  */
591                 CurrentParentNode->Asl.Child = Conditional;
592                 Conditional->Asl.Parent      = CurrentParentNode;
593                 Conditional->Asl.Next        = NULL;
594             }
595         }
596         else if (Next->Asl.ParseOpcode == PARSEOP_DEFAULT)
597         {
598             if (DefaultOp)
599             {
600                 /*
601                  * More than one Default
602                  * (Parser should catch this, should not get here)
603                  */
604                 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Next,
605                     "Found more than one Default()");
606             }
607
608             /* Save the DEFAULT node for later, after CASEs */
609
610             DefaultOp = Next;
611         }
612         else
613         {
614             /* Unknown peer opcode */
615
616             AcpiOsPrintf ("Unknown parse opcode for switch statement: %s (%d)\n",
617                         Next->Asl.ParseOpName, Next->Asl.ParseOpcode);
618         }
619     }
620
621     /* Add the default case at the end of the if/else construct */
622
623     if (DefaultOp)
624     {
625         /* If no CASE statements, this is an error - see below */
626
627         if (CaseOp)
628         {
629             /* Convert the DEFAULT node to an ELSE */
630
631             TrAmlInitNode (DefaultOp, PARSEOP_ELSE);
632             DefaultOp->Asl.Parent = Conditional->Asl.Parent;
633
634             /* Link ELSE node as a peer to the previous IF */
635
636             TrAmlInsertPeer (Conditional, DefaultOp);
637         }
638     }
639
640     if (!CaseOp)
641     {
642         AslError (ASL_ERROR, ASL_MSG_NO_CASES, StartNode, NULL);
643     }
644
645     /*
646      * Add a NAME node for the temp integer:
647      * Change the SWITCH node to a Name (_T_x, Type)
648      */
649     Predicate = StartNode->Asl.Child;
650     TrAmlInitNode (StartNode, PARSEOP_NAME);
651
652     NewOp = StartNode;
653
654     NewOp->Asl.CompileFlags |= NODE_COMPILER_EMITTED;
655
656     NewOp2 = TrCreateValuedLeafNode (PARSEOP_NAMESEG,
657                 (ACPI_INTEGER) ACPI_TO_INTEGER (PredicateValueName));
658     NewOp2->Asl.CompileFlags |= NODE_IS_NAME_DECLARATION;
659     NewOp->Asl.Child  = NewOp2;
660
661     /* Btype was already validated above */
662
663     switch (Btype)
664     {
665     case ACPI_BTYPE_INTEGER:
666         NewOp2->Asl.Next  = TrCreateValuedLeafNode (PARSEOP_ZERO, (ACPI_INTEGER) 0);
667         break;
668
669     case ACPI_BTYPE_STRING:
670         NewOp2->Asl.Next = TrCreateValuedLeafNode (PARSEOP_STRING_LITERAL, (ACPI_INTEGER) "");
671         break;
672
673     case ACPI_BTYPE_BUFFER:
674         TrLinkPeerNode (NewOp2, TrCreateValuedLeafNode (PARSEOP_BUFFER, (ACPI_INTEGER) 0));
675         Next = NewOp2->Asl.Next;
676         TrLinkChildren (Next, 1, TrCreateValuedLeafNode (PARSEOP_ZERO, (ACPI_INTEGER) 1));
677         TrLinkPeerNode (Next->Asl.Child, TrCreateValuedLeafNode (PARSEOP_DEFAULT_ARG, (ACPI_INTEGER) 0));
678
679         TrAmlSetSubtreeParent (Next->Asl.Child, Next);
680         break;
681
682     default:
683         break;
684     }
685
686     TrAmlSetSubtreeParent (NewOp2, NewOp);
687
688     /*
689      * Create and insert a new Store() node which will be used to save the Switch() value.
690      * The store is of the form: Store (Value, _T_x) where _T_x is the temp variable.
691      */
692     Next = TrCreateLeafNode (PARSEOP_STORE);
693     TrAmlInsertPeer (StartNode, Next);
694     TrAmlSetSubtreeParent (Next, StartNode->Asl.Parent);
695
696     TrAmlInitLineNumbers (Next, StartNode);
697     TrAmlInitLineNumbers (NewOp2, StartNode);
698     TrAmlInitLineNumbers (NewOp2->Asl.Next, StartNode);
699
700     /* Complete the Store subtree */
701
702     Next->Asl.Child       = Predicate;
703     Predicate->Asl.Parent = Next;
704
705     NewOp = TrCreateValuedLeafNode (PARSEOP_NAMESEG,
706                 (ACPI_INTEGER) ACPI_TO_INTEGER (PredicateValueName));
707     NewOp->Asl.Parent    = Next;
708     Predicate->Asl.Next  = NewOp;
709 }
710
711