Home | History | Annotate | Line # | Download | only in compiler
prscan.c revision 1.1.1.1.10.3
      1  1.1.1.1.10.2       tls /******************************************************************************
      2  1.1.1.1.10.2       tls  *
      3  1.1.1.1.10.2       tls  * Module Name: prscan - Preprocessor start-up and file scan module
      4  1.1.1.1.10.2       tls  *
      5  1.1.1.1.10.2       tls  *****************************************************************************/
      6  1.1.1.1.10.2       tls 
      7  1.1.1.1.10.2       tls /*
      8  1.1.1.1.10.3  jdolecek  * Copyright (C) 2000 - 2017, Intel Corp.
      9  1.1.1.1.10.2       tls  * All rights reserved.
     10  1.1.1.1.10.2       tls  *
     11  1.1.1.1.10.2       tls  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.1.10.2       tls  * modification, are permitted provided that the following conditions
     13  1.1.1.1.10.2       tls  * are met:
     14  1.1.1.1.10.2       tls  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.1.10.2       tls  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.1.10.2       tls  *    without modification.
     17  1.1.1.1.10.2       tls  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.1.10.2       tls  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.1.10.2       tls  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.1.10.2       tls  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.1.10.2       tls  *    binary redistribution.
     22  1.1.1.1.10.2       tls  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.1.10.2       tls  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.1.10.2       tls  *    from this software without specific prior written permission.
     25  1.1.1.1.10.2       tls  *
     26  1.1.1.1.10.2       tls  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.1.10.2       tls  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.1.10.2       tls  * Software Foundation.
     29  1.1.1.1.10.2       tls  *
     30  1.1.1.1.10.2       tls  * NO WARRANTY
     31  1.1.1.1.10.2       tls  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.1.10.2       tls  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.1.10.2       tls  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.1.10.2       tls  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.1.10.2       tls  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.1.10.2       tls  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.1.10.2       tls  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.1.10.2       tls  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.1.10.2       tls  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.1.10.2       tls  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.1.10.2       tls  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.1.10.2       tls  */
     43  1.1.1.1.10.2       tls 
     44  1.1.1.1.10.2       tls #define _DECLARE_PR_GLOBALS
     45  1.1.1.1.10.2       tls 
     46  1.1.1.1.10.2       tls #include "aslcompiler.h"
     47  1.1.1.1.10.2       tls 
     48  1.1.1.1.10.2       tls /*
     49  1.1.1.1.10.2       tls  * TBDs:
     50  1.1.1.1.10.2       tls  *
     51  1.1.1.1.10.2       tls  * No nested macros, maybe never
     52  1.1.1.1.10.2       tls  * Implement ASL "Include" as well as "#include" here?
     53  1.1.1.1.10.2       tls  */
     54  1.1.1.1.10.2       tls #define _COMPONENT          ASL_PREPROCESSOR
     55  1.1.1.1.10.2       tls         ACPI_MODULE_NAME    ("prscan")
     56  1.1.1.1.10.2       tls 
     57  1.1.1.1.10.2       tls 
     58  1.1.1.1.10.2       tls /* Local prototypes */
     59  1.1.1.1.10.2       tls 
     60  1.1.1.1.10.2       tls static void
     61  1.1.1.1.10.2       tls PrPreprocessInputFile (
     62  1.1.1.1.10.2       tls     void);
     63  1.1.1.1.10.2       tls 
     64  1.1.1.1.10.2       tls static void
     65  1.1.1.1.10.2       tls PrDoDirective (
     66  1.1.1.1.10.2       tls     char                    *DirectiveToken,
     67  1.1.1.1.10.2       tls     char                    **Next);
     68  1.1.1.1.10.2       tls 
     69  1.1.1.1.10.3  jdolecek static void
     70  1.1.1.1.10.3  jdolecek PrGetNextLineInit (
     71  1.1.1.1.10.3  jdolecek     void);
     72  1.1.1.1.10.3  jdolecek 
     73  1.1.1.1.10.3  jdolecek static UINT32
     74  1.1.1.1.10.3  jdolecek PrGetNextLine (
     75  1.1.1.1.10.3  jdolecek     FILE                    *Handle);
     76  1.1.1.1.10.3  jdolecek 
     77  1.1.1.1.10.2       tls static int
     78  1.1.1.1.10.2       tls PrMatchDirective (
     79  1.1.1.1.10.2       tls     char                    *Directive);
     80  1.1.1.1.10.2       tls 
     81  1.1.1.1.10.2       tls static void
     82  1.1.1.1.10.2       tls PrPushDirective (
     83  1.1.1.1.10.2       tls     int                     Directive,
     84  1.1.1.1.10.2       tls     char                    *Argument);
     85  1.1.1.1.10.2       tls 
     86  1.1.1.1.10.2       tls static ACPI_STATUS
     87  1.1.1.1.10.2       tls PrPopDirective (
     88  1.1.1.1.10.2       tls     void);
     89  1.1.1.1.10.2       tls 
     90  1.1.1.1.10.2       tls static void
     91  1.1.1.1.10.2       tls PrDbgPrint (
     92  1.1.1.1.10.2       tls     char                    *Action,
     93  1.1.1.1.10.2       tls     char                    *DirectiveName);
     94  1.1.1.1.10.2       tls 
     95  1.1.1.1.10.3  jdolecek static void
     96  1.1.1.1.10.3  jdolecek PrDoIncludeBuffer (
     97  1.1.1.1.10.3  jdolecek     char                    *Pathname,
     98  1.1.1.1.10.3  jdolecek     char                    *BufferName);
     99  1.1.1.1.10.3  jdolecek 
    100  1.1.1.1.10.3  jdolecek static void
    101  1.1.1.1.10.3  jdolecek PrDoIncludeFile (
    102  1.1.1.1.10.3  jdolecek     char                    *Pathname);
    103  1.1.1.1.10.3  jdolecek 
    104  1.1.1.1.10.2       tls 
    105  1.1.1.1.10.2       tls /*
    106  1.1.1.1.10.2       tls  * Supported preprocessor directives
    107  1.1.1.1.10.3  jdolecek  * Each entry is of the form "Name, ArgumentCount"
    108  1.1.1.1.10.2       tls  */
    109  1.1.1.1.10.2       tls static const PR_DIRECTIVE_INFO      Gbl_DirectiveInfo[] =
    110  1.1.1.1.10.2       tls {
    111  1.1.1.1.10.3  jdolecek     {"define",          1},
    112  1.1.1.1.10.3  jdolecek     {"elif",            0}, /* Converted to #else..#if internally */
    113  1.1.1.1.10.3  jdolecek     {"else",            0},
    114  1.1.1.1.10.3  jdolecek     {"endif",           0},
    115  1.1.1.1.10.3  jdolecek     {"error",           1},
    116  1.1.1.1.10.3  jdolecek     {"if",              1},
    117  1.1.1.1.10.3  jdolecek     {"ifdef",           1},
    118  1.1.1.1.10.3  jdolecek     {"ifndef",          1},
    119  1.1.1.1.10.3  jdolecek     {"include",         0}, /* Argument is not standard format, so just use 0 here */
    120  1.1.1.1.10.3  jdolecek     {"includebuffer",   0}, /* Argument is not standard format, so just use 0 here */
    121  1.1.1.1.10.3  jdolecek     {"line",            1},
    122  1.1.1.1.10.3  jdolecek     {"pragma",          1},
    123  1.1.1.1.10.3  jdolecek     {"undef",           1},
    124  1.1.1.1.10.3  jdolecek     {"warning",         1},
    125  1.1.1.1.10.3  jdolecek     {NULL,              0}
    126  1.1.1.1.10.2       tls };
    127  1.1.1.1.10.2       tls 
    128  1.1.1.1.10.3  jdolecek /* This table must match ordering of above table exactly */
    129  1.1.1.1.10.3  jdolecek 
    130  1.1.1.1.10.2       tls enum Gbl_DirectiveIndexes
    131  1.1.1.1.10.2       tls {
    132  1.1.1.1.10.2       tls     PR_DIRECTIVE_DEFINE = 0,
    133  1.1.1.1.10.2       tls     PR_DIRECTIVE_ELIF,
    134  1.1.1.1.10.2       tls     PR_DIRECTIVE_ELSE,
    135  1.1.1.1.10.2       tls     PR_DIRECTIVE_ENDIF,
    136  1.1.1.1.10.2       tls     PR_DIRECTIVE_ERROR,
    137  1.1.1.1.10.2       tls     PR_DIRECTIVE_IF,
    138  1.1.1.1.10.2       tls     PR_DIRECTIVE_IFDEF,
    139  1.1.1.1.10.2       tls     PR_DIRECTIVE_IFNDEF,
    140  1.1.1.1.10.2       tls     PR_DIRECTIVE_INCLUDE,
    141  1.1.1.1.10.3  jdolecek     PR_DIRECTIVE_INCLUDEBUFFER,
    142  1.1.1.1.10.2       tls     PR_DIRECTIVE_LINE,
    143  1.1.1.1.10.2       tls     PR_DIRECTIVE_PRAGMA,
    144  1.1.1.1.10.2       tls     PR_DIRECTIVE_UNDEF,
    145  1.1.1.1.10.3  jdolecek     PR_DIRECTIVE_WARNING
    146  1.1.1.1.10.2       tls };
    147  1.1.1.1.10.2       tls 
    148  1.1.1.1.10.2       tls #define ASL_DIRECTIVE_NOT_FOUND     -1
    149  1.1.1.1.10.2       tls 
    150  1.1.1.1.10.2       tls 
    151  1.1.1.1.10.2       tls /*******************************************************************************
    152  1.1.1.1.10.2       tls  *
    153  1.1.1.1.10.2       tls  * FUNCTION:    PrInitializePreprocessor
    154  1.1.1.1.10.2       tls  *
    155  1.1.1.1.10.2       tls  * PARAMETERS:  None
    156  1.1.1.1.10.2       tls  *
    157  1.1.1.1.10.2       tls  * RETURN:      None
    158  1.1.1.1.10.2       tls  *
    159  1.1.1.1.10.2       tls  * DESCRIPTION: Startup initialization for the Preprocessor.
    160  1.1.1.1.10.2       tls  *
    161  1.1.1.1.10.2       tls  ******************************************************************************/
    162  1.1.1.1.10.2       tls 
    163  1.1.1.1.10.2       tls void
    164  1.1.1.1.10.2       tls PrInitializePreprocessor (
    165  1.1.1.1.10.2       tls     void)
    166  1.1.1.1.10.2       tls {
    167  1.1.1.1.10.2       tls     /* Init globals and the list of #defines */
    168  1.1.1.1.10.2       tls 
    169  1.1.1.1.10.2       tls     PrInitializeGlobals ();
    170  1.1.1.1.10.2       tls     Gbl_DefineList = NULL;
    171  1.1.1.1.10.2       tls }
    172  1.1.1.1.10.2       tls 
    173  1.1.1.1.10.2       tls 
    174  1.1.1.1.10.2       tls /*******************************************************************************
    175  1.1.1.1.10.2       tls  *
    176  1.1.1.1.10.2       tls  * FUNCTION:    PrInitializeGlobals
    177  1.1.1.1.10.2       tls  *
    178  1.1.1.1.10.2       tls  * PARAMETERS:  None
    179  1.1.1.1.10.2       tls  *
    180  1.1.1.1.10.2       tls  * RETURN:      None
    181  1.1.1.1.10.2       tls  *
    182  1.1.1.1.10.2       tls  * DESCRIPTION: Initialize globals for the Preprocessor. Used for startuup
    183  1.1.1.1.10.2       tls  *              initialization and re-initialization between compiles during
    184  1.1.1.1.10.2       tls  *              a multiple source file compile.
    185  1.1.1.1.10.2       tls  *
    186  1.1.1.1.10.2       tls  ******************************************************************************/
    187  1.1.1.1.10.2       tls 
    188  1.1.1.1.10.2       tls void
    189  1.1.1.1.10.2       tls PrInitializeGlobals (
    190  1.1.1.1.10.2       tls     void)
    191  1.1.1.1.10.2       tls {
    192  1.1.1.1.10.2       tls     /* Init globals */
    193  1.1.1.1.10.2       tls 
    194  1.1.1.1.10.2       tls     Gbl_InputFileList = NULL;
    195  1.1.1.1.10.3  jdolecek     Gbl_CurrentLineNumber = 1;
    196  1.1.1.1.10.2       tls     Gbl_PreprocessorLineNumber = 1;
    197  1.1.1.1.10.2       tls     Gbl_PreprocessorError = FALSE;
    198  1.1.1.1.10.2       tls 
    199  1.1.1.1.10.2       tls     /* These are used to track #if/#else blocks (possibly nested) */
    200  1.1.1.1.10.2       tls 
    201  1.1.1.1.10.2       tls     Gbl_IfDepth = 0;
    202  1.1.1.1.10.2       tls     Gbl_IgnoringThisCodeBlock = FALSE;
    203  1.1.1.1.10.2       tls     Gbl_DirectiveStack = NULL;
    204  1.1.1.1.10.2       tls }
    205  1.1.1.1.10.2       tls 
    206  1.1.1.1.10.2       tls 
    207  1.1.1.1.10.2       tls /*******************************************************************************
    208  1.1.1.1.10.2       tls  *
    209  1.1.1.1.10.2       tls  * FUNCTION:    PrTerminatePreprocessor
    210  1.1.1.1.10.2       tls  *
    211  1.1.1.1.10.2       tls  * PARAMETERS:  None
    212  1.1.1.1.10.2       tls  *
    213  1.1.1.1.10.2       tls  * RETURN:      None
    214  1.1.1.1.10.2       tls  *
    215  1.1.1.1.10.2       tls  * DESCRIPTION: Termination of the preprocessor. Delete lists. Keep any
    216  1.1.1.1.10.2       tls  *              defines that were specified on the command line, in order to
    217  1.1.1.1.10.2       tls  *              support multiple compiles with a single compiler invocation.
    218  1.1.1.1.10.2       tls  *
    219  1.1.1.1.10.2       tls  ******************************************************************************/
    220  1.1.1.1.10.2       tls 
    221  1.1.1.1.10.2       tls void
    222  1.1.1.1.10.2       tls PrTerminatePreprocessor (
    223  1.1.1.1.10.2       tls     void)
    224  1.1.1.1.10.2       tls {
    225  1.1.1.1.10.2       tls     PR_DEFINE_INFO          *DefineInfo;
    226  1.1.1.1.10.2       tls 
    227  1.1.1.1.10.2       tls 
    228  1.1.1.1.10.2       tls     /*
    229  1.1.1.1.10.2       tls      * The persistent defines (created on the command line) are always at the
    230  1.1.1.1.10.2       tls      * end of the list. We save them.
    231  1.1.1.1.10.2       tls      */
    232  1.1.1.1.10.2       tls     while ((Gbl_DefineList) && (!Gbl_DefineList->Persist))
    233  1.1.1.1.10.2       tls     {
    234  1.1.1.1.10.2       tls         DefineInfo = Gbl_DefineList;
    235  1.1.1.1.10.2       tls         Gbl_DefineList = DefineInfo->Next;
    236  1.1.1.1.10.2       tls 
    237  1.1.1.1.10.2       tls         ACPI_FREE (DefineInfo->Replacement);
    238  1.1.1.1.10.2       tls         ACPI_FREE (DefineInfo->Identifier);
    239  1.1.1.1.10.2       tls         ACPI_FREE (DefineInfo);
    240  1.1.1.1.10.2       tls     }
    241  1.1.1.1.10.2       tls }
    242  1.1.1.1.10.2       tls 
    243  1.1.1.1.10.2       tls 
    244  1.1.1.1.10.2       tls /*******************************************************************************
    245  1.1.1.1.10.2       tls  *
    246  1.1.1.1.10.2       tls  * FUNCTION:    PrDoPreprocess
    247  1.1.1.1.10.2       tls  *
    248  1.1.1.1.10.2       tls  * PARAMETERS:  None
    249  1.1.1.1.10.2       tls  *
    250  1.1.1.1.10.2       tls  * RETURN:      None
    251  1.1.1.1.10.2       tls  *
    252  1.1.1.1.10.2       tls  * DESCRIPTION: Main entry point for the iASL Preprocessor. Input file must
    253  1.1.1.1.10.2       tls  *              be already open. Handles multiple input files via the
    254  1.1.1.1.10.2       tls  *              #include directive.
    255  1.1.1.1.10.2       tls  *
    256  1.1.1.1.10.2       tls  ******************************************************************************/
    257  1.1.1.1.10.2       tls 
    258  1.1.1.1.10.2       tls void
    259  1.1.1.1.10.2       tls PrDoPreprocess (
    260  1.1.1.1.10.2       tls     void)
    261  1.1.1.1.10.2       tls {
    262  1.1.1.1.10.2       tls     BOOLEAN                 MoreInputFiles;
    263  1.1.1.1.10.2       tls 
    264  1.1.1.1.10.2       tls 
    265  1.1.1.1.10.2       tls     DbgPrint (ASL_DEBUG_OUTPUT, "Starting preprocessing phase\n\n");
    266  1.1.1.1.10.2       tls 
    267  1.1.1.1.10.2       tls 
    268  1.1.1.1.10.2       tls     FlSeekFile (ASL_FILE_INPUT, 0);
    269  1.1.1.1.10.2       tls     PrDumpPredefinedNames ();
    270  1.1.1.1.10.2       tls 
    271  1.1.1.1.10.2       tls     /* Main preprocessor loop, handles include files */
    272  1.1.1.1.10.2       tls 
    273  1.1.1.1.10.2       tls     do
    274  1.1.1.1.10.2       tls     {
    275  1.1.1.1.10.2       tls         PrPreprocessInputFile ();
    276  1.1.1.1.10.2       tls         MoreInputFiles = PrPopInputFileStack ();
    277  1.1.1.1.10.2       tls 
    278  1.1.1.1.10.2       tls     } while (MoreInputFiles);
    279  1.1.1.1.10.2       tls 
    280  1.1.1.1.10.3  jdolecek     /* Point compiler input to the new preprocessor output file (.pre) */
    281  1.1.1.1.10.2       tls 
    282  1.1.1.1.10.2       tls     FlCloseFile (ASL_FILE_INPUT);
    283  1.1.1.1.10.2       tls     Gbl_Files[ASL_FILE_INPUT].Handle = Gbl_Files[ASL_FILE_PREPROCESSOR].Handle;
    284  1.1.1.1.10.2       tls     AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
    285  1.1.1.1.10.2       tls 
    286  1.1.1.1.10.2       tls     /* Reset globals to allow compiler to run */
    287  1.1.1.1.10.2       tls 
    288  1.1.1.1.10.2       tls     FlSeekFile (ASL_FILE_INPUT, 0);
    289  1.1.1.1.10.3  jdolecek     if (!Gbl_PreprocessOnly)
    290  1.1.1.1.10.3  jdolecek     {
    291  1.1.1.1.10.3  jdolecek         Gbl_CurrentLineNumber = 0;
    292  1.1.1.1.10.3  jdolecek     }
    293  1.1.1.1.10.2       tls 
    294  1.1.1.1.10.2       tls     DbgPrint (ASL_DEBUG_OUTPUT, "Preprocessing phase complete \n\n");
    295  1.1.1.1.10.2       tls }
    296  1.1.1.1.10.2       tls 
    297  1.1.1.1.10.2       tls 
    298  1.1.1.1.10.2       tls /*******************************************************************************
    299  1.1.1.1.10.2       tls  *
    300  1.1.1.1.10.2       tls  * FUNCTION:    PrPreprocessInputFile
    301  1.1.1.1.10.2       tls  *
    302  1.1.1.1.10.2       tls  * PARAMETERS:  None
    303  1.1.1.1.10.2       tls  *
    304  1.1.1.1.10.2       tls  * RETURN:      None
    305  1.1.1.1.10.2       tls  *
    306  1.1.1.1.10.2       tls  * DESCRIPTION: Preprocess one entire file, line-by-line.
    307  1.1.1.1.10.2       tls  *
    308  1.1.1.1.10.2       tls  * Input:  Raw user ASL from ASL_FILE_INPUT
    309  1.1.1.1.10.3  jdolecek  * Output: Preprocessed file written to ASL_FILE_PREPROCESSOR and
    310  1.1.1.1.10.3  jdolecek  *         (optionally) ASL_FILE_PREPROCESSOR_USER
    311  1.1.1.1.10.2       tls  *
    312  1.1.1.1.10.2       tls  ******************************************************************************/
    313  1.1.1.1.10.2       tls 
    314  1.1.1.1.10.2       tls static void
    315  1.1.1.1.10.2       tls PrPreprocessInputFile (
    316  1.1.1.1.10.2       tls     void)
    317  1.1.1.1.10.2       tls {
    318  1.1.1.1.10.3  jdolecek     UINT32                  Status;
    319  1.1.1.1.10.2       tls     char                    *Token;
    320  1.1.1.1.10.2       tls     char                    *ReplaceString;
    321  1.1.1.1.10.2       tls     PR_DEFINE_INFO          *DefineInfo;
    322  1.1.1.1.10.2       tls     ACPI_SIZE               TokenOffset;
    323  1.1.1.1.10.2       tls     char                    *Next;
    324  1.1.1.1.10.2       tls     int                     OffsetAdjust;
    325  1.1.1.1.10.2       tls 
    326  1.1.1.1.10.2       tls 
    327  1.1.1.1.10.3  jdolecek     PrGetNextLineInit ();
    328  1.1.1.1.10.3  jdolecek 
    329  1.1.1.1.10.3  jdolecek     /* Scan source line-by-line and process directives. Then write the .i file */
    330  1.1.1.1.10.2       tls 
    331  1.1.1.1.10.3  jdolecek     while ((Status = PrGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF)
    332  1.1.1.1.10.2       tls     {
    333  1.1.1.1.10.3  jdolecek         Gbl_CurrentLineNumber++;
    334  1.1.1.1.10.3  jdolecek         Gbl_LogicalLineNumber++;
    335  1.1.1.1.10.3  jdolecek 
    336  1.1.1.1.10.3  jdolecek         if (Status == ASL_IGNORE_LINE)
    337  1.1.1.1.10.3  jdolecek         {
    338  1.1.1.1.10.3  jdolecek             goto WriteEntireLine;
    339  1.1.1.1.10.3  jdolecek         }
    340  1.1.1.1.10.3  jdolecek 
    341  1.1.1.1.10.2       tls         /* Need a copy of the input line for strok() */
    342  1.1.1.1.10.2       tls 
    343  1.1.1.1.10.2       tls         strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer);
    344  1.1.1.1.10.2       tls         Token = PrGetNextToken (Gbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next);
    345  1.1.1.1.10.2       tls         OffsetAdjust = 0;
    346  1.1.1.1.10.2       tls 
    347  1.1.1.1.10.2       tls         /* All preprocessor directives must begin with '#' */
    348  1.1.1.1.10.2       tls 
    349  1.1.1.1.10.2       tls         if (Token && (*Token == '#'))
    350  1.1.1.1.10.2       tls         {
    351  1.1.1.1.10.2       tls             if (strlen (Token) == 1)
    352  1.1.1.1.10.2       tls             {
    353  1.1.1.1.10.2       tls                 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
    354  1.1.1.1.10.2       tls             }
    355  1.1.1.1.10.2       tls             else
    356  1.1.1.1.10.2       tls             {
    357  1.1.1.1.10.2       tls                 Token++;    /* Skip leading # */
    358  1.1.1.1.10.2       tls             }
    359  1.1.1.1.10.2       tls 
    360  1.1.1.1.10.2       tls             /* Execute the directive, do not write line to output file */
    361  1.1.1.1.10.2       tls 
    362  1.1.1.1.10.2       tls             PrDoDirective (Token, &Next);
    363  1.1.1.1.10.2       tls             continue;
    364  1.1.1.1.10.2       tls         }
    365  1.1.1.1.10.2       tls 
    366  1.1.1.1.10.2       tls         /*
    367  1.1.1.1.10.2       tls          * If we are currently within the part of an IF/ELSE block that is
    368  1.1.1.1.10.2       tls          * FALSE, ignore the line and do not write it to the output file.
    369  1.1.1.1.10.2       tls          * This continues until an #else or #endif is encountered.
    370  1.1.1.1.10.2       tls          */
    371  1.1.1.1.10.2       tls         if (Gbl_IgnoringThisCodeBlock)
    372  1.1.1.1.10.2       tls         {
    373  1.1.1.1.10.2       tls             continue;
    374  1.1.1.1.10.2       tls         }
    375  1.1.1.1.10.2       tls 
    376  1.1.1.1.10.2       tls         /* Match and replace all #defined names within this source line */
    377  1.1.1.1.10.2       tls 
    378  1.1.1.1.10.2       tls         while (Token)
    379  1.1.1.1.10.2       tls         {
    380  1.1.1.1.10.2       tls             DefineInfo = PrMatchDefine (Token);
    381  1.1.1.1.10.2       tls             if (DefineInfo)
    382  1.1.1.1.10.2       tls             {
    383  1.1.1.1.10.2       tls                 if (DefineInfo->Body)
    384  1.1.1.1.10.2       tls                 {
    385  1.1.1.1.10.2       tls                     /* This is a macro */
    386  1.1.1.1.10.2       tls 
    387  1.1.1.1.10.2       tls                     DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
    388  1.1.1.1.10.2       tls                         "Matched Macro: %s->%s\n",
    389  1.1.1.1.10.2       tls                         Gbl_CurrentLineNumber, DefineInfo->Identifier,
    390  1.1.1.1.10.2       tls                         DefineInfo->Replacement);
    391  1.1.1.1.10.2       tls 
    392  1.1.1.1.10.2       tls                     PrDoMacroInvocation (Gbl_MainTokenBuffer, Token,
    393  1.1.1.1.10.2       tls                         DefineInfo, &Next);
    394  1.1.1.1.10.2       tls                 }
    395  1.1.1.1.10.2       tls                 else
    396  1.1.1.1.10.2       tls                 {
    397  1.1.1.1.10.2       tls                     ReplaceString = DefineInfo->Replacement;
    398  1.1.1.1.10.2       tls 
    399  1.1.1.1.10.2       tls                     /* Replace the name in the original line buffer */
    400  1.1.1.1.10.2       tls 
    401  1.1.1.1.10.2       tls                     TokenOffset = Token - Gbl_MainTokenBuffer + OffsetAdjust;
    402  1.1.1.1.10.2       tls                     PrReplaceData (
    403  1.1.1.1.10.2       tls                         &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token),
    404  1.1.1.1.10.2       tls                         ReplaceString, strlen (ReplaceString));
    405  1.1.1.1.10.2       tls 
    406  1.1.1.1.10.2       tls                     /* Adjust for length difference between old and new name length */
    407  1.1.1.1.10.2       tls 
    408  1.1.1.1.10.2       tls                     OffsetAdjust += strlen (ReplaceString) - strlen (Token);
    409  1.1.1.1.10.2       tls 
    410  1.1.1.1.10.2       tls                     DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
    411  1.1.1.1.10.2       tls                         "Matched #define: %s->%s\n",
    412  1.1.1.1.10.2       tls                         Gbl_CurrentLineNumber, Token,
    413  1.1.1.1.10.2       tls                         *ReplaceString ? ReplaceString : "(NULL STRING)");
    414  1.1.1.1.10.2       tls                 }
    415  1.1.1.1.10.2       tls             }
    416  1.1.1.1.10.2       tls 
    417  1.1.1.1.10.2       tls             Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
    418  1.1.1.1.10.2       tls         }
    419  1.1.1.1.10.2       tls 
    420  1.1.1.1.10.2       tls         Gbl_PreprocessorLineNumber++;
    421  1.1.1.1.10.2       tls 
    422  1.1.1.1.10.3  jdolecek 
    423  1.1.1.1.10.3  jdolecek WriteEntireLine:
    424  1.1.1.1.10.2       tls         /*
    425  1.1.1.1.10.2       tls          * Now we can write the possibly modified source line to the
    426  1.1.1.1.10.3  jdolecek          * preprocessor file(s).
    427  1.1.1.1.10.2       tls          */
    428  1.1.1.1.10.2       tls         FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer,
    429  1.1.1.1.10.2       tls             strlen (Gbl_CurrentLineBuffer));
    430  1.1.1.1.10.2       tls     }
    431  1.1.1.1.10.2       tls }
    432  1.1.1.1.10.2       tls 
    433  1.1.1.1.10.2       tls 
    434  1.1.1.1.10.2       tls /*******************************************************************************
    435  1.1.1.1.10.2       tls  *
    436  1.1.1.1.10.2       tls  * FUNCTION:    PrDoDirective
    437  1.1.1.1.10.2       tls  *
    438  1.1.1.1.10.2       tls  * PARAMETERS:  Directive               - Pointer to directive name token
    439  1.1.1.1.10.2       tls  *              Next                    - "Next" buffer from GetNextToken
    440  1.1.1.1.10.2       tls  *
    441  1.1.1.1.10.2       tls  * RETURN:      None.
    442  1.1.1.1.10.2       tls  *
    443  1.1.1.1.10.2       tls  * DESCRIPTION: Main processing for all preprocessor directives
    444  1.1.1.1.10.2       tls  *
    445  1.1.1.1.10.2       tls  ******************************************************************************/
    446  1.1.1.1.10.2       tls 
    447  1.1.1.1.10.2       tls static void
    448  1.1.1.1.10.2       tls PrDoDirective (
    449  1.1.1.1.10.2       tls     char                    *DirectiveToken,
    450  1.1.1.1.10.2       tls     char                    **Next)
    451  1.1.1.1.10.2       tls {
    452  1.1.1.1.10.2       tls     char                    *Token = Gbl_MainTokenBuffer;
    453  1.1.1.1.10.3  jdolecek     char                    *Token2 = NULL;
    454  1.1.1.1.10.2       tls     char                    *End;
    455  1.1.1.1.10.2       tls     UINT64                  Value;
    456  1.1.1.1.10.2       tls     ACPI_SIZE               TokenOffset;
    457  1.1.1.1.10.2       tls     int                     Directive;
    458  1.1.1.1.10.2       tls     ACPI_STATUS             Status;
    459  1.1.1.1.10.2       tls 
    460  1.1.1.1.10.2       tls 
    461  1.1.1.1.10.2       tls     if (!DirectiveToken)
    462  1.1.1.1.10.2       tls     {
    463  1.1.1.1.10.2       tls         goto SyntaxError;
    464  1.1.1.1.10.2       tls     }
    465  1.1.1.1.10.2       tls 
    466  1.1.1.1.10.2       tls     Directive = PrMatchDirective (DirectiveToken);
    467  1.1.1.1.10.2       tls     if (Directive == ASL_DIRECTIVE_NOT_FOUND)
    468  1.1.1.1.10.2       tls     {
    469  1.1.1.1.10.2       tls         PrError (ASL_ERROR, ASL_MSG_UNKNOWN_DIRECTIVE,
    470  1.1.1.1.10.2       tls             THIS_TOKEN_OFFSET (DirectiveToken));
    471  1.1.1.1.10.2       tls 
    472  1.1.1.1.10.3  jdolecek         DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
    473  1.1.1.1.10.2       tls             "#%s: Unknown directive\n",
    474  1.1.1.1.10.2       tls             Gbl_CurrentLineNumber, DirectiveToken);
    475  1.1.1.1.10.2       tls         return;
    476  1.1.1.1.10.2       tls     }
    477  1.1.1.1.10.2       tls 
    478  1.1.1.1.10.2       tls     /*
    479  1.1.1.1.10.3  jdolecek      * Emit a line directive into the preprocessor file (.pre) after
    480  1.1.1.1.10.3  jdolecek      * every matched directive. This is passed through to the compiler
    481  1.1.1.1.10.3  jdolecek      * so that error/warning messages are kept in sync with the
    482  1.1.1.1.10.3  jdolecek      * original source file.
    483  1.1.1.1.10.3  jdolecek      */
    484  1.1.1.1.10.3  jdolecek     FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\" // #%s\n",
    485  1.1.1.1.10.3  jdolecek         Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename,
    486  1.1.1.1.10.3  jdolecek         Gbl_DirectiveInfo[Directive].Name);
    487  1.1.1.1.10.3  jdolecek 
    488  1.1.1.1.10.3  jdolecek     /*
    489  1.1.1.1.10.2       tls      * If we are currently ignoring this block and we encounter a #else or
    490  1.1.1.1.10.2       tls      * #elif, we must ignore their blocks also if the parent block is also
    491  1.1.1.1.10.2       tls      * being ignored.
    492  1.1.1.1.10.2       tls      */
    493  1.1.1.1.10.2       tls     if (Gbl_IgnoringThisCodeBlock)
    494  1.1.1.1.10.2       tls     {
    495  1.1.1.1.10.2       tls         switch (Directive)
    496  1.1.1.1.10.2       tls         {
    497  1.1.1.1.10.2       tls         case PR_DIRECTIVE_ELSE:
    498  1.1.1.1.10.2       tls         case PR_DIRECTIVE_ELIF:
    499  1.1.1.1.10.2       tls 
    500  1.1.1.1.10.3  jdolecek             if (Gbl_DirectiveStack &&
    501  1.1.1.1.10.3  jdolecek                 Gbl_DirectiveStack->IgnoringThisCodeBlock)
    502  1.1.1.1.10.2       tls             {
    503  1.1.1.1.10.2       tls                 PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name);
    504  1.1.1.1.10.2       tls                 return;
    505  1.1.1.1.10.2       tls             }
    506  1.1.1.1.10.2       tls             break;
    507  1.1.1.1.10.2       tls 
    508  1.1.1.1.10.2       tls         default:
    509  1.1.1.1.10.2       tls             break;
    510  1.1.1.1.10.2       tls         }
    511  1.1.1.1.10.2       tls     }
    512  1.1.1.1.10.2       tls 
    513  1.1.1.1.10.2       tls     /*
    514  1.1.1.1.10.2       tls      * Need to always check for #else, #elif, #endif regardless of
    515  1.1.1.1.10.2       tls      * whether we are ignoring the current code block, since these
    516  1.1.1.1.10.2       tls      * are conditional code block terminators.
    517  1.1.1.1.10.2       tls      */
    518  1.1.1.1.10.2       tls     switch (Directive)
    519  1.1.1.1.10.2       tls     {
    520  1.1.1.1.10.2       tls     case PR_DIRECTIVE_ELSE:
    521  1.1.1.1.10.2       tls 
    522  1.1.1.1.10.2       tls         Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock);
    523  1.1.1.1.10.2       tls         PrDbgPrint ("Executing", "else block");
    524  1.1.1.1.10.2       tls         return;
    525  1.1.1.1.10.2       tls 
    526  1.1.1.1.10.2       tls     case PR_DIRECTIVE_ELIF:
    527  1.1.1.1.10.2       tls 
    528  1.1.1.1.10.2       tls         Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock);
    529  1.1.1.1.10.2       tls         Directive = PR_DIRECTIVE_IF;
    530  1.1.1.1.10.2       tls 
    531  1.1.1.1.10.2       tls         if (Gbl_IgnoringThisCodeBlock == TRUE)
    532  1.1.1.1.10.2       tls         {
    533  1.1.1.1.10.2       tls             /* Not executing the ELSE part -- all done here */
    534  1.1.1.1.10.2       tls             PrDbgPrint ("Ignoring", "elif block");
    535  1.1.1.1.10.2       tls             return;
    536  1.1.1.1.10.2       tls         }
    537  1.1.1.1.10.2       tls 
    538  1.1.1.1.10.2       tls         /*
    539  1.1.1.1.10.2       tls          * After this, we will execute the IF part further below.
    540  1.1.1.1.10.2       tls          * First, however, pop off the original #if directive.
    541  1.1.1.1.10.2       tls          */
    542  1.1.1.1.10.2       tls         if (ACPI_FAILURE (PrPopDirective ()))
    543  1.1.1.1.10.2       tls         {
    544  1.1.1.1.10.2       tls             PrError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
    545  1.1.1.1.10.2       tls                 THIS_TOKEN_OFFSET (DirectiveToken));
    546  1.1.1.1.10.2       tls         }
    547  1.1.1.1.10.2       tls 
    548  1.1.1.1.10.2       tls         PrDbgPrint ("Executing", "elif block");
    549  1.1.1.1.10.2       tls         break;
    550  1.1.1.1.10.2       tls 
    551  1.1.1.1.10.2       tls     case PR_DIRECTIVE_ENDIF:
    552  1.1.1.1.10.2       tls 
    553  1.1.1.1.10.2       tls         PrDbgPrint ("Executing", "endif");
    554  1.1.1.1.10.2       tls 
    555  1.1.1.1.10.2       tls         /* Pop the owning #if/#ifdef/#ifndef */
    556  1.1.1.1.10.2       tls 
    557  1.1.1.1.10.2       tls         if (ACPI_FAILURE (PrPopDirective ()))
    558  1.1.1.1.10.2       tls         {
    559  1.1.1.1.10.2       tls             PrError (ASL_ERROR, ASL_MSG_ENDIF_MISMATCH,
    560  1.1.1.1.10.2       tls                 THIS_TOKEN_OFFSET (DirectiveToken));
    561  1.1.1.1.10.2       tls         }
    562  1.1.1.1.10.2       tls         return;
    563  1.1.1.1.10.2       tls 
    564  1.1.1.1.10.2       tls     default:
    565  1.1.1.1.10.2       tls         break;
    566  1.1.1.1.10.2       tls     }
    567  1.1.1.1.10.2       tls 
    568  1.1.1.1.10.2       tls     /* Most directives have at least one argument */
    569  1.1.1.1.10.2       tls 
    570  1.1.1.1.10.3  jdolecek     if (Gbl_DirectiveInfo[Directive].ArgCount >= 1)
    571  1.1.1.1.10.2       tls     {
    572  1.1.1.1.10.2       tls         Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
    573  1.1.1.1.10.2       tls         if (!Token)
    574  1.1.1.1.10.2       tls         {
    575  1.1.1.1.10.2       tls             goto SyntaxError;
    576  1.1.1.1.10.2       tls         }
    577  1.1.1.1.10.2       tls     }
    578  1.1.1.1.10.2       tls 
    579  1.1.1.1.10.3  jdolecek     if (Gbl_DirectiveInfo[Directive].ArgCount >= 2)
    580  1.1.1.1.10.3  jdolecek     {
    581  1.1.1.1.10.3  jdolecek         Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
    582  1.1.1.1.10.3  jdolecek         if (!Token2)
    583  1.1.1.1.10.3  jdolecek         {
    584  1.1.1.1.10.3  jdolecek             goto SyntaxError;
    585  1.1.1.1.10.3  jdolecek         }
    586  1.1.1.1.10.3  jdolecek     }
    587  1.1.1.1.10.3  jdolecek 
    588  1.1.1.1.10.2       tls     /*
    589  1.1.1.1.10.2       tls      * At this point, if we are ignoring the current code block,
    590  1.1.1.1.10.2       tls      * do not process any more directives (i.e., ignore them also.)
    591  1.1.1.1.10.2       tls      * For "if" style directives, open/push a new block anyway. We
    592  1.1.1.1.10.2       tls      * must do this to keep track of #endif directives
    593  1.1.1.1.10.2       tls      */
    594  1.1.1.1.10.2       tls     if (Gbl_IgnoringThisCodeBlock)
    595  1.1.1.1.10.2       tls     {
    596  1.1.1.1.10.2       tls         switch (Directive)
    597  1.1.1.1.10.2       tls         {
    598  1.1.1.1.10.2       tls         case PR_DIRECTIVE_IF:
    599  1.1.1.1.10.2       tls         case PR_DIRECTIVE_IFDEF:
    600  1.1.1.1.10.2       tls         case PR_DIRECTIVE_IFNDEF:
    601  1.1.1.1.10.2       tls 
    602  1.1.1.1.10.2       tls             PrPushDirective (Directive, Token);
    603  1.1.1.1.10.2       tls             PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name);
    604  1.1.1.1.10.2       tls             break;
    605  1.1.1.1.10.2       tls 
    606  1.1.1.1.10.2       tls         default:
    607  1.1.1.1.10.2       tls             break;
    608  1.1.1.1.10.2       tls         }
    609  1.1.1.1.10.2       tls 
    610  1.1.1.1.10.2       tls         return;
    611  1.1.1.1.10.2       tls     }
    612  1.1.1.1.10.2       tls 
    613  1.1.1.1.10.2       tls     /*
    614  1.1.1.1.10.2       tls      * Execute the directive
    615  1.1.1.1.10.2       tls      */
    616  1.1.1.1.10.2       tls     PrDbgPrint ("Begin execution", Gbl_DirectiveInfo[Directive].Name);
    617  1.1.1.1.10.2       tls 
    618  1.1.1.1.10.2       tls     switch (Directive)
    619  1.1.1.1.10.2       tls     {
    620  1.1.1.1.10.2       tls     case PR_DIRECTIVE_IF:
    621  1.1.1.1.10.2       tls 
    622  1.1.1.1.10.2       tls         TokenOffset = Token - Gbl_MainTokenBuffer;
    623  1.1.1.1.10.2       tls 
    624  1.1.1.1.10.2       tls         /* Need to expand #define macros in the expression string first */
    625  1.1.1.1.10.2       tls 
    626  1.1.1.1.10.2       tls         Status = PrResolveIntegerExpression (
    627  1.1.1.1.10.2       tls             &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
    628  1.1.1.1.10.2       tls         if (ACPI_FAILURE (Status))
    629  1.1.1.1.10.2       tls         {
    630  1.1.1.1.10.2       tls             return;
    631  1.1.1.1.10.2       tls         }
    632  1.1.1.1.10.2       tls 
    633  1.1.1.1.10.2       tls         PrPushDirective (Directive, Token);
    634  1.1.1.1.10.2       tls         if (!Value)
    635  1.1.1.1.10.2       tls         {
    636  1.1.1.1.10.2       tls             Gbl_IgnoringThisCodeBlock = TRUE;
    637  1.1.1.1.10.2       tls         }
    638  1.1.1.1.10.2       tls 
    639  1.1.1.1.10.3  jdolecek         DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
    640  1.1.1.1.10.2       tls             "Resolved #if: %8.8X%8.8X %s\n",
    641  1.1.1.1.10.2       tls             Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value),
    642  1.1.1.1.10.2       tls             Gbl_IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>");
    643  1.1.1.1.10.2       tls         break;
    644  1.1.1.1.10.2       tls 
    645  1.1.1.1.10.2       tls     case PR_DIRECTIVE_IFDEF:
    646  1.1.1.1.10.2       tls 
    647  1.1.1.1.10.2       tls         PrPushDirective (Directive, Token);
    648  1.1.1.1.10.2       tls         if (!PrMatchDefine (Token))
    649  1.1.1.1.10.2       tls         {
    650  1.1.1.1.10.2       tls             Gbl_IgnoringThisCodeBlock = TRUE;
    651  1.1.1.1.10.2       tls         }
    652  1.1.1.1.10.2       tls 
    653  1.1.1.1.10.2       tls         PrDbgPrint ("Evaluated", "ifdef");
    654  1.1.1.1.10.2       tls         break;
    655  1.1.1.1.10.2       tls 
    656  1.1.1.1.10.2       tls     case PR_DIRECTIVE_IFNDEF:
    657  1.1.1.1.10.2       tls 
    658  1.1.1.1.10.2       tls         PrPushDirective (Directive, Token);
    659  1.1.1.1.10.2       tls         if (PrMatchDefine (Token))
    660  1.1.1.1.10.2       tls         {
    661  1.1.1.1.10.2       tls             Gbl_IgnoringThisCodeBlock = TRUE;
    662  1.1.1.1.10.2       tls         }
    663  1.1.1.1.10.2       tls 
    664  1.1.1.1.10.2       tls         PrDbgPrint ("Evaluated", "ifndef");
    665  1.1.1.1.10.2       tls         break;
    666  1.1.1.1.10.2       tls 
    667  1.1.1.1.10.2       tls     case PR_DIRECTIVE_DEFINE:
    668  1.1.1.1.10.2       tls         /*
    669  1.1.1.1.10.2       tls          * By definition, if first char after the name is a paren,
    670  1.1.1.1.10.2       tls          * this is a function macro.
    671  1.1.1.1.10.2       tls          */
    672  1.1.1.1.10.2       tls         TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token);
    673  1.1.1.1.10.2       tls         if (*(&Gbl_CurrentLineBuffer[TokenOffset]) == '(')
    674  1.1.1.1.10.2       tls         {
    675  1.1.1.1.10.2       tls #ifndef MACROS_SUPPORTED
    676  1.1.1.1.10.3  jdolecek             AcpiOsPrintf (
    677  1.1.1.1.10.3  jdolecek                 "%s ERROR - line %u: #define macros are not supported yet\n",
    678  1.1.1.1.10.3  jdolecek                 Gbl_CurrentLineBuffer, Gbl_LogicalLineNumber);
    679  1.1.1.1.10.2       tls             exit(1);
    680  1.1.1.1.10.2       tls #else
    681  1.1.1.1.10.2       tls             PrAddMacro (Token, Next);
    682  1.1.1.1.10.2       tls #endif
    683  1.1.1.1.10.2       tls         }
    684  1.1.1.1.10.2       tls         else
    685  1.1.1.1.10.2       tls         {
    686  1.1.1.1.10.2       tls             /* Use the remainder of the line for the #define */
    687  1.1.1.1.10.2       tls 
    688  1.1.1.1.10.2       tls             Token2 = *Next;
    689  1.1.1.1.10.2       tls             if (Token2)
    690  1.1.1.1.10.2       tls             {
    691  1.1.1.1.10.2       tls                 while ((*Token2 == ' ') || (*Token2 == '\t'))
    692  1.1.1.1.10.2       tls                 {
    693  1.1.1.1.10.2       tls                     Token2++;
    694  1.1.1.1.10.2       tls                 }
    695  1.1.1.1.10.3  jdolecek 
    696  1.1.1.1.10.2       tls                 End = Token2;
    697  1.1.1.1.10.2       tls                 while (*End != '\n')
    698  1.1.1.1.10.2       tls                 {
    699  1.1.1.1.10.2       tls                     End++;
    700  1.1.1.1.10.2       tls                 }
    701  1.1.1.1.10.3  jdolecek 
    702  1.1.1.1.10.2       tls                 *End = 0;
    703  1.1.1.1.10.2       tls             }
    704  1.1.1.1.10.2       tls             else
    705  1.1.1.1.10.2       tls             {
    706  1.1.1.1.10.2       tls                 Token2 = "";
    707  1.1.1.1.10.2       tls             }
    708  1.1.1.1.10.2       tls #if 0
    709  1.1.1.1.10.2       tls             Token2 = PrGetNextToken (NULL, "\n", /*PR_TOKEN_SEPARATORS,*/ Next);
    710  1.1.1.1.10.2       tls             if (!Token2)
    711  1.1.1.1.10.2       tls             {
    712  1.1.1.1.10.2       tls                 Token2 = "";
    713  1.1.1.1.10.2       tls             }
    714  1.1.1.1.10.2       tls #endif
    715  1.1.1.1.10.3  jdolecek             DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
    716  1.1.1.1.10.2       tls                 "New #define: %s->%s\n",
    717  1.1.1.1.10.3  jdolecek                 Gbl_LogicalLineNumber, Token, Token2);
    718  1.1.1.1.10.2       tls 
    719  1.1.1.1.10.2       tls             PrAddDefine (Token, Token2, FALSE);
    720  1.1.1.1.10.2       tls         }
    721  1.1.1.1.10.2       tls         break;
    722  1.1.1.1.10.2       tls 
    723  1.1.1.1.10.2       tls     case PR_DIRECTIVE_ERROR:
    724  1.1.1.1.10.2       tls 
    725  1.1.1.1.10.2       tls         /* Note: No macro expansion */
    726  1.1.1.1.10.2       tls 
    727  1.1.1.1.10.2       tls         PrError (ASL_ERROR, ASL_MSG_ERROR_DIRECTIVE,
    728  1.1.1.1.10.2       tls             THIS_TOKEN_OFFSET (Token));
    729  1.1.1.1.10.2       tls 
    730  1.1.1.1.10.2       tls         Gbl_SourceLine = 0;
    731  1.1.1.1.10.2       tls         Gbl_NextError = Gbl_ErrorLog;
    732  1.1.1.1.10.2       tls         CmCleanupAndExit ();
    733  1.1.1.1.10.2       tls         exit(1);
    734  1.1.1.1.10.2       tls 
    735  1.1.1.1.10.2       tls     case PR_DIRECTIVE_INCLUDE:
    736  1.1.1.1.10.2       tls 
    737  1.1.1.1.10.2       tls         Token = PrGetNextToken (NULL, " \"<>", Next);
    738  1.1.1.1.10.2       tls         if (!Token)
    739  1.1.1.1.10.2       tls         {
    740  1.1.1.1.10.2       tls             goto SyntaxError;
    741  1.1.1.1.10.2       tls         }
    742  1.1.1.1.10.2       tls 
    743  1.1.1.1.10.3  jdolecek         DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
    744  1.1.1.1.10.2       tls             "Start #include file \"%s\"\n", Gbl_CurrentLineNumber,
    745  1.1.1.1.10.2       tls             Token, Gbl_CurrentLineNumber);
    746  1.1.1.1.10.2       tls 
    747  1.1.1.1.10.3  jdolecek         PrDoIncludeFile (Token);
    748  1.1.1.1.10.3  jdolecek         break;
    749  1.1.1.1.10.3  jdolecek 
    750  1.1.1.1.10.3  jdolecek     case PR_DIRECTIVE_INCLUDEBUFFER:
    751  1.1.1.1.10.3  jdolecek 
    752  1.1.1.1.10.3  jdolecek         Token = PrGetNextToken (NULL, " \"<>", Next);
    753  1.1.1.1.10.3  jdolecek         if (!Token)
    754  1.1.1.1.10.3  jdolecek         {
    755  1.1.1.1.10.3  jdolecek             goto SyntaxError;
    756  1.1.1.1.10.3  jdolecek         }
    757  1.1.1.1.10.3  jdolecek 
    758  1.1.1.1.10.3  jdolecek         Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
    759  1.1.1.1.10.3  jdolecek         if (!Token2)
    760  1.1.1.1.10.3  jdolecek         {
    761  1.1.1.1.10.3  jdolecek             goto SyntaxError;
    762  1.1.1.1.10.3  jdolecek         }
    763  1.1.1.1.10.3  jdolecek 
    764  1.1.1.1.10.3  jdolecek         DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
    765  1.1.1.1.10.3  jdolecek             "Start #includebuffer input from file \"%s\", buffer name %s\n",
    766  1.1.1.1.10.3  jdolecek             Gbl_CurrentLineNumber, Token, Token2);
    767  1.1.1.1.10.3  jdolecek 
    768  1.1.1.1.10.3  jdolecek         PrDoIncludeBuffer (Token, Token2);
    769  1.1.1.1.10.2       tls         break;
    770  1.1.1.1.10.2       tls 
    771  1.1.1.1.10.2       tls     case PR_DIRECTIVE_LINE:
    772  1.1.1.1.10.2       tls 
    773  1.1.1.1.10.2       tls         TokenOffset = Token - Gbl_MainTokenBuffer;
    774  1.1.1.1.10.2       tls 
    775  1.1.1.1.10.2       tls         Status = PrResolveIntegerExpression (
    776  1.1.1.1.10.2       tls             &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
    777  1.1.1.1.10.2       tls         if (ACPI_FAILURE (Status))
    778  1.1.1.1.10.2       tls         {
    779  1.1.1.1.10.2       tls             return;
    780  1.1.1.1.10.2       tls         }
    781  1.1.1.1.10.2       tls 
    782  1.1.1.1.10.3  jdolecek         DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
    783  1.1.1.1.10.2       tls             "User #line invocation %s\n", Gbl_CurrentLineNumber,
    784  1.1.1.1.10.2       tls             Token);
    785  1.1.1.1.10.2       tls 
    786  1.1.1.1.10.2       tls         Gbl_CurrentLineNumber = (UINT32) Value;
    787  1.1.1.1.10.2       tls 
    788  1.1.1.1.10.2       tls         /* Emit #line into the preprocessor file */
    789  1.1.1.1.10.2       tls 
    790  1.1.1.1.10.2       tls         FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n",
    791  1.1.1.1.10.2       tls             Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename);
    792  1.1.1.1.10.2       tls         break;
    793  1.1.1.1.10.2       tls 
    794  1.1.1.1.10.2       tls     case PR_DIRECTIVE_PRAGMA:
    795  1.1.1.1.10.2       tls 
    796  1.1.1.1.10.2       tls         if (!strcmp (Token, "disable"))
    797  1.1.1.1.10.2       tls         {
    798  1.1.1.1.10.2       tls             Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
    799  1.1.1.1.10.2       tls             if (!Token)
    800  1.1.1.1.10.2       tls             {
    801  1.1.1.1.10.2       tls                 goto SyntaxError;
    802  1.1.1.1.10.2       tls             }
    803  1.1.1.1.10.2       tls 
    804  1.1.1.1.10.2       tls             TokenOffset = Token - Gbl_MainTokenBuffer;
    805  1.1.1.1.10.2       tls             AslDisableException (&Gbl_CurrentLineBuffer[TokenOffset]);
    806  1.1.1.1.10.2       tls         }
    807  1.1.1.1.10.2       tls         else if (!strcmp (Token, "message"))
    808  1.1.1.1.10.2       tls         {
    809  1.1.1.1.10.2       tls             Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
    810  1.1.1.1.10.2       tls             if (!Token)
    811  1.1.1.1.10.2       tls             {
    812  1.1.1.1.10.2       tls                 goto SyntaxError;
    813  1.1.1.1.10.2       tls             }
    814  1.1.1.1.10.2       tls 
    815  1.1.1.1.10.2       tls             TokenOffset = Token - Gbl_MainTokenBuffer;
    816  1.1.1.1.10.2       tls             AcpiOsPrintf ("%s\n", &Gbl_CurrentLineBuffer[TokenOffset]);
    817  1.1.1.1.10.2       tls         }
    818  1.1.1.1.10.2       tls         else
    819  1.1.1.1.10.2       tls         {
    820  1.1.1.1.10.2       tls             PrError (ASL_ERROR, ASL_MSG_UNKNOWN_PRAGMA,
    821  1.1.1.1.10.2       tls                 THIS_TOKEN_OFFSET (Token));
    822  1.1.1.1.10.2       tls             return;
    823  1.1.1.1.10.2       tls         }
    824  1.1.1.1.10.2       tls 
    825  1.1.1.1.10.2       tls         break;
    826  1.1.1.1.10.2       tls 
    827  1.1.1.1.10.2       tls     case PR_DIRECTIVE_UNDEF:
    828  1.1.1.1.10.2       tls 
    829  1.1.1.1.10.3  jdolecek         DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
    830  1.1.1.1.10.2       tls             "#undef: %s\n", Gbl_CurrentLineNumber, Token);
    831  1.1.1.1.10.2       tls 
    832  1.1.1.1.10.2       tls         PrRemoveDefine (Token);
    833  1.1.1.1.10.2       tls         break;
    834  1.1.1.1.10.2       tls 
    835  1.1.1.1.10.2       tls     case PR_DIRECTIVE_WARNING:
    836  1.1.1.1.10.2       tls 
    837  1.1.1.1.10.2       tls         PrError (ASL_WARNING, ASL_MSG_WARNING_DIRECTIVE,
    838  1.1.1.1.10.2       tls             THIS_TOKEN_OFFSET (Token));
    839  1.1.1.1.10.3  jdolecek 
    840  1.1.1.1.10.3  jdolecek         Gbl_SourceLine = 0;
    841  1.1.1.1.10.3  jdolecek         Gbl_NextError = Gbl_ErrorLog;
    842  1.1.1.1.10.2       tls         break;
    843  1.1.1.1.10.2       tls 
    844  1.1.1.1.10.2       tls     default:
    845  1.1.1.1.10.2       tls 
    846  1.1.1.1.10.2       tls         /* Should never get here */
    847  1.1.1.1.10.3  jdolecek         DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
    848  1.1.1.1.10.2       tls             "Unrecognized directive: %u\n",
    849  1.1.1.1.10.2       tls             Gbl_CurrentLineNumber, Directive);
    850  1.1.1.1.10.2       tls         break;
    851  1.1.1.1.10.2       tls     }
    852  1.1.1.1.10.2       tls 
    853  1.1.1.1.10.2       tls     return;
    854  1.1.1.1.10.2       tls 
    855  1.1.1.1.10.2       tls SyntaxError:
    856  1.1.1.1.10.2       tls 
    857  1.1.1.1.10.2       tls     PrError (ASL_ERROR, ASL_MSG_DIRECTIVE_SYNTAX,
    858  1.1.1.1.10.2       tls         THIS_TOKEN_OFFSET (DirectiveToken));
    859  1.1.1.1.10.2       tls     return;
    860  1.1.1.1.10.2       tls }
    861  1.1.1.1.10.2       tls 
    862  1.1.1.1.10.2       tls 
    863  1.1.1.1.10.2       tls /*******************************************************************************
    864  1.1.1.1.10.2       tls  *
    865  1.1.1.1.10.3  jdolecek  * FUNCTION:    PrGetNextLine, PrGetNextLineInit
    866  1.1.1.1.10.3  jdolecek  *
    867  1.1.1.1.10.3  jdolecek  * PARAMETERS:  Handle              - Open file handle for the source file
    868  1.1.1.1.10.3  jdolecek  *
    869  1.1.1.1.10.3  jdolecek  * RETURN:      Status of the GetLine operation:
    870  1.1.1.1.10.3  jdolecek  *              AE_OK               - Normal line, OK status
    871  1.1.1.1.10.3  jdolecek  *              ASL_IGNORE_LINE     - Line is blank or part of a multi-line
    872  1.1.1.1.10.3  jdolecek  *                                      comment
    873  1.1.1.1.10.3  jdolecek  *              ASL_EOF             - End-of-file reached
    874  1.1.1.1.10.3  jdolecek  *
    875  1.1.1.1.10.3  jdolecek  * DESCRIPTION: Get the next text line from the input file. Does not strip
    876  1.1.1.1.10.3  jdolecek  *              comments.
    877  1.1.1.1.10.3  jdolecek  *
    878  1.1.1.1.10.3  jdolecek  ******************************************************************************/
    879  1.1.1.1.10.3  jdolecek 
    880  1.1.1.1.10.3  jdolecek #define PR_NORMAL_TEXT          0
    881  1.1.1.1.10.3  jdolecek #define PR_MULTI_LINE_COMMENT   1
    882  1.1.1.1.10.3  jdolecek #define PR_SINGLE_LINE_COMMENT  2
    883  1.1.1.1.10.3  jdolecek #define PR_QUOTED_STRING        3
    884  1.1.1.1.10.3  jdolecek 
    885  1.1.1.1.10.3  jdolecek static UINT8                    AcpiGbl_LineScanState = PR_NORMAL_TEXT;
    886  1.1.1.1.10.3  jdolecek 
    887  1.1.1.1.10.3  jdolecek static void
    888  1.1.1.1.10.3  jdolecek PrGetNextLineInit (
    889  1.1.1.1.10.3  jdolecek     void)
    890  1.1.1.1.10.3  jdolecek {
    891  1.1.1.1.10.3  jdolecek     AcpiGbl_LineScanState = 0;
    892  1.1.1.1.10.3  jdolecek }
    893  1.1.1.1.10.3  jdolecek 
    894  1.1.1.1.10.3  jdolecek static UINT32
    895  1.1.1.1.10.3  jdolecek PrGetNextLine (
    896  1.1.1.1.10.3  jdolecek     FILE                    *Handle)
    897  1.1.1.1.10.3  jdolecek {
    898  1.1.1.1.10.3  jdolecek     UINT32                  i;
    899  1.1.1.1.10.3  jdolecek     int                     c = 0;
    900  1.1.1.1.10.3  jdolecek     int                     PreviousChar;
    901  1.1.1.1.10.3  jdolecek 
    902  1.1.1.1.10.3  jdolecek 
    903  1.1.1.1.10.3  jdolecek     /* Always clear the global line buffer */
    904  1.1.1.1.10.3  jdolecek 
    905  1.1.1.1.10.3  jdolecek     memset (Gbl_CurrentLineBuffer, 0, Gbl_LineBufferSize);
    906  1.1.1.1.10.3  jdolecek     for (i = 0; ;)
    907  1.1.1.1.10.3  jdolecek     {
    908  1.1.1.1.10.3  jdolecek         /*
    909  1.1.1.1.10.3  jdolecek          * If line is too long, expand the line buffers. Also increases
    910  1.1.1.1.10.3  jdolecek          * Gbl_LineBufferSize.
    911  1.1.1.1.10.3  jdolecek          */
    912  1.1.1.1.10.3  jdolecek         if (i >= Gbl_LineBufferSize)
    913  1.1.1.1.10.3  jdolecek         {
    914  1.1.1.1.10.3  jdolecek             UtExpandLineBuffers ();
    915  1.1.1.1.10.3  jdolecek         }
    916  1.1.1.1.10.3  jdolecek 
    917  1.1.1.1.10.3  jdolecek         PreviousChar = c;
    918  1.1.1.1.10.3  jdolecek         c = getc (Handle);
    919  1.1.1.1.10.3  jdolecek         if (c == EOF)
    920  1.1.1.1.10.3  jdolecek         {
    921  1.1.1.1.10.3  jdolecek             /*
    922  1.1.1.1.10.3  jdolecek              * On EOF: If there is anything in the line buffer, terminate
    923  1.1.1.1.10.3  jdolecek              * it with a newline, and catch the EOF on the next call
    924  1.1.1.1.10.3  jdolecek              * to this function.
    925  1.1.1.1.10.3  jdolecek              */
    926  1.1.1.1.10.3  jdolecek             if (i > 0)
    927  1.1.1.1.10.3  jdolecek             {
    928  1.1.1.1.10.3  jdolecek                 Gbl_CurrentLineBuffer[i] = '\n';
    929  1.1.1.1.10.3  jdolecek                 return (AE_OK);
    930  1.1.1.1.10.3  jdolecek             }
    931  1.1.1.1.10.3  jdolecek 
    932  1.1.1.1.10.3  jdolecek             return (ASL_EOF);
    933  1.1.1.1.10.3  jdolecek         }
    934  1.1.1.1.10.3  jdolecek 
    935  1.1.1.1.10.3  jdolecek         /* Update state machine as necessary */
    936  1.1.1.1.10.3  jdolecek 
    937  1.1.1.1.10.3  jdolecek         switch (AcpiGbl_LineScanState)
    938  1.1.1.1.10.3  jdolecek         {
    939  1.1.1.1.10.3  jdolecek         case PR_NORMAL_TEXT:
    940  1.1.1.1.10.3  jdolecek 
    941  1.1.1.1.10.3  jdolecek             /* Check for multi-line comment start */
    942  1.1.1.1.10.3  jdolecek 
    943  1.1.1.1.10.3  jdolecek             if ((PreviousChar == '/') && (c == '*'))
    944  1.1.1.1.10.3  jdolecek             {
    945  1.1.1.1.10.3  jdolecek                 AcpiGbl_LineScanState = PR_MULTI_LINE_COMMENT;
    946  1.1.1.1.10.3  jdolecek             }
    947  1.1.1.1.10.3  jdolecek 
    948  1.1.1.1.10.3  jdolecek             /* Check for single-line comment start */
    949  1.1.1.1.10.3  jdolecek 
    950  1.1.1.1.10.3  jdolecek             else if ((PreviousChar == '/') && (c == '/'))
    951  1.1.1.1.10.3  jdolecek             {
    952  1.1.1.1.10.3  jdolecek                 AcpiGbl_LineScanState = PR_SINGLE_LINE_COMMENT;
    953  1.1.1.1.10.3  jdolecek             }
    954  1.1.1.1.10.3  jdolecek 
    955  1.1.1.1.10.3  jdolecek             /* Check for quoted string start */
    956  1.1.1.1.10.3  jdolecek 
    957  1.1.1.1.10.3  jdolecek             else if (PreviousChar == '"')
    958  1.1.1.1.10.3  jdolecek             {
    959  1.1.1.1.10.3  jdolecek                 AcpiGbl_LineScanState = PR_QUOTED_STRING;
    960  1.1.1.1.10.3  jdolecek             }
    961  1.1.1.1.10.3  jdolecek             break;
    962  1.1.1.1.10.3  jdolecek 
    963  1.1.1.1.10.3  jdolecek         case PR_QUOTED_STRING:
    964  1.1.1.1.10.3  jdolecek 
    965  1.1.1.1.10.3  jdolecek             if (PreviousChar == '"')
    966  1.1.1.1.10.3  jdolecek             {
    967  1.1.1.1.10.3  jdolecek                 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
    968  1.1.1.1.10.3  jdolecek             }
    969  1.1.1.1.10.3  jdolecek             break;
    970  1.1.1.1.10.3  jdolecek 
    971  1.1.1.1.10.3  jdolecek         case PR_MULTI_LINE_COMMENT:
    972  1.1.1.1.10.3  jdolecek 
    973  1.1.1.1.10.3  jdolecek             /* Check for multi-line comment end */
    974  1.1.1.1.10.3  jdolecek 
    975  1.1.1.1.10.3  jdolecek             if ((PreviousChar == '*') && (c == '/'))
    976  1.1.1.1.10.3  jdolecek             {
    977  1.1.1.1.10.3  jdolecek                 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
    978  1.1.1.1.10.3  jdolecek             }
    979  1.1.1.1.10.3  jdolecek             break;
    980  1.1.1.1.10.3  jdolecek 
    981  1.1.1.1.10.3  jdolecek         case PR_SINGLE_LINE_COMMENT: /* Just ignore text until EOL */
    982  1.1.1.1.10.3  jdolecek         default:
    983  1.1.1.1.10.3  jdolecek             break;
    984  1.1.1.1.10.3  jdolecek         }
    985  1.1.1.1.10.3  jdolecek 
    986  1.1.1.1.10.3  jdolecek         /* Always copy the character into line buffer */
    987  1.1.1.1.10.3  jdolecek 
    988  1.1.1.1.10.3  jdolecek         Gbl_CurrentLineBuffer[i] = (char) c;
    989  1.1.1.1.10.3  jdolecek         i++;
    990  1.1.1.1.10.3  jdolecek 
    991  1.1.1.1.10.3  jdolecek         /* Always exit on end-of-line */
    992  1.1.1.1.10.3  jdolecek 
    993  1.1.1.1.10.3  jdolecek         if (c == '\n')
    994  1.1.1.1.10.3  jdolecek         {
    995  1.1.1.1.10.3  jdolecek             /* Handle multi-line comments */
    996  1.1.1.1.10.3  jdolecek 
    997  1.1.1.1.10.3  jdolecek             if (AcpiGbl_LineScanState == PR_MULTI_LINE_COMMENT)
    998  1.1.1.1.10.3  jdolecek             {
    999  1.1.1.1.10.3  jdolecek                 return (ASL_IGNORE_LINE);
   1000  1.1.1.1.10.3  jdolecek             }
   1001  1.1.1.1.10.3  jdolecek 
   1002  1.1.1.1.10.3  jdolecek             /* End of single-line comment */
   1003  1.1.1.1.10.3  jdolecek 
   1004  1.1.1.1.10.3  jdolecek             if (AcpiGbl_LineScanState == PR_SINGLE_LINE_COMMENT)
   1005  1.1.1.1.10.3  jdolecek             {
   1006  1.1.1.1.10.3  jdolecek                 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
   1007  1.1.1.1.10.3  jdolecek                 return (AE_OK);
   1008  1.1.1.1.10.3  jdolecek             }
   1009  1.1.1.1.10.3  jdolecek 
   1010  1.1.1.1.10.3  jdolecek             /* Blank line */
   1011  1.1.1.1.10.3  jdolecek 
   1012  1.1.1.1.10.3  jdolecek             if (i == 1)
   1013  1.1.1.1.10.3  jdolecek             {
   1014  1.1.1.1.10.3  jdolecek                 return (ASL_IGNORE_LINE);
   1015  1.1.1.1.10.3  jdolecek             }
   1016  1.1.1.1.10.3  jdolecek 
   1017  1.1.1.1.10.3  jdolecek             return (AE_OK);
   1018  1.1.1.1.10.3  jdolecek         }
   1019  1.1.1.1.10.3  jdolecek     }
   1020  1.1.1.1.10.3  jdolecek }
   1021  1.1.1.1.10.3  jdolecek 
   1022  1.1.1.1.10.3  jdolecek 
   1023  1.1.1.1.10.3  jdolecek /*******************************************************************************
   1024  1.1.1.1.10.3  jdolecek  *
   1025  1.1.1.1.10.2       tls  * FUNCTION:    PrMatchDirective
   1026  1.1.1.1.10.2       tls  *
   1027  1.1.1.1.10.2       tls  * PARAMETERS:  Directive           - Pointer to directive name token
   1028  1.1.1.1.10.2       tls  *
   1029  1.1.1.1.10.2       tls  * RETURN:      Index into command array, -1 if not found
   1030  1.1.1.1.10.2       tls  *
   1031  1.1.1.1.10.2       tls  * DESCRIPTION: Lookup the incoming directive in the known directives table.
   1032  1.1.1.1.10.2       tls  *
   1033  1.1.1.1.10.2       tls  ******************************************************************************/
   1034  1.1.1.1.10.2       tls 
   1035  1.1.1.1.10.2       tls static int
   1036  1.1.1.1.10.2       tls PrMatchDirective (
   1037  1.1.1.1.10.2       tls     char                    *Directive)
   1038  1.1.1.1.10.2       tls {
   1039  1.1.1.1.10.2       tls     int                     i;
   1040  1.1.1.1.10.2       tls 
   1041  1.1.1.1.10.2       tls 
   1042  1.1.1.1.10.2       tls     if (!Directive || Directive[0] == 0)
   1043  1.1.1.1.10.2       tls     {
   1044  1.1.1.1.10.2       tls         return (ASL_DIRECTIVE_NOT_FOUND);
   1045  1.1.1.1.10.2       tls     }
   1046  1.1.1.1.10.2       tls 
   1047  1.1.1.1.10.2       tls     for (i = 0; Gbl_DirectiveInfo[i].Name; i++)
   1048  1.1.1.1.10.2       tls     {
   1049  1.1.1.1.10.2       tls         if (!strcmp (Gbl_DirectiveInfo[i].Name, Directive))
   1050  1.1.1.1.10.2       tls         {
   1051  1.1.1.1.10.2       tls             return (i);
   1052  1.1.1.1.10.2       tls         }
   1053  1.1.1.1.10.2       tls     }
   1054  1.1.1.1.10.2       tls 
   1055  1.1.1.1.10.2       tls     return (ASL_DIRECTIVE_NOT_FOUND);    /* Command not recognized */
   1056  1.1.1.1.10.2       tls }
   1057  1.1.1.1.10.2       tls 
   1058  1.1.1.1.10.2       tls 
   1059  1.1.1.1.10.2       tls /*******************************************************************************
   1060  1.1.1.1.10.2       tls  *
   1061  1.1.1.1.10.2       tls  * FUNCTION:    PrPushDirective
   1062  1.1.1.1.10.2       tls  *
   1063  1.1.1.1.10.2       tls  * PARAMETERS:  Directive           - Encoded directive ID
   1064  1.1.1.1.10.2       tls  *              Argument            - String containing argument to the
   1065  1.1.1.1.10.2       tls  *                                    directive
   1066  1.1.1.1.10.2       tls  *
   1067  1.1.1.1.10.2       tls  * RETURN:      None
   1068  1.1.1.1.10.2       tls  *
   1069  1.1.1.1.10.2       tls  * DESCRIPTION: Push an item onto the directive stack. Used for processing
   1070  1.1.1.1.10.2       tls  *              nested #if/#else type conditional compilation directives.
   1071  1.1.1.1.10.2       tls  *              Specifically: Used on detection of #if/#ifdef/#ifndef to open
   1072  1.1.1.1.10.2       tls  *              a block.
   1073  1.1.1.1.10.2       tls  *
   1074  1.1.1.1.10.2       tls  ******************************************************************************/
   1075  1.1.1.1.10.2       tls 
   1076  1.1.1.1.10.2       tls static void
   1077  1.1.1.1.10.2       tls PrPushDirective (
   1078  1.1.1.1.10.2       tls     int                     Directive,
   1079  1.1.1.1.10.2       tls     char                    *Argument)
   1080  1.1.1.1.10.2       tls {
   1081  1.1.1.1.10.2       tls     DIRECTIVE_INFO          *Info;
   1082  1.1.1.1.10.2       tls 
   1083  1.1.1.1.10.2       tls 
   1084  1.1.1.1.10.2       tls     /* Allocate and populate a stack info item */
   1085  1.1.1.1.10.2       tls 
   1086  1.1.1.1.10.2       tls     Info = ACPI_ALLOCATE (sizeof (DIRECTIVE_INFO));
   1087  1.1.1.1.10.2       tls 
   1088  1.1.1.1.10.2       tls     Info->Next = Gbl_DirectiveStack;
   1089  1.1.1.1.10.2       tls     Info->Directive = Directive;
   1090  1.1.1.1.10.2       tls     Info->IgnoringThisCodeBlock = Gbl_IgnoringThisCodeBlock;
   1091  1.1.1.1.10.2       tls     strncpy (Info->Argument, Argument, MAX_ARGUMENT_LENGTH);
   1092  1.1.1.1.10.2       tls 
   1093  1.1.1.1.10.2       tls     DbgPrint (ASL_DEBUG_OUTPUT,
   1094  1.1.1.1.10.2       tls         "Pr(%.4u) - [%u %s] %*s Pushed [#%s %s]: IgnoreFlag = %s\n",
   1095  1.1.1.1.10.2       tls         Gbl_CurrentLineNumber, Gbl_IfDepth,
   1096  1.1.1.1.10.2       tls         Gbl_IgnoringThisCodeBlock ? "I" : "E",
   1097  1.1.1.1.10.2       tls         Gbl_IfDepth * 4, " ",
   1098  1.1.1.1.10.2       tls         Gbl_DirectiveInfo[Directive].Name,
   1099  1.1.1.1.10.2       tls         Argument, Gbl_IgnoringThisCodeBlock ? "TRUE" : "FALSE");
   1100  1.1.1.1.10.2       tls 
   1101  1.1.1.1.10.2       tls     /* Push new item */
   1102  1.1.1.1.10.2       tls 
   1103  1.1.1.1.10.2       tls     Gbl_DirectiveStack = Info;
   1104  1.1.1.1.10.2       tls     Gbl_IfDepth++;
   1105  1.1.1.1.10.2       tls }
   1106  1.1.1.1.10.2       tls 
   1107  1.1.1.1.10.2       tls 
   1108  1.1.1.1.10.2       tls /*******************************************************************************
   1109  1.1.1.1.10.2       tls  *
   1110  1.1.1.1.10.2       tls  * FUNCTION:    PrPopDirective
   1111  1.1.1.1.10.2       tls  *
   1112  1.1.1.1.10.2       tls  * PARAMETERS:  None
   1113  1.1.1.1.10.2       tls  *
   1114  1.1.1.1.10.2       tls  * RETURN:      Status. Error if the stack is empty.
   1115  1.1.1.1.10.2       tls  *
   1116  1.1.1.1.10.2       tls  * DESCRIPTION: Pop an item off the directive stack. Used for processing
   1117  1.1.1.1.10.2       tls  *              nested #if/#else type conditional compilation directives.
   1118  1.1.1.1.10.2       tls  *              Specifically: Used on detection of #elif and #endif to remove
   1119  1.1.1.1.10.2       tls  *              the original #if/#ifdef/#ifndef from the stack and close
   1120  1.1.1.1.10.2       tls  *              the block.
   1121  1.1.1.1.10.2       tls  *
   1122  1.1.1.1.10.2       tls  ******************************************************************************/
   1123  1.1.1.1.10.2       tls 
   1124  1.1.1.1.10.2       tls static ACPI_STATUS
   1125  1.1.1.1.10.2       tls PrPopDirective (
   1126  1.1.1.1.10.2       tls     void)
   1127  1.1.1.1.10.2       tls {
   1128  1.1.1.1.10.2       tls     DIRECTIVE_INFO          *Info;
   1129  1.1.1.1.10.2       tls 
   1130  1.1.1.1.10.2       tls 
   1131  1.1.1.1.10.2       tls     /* Check for empty stack */
   1132  1.1.1.1.10.2       tls 
   1133  1.1.1.1.10.2       tls     Info = Gbl_DirectiveStack;
   1134  1.1.1.1.10.2       tls     if (!Info)
   1135  1.1.1.1.10.2       tls     {
   1136  1.1.1.1.10.2       tls         return (AE_ERROR);
   1137  1.1.1.1.10.2       tls     }
   1138  1.1.1.1.10.2       tls 
   1139  1.1.1.1.10.2       tls     /* Pop one item, keep globals up-to-date */
   1140  1.1.1.1.10.2       tls 
   1141  1.1.1.1.10.2       tls     Gbl_IfDepth--;
   1142  1.1.1.1.10.2       tls     Gbl_IgnoringThisCodeBlock = Info->IgnoringThisCodeBlock;
   1143  1.1.1.1.10.2       tls     Gbl_DirectiveStack = Info->Next;
   1144  1.1.1.1.10.2       tls 
   1145  1.1.1.1.10.2       tls     DbgPrint (ASL_DEBUG_OUTPUT,
   1146  1.1.1.1.10.2       tls         "Pr(%.4u) - [%u %s] %*s Popped [#%s %s]: IgnoreFlag now = %s\n",
   1147  1.1.1.1.10.2       tls         Gbl_CurrentLineNumber, Gbl_IfDepth,
   1148  1.1.1.1.10.2       tls         Gbl_IgnoringThisCodeBlock ? "I" : "E",
   1149  1.1.1.1.10.2       tls         Gbl_IfDepth * 4, " ",
   1150  1.1.1.1.10.2       tls         Gbl_DirectiveInfo[Info->Directive].Name,
   1151  1.1.1.1.10.2       tls         Info->Argument, Gbl_IgnoringThisCodeBlock ? "TRUE" : "FALSE");
   1152  1.1.1.1.10.2       tls 
   1153  1.1.1.1.10.2       tls     ACPI_FREE (Info);
   1154  1.1.1.1.10.2       tls     return (AE_OK);
   1155  1.1.1.1.10.2       tls }
   1156  1.1.1.1.10.2       tls 
   1157  1.1.1.1.10.2       tls 
   1158  1.1.1.1.10.2       tls /*******************************************************************************
   1159  1.1.1.1.10.2       tls  *
   1160  1.1.1.1.10.2       tls  * FUNCTION:    PrDbgPrint
   1161  1.1.1.1.10.2       tls  *
   1162  1.1.1.1.10.2       tls  * PARAMETERS:  Action              - Action being performed
   1163  1.1.1.1.10.2       tls  *              DirectiveName       - Directive being processed
   1164  1.1.1.1.10.2       tls  *
   1165  1.1.1.1.10.2       tls  * RETURN:      None
   1166  1.1.1.1.10.2       tls  *
   1167  1.1.1.1.10.2       tls  * DESCRIPTION: Special debug print for directive processing.
   1168  1.1.1.1.10.2       tls  *
   1169  1.1.1.1.10.2       tls  ******************************************************************************/
   1170  1.1.1.1.10.2       tls 
   1171  1.1.1.1.10.2       tls static void
   1172  1.1.1.1.10.2       tls PrDbgPrint (
   1173  1.1.1.1.10.2       tls     char                    *Action,
   1174  1.1.1.1.10.2       tls     char                    *DirectiveName)
   1175  1.1.1.1.10.2       tls {
   1176  1.1.1.1.10.2       tls 
   1177  1.1.1.1.10.2       tls     DbgPrint (ASL_DEBUG_OUTPUT, "Pr(%.4u) - [%u %s] "
   1178  1.1.1.1.10.3  jdolecek         "%*s %s #%s, IfDepth %u\n",
   1179  1.1.1.1.10.2       tls         Gbl_CurrentLineNumber, Gbl_IfDepth,
   1180  1.1.1.1.10.2       tls         Gbl_IgnoringThisCodeBlock ? "I" : "E",
   1181  1.1.1.1.10.2       tls         Gbl_IfDepth * 4, " ",
   1182  1.1.1.1.10.2       tls         Action, DirectiveName, Gbl_IfDepth);
   1183  1.1.1.1.10.2       tls }
   1184  1.1.1.1.10.3  jdolecek 
   1185  1.1.1.1.10.3  jdolecek 
   1186  1.1.1.1.10.3  jdolecek /*******************************************************************************
   1187  1.1.1.1.10.3  jdolecek  *
   1188  1.1.1.1.10.3  jdolecek  * FUNCTION:    PrDoIncludeFile
   1189  1.1.1.1.10.3  jdolecek  *
   1190  1.1.1.1.10.3  jdolecek  * PARAMETERS:  Pathname                - Name of the input file
   1191  1.1.1.1.10.3  jdolecek  *
   1192  1.1.1.1.10.3  jdolecek  * RETURN:      None.
   1193  1.1.1.1.10.3  jdolecek  *
   1194  1.1.1.1.10.3  jdolecek  * DESCRIPTION: Open an include file, from #include.
   1195  1.1.1.1.10.3  jdolecek  *
   1196  1.1.1.1.10.3  jdolecek  ******************************************************************************/
   1197  1.1.1.1.10.3  jdolecek 
   1198  1.1.1.1.10.3  jdolecek static void
   1199  1.1.1.1.10.3  jdolecek PrDoIncludeFile (
   1200  1.1.1.1.10.3  jdolecek     char                    *Pathname)
   1201  1.1.1.1.10.3  jdolecek {
   1202  1.1.1.1.10.3  jdolecek     char                    *FullPathname;
   1203  1.1.1.1.10.3  jdolecek 
   1204  1.1.1.1.10.3  jdolecek 
   1205  1.1.1.1.10.3  jdolecek     (void) PrOpenIncludeFile (Pathname, "r", &FullPathname);
   1206  1.1.1.1.10.3  jdolecek }
   1207  1.1.1.1.10.3  jdolecek 
   1208  1.1.1.1.10.3  jdolecek 
   1209  1.1.1.1.10.3  jdolecek /*******************************************************************************
   1210  1.1.1.1.10.3  jdolecek  *
   1211  1.1.1.1.10.3  jdolecek  * FUNCTION:    PrDoIncludeBuffer
   1212  1.1.1.1.10.3  jdolecek  *
   1213  1.1.1.1.10.3  jdolecek  * PARAMETERS:  Pathname                - Name of the input binary file
   1214  1.1.1.1.10.3  jdolecek  *              BufferName              - ACPI namepath of the buffer
   1215  1.1.1.1.10.3  jdolecek  *
   1216  1.1.1.1.10.3  jdolecek  * RETURN:      None.
   1217  1.1.1.1.10.3  jdolecek  *
   1218  1.1.1.1.10.3  jdolecek  * DESCRIPTION: Create an ACPI buffer object from a binary file. The contents
   1219  1.1.1.1.10.3  jdolecek  *              of the file are emitted into the buffer object as ascii
   1220  1.1.1.1.10.3  jdolecek  *              hex data. From #includebuffer.
   1221  1.1.1.1.10.3  jdolecek  *
   1222  1.1.1.1.10.3  jdolecek  ******************************************************************************/
   1223  1.1.1.1.10.3  jdolecek 
   1224  1.1.1.1.10.3  jdolecek static void
   1225  1.1.1.1.10.3  jdolecek PrDoIncludeBuffer (
   1226  1.1.1.1.10.3  jdolecek     char                    *Pathname,
   1227  1.1.1.1.10.3  jdolecek     char                    *BufferName)
   1228  1.1.1.1.10.3  jdolecek {
   1229  1.1.1.1.10.3  jdolecek     char                    *FullPathname;
   1230  1.1.1.1.10.3  jdolecek     FILE                    *BinaryBufferFile;
   1231  1.1.1.1.10.3  jdolecek     UINT32                  i = 0;
   1232  1.1.1.1.10.3  jdolecek     UINT8                   c;
   1233  1.1.1.1.10.3  jdolecek 
   1234  1.1.1.1.10.3  jdolecek 
   1235  1.1.1.1.10.3  jdolecek     BinaryBufferFile = PrOpenIncludeFile (Pathname, "rb", &FullPathname);
   1236  1.1.1.1.10.3  jdolecek     if (!BinaryBufferFile)
   1237  1.1.1.1.10.3  jdolecek     {
   1238  1.1.1.1.10.3  jdolecek         return;
   1239  1.1.1.1.10.3  jdolecek     }
   1240  1.1.1.1.10.3  jdolecek 
   1241  1.1.1.1.10.3  jdolecek     /* Emit "Name (XXXX, Buffer() {" header */
   1242  1.1.1.1.10.3  jdolecek 
   1243  1.1.1.1.10.3  jdolecek     FlPrintFile (ASL_FILE_PREPROCESSOR, "Name (%s, Buffer()\n{", BufferName);
   1244  1.1.1.1.10.3  jdolecek 
   1245  1.1.1.1.10.3  jdolecek     /* Dump the entire file in ascii hex format */
   1246  1.1.1.1.10.3  jdolecek 
   1247  1.1.1.1.10.3  jdolecek     while (fread (&c, 1, 1, BinaryBufferFile))
   1248  1.1.1.1.10.3  jdolecek     {
   1249  1.1.1.1.10.3  jdolecek         if (!(i % 8))
   1250  1.1.1.1.10.3  jdolecek         {
   1251  1.1.1.1.10.3  jdolecek             FlPrintFile (ASL_FILE_PREPROCESSOR, "\n   ", c);
   1252  1.1.1.1.10.3  jdolecek         }
   1253  1.1.1.1.10.3  jdolecek 
   1254  1.1.1.1.10.3  jdolecek         FlPrintFile (ASL_FILE_PREPROCESSOR, " 0x%2.2X,", c);
   1255  1.1.1.1.10.3  jdolecek         i++;
   1256  1.1.1.1.10.3  jdolecek     }
   1257  1.1.1.1.10.3  jdolecek 
   1258  1.1.1.1.10.3  jdolecek     DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
   1259  1.1.1.1.10.3  jdolecek         "#includebuffer: read %u bytes from %s\n",
   1260  1.1.1.1.10.3  jdolecek         Gbl_CurrentLineNumber, i, FullPathname);
   1261  1.1.1.1.10.3  jdolecek 
   1262  1.1.1.1.10.3  jdolecek     /* Close the Name() operator */
   1263  1.1.1.1.10.3  jdolecek 
   1264  1.1.1.1.10.3  jdolecek     FlPrintFile (ASL_FILE_PREPROCESSOR, "\n})\n", BufferName);
   1265  1.1.1.1.10.3  jdolecek     fclose (BinaryBufferFile);
   1266  1.1.1.1.10.3  jdolecek }
   1267