asltransform.c revision 1.1.1.6 1 /******************************************************************************
2 *
3 * Module Name: asltransform - Parse tree transforms
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2016, 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 #include "aslcompiler.h"
45 #include "aslcompiler.y.h"
46
47 #define _COMPONENT ACPI_COMPILER
48 ACPI_MODULE_NAME ("asltransform")
49
50 /* Local prototypes */
51
52 static void
53 TrTransformSubtree (
54 ACPI_PARSE_OBJECT *Op);
55
56 static char *
57 TrAmlGetNextTempName (
58 ACPI_PARSE_OBJECT *Op,
59 UINT8 *TempCount);
60
61 static void
62 TrAmlInitLineNumbers (
63 ACPI_PARSE_OBJECT *Op,
64 ACPI_PARSE_OBJECT *Neighbor);
65
66 static void
67 TrAmlInitNode (
68 ACPI_PARSE_OBJECT *Op,
69 UINT16 ParseOpcode);
70
71 static void
72 TrAmlSetSubtreeParent (
73 ACPI_PARSE_OBJECT *Op,
74 ACPI_PARSE_OBJECT *Parent);
75
76 static void
77 TrAmlInsertPeer (
78 ACPI_PARSE_OBJECT *Op,
79 ACPI_PARSE_OBJECT *NewPeer);
80
81 static void
82 TrDoDefinitionBlock (
83 ACPI_PARSE_OBJECT *Op);
84
85 static void
86 TrDoSwitch (
87 ACPI_PARSE_OBJECT *StartNode);
88
89
90 /*******************************************************************************
91 *
92 * FUNCTION: TrAmlGetNextTempName
93 *
94 * PARAMETERS: Op - Current parse op
95 * TempCount - Current temporary counter. Was originally
96 * per-module; Currently per method, could be
97 * expanded to per-scope.
98 *
99 * RETURN: A pointer to name (allocated here).
100 *
101 * DESCRIPTION: Generate an ACPI name of the form _T_x. These names are
102 * reserved for use by the ASL compiler. (_T_0 through _T_Z)
103 *
104 ******************************************************************************/
105
106 static char *
107 TrAmlGetNextTempName (
108 ACPI_PARSE_OBJECT *Op,
109 UINT8 *TempCount)
110 {
111 char *TempName;
112
113
114 if (*TempCount >= (10 + 26)) /* 0-35 valid: 0-9 and A-Z for TempName[3] */
115 {
116 /* Too many temps */
117
118 AslError (ASL_ERROR, ASL_MSG_TOO_MANY_TEMPS, Op, NULL);
119 return (NULL);
120 }
121
122 TempName = UtLocalCalloc (5);
123
124 if (*TempCount < 10) /* 0-9 */
125 {
126 TempName[3] = (char) (*TempCount + '0');
127 }
128 else /* 10-35: A-Z */
129 {
130 TempName[3] = (char) (*TempCount + ('A' - 10));
131 }
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
158 static void
159 TrAmlInitLineNumbers (
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
185 static void
186 TrAmlInitNode (
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
209 static void
210 TrAmlSetSubtreeParent (
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
239 static void
240 TrAmlInsertPeer (
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
263 ACPI_STATUS
264 TrAmlTransformWalk (
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
289 static void
290 TrTransformSubtree (
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_DEFINITION_BLOCK:
302
303 TrDoDefinitionBlock (Op);
304 break;
305
306 case PARSEOP_SWITCH:
307
308 TrDoSwitch (Op);
309 break;
310
311 case PARSEOP_METHOD:
312 /*
313 * TBD: Zero the tempname (_T_x) count. Probably shouldn't be a global,
314 * however
315 */
316 Gbl_TempCount = 0;
317 break;
318
319 default:
320
321 /* Nothing to do here for other opcodes */
322
323 break;
324 }
325 }
326
327
328 /*******************************************************************************
329 *
330 * FUNCTION: TrDoDefinitionBlock
331 *
332 * PARAMETERS: Op - Parse node
333 *
334 * RETURN: None
335 *
336 * DESCRIPTION: Find the end of the definition block and set a global to this
337 * node. It is used by the compiler to insert compiler-generated
338 * names at the root level of the namespace.
339 *
340 ******************************************************************************/
341
342 static void
343 TrDoDefinitionBlock (
344 ACPI_PARSE_OBJECT *Op)
345 {
346 ACPI_PARSE_OBJECT *Next;
347 UINT32 i;
348
349
350 Next = Op->Asl.Child;
351 for (i = 0; i < 5; i++)
352 {
353 Next = Next->Asl.Next;
354 if (i == 0)
355 {
356 /*
357 * This is the table signature. Only the DSDT can be assumed
358 * to be at the root of the namespace; Therefore, namepath
359 * optimization can only be performed on the DSDT.
360 */
361 if (!ACPI_COMPARE_NAME (Next->Asl.Value.String, ACPI_SIG_DSDT))
362 {
363 Gbl_ReferenceOptimizationFlag = FALSE;
364 }
365 }
366 }
367
368 Gbl_FirstLevelInsertionNode = Next;
369 }
370
371
372 /*******************************************************************************
373 *
374 * FUNCTION: TrDoSwitch
375 *
376 * PARAMETERS: StartNode - Parse node for SWITCH
377 *
378 * RETURN: None
379 *
380 * DESCRIPTION: Translate ASL SWITCH statement to if/else pairs. There is
381 * no actual AML opcode for SWITCH -- it must be simulated.
382 *
383 ******************************************************************************/
384
385 static void
386 TrDoSwitch (
387 ACPI_PARSE_OBJECT *StartNode)
388 {
389 ACPI_PARSE_OBJECT *Next;
390 ACPI_PARSE_OBJECT *CaseOp = NULL;
391 ACPI_PARSE_OBJECT *CaseBlock = NULL;
392 ACPI_PARSE_OBJECT *DefaultOp = NULL;
393 ACPI_PARSE_OBJECT *CurrentParentNode;
394 ACPI_PARSE_OBJECT *Conditional = NULL;
395 ACPI_PARSE_OBJECT *Predicate;
396 ACPI_PARSE_OBJECT *Peer;
397 ACPI_PARSE_OBJECT *NewOp;
398 ACPI_PARSE_OBJECT *NewOp2;
399 ACPI_PARSE_OBJECT *MethodOp;
400 ACPI_PARSE_OBJECT *StoreOp;
401 ACPI_PARSE_OBJECT *BreakOp;
402 ACPI_PARSE_OBJECT *BufferOp;
403 char *PredicateValueName;
404 UINT16 Index;
405 UINT32 Btype;
406
407
408 /* Start node is the Switch() node */
409
410 CurrentParentNode = StartNode;
411
412 /* Create a new temp name of the form _T_x */
413
414 PredicateValueName = TrAmlGetNextTempName (StartNode, &Gbl_TempCount);
415 if (!PredicateValueName)
416 {
417 return;
418 }
419
420 /* First child is the Switch() predicate */
421
422 Next = StartNode->Asl.Child;
423
424 /*
425 * Examine the return type of the Switch Value -
426 * must be Integer/Buffer/String
427 */
428 Index = (UINT16) (Next->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE);
429 Btype = AslKeywordMapping[Index].AcpiBtype;
430 if ((Btype != ACPI_BTYPE_INTEGER) &&
431 (Btype != ACPI_BTYPE_STRING) &&
432 (Btype != ACPI_BTYPE_BUFFER))
433 {
434 AslError (ASL_WARNING, ASL_MSG_SWITCH_TYPE, Next, NULL);
435 Btype = ACPI_BTYPE_INTEGER;
436 }
437
438 /* CASE statements start at next child */
439
440 Peer = Next->Asl.Next;
441 while (Peer)
442 {
443 Next = Peer;
444 Peer = Next->Asl.Next;
445
446 if (Next->Asl.ParseOpcode == PARSEOP_CASE)
447 {
448 if (CaseOp)
449 {
450 /* Add an ELSE to complete the previous CASE */
451
452 NewOp = TrCreateLeafNode (PARSEOP_ELSE);
453 NewOp->Asl.Parent = Conditional->Asl.Parent;
454 TrAmlInitLineNumbers (NewOp, NewOp->Asl.Parent);
455
456 /* Link ELSE node as a peer to the previous IF */
457
458 TrAmlInsertPeer (Conditional, NewOp);
459 CurrentParentNode = NewOp;
460 }
461
462 CaseOp = Next;
463 Conditional = CaseOp;
464 CaseBlock = CaseOp->Asl.Child->Asl.Next;
465 Conditional->Asl.Child->Asl.Next = NULL;
466 Predicate = CaseOp->Asl.Child;
467
468 if ((Predicate->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
469 (Predicate->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
470 {
471 /*
472 * Convert the package declaration to this form:
473 *
474 * If (LNotEqual (Match (Package(<size>){<data>},
475 * MEQ, _T_x, MTR, Zero, Zero), Ones))
476 */
477 NewOp2 = TrCreateLeafNode (PARSEOP_MATCHTYPE_MEQ);
478 Predicate->Asl.Next = NewOp2;
479 TrAmlInitLineNumbers (NewOp2, Conditional);
480
481 NewOp = NewOp2;
482 NewOp2 = TrCreateValuedLeafNode (PARSEOP_NAMESTRING,
483 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
484 NewOp->Asl.Next = NewOp2;
485 TrAmlInitLineNumbers (NewOp2, Predicate);
486
487 NewOp = NewOp2;
488 NewOp2 = TrCreateLeafNode (PARSEOP_MATCHTYPE_MTR);
489 NewOp->Asl.Next = NewOp2;
490 TrAmlInitLineNumbers (NewOp2, Predicate);
491
492 NewOp = NewOp2;
493 NewOp2 = TrCreateLeafNode (PARSEOP_ZERO);
494 NewOp->Asl.Next = NewOp2;
495 TrAmlInitLineNumbers (NewOp2, Predicate);
496
497 NewOp = NewOp2;
498 NewOp2 = TrCreateLeafNode (PARSEOP_ZERO);
499 NewOp->Asl.Next = NewOp2;
500 TrAmlInitLineNumbers (NewOp2, Predicate);
501
502 NewOp2 = TrCreateLeafNode (PARSEOP_MATCH);
503 NewOp2->Asl.Child = Predicate; /* PARSEOP_PACKAGE */
504 TrAmlInitLineNumbers (NewOp2, Conditional);
505 TrAmlSetSubtreeParent (Predicate, NewOp2);
506
507 NewOp = NewOp2;
508 NewOp2 = TrCreateLeafNode (PARSEOP_ONES);
509 NewOp->Asl.Next = NewOp2;
510 TrAmlInitLineNumbers (NewOp2, Conditional);
511
512 NewOp2 = TrCreateLeafNode (PARSEOP_LEQUAL);
513 NewOp2->Asl.Child = NewOp;
514 NewOp->Asl.Parent = NewOp2;
515 TrAmlInitLineNumbers (NewOp2, Conditional);
516 TrAmlSetSubtreeParent (NewOp, NewOp2);
517
518 NewOp = NewOp2;
519 NewOp2 = TrCreateLeafNode (PARSEOP_LNOT);
520 NewOp2->Asl.Child = NewOp;
521 NewOp2->Asl.Parent = Conditional;
522 NewOp->Asl.Parent = NewOp2;
523 TrAmlInitLineNumbers (NewOp2, Conditional);
524
525 Conditional->Asl.Child = NewOp2;
526 NewOp2->Asl.Next = CaseBlock;
527 }
528 else
529 {
530 /*
531 * Integer and Buffer case.
532 *
533 * Change CaseOp() to: If (LEqual (SwitchValue, CaseValue)) {...}
534 * Note: SwitchValue is first to allow the CaseValue to be implicitly
535 * converted to the type of SwitchValue if necessary.
536 *
537 * CaseOp->Child is the case value
538 * CaseOp->Child->Peer is the beginning of the case block
539 */
540 NewOp = TrCreateValuedLeafNode (PARSEOP_NAMESTRING,
541 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
542 NewOp->Asl.Next = Predicate;
543 TrAmlInitLineNumbers (NewOp, Predicate);
544
545 NewOp2 = TrCreateLeafNode (PARSEOP_LEQUAL);
546 NewOp2->Asl.Parent = Conditional;
547 NewOp2->Asl.Child = NewOp;
548 TrAmlInitLineNumbers (NewOp2, Conditional);
549
550 TrAmlSetSubtreeParent (NewOp, NewOp2);
551
552 Predicate = NewOp2;
553 Predicate->Asl.Next = CaseBlock;
554
555 TrAmlSetSubtreeParent (Predicate, Conditional);
556 Conditional->Asl.Child = Predicate;
557 }
558
559 /* Reinitialize the CASE node to an IF node */
560
561 TrAmlInitNode (Conditional, PARSEOP_IF);
562
563 /*
564 * The first CASE(IF) is not nested under an ELSE.
565 * All other CASEs are children of a parent ELSE.
566 */
567 if (CurrentParentNode == StartNode)
568 {
569 Conditional->Asl.Next = NULL;
570 }
571 else
572 {
573 /*
574 * The IF is a child of previous IF/ELSE. It
575 * is therefore without peer.
576 */
577 CurrentParentNode->Asl.Child = Conditional;
578 Conditional->Asl.Parent = CurrentParentNode;
579 Conditional->Asl.Next = NULL;
580 }
581 }
582 else if (Next->Asl.ParseOpcode == PARSEOP_DEFAULT)
583 {
584 if (DefaultOp)
585 {
586 /*
587 * More than one Default
588 * (Parser does not catch this, must check here)
589 */
590 AslError (ASL_ERROR, ASL_MSG_MULTIPLE_DEFAULT, Next, NULL);
591 }
592 else
593 {
594 /* Save the DEFAULT node for later, after CASEs */
595
596 DefaultOp = Next;
597 }
598 }
599 else
600 {
601 /* Unknown peer opcode */
602
603 AcpiOsPrintf ("Unknown parse opcode for switch statement: %s (%u)\n",
604 Next->Asl.ParseOpName, Next->Asl.ParseOpcode);
605 }
606 }
607
608 /* Add the default case at the end of the if/else construct */
609
610 if (DefaultOp)
611 {
612 /* If no CASE statements, this is an error - see below */
613
614 if (CaseOp)
615 {
616 /* Convert the DEFAULT node to an ELSE */
617
618 TrAmlInitNode (DefaultOp, PARSEOP_ELSE);
619 DefaultOp->Asl.Parent = Conditional->Asl.Parent;
620
621 /* Link ELSE node as a peer to the previous IF */
622
623 TrAmlInsertPeer (Conditional, DefaultOp);
624 }
625 }
626
627 if (!CaseOp)
628 {
629 AslError (ASL_ERROR, ASL_MSG_NO_CASES, StartNode, NULL);
630 }
631
632
633 /*
634 * Create a Name(_T_x, ...) statement. This statement must appear at the
635 * method level, in case a loop surrounds the switch statement and could
636 * cause the name to be created twice (error).
637 */
638
639 /* Create the Name node */
640
641 Predicate = StartNode->Asl.Child;
642 NewOp = TrCreateLeafNode (PARSEOP_NAME);
643 TrAmlInitLineNumbers (NewOp, StartNode);
644
645 /* Find the parent method */
646
647 Next = StartNode;
648 while ((Next->Asl.ParseOpcode != PARSEOP_METHOD) &&
649 (Next->Asl.ParseOpcode != PARSEOP_DEFINITION_BLOCK))
650 {
651 Next = Next->Asl.Parent;
652 }
653 MethodOp = Next;
654
655 NewOp->Asl.CompileFlags |= NODE_COMPILER_EMITTED;
656 NewOp->Asl.Parent = Next;
657
658 /* Insert name after the method name and arguments */
659
660 Next = Next->Asl.Child; /* Name */
661 Next = Next->Asl.Next; /* NumArgs */
662 Next = Next->Asl.Next; /* SerializeRule */
663
664 /*
665 * If method is not Serialized, we must make is so, because of the way
666 * that Switch() must be implemented -- we cannot allow multiple threads
667 * to execute this method concurrently since we need to create local
668 * temporary name(s).
669 */
670 if (Next->Asl.ParseOpcode != PARSEOP_SERIALIZERULE_SERIAL)
671 {
672 AslError (ASL_REMARK, ASL_MSG_SERIALIZED, MethodOp,
673 "Due to use of Switch operator");
674 Next->Asl.ParseOpcode = PARSEOP_SERIALIZERULE_SERIAL;
675 }
676
677 Next = Next->Asl.Next; /* SyncLevel */
678 Next = Next->Asl.Next; /* ReturnType */
679 Next = Next->Asl.Next; /* ParameterTypes */
680
681 TrAmlInsertPeer (Next, NewOp);
682 TrAmlInitLineNumbers (NewOp, Next);
683
684 /* Create the NameSeg child for the Name node */
685
686 NewOp2 = TrCreateValuedLeafNode (PARSEOP_NAMESEG,
687 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
688 TrAmlInitLineNumbers (NewOp2, NewOp);
689 NewOp2->Asl.CompileFlags |= NODE_IS_NAME_DECLARATION;
690 NewOp->Asl.Child = NewOp2;
691
692 /* Create the initial value for the Name. Btype was already validated above */
693
694 switch (Btype)
695 {
696 case ACPI_BTYPE_INTEGER:
697
698 NewOp2->Asl.Next = TrCreateValuedLeafNode (PARSEOP_ZERO,
699 (UINT64) 0);
700 TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp);
701 break;
702
703 case ACPI_BTYPE_STRING:
704
705 NewOp2->Asl.Next = TrCreateValuedLeafNode (PARSEOP_STRING_LITERAL,
706 (UINT64) ACPI_TO_INTEGER (""));
707 TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp);
708 break;
709
710 case ACPI_BTYPE_BUFFER:
711
712 (void) TrLinkPeerNode (NewOp2, TrCreateValuedLeafNode (PARSEOP_BUFFER,
713 (UINT64) 0));
714 Next = NewOp2->Asl.Next;
715 TrAmlInitLineNumbers (Next, NewOp2);
716 (void) TrLinkChildren (Next, 1, TrCreateValuedLeafNode (PARSEOP_ZERO,
717 (UINT64) 1));
718 TrAmlInitLineNumbers (Next->Asl.Child, Next);
719
720 BufferOp = TrCreateValuedLeafNode (PARSEOP_DEFAULT_ARG, (UINT64) 0);
721 TrAmlInitLineNumbers (BufferOp, Next->Asl.Child);
722 (void) TrLinkPeerNode (Next->Asl.Child, BufferOp);
723
724 TrAmlSetSubtreeParent (Next->Asl.Child, Next);
725 break;
726
727 default:
728
729 break;
730 }
731
732 TrAmlSetSubtreeParent (NewOp2, NewOp);
733
734 /*
735 * Transform the Switch() into a While(One)-Break node.
736 * And create a Store() node which will be used to save the
737 * Switch() value. The store is of the form: Store (Value, _T_x)
738 * where _T_x is the temp variable.
739 */
740 TrAmlInitNode (StartNode, PARSEOP_WHILE);
741 NewOp = TrCreateLeafNode (PARSEOP_ONE);
742 TrAmlInitLineNumbers (NewOp, StartNode);
743 NewOp->Asl.Next = Predicate->Asl.Next;
744 NewOp->Asl.Parent = StartNode;
745 StartNode->Asl.Child = NewOp;
746
747 /* Create a Store() node */
748
749 StoreOp = TrCreateLeafNode (PARSEOP_STORE);
750 TrAmlInitLineNumbers (StoreOp, NewOp);
751 StoreOp->Asl.Parent = StartNode;
752 TrAmlInsertPeer (NewOp, StoreOp);
753
754 /* Complete the Store subtree */
755
756 StoreOp->Asl.Child = Predicate;
757 Predicate->Asl.Parent = StoreOp;
758
759 NewOp = TrCreateValuedLeafNode (PARSEOP_NAMESEG,
760 (UINT64) ACPI_TO_INTEGER (PredicateValueName));
761 TrAmlInitLineNumbers (NewOp, StoreOp);
762 NewOp->Asl.Parent = StoreOp;
763 Predicate->Asl.Next = NewOp;
764
765 /* Create a Break() node and insert it into the end of While() */
766
767 Conditional = StartNode->Asl.Child;
768 while (Conditional->Asl.Next)
769 {
770 Conditional = Conditional->Asl.Next;
771 }
772
773 BreakOp = TrCreateLeafNode (PARSEOP_BREAK);
774 TrAmlInitLineNumbers (BreakOp, NewOp);
775 BreakOp->Asl.Parent = StartNode;
776 TrAmlInsertPeer (Conditional, BreakOp);
777 }
778