asltransform.c revision 245582
1/******************************************************************************
2 *
3 * Module Name: asltransform - Parse tree transforms
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions, and the following disclaimer,
16 *    without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 *    substantially similar to the "NO WARRANTY" disclaimer below
19 *    ("Disclaimer") and any redistribution must be conditioned upon
20 *    including a substantially similar Disclaimer requirement for further
21 *    binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 *    of any contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44
45#include <contrib/dev/acpica/compiler/aslcompiler.h>
46#include "aslcompiler.y.h"
47
48#define _COMPONENT          ACPI_COMPILER
49        ACPI_MODULE_NAME    ("asltransform")
50
51/* Local prototypes */
52
53static void
54TrTransformSubtree (
55    ACPI_PARSE_OBJECT       *Op);
56
57static char *
58TrAmlGetNextTempName (
59    ACPI_PARSE_OBJECT       *Op,
60    UINT8                   *TempCount);
61
62static void
63TrAmlInitLineNumbers (
64    ACPI_PARSE_OBJECT       *Op,
65    ACPI_PARSE_OBJECT       *Neighbor);
66
67static void
68TrAmlInitNode (
69    ACPI_PARSE_OBJECT       *Op,
70    UINT16                  ParseOpcode);
71
72static void
73TrAmlSetSubtreeParent (
74    ACPI_PARSE_OBJECT       *Op,
75    ACPI_PARSE_OBJECT       *Parent);
76
77static void
78TrAmlInsertPeer (
79    ACPI_PARSE_OBJECT       *Op,
80    ACPI_PARSE_OBJECT       *NewPeer);
81
82static void
83TrDoDefinitionBlock (
84    ACPI_PARSE_OBJECT       *Op);
85
86static void
87TrDoSwitch (
88    ACPI_PARSE_OBJECT       *StartNode);
89
90
91/*******************************************************************************
92 *
93 * FUNCTION:    TrAmlGetNextTempName
94 *
95 * PARAMETERS:  Op              - Current parse op
96 *              TempCount       - Current temporary counter. Was originally
97 *                                per-module; Currently per method, could be
98 *                                expanded to per-scope.
99 *
100 * RETURN:      A pointer to name (allocated here).
101 *
102 * DESCRIPTION: Generate an ACPI name of the form _T_x. These names are
103 *              reserved for use by the ASL compiler. (_T_0 through _T_Z)
104 *
105 ******************************************************************************/
106
107static char *
108TrAmlGetNextTempName (
109    ACPI_PARSE_OBJECT       *Op,
110    UINT8                   *TempCount)
111{
112    char                    *TempName;
113
114
115    if (*TempCount >= (10+26))  /* 0-35 valid: 0-9 and A-Z for TempName[3] */
116    {
117        /* Too many temps */
118
119        AslError (ASL_ERROR, ASL_MSG_TOO_MANY_TEMPS, Op, NULL);
120        return (NULL);
121    }
122
123    TempName = UtLocalCalloc (5);
124
125    if (*TempCount < 10)    /* 0-9 */
126    {
127        TempName[3] = (char) (*TempCount + '0');
128    }
129    else                    /* 10-35: A-Z */
130    {
131        TempName[3] = (char) (*TempCount + ('A' - 10));
132    }
133    (*TempCount)++;
134
135    /* First three characters are always "_T_" */
136
137    TempName[0] = '_';
138    TempName[1] = 'T';
139    TempName[2] = '_';
140
141    return (TempName);
142}
143
144
145/*******************************************************************************
146 *
147 * FUNCTION:    TrAmlInitLineNumbers
148 *
149 * PARAMETERS:  Op              - Op to be initialized
150 *              Neighbor        - Op used for initialization values
151 *
152 * RETURN:      None
153 *
154 * DESCRIPTION: Initialized the various line numbers for a parse node.
155 *
156 ******************************************************************************/
157
158static void
159TrAmlInitLineNumbers (
160    ACPI_PARSE_OBJECT       *Op,
161    ACPI_PARSE_OBJECT       *Neighbor)
162{
163
164    Op->Asl.EndLine           = Neighbor->Asl.EndLine;
165    Op->Asl.EndLogicalLine    = Neighbor->Asl.EndLogicalLine;
166    Op->Asl.LineNumber        = Neighbor->Asl.LineNumber;
167    Op->Asl.LogicalByteOffset = Neighbor->Asl.LogicalByteOffset;
168    Op->Asl.LogicalLineNumber = Neighbor->Asl.LogicalLineNumber;
169}
170
171
172/*******************************************************************************
173 *
174 * FUNCTION:    TrAmlInitNode
175 *
176 * PARAMETERS:  Op              - Op to be initialized
177 *              ParseOpcode     - Opcode for this node
178 *
179 * RETURN:      None
180 *
181 * DESCRIPTION: Initialize a node with the parse opcode and opcode name.
182 *
183 ******************************************************************************/
184
185static void
186TrAmlInitNode (
187    ACPI_PARSE_OBJECT       *Op,
188    UINT16                  ParseOpcode)
189{
190
191    Op->Asl.ParseOpcode = ParseOpcode;
192    UtSetParseOpName (Op);
193}
194
195
196/*******************************************************************************
197 *
198 * FUNCTION:    TrAmlSetSubtreeParent
199 *
200 * PARAMETERS:  Op              - First node in a list of peer nodes
201 *              Parent          - Parent of the subtree
202 *
203 * RETURN:      None
204 *
205 * DESCRIPTION: Set the parent for all peer nodes in a subtree
206 *
207 ******************************************************************************/
208
209static void
210TrAmlSetSubtreeParent (
211    ACPI_PARSE_OBJECT       *Op,
212    ACPI_PARSE_OBJECT       *Parent)
213{
214    ACPI_PARSE_OBJECT       *Next;
215
216
217    Next = Op;
218    while (Next)
219    {
220        Next->Asl.Parent = Parent;
221        Next             = Next->Asl.Next;
222    }
223}
224
225
226/*******************************************************************************
227 *
228 * FUNCTION:    TrAmlInsertPeer
229 *
230 * PARAMETERS:  Op              - First node in a list of peer nodes
231 *              NewPeer         - Peer node to insert
232 *
233 * RETURN:      None
234 *
235 * DESCRIPTION: Insert a new peer node into a list of peers.
236 *
237 ******************************************************************************/
238
239static void
240TrAmlInsertPeer (
241    ACPI_PARSE_OBJECT       *Op,
242    ACPI_PARSE_OBJECT       *NewPeer)
243{
244
245    NewPeer->Asl.Next = Op->Asl.Next;
246    Op->Asl.Next      = NewPeer;
247}
248
249
250/*******************************************************************************
251 *
252 * FUNCTION:    TrAmlTransformWalk
253 *
254 * PARAMETERS:  ASL_WALK_CALLBACK
255 *
256 * RETURN:      None
257 *
258 * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML
259 *              operands.
260 *
261 ******************************************************************************/
262
263ACPI_STATUS
264TrAmlTransformWalk (
265    ACPI_PARSE_OBJECT       *Op,
266    UINT32                  Level,
267    void                    *Context)
268{
269
270    TrTransformSubtree (Op);
271    return (AE_OK);
272}
273
274
275/*******************************************************************************
276 *
277 * FUNCTION:    TrTransformSubtree
278 *
279 * PARAMETERS:  Op        - The parent parse node
280 *
281 * RETURN:      None
282 *
283 * DESCRIPTION: Prepare nodes to be output as AML data and operands. The more
284 *              complex AML opcodes require processing of the child nodes
285 *              (arguments/operands).
286 *
287 ******************************************************************************/
288
289static void
290TrTransformSubtree (
291    ACPI_PARSE_OBJECT           *Op)
292{
293
294    if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
295    {
296        return;
297    }
298
299    switch (Op->Asl.ParseOpcode)
300    {
301    case PARSEOP_DEFINITIONBLOCK:
302        TrDoDefinitionBlock (Op);
303        break;
304
305    case PARSEOP_SWITCH:
306        TrDoSwitch (Op);
307        break;
308
309    case PARSEOP_METHOD:
310
311        /*
312         * TBD: Zero the tempname (_T_x) count. Probably shouldn't be a global,
313         * however
314         */
315        Gbl_TempCount = 0;
316        break;
317
318    default:
319        /* Nothing to do here for other opcodes */
320        break;
321    }
322}
323
324
325/*******************************************************************************
326 *
327 * FUNCTION:    TrDoDefinitionBlock
328 *
329 * PARAMETERS:  Op        - Parse node
330 *
331 * RETURN:      None
332 *
333 * DESCRIPTION: Find the end of the definition block and set a global to this
334 *              node. It is used by the compiler to insert compiler-generated
335 *              names at the root level of the namespace.
336 *
337 ******************************************************************************/
338
339static void
340TrDoDefinitionBlock (
341    ACPI_PARSE_OBJECT       *Op)
342{
343    ACPI_PARSE_OBJECT       *Next;
344    UINT32                  i;
345
346
347    Next = Op->Asl.Child;
348    for (i = 0; i < 5; i++)
349    {
350        Next = Next->Asl.Next;
351        if (i == 0)
352        {
353            /*
354             * This is the table signature. Only the DSDT can be assumed
355             * to be at the root of the namespace;  Therefore, namepath
356             * optimization can only be performed on the DSDT.
357             */
358            if (!ACPI_COMPARE_NAME (Next->Asl.Value.String, ACPI_SIG_DSDT))
359            {
360                Gbl_ReferenceOptimizationFlag = FALSE;
361            }
362        }
363    }
364
365    Gbl_FirstLevelInsertionNode = Next;
366}
367
368
369/*******************************************************************************
370 *
371 * FUNCTION:    TrDoSwitch
372 *
373 * PARAMETERS:  StartNode        - Parse node for SWITCH
374 *
375 * RETURN:      None
376 *
377 *
378 * DESCRIPTION: Translate ASL SWITCH statement to if/else pairs. There is
379 *              no actual AML opcode for SWITCH -- it must be simulated.
380 *
381 ******************************************************************************/
382
383static void
384TrDoSwitch (
385    ACPI_PARSE_OBJECT       *StartNode)
386{
387    ACPI_PARSE_OBJECT       *Next;
388    ACPI_PARSE_OBJECT       *CaseOp = NULL;
389    ACPI_PARSE_OBJECT       *CaseBlock = NULL;
390    ACPI_PARSE_OBJECT       *DefaultOp = NULL;
391    ACPI_PARSE_OBJECT       *CurrentParentNode;
392    ACPI_PARSE_OBJECT       *Conditional = NULL;
393    ACPI_PARSE_OBJECT       *Predicate;
394    ACPI_PARSE_OBJECT       *Peer;
395    ACPI_PARSE_OBJECT       *NewOp;
396    ACPI_PARSE_OBJECT       *NewOp2;
397    ACPI_PARSE_OBJECT       *MethodOp;
398    ACPI_PARSE_OBJECT       *StoreOp;
399    ACPI_PARSE_OBJECT       *BreakOp;
400    ACPI_PARSE_OBJECT       *BufferOp;
401    char                    *PredicateValueName;
402    UINT16                  Index;
403    UINT32                  Btype;
404
405
406    /* Start node is the Switch() node */
407
408    CurrentParentNode  = StartNode;
409
410    /* Create a new temp name of the form _T_x */
411
412    PredicateValueName = TrAmlGetNextTempName (StartNode, &Gbl_TempCount);
413    if (!PredicateValueName)
414    {
415        return;
416    }
417
418    /* First child is the Switch() predicate */
419
420    Next = StartNode->Asl.Child;
421
422    /*
423     * Examine the return type of the Switch Value -
424     * must be Integer/Buffer/String
425     */
426    Index = (UINT16) (Next->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE);
427    Btype = AslKeywordMapping[Index].AcpiBtype;
428    if ((Btype != ACPI_BTYPE_INTEGER) &&
429        (Btype != ACPI_BTYPE_STRING)  &&
430        (Btype != ACPI_BTYPE_BUFFER))
431    {
432        AslError (ASL_WARNING, ASL_MSG_SWITCH_TYPE, Next, NULL);
433        Btype = ACPI_BTYPE_INTEGER;
434    }
435
436    /* CASE statements start at next child */
437
438    Peer = Next->Asl.Next;
439    while (Peer)
440    {
441        Next = Peer;
442        Peer = Next->Asl.Next;
443
444        if (Next->Asl.ParseOpcode == PARSEOP_CASE)
445        {
446            if (CaseOp)
447            {
448                /* Add an ELSE to complete the previous CASE */
449
450                if (!Conditional)
451                {
452                    return;
453                }
454                NewOp             = TrCreateLeafNode (PARSEOP_ELSE);
455                NewOp->Asl.Parent = Conditional->Asl.Parent;
456                TrAmlInitLineNumbers (NewOp, NewOp->Asl.Parent);
457
458                /* Link ELSE node as a peer to the previous IF */
459
460                TrAmlInsertPeer (Conditional, NewOp);
461                CurrentParentNode = NewOp;
462            }
463
464            CaseOp      = Next;
465            Conditional = CaseOp;
466            CaseBlock   = CaseOp->Asl.Child->Asl.Next;
467            Conditional->Asl.Child->Asl.Next = NULL;
468            Predicate = CaseOp->Asl.Child;
469
470            if ((Predicate->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
471                (Predicate->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
472            {
473                /*
474                 * Convert the package declaration to this form:
475                 *
476                 * If (LNotEqual (Match (Package(<size>){<data>},
477                 *                       MEQ, _T_x, MTR, Zero, Zero), Ones))
478                 */
479                NewOp2              = TrCreateLeafNode (PARSEOP_MATCHTYPE_MEQ);
480                Predicate->Asl.Next = NewOp2;
481                TrAmlInitLineNumbers (NewOp2, Conditional);
482
483                NewOp               = NewOp2;
484                NewOp2              = TrCreateValuedLeafNode (PARSEOP_NAMESTRING,
485                                        (UINT64) ACPI_TO_INTEGER (PredicateValueName));
486                NewOp->Asl.Next     = NewOp2;
487                TrAmlInitLineNumbers (NewOp2, Predicate);
488
489                NewOp               = NewOp2;
490                NewOp2              = TrCreateLeafNode (PARSEOP_MATCHTYPE_MTR);
491                NewOp->Asl.Next     = NewOp2;
492                TrAmlInitLineNumbers (NewOp2, Predicate);
493
494                NewOp               = NewOp2;
495                NewOp2              = TrCreateLeafNode (PARSEOP_ZERO);
496                NewOp->Asl.Next     = NewOp2;
497                TrAmlInitLineNumbers (NewOp2, Predicate);
498
499                NewOp               = NewOp2;
500                NewOp2              = TrCreateLeafNode (PARSEOP_ZERO);
501                NewOp->Asl.Next     = NewOp2;
502                TrAmlInitLineNumbers (NewOp2, Predicate);
503
504                NewOp2              = TrCreateLeafNode (PARSEOP_MATCH);
505                NewOp2->Asl.Child   = Predicate;  /* PARSEOP_PACKAGE */
506                TrAmlInitLineNumbers (NewOp2, Conditional);
507                TrAmlSetSubtreeParent (Predicate, NewOp2);
508
509                NewOp               = NewOp2;
510                NewOp2              = TrCreateLeafNode (PARSEOP_ONES);
511                NewOp->Asl.Next     = NewOp2;
512                TrAmlInitLineNumbers (NewOp2, Conditional);
513
514                NewOp2              = TrCreateLeafNode (PARSEOP_LEQUAL);
515                NewOp2->Asl.Child   = NewOp;
516                NewOp->Asl.Parent   = NewOp2;
517                TrAmlInitLineNumbers (NewOp2, Conditional);
518                TrAmlSetSubtreeParent (NewOp, NewOp2);
519
520                NewOp               = NewOp2;
521                NewOp2              = TrCreateLeafNode (PARSEOP_LNOT);
522                NewOp2->Asl.Child   = NewOp;
523                NewOp2->Asl.Parent  = Conditional;
524                NewOp->Asl.Parent   = NewOp2;
525                TrAmlInitLineNumbers (NewOp2, Conditional);
526
527                Conditional->Asl.Child = NewOp2;
528                NewOp2->Asl.Next = CaseBlock;
529            }
530            else
531            {
532                /*
533                 * Integer and Buffer case.
534                 *
535                 * Change CaseOp() to:  If (LEqual (SwitchValue, CaseValue)) {...}
536                 * Note: SwitchValue is first to allow the CaseValue to be implicitly
537                 * converted to the type of SwitchValue if necessary.
538                 *
539                 * CaseOp->Child is the case value
540                 * CaseOp->Child->Peer is the beginning of the case block
541                 */
542                NewOp = TrCreateValuedLeafNode (PARSEOP_NAMESTRING,
543                            (UINT64) ACPI_TO_INTEGER (PredicateValueName));
544                NewOp->Asl.Next = Predicate;
545                TrAmlInitLineNumbers (NewOp, Predicate);
546
547                NewOp2              = TrCreateLeafNode (PARSEOP_LEQUAL);
548                NewOp2->Asl.Parent  = Conditional;
549                NewOp2->Asl.Child   = NewOp;
550                TrAmlInitLineNumbers (NewOp2, Conditional);
551
552                TrAmlSetSubtreeParent (NewOp, NewOp2);
553
554                Predicate           = NewOp2;
555                Predicate->Asl.Next = CaseBlock;
556
557                TrAmlSetSubtreeParent (Predicate, Conditional);
558                Conditional->Asl.Child = Predicate;
559            }
560
561            /* Reinitialize the CASE node to an IF node */
562
563            TrAmlInitNode (Conditional, PARSEOP_IF);
564
565            /*
566             * The first CASE(IF) is not nested under an ELSE.
567             * All other CASEs are children of a parent ELSE.
568             */
569            if (CurrentParentNode == StartNode)
570            {
571                Conditional->Asl.Next = NULL;
572            }
573            else
574            {
575                /*
576                 * The IF is a child of previous IF/ELSE. It
577                 * is therefore without peer.
578                 */
579                CurrentParentNode->Asl.Child = Conditional;
580                Conditional->Asl.Parent      = CurrentParentNode;
581                Conditional->Asl.Next        = NULL;
582            }
583        }
584        else if (Next->Asl.ParseOpcode == PARSEOP_DEFAULT)
585        {
586            if (DefaultOp)
587            {
588                /*
589                 * More than one Default
590                 * (Parser does not catch this, must check here)
591                 */
592                AslError (ASL_ERROR, ASL_MSG_MULTIPLE_DEFAULT, Next, NULL);
593            }
594            else
595            {
596                /* Save the DEFAULT node for later, after CASEs */
597
598                DefaultOp = Next;
599            }
600        }
601        else
602        {
603            /* Unknown peer opcode */
604
605            AcpiOsPrintf ("Unknown parse opcode for switch statement: %s (%u)\n",
606                        Next->Asl.ParseOpName, Next->Asl.ParseOpcode);
607        }
608    }
609
610    /* Add the default case at the end of the if/else construct */
611
612    if (DefaultOp)
613    {
614        /* If no CASE statements, this is an error - see below */
615
616        if (CaseOp)
617        {
618            /* Convert the DEFAULT node to an ELSE */
619
620            if (!Conditional)
621            {
622                return;
623            }
624
625            TrAmlInitNode (DefaultOp, PARSEOP_ELSE);
626            DefaultOp->Asl.Parent = Conditional->Asl.Parent;
627
628            /* Link ELSE node as a peer to the previous IF */
629
630            TrAmlInsertPeer (Conditional, DefaultOp);
631        }
632    }
633
634    if (!CaseOp)
635    {
636        AslError (ASL_ERROR, ASL_MSG_NO_CASES, StartNode, NULL);
637    }
638
639
640    /*
641     * Create a Name(_T_x, ...) statement. This statement must appear at the
642     * method level, in case a loop surrounds the switch statement and could
643     * cause the name to be created twice (error).
644     */
645
646    /* Create the Name node */
647
648    Predicate = StartNode->Asl.Child;
649    NewOp = TrCreateLeafNode (PARSEOP_NAME);
650    TrAmlInitLineNumbers (NewOp, StartNode);
651
652    /* Find the parent method */
653
654    Next = StartNode;
655    while ((Next->Asl.ParseOpcode != PARSEOP_METHOD) &&
656           (Next->Asl.ParseOpcode != PARSEOP_DEFINITIONBLOCK))
657    {
658        Next = Next->Asl.Parent;
659    }
660    MethodOp = Next;
661
662    NewOp->Asl.CompileFlags |= NODE_COMPILER_EMITTED;
663    NewOp->Asl.Parent = Next;
664
665    /* Insert name after the method name and arguments */
666
667    Next = Next->Asl.Child; /* Name */
668    Next = Next->Asl.Next;  /* NumArgs */
669    Next = Next->Asl.Next;  /* SerializeRule */
670
671    /*
672     * If method is not Serialized, we must make is so, because of the way
673     * that Switch() must be implemented -- we cannot allow multiple threads
674     * to execute this method concurrently since we need to create local
675     * temporary name(s).
676     */
677    if (Next->Asl.ParseOpcode != PARSEOP_SERIALIZERULE_SERIAL)
678    {
679        AslError (ASL_REMARK, ASL_MSG_SERIALIZED, MethodOp, "Due to use of Switch operator");
680        Next->Asl.ParseOpcode = PARSEOP_SERIALIZERULE_SERIAL;
681    }
682
683    Next = Next->Asl.Next;  /* SyncLevel */
684    Next = Next->Asl.Next;  /* ReturnType */
685    Next = Next->Asl.Next;  /* ParameterTypes */
686
687    TrAmlInsertPeer (Next, NewOp);
688    TrAmlInitLineNumbers (NewOp, Next);
689
690    /* Create the NameSeg child for the Name node */
691
692    NewOp2 = TrCreateValuedLeafNode (PARSEOP_NAMESEG,
693                (UINT64) ACPI_TO_INTEGER (PredicateValueName));
694    TrAmlInitLineNumbers (NewOp2, NewOp);
695    NewOp2->Asl.CompileFlags |= NODE_IS_NAME_DECLARATION;
696    NewOp->Asl.Child  = NewOp2;
697
698    /* Create the initial value for the Name. Btype was already validated above */
699
700    switch (Btype)
701    {
702    case ACPI_BTYPE_INTEGER:
703        NewOp2->Asl.Next = TrCreateValuedLeafNode (PARSEOP_ZERO,
704                                (UINT64) 0);
705        TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp);
706        break;
707
708    case ACPI_BTYPE_STRING:
709        NewOp2->Asl.Next = TrCreateValuedLeafNode (PARSEOP_STRING_LITERAL,
710                                (UINT64) ACPI_TO_INTEGER (""));
711        TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp);
712        break;
713
714    case ACPI_BTYPE_BUFFER:
715        (void) TrLinkPeerNode (NewOp2, TrCreateValuedLeafNode (PARSEOP_BUFFER,
716                                    (UINT64) 0));
717        Next = NewOp2->Asl.Next;
718        TrAmlInitLineNumbers (Next, NewOp2);
719        (void) TrLinkChildren (Next, 1, TrCreateValuedLeafNode (PARSEOP_ZERO,
720                                    (UINT64) 1));
721        TrAmlInitLineNumbers (Next->Asl.Child, Next);
722
723        BufferOp = TrCreateValuedLeafNode (PARSEOP_DEFAULT_ARG, (UINT64) 0);
724        TrAmlInitLineNumbers (BufferOp, Next->Asl.Child);
725        (void) TrLinkPeerNode (Next->Asl.Child, BufferOp);
726
727        TrAmlSetSubtreeParent (Next->Asl.Child, Next);
728        break;
729
730    default:
731        break;
732    }
733
734    TrAmlSetSubtreeParent (NewOp2, NewOp);
735
736    /*
737     * Transform the Switch() into a While(One)-Break node.
738     * And create a Store() node which will be used to save the
739     * Switch() value. The store is of the form: Store (Value, _T_x)
740     * where _T_x is the temp variable.
741     */
742    TrAmlInitNode (StartNode, PARSEOP_WHILE);
743    NewOp = TrCreateLeafNode (PARSEOP_ONE);
744    TrAmlInitLineNumbers (NewOp, StartNode);
745    NewOp->Asl.Next = Predicate->Asl.Next;
746    NewOp->Asl.Parent = StartNode;
747    StartNode->Asl.Child = NewOp;
748
749    /* Create a Store() node */
750
751    StoreOp = TrCreateLeafNode (PARSEOP_STORE);
752    TrAmlInitLineNumbers (StoreOp, NewOp);
753    StoreOp->Asl.Parent = StartNode;
754    TrAmlInsertPeer (NewOp, StoreOp);
755
756    /* Complete the Store subtree */
757
758    StoreOp->Asl.Child = Predicate;
759    Predicate->Asl.Parent = StoreOp;
760
761    NewOp = TrCreateValuedLeafNode (PARSEOP_NAMESEG,
762                (UINT64) ACPI_TO_INTEGER (PredicateValueName));
763    TrAmlInitLineNumbers (NewOp, StoreOp);
764    NewOp->Asl.Parent    = StoreOp;
765    Predicate->Asl.Next  = NewOp;
766
767    /* Create a Break() node and insert it into the end of While() */
768
769    Conditional = StartNode->Asl.Child;
770    while (Conditional->Asl.Next)
771    {
772        Conditional = Conditional->Asl.Next;
773    }
774
775    BreakOp = TrCreateLeafNode (PARSEOP_BREAK);
776    TrAmlInitLineNumbers (BreakOp, NewOp);
777    BreakOp->Asl.Parent = StartNode;
778    TrAmlInsertPeer (Conditional, BreakOp);
779}
780