1 /******************************************************************************
3 * Module Name: asltree - parse tree management
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include "aslcompiler.h"
45 #include "aslcompiler.y.h"
49 #define _COMPONENT ACPI_COMPILER
50 ACPI_MODULE_NAME ("asltree")
52 /* Local prototypes */
54 static ACPI_PARSE_OBJECT *
63 /*******************************************************************************
65 * FUNCTION: TrGetNextNode
69 * RETURN: New parse node. Aborts on allocation failure
71 * DESCRIPTION: Allocate a new parse node for the parse tree. Bypass the local
72 * dynamic memory manager for performance reasons (This has a
73 * major impact on the speed of the compiler.)
75 ******************************************************************************/
77 static ACPI_PARSE_OBJECT *
81 ASL_CACHE_INFO *Cache;
84 if (Gbl_ParseOpCacheNext >= Gbl_ParseOpCacheLast)
86 /* Allocate a new buffer */
88 Cache = UtLocalCalloc (sizeof (Cache->Next) +
89 (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE));
91 /* Link new cache buffer to head of list */
93 Cache->Next = Gbl_ParseOpCacheList;
94 Gbl_ParseOpCacheList = Cache;
96 /* Setup cache management pointers */
98 Gbl_ParseOpCacheNext = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, Cache->Buffer);
99 Gbl_ParseOpCacheLast = Gbl_ParseOpCacheNext + ASL_PARSEOP_CACHE_SIZE;
103 return (Gbl_ParseOpCacheNext++);
107 /*******************************************************************************
109 * FUNCTION: TrAllocateNode
111 * PARAMETERS: ParseOpcode - Opcode to be assigned to the node
113 * RETURN: New parse node. Aborts on allocation failure
115 * DESCRIPTION: Allocate and initialize a new parse node for the parse tree
117 ******************************************************************************/
123 ACPI_PARSE_OBJECT *Op;
126 Op = TrGetNextNode ();
128 Op->Asl.ParseOpcode = (UINT16) ParseOpcode;
129 Op->Asl.Filename = Gbl_Files[ASL_FILE_INPUT].Filename;
130 Op->Asl.LineNumber = Gbl_CurrentLineNumber;
131 Op->Asl.LogicalLineNumber = Gbl_LogicalLineNumber;
132 Op->Asl.LogicalByteOffset = Gbl_CurrentLineOffset;
133 Op->Asl.Column = Gbl_CurrentColumn;
135 UtSetParseOpName (Op);
140 /*******************************************************************************
142 * FUNCTION: TrReleaseNode
144 * PARAMETERS: Op - Op to be released
148 * DESCRIPTION: "release" a node. In truth, nothing is done since the node
149 * is part of a larger buffer
151 ******************************************************************************/
155 ACPI_PARSE_OBJECT *Op)
162 /*******************************************************************************
164 * FUNCTION: TrUpdateNode
166 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
167 * Op - An existing parse node
169 * RETURN: The updated node
171 * DESCRIPTION: Change the parse opcode assigned to a node. Usually used to
172 * change an opcode to DEFAULT_ARG so that the node is ignored
173 * during the code generation. Also used to set generic integers
174 * to a specific size (8, 16, 32, or 64 bits)
176 ******************************************************************************/
181 ACPI_PARSE_OBJECT *Op)
189 DbgPrint (ASL_PARSE_OUTPUT,
190 "\nUpdateNode: Old - %s, New - %s\n\n",
191 UtGetOpName (Op->Asl.ParseOpcode),
192 UtGetOpName (ParseOpcode));
194 /* Assign new opcode and name */
196 if (Op->Asl.ParseOpcode == PARSEOP_ONES)
200 case PARSEOP_BYTECONST:
202 Op->Asl.Value.Integer = ACPI_UINT8_MAX;
205 case PARSEOP_WORDCONST:
207 Op->Asl.Value.Integer = ACPI_UINT16_MAX;
210 case PARSEOP_DWORDCONST:
212 Op->Asl.Value.Integer = ACPI_UINT32_MAX;
215 /* Don't need to do the QWORD case */
219 /* Don't care about others */
224 Op->Asl.ParseOpcode = (UINT16) ParseOpcode;
225 UtSetParseOpName (Op);
228 * For the BYTE, WORD, and DWORD constants, make sure that the integer
229 * that was passed in will actually fit into the data type
233 case PARSEOP_BYTECONST:
235 UtCheckIntegerRange (Op, 0x00, ACPI_UINT8_MAX);
236 Op->Asl.Value.Integer &= ACPI_UINT8_MAX;
239 case PARSEOP_WORDCONST:
241 UtCheckIntegerRange (Op, 0x00, ACPI_UINT16_MAX);
242 Op->Asl.Value.Integer &= ACPI_UINT16_MAX;
245 case PARSEOP_DWORDCONST:
247 UtCheckIntegerRange (Op, 0x00, ACPI_UINT32_MAX);
248 Op->Asl.Value.Integer &= ACPI_UINT32_MAX;
253 /* Don't care about others, don't need to check QWORD */
262 /*******************************************************************************
264 * FUNCTION: TrGetNodeFlagName
266 * PARAMETERS: Flags - Flags word to be decoded
268 * RETURN: Name string. Always returns a valid string pointer.
270 * DESCRIPTION: Decode a flags word
272 ******************************************************************************/
283 return ("NODE_VISITED");
285 case NODE_AML_PACKAGE:
287 return ("NODE_AML_PACKAGE");
291 return ("NODE_IS_TARGET");
293 case NODE_IS_RESOURCE_DESC:
295 return ("NODE_IS_RESOURCE_DESC");
297 case NODE_IS_RESOURCE_FIELD:
299 return ("NODE_IS_RESOURCE_FIELD");
301 case NODE_HAS_NO_EXIT:
303 return ("NODE_HAS_NO_EXIT");
305 case NODE_IF_HAS_NO_EXIT:
307 return ("NODE_IF_HAS_NO_EXIT");
309 case NODE_NAME_INTERNALIZED:
311 return ("NODE_NAME_INTERNALIZED");
313 case NODE_METHOD_NO_RETVAL:
315 return ("NODE_METHOD_NO_RETVAL");
317 case NODE_METHOD_SOME_NO_RETVAL:
319 return ("NODE_METHOD_SOME_NO_RETVAL");
321 case NODE_RESULT_NOT_USED:
323 return ("NODE_RESULT_NOT_USED");
325 case NODE_METHOD_TYPED:
327 return ("NODE_METHOD_TYPED");
329 case NODE_COMPILE_TIME_CONST:
331 return ("NODE_COMPILE_TIME_CONST");
333 case NODE_IS_TERM_ARG:
335 return ("NODE_IS_TERM_ARG");
337 case NODE_WAS_ONES_OP:
339 return ("NODE_WAS_ONES_OP");
341 case NODE_IS_NAME_DECLARATION:
343 return ("NODE_IS_NAME_DECLARATION");
347 return ("Multiple Flags (or unknown flag) set");
352 /*******************************************************************************
354 * FUNCTION: TrSetNodeFlags
356 * PARAMETERS: Op - An existing parse node
357 * Flags - New flags word
359 * RETURN: The updated parser op
361 * DESCRIPTION: Set bits in the node flags word. Will not clear bits, only set
363 ******************************************************************************/
367 ACPI_PARSE_OBJECT *Op,
371 DbgPrint (ASL_PARSE_OUTPUT,
372 "\nSetNodeFlags: Op %p, %8.8X %s\n\n", Op, Flags,
373 TrGetNodeFlagName (Flags));
380 Op->Asl.CompileFlags |= Flags;
385 /*******************************************************************************
387 * FUNCTION: TrSetNodeAmlLength
389 * PARAMETERS: Op - An existing parse node
390 * Length - AML Length
392 * RETURN: The updated parser op
394 * DESCRIPTION: Set the AML Length in a node. Used by the parser to indicate
395 * the presence of a node that must be reduced to a fixed length
398 ******************************************************************************/
402 ACPI_PARSE_OBJECT *Op,
406 DbgPrint (ASL_PARSE_OUTPUT,
407 "\nSetNodeAmlLength: Op %p, %8.8X\n", Op, Length);
414 Op->Asl.AmlLength = Length;
419 /*******************************************************************************
421 * FUNCTION: TrSetEndLineNumber
423 * PARAMETERS: Op - An existing parse node
427 * DESCRIPTION: Set the ending line numbers (file line and logical line) of a
428 * parse node to the current line numbers.
430 ******************************************************************************/
434 ACPI_PARSE_OBJECT *Op)
437 /* If the end line # is already set, just return */
444 Op->Asl.EndLine = Gbl_CurrentLineNumber;
445 Op->Asl.EndLogicalLine = Gbl_LogicalLineNumber;
449 /*******************************************************************************
451 * FUNCTION: TrCreateAssignmentNode
453 * PARAMETERS: Target - Assignment target
454 * Source - Assignment source
456 * RETURN: Pointer to the new node. Aborts on allocation failure
458 * DESCRIPTION: Implements the C-style '=' operator. It changes the parse
459 * tree if possible to utilize the last argument of the math
460 * operators which is a target operand -- thus saving invocation
461 * of and additional Store() operator. An optimization.
463 ******************************************************************************/
466 TrCreateAssignmentNode (
467 ACPI_PARSE_OBJECT *Target,
468 ACPI_PARSE_OBJECT *Source)
470 ACPI_PARSE_OBJECT *TargetOp;
471 ACPI_PARSE_OBJECT *SourceOp1;
472 ACPI_PARSE_OBJECT *SourceOp2;
473 ACPI_PARSE_OBJECT *Operator;
476 DbgPrint (ASL_PARSE_OUTPUT,
477 "\nTrCreateAssignmentNode Line [%u to %u] Source %s Target %s\n",
478 Source->Asl.LineNumber, Source->Asl.EndLine,
479 UtGetOpName (Source->Asl.ParseOpcode),
480 UtGetOpName (Target->Asl.ParseOpcode));
482 TrSetNodeFlags (Target, NODE_IS_TARGET);
484 switch (Source->Asl.ParseOpcode)
487 * Only these operators can be optimized because they have
494 case PARSEOP_MULTIPLY:
497 case PARSEOP_SHIFTLEFT:
498 case PARSEOP_SHIFTRIGHT:
499 case PARSEOP_SUBTRACT:
504 /* Otherwise, just create a normal Store operator */
512 * Transform the parse tree such that the target is moved to the
513 * last operand of the operator
515 SourceOp1 = Source->Asl.Child;
516 SourceOp2 = SourceOp1->Asl.Next;
518 /* NOT only has one operand, but has a target */
520 if (Source->Asl.ParseOpcode == PARSEOP_NOT)
522 SourceOp2 = SourceOp1;
525 /* DIVIDE has an extra target operand (remainder) */
527 if (Source->Asl.ParseOpcode == PARSEOP_DIVIDE)
529 SourceOp2 = SourceOp2->Asl.Next;
532 TargetOp = SourceOp2->Asl.Next;
535 * Can't perform this optimization if there already is a target
536 * for the operator (ZERO is a "no target" placeholder).
538 if (TargetOp->Asl.ParseOpcode != PARSEOP_ZERO)
543 /* Link in the target as the final operand */
545 SourceOp2->Asl.Next = Target;
546 Target->Asl.Parent = Source;
553 Operator = TrAllocateNode (PARSEOP_STORE);
554 TrLinkChildren (Operator, 2, Source, Target);
556 /* Set the appropriate line numbers for the new node */
558 Operator->Asl.LineNumber = Target->Asl.LineNumber;
559 Operator->Asl.LogicalLineNumber = Target->Asl.LogicalLineNumber;
560 Operator->Asl.LogicalByteOffset = Target->Asl.LogicalByteOffset;
561 Operator->Asl.Column = Target->Asl.Column;
567 /*******************************************************************************
569 * FUNCTION: TrCreateLeafNode
571 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
573 * RETURN: Pointer to the new node. Aborts on allocation failure
575 * DESCRIPTION: Create a simple leaf node (no children or peers, and no value
576 * assigned to the node)
578 ******************************************************************************/
584 ACPI_PARSE_OBJECT *Op;
587 Op = TrAllocateNode (ParseOpcode);
589 DbgPrint (ASL_PARSE_OUTPUT,
590 "\nCreateLeafNode Ln/Col %u/%u NewNode %p Op %s\n\n",
591 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode));
597 /*******************************************************************************
599 * FUNCTION: TrCreateConstantLeafNode
601 * PARAMETERS: ParseOpcode - The constant opcode
603 * RETURN: Pointer to the new node. Aborts on allocation failure
605 * DESCRIPTION: Create a leaf node (no children or peers) for one of the
606 * special constants - __LINE__, __FILE__, and __DATE__.
608 * Note: An implemenation of __FUNC__ cannot happen here because we don't
609 * have a full parse tree at this time and cannot find the parent control
610 * method. If it is ever needed, __FUNC__ must be implemented later, after
611 * the parse tree has been fully constructed.
613 ******************************************************************************/
616 TrCreateConstantLeafNode (
619 ACPI_PARSE_OBJECT *Op = NULL;
621 char *StaticTimeString;
629 case PARSEOP___LINE__:
631 Op = TrAllocateNode (PARSEOP_INTEGER);
632 Op->Asl.Value.Integer = Op->Asl.LineNumber;
635 case PARSEOP___PATH__:
637 Op = TrAllocateNode (PARSEOP_STRING_LITERAL);
639 /* Op.Asl.Filename contains the full pathname to the file */
641 Op->Asl.Value.String = Op->Asl.Filename;
644 case PARSEOP___FILE__:
646 Op = TrAllocateNode (PARSEOP_STRING_LITERAL);
648 /* Get the simple filename from the full path */
650 FlSplitInputPathname (Op->Asl.Filename, &Path, &Filename);
651 Op->Asl.Value.String = Filename;
654 case PARSEOP___DATE__:
656 Op = TrAllocateNode (PARSEOP_STRING_LITERAL);
658 /* Get a copy of the current time */
660 CurrentTime = time (NULL);
661 StaticTimeString = ctime (&CurrentTime);
662 TimeString = UtLocalCalloc (strlen (StaticTimeString) + 1);
663 strcpy (TimeString, StaticTimeString);
665 TimeString[strlen(TimeString) -1] = 0; /* Remove trailing newline */
666 Op->Asl.Value.String = TimeString;
669 default: /* This would be an internal error */
674 DbgPrint (ASL_PARSE_OUTPUT,
675 "\nCreateConstantLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X ",
676 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode),
677 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
682 /*******************************************************************************
684 * FUNCTION: TrCreateTargetOperand
686 * PARAMETERS: OriginalOp - Op to be copied
688 * RETURN: Pointer to the new node. Aborts on allocation failure
690 * DESCRIPTION: Copy an existing node (and subtree). Used in ASL+ (C-style)
691 * expressions where the target is the same as one of the
692 * operands. A new node and subtree must be created from the
693 * original so that the parse tree can be linked properly.
695 * NOTE: This code is specific to target operands that are the last
696 * operand in an ASL/AML operator. Meaning that the top-level
697 * parse Op in a possible subtree has a NULL Next pointer.
698 * This simplifies the recursion.
701 * DeRefOf (Local1) += 32
703 * This gets converted to:
704 * Add (DeRefOf (Local1), 32, DeRefOf (Local1))
706 * Each DeRefOf has a single child, Local1. Even more complex
707 * subtrees can be created via the Index and DeRefOf operators.
709 ******************************************************************************/
712 TrCreateTargetOperand (
713 ACPI_PARSE_OBJECT *OriginalOp,
714 ACPI_PARSE_OBJECT *ParentOp)
716 ACPI_PARSE_OBJECT *Op;
724 Op = TrGetNextNode ();
726 /* Copy the pertinent values (omit link pointer fields) */
728 Op->Asl.Value = OriginalOp->Asl.Value;
729 Op->Asl.Filename = OriginalOp->Asl.Filename;
730 Op->Asl.LineNumber = OriginalOp->Asl.LineNumber;
731 Op->Asl.LogicalLineNumber = OriginalOp->Asl.LogicalLineNumber;
732 Op->Asl.LogicalByteOffset = OriginalOp->Asl.LogicalByteOffset;
733 Op->Asl.Column = OriginalOp->Asl.Column;
734 Op->Asl.Flags = OriginalOp->Asl.Flags;
735 Op->Asl.CompileFlags = OriginalOp->Asl.CompileFlags;
736 Op->Asl.AmlOpcode = OriginalOp->Asl.AmlOpcode;
737 Op->Asl.ParseOpcode = OriginalOp->Asl.ParseOpcode;
738 Op->Asl.Parent = ParentOp;
739 UtSetParseOpName (Op);
741 /* Copy a possible subtree below this node */
743 if (OriginalOp->Asl.Child)
745 Op->Asl.Child = TrCreateTargetOperand (OriginalOp->Asl.Child, Op);
748 if (OriginalOp->Asl.Next) /* Null for top-level node */
750 Op->Asl.Next = TrCreateTargetOperand (OriginalOp->Asl.Next, ParentOp);
757 /*******************************************************************************
759 * FUNCTION: TrCreateValuedLeafNode
761 * PARAMETERS: ParseOpcode - New opcode to be assigned to the node
762 * Value - Value to be assigned to the node
764 * RETURN: Pointer to the new node. Aborts on allocation failure
766 * DESCRIPTION: Create a leaf node (no children or peers) with a value
769 ******************************************************************************/
772 TrCreateValuedLeafNode (
776 ACPI_PARSE_OBJECT *Op;
779 Op = TrAllocateNode (ParseOpcode);
781 DbgPrint (ASL_PARSE_OUTPUT,
782 "\nCreateValuedLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X ",
783 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode),
784 ACPI_FORMAT_UINT64 (Value));
785 Op->Asl.Value.Integer = Value;
789 case PARSEOP_STRING_LITERAL:
791 DbgPrint (ASL_PARSE_OUTPUT, "STRING->%s", Value);
794 case PARSEOP_NAMESEG:
796 DbgPrint (ASL_PARSE_OUTPUT, "NAMESEG->%s", Value);
799 case PARSEOP_NAMESTRING:
801 DbgPrint (ASL_PARSE_OUTPUT, "NAMESTRING->%s", Value);
806 DbgPrint (ASL_PARSE_OUTPUT, "EISAID->%s", Value);
811 DbgPrint (ASL_PARSE_OUTPUT, "METHOD");
814 case PARSEOP_INTEGER:
816 DbgPrint (ASL_PARSE_OUTPUT, "INTEGER");
824 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
829 /*******************************************************************************
831 * FUNCTION: TrCreateNode
833 * PARAMETERS: ParseOpcode - Opcode to be assigned to the node
834 * NumChildren - Number of children to follow
835 * ... - A list of child nodes to link to the new
836 * node. NumChildren long.
838 * RETURN: Pointer to the new node. Aborts on allocation failure
840 * DESCRIPTION: Create a new parse node and link together a list of child
841 * nodes underneath the new node.
843 ******************************************************************************/
851 ACPI_PARSE_OBJECT *Op;
852 ACPI_PARSE_OBJECT *Child;
853 ACPI_PARSE_OBJECT *PrevChild;
859 va_start (ap, NumChildren);
861 /* Allocate one new node */
863 Op = TrAllocateNode (ParseOpcode);
865 DbgPrint (ASL_PARSE_OUTPUT,
866 "\nCreateNode Ln/Col %u/%u NewParent %p Child %u Op %s ",
867 Op->Asl.LineNumber, Op->Asl.Column, Op, NumChildren, UtGetOpName(ParseOpcode));
869 /* Some extra debug output based on the parse opcode */
873 case PARSEOP_DEFINITIONBLOCK:
876 DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
879 case PARSEOP_OPERATIONREGION:
881 DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
886 DbgPrint (ASL_PARSE_OUTPUT, "OR->");
891 /* Nothing to do for other opcodes */
896 /* Link the new node to its children */
900 for (i = 0; i < NumChildren; i++)
902 /* Get the next child */
904 Child = va_arg (ap, ACPI_PARSE_OBJECT *);
905 DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
908 * If child is NULL, this means that an optional argument
909 * was omitted. We must create a placeholder with a special
910 * opcode (DEFAULT_ARG) so that the code generator will know
911 * that it must emit the correct default for this argument
915 Child = TrAllocateNode (PARSEOP_DEFAULT_ARG);
918 /* Link first child to parent */
923 Op->Asl.Child = Child;
926 /* Point all children to parent */
928 Child->Asl.Parent = Op;
930 /* Link children in a peer list */
934 PrevChild->Asl.Next = Child;
938 * This child might be a list, point all nodes in the list
941 while (Child->Asl.Next)
943 Child = Child->Asl.Next;
944 Child->Asl.Parent = Op;
951 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
956 /*******************************************************************************
958 * FUNCTION: TrLinkChildren
960 * PARAMETERS: Op - An existing parse node
961 * NumChildren - Number of children to follow
962 * ... - A list of child nodes to link to the new
963 * node. NumChildren long.
965 * RETURN: The updated (linked) node
967 * DESCRIPTION: Link a group of nodes to an existing parse node
969 ******************************************************************************/
973 ACPI_PARSE_OBJECT *Op,
977 ACPI_PARSE_OBJECT *Child;
978 ACPI_PARSE_OBJECT *PrevChild;
984 va_start (ap, NumChildren);
987 TrSetEndLineNumber (Op);
989 DbgPrint (ASL_PARSE_OUTPUT,
990 "\nLinkChildren Line [%u to %u] NewParent %p Child %u Op %s ",
991 Op->Asl.LineNumber, Op->Asl.EndLine,
992 Op, NumChildren, UtGetOpName(Op->Asl.ParseOpcode));
994 switch (Op->Asl.ParseOpcode)
996 case PARSEOP_DEFINITIONBLOCK:
999 DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
1002 case PARSEOP_OPERATIONREGION:
1004 DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
1009 DbgPrint (ASL_PARSE_OUTPUT, "OR->");
1014 /* Nothing to do for other opcodes */
1019 /* Link the new node to it's children */
1023 for (i = 0; i < NumChildren; i++)
1025 Child = va_arg (ap, ACPI_PARSE_OBJECT *);
1027 if ((Child == PrevChild) && (Child != NULL))
1029 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Child,
1030 "Child node list invalid");
1035 DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
1038 * If child is NULL, this means that an optional argument
1039 * was omitted. We must create a placeholder with a special
1040 * opcode (DEFAULT_ARG) so that the code generator will know
1041 * that it must emit the correct default for this argument
1045 Child = TrAllocateNode (PARSEOP_DEFAULT_ARG);
1048 /* Link first child to parent */
1053 Op->Asl.Child = Child;
1056 /* Point all children to parent */
1058 Child->Asl.Parent = Op;
1060 /* Link children in a peer list */
1064 PrevChild->Asl.Next = Child;
1068 * This child might be a list, point all nodes in the list
1069 * to the same parent
1071 while (Child->Asl.Next)
1073 Child = Child->Asl.Next;
1074 Child->Asl.Parent = Op;
1080 DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
1085 /*******************************************************************************
1087 * FUNCTION: TrLinkPeerNode
1089 * PARAMETERS: Op1 - First peer
1092 * RETURN: Op1 or the non-null node.
1094 * DESCRIPTION: Link two nodes as peers. Handles cases where one peer is null.
1096 ******************************************************************************/
1100 ACPI_PARSE_OBJECT *Op1,
1101 ACPI_PARSE_OBJECT *Op2)
1103 ACPI_PARSE_OBJECT *Next;
1106 DbgPrint (ASL_PARSE_OUTPUT,
1107 "\nLinkPeerNode: 1=%p (%s), 2=%p (%s)\n\n",
1108 Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode) : NULL,
1109 Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode) : NULL);
1112 if ((!Op1) && (!Op2))
1114 DbgPrint (ASL_PARSE_OUTPUT, "\nTwo Null nodes!\n");
1118 /* If one of the nodes is null, just return the non-null node */
1132 DbgPrint (ASL_DEBUG_OUTPUT,
1133 "\n\n************* Internal error, linking node to itself %p\n\n\n",
1135 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op1,
1136 "Linking node to itself");
1140 Op1->Asl.Parent = Op2->Asl.Parent;
1143 * Op 1 may already have a peer list (such as an IF/ELSE pair),
1144 * so we must walk to the end of the list and attach the new
1148 while (Next->Asl.Next)
1150 Next = Next->Asl.Next;
1153 Next->Asl.Next = Op2;
1158 /*******************************************************************************
1160 * FUNCTION: TrLinkPeerNodes
1162 * PARAMETERS: NumPeers - The number of nodes in the list to follow
1163 * ... - A list of nodes to link together as peers
1165 * RETURN: The first node in the list (head of the peer list)
1167 * DESCRIPTION: Link together an arbitrary number of peer nodes.
1169 ******************************************************************************/
1176 ACPI_PARSE_OBJECT *This;
1177 ACPI_PARSE_OBJECT *Next;
1180 ACPI_PARSE_OBJECT *Start;
1183 DbgPrint (ASL_PARSE_OUTPUT,
1184 "\nLinkPeerNodes: (%u) ", NumPeers);
1186 va_start (ap, NumPeers);
1187 This = va_arg (ap, ACPI_PARSE_OBJECT *);
1193 for (i = 0; i < (NumPeers -1); i++)
1195 DbgPrint (ASL_PARSE_OUTPUT, "%u=%p ", (i+1), This);
1197 while (This->Asl.Next)
1199 This = This->Asl.Next;
1202 /* Get another peer node */
1204 Next = va_arg (ap, ACPI_PARSE_OBJECT *);
1207 Next = TrAllocateNode (PARSEOP_DEFAULT_ARG);
1210 /* link new node to the current node */
1212 This->Asl.Next = Next;
1217 DbgPrint (ASL_PARSE_OUTPUT,"\n\n");
1222 /*******************************************************************************
1224 * FUNCTION: TrLinkChildNode
1226 * PARAMETERS: Op1 - Parent node
1227 * Op2 - Op to become a child
1229 * RETURN: The parent node
1231 * DESCRIPTION: Link two nodes together as a parent and child
1233 ******************************************************************************/
1237 ACPI_PARSE_OBJECT *Op1,
1238 ACPI_PARSE_OBJECT *Op2)
1240 ACPI_PARSE_OBJECT *Next;
1243 DbgPrint (ASL_PARSE_OUTPUT,
1244 "\nLinkChildNode: Parent=%p (%s), Child=%p (%s)\n\n",
1245 Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode): NULL,
1246 Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode): NULL);
1253 Op1->Asl.Child = Op2;
1255 /* Set the child and all peers of the child to point to the parent */
1260 Next->Asl.Parent = Op1;
1261 Next = Next->Asl.Next;
1268 /*******************************************************************************
1270 * FUNCTION: TrWalkParseTree
1272 * PARAMETERS: Visitation - Type of walk
1273 * DescendingCallback - Called during tree descent
1274 * AscendingCallback - Called during tree ascent
1275 * Context - To be passed to the callbacks
1277 * RETURN: Status from callback(s)
1279 * DESCRIPTION: Walk the entire parse tree.
1281 ******************************************************************************/
1285 ACPI_PARSE_OBJECT *Op,
1287 ASL_WALK_CALLBACK DescendingCallback,
1288 ASL_WALK_CALLBACK AscendingCallback,
1292 BOOLEAN NodePreviouslyVisited;
1293 ACPI_PARSE_OBJECT *StartOp = Op;
1303 NodePreviouslyVisited = FALSE;
1307 case ASL_WALK_VISIT_DOWNWARD:
1311 if (!NodePreviouslyVisited)
1313 /* Let the callback process the node. */
1315 Status = DescendingCallback (Op, Level, Context);
1316 if (ACPI_SUCCESS (Status))
1318 /* Visit children first, once */
1327 else if (Status != AE_CTRL_DEPTH)
1329 /* Exit immediately on any error */
1335 /* Terminate walk at start op */
1342 /* No more children, visit peers */
1347 NodePreviouslyVisited = FALSE;
1351 /* No children or peers, re-visit parent */
1357 Op = Op->Asl.Parent;
1358 NodePreviouslyVisited = TRUE;
1363 case ASL_WALK_VISIT_UPWARD:
1367 /* Visit leaf node (no children) or parent node on return trip */
1369 if ((!Op->Asl.Child) ||
1370 (NodePreviouslyVisited))
1372 /* Let the callback process the node. */
1374 Status = AscendingCallback (Op, Level, Context);
1375 if (ACPI_FAILURE (Status))
1382 /* Visit children first, once */
1389 /* Terminate walk at start op */
1396 /* No more children, visit peers */
1401 NodePreviouslyVisited = FALSE;
1405 /* No children or peers, re-visit parent */
1411 Op = Op->Asl.Parent;
1412 NodePreviouslyVisited = TRUE;
1417 case ASL_WALK_VISIT_TWICE:
1421 if (NodePreviouslyVisited)
1423 Status = AscendingCallback (Op, Level, Context);
1424 if (ACPI_FAILURE (Status))
1431 /* Let the callback process the node. */
1433 Status = DescendingCallback (Op, Level, Context);
1434 if (ACPI_SUCCESS (Status))
1436 /* Visit children first, once */
1445 else if (Status != AE_CTRL_DEPTH)
1447 /* Exit immediately on any error */
1453 /* Terminate walk at start op */
1460 /* No more children, visit peers */
1465 NodePreviouslyVisited = FALSE;
1469 /* No children or peers, re-visit parent */
1475 Op = Op->Asl.Parent;
1476 NodePreviouslyVisited = TRUE;
1482 /* No other types supported */
1486 /* If we get here, the walk completed with no errors */