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