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