Home | History | Annotate | Line # | Download | only in compiler
asltree.c revision 1.4.2.5
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: asltree - parse tree management
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7      1.2  christos /*
      8  1.4.2.4     skrll  * Copyright (C) 2000 - 2017, Intel Corp.
      9      1.1    jruoho  * All rights reserved.
     10      1.1    jruoho  *
     11      1.2  christos  * Redistribution and use in source and binary forms, with or without
     12      1.2  christos  * modification, are permitted provided that the following conditions
     13      1.2  christos  * are met:
     14      1.2  christos  * 1. Redistributions of source code must retain the above copyright
     15      1.2  christos  *    notice, this list of conditions, and the following disclaimer,
     16      1.2  christos  *    without modification.
     17      1.2  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.2  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.2  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.2  christos  *    including a substantially similar Disclaimer requirement for further
     21      1.2  christos  *    binary redistribution.
     22      1.2  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.2  christos  *    of any contributors may be used to endorse or promote products derived
     24      1.2  christos  *    from this software without specific prior written permission.
     25      1.2  christos  *
     26      1.2  christos  * Alternatively, this software may be distributed under the terms of the
     27      1.2  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.2  christos  * Software Foundation.
     29      1.2  christos  *
     30      1.2  christos  * NO WARRANTY
     31      1.2  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.2  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.2  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.2  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.2  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.2  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.2  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.2  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.2  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.2  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.2  christos  * POSSIBILITY OF SUCH DAMAGES.
     42      1.2  christos  */
     43      1.1    jruoho 
     44      1.1    jruoho #include "aslcompiler.h"
     45      1.1    jruoho #include "aslcompiler.y.h"
     46      1.3  christos #include "acapps.h"
     47  1.4.2.5     skrll #include "acconvert.h"
     48      1.2  christos #include <time.h>
     49      1.1    jruoho 
     50      1.1    jruoho #define _COMPONENT          ACPI_COMPILER
     51      1.1    jruoho         ACPI_MODULE_NAME    ("asltree")
     52      1.1    jruoho 
     53      1.1    jruoho /* Local prototypes */
     54      1.1    jruoho 
     55      1.1    jruoho static ACPI_PARSE_OBJECT *
     56      1.1    jruoho TrGetNextNode (
     57      1.1    jruoho     void);
     58      1.1    jruoho 
     59      1.1    jruoho 
     60      1.1    jruoho /*******************************************************************************
     61      1.1    jruoho  *
     62  1.4.2.3     skrll  * FUNCTION:    TrSetParent
     63  1.4.2.3     skrll  *
     64  1.4.2.3     skrll  * PARAMETERS:  Op                  - To be set to new parent
     65  1.4.2.3     skrll  *              ParentOp            - The parent
     66  1.4.2.3     skrll  *
     67  1.4.2.3     skrll  * RETURN:      None, sets Op parent directly
     68  1.4.2.3     skrll  *
     69  1.4.2.3     skrll  * DESCRIPTION: Change the parent of a parse op.
     70  1.4.2.3     skrll  *
     71  1.4.2.3     skrll  ******************************************************************************/
     72  1.4.2.3     skrll 
     73  1.4.2.3     skrll void
     74  1.4.2.3     skrll TrSetParent (
     75  1.4.2.3     skrll     ACPI_PARSE_OBJECT       *Op,
     76  1.4.2.3     skrll     ACPI_PARSE_OBJECT       *ParentOp)
     77  1.4.2.3     skrll {
     78  1.4.2.3     skrll 
     79  1.4.2.3     skrll     Op->Asl.Parent = ParentOp;
     80  1.4.2.3     skrll }
     81  1.4.2.3     skrll 
     82  1.4.2.3     skrll 
     83  1.4.2.3     skrll /*******************************************************************************
     84  1.4.2.3     skrll  *
     85      1.1    jruoho  * FUNCTION:    TrGetNextNode
     86      1.1    jruoho  *
     87      1.1    jruoho  * PARAMETERS:  None
     88      1.1    jruoho  *
     89      1.3  christos  * RETURN:      New parse node. Aborts on allocation failure
     90      1.1    jruoho  *
     91      1.3  christos  * DESCRIPTION: Allocate a new parse node for the parse tree. Bypass the local
     92      1.1    jruoho  *              dynamic memory manager for performance reasons (This has a
     93      1.1    jruoho  *              major impact on the speed of the compiler.)
     94      1.1    jruoho  *
     95      1.1    jruoho  ******************************************************************************/
     96      1.1    jruoho 
     97      1.1    jruoho static ACPI_PARSE_OBJECT *
     98      1.1    jruoho TrGetNextNode (
     99      1.1    jruoho     void)
    100      1.1    jruoho {
    101      1.4  christos     ASL_CACHE_INFO          *Cache;
    102      1.4  christos 
    103      1.1    jruoho 
    104      1.4  christos     if (Gbl_ParseOpCacheNext >= Gbl_ParseOpCacheLast)
    105      1.1    jruoho     {
    106      1.4  christos         /* Allocate a new buffer */
    107      1.4  christos 
    108      1.4  christos         Cache = UtLocalCalloc (sizeof (Cache->Next) +
    109      1.4  christos             (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE));
    110      1.4  christos 
    111      1.4  christos         /* Link new cache buffer to head of list */
    112      1.4  christos 
    113      1.4  christos         Cache->Next = Gbl_ParseOpCacheList;
    114      1.4  christos         Gbl_ParseOpCacheList = Cache;
    115      1.4  christos 
    116      1.4  christos         /* Setup cache management pointers */
    117      1.4  christos 
    118      1.4  christos         Gbl_ParseOpCacheNext = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, Cache->Buffer);
    119      1.4  christos         Gbl_ParseOpCacheLast = Gbl_ParseOpCacheNext + ASL_PARSEOP_CACHE_SIZE;
    120      1.1    jruoho     }
    121      1.1    jruoho 
    122      1.4  christos     Gbl_ParseOpCount++;
    123      1.4  christos     return (Gbl_ParseOpCacheNext++);
    124      1.1    jruoho }
    125      1.1    jruoho 
    126      1.1    jruoho 
    127      1.1    jruoho /*******************************************************************************
    128      1.1    jruoho  *
    129      1.1    jruoho  * FUNCTION:    TrAllocateNode
    130      1.1    jruoho  *
    131      1.1    jruoho  * PARAMETERS:  ParseOpcode         - Opcode to be assigned to the node
    132      1.1    jruoho  *
    133      1.3  christos  * RETURN:      New parse node. Aborts on allocation failure
    134      1.1    jruoho  *
    135      1.1    jruoho  * DESCRIPTION: Allocate and initialize a new parse node for the parse tree
    136      1.1    jruoho  *
    137      1.1    jruoho  ******************************************************************************/
    138      1.1    jruoho 
    139      1.1    jruoho ACPI_PARSE_OBJECT *
    140      1.1    jruoho TrAllocateNode (
    141      1.1    jruoho     UINT32                  ParseOpcode)
    142      1.1    jruoho {
    143      1.1    jruoho     ACPI_PARSE_OBJECT       *Op;
    144  1.4.2.5     skrll     ACPI_PARSE_OBJECT       *LatestNode;
    145      1.1    jruoho 
    146      1.1    jruoho 
    147      1.1    jruoho     Op = TrGetNextNode ();
    148      1.1    jruoho 
    149      1.1    jruoho     Op->Asl.ParseOpcode       = (UINT16) ParseOpcode;
    150      1.1    jruoho     Op->Asl.Filename          = Gbl_Files[ASL_FILE_INPUT].Filename;
    151      1.1    jruoho     Op->Asl.LineNumber        = Gbl_CurrentLineNumber;
    152      1.1    jruoho     Op->Asl.LogicalLineNumber = Gbl_LogicalLineNumber;
    153      1.1    jruoho     Op->Asl.LogicalByteOffset = Gbl_CurrentLineOffset;
    154      1.1    jruoho     Op->Asl.Column            = Gbl_CurrentColumn;
    155      1.1    jruoho 
    156      1.1    jruoho     UtSetParseOpName (Op);
    157  1.4.2.5     skrll 
    158  1.4.2.5     skrll     /* The following is for capturing comments */
    159  1.4.2.5     skrll 
    160  1.4.2.5     skrll     if(Gbl_CaptureComments)
    161  1.4.2.5     skrll     {
    162  1.4.2.5     skrll         LatestNode = Gbl_CommentState.Latest_Parse_Node;
    163  1.4.2.5     skrll         Op->Asl.InlineComment     = NULL;
    164  1.4.2.5     skrll         Op->Asl.EndNodeComment    = NULL;
    165  1.4.2.5     skrll         Op->Asl.CommentList       = NULL;
    166  1.4.2.5     skrll         Op->Asl.FileChanged       = FALSE;
    167  1.4.2.5     skrll 
    168  1.4.2.5     skrll         /*
    169  1.4.2.5     skrll          * Check to see if the file name has changed before resetting the
    170  1.4.2.5     skrll          * latest parse node.
    171  1.4.2.5     skrll          */
    172  1.4.2.5     skrll         if (LatestNode &&
    173  1.4.2.5     skrll             (ParseOpcode != PARSEOP_INCLUDE) &&
    174  1.4.2.5     skrll             (ParseOpcode != PARSEOP_INCLUDE_END) &&
    175  1.4.2.5     skrll             strcmp (LatestNode->Asl.Filename, Op->Asl.Filename))
    176  1.4.2.5     skrll         {
    177  1.4.2.5     skrll             CvDbgPrint ("latest node: %s\n", LatestNode->Asl.ParseOpName);
    178  1.4.2.5     skrll             Op->Asl.FileChanged = TRUE;
    179  1.4.2.5     skrll             if (Gbl_IncludeFileStack)
    180  1.4.2.5     skrll             {
    181  1.4.2.5     skrll                 Op->Asl.ParentFilename = Gbl_IncludeFileStack->Filename;
    182  1.4.2.5     skrll             }
    183  1.4.2.5     skrll             else
    184  1.4.2.5     skrll             {
    185  1.4.2.5     skrll                 Op->Asl.ParentFilename = NULL;
    186  1.4.2.5     skrll             }
    187  1.4.2.5     skrll         }
    188  1.4.2.5     skrll 
    189  1.4.2.5     skrll         Gbl_CommentState.Latest_Parse_Node = Op;
    190  1.4.2.5     skrll 	CvDbgPrint ("trallocatenode=Set latest parse node to this node.\n");
    191  1.4.2.5     skrll 	CvDbgPrint ("           Op->Asl.ParseOpName = %s\n",
    192  1.4.2.5     skrll 	    Gbl_CommentState.Latest_Parse_Node->Asl.ParseOpName);
    193  1.4.2.5     skrll 	CvDbgPrint ("           Op->Asl.ParseOpcode = 0x%x\n", ParseOpcode);
    194  1.4.2.5     skrll 
    195  1.4.2.5     skrll 	if (Op->Asl.FileChanged)
    196  1.4.2.5     skrll 	{
    197  1.4.2.5     skrll 	    CvDbgPrint("    file has been changed!\n");
    198  1.4.2.5     skrll 	}
    199  1.4.2.5     skrll 
    200  1.4.2.5     skrll         /*
    201  1.4.2.5     skrll          * if this parse op's syntax uses () and {} (i.e. Package(1){0x00}) then
    202  1.4.2.5     skrll          * set a flag in the comment state. This facilitates paring comments for
    203  1.4.2.5     skrll          * these types of opcodes.
    204  1.4.2.5     skrll          */
    205  1.4.2.5     skrll         if ((CvParseOpBlockType(Op) == (BLOCK_PAREN | BLOCK_BRACE)) &&
    206  1.4.2.5     skrll             (ParseOpcode != PARSEOP_DEFINITION_BLOCK))
    207  1.4.2.5     skrll         {
    208  1.4.2.5     skrll             CvDbgPrint ("Parsing paren/Brace node now!\n");
    209  1.4.2.5     skrll             Gbl_CommentState.ParsingParenBraceNode = Op;
    210  1.4.2.5     skrll         }
    211  1.4.2.5     skrll 
    212  1.4.2.5     skrll         if (Gbl_Comment_List_Head)
    213  1.4.2.5     skrll         {
    214  1.4.2.5     skrll             CvDbgPrint ("Transferring...\n");
    215  1.4.2.5     skrll             Op->Asl.CommentList = Gbl_Comment_List_Head;
    216  1.4.2.5     skrll             Gbl_Comment_List_Head = NULL;
    217  1.4.2.5     skrll             Gbl_Comment_List_Tail = NULL;
    218  1.4.2.5     skrll             CvDbgPrint ("    Transferred current comment list to this node.\n");
    219  1.4.2.5     skrll             CvDbgPrint ("    %s\n", Op->Asl.CommentList->Comment);
    220  1.4.2.5     skrll         }
    221  1.4.2.5     skrll         if (Gbl_Inline_Comment_Buffer)
    222  1.4.2.5     skrll         {
    223  1.4.2.5     skrll             Op->Asl.InlineComment = Gbl_Inline_Comment_Buffer;
    224  1.4.2.5     skrll             Gbl_Inline_Comment_Buffer = NULL;
    225  1.4.2.5     skrll             CvDbgPrint ("Transferred current inline comment list to this node.\n");
    226  1.4.2.5     skrll         }
    227  1.4.2.5     skrll 
    228  1.4.2.5     skrll     }
    229  1.4.2.5     skrll 
    230      1.3  christos     return (Op);
    231      1.1    jruoho }
    232      1.1    jruoho 
    233      1.1    jruoho 
    234      1.1    jruoho /*******************************************************************************
    235      1.1    jruoho  *
    236      1.1    jruoho  * FUNCTION:    TrReleaseNode
    237      1.1    jruoho  *
    238      1.1    jruoho  * PARAMETERS:  Op            - Op to be released
    239      1.1    jruoho  *
    240      1.1    jruoho  * RETURN:      None
    241      1.1    jruoho  *
    242      1.3  christos  * DESCRIPTION: "release" a node. In truth, nothing is done since the node
    243      1.1    jruoho  *              is part of a larger buffer
    244      1.1    jruoho  *
    245      1.1    jruoho  ******************************************************************************/
    246      1.1    jruoho 
    247      1.1    jruoho void
    248      1.1    jruoho TrReleaseNode (
    249      1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    250      1.1    jruoho {
    251      1.1    jruoho 
    252      1.1    jruoho     return;
    253      1.1    jruoho }
    254      1.1    jruoho 
    255      1.1    jruoho 
    256      1.1    jruoho /*******************************************************************************
    257      1.1    jruoho  *
    258  1.4.2.2     skrll  * FUNCTION:    TrSetCurrentFilename
    259  1.4.2.2     skrll  *
    260  1.4.2.2     skrll  * PARAMETERS:  Op                  - An existing parse node
    261  1.4.2.2     skrll  *
    262  1.4.2.2     skrll  * RETURN:      None
    263  1.4.2.2     skrll  *
    264  1.4.2.2     skrll  * DESCRIPTION: Save the include file filename. Used for debug output only.
    265  1.4.2.2     skrll  *
    266  1.4.2.2     skrll  ******************************************************************************/
    267  1.4.2.2     skrll 
    268  1.4.2.2     skrll void
    269  1.4.2.2     skrll TrSetCurrentFilename (
    270  1.4.2.2     skrll     ACPI_PARSE_OBJECT       *Op)
    271  1.4.2.2     skrll {
    272  1.4.2.2     skrll     Op->Asl.Filename = Gbl_PreviousIncludeFilename;
    273  1.4.2.2     skrll }
    274  1.4.2.2     skrll 
    275  1.4.2.2     skrll 
    276  1.4.2.2     skrll /*******************************************************************************
    277  1.4.2.2     skrll  *
    278      1.1    jruoho  * FUNCTION:    TrUpdateNode
    279      1.1    jruoho  *
    280      1.1    jruoho  * PARAMETERS:  ParseOpcode         - New opcode to be assigned to the node
    281  1.4.2.2     skrll  *              Op                  - An existing parse node
    282      1.1    jruoho  *
    283      1.1    jruoho  * RETURN:      The updated node
    284      1.1    jruoho  *
    285      1.3  christos  * DESCRIPTION: Change the parse opcode assigned to a node. Usually used to
    286      1.1    jruoho  *              change an opcode to DEFAULT_ARG so that the node is ignored
    287      1.3  christos  *              during the code generation. Also used to set generic integers
    288      1.1    jruoho  *              to a specific size (8, 16, 32, or 64 bits)
    289      1.1    jruoho  *
    290      1.1    jruoho  ******************************************************************************/
    291      1.1    jruoho 
    292      1.1    jruoho ACPI_PARSE_OBJECT *
    293      1.1    jruoho TrUpdateNode (
    294      1.1    jruoho     UINT32                  ParseOpcode,
    295      1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    296      1.1    jruoho {
    297      1.1    jruoho 
    298      1.1    jruoho     if (!Op)
    299      1.1    jruoho     {
    300      1.3  christos         return (NULL);
    301      1.1    jruoho     }
    302      1.1    jruoho 
    303      1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    304  1.4.2.1     skrll         "\nUpdateNode: Old - %s, New - %s\n",
    305      1.1    jruoho         UtGetOpName (Op->Asl.ParseOpcode),
    306      1.1    jruoho         UtGetOpName (ParseOpcode));
    307      1.1    jruoho 
    308      1.1    jruoho     /* Assign new opcode and name */
    309      1.1    jruoho 
    310      1.1    jruoho     if (Op->Asl.ParseOpcode == PARSEOP_ONES)
    311      1.1    jruoho     {
    312      1.1    jruoho         switch (ParseOpcode)
    313      1.1    jruoho         {
    314      1.1    jruoho         case PARSEOP_BYTECONST:
    315      1.3  christos 
    316      1.3  christos             Op->Asl.Value.Integer = ACPI_UINT8_MAX;
    317      1.1    jruoho             break;
    318      1.1    jruoho 
    319      1.1    jruoho         case PARSEOP_WORDCONST:
    320      1.3  christos 
    321      1.3  christos             Op->Asl.Value.Integer = ACPI_UINT16_MAX;
    322      1.1    jruoho             break;
    323      1.1    jruoho 
    324      1.1    jruoho         case PARSEOP_DWORDCONST:
    325      1.3  christos 
    326      1.3  christos             Op->Asl.Value.Integer = ACPI_UINT32_MAX;
    327      1.1    jruoho             break;
    328      1.1    jruoho 
    329      1.3  christos         /* Don't need to do the QWORD case */
    330      1.3  christos 
    331      1.1    jruoho         default:
    332      1.3  christos 
    333      1.3  christos             /* Don't care about others */
    334      1.1    jruoho             break;
    335      1.1    jruoho         }
    336      1.1    jruoho     }
    337      1.1    jruoho 
    338      1.1    jruoho     Op->Asl.ParseOpcode = (UINT16) ParseOpcode;
    339      1.1    jruoho     UtSetParseOpName (Op);
    340      1.1    jruoho 
    341      1.1    jruoho     /*
    342      1.1    jruoho      * For the BYTE, WORD, and DWORD constants, make sure that the integer
    343      1.1    jruoho      * that was passed in will actually fit into the data type
    344      1.1    jruoho      */
    345      1.1    jruoho     switch (ParseOpcode)
    346      1.1    jruoho     {
    347      1.1    jruoho     case PARSEOP_BYTECONST:
    348      1.3  christos 
    349      1.3  christos         UtCheckIntegerRange (Op, 0x00, ACPI_UINT8_MAX);
    350      1.3  christos         Op->Asl.Value.Integer &= ACPI_UINT8_MAX;
    351      1.1    jruoho         break;
    352      1.1    jruoho 
    353      1.1    jruoho     case PARSEOP_WORDCONST:
    354      1.3  christos 
    355      1.3  christos         UtCheckIntegerRange (Op, 0x00, ACPI_UINT16_MAX);
    356      1.3  christos         Op->Asl.Value.Integer &= ACPI_UINT16_MAX;
    357      1.1    jruoho         break;
    358      1.1    jruoho 
    359      1.1    jruoho     case PARSEOP_DWORDCONST:
    360      1.3  christos 
    361      1.3  christos         UtCheckIntegerRange (Op, 0x00, ACPI_UINT32_MAX);
    362      1.3  christos         Op->Asl.Value.Integer &= ACPI_UINT32_MAX;
    363      1.1    jruoho         break;
    364      1.1    jruoho 
    365      1.1    jruoho     default:
    366      1.3  christos 
    367      1.1    jruoho         /* Don't care about others, don't need to check QWORD */
    368      1.3  christos 
    369      1.1    jruoho         break;
    370      1.1    jruoho     }
    371      1.1    jruoho 
    372  1.4.2.5     skrll     /* Converter: if this is a method invocation, turn off capture comments. */
    373  1.4.2.5     skrll     if (Gbl_CaptureComments &&
    374  1.4.2.5     skrll         (ParseOpcode == PARSEOP_METHODCALL))
    375  1.4.2.5     skrll     {
    376  1.4.2.5     skrll         Gbl_CommentState.CaptureComments = FALSE;
    377  1.4.2.5     skrll     }
    378  1.4.2.5     skrll 
    379      1.3  christos     return (Op);
    380      1.1    jruoho }
    381      1.1    jruoho 
    382      1.1    jruoho 
    383      1.1    jruoho /*******************************************************************************
    384      1.1    jruoho  *
    385  1.4.2.1     skrll  * FUNCTION:    TrPrintNodeCompileFlags
    386      1.1    jruoho  *
    387      1.1    jruoho  * PARAMETERS:  Flags               - Flags word to be decoded
    388      1.1    jruoho  *
    389  1.4.2.1     skrll  * RETURN:      None
    390      1.1    jruoho  *
    391  1.4.2.1     skrll  * DESCRIPTION: Decode a flags word to text. Displays all flags that are set.
    392      1.1    jruoho  *
    393      1.1    jruoho  ******************************************************************************/
    394      1.1    jruoho 
    395  1.4.2.1     skrll void
    396  1.4.2.1     skrll TrPrintNodeCompileFlags (
    397      1.1    jruoho     UINT32                  Flags)
    398      1.1    jruoho {
    399  1.4.2.1     skrll     UINT32                  i;
    400  1.4.2.1     skrll     UINT32                  FlagBit = 1;
    401  1.4.2.1     skrll     char                    *FlagName = NULL;
    402  1.4.2.1     skrll 
    403      1.1    jruoho 
    404  1.4.2.1     skrll     for (i = 0; i < 32; i++)
    405      1.1    jruoho     {
    406  1.4.2.1     skrll         switch (Flags & FlagBit)
    407  1.4.2.1     skrll         {
    408  1.4.2.1     skrll         case NODE_VISITED:
    409      1.3  christos 
    410  1.4.2.1     skrll             FlagName = "NODE_VISITED";
    411  1.4.2.1     skrll             break;
    412      1.1    jruoho 
    413  1.4.2.1     skrll         case NODE_AML_PACKAGE:
    414      1.3  christos 
    415  1.4.2.1     skrll             FlagName = "NODE_AML_PACKAGE";
    416  1.4.2.1     skrll             break;
    417      1.1    jruoho 
    418  1.4.2.1     skrll         case NODE_IS_TARGET:
    419      1.3  christos 
    420  1.4.2.1     skrll             FlagName = "NODE_IS_TARGET";
    421  1.4.2.1     skrll             break;
    422      1.1    jruoho 
    423  1.4.2.1     skrll         case NODE_IS_RESOURCE_DESC:
    424      1.3  christos 
    425  1.4.2.1     skrll             FlagName = "NODE_IS_RESOURCE_DESC";
    426  1.4.2.1     skrll             break;
    427      1.1    jruoho 
    428  1.4.2.1     skrll         case NODE_IS_RESOURCE_FIELD:
    429      1.3  christos 
    430  1.4.2.1     skrll             FlagName = "NODE_IS_RESOURCE_FIELD";
    431  1.4.2.1     skrll             break;
    432      1.1    jruoho 
    433  1.4.2.1     skrll         case NODE_HAS_NO_EXIT:
    434      1.3  christos 
    435  1.4.2.1     skrll             FlagName = "NODE_HAS_NO_EXIT";
    436  1.4.2.1     skrll             break;
    437      1.1    jruoho 
    438  1.4.2.1     skrll         case NODE_IF_HAS_NO_EXIT:
    439      1.3  christos 
    440  1.4.2.1     skrll             FlagName = "NODE_IF_HAS_NO_EXIT";
    441  1.4.2.1     skrll             break;
    442      1.1    jruoho 
    443  1.4.2.1     skrll         case NODE_NAME_INTERNALIZED:
    444      1.3  christos 
    445  1.4.2.1     skrll             FlagName = "NODE_NAME_INTERNALIZED";
    446  1.4.2.1     skrll             break;
    447      1.1    jruoho 
    448  1.4.2.1     skrll         case NODE_METHOD_NO_RETVAL:
    449      1.3  christos 
    450  1.4.2.1     skrll             FlagName = "NODE_METHOD_NO_RETVAL";
    451  1.4.2.1     skrll             break;
    452      1.1    jruoho 
    453  1.4.2.1     skrll         case NODE_METHOD_SOME_NO_RETVAL:
    454      1.3  christos 
    455  1.4.2.1     skrll             FlagName = "NODE_METHOD_SOME_NO_RETVAL";
    456  1.4.2.1     skrll             break;
    457      1.1    jruoho 
    458  1.4.2.1     skrll         case NODE_RESULT_NOT_USED:
    459      1.3  christos 
    460  1.4.2.1     skrll             FlagName = "NODE_RESULT_NOT_USED";
    461  1.4.2.1     skrll             break;
    462      1.1    jruoho 
    463  1.4.2.1     skrll         case NODE_METHOD_TYPED:
    464      1.3  christos 
    465  1.4.2.1     skrll             FlagName = "NODE_METHOD_TYPED";
    466  1.4.2.1     skrll             break;
    467      1.1    jruoho 
    468  1.4.2.2     skrll         case NODE_COULD_NOT_REDUCE:
    469  1.4.2.2     skrll 
    470  1.4.2.2     skrll             FlagName = "NODE_COULD_NOT_REDUCE";
    471  1.4.2.2     skrll             break;
    472  1.4.2.2     skrll 
    473  1.4.2.1     skrll         case NODE_COMPILE_TIME_CONST:
    474      1.1    jruoho 
    475  1.4.2.1     skrll             FlagName = "NODE_COMPILE_TIME_CONST";
    476  1.4.2.1     skrll             break;
    477      1.1    jruoho 
    478  1.4.2.1     skrll         case NODE_IS_TERM_ARG:
    479      1.3  christos 
    480  1.4.2.1     skrll             FlagName = "NODE_IS_TERM_ARG";
    481  1.4.2.1     skrll             break;
    482      1.1    jruoho 
    483  1.4.2.1     skrll         case NODE_WAS_ONES_OP:
    484      1.3  christos 
    485  1.4.2.1     skrll             FlagName = "NODE_WAS_ONES_OP";
    486  1.4.2.1     skrll             break;
    487      1.1    jruoho 
    488  1.4.2.1     skrll         case NODE_IS_NAME_DECLARATION:
    489      1.3  christos 
    490  1.4.2.1     skrll             FlagName = "NODE_IS_NAME_DECLARATION";
    491  1.4.2.1     skrll             break;
    492      1.1    jruoho 
    493  1.4.2.1     skrll         case NODE_COMPILER_EMITTED:
    494  1.4.2.1     skrll 
    495  1.4.2.1     skrll             FlagName = "NODE_COMPILER_EMITTED";
    496  1.4.2.1     skrll             break;
    497  1.4.2.1     skrll 
    498  1.4.2.1     skrll         case NODE_IS_DUPLICATE:
    499  1.4.2.1     skrll 
    500  1.4.2.1     skrll             FlagName = "NODE_IS_DUPLICATE";
    501  1.4.2.1     skrll             break;
    502  1.4.2.1     skrll 
    503  1.4.2.1     skrll         case NODE_IS_RESOURCE_DATA:
    504  1.4.2.1     skrll 
    505  1.4.2.1     skrll             FlagName = "NODE_IS_RESOURCE_DATA";
    506  1.4.2.1     skrll             break;
    507  1.4.2.1     skrll 
    508  1.4.2.1     skrll         case NODE_IS_NULL_RETURN:
    509  1.4.2.1     skrll 
    510  1.4.2.1     skrll             FlagName = "NODE_IS_NULL_RETURN";
    511  1.4.2.1     skrll             break;
    512  1.4.2.1     skrll 
    513  1.4.2.1     skrll         default:
    514  1.4.2.1     skrll             break;
    515  1.4.2.1     skrll         }
    516  1.4.2.1     skrll 
    517  1.4.2.1     skrll         if (FlagName)
    518  1.4.2.1     skrll         {
    519  1.4.2.1     skrll             DbgPrint (ASL_PARSE_OUTPUT, " %s", FlagName);
    520  1.4.2.1     skrll             FlagName = NULL;
    521  1.4.2.1     skrll         }
    522      1.3  christos 
    523  1.4.2.1     skrll         FlagBit <<= 1;
    524      1.1    jruoho     }
    525      1.1    jruoho }
    526      1.1    jruoho 
    527      1.1    jruoho 
    528      1.1    jruoho /*******************************************************************************
    529      1.1    jruoho  *
    530      1.1    jruoho  * FUNCTION:    TrSetNodeFlags
    531      1.1    jruoho  *
    532      1.1    jruoho  * PARAMETERS:  Op                  - An existing parse node
    533      1.1    jruoho  *              Flags               - New flags word
    534      1.1    jruoho  *
    535      1.1    jruoho  * RETURN:      The updated parser op
    536      1.1    jruoho  *
    537      1.3  christos  * DESCRIPTION: Set bits in the node flags word. Will not clear bits, only set
    538      1.1    jruoho  *
    539      1.1    jruoho  ******************************************************************************/
    540      1.1    jruoho 
    541      1.1    jruoho ACPI_PARSE_OBJECT *
    542      1.1    jruoho TrSetNodeFlags (
    543      1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    544      1.1    jruoho     UINT32                  Flags)
    545      1.1    jruoho {
    546      1.1    jruoho 
    547      1.1    jruoho     if (!Op)
    548      1.1    jruoho     {
    549      1.3  christos         return (NULL);
    550      1.1    jruoho     }
    551      1.1    jruoho 
    552  1.4.2.1     skrll     DbgPrint (ASL_PARSE_OUTPUT,
    553  1.4.2.1     skrll         "\nSetNodeFlags: %s Op %p, %8.8X", Op->Asl.ParseOpName, Op, Flags);
    554  1.4.2.1     skrll 
    555  1.4.2.1     skrll     TrPrintNodeCompileFlags (Flags);
    556  1.4.2.1     skrll     DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
    557  1.4.2.1     skrll 
    558      1.1    jruoho     Op->Asl.CompileFlags |= Flags;
    559      1.3  christos     return (Op);
    560      1.3  christos }
    561      1.3  christos 
    562      1.3  christos 
    563      1.3  christos /*******************************************************************************
    564      1.3  christos  *
    565      1.3  christos  * FUNCTION:    TrSetNodeAmlLength
    566      1.3  christos  *
    567      1.3  christos  * PARAMETERS:  Op                  - An existing parse node
    568      1.3  christos  *              Length              - AML Length
    569      1.3  christos  *
    570      1.3  christos  * RETURN:      The updated parser op
    571      1.3  christos  *
    572      1.3  christos  * DESCRIPTION: Set the AML Length in a node. Used by the parser to indicate
    573      1.3  christos  *              the presence of a node that must be reduced to a fixed length
    574      1.3  christos  *              constant.
    575      1.3  christos  *
    576      1.3  christos  ******************************************************************************/
    577      1.1    jruoho 
    578      1.3  christos ACPI_PARSE_OBJECT *
    579      1.3  christos TrSetNodeAmlLength (
    580      1.3  christos     ACPI_PARSE_OBJECT       *Op,
    581      1.3  christos     UINT32                  Length)
    582      1.3  christos {
    583      1.3  christos 
    584      1.3  christos     DbgPrint (ASL_PARSE_OUTPUT,
    585      1.3  christos         "\nSetNodeAmlLength: Op %p, %8.8X\n", Op, Length);
    586      1.3  christos 
    587      1.3  christos     if (!Op)
    588      1.3  christos     {
    589      1.3  christos         return (NULL);
    590      1.3  christos     }
    591      1.3  christos 
    592      1.3  christos     Op->Asl.AmlLength = Length;
    593      1.3  christos     return (Op);
    594      1.1    jruoho }
    595      1.1    jruoho 
    596      1.1    jruoho 
    597      1.1    jruoho /*******************************************************************************
    598      1.1    jruoho  *
    599      1.1    jruoho  * FUNCTION:    TrSetEndLineNumber
    600      1.1    jruoho  *
    601      1.1    jruoho  * PARAMETERS:  Op                - An existing parse node
    602      1.1    jruoho  *
    603      1.1    jruoho  * RETURN:      None.
    604      1.1    jruoho  *
    605      1.1    jruoho  * DESCRIPTION: Set the ending line numbers (file line and logical line) of a
    606      1.1    jruoho  *              parse node to the current line numbers.
    607      1.1    jruoho  *
    608      1.1    jruoho  ******************************************************************************/
    609      1.1    jruoho 
    610      1.1    jruoho void
    611      1.1    jruoho TrSetEndLineNumber (
    612      1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    613      1.1    jruoho {
    614      1.1    jruoho 
    615      1.1    jruoho     /* If the end line # is already set, just return */
    616      1.1    jruoho 
    617      1.1    jruoho     if (Op->Asl.EndLine)
    618      1.1    jruoho     {
    619      1.1    jruoho         return;
    620      1.1    jruoho     }
    621      1.1    jruoho 
    622  1.4.2.2     skrll     Op->Asl.EndLine = Gbl_CurrentLineNumber;
    623      1.1    jruoho     Op->Asl.EndLogicalLine = Gbl_LogicalLineNumber;
    624      1.1    jruoho }
    625      1.1    jruoho 
    626      1.1    jruoho 
    627      1.1    jruoho /*******************************************************************************
    628      1.1    jruoho  *
    629  1.4.2.1     skrll  * FUNCTION:    TrCreateAssignmentNode
    630  1.4.2.1     skrll  *
    631  1.4.2.1     skrll  * PARAMETERS:  Target              - Assignment target
    632  1.4.2.1     skrll  *              Source              - Assignment source
    633  1.4.2.1     skrll  *
    634  1.4.2.1     skrll  * RETURN:      Pointer to the new node. Aborts on allocation failure
    635  1.4.2.1     skrll  *
    636  1.4.2.1     skrll  * DESCRIPTION: Implements the C-style '=' operator. It changes the parse
    637  1.4.2.1     skrll  *              tree if possible to utilize the last argument of the math
    638  1.4.2.1     skrll  *              operators which is a target operand -- thus saving invocation
    639  1.4.2.1     skrll  *              of and additional Store() operator. An optimization.
    640  1.4.2.1     skrll  *
    641  1.4.2.1     skrll  ******************************************************************************/
    642  1.4.2.1     skrll 
    643  1.4.2.1     skrll ACPI_PARSE_OBJECT *
    644  1.4.2.1     skrll TrCreateAssignmentNode (
    645  1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Target,
    646  1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Source)
    647  1.4.2.1     skrll {
    648  1.4.2.1     skrll     ACPI_PARSE_OBJECT       *TargetOp;
    649  1.4.2.1     skrll     ACPI_PARSE_OBJECT       *SourceOp1;
    650  1.4.2.1     skrll     ACPI_PARSE_OBJECT       *SourceOp2;
    651  1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Operator;
    652  1.4.2.1     skrll 
    653  1.4.2.1     skrll 
    654  1.4.2.1     skrll     DbgPrint (ASL_PARSE_OUTPUT,
    655  1.4.2.1     skrll         "\nTrCreateAssignmentNode  Line [%u to %u] Source %s Target %s\n",
    656  1.4.2.1     skrll         Source->Asl.LineNumber, Source->Asl.EndLine,
    657  1.4.2.1     skrll         UtGetOpName (Source->Asl.ParseOpcode),
    658  1.4.2.1     skrll         UtGetOpName (Target->Asl.ParseOpcode));
    659  1.4.2.1     skrll 
    660  1.4.2.1     skrll     TrSetNodeFlags (Target, NODE_IS_TARGET);
    661  1.4.2.1     skrll 
    662  1.4.2.1     skrll     switch (Source->Asl.ParseOpcode)
    663  1.4.2.1     skrll     {
    664  1.4.2.1     skrll     /*
    665  1.4.2.1     skrll      * Only these operators can be optimized because they have
    666  1.4.2.1     skrll      * a target operand
    667  1.4.2.1     skrll      */
    668  1.4.2.1     skrll     case PARSEOP_ADD:
    669  1.4.2.1     skrll     case PARSEOP_AND:
    670  1.4.2.1     skrll     case PARSEOP_DIVIDE:
    671  1.4.2.2     skrll     case PARSEOP_INDEX:
    672  1.4.2.1     skrll     case PARSEOP_MOD:
    673  1.4.2.1     skrll     case PARSEOP_MULTIPLY:
    674  1.4.2.1     skrll     case PARSEOP_NOT:
    675  1.4.2.1     skrll     case PARSEOP_OR:
    676  1.4.2.1     skrll     case PARSEOP_SHIFTLEFT:
    677  1.4.2.1     skrll     case PARSEOP_SHIFTRIGHT:
    678  1.4.2.1     skrll     case PARSEOP_SUBTRACT:
    679  1.4.2.1     skrll     case PARSEOP_XOR:
    680  1.4.2.1     skrll 
    681  1.4.2.1     skrll         break;
    682  1.4.2.1     skrll 
    683  1.4.2.1     skrll     /* Otherwise, just create a normal Store operator */
    684  1.4.2.1     skrll 
    685  1.4.2.1     skrll     default:
    686  1.4.2.1     skrll 
    687  1.4.2.1     skrll         goto CannotOptimize;
    688  1.4.2.1     skrll     }
    689  1.4.2.1     skrll 
    690  1.4.2.1     skrll     /*
    691  1.4.2.1     skrll      * Transform the parse tree such that the target is moved to the
    692  1.4.2.1     skrll      * last operand of the operator
    693  1.4.2.1     skrll      */
    694  1.4.2.1     skrll     SourceOp1 = Source->Asl.Child;
    695  1.4.2.1     skrll     SourceOp2 = SourceOp1->Asl.Next;
    696  1.4.2.1     skrll 
    697  1.4.2.1     skrll     /* NOT only has one operand, but has a target */
    698  1.4.2.1     skrll 
    699  1.4.2.1     skrll     if (Source->Asl.ParseOpcode == PARSEOP_NOT)
    700  1.4.2.1     skrll     {
    701  1.4.2.1     skrll         SourceOp2 = SourceOp1;
    702  1.4.2.1     skrll     }
    703  1.4.2.1     skrll 
    704  1.4.2.1     skrll     /* DIVIDE has an extra target operand (remainder) */
    705  1.4.2.1     skrll 
    706  1.4.2.1     skrll     if (Source->Asl.ParseOpcode == PARSEOP_DIVIDE)
    707  1.4.2.1     skrll     {
    708  1.4.2.1     skrll         SourceOp2 = SourceOp2->Asl.Next;
    709  1.4.2.1     skrll     }
    710  1.4.2.1     skrll 
    711  1.4.2.1     skrll     TargetOp = SourceOp2->Asl.Next;
    712  1.4.2.1     skrll 
    713  1.4.2.1     skrll     /*
    714  1.4.2.1     skrll      * Can't perform this optimization if there already is a target
    715  1.4.2.1     skrll      * for the operator (ZERO is a "no target" placeholder).
    716  1.4.2.1     skrll      */
    717  1.4.2.1     skrll     if (TargetOp->Asl.ParseOpcode != PARSEOP_ZERO)
    718  1.4.2.1     skrll     {
    719  1.4.2.1     skrll         goto CannotOptimize;
    720  1.4.2.1     skrll     }
    721  1.4.2.1     skrll 
    722  1.4.2.1     skrll     /* Link in the target as the final operand */
    723  1.4.2.1     skrll 
    724  1.4.2.1     skrll     SourceOp2->Asl.Next = Target;
    725  1.4.2.1     skrll     Target->Asl.Parent = Source;
    726  1.4.2.1     skrll 
    727  1.4.2.1     skrll     return (Source);
    728  1.4.2.1     skrll 
    729  1.4.2.1     skrll 
    730  1.4.2.1     skrll CannotOptimize:
    731  1.4.2.1     skrll 
    732  1.4.2.1     skrll     Operator = TrAllocateNode (PARSEOP_STORE);
    733  1.4.2.1     skrll     TrLinkChildren (Operator, 2, Source, Target);
    734  1.4.2.1     skrll 
    735  1.4.2.1     skrll     /* Set the appropriate line numbers for the new node */
    736  1.4.2.1     skrll 
    737  1.4.2.1     skrll     Operator->Asl.LineNumber        = Target->Asl.LineNumber;
    738  1.4.2.1     skrll     Operator->Asl.LogicalLineNumber = Target->Asl.LogicalLineNumber;
    739  1.4.2.1     skrll     Operator->Asl.LogicalByteOffset = Target->Asl.LogicalByteOffset;
    740  1.4.2.1     skrll     Operator->Asl.Column            = Target->Asl.Column;
    741  1.4.2.1     skrll 
    742  1.4.2.1     skrll     return (Operator);
    743  1.4.2.1     skrll }
    744  1.4.2.1     skrll 
    745  1.4.2.1     skrll 
    746  1.4.2.1     skrll /*******************************************************************************
    747  1.4.2.1     skrll  *
    748      1.1    jruoho  * FUNCTION:    TrCreateLeafNode
    749      1.1    jruoho  *
    750      1.1    jruoho  * PARAMETERS:  ParseOpcode         - New opcode to be assigned to the node
    751      1.1    jruoho  *
    752      1.3  christos  * RETURN:      Pointer to the new node. Aborts on allocation failure
    753      1.1    jruoho  *
    754      1.1    jruoho  * DESCRIPTION: Create a simple leaf node (no children or peers, and no value
    755      1.1    jruoho  *              assigned to the node)
    756      1.1    jruoho  *
    757      1.1    jruoho  ******************************************************************************/
    758      1.1    jruoho 
    759      1.1    jruoho ACPI_PARSE_OBJECT *
    760      1.1    jruoho TrCreateLeafNode (
    761      1.1    jruoho     UINT32                  ParseOpcode)
    762      1.1    jruoho {
    763      1.1    jruoho     ACPI_PARSE_OBJECT       *Op;
    764      1.1    jruoho 
    765      1.1    jruoho 
    766      1.1    jruoho     Op = TrAllocateNode (ParseOpcode);
    767      1.1    jruoho 
    768      1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    769      1.1    jruoho         "\nCreateLeafNode  Ln/Col %u/%u NewNode %p  Op %s\n\n",
    770  1.4.2.1     skrll         Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode));
    771  1.4.2.1     skrll 
    772  1.4.2.1     skrll     return (Op);
    773  1.4.2.1     skrll }
    774  1.4.2.1     skrll 
    775  1.4.2.1     skrll 
    776  1.4.2.1     skrll /*******************************************************************************
    777  1.4.2.1     skrll  *
    778  1.4.2.1     skrll  * FUNCTION:    TrCreateNullTarget
    779  1.4.2.1     skrll  *
    780  1.4.2.1     skrll  * PARAMETERS:  None
    781  1.4.2.1     skrll  *
    782  1.4.2.1     skrll  * RETURN:      Pointer to the new node. Aborts on allocation failure
    783  1.4.2.1     skrll  *
    784  1.4.2.1     skrll  * DESCRIPTION: Create a "null" target node. This is defined by the ACPI
    785  1.4.2.1     skrll  *              specification to be a zero AML opcode, and indicates that
    786  1.4.2.1     skrll  *              no target has been specified for the parent operation
    787  1.4.2.1     skrll  *
    788  1.4.2.1     skrll  ******************************************************************************/
    789  1.4.2.1     skrll 
    790  1.4.2.1     skrll ACPI_PARSE_OBJECT *
    791  1.4.2.1     skrll TrCreateNullTarget (
    792  1.4.2.1     skrll     void)
    793  1.4.2.1     skrll {
    794  1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Op;
    795  1.4.2.1     skrll 
    796  1.4.2.1     skrll 
    797  1.4.2.1     skrll     Op = TrAllocateNode (PARSEOP_ZERO);
    798  1.4.2.1     skrll     Op->Asl.CompileFlags |= (NODE_IS_TARGET | NODE_COMPILE_TIME_CONST);
    799  1.4.2.1     skrll 
    800  1.4.2.1     skrll     DbgPrint (ASL_PARSE_OUTPUT,
    801  1.4.2.1     skrll         "\nCreateNullTarget  Ln/Col %u/%u NewNode %p  Op %s\n",
    802  1.4.2.1     skrll         Op->Asl.LineNumber, Op->Asl.Column, Op,
    803  1.4.2.1     skrll         UtGetOpName (Op->Asl.ParseOpcode));
    804      1.1    jruoho 
    805      1.3  christos     return (Op);
    806      1.1    jruoho }
    807      1.1    jruoho 
    808      1.1    jruoho 
    809      1.1    jruoho /*******************************************************************************
    810      1.1    jruoho  *
    811      1.2  christos  * FUNCTION:    TrCreateConstantLeafNode
    812      1.2  christos  *
    813      1.2  christos  * PARAMETERS:  ParseOpcode         - The constant opcode
    814      1.2  christos  *
    815      1.3  christos  * RETURN:      Pointer to the new node. Aborts on allocation failure
    816      1.2  christos  *
    817      1.2  christos  * DESCRIPTION: Create a leaf node (no children or peers) for one of the
    818      1.2  christos  *              special constants - __LINE__, __FILE__, and __DATE__.
    819      1.2  christos  *
    820      1.2  christos  * Note: An implemenation of __FUNC__ cannot happen here because we don't
    821      1.2  christos  * have a full parse tree at this time and cannot find the parent control
    822      1.2  christos  * method. If it is ever needed, __FUNC__ must be implemented later, after
    823      1.2  christos  * the parse tree has been fully constructed.
    824      1.2  christos  *
    825      1.2  christos  ******************************************************************************/
    826      1.2  christos 
    827      1.2  christos ACPI_PARSE_OBJECT *
    828      1.2  christos TrCreateConstantLeafNode (
    829      1.2  christos     UINT32                  ParseOpcode)
    830      1.2  christos {
    831      1.2  christos     ACPI_PARSE_OBJECT       *Op = NULL;
    832      1.2  christos     time_t                  CurrentTime;
    833      1.2  christos     char                    *StaticTimeString;
    834      1.2  christos     char                    *TimeString;
    835      1.3  christos     char                    *Filename;
    836      1.2  christos 
    837      1.2  christos 
    838      1.2  christos     switch (ParseOpcode)
    839      1.2  christos     {
    840      1.2  christos     case PARSEOP___LINE__:
    841      1.3  christos 
    842      1.2  christos         Op = TrAllocateNode (PARSEOP_INTEGER);
    843      1.2  christos         Op->Asl.Value.Integer = Op->Asl.LineNumber;
    844      1.2  christos         break;
    845      1.2  christos 
    846      1.3  christos     case PARSEOP___PATH__:
    847      1.3  christos 
    848      1.2  christos         Op = TrAllocateNode (PARSEOP_STRING_LITERAL);
    849      1.2  christos 
    850      1.2  christos         /* Op.Asl.Filename contains the full pathname to the file */
    851      1.2  christos 
    852      1.2  christos         Op->Asl.Value.String = Op->Asl.Filename;
    853      1.2  christos         break;
    854      1.2  christos 
    855      1.3  christos     case PARSEOP___FILE__:
    856      1.3  christos 
    857      1.3  christos         Op = TrAllocateNode (PARSEOP_STRING_LITERAL);
    858      1.3  christos 
    859      1.3  christos         /* Get the simple filename from the full path */
    860      1.3  christos 
    861  1.4.2.1     skrll         FlSplitInputPathname (Op->Asl.Filename, NULL, &Filename);
    862      1.3  christos         Op->Asl.Value.String = Filename;
    863      1.3  christos         break;
    864      1.3  christos 
    865      1.3  christos     case PARSEOP___DATE__:
    866      1.3  christos 
    867      1.2  christos         Op = TrAllocateNode (PARSEOP_STRING_LITERAL);
    868      1.2  christos 
    869      1.2  christos         /* Get a copy of the current time */
    870      1.2  christos 
    871      1.2  christos         CurrentTime = time (NULL);
    872      1.2  christos         StaticTimeString = ctime (&CurrentTime);
    873      1.2  christos         TimeString = UtLocalCalloc (strlen (StaticTimeString) + 1);
    874      1.2  christos         strcpy (TimeString, StaticTimeString);
    875      1.2  christos 
    876      1.2  christos         TimeString[strlen(TimeString) -1] = 0;  /* Remove trailing newline */
    877      1.2  christos         Op->Asl.Value.String = TimeString;
    878      1.2  christos         break;
    879      1.2  christos 
    880      1.2  christos     default: /* This would be an internal error */
    881      1.3  christos 
    882      1.2  christos         return (NULL);
    883      1.2  christos     }
    884      1.2  christos 
    885      1.2  christos     DbgPrint (ASL_PARSE_OUTPUT,
    886  1.4.2.2     skrll         "\nCreateConstantLeafNode  Ln/Col %u/%u NewNode %p  "
    887  1.4.2.2     skrll         "Op %s  Value %8.8X%8.8X  \n",
    888      1.2  christos         Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode),
    889      1.2  christos         ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
    890      1.2  christos     return (Op);
    891      1.2  christos }
    892      1.2  christos 
    893      1.2  christos 
    894      1.2  christos /*******************************************************************************
    895      1.2  christos  *
    896  1.4.2.1     skrll  * FUNCTION:    TrCreateTargetOperand
    897  1.4.2.1     skrll  *
    898  1.4.2.1     skrll  * PARAMETERS:  OriginalOp          - Op to be copied
    899  1.4.2.1     skrll  *
    900  1.4.2.1     skrll  * RETURN:      Pointer to the new node. Aborts on allocation failure
    901  1.4.2.1     skrll  *
    902  1.4.2.1     skrll  * DESCRIPTION: Copy an existing node (and subtree). Used in ASL+ (C-style)
    903  1.4.2.1     skrll  *              expressions where the target is the same as one of the
    904  1.4.2.1     skrll  *              operands. A new node and subtree must be created from the
    905  1.4.2.1     skrll  *              original so that the parse tree can be linked properly.
    906  1.4.2.1     skrll  *
    907  1.4.2.1     skrll  * NOTE:        This code is specific to target operands that are the last
    908  1.4.2.1     skrll  *              operand in an ASL/AML operator. Meaning that the top-level
    909  1.4.2.1     skrll  *              parse Op in a possible subtree has a NULL Next pointer.
    910  1.4.2.1     skrll  *              This simplifies the recursion.
    911  1.4.2.1     skrll  *
    912  1.4.2.1     skrll  *              Subtree example:
    913  1.4.2.1     skrll  *                  DeRefOf (Local1) += 32
    914  1.4.2.1     skrll  *
    915  1.4.2.1     skrll  *              This gets converted to:
    916  1.4.2.1     skrll  *                  Add (DeRefOf (Local1), 32, DeRefOf (Local1))
    917  1.4.2.1     skrll  *
    918  1.4.2.1     skrll  *              Each DeRefOf has a single child, Local1. Even more complex
    919  1.4.2.1     skrll  *              subtrees can be created via the Index and DeRefOf operators.
    920  1.4.2.1     skrll  *
    921  1.4.2.1     skrll  ******************************************************************************/
    922  1.4.2.1     skrll 
    923  1.4.2.1     skrll ACPI_PARSE_OBJECT *
    924  1.4.2.1     skrll TrCreateTargetOperand (
    925  1.4.2.1     skrll     ACPI_PARSE_OBJECT       *OriginalOp,
    926  1.4.2.1     skrll     ACPI_PARSE_OBJECT       *ParentOp)
    927  1.4.2.1     skrll {
    928  1.4.2.1     skrll     ACPI_PARSE_OBJECT       *Op;
    929  1.4.2.1     skrll 
    930  1.4.2.1     skrll 
    931  1.4.2.1     skrll     if (!OriginalOp)
    932  1.4.2.1     skrll     {
    933  1.4.2.1     skrll         return (NULL);
    934  1.4.2.1     skrll     }
    935  1.4.2.1     skrll 
    936  1.4.2.1     skrll     Op = TrGetNextNode ();
    937  1.4.2.1     skrll 
    938  1.4.2.1     skrll     /* Copy the pertinent values (omit link pointer fields) */
    939  1.4.2.1     skrll 
    940  1.4.2.1     skrll     Op->Asl.Value               = OriginalOp->Asl.Value;
    941  1.4.2.1     skrll     Op->Asl.Filename            = OriginalOp->Asl.Filename;
    942  1.4.2.1     skrll     Op->Asl.LineNumber          = OriginalOp->Asl.LineNumber;
    943  1.4.2.1     skrll     Op->Asl.LogicalLineNumber   = OriginalOp->Asl.LogicalLineNumber;
    944  1.4.2.1     skrll     Op->Asl.LogicalByteOffset   = OriginalOp->Asl.LogicalByteOffset;
    945  1.4.2.1     skrll     Op->Asl.Column              = OriginalOp->Asl.Column;
    946  1.4.2.1     skrll     Op->Asl.Flags               = OriginalOp->Asl.Flags;
    947  1.4.2.1     skrll     Op->Asl.CompileFlags        = OriginalOp->Asl.CompileFlags;
    948  1.4.2.1     skrll     Op->Asl.AmlOpcode           = OriginalOp->Asl.AmlOpcode;
    949  1.4.2.1     skrll     Op->Asl.ParseOpcode         = OriginalOp->Asl.ParseOpcode;
    950  1.4.2.1     skrll     Op->Asl.Parent              = ParentOp;
    951  1.4.2.1     skrll     UtSetParseOpName (Op);
    952  1.4.2.1     skrll 
    953  1.4.2.1     skrll     /* Copy a possible subtree below this node */
    954  1.4.2.1     skrll 
    955  1.4.2.1     skrll     if (OriginalOp->Asl.Child)
    956  1.4.2.1     skrll     {
    957  1.4.2.1     skrll         Op->Asl.Child = TrCreateTargetOperand (OriginalOp->Asl.Child, Op);
    958  1.4.2.1     skrll     }
    959  1.4.2.1     skrll 
    960  1.4.2.1     skrll     if (OriginalOp->Asl.Next) /* Null for top-level node */
    961  1.4.2.1     skrll     {
    962  1.4.2.1     skrll         Op->Asl.Next = TrCreateTargetOperand (OriginalOp->Asl.Next, ParentOp);
    963  1.4.2.1     skrll     }
    964  1.4.2.1     skrll 
    965  1.4.2.1     skrll     return (Op);
    966  1.4.2.1     skrll }
    967  1.4.2.1     skrll 
    968  1.4.2.1     skrll 
    969  1.4.2.1     skrll /*******************************************************************************
    970  1.4.2.1     skrll  *
    971      1.1    jruoho  * FUNCTION:    TrCreateValuedLeafNode
    972      1.1    jruoho  *
    973      1.1    jruoho  * PARAMETERS:  ParseOpcode         - New opcode to be assigned to the node
    974      1.1    jruoho  *              Value               - Value to be assigned to the node
    975      1.1    jruoho  *
    976      1.3  christos  * RETURN:      Pointer to the new node. Aborts on allocation failure
    977      1.1    jruoho  *
    978      1.1    jruoho  * DESCRIPTION: Create a leaf node (no children or peers) with a value
    979      1.1    jruoho  *              assigned to it
    980      1.1    jruoho  *
    981      1.1    jruoho  ******************************************************************************/
    982      1.1    jruoho 
    983      1.1    jruoho ACPI_PARSE_OBJECT *
    984      1.1    jruoho TrCreateValuedLeafNode (
    985      1.1    jruoho     UINT32                  ParseOpcode,
    986      1.1    jruoho     UINT64                  Value)
    987      1.1    jruoho {
    988      1.1    jruoho     ACPI_PARSE_OBJECT       *Op;
    989      1.1    jruoho 
    990      1.1    jruoho 
    991      1.1    jruoho     Op = TrAllocateNode (ParseOpcode);
    992      1.1    jruoho 
    993      1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    994  1.4.2.2     skrll         "\nCreateValuedLeafNode  Ln/Col %u/%u NewNode %p  "
    995  1.4.2.2     skrll         "Op %s  Value %8.8X%8.8X  ",
    996      1.1    jruoho         Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode),
    997      1.1    jruoho         ACPI_FORMAT_UINT64 (Value));
    998      1.1    jruoho     Op->Asl.Value.Integer = Value;
    999      1.1    jruoho 
   1000      1.1    jruoho     switch (ParseOpcode)
   1001      1.1    jruoho     {
   1002      1.1    jruoho     case PARSEOP_STRING_LITERAL:
   1003      1.3  christos 
   1004      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "STRING->%s", Value);
   1005      1.1    jruoho         break;
   1006      1.1    jruoho 
   1007      1.1    jruoho     case PARSEOP_NAMESEG:
   1008      1.3  christos 
   1009      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "NAMESEG->%s", Value);
   1010      1.1    jruoho         break;
   1011      1.1    jruoho 
   1012      1.1    jruoho     case PARSEOP_NAMESTRING:
   1013      1.3  christos 
   1014      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "NAMESTRING->%s", Value);
   1015      1.1    jruoho         break;
   1016      1.1    jruoho 
   1017      1.1    jruoho     case PARSEOP_EISAID:
   1018      1.3  christos 
   1019      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "EISAID->%s", Value);
   1020      1.1    jruoho         break;
   1021      1.1    jruoho 
   1022      1.1    jruoho     case PARSEOP_METHOD:
   1023      1.3  christos 
   1024      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "METHOD");
   1025      1.1    jruoho         break;
   1026      1.1    jruoho 
   1027      1.1    jruoho     case PARSEOP_INTEGER:
   1028      1.3  christos 
   1029  1.4.2.1     skrll         DbgPrint (ASL_PARSE_OUTPUT, "INTEGER->%8.8X%8.8X",
   1030  1.4.2.1     skrll             ACPI_FORMAT_UINT64 (Value));
   1031      1.1    jruoho         break;
   1032      1.1    jruoho 
   1033      1.1    jruoho     default:
   1034      1.3  christos 
   1035      1.1    jruoho         break;
   1036      1.1    jruoho     }
   1037      1.1    jruoho 
   1038      1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
   1039      1.3  christos     return (Op);
   1040      1.1    jruoho }
   1041      1.1    jruoho 
   1042      1.1    jruoho 
   1043      1.1    jruoho /*******************************************************************************
   1044      1.1    jruoho  *
   1045      1.1    jruoho  * FUNCTION:    TrCreateNode
   1046      1.1    jruoho  *
   1047      1.1    jruoho  * PARAMETERS:  ParseOpcode         - Opcode to be assigned to the node
   1048      1.1    jruoho  *              NumChildren         - Number of children to follow
   1049      1.1    jruoho  *              ...                 - A list of child nodes to link to the new
   1050      1.3  christos  *                                    node. NumChildren long.
   1051      1.1    jruoho  *
   1052      1.3  christos  * RETURN:      Pointer to the new node. Aborts on allocation failure
   1053      1.1    jruoho  *
   1054      1.1    jruoho  * DESCRIPTION: Create a new parse node and link together a list of child
   1055      1.1    jruoho  *              nodes underneath the new node.
   1056      1.1    jruoho  *
   1057      1.1    jruoho  ******************************************************************************/
   1058      1.1    jruoho 
   1059      1.1    jruoho ACPI_PARSE_OBJECT *
   1060      1.1    jruoho TrCreateNode (
   1061      1.1    jruoho     UINT32                  ParseOpcode,
   1062      1.1    jruoho     UINT32                  NumChildren,
   1063      1.1    jruoho     ...)
   1064      1.1    jruoho {
   1065      1.1    jruoho     ACPI_PARSE_OBJECT       *Op;
   1066      1.1    jruoho     ACPI_PARSE_OBJECT       *Child;
   1067      1.1    jruoho     ACPI_PARSE_OBJECT       *PrevChild;
   1068      1.1    jruoho     va_list                 ap;
   1069      1.1    jruoho     UINT32                  i;
   1070      1.1    jruoho     BOOLEAN                 FirstChild;
   1071      1.1    jruoho 
   1072      1.1    jruoho 
   1073      1.1    jruoho     va_start (ap, NumChildren);
   1074      1.1    jruoho 
   1075      1.1    jruoho     /* Allocate one new node */
   1076      1.1    jruoho 
   1077      1.1    jruoho     Op = TrAllocateNode (ParseOpcode);
   1078      1.1    jruoho 
   1079      1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
   1080      1.1    jruoho         "\nCreateNode  Ln/Col %u/%u NewParent %p Child %u Op %s  ",
   1081  1.4.2.2     skrll         Op->Asl.LineNumber, Op->Asl.Column, Op,
   1082  1.4.2.2     skrll         NumChildren, UtGetOpName(ParseOpcode));
   1083      1.1    jruoho 
   1084      1.1    jruoho     /* Some extra debug output based on the parse opcode */
   1085      1.1    jruoho 
   1086      1.1    jruoho     switch (ParseOpcode)
   1087      1.1    jruoho     {
   1088  1.4.2.2     skrll     case PARSEOP_ASL_CODE:
   1089      1.3  christos 
   1090  1.4.2.3     skrll         Gbl_ParseTreeRoot = Op;
   1091  1.4.2.2     skrll         Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
   1092  1.4.2.2     skrll         DbgPrint (ASL_PARSE_OUTPUT, "ASLCODE (Tree Completed)->");
   1093  1.4.2.2     skrll         break;
   1094  1.4.2.2     skrll 
   1095  1.4.2.2     skrll     case PARSEOP_DEFINITION_BLOCK:
   1096  1.4.2.2     skrll 
   1097      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
   1098      1.1    jruoho         break;
   1099      1.1    jruoho 
   1100      1.1    jruoho     case PARSEOP_OPERATIONREGION:
   1101      1.3  christos 
   1102      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
   1103      1.1    jruoho         break;
   1104      1.1    jruoho 
   1105      1.1    jruoho     case PARSEOP_OR:
   1106      1.3  christos 
   1107      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "OR->");
   1108      1.1    jruoho         break;
   1109      1.1    jruoho 
   1110      1.1    jruoho     default:
   1111      1.3  christos 
   1112      1.1    jruoho         /* Nothing to do for other opcodes */
   1113      1.3  christos 
   1114      1.1    jruoho         break;
   1115      1.1    jruoho     }
   1116      1.1    jruoho 
   1117      1.1    jruoho     /* Link the new node to its children */
   1118      1.1    jruoho 
   1119      1.1    jruoho     PrevChild = NULL;
   1120      1.1    jruoho     FirstChild = TRUE;
   1121      1.1    jruoho     for (i = 0; i < NumChildren; i++)
   1122      1.1    jruoho     {
   1123      1.1    jruoho         /* Get the next child */
   1124      1.1    jruoho 
   1125      1.1    jruoho         Child = va_arg (ap, ACPI_PARSE_OBJECT *);
   1126      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
   1127      1.1    jruoho 
   1128      1.1    jruoho         /*
   1129      1.1    jruoho          * If child is NULL, this means that an optional argument
   1130      1.3  christos          * was omitted. We must create a placeholder with a special
   1131      1.1    jruoho          * opcode (DEFAULT_ARG) so that the code generator will know
   1132      1.1    jruoho          * that it must emit the correct default for this argument
   1133      1.1    jruoho          */
   1134      1.1    jruoho         if (!Child)
   1135      1.1    jruoho         {
   1136      1.1    jruoho             Child = TrAllocateNode (PARSEOP_DEFAULT_ARG);
   1137      1.1    jruoho         }
   1138      1.1    jruoho 
   1139      1.1    jruoho         /* Link first child to parent */
   1140      1.1    jruoho 
   1141      1.1    jruoho         if (FirstChild)
   1142      1.1    jruoho         {
   1143      1.1    jruoho             FirstChild = FALSE;
   1144      1.1    jruoho             Op->Asl.Child = Child;
   1145  1.4.2.5     skrll 
   1146  1.4.2.5     skrll             /*
   1147  1.4.2.5     skrll              * For the ASL-/ASL+ converter: if the ParseOp is a connection,
   1148  1.4.2.5     skrll              * external, offset or accessAs, it means that the comments in the
   1149  1.4.2.5     skrll              * FirstChild belongs to their parent due to the parsing order in
   1150  1.4.2.5     skrll              * the .y files. To correct this, take the comments in the
   1151  1.4.2.5     skrll              * FirstChild place it in the parent. This also means that
   1152  1.4.2.5     skrll              * legitimate comments for the child gets put to the parent.
   1153  1.4.2.5     skrll              */
   1154  1.4.2.5     skrll             if (Gbl_CaptureComments &&
   1155  1.4.2.5     skrll                 ((ParseOpcode == PARSEOP_CONNECTION) ||
   1156  1.4.2.5     skrll                  (ParseOpcode == PARSEOP_EXTERNAL) ||
   1157  1.4.2.5     skrll                  (ParseOpcode == PARSEOP_OFFSET) ||
   1158  1.4.2.5     skrll                  (ParseOpcode == PARSEOP_ACCESSAS)))
   1159  1.4.2.5     skrll             {
   1160  1.4.2.5     skrll                 Op->Asl.CommentList      = Child->Asl.CommentList;
   1161  1.4.2.5     skrll                 Op->Asl.EndBlkComment    = Child->Asl.EndBlkComment;
   1162  1.4.2.5     skrll                 Op->Asl.InlineComment    = Child->Asl.InlineComment;
   1163  1.4.2.5     skrll                 Op->Asl.FileChanged      = Child->Asl.FileChanged;
   1164  1.4.2.5     skrll 
   1165  1.4.2.5     skrll                 Child->Asl.CommentList   = NULL;
   1166  1.4.2.5     skrll                 Child->Asl.EndBlkComment = NULL;
   1167  1.4.2.5     skrll                 Child->Asl.InlineComment = NULL;
   1168  1.4.2.5     skrll                 Child->Asl.FileChanged   = FALSE;
   1169  1.4.2.5     skrll 
   1170  1.4.2.5     skrll                 /*
   1171  1.4.2.5     skrll                  * These do not need to be "passed off". They can be copied
   1172  1.4.2.5     skrll                  * because the code for these opcodes should be printed in the
   1173  1.4.2.5     skrll                  * same file.
   1174  1.4.2.5     skrll                  */
   1175  1.4.2.5     skrll                 Op->Asl.Filename         = Child->Asl.Filename;
   1176  1.4.2.5     skrll                 Op->Asl.ParentFilename   = Child->Asl.ParentFilename;
   1177  1.4.2.5     skrll             }
   1178      1.1    jruoho         }
   1179      1.1    jruoho 
   1180      1.1    jruoho         /* Point all children to parent */
   1181      1.1    jruoho 
   1182      1.1    jruoho         Child->Asl.Parent = Op;
   1183      1.1    jruoho 
   1184      1.1    jruoho         /* Link children in a peer list */
   1185      1.1    jruoho 
   1186      1.1    jruoho         if (PrevChild)
   1187      1.1    jruoho         {
   1188      1.1    jruoho             PrevChild->Asl.Next = Child;
   1189      1.1    jruoho         };
   1190      1.1    jruoho 
   1191  1.4.2.5     skrll         /* Get the comment from last child in the resource template call */
   1192  1.4.2.5     skrll 
   1193  1.4.2.5     skrll         if (Gbl_CaptureComments &&
   1194  1.4.2.5     skrll             (Op->Asl.ParseOpcode == PARSEOP_RESOURCETEMPLATE))
   1195  1.4.2.5     skrll         {
   1196  1.4.2.5     skrll             CvDbgPrint ("Transferred current comment list to this node.\n");
   1197  1.4.2.5     skrll             Op->Asl.CommentList = Child->Asl.CommentList;
   1198  1.4.2.5     skrll             Child->Asl.CommentList = NULL;
   1199  1.4.2.5     skrll             Op->Asl.InlineComment = Child->Asl.InlineComment;
   1200  1.4.2.5     skrll             Child->Asl.InlineComment = NULL;
   1201  1.4.2.5     skrll         }
   1202  1.4.2.5     skrll 
   1203      1.1    jruoho         /*
   1204      1.1    jruoho          * This child might be a list, point all nodes in the list
   1205      1.1    jruoho          * to the same parent
   1206      1.1    jruoho          */
   1207      1.1    jruoho         while (Child->Asl.Next)
   1208      1.1    jruoho         {
   1209      1.1    jruoho             Child = Child->Asl.Next;
   1210      1.1    jruoho             Child->Asl.Parent = Op;
   1211      1.1    jruoho         }
   1212      1.1    jruoho 
   1213      1.1    jruoho         PrevChild = Child;
   1214      1.1    jruoho     }
   1215      1.1    jruoho     va_end(ap);
   1216      1.1    jruoho 
   1217  1.4.2.1     skrll     DbgPrint (ASL_PARSE_OUTPUT, "\n");
   1218      1.3  christos     return (Op);
   1219      1.1    jruoho }
   1220      1.1    jruoho 
   1221      1.1    jruoho 
   1222      1.1    jruoho /*******************************************************************************
   1223      1.1    jruoho  *
   1224      1.1    jruoho  * FUNCTION:    TrLinkChildren
   1225      1.1    jruoho  *
   1226      1.1    jruoho  * PARAMETERS:  Op                - An existing parse node
   1227  1.4.2.5     skrll  *              NumChildren        - Number of children to follow
   1228  1.4.2.5     skrll  *              ...                - A list of child nodes to link to the new
   1229  1.4.2.5     skrll  *                                   node. NumChildren long.
   1230      1.1    jruoho  *
   1231      1.1    jruoho  * RETURN:      The updated (linked) node
   1232      1.1    jruoho  *
   1233      1.1    jruoho  * DESCRIPTION: Link a group of nodes to an existing parse node
   1234      1.1    jruoho  *
   1235      1.1    jruoho  ******************************************************************************/
   1236      1.1    jruoho 
   1237      1.1    jruoho ACPI_PARSE_OBJECT *
   1238      1.1    jruoho TrLinkChildren (
   1239      1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
   1240      1.1    jruoho     UINT32                  NumChildren,
   1241      1.1    jruoho     ...)
   1242      1.1    jruoho {
   1243      1.1    jruoho     ACPI_PARSE_OBJECT       *Child;
   1244      1.1    jruoho     ACPI_PARSE_OBJECT       *PrevChild;
   1245      1.1    jruoho     va_list                 ap;
   1246      1.1    jruoho     UINT32                  i;
   1247      1.1    jruoho     BOOLEAN                 FirstChild;
   1248      1.1    jruoho 
   1249      1.1    jruoho 
   1250      1.1    jruoho     va_start (ap, NumChildren);
   1251      1.1    jruoho 
   1252      1.1    jruoho 
   1253      1.1    jruoho     TrSetEndLineNumber (Op);
   1254      1.1    jruoho 
   1255      1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
   1256      1.1    jruoho         "\nLinkChildren  Line [%u to %u] NewParent %p Child %u Op %s  ",
   1257      1.1    jruoho         Op->Asl.LineNumber, Op->Asl.EndLine,
   1258      1.1    jruoho         Op, NumChildren, UtGetOpName(Op->Asl.ParseOpcode));
   1259      1.1    jruoho 
   1260      1.1    jruoho     switch (Op->Asl.ParseOpcode)
   1261      1.1    jruoho     {
   1262  1.4.2.2     skrll     case PARSEOP_ASL_CODE:
   1263      1.3  christos 
   1264  1.4.2.3     skrll         Gbl_ParseTreeRoot = Op;
   1265  1.4.2.2     skrll         Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
   1266  1.4.2.2     skrll         DbgPrint (ASL_PARSE_OUTPUT, "ASLCODE (Tree Completed)->");
   1267  1.4.2.2     skrll         break;
   1268  1.4.2.2     skrll 
   1269  1.4.2.2     skrll     case PARSEOP_DEFINITION_BLOCK:
   1270  1.4.2.2     skrll 
   1271      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
   1272      1.1    jruoho         break;
   1273      1.1    jruoho 
   1274      1.1    jruoho     case PARSEOP_OPERATIONREGION:
   1275      1.3  christos 
   1276      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
   1277      1.1    jruoho         break;
   1278      1.1    jruoho 
   1279      1.1    jruoho     case PARSEOP_OR:
   1280      1.3  christos 
   1281      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "OR->");
   1282      1.1    jruoho         break;
   1283      1.1    jruoho 
   1284      1.1    jruoho     default:
   1285      1.3  christos 
   1286      1.1    jruoho         /* Nothing to do for other opcodes */
   1287      1.3  christos 
   1288      1.1    jruoho         break;
   1289      1.1    jruoho     }
   1290      1.1    jruoho 
   1291  1.4.2.5     skrll     /* The following is for capturing comments */
   1292  1.4.2.5     skrll 
   1293  1.4.2.5     skrll     if(Gbl_CaptureComments)
   1294  1.4.2.5     skrll     {
   1295  1.4.2.5     skrll         /*
   1296  1.4.2.5     skrll          * If there are "regular comments" detected at this point,
   1297  1.4.2.5     skrll          * then is an endBlk comment. Categorize it as so and distribute
   1298  1.4.2.5     skrll          * all regular comments to this parse node.
   1299  1.4.2.5     skrll          */
   1300  1.4.2.5     skrll         if (Gbl_Comment_List_Head)
   1301  1.4.2.5     skrll         {
   1302  1.4.2.5     skrll             Op->Asl.EndBlkComment = Gbl_Comment_List_Head;
   1303  1.4.2.5     skrll             CvDbgPrint ("EndBlk Comment for %s: %s",
   1304  1.4.2.5     skrll                 Op->Asl.ParseOpName, Gbl_Comment_List_Head->Comment);
   1305  1.4.2.5     skrll             Gbl_Comment_List_Head = NULL;
   1306  1.4.2.5     skrll             Gbl_Comment_List_Tail = NULL;
   1307  1.4.2.5     skrll         }
   1308  1.4.2.5     skrll     }
   1309  1.4.2.5     skrll 
   1310      1.1    jruoho     /* Link the new node to it's children */
   1311      1.1    jruoho 
   1312      1.1    jruoho     PrevChild = NULL;
   1313      1.1    jruoho     FirstChild = TRUE;
   1314      1.1    jruoho     for (i = 0; i < NumChildren; i++)
   1315      1.1    jruoho     {
   1316      1.1    jruoho         Child = va_arg (ap, ACPI_PARSE_OBJECT *);
   1317      1.1    jruoho 
   1318      1.1    jruoho         if ((Child == PrevChild) && (Child != NULL))
   1319      1.1    jruoho         {
   1320      1.1    jruoho             AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Child,
   1321      1.1    jruoho                 "Child node list invalid");
   1322      1.3  christos             va_end(ap);
   1323      1.3  christos             return (Op);
   1324      1.1    jruoho         }
   1325      1.1    jruoho 
   1326      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
   1327      1.1    jruoho 
   1328      1.1    jruoho         /*
   1329      1.1    jruoho          * If child is NULL, this means that an optional argument
   1330      1.3  christos          * was omitted. We must create a placeholder with a special
   1331      1.1    jruoho          * opcode (DEFAULT_ARG) so that the code generator will know
   1332      1.1    jruoho          * that it must emit the correct default for this argument
   1333      1.1    jruoho          */
   1334      1.1    jruoho         if (!Child)
   1335      1.1    jruoho         {
   1336      1.1    jruoho             Child = TrAllocateNode (PARSEOP_DEFAULT_ARG);
   1337      1.1    jruoho         }
   1338      1.1    jruoho 
   1339      1.1    jruoho         /* Link first child to parent */
   1340      1.1    jruoho 
   1341      1.1    jruoho         if (FirstChild)
   1342      1.1    jruoho         {
   1343      1.1    jruoho             FirstChild = FALSE;
   1344      1.1    jruoho             Op->Asl.Child = Child;
   1345      1.1    jruoho         }
   1346      1.1    jruoho 
   1347      1.1    jruoho         /* Point all children to parent */
   1348      1.1    jruoho 
   1349      1.1    jruoho         Child->Asl.Parent = Op;
   1350      1.1    jruoho 
   1351      1.1    jruoho         /* Link children in a peer list */
   1352      1.1    jruoho 
   1353      1.1    jruoho         if (PrevChild)
   1354      1.1    jruoho         {
   1355      1.1    jruoho             PrevChild->Asl.Next = Child;
   1356      1.1    jruoho         };
   1357      1.1    jruoho 
   1358      1.1    jruoho         /*
   1359      1.1    jruoho          * This child might be a list, point all nodes in the list
   1360      1.1    jruoho          * to the same parent
   1361      1.1    jruoho          */
   1362      1.1    jruoho         while (Child->Asl.Next)
   1363      1.1    jruoho         {
   1364      1.1    jruoho             Child = Child->Asl.Next;
   1365      1.1    jruoho             Child->Asl.Parent = Op;
   1366      1.1    jruoho         }
   1367  1.4.2.2     skrll 
   1368      1.1    jruoho         PrevChild = Child;
   1369      1.1    jruoho     }
   1370      1.3  christos 
   1371      1.1    jruoho     va_end(ap);
   1372      1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
   1373  1.4.2.5     skrll 
   1374  1.4.2.5     skrll 
   1375  1.4.2.5     skrll     if(Gbl_CaptureComments)
   1376  1.4.2.5     skrll     {
   1377  1.4.2.5     skrll         Gbl_CommentState.Latest_Parse_Node = Op;
   1378  1.4.2.5     skrll         CvDbgPrint ("trlinkchildren=====Set latest parse node to this node.\n");
   1379  1.4.2.5     skrll     }
   1380      1.3  christos     return (Op);
   1381      1.1    jruoho }
   1382      1.1    jruoho 
   1383      1.1    jruoho 
   1384      1.1    jruoho /*******************************************************************************
   1385      1.1    jruoho  *
   1386      1.1    jruoho  * FUNCTION:    TrLinkPeerNode
   1387      1.1    jruoho  *
   1388      1.1    jruoho  * PARAMETERS:  Op1           - First peer
   1389      1.1    jruoho  *              Op2           - Second peer
   1390      1.1    jruoho  *
   1391      1.1    jruoho  * RETURN:      Op1 or the non-null node.
   1392      1.1    jruoho  *
   1393      1.3  christos  * DESCRIPTION: Link two nodes as peers. Handles cases where one peer is null.
   1394      1.1    jruoho  *
   1395      1.1    jruoho  ******************************************************************************/
   1396      1.1    jruoho 
   1397      1.1    jruoho ACPI_PARSE_OBJECT *
   1398      1.1    jruoho TrLinkPeerNode (
   1399      1.1    jruoho     ACPI_PARSE_OBJECT       *Op1,
   1400      1.1    jruoho     ACPI_PARSE_OBJECT       *Op2)
   1401      1.1    jruoho {
   1402      1.1    jruoho     ACPI_PARSE_OBJECT       *Next;
   1403      1.1    jruoho 
   1404      1.1    jruoho 
   1405      1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
   1406  1.4.2.1     skrll         "\nLinkPeerNode: 1=%p (%s), 2=%p (%s)\n",
   1407      1.1    jruoho         Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode) : NULL,
   1408      1.1    jruoho         Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode) : NULL);
   1409      1.1    jruoho 
   1410      1.1    jruoho 
   1411      1.1    jruoho     if ((!Op1) && (!Op2))
   1412      1.1    jruoho     {
   1413      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "\nTwo Null nodes!\n");
   1414      1.3  christos         return (Op1);
   1415      1.1    jruoho     }
   1416      1.1    jruoho 
   1417      1.1    jruoho     /* If one of the nodes is null, just return the non-null node */
   1418      1.1    jruoho 
   1419      1.1    jruoho     if (!Op2)
   1420      1.1    jruoho     {
   1421      1.3  christos         return (Op1);
   1422      1.1    jruoho     }
   1423      1.1    jruoho 
   1424      1.1    jruoho     if (!Op1)
   1425      1.1    jruoho     {
   1426      1.3  christos         return (Op2);
   1427      1.1    jruoho     }
   1428      1.1    jruoho 
   1429      1.1    jruoho     if (Op1 == Op2)
   1430      1.1    jruoho     {
   1431      1.1    jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
   1432  1.4.2.1     skrll             "\n************* Internal error, linking node to itself %p\n",
   1433      1.1    jruoho             Op1);
   1434      1.1    jruoho         AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op1,
   1435      1.1    jruoho             "Linking node to itself");
   1436      1.3  christos         return (Op1);
   1437      1.1    jruoho     }
   1438      1.1    jruoho 
   1439      1.1    jruoho     Op1->Asl.Parent = Op2->Asl.Parent;
   1440      1.1    jruoho 
   1441      1.1    jruoho     /*
   1442      1.1    jruoho      * Op 1 may already have a peer list (such as an IF/ELSE pair),
   1443      1.1    jruoho      * so we must walk to the end of the list and attach the new
   1444      1.1    jruoho      * peer at the end
   1445      1.1    jruoho      */
   1446      1.1    jruoho     Next = Op1;
   1447      1.1    jruoho     while (Next->Asl.Next)
   1448      1.1    jruoho     {
   1449      1.1    jruoho         Next = Next->Asl.Next;
   1450      1.1    jruoho     }
   1451      1.1    jruoho 
   1452      1.1    jruoho     Next->Asl.Next = Op2;
   1453      1.3  christos     return (Op1);
   1454      1.1    jruoho }
   1455      1.1    jruoho 
   1456      1.1    jruoho 
   1457      1.1    jruoho /*******************************************************************************
   1458      1.1    jruoho  *
   1459      1.1    jruoho  * FUNCTION:    TrLinkPeerNodes
   1460      1.1    jruoho  *
   1461      1.1    jruoho  * PARAMETERS:  NumPeers            - The number of nodes in the list to follow
   1462      1.1    jruoho  *              ...                 - A list of nodes to link together as peers
   1463      1.1    jruoho  *
   1464      1.1    jruoho  * RETURN:      The first node in the list (head of the peer list)
   1465      1.1    jruoho  *
   1466      1.1    jruoho  * DESCRIPTION: Link together an arbitrary number of peer nodes.
   1467      1.1    jruoho  *
   1468      1.1    jruoho  ******************************************************************************/
   1469      1.1    jruoho 
   1470      1.1    jruoho ACPI_PARSE_OBJECT *
   1471      1.1    jruoho TrLinkPeerNodes (
   1472      1.1    jruoho     UINT32                  NumPeers,
   1473      1.1    jruoho     ...)
   1474      1.1    jruoho {
   1475      1.1    jruoho     ACPI_PARSE_OBJECT       *This;
   1476      1.1    jruoho     ACPI_PARSE_OBJECT       *Next;
   1477      1.1    jruoho     va_list                 ap;
   1478      1.1    jruoho     UINT32                  i;
   1479      1.1    jruoho     ACPI_PARSE_OBJECT       *Start;
   1480      1.1    jruoho 
   1481      1.1    jruoho 
   1482      1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
   1483      1.1    jruoho         "\nLinkPeerNodes: (%u) ", NumPeers);
   1484      1.1    jruoho 
   1485      1.1    jruoho     va_start (ap, NumPeers);
   1486      1.1    jruoho     This = va_arg (ap, ACPI_PARSE_OBJECT *);
   1487      1.1    jruoho     Start = This;
   1488      1.1    jruoho 
   1489      1.1    jruoho     /*
   1490      1.1    jruoho      * Link all peers
   1491      1.1    jruoho      */
   1492      1.1    jruoho     for (i = 0; i < (NumPeers -1); i++)
   1493      1.1    jruoho     {
   1494      1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "%u=%p ", (i+1), This);
   1495      1.1    jruoho 
   1496      1.1    jruoho         while (This->Asl.Next)
   1497      1.1    jruoho         {
   1498      1.1    jruoho             This = This->Asl.Next;
   1499      1.1    jruoho         }
   1500      1.1    jruoho 
   1501      1.1    jruoho         /* Get another peer node */
   1502      1.1    jruoho 
   1503      1.1    jruoho         Next = va_arg (ap, ACPI_PARSE_OBJECT *);
   1504      1.1    jruoho         if (!Next)
   1505      1.1    jruoho         {
   1506      1.1    jruoho             Next = TrAllocateNode (PARSEOP_DEFAULT_ARG);
   1507      1.1    jruoho         }
   1508      1.1    jruoho 
   1509      1.1    jruoho         /* link new node to the current node */
   1510      1.1    jruoho 
   1511      1.1    jruoho         This->Asl.Next = Next;
   1512      1.1    jruoho         This = Next;
   1513      1.1    jruoho     }
   1514      1.1    jruoho     va_end (ap);
   1515      1.1    jruoho 
   1516  1.4.2.1     skrll     DbgPrint (ASL_PARSE_OUTPUT,"\n");
   1517      1.1    jruoho     return (Start);
   1518      1.1    jruoho }
   1519      1.1    jruoho 
   1520      1.1    jruoho 
   1521      1.1    jruoho /*******************************************************************************
   1522      1.1    jruoho  *
   1523      1.1    jruoho  * FUNCTION:    TrLinkChildNode
   1524      1.1    jruoho  *
   1525      1.1    jruoho  * PARAMETERS:  Op1           - Parent node
   1526      1.1    jruoho  *              Op2           - Op to become a child
   1527      1.1    jruoho  *
   1528      1.1    jruoho  * RETURN:      The parent node
   1529      1.1    jruoho  *
   1530      1.1    jruoho  * DESCRIPTION: Link two nodes together as a parent and child
   1531      1.1    jruoho  *
   1532      1.1    jruoho  ******************************************************************************/
   1533      1.1    jruoho 
   1534      1.1    jruoho ACPI_PARSE_OBJECT *
   1535      1.1    jruoho TrLinkChildNode (
   1536      1.1    jruoho     ACPI_PARSE_OBJECT       *Op1,
   1537      1.1    jruoho     ACPI_PARSE_OBJECT       *Op2)
   1538      1.1    jruoho {
   1539      1.1    jruoho     ACPI_PARSE_OBJECT       *Next;
   1540      1.1    jruoho 
   1541      1.1    jruoho 
   1542      1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
   1543  1.4.2.1     skrll         "\nLinkChildNode: Parent=%p (%s), Child=%p (%s)\n",
   1544      1.1    jruoho         Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode): NULL,
   1545      1.1    jruoho         Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode): NULL);
   1546      1.1    jruoho 
   1547  1.4.2.5     skrll     /*
   1548  1.4.2.5     skrll      * Converter: if TrLinkChildNode is called to link a method call,
   1549  1.4.2.5     skrll      * turn on capture comments as it signifies that we are done parsing
   1550  1.4.2.5     skrll      * a method call.
   1551  1.4.2.5     skrll      */
   1552  1.4.2.5     skrll     if (Gbl_CaptureComments)
   1553  1.4.2.5     skrll     {
   1554  1.4.2.5     skrll         if (Op1->Asl.ParseOpcode == PARSEOP_METHODCALL)
   1555  1.4.2.5     skrll         {
   1556  1.4.2.5     skrll             Gbl_CommentState.CaptureComments = TRUE;
   1557  1.4.2.5     skrll         }
   1558  1.4.2.5     skrll         Gbl_CommentState.Latest_Parse_Node = Op1;
   1559  1.4.2.5     skrll     }
   1560      1.1    jruoho     if (!Op1 || !Op2)
   1561      1.1    jruoho     {
   1562      1.3  christos         return (Op1);
   1563      1.1    jruoho     }
   1564      1.1    jruoho 
   1565      1.1    jruoho     Op1->Asl.Child = Op2;
   1566      1.1    jruoho 
   1567      1.1    jruoho     /* Set the child and all peers of the child to point to the parent */
   1568      1.1    jruoho 
   1569      1.1    jruoho     Next = Op2;
   1570      1.1    jruoho     while (Next)
   1571      1.1    jruoho     {
   1572      1.1    jruoho         Next->Asl.Parent = Op1;
   1573      1.1    jruoho         Next = Next->Asl.Next;
   1574      1.1    jruoho     }
   1575      1.1    jruoho 
   1576      1.3  christos     return (Op1);
   1577      1.1    jruoho }
   1578      1.1    jruoho 
   1579      1.1    jruoho 
   1580      1.1    jruoho /*******************************************************************************
   1581      1.1    jruoho  *
   1582      1.1    jruoho  * FUNCTION:    TrWalkParseTree
   1583      1.1    jruoho  *
   1584      1.1    jruoho  * PARAMETERS:  Visitation              - Type of walk
   1585      1.1    jruoho  *              DescendingCallback      - Called during tree descent
   1586      1.1    jruoho  *              AscendingCallback       - Called during tree ascent
   1587      1.1    jruoho  *              Context                 - To be passed to the callbacks
   1588      1.1    jruoho  *
   1589      1.1    jruoho  * RETURN:      Status from callback(s)
   1590      1.1    jruoho  *
   1591      1.1    jruoho  * DESCRIPTION: Walk the entire parse tree.
   1592      1.1    jruoho  *
   1593      1.1    jruoho  ******************************************************************************/
   1594      1.1    jruoho 
   1595      1.1    jruoho ACPI_STATUS
   1596      1.1    jruoho TrWalkParseTree (
   1597      1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
   1598      1.1    jruoho     UINT32                  Visitation,
   1599      1.1    jruoho     ASL_WALK_CALLBACK       DescendingCallback,
   1600      1.1    jruoho     ASL_WALK_CALLBACK       AscendingCallback,
   1601      1.1    jruoho     void                    *Context)
   1602      1.1    jruoho {
   1603      1.1    jruoho     UINT32                  Level;
   1604      1.1    jruoho     BOOLEAN                 NodePreviouslyVisited;
   1605      1.1    jruoho     ACPI_PARSE_OBJECT       *StartOp = Op;
   1606      1.1    jruoho     ACPI_STATUS             Status;
   1607      1.1    jruoho 
   1608      1.1    jruoho 
   1609  1.4.2.3     skrll     if (!Gbl_ParseTreeRoot)
   1610      1.1    jruoho     {
   1611      1.1    jruoho         return (AE_OK);
   1612      1.1    jruoho     }
   1613      1.1    jruoho 
   1614      1.1    jruoho     Level = 0;
   1615      1.1    jruoho     NodePreviouslyVisited = FALSE;
   1616      1.1    jruoho 
   1617      1.1    jruoho     switch (Visitation)
   1618      1.1    jruoho     {
   1619      1.1    jruoho     case ASL_WALK_VISIT_DOWNWARD:
   1620      1.1    jruoho 
   1621      1.1    jruoho         while (Op)
   1622      1.1    jruoho         {
   1623      1.1    jruoho             if (!NodePreviouslyVisited)
   1624      1.1    jruoho             {
   1625      1.1    jruoho                 /* Let the callback process the node. */
   1626      1.1    jruoho 
   1627      1.1    jruoho                 Status = DescendingCallback (Op, Level, Context);
   1628      1.1    jruoho                 if (ACPI_SUCCESS (Status))
   1629      1.1    jruoho                 {
   1630      1.1    jruoho                     /* Visit children first, once */
   1631      1.1    jruoho 
   1632      1.1    jruoho                     if (Op->Asl.Child)
   1633      1.1    jruoho                     {
   1634      1.1    jruoho                         Level++;
   1635      1.1    jruoho                         Op = Op->Asl.Child;
   1636      1.1    jruoho                         continue;
   1637      1.1    jruoho                     }
   1638      1.1    jruoho                 }
   1639      1.1    jruoho                 else if (Status != AE_CTRL_DEPTH)
   1640      1.1    jruoho                 {
   1641      1.1    jruoho                     /* Exit immediately on any error */
   1642      1.1    jruoho 
   1643      1.1    jruoho                     return (Status);
   1644      1.1    jruoho                 }
   1645      1.1    jruoho             }
   1646      1.1    jruoho 
   1647      1.1    jruoho             /* Terminate walk at start op */
   1648      1.1    jruoho 
   1649      1.1    jruoho             if (Op == StartOp)
   1650      1.1    jruoho             {
   1651      1.1    jruoho                 break;
   1652      1.1    jruoho             }
   1653      1.1    jruoho 
   1654      1.1    jruoho             /* No more children, visit peers */
   1655      1.1    jruoho 
   1656      1.1    jruoho             if (Op->Asl.Next)
   1657      1.1    jruoho             {
   1658      1.1    jruoho                 Op = Op->Asl.Next;
   1659      1.1    jruoho                 NodePreviouslyVisited = FALSE;
   1660      1.1    jruoho             }
   1661      1.1    jruoho             else
   1662      1.1    jruoho             {
   1663      1.1    jruoho                 /* No children or peers, re-visit parent */
   1664      1.1    jruoho 
   1665      1.1    jruoho                 if (Level != 0 )
   1666      1.1    jruoho                 {
   1667      1.1    jruoho                     Level--;
   1668      1.1    jruoho                 }
   1669      1.1    jruoho                 Op = Op->Asl.Parent;
   1670      1.1    jruoho                 NodePreviouslyVisited = TRUE;
   1671      1.1    jruoho             }
   1672      1.1    jruoho         }
   1673      1.1    jruoho         break;
   1674      1.1    jruoho 
   1675      1.1    jruoho     case ASL_WALK_VISIT_UPWARD:
   1676      1.1    jruoho 
   1677      1.1    jruoho         while (Op)
   1678      1.1    jruoho         {
   1679      1.1    jruoho             /* Visit leaf node (no children) or parent node on return trip */
   1680      1.1    jruoho 
   1681      1.1    jruoho             if ((!Op->Asl.Child) ||
   1682      1.1    jruoho                 (NodePreviouslyVisited))
   1683      1.1    jruoho             {
   1684      1.1    jruoho                 /* Let the callback process the node. */
   1685      1.1    jruoho 
   1686      1.1    jruoho                 Status = AscendingCallback (Op, Level, Context);
   1687      1.1    jruoho                 if (ACPI_FAILURE (Status))
   1688      1.1    jruoho                 {
   1689      1.1    jruoho                     return (Status);
   1690      1.1    jruoho                 }
   1691      1.1    jruoho             }
   1692      1.1    jruoho             else
   1693      1.1    jruoho             {
   1694      1.1    jruoho                 /* Visit children first, once */
   1695      1.1    jruoho 
   1696      1.1    jruoho                 Level++;
   1697      1.1    jruoho                 Op = Op->Asl.Child;
   1698      1.1    jruoho                 continue;
   1699      1.1    jruoho             }
   1700      1.1    jruoho 
   1701      1.1    jruoho             /* Terminate walk at start op */
   1702      1.1    jruoho 
   1703      1.1    jruoho             if (Op == StartOp)
   1704      1.1    jruoho             {
   1705      1.1    jruoho                 break;
   1706      1.1    jruoho             }
   1707      1.1    jruoho 
   1708      1.1    jruoho             /* No more children, visit peers */
   1709      1.1    jruoho 
   1710      1.1    jruoho             if (Op->Asl.Next)
   1711      1.1    jruoho             {
   1712      1.1    jruoho                 Op = Op->Asl.Next;
   1713      1.1    jruoho                 NodePreviouslyVisited = FALSE;
   1714      1.1    jruoho             }
   1715      1.1    jruoho             else
   1716      1.1    jruoho             {
   1717      1.1    jruoho                 /* No children or peers, re-visit parent */
   1718      1.1    jruoho 
   1719      1.1    jruoho                 if (Level != 0 )
   1720      1.1    jruoho                 {
   1721      1.1    jruoho                     Level--;
   1722      1.1    jruoho                 }
   1723      1.1    jruoho                 Op = Op->Asl.Parent;
   1724      1.1    jruoho                 NodePreviouslyVisited = TRUE;
   1725      1.1    jruoho             }
   1726      1.1    jruoho         }
   1727      1.1    jruoho         break;
   1728      1.1    jruoho 
   1729      1.1    jruoho      case ASL_WALK_VISIT_TWICE:
   1730      1.1    jruoho 
   1731      1.1    jruoho         while (Op)
   1732      1.1    jruoho         {
   1733      1.1    jruoho             if (NodePreviouslyVisited)
   1734      1.1    jruoho             {
   1735      1.1    jruoho                 Status = AscendingCallback (Op, Level, Context);
   1736      1.1    jruoho                 if (ACPI_FAILURE (Status))
   1737      1.1    jruoho                 {
   1738      1.1    jruoho                     return (Status);
   1739      1.1    jruoho                 }
   1740      1.1    jruoho             }
   1741      1.1    jruoho             else
   1742      1.1    jruoho             {
   1743      1.1    jruoho                 /* Let the callback process the node. */
   1744      1.1    jruoho 
   1745      1.1    jruoho                 Status = DescendingCallback (Op, Level, Context);
   1746      1.1    jruoho                 if (ACPI_SUCCESS (Status))
   1747      1.1    jruoho                 {
   1748      1.1    jruoho                     /* Visit children first, once */
   1749      1.1    jruoho 
   1750      1.1    jruoho                     if (Op->Asl.Child)
   1751      1.1    jruoho                     {
   1752      1.1    jruoho                         Level++;
   1753      1.1    jruoho                         Op = Op->Asl.Child;
   1754      1.1    jruoho                         continue;
   1755      1.1    jruoho                     }
   1756      1.1    jruoho                 }
   1757      1.1    jruoho                 else if (Status != AE_CTRL_DEPTH)
   1758      1.1    jruoho                 {
   1759      1.1    jruoho                     /* Exit immediately on any error */
   1760      1.1    jruoho 
   1761      1.1    jruoho                     return (Status);
   1762      1.1    jruoho                 }
   1763      1.1    jruoho             }
   1764      1.1    jruoho 
   1765      1.1    jruoho             /* Terminate walk at start op */
   1766      1.1    jruoho 
   1767      1.1    jruoho             if (Op == StartOp)
   1768      1.1    jruoho             {
   1769      1.1    jruoho                 break;
   1770      1.1    jruoho             }
   1771      1.1    jruoho 
   1772      1.1    jruoho             /* No more children, visit peers */
   1773      1.1    jruoho 
   1774      1.1    jruoho             if (Op->Asl.Next)
   1775      1.1    jruoho             {
   1776      1.1    jruoho                 Op = Op->Asl.Next;
   1777      1.1    jruoho                 NodePreviouslyVisited = FALSE;
   1778      1.1    jruoho             }
   1779      1.1    jruoho             else
   1780      1.1    jruoho             {
   1781      1.1    jruoho                 /* No children or peers, re-visit parent */
   1782      1.1    jruoho 
   1783      1.1    jruoho                 if (Level != 0 )
   1784      1.1    jruoho                 {
   1785      1.1    jruoho                     Level--;
   1786      1.1    jruoho                 }
   1787      1.1    jruoho                 Op = Op->Asl.Parent;
   1788      1.1    jruoho                 NodePreviouslyVisited = TRUE;
   1789      1.1    jruoho             }
   1790      1.1    jruoho         }
   1791      1.1    jruoho         break;
   1792      1.1    jruoho 
   1793      1.1    jruoho     default:
   1794      1.1    jruoho         /* No other types supported */
   1795      1.1    jruoho         break;
   1796      1.1    jruoho     }
   1797      1.1    jruoho 
   1798      1.1    jruoho     /* If we get here, the walk completed with no errors */
   1799      1.1    jruoho 
   1800      1.1    jruoho     return (AE_OK);
   1801      1.1    jruoho }
   1802