14c52cad2SJung-uk Kim /******************************************************************************
24c52cad2SJung-uk Kim *
34c52cad2SJung-uk Kim * Module Name: prscan - Preprocessor start-up and file scan module
44c52cad2SJung-uk Kim *
54c52cad2SJung-uk Kim *****************************************************************************/
64c52cad2SJung-uk Kim
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim *
90d84335fSJung-uk Kim * 1. Copyright Notice
100d84335fSJung-uk Kim *
11*722b1667SJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
124c52cad2SJung-uk Kim * All rights reserved.
134c52cad2SJung-uk Kim *
140d84335fSJung-uk Kim * 2. License
150d84335fSJung-uk Kim *
160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim * property rights.
200d84335fSJung-uk Kim *
210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim *
280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim *
370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim * conditions are met:
390d84335fSJung-uk Kim *
400d84335fSJung-uk Kim * 3. Conditions
410d84335fSJung-uk Kim *
420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim *
540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim * make.
650d84335fSJung-uk Kim *
660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim * distribution.
710d84335fSJung-uk Kim *
720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim * Intel Code.
740d84335fSJung-uk Kim *
750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim * without prior written authorization from Intel.
790d84335fSJung-uk Kim *
800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim *
820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim *
900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim * LIMITED REMEDY.
980d84335fSJung-uk Kim *
990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim * such license, approval or letter.
1130d84335fSJung-uk Kim *
1140d84335fSJung-uk Kim *****************************************************************************
1150d84335fSJung-uk Kim *
1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim * following license:
1180d84335fSJung-uk Kim *
1194c52cad2SJung-uk Kim * Redistribution and use in source and binary forms, with or without
1204c52cad2SJung-uk Kim * modification, are permitted provided that the following conditions
1214c52cad2SJung-uk Kim * are met:
1224c52cad2SJung-uk Kim * 1. Redistributions of source code must retain the above copyright
1234c52cad2SJung-uk Kim * notice, this list of conditions, and the following disclaimer,
1244c52cad2SJung-uk Kim * without modification.
1254c52cad2SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1264c52cad2SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below
1274c52cad2SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon
1284c52cad2SJung-uk Kim * including a substantially similar Disclaimer requirement for further
1294c52cad2SJung-uk Kim * binary redistribution.
1304c52cad2SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names
1314c52cad2SJung-uk Kim * of any contributors may be used to endorse or promote products derived
1324c52cad2SJung-uk Kim * from this software without specific prior written permission.
1334c52cad2SJung-uk Kim *
1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim *
1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
1474c52cad2SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free
1484c52cad2SJung-uk Kim * Software Foundation.
1494c52cad2SJung-uk Kim *
1500d84335fSJung-uk Kim *****************************************************************************/
1514c52cad2SJung-uk Kim
1524c52cad2SJung-uk Kim #define _DECLARE_PR_GLOBALS
1534c52cad2SJung-uk Kim
1544c52cad2SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
1554c52cad2SJung-uk Kim
1564c52cad2SJung-uk Kim /*
1574c52cad2SJung-uk Kim * TBDs:
1584c52cad2SJung-uk Kim *
1594c52cad2SJung-uk Kim * No nested macros, maybe never
1604c52cad2SJung-uk Kim * Implement ASL "Include" as well as "#include" here?
1614c52cad2SJung-uk Kim */
1624c52cad2SJung-uk Kim #define _COMPONENT ASL_PREPROCESSOR
1634c52cad2SJung-uk Kim ACPI_MODULE_NAME ("prscan")
1644c52cad2SJung-uk Kim
1654c52cad2SJung-uk Kim
1664c52cad2SJung-uk Kim /* Local prototypes */
1674c52cad2SJung-uk Kim
1684c52cad2SJung-uk Kim static void
1694c52cad2SJung-uk Kim PrPreprocessInputFile (
1704c52cad2SJung-uk Kim void);
1714c52cad2SJung-uk Kim
1724c52cad2SJung-uk Kim static void
1734c52cad2SJung-uk Kim PrDoDirective (
1744c52cad2SJung-uk Kim char *DirectiveToken,
1758d744e47SJung-uk Kim char **Next);
1764c52cad2SJung-uk Kim
1775ef50723SJung-uk Kim static void
1785ef50723SJung-uk Kim PrGetNextLineInit (
1795ef50723SJung-uk Kim void);
1805ef50723SJung-uk Kim
1815ef50723SJung-uk Kim static UINT32
1825ef50723SJung-uk Kim PrGetNextLine (
1835ef50723SJung-uk Kim FILE *Handle);
1845ef50723SJung-uk Kim
1854c52cad2SJung-uk Kim static int
1864c52cad2SJung-uk Kim PrMatchDirective (
1874c52cad2SJung-uk Kim char *Directive);
1884c52cad2SJung-uk Kim
1898d744e47SJung-uk Kim static void
1908d744e47SJung-uk Kim PrPushDirective (
1918d744e47SJung-uk Kim int Directive,
1928d744e47SJung-uk Kim char *Argument);
1938d744e47SJung-uk Kim
1948d744e47SJung-uk Kim static ACPI_STATUS
1958d744e47SJung-uk Kim PrPopDirective (
1968d744e47SJung-uk Kim void);
1978d744e47SJung-uk Kim
1988d744e47SJung-uk Kim static void
1998d744e47SJung-uk Kim PrDbgPrint (
2008d744e47SJung-uk Kim char *Action,
2018d744e47SJung-uk Kim char *DirectiveName);
2028d744e47SJung-uk Kim
203a371a5fdSJung-uk Kim static void
204a371a5fdSJung-uk Kim PrDoIncludeBuffer (
205a371a5fdSJung-uk Kim char *Pathname,
206a371a5fdSJung-uk Kim char *BufferName);
207a371a5fdSJung-uk Kim
208a371a5fdSJung-uk Kim static void
209a371a5fdSJung-uk Kim PrDoIncludeFile (
210a371a5fdSJung-uk Kim char *Pathname);
211a371a5fdSJung-uk Kim
2128d744e47SJung-uk Kim
2134c52cad2SJung-uk Kim /*
2144c52cad2SJung-uk Kim * Supported preprocessor directives
215a371a5fdSJung-uk Kim * Each entry is of the form "Name, ArgumentCount"
2164c52cad2SJung-uk Kim */
2176f1f1a63SJung-uk Kim static const PR_DIRECTIVE_INFO AslGbl_DirectiveInfo[] =
2184c52cad2SJung-uk Kim {
2194c52cad2SJung-uk Kim {"define", 1},
2204c52cad2SJung-uk Kim {"elif", 0}, /* Converted to #else..#if internally */
2214c52cad2SJung-uk Kim {"else", 0},
2224c52cad2SJung-uk Kim {"endif", 0},
2234c52cad2SJung-uk Kim {"error", 1},
2244c52cad2SJung-uk Kim {"if", 1},
2254c52cad2SJung-uk Kim {"ifdef", 1},
2264c52cad2SJung-uk Kim {"ifndef", 1},
227a371a5fdSJung-uk Kim {"include", 0}, /* Argument is not standard format, so just use 0 here */
228a371a5fdSJung-uk Kim {"includebuffer", 0}, /* Argument is not standard format, so just use 0 here */
2294c52cad2SJung-uk Kim {"line", 1},
2304c52cad2SJung-uk Kim {"pragma", 1},
2314c52cad2SJung-uk Kim {"undef", 1},
2324c52cad2SJung-uk Kim {"warning", 1},
2334c52cad2SJung-uk Kim {NULL, 0}
2344c52cad2SJung-uk Kim };
2354c52cad2SJung-uk Kim
236a371a5fdSJung-uk Kim /* This table must match ordering of above table exactly */
237a371a5fdSJung-uk Kim
2384c52cad2SJung-uk Kim enum Gbl_DirectiveIndexes
2394c52cad2SJung-uk Kim {
2404c52cad2SJung-uk Kim PR_DIRECTIVE_DEFINE = 0,
2414c52cad2SJung-uk Kim PR_DIRECTIVE_ELIF,
2424c52cad2SJung-uk Kim PR_DIRECTIVE_ELSE,
2434c52cad2SJung-uk Kim PR_DIRECTIVE_ENDIF,
2444c52cad2SJung-uk Kim PR_DIRECTIVE_ERROR,
2454c52cad2SJung-uk Kim PR_DIRECTIVE_IF,
2464c52cad2SJung-uk Kim PR_DIRECTIVE_IFDEF,
2474c52cad2SJung-uk Kim PR_DIRECTIVE_IFNDEF,
2484c52cad2SJung-uk Kim PR_DIRECTIVE_INCLUDE,
249a371a5fdSJung-uk Kim PR_DIRECTIVE_INCLUDEBUFFER,
2504c52cad2SJung-uk Kim PR_DIRECTIVE_LINE,
2514c52cad2SJung-uk Kim PR_DIRECTIVE_PRAGMA,
2524c52cad2SJung-uk Kim PR_DIRECTIVE_UNDEF,
253fe0f0bbbSJung-uk Kim PR_DIRECTIVE_WARNING
2544c52cad2SJung-uk Kim };
2554c52cad2SJung-uk Kim
2564c52cad2SJung-uk Kim #define ASL_DIRECTIVE_NOT_FOUND -1
2574c52cad2SJung-uk Kim
2584c52cad2SJung-uk Kim
2594c52cad2SJung-uk Kim /*******************************************************************************
2604c52cad2SJung-uk Kim *
2614c52cad2SJung-uk Kim * FUNCTION: PrInitializePreprocessor
2624c52cad2SJung-uk Kim *
2634c52cad2SJung-uk Kim * PARAMETERS: None
2644c52cad2SJung-uk Kim *
2654c52cad2SJung-uk Kim * RETURN: None
2664c52cad2SJung-uk Kim *
2674c52cad2SJung-uk Kim * DESCRIPTION: Startup initialization for the Preprocessor.
2684c52cad2SJung-uk Kim *
2694c52cad2SJung-uk Kim ******************************************************************************/
2704c52cad2SJung-uk Kim
2714c52cad2SJung-uk Kim void
PrInitializePreprocessor(void)2724c52cad2SJung-uk Kim PrInitializePreprocessor (
2734c52cad2SJung-uk Kim void)
2744c52cad2SJung-uk Kim {
2754c52cad2SJung-uk Kim /* Init globals and the list of #defines */
2764c52cad2SJung-uk Kim
2774c52cad2SJung-uk Kim PrInitializeGlobals ();
2786f1f1a63SJung-uk Kim AslGbl_DefineList = NULL;
2794c52cad2SJung-uk Kim }
2804c52cad2SJung-uk Kim
2814c52cad2SJung-uk Kim
2824c52cad2SJung-uk Kim /*******************************************************************************
2834c52cad2SJung-uk Kim *
2844c52cad2SJung-uk Kim * FUNCTION: PrInitializeGlobals
2854c52cad2SJung-uk Kim *
2864c52cad2SJung-uk Kim * PARAMETERS: None
2874c52cad2SJung-uk Kim *
2884c52cad2SJung-uk Kim * RETURN: None
2894c52cad2SJung-uk Kim *
2904c52cad2SJung-uk Kim * DESCRIPTION: Initialize globals for the Preprocessor. Used for startuup
2914c52cad2SJung-uk Kim * initialization and re-initialization between compiles during
2924c52cad2SJung-uk Kim * a multiple source file compile.
2934c52cad2SJung-uk Kim *
2944c52cad2SJung-uk Kim ******************************************************************************/
2954c52cad2SJung-uk Kim
2964c52cad2SJung-uk Kim void
PrInitializeGlobals(void)2974c52cad2SJung-uk Kim PrInitializeGlobals (
2984c52cad2SJung-uk Kim void)
2994c52cad2SJung-uk Kim {
3004c52cad2SJung-uk Kim /* Init globals */
3014c52cad2SJung-uk Kim
3026f1f1a63SJung-uk Kim AslGbl_InputFileList = NULL;
3036f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber = 1;
3046f1f1a63SJung-uk Kim AslGbl_PreprocessorLineNumber = 1;
3056f1f1a63SJung-uk Kim AslGbl_PreprocessorError = FALSE;
3068d744e47SJung-uk Kim
3078d744e47SJung-uk Kim /* These are used to track #if/#else blocks (possibly nested) */
3088d744e47SJung-uk Kim
3096f1f1a63SJung-uk Kim AslGbl_IfDepth = 0;
3106f1f1a63SJung-uk Kim AslGbl_IgnoringThisCodeBlock = FALSE;
3116f1f1a63SJung-uk Kim AslGbl_DirectiveStack = NULL;
3124c52cad2SJung-uk Kim }
3134c52cad2SJung-uk Kim
3144c52cad2SJung-uk Kim
3154c52cad2SJung-uk Kim /*******************************************************************************
3164c52cad2SJung-uk Kim *
3174c52cad2SJung-uk Kim * FUNCTION: PrTerminatePreprocessor
3184c52cad2SJung-uk Kim *
3194c52cad2SJung-uk Kim * PARAMETERS: None
3204c52cad2SJung-uk Kim *
3214c52cad2SJung-uk Kim * RETURN: None
3224c52cad2SJung-uk Kim *
3234c52cad2SJung-uk Kim * DESCRIPTION: Termination of the preprocessor. Delete lists. Keep any
3244c52cad2SJung-uk Kim * defines that were specified on the command line, in order to
3254c52cad2SJung-uk Kim * support multiple compiles with a single compiler invocation.
3264c52cad2SJung-uk Kim *
3274c52cad2SJung-uk Kim ******************************************************************************/
3284c52cad2SJung-uk Kim
3294c52cad2SJung-uk Kim void
PrTerminatePreprocessor(void)3304c52cad2SJung-uk Kim PrTerminatePreprocessor (
3314c52cad2SJung-uk Kim void)
3324c52cad2SJung-uk Kim {
3334c52cad2SJung-uk Kim PR_DEFINE_INFO *DefineInfo;
3344c52cad2SJung-uk Kim
3354c52cad2SJung-uk Kim
3364c52cad2SJung-uk Kim /*
3374c52cad2SJung-uk Kim * The persistent defines (created on the command line) are always at the
3384c52cad2SJung-uk Kim * end of the list. We save them.
3394c52cad2SJung-uk Kim */
3406f1f1a63SJung-uk Kim while ((AslGbl_DefineList) && (!AslGbl_DefineList->Persist))
3414c52cad2SJung-uk Kim {
3426f1f1a63SJung-uk Kim DefineInfo = AslGbl_DefineList;
3436f1f1a63SJung-uk Kim AslGbl_DefineList = DefineInfo->Next;
3444c52cad2SJung-uk Kim
3454c52cad2SJung-uk Kim ACPI_FREE (DefineInfo->Replacement);
3464c52cad2SJung-uk Kim ACPI_FREE (DefineInfo->Identifier);
3474c52cad2SJung-uk Kim ACPI_FREE (DefineInfo);
3484c52cad2SJung-uk Kim }
3494c52cad2SJung-uk Kim }
3504c52cad2SJung-uk Kim
3514c52cad2SJung-uk Kim
3524c52cad2SJung-uk Kim /*******************************************************************************
3534c52cad2SJung-uk Kim *
3544c52cad2SJung-uk Kim * FUNCTION: PrDoPreprocess
3554c52cad2SJung-uk Kim *
3564c52cad2SJung-uk Kim * PARAMETERS: None
3574c52cad2SJung-uk Kim *
3588d744e47SJung-uk Kim * RETURN: None
3594c52cad2SJung-uk Kim *
3604c52cad2SJung-uk Kim * DESCRIPTION: Main entry point for the iASL Preprocessor. Input file must
3614c52cad2SJung-uk Kim * be already open. Handles multiple input files via the
3624c52cad2SJung-uk Kim * #include directive.
3634c52cad2SJung-uk Kim *
3644c52cad2SJung-uk Kim ******************************************************************************/
3654c52cad2SJung-uk Kim
3668d744e47SJung-uk Kim void
PrDoPreprocess(void)3674c52cad2SJung-uk Kim PrDoPreprocess (
3684c52cad2SJung-uk Kim void)
3694c52cad2SJung-uk Kim {
3704c52cad2SJung-uk Kim BOOLEAN MoreInputFiles;
3714c52cad2SJung-uk Kim
3724c52cad2SJung-uk Kim
3734c52cad2SJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT, "Starting preprocessing phase\n\n");
3744c52cad2SJung-uk Kim
3754c52cad2SJung-uk Kim
3764c52cad2SJung-uk Kim FlSeekFile (ASL_FILE_INPUT, 0);
3774c52cad2SJung-uk Kim PrDumpPredefinedNames ();
3784c52cad2SJung-uk Kim
3794c52cad2SJung-uk Kim /* Main preprocessor loop, handles include files */
3804c52cad2SJung-uk Kim
3814c52cad2SJung-uk Kim do
3824c52cad2SJung-uk Kim {
3834c52cad2SJung-uk Kim PrPreprocessInputFile ();
3844c52cad2SJung-uk Kim MoreInputFiles = PrPopInputFileStack ();
3854c52cad2SJung-uk Kim
3864c52cad2SJung-uk Kim } while (MoreInputFiles);
3874c52cad2SJung-uk Kim
3885ef50723SJung-uk Kim /* Point compiler input to the new preprocessor output file (.pre) */
3894c52cad2SJung-uk Kim
3904c52cad2SJung-uk Kim FlCloseFile (ASL_FILE_INPUT);
3916f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Handle = AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle;
3926f1f1a63SJung-uk Kim AslCompilerin = AslGbl_Files[ASL_FILE_INPUT].Handle;
3934c52cad2SJung-uk Kim
3944c52cad2SJung-uk Kim /* Reset globals to allow compiler to run */
3954c52cad2SJung-uk Kim
3964c52cad2SJung-uk Kim FlSeekFile (ASL_FILE_INPUT, 0);
3976f1f1a63SJung-uk Kim if (!AslGbl_PreprocessOnly)
3985ef50723SJung-uk Kim {
3996f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber = 0;
4005ef50723SJung-uk Kim }
4014c52cad2SJung-uk Kim
4024c52cad2SJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT, "Preprocessing phase complete \n\n");
4034c52cad2SJung-uk Kim }
4044c52cad2SJung-uk Kim
4054c52cad2SJung-uk Kim
4064c52cad2SJung-uk Kim /*******************************************************************************
4074c52cad2SJung-uk Kim *
4084c52cad2SJung-uk Kim * FUNCTION: PrPreprocessInputFile
4094c52cad2SJung-uk Kim *
4104c52cad2SJung-uk Kim * PARAMETERS: None
4114c52cad2SJung-uk Kim *
4124c52cad2SJung-uk Kim * RETURN: None
4134c52cad2SJung-uk Kim *
4144c52cad2SJung-uk Kim * DESCRIPTION: Preprocess one entire file, line-by-line.
4154c52cad2SJung-uk Kim *
4164c52cad2SJung-uk Kim * Input: Raw user ASL from ASL_FILE_INPUT
4175ef50723SJung-uk Kim * Output: Preprocessed file written to ASL_FILE_PREPROCESSOR and
4185ef50723SJung-uk Kim * (optionally) ASL_FILE_PREPROCESSOR_USER
4194c52cad2SJung-uk Kim *
4204c52cad2SJung-uk Kim ******************************************************************************/
4214c52cad2SJung-uk Kim
4224c52cad2SJung-uk Kim static void
PrPreprocessInputFile(void)4234c52cad2SJung-uk Kim PrPreprocessInputFile (
4244c52cad2SJung-uk Kim void)
4254c52cad2SJung-uk Kim {
4265ef50723SJung-uk Kim UINT32 Status;
4274c52cad2SJung-uk Kim char *Token;
4284c52cad2SJung-uk Kim char *ReplaceString;
4294c52cad2SJung-uk Kim PR_DEFINE_INFO *DefineInfo;
4304c52cad2SJung-uk Kim ACPI_SIZE TokenOffset;
4314c52cad2SJung-uk Kim char *Next;
4324c52cad2SJung-uk Kim int OffsetAdjust;
4334c52cad2SJung-uk Kim
4344c52cad2SJung-uk Kim
4355ef50723SJung-uk Kim PrGetNextLineInit ();
4365ef50723SJung-uk Kim
437fe0f0bbbSJung-uk Kim /* Scan source line-by-line and process directives. Then write the .i file */
4384c52cad2SJung-uk Kim
4396f1f1a63SJung-uk Kim while ((Status = PrGetNextLine (AslGbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF)
4404c52cad2SJung-uk Kim {
4416f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber++;
4426f1f1a63SJung-uk Kim AslGbl_LogicalLineNumber++;
4435ef50723SJung-uk Kim
444f8146b88SJung-uk Kim if (Status == ASL_IGNORE_LINE)
4455ef50723SJung-uk Kim {
4465ef50723SJung-uk Kim goto WriteEntireLine;
4475ef50723SJung-uk Kim }
4485ef50723SJung-uk Kim
4494c52cad2SJung-uk Kim /* Need a copy of the input line for strok() */
4504c52cad2SJung-uk Kim
4516f1f1a63SJung-uk Kim strcpy (AslGbl_MainTokenBuffer, AslGbl_CurrentLineBuffer);
4526f1f1a63SJung-uk Kim Token = PrGetNextToken (AslGbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next);
4534c52cad2SJung-uk Kim OffsetAdjust = 0;
4544c52cad2SJung-uk Kim
4554c52cad2SJung-uk Kim /* All preprocessor directives must begin with '#' */
4564c52cad2SJung-uk Kim
4574c52cad2SJung-uk Kim if (Token && (*Token == '#'))
4584c52cad2SJung-uk Kim {
4594c52cad2SJung-uk Kim if (strlen (Token) == 1)
4604c52cad2SJung-uk Kim {
4614c52cad2SJung-uk Kim Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
4624c52cad2SJung-uk Kim }
4634c52cad2SJung-uk Kim else
4644c52cad2SJung-uk Kim {
4654c52cad2SJung-uk Kim Token++; /* Skip leading # */
4664c52cad2SJung-uk Kim }
4674c52cad2SJung-uk Kim
4684c52cad2SJung-uk Kim /* Execute the directive, do not write line to output file */
4694c52cad2SJung-uk Kim
4708d744e47SJung-uk Kim PrDoDirective (Token, &Next);
4714c52cad2SJung-uk Kim continue;
4724c52cad2SJung-uk Kim }
4734c52cad2SJung-uk Kim
4744c52cad2SJung-uk Kim /*
4754c52cad2SJung-uk Kim * If we are currently within the part of an IF/ELSE block that is
4764c52cad2SJung-uk Kim * FALSE, ignore the line and do not write it to the output file.
4774c52cad2SJung-uk Kim * This continues until an #else or #endif is encountered.
4784c52cad2SJung-uk Kim */
4796f1f1a63SJung-uk Kim if (AslGbl_IgnoringThisCodeBlock)
4804c52cad2SJung-uk Kim {
4814c52cad2SJung-uk Kim continue;
4824c52cad2SJung-uk Kim }
4834c52cad2SJung-uk Kim
4844c52cad2SJung-uk Kim /* Match and replace all #defined names within this source line */
4854c52cad2SJung-uk Kim
4864c52cad2SJung-uk Kim while (Token)
4874c52cad2SJung-uk Kim {
4884c52cad2SJung-uk Kim DefineInfo = PrMatchDefine (Token);
4894c52cad2SJung-uk Kim if (DefineInfo)
4904c52cad2SJung-uk Kim {
4914c52cad2SJung-uk Kim if (DefineInfo->Body)
4924c52cad2SJung-uk Kim {
4934c52cad2SJung-uk Kim /* This is a macro */
4944c52cad2SJung-uk Kim
4954c52cad2SJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
4964c52cad2SJung-uk Kim "Matched Macro: %s->%s\n",
4976f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, DefineInfo->Identifier,
4984c52cad2SJung-uk Kim DefineInfo->Replacement);
4994c52cad2SJung-uk Kim
5006f1f1a63SJung-uk Kim PrDoMacroInvocation (AslGbl_MainTokenBuffer, Token,
5014c52cad2SJung-uk Kim DefineInfo, &Next);
5024c52cad2SJung-uk Kim }
5034c52cad2SJung-uk Kim else
5044c52cad2SJung-uk Kim {
5054c52cad2SJung-uk Kim ReplaceString = DefineInfo->Replacement;
5064c52cad2SJung-uk Kim
5074c52cad2SJung-uk Kim /* Replace the name in the original line buffer */
5084c52cad2SJung-uk Kim
5096f1f1a63SJung-uk Kim TokenOffset = Token - AslGbl_MainTokenBuffer + OffsetAdjust;
5104c52cad2SJung-uk Kim PrReplaceData (
5116f1f1a63SJung-uk Kim &AslGbl_CurrentLineBuffer[TokenOffset], strlen (Token),
5124c52cad2SJung-uk Kim ReplaceString, strlen (ReplaceString));
5134c52cad2SJung-uk Kim
5144c52cad2SJung-uk Kim /* Adjust for length difference between old and new name length */
5154c52cad2SJung-uk Kim
5164c52cad2SJung-uk Kim OffsetAdjust += strlen (ReplaceString) - strlen (Token);
5174c52cad2SJung-uk Kim
5184c52cad2SJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
5194c52cad2SJung-uk Kim "Matched #define: %s->%s\n",
5206f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, Token,
5214c52cad2SJung-uk Kim *ReplaceString ? ReplaceString : "(NULL STRING)");
5224c52cad2SJung-uk Kim }
5234c52cad2SJung-uk Kim }
5244c52cad2SJung-uk Kim
5254c52cad2SJung-uk Kim Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
5264c52cad2SJung-uk Kim }
5274c52cad2SJung-uk Kim
5286f1f1a63SJung-uk Kim AslGbl_PreprocessorLineNumber++;
529eef1b955SJung-uk Kim
5305ef50723SJung-uk Kim
5315ef50723SJung-uk Kim WriteEntireLine:
532eef1b955SJung-uk Kim /*
533eef1b955SJung-uk Kim * Now we can write the possibly modified source line to the
5345ef50723SJung-uk Kim * preprocessor file(s).
535eef1b955SJung-uk Kim */
5366f1f1a63SJung-uk Kim FlWriteFile (ASL_FILE_PREPROCESSOR, AslGbl_CurrentLineBuffer,
5376f1f1a63SJung-uk Kim strlen (AslGbl_CurrentLineBuffer));
5384c52cad2SJung-uk Kim }
5394c52cad2SJung-uk Kim }
5404c52cad2SJung-uk Kim
5414c52cad2SJung-uk Kim
5424c52cad2SJung-uk Kim /*******************************************************************************
5434c52cad2SJung-uk Kim *
5444c52cad2SJung-uk Kim * FUNCTION: PrDoDirective
5454c52cad2SJung-uk Kim *
5464c52cad2SJung-uk Kim * PARAMETERS: Directive - Pointer to directive name token
5474c52cad2SJung-uk Kim * Next - "Next" buffer from GetNextToken
5484c52cad2SJung-uk Kim *
5498d744e47SJung-uk Kim * RETURN: None.
5504c52cad2SJung-uk Kim *
5514c52cad2SJung-uk Kim * DESCRIPTION: Main processing for all preprocessor directives
5524c52cad2SJung-uk Kim *
5534c52cad2SJung-uk Kim ******************************************************************************/
5544c52cad2SJung-uk Kim
5554c52cad2SJung-uk Kim static void
PrDoDirective(char * DirectiveToken,char ** Next)5564c52cad2SJung-uk Kim PrDoDirective (
5574c52cad2SJung-uk Kim char *DirectiveToken,
5588d744e47SJung-uk Kim char **Next)
5594c52cad2SJung-uk Kim {
5606f1f1a63SJung-uk Kim char *Token = AslGbl_MainTokenBuffer;
561a371a5fdSJung-uk Kim char *Token2 = NULL;
5624c52cad2SJung-uk Kim char *End;
5634c52cad2SJung-uk Kim UINT64 Value;
5644c52cad2SJung-uk Kim ACPI_SIZE TokenOffset;
5654c52cad2SJung-uk Kim int Directive;
5664c52cad2SJung-uk Kim ACPI_STATUS Status;
5674c52cad2SJung-uk Kim
5684c52cad2SJung-uk Kim
5694c52cad2SJung-uk Kim if (!DirectiveToken)
5704c52cad2SJung-uk Kim {
5714c52cad2SJung-uk Kim goto SyntaxError;
5724c52cad2SJung-uk Kim }
5734c52cad2SJung-uk Kim
5744c52cad2SJung-uk Kim Directive = PrMatchDirective (DirectiveToken);
5754c52cad2SJung-uk Kim if (Directive == ASL_DIRECTIVE_NOT_FOUND)
5764c52cad2SJung-uk Kim {
5774c52cad2SJung-uk Kim PrError (ASL_ERROR, ASL_MSG_UNKNOWN_DIRECTIVE,
5784c52cad2SJung-uk Kim THIS_TOKEN_OFFSET (DirectiveToken));
5794c52cad2SJung-uk Kim
580a371a5fdSJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
5814c52cad2SJung-uk Kim "#%s: Unknown directive\n",
5826f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, DirectiveToken);
5834c52cad2SJung-uk Kim return;
5844c52cad2SJung-uk Kim }
5854c52cad2SJung-uk Kim
5868d744e47SJung-uk Kim /*
587fe0f0bbbSJung-uk Kim * Emit a line directive into the preprocessor file (.pre) after
588fe0f0bbbSJung-uk Kim * every matched directive. This is passed through to the compiler
589fe0f0bbbSJung-uk Kim * so that error/warning messages are kept in sync with the
590fe0f0bbbSJung-uk Kim * original source file.
591fe0f0bbbSJung-uk Kim */
592fe0f0bbbSJung-uk Kim FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\" // #%s\n",
5936f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_Files[ASL_FILE_INPUT].Filename,
5946f1f1a63SJung-uk Kim AslGbl_DirectiveInfo[Directive].Name);
595fe0f0bbbSJung-uk Kim
596fe0f0bbbSJung-uk Kim /*
5978d744e47SJung-uk Kim * If we are currently ignoring this block and we encounter a #else or
5988d744e47SJung-uk Kim * #elif, we must ignore their blocks also if the parent block is also
5998d744e47SJung-uk Kim * being ignored.
6008d744e47SJung-uk Kim */
6016f1f1a63SJung-uk Kim if (AslGbl_IgnoringThisCodeBlock)
6024c52cad2SJung-uk Kim {
6038d744e47SJung-uk Kim switch (Directive)
6048d744e47SJung-uk Kim {
6058d744e47SJung-uk Kim case PR_DIRECTIVE_ELSE:
6068d744e47SJung-uk Kim case PR_DIRECTIVE_ELIF:
6078d744e47SJung-uk Kim
6086f1f1a63SJung-uk Kim if (AslGbl_DirectiveStack &&
6096f1f1a63SJung-uk Kim AslGbl_DirectiveStack->IgnoringThisCodeBlock)
6108d744e47SJung-uk Kim {
6116f1f1a63SJung-uk Kim PrDbgPrint ("Ignoring", AslGbl_DirectiveInfo[Directive].Name);
6128d744e47SJung-uk Kim return;
6138d744e47SJung-uk Kim }
6148d744e47SJung-uk Kim break;
6158d744e47SJung-uk Kim
6168d744e47SJung-uk Kim default:
6178d744e47SJung-uk Kim break;
6188d744e47SJung-uk Kim }
6194c52cad2SJung-uk Kim }
6204c52cad2SJung-uk Kim
6214c52cad2SJung-uk Kim /*
6224c52cad2SJung-uk Kim * Need to always check for #else, #elif, #endif regardless of
6234c52cad2SJung-uk Kim * whether we are ignoring the current code block, since these
6244c52cad2SJung-uk Kim * are conditional code block terminators.
6254c52cad2SJung-uk Kim */
6264c52cad2SJung-uk Kim switch (Directive)
6274c52cad2SJung-uk Kim {
6288d744e47SJung-uk Kim case PR_DIRECTIVE_ELSE:
6298d744e47SJung-uk Kim
6306f1f1a63SJung-uk Kim AslGbl_IgnoringThisCodeBlock = !(AslGbl_IgnoringThisCodeBlock);
6318d744e47SJung-uk Kim PrDbgPrint ("Executing", "else block");
6328d744e47SJung-uk Kim return;
6338d744e47SJung-uk Kim
6344c52cad2SJung-uk Kim case PR_DIRECTIVE_ELIF:
635a9d8d09cSJung-uk Kim
6366f1f1a63SJung-uk Kim AslGbl_IgnoringThisCodeBlock = !(AslGbl_IgnoringThisCodeBlock);
6378d744e47SJung-uk Kim Directive = PR_DIRECTIVE_IF;
6388d744e47SJung-uk Kim
6396f1f1a63SJung-uk Kim if (AslGbl_IgnoringThisCodeBlock == TRUE)
6404c52cad2SJung-uk Kim {
6414c52cad2SJung-uk Kim /* Not executing the ELSE part -- all done here */
6428d744e47SJung-uk Kim PrDbgPrint ("Ignoring", "elif block");
6434c52cad2SJung-uk Kim return;
6444c52cad2SJung-uk Kim }
6454c52cad2SJung-uk Kim
6468d744e47SJung-uk Kim /*
6478d744e47SJung-uk Kim * After this, we will execute the IF part further below.
6488d744e47SJung-uk Kim * First, however, pop off the original #if directive.
6498d744e47SJung-uk Kim */
6508d744e47SJung-uk Kim if (ACPI_FAILURE (PrPopDirective ()))
6518d744e47SJung-uk Kim {
6528d744e47SJung-uk Kim PrError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
6538d744e47SJung-uk Kim THIS_TOKEN_OFFSET (DirectiveToken));
6548d744e47SJung-uk Kim }
6554c52cad2SJung-uk Kim
6568d744e47SJung-uk Kim PrDbgPrint ("Executing", "elif block");
6574c52cad2SJung-uk Kim break;
6584c52cad2SJung-uk Kim
6594c52cad2SJung-uk Kim case PR_DIRECTIVE_ENDIF:
660a9d8d09cSJung-uk Kim
6618d744e47SJung-uk Kim PrDbgPrint ("Executing", "endif");
6628d744e47SJung-uk Kim
6638d744e47SJung-uk Kim /* Pop the owning #if/#ifdef/#ifndef */
6648d744e47SJung-uk Kim
6658d744e47SJung-uk Kim if (ACPI_FAILURE (PrPopDirective ()))
6664c52cad2SJung-uk Kim {
6674c52cad2SJung-uk Kim PrError (ASL_ERROR, ASL_MSG_ENDIF_MISMATCH,
6684c52cad2SJung-uk Kim THIS_TOKEN_OFFSET (DirectiveToken));
6694c52cad2SJung-uk Kim }
6704c52cad2SJung-uk Kim return;
6714c52cad2SJung-uk Kim
6724c52cad2SJung-uk Kim default:
6734c52cad2SJung-uk Kim break;
6744c52cad2SJung-uk Kim }
6754c52cad2SJung-uk Kim
6764c52cad2SJung-uk Kim /* Most directives have at least one argument */
6774c52cad2SJung-uk Kim
6786f1f1a63SJung-uk Kim if (AslGbl_DirectiveInfo[Directive].ArgCount >= 1)
6794c52cad2SJung-uk Kim {
6804c52cad2SJung-uk Kim Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
6814c52cad2SJung-uk Kim if (!Token)
6824c52cad2SJung-uk Kim {
6834c52cad2SJung-uk Kim goto SyntaxError;
6844c52cad2SJung-uk Kim }
6854c52cad2SJung-uk Kim }
6864c52cad2SJung-uk Kim
6876f1f1a63SJung-uk Kim if (AslGbl_DirectiveInfo[Directive].ArgCount >= 2)
688a371a5fdSJung-uk Kim {
689a371a5fdSJung-uk Kim Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
690a371a5fdSJung-uk Kim if (!Token2)
691a371a5fdSJung-uk Kim {
692a371a5fdSJung-uk Kim goto SyntaxError;
693a371a5fdSJung-uk Kim }
694a371a5fdSJung-uk Kim }
695a371a5fdSJung-uk Kim
6968d744e47SJung-uk Kim /*
6978d744e47SJung-uk Kim * At this point, if we are ignoring the current code block,
6988d744e47SJung-uk Kim * do not process any more directives (i.e., ignore them also.)
6998d744e47SJung-uk Kim * For "if" style directives, open/push a new block anyway. We
7008d744e47SJung-uk Kim * must do this to keep track of #endif directives
7018d744e47SJung-uk Kim */
7026f1f1a63SJung-uk Kim if (AslGbl_IgnoringThisCodeBlock)
7038d744e47SJung-uk Kim {
7044c52cad2SJung-uk Kim switch (Directive)
7054c52cad2SJung-uk Kim {
7068d744e47SJung-uk Kim case PR_DIRECTIVE_IF:
7078d744e47SJung-uk Kim case PR_DIRECTIVE_IFDEF:
7088d744e47SJung-uk Kim case PR_DIRECTIVE_IFNDEF:
7098d744e47SJung-uk Kim
7108d744e47SJung-uk Kim PrPushDirective (Directive, Token);
7116f1f1a63SJung-uk Kim PrDbgPrint ("Ignoring", AslGbl_DirectiveInfo[Directive].Name);
7128d744e47SJung-uk Kim break;
7138d744e47SJung-uk Kim
7148d744e47SJung-uk Kim default:
7158d744e47SJung-uk Kim break;
7168d744e47SJung-uk Kim }
7178d744e47SJung-uk Kim
7188d744e47SJung-uk Kim return;
7198d744e47SJung-uk Kim }
7208d744e47SJung-uk Kim
7218d744e47SJung-uk Kim /*
7228d744e47SJung-uk Kim * Execute the directive
7238d744e47SJung-uk Kim */
7246f1f1a63SJung-uk Kim PrDbgPrint ("Begin execution", AslGbl_DirectiveInfo[Directive].Name);
7258d744e47SJung-uk Kim
7268d744e47SJung-uk Kim switch (Directive)
7278d744e47SJung-uk Kim {
7288d744e47SJung-uk Kim case PR_DIRECTIVE_IF:
7298d744e47SJung-uk Kim
7306f1f1a63SJung-uk Kim TokenOffset = Token - AslGbl_MainTokenBuffer;
7318d744e47SJung-uk Kim
7328d744e47SJung-uk Kim /* Need to expand #define macros in the expression string first */
7338d744e47SJung-uk Kim
7348d744e47SJung-uk Kim Status = PrResolveIntegerExpression (
7356f1f1a63SJung-uk Kim &AslGbl_CurrentLineBuffer[TokenOffset-1], &Value);
7368d744e47SJung-uk Kim if (ACPI_FAILURE (Status))
7378d744e47SJung-uk Kim {
7388d744e47SJung-uk Kim return;
7398d744e47SJung-uk Kim }
7408d744e47SJung-uk Kim
7418d744e47SJung-uk Kim PrPushDirective (Directive, Token);
7428d744e47SJung-uk Kim if (!Value)
7438d744e47SJung-uk Kim {
7446f1f1a63SJung-uk Kim AslGbl_IgnoringThisCodeBlock = TRUE;
7458d744e47SJung-uk Kim }
7468d744e47SJung-uk Kim
747a371a5fdSJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
7488d744e47SJung-uk Kim "Resolved #if: %8.8X%8.8X %s\n",
7496f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value),
7506f1f1a63SJung-uk Kim AslGbl_IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>");
7518d744e47SJung-uk Kim break;
7528d744e47SJung-uk Kim
7538d744e47SJung-uk Kim case PR_DIRECTIVE_IFDEF:
7548d744e47SJung-uk Kim
7558d744e47SJung-uk Kim PrPushDirective (Directive, Token);
7568d744e47SJung-uk Kim if (!PrMatchDefine (Token))
7578d744e47SJung-uk Kim {
7586f1f1a63SJung-uk Kim AslGbl_IgnoringThisCodeBlock = TRUE;
7598d744e47SJung-uk Kim }
7608d744e47SJung-uk Kim
7618d744e47SJung-uk Kim PrDbgPrint ("Evaluated", "ifdef");
7628d744e47SJung-uk Kim break;
7638d744e47SJung-uk Kim
7648d744e47SJung-uk Kim case PR_DIRECTIVE_IFNDEF:
7658d744e47SJung-uk Kim
7668d744e47SJung-uk Kim PrPushDirective (Directive, Token);
7678d744e47SJung-uk Kim if (PrMatchDefine (Token))
7688d744e47SJung-uk Kim {
7696f1f1a63SJung-uk Kim AslGbl_IgnoringThisCodeBlock = TRUE;
7708d744e47SJung-uk Kim }
7718d744e47SJung-uk Kim
7728d744e47SJung-uk Kim PrDbgPrint ("Evaluated", "ifndef");
7738d744e47SJung-uk Kim break;
7748d744e47SJung-uk Kim
7754c52cad2SJung-uk Kim case PR_DIRECTIVE_DEFINE:
7764c52cad2SJung-uk Kim /*
7774c52cad2SJung-uk Kim * By definition, if first char after the name is a paren,
7784c52cad2SJung-uk Kim * this is a function macro.
7794c52cad2SJung-uk Kim */
7806f1f1a63SJung-uk Kim TokenOffset = Token - AslGbl_MainTokenBuffer + strlen (Token);
7816f1f1a63SJung-uk Kim if (*(&AslGbl_CurrentLineBuffer[TokenOffset]) == '(')
7824c52cad2SJung-uk Kim {
783*722b1667SJung-uk Kim
784*722b1667SJung-uk Kim #ifdef MACROS_SUPPORTED
785f8146b88SJung-uk Kim AcpiOsPrintf(
786f8146b88SJung-uk Kim "%s ERROR - line %u: #define macros are not supported yet\n",
7876f1f1a63SJung-uk Kim AslGbl_CurrentLineBuffer, AslGbl_LogicalLineNumber);
788eef1b955SJung-uk Kim exit(1);
7894c52cad2SJung-uk Kim #else
7904c52cad2SJung-uk Kim PrAddMacro (Token, Next);
7914c52cad2SJung-uk Kim #endif
7924c52cad2SJung-uk Kim }
793*722b1667SJung-uk Kim
794*722b1667SJung-uk Kim
7954c52cad2SJung-uk Kim else
7964c52cad2SJung-uk Kim {
7974c52cad2SJung-uk Kim /* Use the remainder of the line for the #define */
7984c52cad2SJung-uk Kim
7994c52cad2SJung-uk Kim Token2 = *Next;
8004c52cad2SJung-uk Kim if (Token2)
8014c52cad2SJung-uk Kim {
8024c52cad2SJung-uk Kim while ((*Token2 == ' ') || (*Token2 == '\t'))
8034c52cad2SJung-uk Kim {
8044c52cad2SJung-uk Kim Token2++;
8054c52cad2SJung-uk Kim }
806f8146b88SJung-uk Kim
8074c52cad2SJung-uk Kim End = Token2;
8084c52cad2SJung-uk Kim while (*End != '\n')
8094c52cad2SJung-uk Kim {
8104c52cad2SJung-uk Kim End++;
8114c52cad2SJung-uk Kim }
812f8146b88SJung-uk Kim
8134c52cad2SJung-uk Kim *End = 0;
8144c52cad2SJung-uk Kim }
8154c52cad2SJung-uk Kim else
8164c52cad2SJung-uk Kim {
8174c52cad2SJung-uk Kim Token2 = "";
8184c52cad2SJung-uk Kim }
8194c52cad2SJung-uk Kim #if 0
8204c52cad2SJung-uk Kim Token2 = PrGetNextToken (NULL, "\n", /*PR_TOKEN_SEPARATORS,*/ Next);
8214c52cad2SJung-uk Kim if (!Token2)
8224c52cad2SJung-uk Kim {
8234c52cad2SJung-uk Kim Token2 = "";
8244c52cad2SJung-uk Kim }
8254c52cad2SJung-uk Kim #endif
826a371a5fdSJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
8274c52cad2SJung-uk Kim "New #define: %s->%s\n",
8286f1f1a63SJung-uk Kim AslGbl_LogicalLineNumber, Token, Token2);
8294c52cad2SJung-uk Kim
8304c52cad2SJung-uk Kim PrAddDefine (Token, Token2, FALSE);
8314c52cad2SJung-uk Kim }
8324c52cad2SJung-uk Kim break;
8334c52cad2SJung-uk Kim
8344c52cad2SJung-uk Kim case PR_DIRECTIVE_ERROR:
835a9d8d09cSJung-uk Kim
8364c52cad2SJung-uk Kim /* Note: No macro expansion */
8374c52cad2SJung-uk Kim
8384c52cad2SJung-uk Kim PrError (ASL_ERROR, ASL_MSG_ERROR_DIRECTIVE,
8394c52cad2SJung-uk Kim THIS_TOKEN_OFFSET (Token));
8404c52cad2SJung-uk Kim
8416f1f1a63SJung-uk Kim AslGbl_SourceLine = 0;
8426f1f1a63SJung-uk Kim AslGbl_NextError = AslGbl_ErrorLog;
8438d744e47SJung-uk Kim CmCleanupAndExit ();
8448d744e47SJung-uk Kim exit(1);
8454c52cad2SJung-uk Kim
8464c52cad2SJung-uk Kim case PR_DIRECTIVE_INCLUDE:
847a9d8d09cSJung-uk Kim
8484c52cad2SJung-uk Kim Token = PrGetNextToken (NULL, " \"<>", Next);
8494c52cad2SJung-uk Kim if (!Token)
8504c52cad2SJung-uk Kim {
8514c52cad2SJung-uk Kim goto SyntaxError;
8524c52cad2SJung-uk Kim }
8534c52cad2SJung-uk Kim
854a371a5fdSJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
8556f1f1a63SJung-uk Kim "Start #include file \"%s\"\n", AslGbl_CurrentLineNumber,
856a009b7dcSJung-uk Kim Token);
8574c52cad2SJung-uk Kim
858a371a5fdSJung-uk Kim PrDoIncludeFile (Token);
859a371a5fdSJung-uk Kim break;
860a371a5fdSJung-uk Kim
861a371a5fdSJung-uk Kim case PR_DIRECTIVE_INCLUDEBUFFER:
862a371a5fdSJung-uk Kim
863a371a5fdSJung-uk Kim Token = PrGetNextToken (NULL, " \"<>", Next);
864a371a5fdSJung-uk Kim if (!Token)
865a371a5fdSJung-uk Kim {
866a371a5fdSJung-uk Kim goto SyntaxError;
867a371a5fdSJung-uk Kim }
868a371a5fdSJung-uk Kim
869a371a5fdSJung-uk Kim Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
870a371a5fdSJung-uk Kim if (!Token2)
871a371a5fdSJung-uk Kim {
872a371a5fdSJung-uk Kim goto SyntaxError;
873a371a5fdSJung-uk Kim }
874a371a5fdSJung-uk Kim
875a371a5fdSJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
876a371a5fdSJung-uk Kim "Start #includebuffer input from file \"%s\", buffer name %s\n",
8776f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, Token, Token2);
878a371a5fdSJung-uk Kim
879a371a5fdSJung-uk Kim PrDoIncludeBuffer (Token, Token2);
8804c52cad2SJung-uk Kim break;
8814c52cad2SJung-uk Kim
882eef1b955SJung-uk Kim case PR_DIRECTIVE_LINE:
883a9d8d09cSJung-uk Kim
8846f1f1a63SJung-uk Kim TokenOffset = Token - AslGbl_MainTokenBuffer;
885eef1b955SJung-uk Kim
886eef1b955SJung-uk Kim Status = PrResolveIntegerExpression (
8876f1f1a63SJung-uk Kim &AslGbl_CurrentLineBuffer[TokenOffset-1], &Value);
888eef1b955SJung-uk Kim if (ACPI_FAILURE (Status))
889eef1b955SJung-uk Kim {
890eef1b955SJung-uk Kim return;
891eef1b955SJung-uk Kim }
892eef1b955SJung-uk Kim
893a371a5fdSJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
8946f1f1a63SJung-uk Kim "User #line invocation %s\n", AslGbl_CurrentLineNumber,
895eef1b955SJung-uk Kim Token);
896eef1b955SJung-uk Kim
8976f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber = (UINT32) Value;
898eef1b955SJung-uk Kim
899eef1b955SJung-uk Kim /* Emit #line into the preprocessor file */
900eef1b955SJung-uk Kim
901eef1b955SJung-uk Kim FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n",
9026f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_Files[ASL_FILE_INPUT].Filename);
903eef1b955SJung-uk Kim break;
904eef1b955SJung-uk Kim
9054c52cad2SJung-uk Kim case PR_DIRECTIVE_PRAGMA:
9064c52cad2SJung-uk Kim
907a9d8d09cSJung-uk Kim if (!strcmp (Token, "disable"))
9084c52cad2SJung-uk Kim {
909a9d8d09cSJung-uk Kim Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
910a9d8d09cSJung-uk Kim if (!Token)
911a9d8d09cSJung-uk Kim {
912a9d8d09cSJung-uk Kim goto SyntaxError;
9134c52cad2SJung-uk Kim }
9144c52cad2SJung-uk Kim
9156f1f1a63SJung-uk Kim TokenOffset = Token - AslGbl_MainTokenBuffer;
9166f1f1a63SJung-uk Kim AslDisableException (&AslGbl_CurrentLineBuffer[TokenOffset]);
917a9d8d09cSJung-uk Kim }
918a9d8d09cSJung-uk Kim else if (!strcmp (Token, "message"))
919a9d8d09cSJung-uk Kim {
9204c52cad2SJung-uk Kim Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
9214c52cad2SJung-uk Kim if (!Token)
9224c52cad2SJung-uk Kim {
9234c52cad2SJung-uk Kim goto SyntaxError;
9244c52cad2SJung-uk Kim }
9254c52cad2SJung-uk Kim
9266f1f1a63SJung-uk Kim TokenOffset = Token - AslGbl_MainTokenBuffer;
9276f1f1a63SJung-uk Kim AcpiOsPrintf ("%s\n", &AslGbl_CurrentLineBuffer[TokenOffset]);
928a9d8d09cSJung-uk Kim }
929a9d8d09cSJung-uk Kim else
930a9d8d09cSJung-uk Kim {
931a9d8d09cSJung-uk Kim PrError (ASL_ERROR, ASL_MSG_UNKNOWN_PRAGMA,
932a9d8d09cSJung-uk Kim THIS_TOKEN_OFFSET (Token));
933a9d8d09cSJung-uk Kim return;
934a9d8d09cSJung-uk Kim }
935a9d8d09cSJung-uk Kim
9364c52cad2SJung-uk Kim break;
9374c52cad2SJung-uk Kim
9384c52cad2SJung-uk Kim case PR_DIRECTIVE_UNDEF:
939a9d8d09cSJung-uk Kim
940a371a5fdSJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
9416f1f1a63SJung-uk Kim "#undef: %s\n", AslGbl_CurrentLineNumber, Token);
9424c52cad2SJung-uk Kim
9434c52cad2SJung-uk Kim PrRemoveDefine (Token);
9444c52cad2SJung-uk Kim break;
9454c52cad2SJung-uk Kim
9464c52cad2SJung-uk Kim case PR_DIRECTIVE_WARNING:
947a9d8d09cSJung-uk Kim
9488d744e47SJung-uk Kim PrError (ASL_WARNING, ASL_MSG_WARNING_DIRECTIVE,
9494c52cad2SJung-uk Kim THIS_TOKEN_OFFSET (Token));
950fe0f0bbbSJung-uk Kim
9516f1f1a63SJung-uk Kim AslGbl_SourceLine = 0;
9526f1f1a63SJung-uk Kim AslGbl_NextError = AslGbl_ErrorLog;
9534c52cad2SJung-uk Kim break;
9544c52cad2SJung-uk Kim
9554c52cad2SJung-uk Kim default:
956a9d8d09cSJung-uk Kim
9574c52cad2SJung-uk Kim /* Should never get here */
958a371a5fdSJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
9594c52cad2SJung-uk Kim "Unrecognized directive: %u\n",
9606f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, Directive);
9614c52cad2SJung-uk Kim break;
9624c52cad2SJung-uk Kim }
9634c52cad2SJung-uk Kim
9644c52cad2SJung-uk Kim return;
9654c52cad2SJung-uk Kim
9664c52cad2SJung-uk Kim SyntaxError:
9674c52cad2SJung-uk Kim
9684c52cad2SJung-uk Kim PrError (ASL_ERROR, ASL_MSG_DIRECTIVE_SYNTAX,
9694c52cad2SJung-uk Kim THIS_TOKEN_OFFSET (DirectiveToken));
9704c52cad2SJung-uk Kim return;
9714c52cad2SJung-uk Kim }
9724c52cad2SJung-uk Kim
9734c52cad2SJung-uk Kim
9744c52cad2SJung-uk Kim /*******************************************************************************
9754c52cad2SJung-uk Kim *
9765ef50723SJung-uk Kim * FUNCTION: PrGetNextLine, PrGetNextLineInit
9775ef50723SJung-uk Kim *
9785ef50723SJung-uk Kim * PARAMETERS: Handle - Open file handle for the source file
9795ef50723SJung-uk Kim *
9805ef50723SJung-uk Kim * RETURN: Status of the GetLine operation:
9815ef50723SJung-uk Kim * AE_OK - Normal line, OK status
982f8146b88SJung-uk Kim * ASL_IGNORE_LINE - Line is blank or part of a multi-line
983f8146b88SJung-uk Kim * comment
9845ef50723SJung-uk Kim * ASL_EOF - End-of-file reached
9855ef50723SJung-uk Kim *
9865ef50723SJung-uk Kim * DESCRIPTION: Get the next text line from the input file. Does not strip
9875ef50723SJung-uk Kim * comments.
9885ef50723SJung-uk Kim *
9895ef50723SJung-uk Kim ******************************************************************************/
9905ef50723SJung-uk Kim
9915ef50723SJung-uk Kim #define PR_NORMAL_TEXT 0
992fe0f0bbbSJung-uk Kim #define PR_MULTI_LINE_COMMENT 1
993fe0f0bbbSJung-uk Kim #define PR_SINGLE_LINE_COMMENT 2
994fe0f0bbbSJung-uk Kim #define PR_QUOTED_STRING 3
9955ef50723SJung-uk Kim
9965ef50723SJung-uk Kim static UINT8 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
9975ef50723SJung-uk Kim
9985ef50723SJung-uk Kim static void
PrGetNextLineInit(void)9995ef50723SJung-uk Kim PrGetNextLineInit (
10005ef50723SJung-uk Kim void)
10015ef50723SJung-uk Kim {
10025ef50723SJung-uk Kim AcpiGbl_LineScanState = 0;
10035ef50723SJung-uk Kim }
10045ef50723SJung-uk Kim
10055ef50723SJung-uk Kim static UINT32
PrGetNextLine(FILE * Handle)10065ef50723SJung-uk Kim PrGetNextLine (
10075ef50723SJung-uk Kim FILE *Handle)
10085ef50723SJung-uk Kim {
10095ef50723SJung-uk Kim UINT32 i;
10105ef50723SJung-uk Kim int c = 0;
10115ef50723SJung-uk Kim int PreviousChar;
10125ef50723SJung-uk Kim
10135ef50723SJung-uk Kim
10145ef50723SJung-uk Kim /* Always clear the global line buffer */
10155ef50723SJung-uk Kim
10166f1f1a63SJung-uk Kim memset (AslGbl_CurrentLineBuffer, 0, AslGbl_LineBufferSize);
10175ef50723SJung-uk Kim for (i = 0; ;)
10185ef50723SJung-uk Kim {
10195ef50723SJung-uk Kim /*
10205ef50723SJung-uk Kim * If line is too long, expand the line buffers. Also increases
10216f1f1a63SJung-uk Kim * AslGbl_LineBufferSize.
10225ef50723SJung-uk Kim */
10236f1f1a63SJung-uk Kim if (i >= AslGbl_LineBufferSize)
10245ef50723SJung-uk Kim {
10255ef50723SJung-uk Kim UtExpandLineBuffers ();
10265ef50723SJung-uk Kim }
10275ef50723SJung-uk Kim
10285ef50723SJung-uk Kim PreviousChar = c;
10295ef50723SJung-uk Kim c = getc (Handle);
10305ef50723SJung-uk Kim if (c == EOF)
10315ef50723SJung-uk Kim {
1032f8146b88SJung-uk Kim /*
1033f8146b88SJung-uk Kim * On EOF: If there is anything in the line buffer, terminate
1034f8146b88SJung-uk Kim * it with a newline, and catch the EOF on the next call
1035f8146b88SJung-uk Kim * to this function.
1036f8146b88SJung-uk Kim */
1037f8146b88SJung-uk Kim if (i > 0)
1038f8146b88SJung-uk Kim {
10396f1f1a63SJung-uk Kim AslGbl_CurrentLineBuffer[i] = '\n';
1040f8146b88SJung-uk Kim return (AE_OK);
1041f8146b88SJung-uk Kim }
1042f8146b88SJung-uk Kim
10435ef50723SJung-uk Kim return (ASL_EOF);
10445ef50723SJung-uk Kim }
10455ef50723SJung-uk Kim
1046fe0f0bbbSJung-uk Kim /* Update state machine as necessary */
10475ef50723SJung-uk Kim
1048fe0f0bbbSJung-uk Kim switch (AcpiGbl_LineScanState)
10495ef50723SJung-uk Kim {
1050fe0f0bbbSJung-uk Kim case PR_NORMAL_TEXT:
1051fe0f0bbbSJung-uk Kim
1052fe0f0bbbSJung-uk Kim /* Check for multi-line comment start */
1053fe0f0bbbSJung-uk Kim
1054fe0f0bbbSJung-uk Kim if ((PreviousChar == '/') && (c == '*'))
1055fe0f0bbbSJung-uk Kim {
1056fe0f0bbbSJung-uk Kim AcpiGbl_LineScanState = PR_MULTI_LINE_COMMENT;
10575ef50723SJung-uk Kim }
10585ef50723SJung-uk Kim
1059fe0f0bbbSJung-uk Kim /* Check for single-line comment start */
10605ef50723SJung-uk Kim
1061fe0f0bbbSJung-uk Kim else if ((PreviousChar == '/') && (c == '/'))
1062fe0f0bbbSJung-uk Kim {
1063fe0f0bbbSJung-uk Kim AcpiGbl_LineScanState = PR_SINGLE_LINE_COMMENT;
1064fe0f0bbbSJung-uk Kim }
1065fe0f0bbbSJung-uk Kim
1066fe0f0bbbSJung-uk Kim /* Check for quoted string start */
1067fe0f0bbbSJung-uk Kim
1068fe0f0bbbSJung-uk Kim else if (PreviousChar == '"')
1069fe0f0bbbSJung-uk Kim {
1070fe0f0bbbSJung-uk Kim AcpiGbl_LineScanState = PR_QUOTED_STRING;
1071fe0f0bbbSJung-uk Kim }
1072fe0f0bbbSJung-uk Kim break;
1073fe0f0bbbSJung-uk Kim
1074fe0f0bbbSJung-uk Kim case PR_QUOTED_STRING:
1075fe0f0bbbSJung-uk Kim
1076fe0f0bbbSJung-uk Kim if (PreviousChar == '"')
10775ef50723SJung-uk Kim {
10785ef50723SJung-uk Kim AcpiGbl_LineScanState = PR_NORMAL_TEXT;
10795ef50723SJung-uk Kim }
1080fe0f0bbbSJung-uk Kim break;
1081fe0f0bbbSJung-uk Kim
1082fe0f0bbbSJung-uk Kim case PR_MULTI_LINE_COMMENT:
1083fe0f0bbbSJung-uk Kim
1084fe0f0bbbSJung-uk Kim /* Check for multi-line comment end */
1085fe0f0bbbSJung-uk Kim
1086fe0f0bbbSJung-uk Kim if ((PreviousChar == '*') && (c == '/'))
1087fe0f0bbbSJung-uk Kim {
1088fe0f0bbbSJung-uk Kim AcpiGbl_LineScanState = PR_NORMAL_TEXT;
1089fe0f0bbbSJung-uk Kim }
1090fe0f0bbbSJung-uk Kim break;
1091fe0f0bbbSJung-uk Kim
1092fe0f0bbbSJung-uk Kim case PR_SINGLE_LINE_COMMENT: /* Just ignore text until EOL */
1093fe0f0bbbSJung-uk Kim default:
1094fe0f0bbbSJung-uk Kim break;
1095fe0f0bbbSJung-uk Kim }
10965ef50723SJung-uk Kim
10975ef50723SJung-uk Kim /* Always copy the character into line buffer */
10985ef50723SJung-uk Kim
10996f1f1a63SJung-uk Kim AslGbl_CurrentLineBuffer[i] = (char) c;
11005ef50723SJung-uk Kim i++;
11015ef50723SJung-uk Kim
11025ef50723SJung-uk Kim /* Always exit on end-of-line */
11035ef50723SJung-uk Kim
11045ef50723SJung-uk Kim if (c == '\n')
11055ef50723SJung-uk Kim {
11065ef50723SJung-uk Kim /* Handle multi-line comments */
11075ef50723SJung-uk Kim
1108fe0f0bbbSJung-uk Kim if (AcpiGbl_LineScanState == PR_MULTI_LINE_COMMENT)
11095ef50723SJung-uk Kim {
1110f8146b88SJung-uk Kim return (ASL_IGNORE_LINE);
11115ef50723SJung-uk Kim }
1112fe0f0bbbSJung-uk Kim
1113fe0f0bbbSJung-uk Kim /* End of single-line comment */
1114fe0f0bbbSJung-uk Kim
1115fe0f0bbbSJung-uk Kim if (AcpiGbl_LineScanState == PR_SINGLE_LINE_COMMENT)
1116fe0f0bbbSJung-uk Kim {
1117fe0f0bbbSJung-uk Kim AcpiGbl_LineScanState = PR_NORMAL_TEXT;
1118fe0f0bbbSJung-uk Kim return (AE_OK);
1119fe0f0bbbSJung-uk Kim }
1120fe0f0bbbSJung-uk Kim
1121fe0f0bbbSJung-uk Kim /* Blank line */
1122fe0f0bbbSJung-uk Kim
11235ef50723SJung-uk Kim if (i == 1)
11245ef50723SJung-uk Kim {
1125f8146b88SJung-uk Kim return (ASL_IGNORE_LINE);
11265ef50723SJung-uk Kim }
1127f8146b88SJung-uk Kim
11285ef50723SJung-uk Kim return (AE_OK);
11295ef50723SJung-uk Kim }
11305ef50723SJung-uk Kim }
11315ef50723SJung-uk Kim }
11325ef50723SJung-uk Kim
11335ef50723SJung-uk Kim
11345ef50723SJung-uk Kim /*******************************************************************************
11355ef50723SJung-uk Kim *
11364c52cad2SJung-uk Kim * FUNCTION: PrMatchDirective
11374c52cad2SJung-uk Kim *
11384c52cad2SJung-uk Kim * PARAMETERS: Directive - Pointer to directive name token
11394c52cad2SJung-uk Kim *
11404c52cad2SJung-uk Kim * RETURN: Index into command array, -1 if not found
11414c52cad2SJung-uk Kim *
11424c52cad2SJung-uk Kim * DESCRIPTION: Lookup the incoming directive in the known directives table.
11434c52cad2SJung-uk Kim *
11444c52cad2SJung-uk Kim ******************************************************************************/
11454c52cad2SJung-uk Kim
11464c52cad2SJung-uk Kim static int
PrMatchDirective(char * Directive)11474c52cad2SJung-uk Kim PrMatchDirective (
11484c52cad2SJung-uk Kim char *Directive)
11494c52cad2SJung-uk Kim {
11504c52cad2SJung-uk Kim int i;
11514c52cad2SJung-uk Kim
11524c52cad2SJung-uk Kim
11534c52cad2SJung-uk Kim if (!Directive || Directive[0] == 0)
11544c52cad2SJung-uk Kim {
11554c52cad2SJung-uk Kim return (ASL_DIRECTIVE_NOT_FOUND);
11564c52cad2SJung-uk Kim }
11574c52cad2SJung-uk Kim
11586f1f1a63SJung-uk Kim for (i = 0; AslGbl_DirectiveInfo[i].Name; i++)
11594c52cad2SJung-uk Kim {
11606f1f1a63SJung-uk Kim if (!strcmp (AslGbl_DirectiveInfo[i].Name, Directive))
11614c52cad2SJung-uk Kim {
11624c52cad2SJung-uk Kim return (i);
11634c52cad2SJung-uk Kim }
11644c52cad2SJung-uk Kim }
11654c52cad2SJung-uk Kim
11664c52cad2SJung-uk Kim return (ASL_DIRECTIVE_NOT_FOUND); /* Command not recognized */
11674c52cad2SJung-uk Kim }
11688d744e47SJung-uk Kim
11698d744e47SJung-uk Kim
11708d744e47SJung-uk Kim /*******************************************************************************
11718d744e47SJung-uk Kim *
11728d744e47SJung-uk Kim * FUNCTION: PrPushDirective
11738d744e47SJung-uk Kim *
11748d744e47SJung-uk Kim * PARAMETERS: Directive - Encoded directive ID
11758d744e47SJung-uk Kim * Argument - String containing argument to the
11768d744e47SJung-uk Kim * directive
11778d744e47SJung-uk Kim *
11788d744e47SJung-uk Kim * RETURN: None
11798d744e47SJung-uk Kim *
11808d744e47SJung-uk Kim * DESCRIPTION: Push an item onto the directive stack. Used for processing
11818d744e47SJung-uk Kim * nested #if/#else type conditional compilation directives.
11828d744e47SJung-uk Kim * Specifically: Used on detection of #if/#ifdef/#ifndef to open
11838d744e47SJung-uk Kim * a block.
11848d744e47SJung-uk Kim *
11858d744e47SJung-uk Kim ******************************************************************************/
11868d744e47SJung-uk Kim
11878d744e47SJung-uk Kim static void
PrPushDirective(int Directive,char * Argument)11888d744e47SJung-uk Kim PrPushDirective (
11898d744e47SJung-uk Kim int Directive,
11908d744e47SJung-uk Kim char *Argument)
11918d744e47SJung-uk Kim {
11928d744e47SJung-uk Kim DIRECTIVE_INFO *Info;
11938d744e47SJung-uk Kim
11948d744e47SJung-uk Kim
11958d744e47SJung-uk Kim /* Allocate and populate a stack info item */
11968d744e47SJung-uk Kim
11976f1f1a63SJung-uk Kim Info = ACPI_CAST_PTR (DIRECTIVE_INFO,
11986f1f1a63SJung-uk Kim UtLocalCacheCalloc (sizeof (DIRECTIVE_INFO)));
11998d744e47SJung-uk Kim
12006f1f1a63SJung-uk Kim Info->Next = AslGbl_DirectiveStack;
12018d744e47SJung-uk Kim Info->Directive = Directive;
12026f1f1a63SJung-uk Kim Info->IgnoringThisCodeBlock = AslGbl_IgnoringThisCodeBlock;
1203f1db5ef7SJung-uk Kim AcpiUtSafeStrncpy (Info->Argument, Argument, MAX_ARGUMENT_LENGTH);
12048d744e47SJung-uk Kim
12058d744e47SJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT,
12068d744e47SJung-uk Kim "Pr(%.4u) - [%u %s] %*s Pushed [#%s %s]: IgnoreFlag = %s\n",
12076f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_IfDepth,
12086f1f1a63SJung-uk Kim AslGbl_IgnoringThisCodeBlock ? "I" : "E",
12096f1f1a63SJung-uk Kim AslGbl_IfDepth * 4, " ",
12106f1f1a63SJung-uk Kim AslGbl_DirectiveInfo[Directive].Name,
12116f1f1a63SJung-uk Kim Argument, AslGbl_IgnoringThisCodeBlock ? "TRUE" : "FALSE");
12128d744e47SJung-uk Kim
12138d744e47SJung-uk Kim /* Push new item */
12148d744e47SJung-uk Kim
12156f1f1a63SJung-uk Kim AslGbl_DirectiveStack = Info;
12166f1f1a63SJung-uk Kim AslGbl_IfDepth++;
12178d744e47SJung-uk Kim }
12188d744e47SJung-uk Kim
12198d744e47SJung-uk Kim
12208d744e47SJung-uk Kim /*******************************************************************************
12218d744e47SJung-uk Kim *
12228d744e47SJung-uk Kim * FUNCTION: PrPopDirective
12238d744e47SJung-uk Kim *
12248d744e47SJung-uk Kim * PARAMETERS: None
12258d744e47SJung-uk Kim *
12268d744e47SJung-uk Kim * RETURN: Status. Error if the stack is empty.
12278d744e47SJung-uk Kim *
12288d744e47SJung-uk Kim * DESCRIPTION: Pop an item off the directive stack. Used for processing
12298d744e47SJung-uk Kim * nested #if/#else type conditional compilation directives.
12308d744e47SJung-uk Kim * Specifically: Used on detection of #elif and #endif to remove
12318d744e47SJung-uk Kim * the original #if/#ifdef/#ifndef from the stack and close
12328d744e47SJung-uk Kim * the block.
12338d744e47SJung-uk Kim *
12348d744e47SJung-uk Kim ******************************************************************************/
12358d744e47SJung-uk Kim
12368d744e47SJung-uk Kim static ACPI_STATUS
PrPopDirective(void)12378d744e47SJung-uk Kim PrPopDirective (
12388d744e47SJung-uk Kim void)
12398d744e47SJung-uk Kim {
12408d744e47SJung-uk Kim DIRECTIVE_INFO *Info;
12418d744e47SJung-uk Kim
12428d744e47SJung-uk Kim
12438d744e47SJung-uk Kim /* Check for empty stack */
12448d744e47SJung-uk Kim
12456f1f1a63SJung-uk Kim Info = AslGbl_DirectiveStack;
12468d744e47SJung-uk Kim if (!Info)
12478d744e47SJung-uk Kim {
12488d744e47SJung-uk Kim return (AE_ERROR);
12498d744e47SJung-uk Kim }
12508d744e47SJung-uk Kim
12518d744e47SJung-uk Kim /* Pop one item, keep globals up-to-date */
12528d744e47SJung-uk Kim
12536f1f1a63SJung-uk Kim AslGbl_IfDepth--;
12546f1f1a63SJung-uk Kim AslGbl_IgnoringThisCodeBlock = Info->IgnoringThisCodeBlock;
12556f1f1a63SJung-uk Kim AslGbl_DirectiveStack = Info->Next;
12568d744e47SJung-uk Kim
12578d744e47SJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT,
12588d744e47SJung-uk Kim "Pr(%.4u) - [%u %s] %*s Popped [#%s %s]: IgnoreFlag now = %s\n",
12596f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_IfDepth,
12606f1f1a63SJung-uk Kim AslGbl_IgnoringThisCodeBlock ? "I" : "E",
12616f1f1a63SJung-uk Kim AslGbl_IfDepth * 4, " ",
12626f1f1a63SJung-uk Kim AslGbl_DirectiveInfo[Info->Directive].Name,
12636f1f1a63SJung-uk Kim Info->Argument, AslGbl_IgnoringThisCodeBlock ? "TRUE" : "FALSE");
12648d744e47SJung-uk Kim
12658d744e47SJung-uk Kim return (AE_OK);
12668d744e47SJung-uk Kim }
12678d744e47SJung-uk Kim
12688d744e47SJung-uk Kim
12698d744e47SJung-uk Kim /*******************************************************************************
12708d744e47SJung-uk Kim *
12718d744e47SJung-uk Kim * FUNCTION: PrDbgPrint
12728d744e47SJung-uk Kim *
12738d744e47SJung-uk Kim * PARAMETERS: Action - Action being performed
12748d744e47SJung-uk Kim * DirectiveName - Directive being processed
12758d744e47SJung-uk Kim *
12768d744e47SJung-uk Kim * RETURN: None
12778d744e47SJung-uk Kim *
12788d744e47SJung-uk Kim * DESCRIPTION: Special debug print for directive processing.
12798d744e47SJung-uk Kim *
12808d744e47SJung-uk Kim ******************************************************************************/
12818d744e47SJung-uk Kim
12828d744e47SJung-uk Kim static void
PrDbgPrint(char * Action,char * DirectiveName)12838d744e47SJung-uk Kim PrDbgPrint (
12848d744e47SJung-uk Kim char *Action,
12858d744e47SJung-uk Kim char *DirectiveName)
12868d744e47SJung-uk Kim {
12878d744e47SJung-uk Kim
12888d744e47SJung-uk Kim DbgPrint (ASL_DEBUG_OUTPUT, "Pr(%.4u) - [%u %s] "
1289a371a5fdSJung-uk Kim "%*s %s #%s, IfDepth %u\n",
12906f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_IfDepth,
12916f1f1a63SJung-uk Kim AslGbl_IgnoringThisCodeBlock ? "I" : "E",
12926f1f1a63SJung-uk Kim AslGbl_IfDepth * 4, " ",
12936f1f1a63SJung-uk Kim Action, DirectiveName, AslGbl_IfDepth);
12948d744e47SJung-uk Kim }
1295a371a5fdSJung-uk Kim
1296a371a5fdSJung-uk Kim
1297a371a5fdSJung-uk Kim /*******************************************************************************
1298a371a5fdSJung-uk Kim *
1299a371a5fdSJung-uk Kim * FUNCTION: PrDoIncludeFile
1300a371a5fdSJung-uk Kim *
1301a371a5fdSJung-uk Kim * PARAMETERS: Pathname - Name of the input file
1302a371a5fdSJung-uk Kim *
1303a371a5fdSJung-uk Kim * RETURN: None.
1304a371a5fdSJung-uk Kim *
1305a371a5fdSJung-uk Kim * DESCRIPTION: Open an include file, from #include.
1306a371a5fdSJung-uk Kim *
1307a371a5fdSJung-uk Kim ******************************************************************************/
1308a371a5fdSJung-uk Kim
1309a371a5fdSJung-uk Kim static void
PrDoIncludeFile(char * Pathname)1310a371a5fdSJung-uk Kim PrDoIncludeFile (
1311a371a5fdSJung-uk Kim char *Pathname)
1312a371a5fdSJung-uk Kim {
1313a371a5fdSJung-uk Kim char *FullPathname;
1314a371a5fdSJung-uk Kim
1315a371a5fdSJung-uk Kim
1316a371a5fdSJung-uk Kim (void) PrOpenIncludeFile (Pathname, "r", &FullPathname);
1317a371a5fdSJung-uk Kim }
1318a371a5fdSJung-uk Kim
1319a371a5fdSJung-uk Kim
1320a371a5fdSJung-uk Kim /*******************************************************************************
1321a371a5fdSJung-uk Kim *
1322a371a5fdSJung-uk Kim * FUNCTION: PrDoIncludeBuffer
1323a371a5fdSJung-uk Kim *
1324a371a5fdSJung-uk Kim * PARAMETERS: Pathname - Name of the input binary file
1325a371a5fdSJung-uk Kim * BufferName - ACPI namepath of the buffer
1326a371a5fdSJung-uk Kim *
1327a371a5fdSJung-uk Kim * RETURN: None.
1328a371a5fdSJung-uk Kim *
1329a371a5fdSJung-uk Kim * DESCRIPTION: Create an ACPI buffer object from a binary file. The contents
1330a371a5fdSJung-uk Kim * of the file are emitted into the buffer object as ascii
1331a371a5fdSJung-uk Kim * hex data. From #includebuffer.
1332a371a5fdSJung-uk Kim *
1333a371a5fdSJung-uk Kim ******************************************************************************/
1334a371a5fdSJung-uk Kim
1335a371a5fdSJung-uk Kim static void
PrDoIncludeBuffer(char * Pathname,char * BufferName)1336a371a5fdSJung-uk Kim PrDoIncludeBuffer (
1337a371a5fdSJung-uk Kim char *Pathname,
1338a371a5fdSJung-uk Kim char *BufferName)
1339a371a5fdSJung-uk Kim {
1340a371a5fdSJung-uk Kim char *FullPathname;
1341a371a5fdSJung-uk Kim FILE *BinaryBufferFile;
1342a371a5fdSJung-uk Kim UINT32 i = 0;
1343a371a5fdSJung-uk Kim UINT8 c;
1344a371a5fdSJung-uk Kim
1345a371a5fdSJung-uk Kim
1346a371a5fdSJung-uk Kim BinaryBufferFile = PrOpenIncludeFile (Pathname, "rb", &FullPathname);
1347a371a5fdSJung-uk Kim if (!BinaryBufferFile)
1348a371a5fdSJung-uk Kim {
1349a371a5fdSJung-uk Kim return;
1350a371a5fdSJung-uk Kim }
1351a371a5fdSJung-uk Kim
1352a371a5fdSJung-uk Kim /* Emit "Name (XXXX, Buffer() {" header */
1353a371a5fdSJung-uk Kim
1354a371a5fdSJung-uk Kim FlPrintFile (ASL_FILE_PREPROCESSOR, "Name (%s, Buffer()\n{", BufferName);
1355a371a5fdSJung-uk Kim
1356a371a5fdSJung-uk Kim /* Dump the entire file in ascii hex format */
1357a371a5fdSJung-uk Kim
1358a371a5fdSJung-uk Kim while (fread (&c, 1, 1, BinaryBufferFile))
1359a371a5fdSJung-uk Kim {
1360a371a5fdSJung-uk Kim if (!(i % 8))
1361a371a5fdSJung-uk Kim {
1362a009b7dcSJung-uk Kim FlPrintFile (ASL_FILE_PREPROCESSOR, "\n ");
1363a371a5fdSJung-uk Kim }
1364a371a5fdSJung-uk Kim
1365a371a5fdSJung-uk Kim FlPrintFile (ASL_FILE_PREPROCESSOR, " 0x%2.2X,", c);
1366a371a5fdSJung-uk Kim i++;
1367a371a5fdSJung-uk Kim }
1368a371a5fdSJung-uk Kim
1369a371a5fdSJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
1370a371a5fdSJung-uk Kim "#includebuffer: read %u bytes from %s\n",
13716f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, i, FullPathname);
1372a371a5fdSJung-uk Kim
1373a371a5fdSJung-uk Kim /* Close the Name() operator */
1374a371a5fdSJung-uk Kim
1375a009b7dcSJung-uk Kim FlPrintFile (ASL_FILE_PREPROCESSOR, "\n})\n");
1376a371a5fdSJung-uk Kim fclose (BinaryBufferFile);
1377a371a5fdSJung-uk Kim }
1378