xref: /freebsd/sys/contrib/dev/acpica/compiler/prscan.c (revision eef1b955be5a82b4afee3810ab7995127a5133fe)
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 
74c52cad2SJung-uk Kim /*
84c52cad2SJung-uk Kim  * Copyright (C) 2000 - 2012, Intel Corp.
94c52cad2SJung-uk Kim  * All rights reserved.
104c52cad2SJung-uk Kim  *
114c52cad2SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
124c52cad2SJung-uk Kim  * modification, are permitted provided that the following conditions
134c52cad2SJung-uk Kim  * are met:
144c52cad2SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
154c52cad2SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
164c52cad2SJung-uk Kim  *    without modification.
174c52cad2SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
184c52cad2SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
194c52cad2SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
204c52cad2SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
214c52cad2SJung-uk Kim  *    binary redistribution.
224c52cad2SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
234c52cad2SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
244c52cad2SJung-uk Kim  *    from this software without specific prior written permission.
254c52cad2SJung-uk Kim  *
264c52cad2SJung-uk Kim  * Alternatively, this software may be distributed under the terms of the
274c52cad2SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
284c52cad2SJung-uk Kim  * Software Foundation.
294c52cad2SJung-uk Kim  *
304c52cad2SJung-uk Kim  * NO WARRANTY
314c52cad2SJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
324c52cad2SJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
334c52cad2SJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
344c52cad2SJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
354c52cad2SJung-uk Kim  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
364c52cad2SJung-uk Kim  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
374c52cad2SJung-uk Kim  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
384c52cad2SJung-uk Kim  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
394c52cad2SJung-uk Kim  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
404c52cad2SJung-uk Kim  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
414c52cad2SJung-uk Kim  * POSSIBILITY OF SUCH DAMAGES.
424c52cad2SJung-uk Kim  */
434c52cad2SJung-uk Kim 
444c52cad2SJung-uk Kim #define _DECLARE_PR_GLOBALS
454c52cad2SJung-uk Kim 
464c52cad2SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
474c52cad2SJung-uk Kim #include <contrib/dev/acpica/compiler/dtcompiler.h>
484c52cad2SJung-uk Kim 
494c52cad2SJung-uk Kim /*
504c52cad2SJung-uk Kim  * TBDs:
514c52cad2SJung-uk Kim  *
524c52cad2SJung-uk Kim  * No nested macros, maybe never
534c52cad2SJung-uk Kim  * Implement ASL "Include" as well as "#include" here?
544c52cad2SJung-uk Kim  */
554c52cad2SJung-uk Kim #define _COMPONENT          ASL_PREPROCESSOR
564c52cad2SJung-uk Kim         ACPI_MODULE_NAME    ("prscan")
574c52cad2SJung-uk Kim 
584c52cad2SJung-uk Kim 
594c52cad2SJung-uk Kim /* Local prototypes */
604c52cad2SJung-uk Kim 
614c52cad2SJung-uk Kim static void
624c52cad2SJung-uk Kim PrPreprocessInputFile (
634c52cad2SJung-uk Kim     void);
644c52cad2SJung-uk Kim 
654c52cad2SJung-uk Kim static void
664c52cad2SJung-uk Kim PrDoDirective (
674c52cad2SJung-uk Kim     char                    *DirectiveToken,
684c52cad2SJung-uk Kim     char                    **Next,
694c52cad2SJung-uk Kim     BOOLEAN                 *IgnoringThisCodeBlock);
704c52cad2SJung-uk Kim 
714c52cad2SJung-uk Kim static int
724c52cad2SJung-uk Kim PrMatchDirective (
734c52cad2SJung-uk Kim     char                    *Directive);
744c52cad2SJung-uk Kim 
754c52cad2SJung-uk Kim /*
764c52cad2SJung-uk Kim  * Supported preprocessor directives
774c52cad2SJung-uk Kim  */
784c52cad2SJung-uk Kim static const PR_DIRECTIVE_INFO      Gbl_DirectiveInfo[] =
794c52cad2SJung-uk Kim {
804c52cad2SJung-uk Kim     {"define",  1},
814c52cad2SJung-uk Kim     {"elif",    0}, /* Converted to #else..#if internally */
824c52cad2SJung-uk Kim     {"else",    0},
834c52cad2SJung-uk Kim     {"endif",   0},
844c52cad2SJung-uk Kim     {"error",   1},
854c52cad2SJung-uk Kim     {"if",      1},
864c52cad2SJung-uk Kim     {"ifdef",   1},
874c52cad2SJung-uk Kim     {"ifndef",  1},
884c52cad2SJung-uk Kim     {"include", 0}, /* Argument is not standard format, so 0 */
894c52cad2SJung-uk Kim     {"line",    1},
904c52cad2SJung-uk Kim     {"pragma",  1},
914c52cad2SJung-uk Kim     {"undef",   1},
924c52cad2SJung-uk Kim     {"warning", 1},
934c52cad2SJung-uk Kim     {NULL,      0}
944c52cad2SJung-uk Kim };
954c52cad2SJung-uk Kim 
964c52cad2SJung-uk Kim enum Gbl_DirectiveIndexes
974c52cad2SJung-uk Kim {
984c52cad2SJung-uk Kim     PR_DIRECTIVE_DEFINE = 0,
994c52cad2SJung-uk Kim     PR_DIRECTIVE_ELIF,
1004c52cad2SJung-uk Kim     PR_DIRECTIVE_ELSE,
1014c52cad2SJung-uk Kim     PR_DIRECTIVE_ENDIF,
1024c52cad2SJung-uk Kim     PR_DIRECTIVE_ERROR,
1034c52cad2SJung-uk Kim     PR_DIRECTIVE_IF,
1044c52cad2SJung-uk Kim     PR_DIRECTIVE_IFDEF,
1054c52cad2SJung-uk Kim     PR_DIRECTIVE_IFNDEF,
1064c52cad2SJung-uk Kim     PR_DIRECTIVE_INCLUDE,
1074c52cad2SJung-uk Kim     PR_DIRECTIVE_LINE,
1084c52cad2SJung-uk Kim     PR_DIRECTIVE_PRAGMA,
1094c52cad2SJung-uk Kim     PR_DIRECTIVE_UNDEF,
1104c52cad2SJung-uk Kim     PR_DIRECTIVE_WARNING,
1114c52cad2SJung-uk Kim };
1124c52cad2SJung-uk Kim 
1134c52cad2SJung-uk Kim #define ASL_DIRECTIVE_NOT_FOUND     -1
1144c52cad2SJung-uk Kim 
1154c52cad2SJung-uk Kim 
1164c52cad2SJung-uk Kim /*******************************************************************************
1174c52cad2SJung-uk Kim  *
1184c52cad2SJung-uk Kim  * FUNCTION:    PrInitializePreprocessor
1194c52cad2SJung-uk Kim  *
1204c52cad2SJung-uk Kim  * PARAMETERS:  None
1214c52cad2SJung-uk Kim  *
1224c52cad2SJung-uk Kim  * RETURN:      None
1234c52cad2SJung-uk Kim  *
1244c52cad2SJung-uk Kim  * DESCRIPTION: Startup initialization for the Preprocessor.
1254c52cad2SJung-uk Kim  *
1264c52cad2SJung-uk Kim  ******************************************************************************/
1274c52cad2SJung-uk Kim 
1284c52cad2SJung-uk Kim void
1294c52cad2SJung-uk Kim PrInitializePreprocessor (
1304c52cad2SJung-uk Kim     void)
1314c52cad2SJung-uk Kim {
1324c52cad2SJung-uk Kim     /* Init globals and the list of #defines */
1334c52cad2SJung-uk Kim 
1344c52cad2SJung-uk Kim     PrInitializeGlobals ();
1354c52cad2SJung-uk Kim     Gbl_DefineList = NULL;
1364c52cad2SJung-uk Kim }
1374c52cad2SJung-uk Kim 
1384c52cad2SJung-uk Kim 
1394c52cad2SJung-uk Kim /*******************************************************************************
1404c52cad2SJung-uk Kim  *
1414c52cad2SJung-uk Kim  * FUNCTION:    PrInitializeGlobals
1424c52cad2SJung-uk Kim  *
1434c52cad2SJung-uk Kim  * PARAMETERS:  None
1444c52cad2SJung-uk Kim  *
1454c52cad2SJung-uk Kim  * RETURN:      None
1464c52cad2SJung-uk Kim  *
1474c52cad2SJung-uk Kim  * DESCRIPTION: Initialize globals for the Preprocessor. Used for startuup
1484c52cad2SJung-uk Kim  *              initialization and re-initialization between compiles during
1494c52cad2SJung-uk Kim  *              a multiple source file compile.
1504c52cad2SJung-uk Kim  *
1514c52cad2SJung-uk Kim  ******************************************************************************/
1524c52cad2SJung-uk Kim 
1534c52cad2SJung-uk Kim void
1544c52cad2SJung-uk Kim PrInitializeGlobals (
1554c52cad2SJung-uk Kim     void)
1564c52cad2SJung-uk Kim {
1574c52cad2SJung-uk Kim     /* Init globals */
1584c52cad2SJung-uk Kim 
1594c52cad2SJung-uk Kim     Gbl_IfDepth = 0;
1604c52cad2SJung-uk Kim     Gbl_InputFileList = NULL;
1614c52cad2SJung-uk Kim     Gbl_CurrentLineNumber = 0;
1624c52cad2SJung-uk Kim     Gbl_PreprocessorLineNumber = 1;
1634c52cad2SJung-uk Kim     Gbl_PreprocessorError = FALSE;
1644c52cad2SJung-uk Kim }
1654c52cad2SJung-uk Kim 
1664c52cad2SJung-uk Kim 
1674c52cad2SJung-uk Kim /*******************************************************************************
1684c52cad2SJung-uk Kim  *
1694c52cad2SJung-uk Kim  * FUNCTION:    PrTerminatePreprocessor
1704c52cad2SJung-uk Kim  *
1714c52cad2SJung-uk Kim  * PARAMETERS:  None
1724c52cad2SJung-uk Kim  *
1734c52cad2SJung-uk Kim  * RETURN:      None
1744c52cad2SJung-uk Kim  *
1754c52cad2SJung-uk Kim  * DESCRIPTION: Termination of the preprocessor. Delete lists. Keep any
1764c52cad2SJung-uk Kim  *              defines that were specified on the command line, in order to
1774c52cad2SJung-uk Kim  *              support multiple compiles with a single compiler invocation.
1784c52cad2SJung-uk Kim  *
1794c52cad2SJung-uk Kim  ******************************************************************************/
1804c52cad2SJung-uk Kim 
1814c52cad2SJung-uk Kim void
1824c52cad2SJung-uk Kim PrTerminatePreprocessor (
1834c52cad2SJung-uk Kim     void)
1844c52cad2SJung-uk Kim {
1854c52cad2SJung-uk Kim     PR_DEFINE_INFO          *DefineInfo;
1864c52cad2SJung-uk Kim 
1874c52cad2SJung-uk Kim 
1884c52cad2SJung-uk Kim     /*
1894c52cad2SJung-uk Kim      * The persistent defines (created on the command line) are always at the
1904c52cad2SJung-uk Kim      * end of the list. We save them.
1914c52cad2SJung-uk Kim      */
1924c52cad2SJung-uk Kim     while ((Gbl_DefineList) && (!Gbl_DefineList->Persist))
1934c52cad2SJung-uk Kim     {
1944c52cad2SJung-uk Kim         DefineInfo = Gbl_DefineList;
1954c52cad2SJung-uk Kim         Gbl_DefineList = DefineInfo->Next;
1964c52cad2SJung-uk Kim 
1974c52cad2SJung-uk Kim         ACPI_FREE (DefineInfo->Replacement);
1984c52cad2SJung-uk Kim         ACPI_FREE (DefineInfo->Identifier);
1994c52cad2SJung-uk Kim         ACPI_FREE (DefineInfo);
2004c52cad2SJung-uk Kim     }
2014c52cad2SJung-uk Kim }
2024c52cad2SJung-uk Kim 
2034c52cad2SJung-uk Kim 
2044c52cad2SJung-uk Kim /*******************************************************************************
2054c52cad2SJung-uk Kim  *
2064c52cad2SJung-uk Kim  * FUNCTION:    PrDoPreprocess
2074c52cad2SJung-uk Kim  *
2084c52cad2SJung-uk Kim  * PARAMETERS:  None
2094c52cad2SJung-uk Kim  *
2104c52cad2SJung-uk Kim  * RETURN:      Error Status. TRUE if error, FALSE if OK.
2114c52cad2SJung-uk Kim  *
2124c52cad2SJung-uk Kim  * DESCRIPTION: Main entry point for the iASL Preprocessor. Input file must
2134c52cad2SJung-uk Kim  *              be already open. Handles multiple input files via the
2144c52cad2SJung-uk Kim  *              #include directive.
2154c52cad2SJung-uk Kim  *
2164c52cad2SJung-uk Kim  ******************************************************************************/
2174c52cad2SJung-uk Kim 
2184c52cad2SJung-uk Kim BOOLEAN
2194c52cad2SJung-uk Kim PrDoPreprocess (
2204c52cad2SJung-uk Kim     void)
2214c52cad2SJung-uk Kim {
2224c52cad2SJung-uk Kim     BOOLEAN                 MoreInputFiles;
2234c52cad2SJung-uk Kim 
2244c52cad2SJung-uk Kim 
2254c52cad2SJung-uk Kim     DbgPrint (ASL_DEBUG_OUTPUT, "Starting preprocessing phase\n\n");
2264c52cad2SJung-uk Kim 
2274c52cad2SJung-uk Kim 
2284c52cad2SJung-uk Kim     FlSeekFile (ASL_FILE_INPUT, 0);
2294c52cad2SJung-uk Kim     PrDumpPredefinedNames ();
2304c52cad2SJung-uk Kim 
2314c52cad2SJung-uk Kim     /* Main preprocessor loop, handles include files */
2324c52cad2SJung-uk Kim 
2334c52cad2SJung-uk Kim     do
2344c52cad2SJung-uk Kim     {
2354c52cad2SJung-uk Kim         PrPreprocessInputFile ();
2364c52cad2SJung-uk Kim         MoreInputFiles = PrPopInputFileStack ();
2374c52cad2SJung-uk Kim 
2384c52cad2SJung-uk Kim     } while (MoreInputFiles);
2394c52cad2SJung-uk Kim 
2404c52cad2SJung-uk Kim 
2414c52cad2SJung-uk Kim     /*
2424c52cad2SJung-uk Kim      * TBD: is this necessary? (Do we abort on any preprocessing errors?)
2434c52cad2SJung-uk Kim      */
2444c52cad2SJung-uk Kim     if (Gbl_PreprocessorError)
2454c52cad2SJung-uk Kim     {
2464c52cad2SJung-uk Kim         /* TBD: can't use source_output file for preprocessor error reporting */
2474c52cad2SJung-uk Kim 
2484c52cad2SJung-uk Kim         Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle = NULL;
2494c52cad2SJung-uk Kim         PrTerminatePreprocessor ();
2504c52cad2SJung-uk Kim         return (TRUE);
2514c52cad2SJung-uk Kim     }
2524c52cad2SJung-uk Kim 
2534c52cad2SJung-uk Kim     /* Point compiler input to the new preprocessor file (.i) */
2544c52cad2SJung-uk Kim 
2554c52cad2SJung-uk Kim     FlCloseFile (ASL_FILE_INPUT);
2564c52cad2SJung-uk Kim     Gbl_Files[ASL_FILE_INPUT].Handle = Gbl_Files[ASL_FILE_PREPROCESSOR].Handle;
2574c52cad2SJung-uk Kim     AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
2584c52cad2SJung-uk Kim 
2594c52cad2SJung-uk Kim     /* Reset globals to allow compiler to run */
2604c52cad2SJung-uk Kim 
2614c52cad2SJung-uk Kim     FlSeekFile (ASL_FILE_INPUT, 0);
2624c52cad2SJung-uk Kim     Gbl_CurrentLineNumber = 1;
2634c52cad2SJung-uk Kim 
2644c52cad2SJung-uk Kim     DbgPrint (ASL_DEBUG_OUTPUT, "Preprocessing phase complete \n\n");
2654c52cad2SJung-uk Kim     return (FALSE);
2664c52cad2SJung-uk Kim }
2674c52cad2SJung-uk Kim 
2684c52cad2SJung-uk Kim 
2694c52cad2SJung-uk Kim /*******************************************************************************
2704c52cad2SJung-uk Kim  *
2714c52cad2SJung-uk Kim  * FUNCTION:    PrPreprocessInputFile
2724c52cad2SJung-uk Kim  *
2734c52cad2SJung-uk Kim  * PARAMETERS:  None
2744c52cad2SJung-uk Kim  *
2754c52cad2SJung-uk Kim  * RETURN:      None
2764c52cad2SJung-uk Kim  *
2774c52cad2SJung-uk Kim  * DESCRIPTION: Preprocess one entire file, line-by-line.
2784c52cad2SJung-uk Kim  *
2794c52cad2SJung-uk Kim  * Input:  Raw user ASL from ASL_FILE_INPUT
2804c52cad2SJung-uk Kim  * Output: Preprocessed file written to ASL_FILE_PREPROCESSOR
2814c52cad2SJung-uk Kim  *
2824c52cad2SJung-uk Kim  ******************************************************************************/
2834c52cad2SJung-uk Kim 
2844c52cad2SJung-uk Kim static void
2854c52cad2SJung-uk Kim PrPreprocessInputFile (
2864c52cad2SJung-uk Kim     void)
2874c52cad2SJung-uk Kim {
2884c52cad2SJung-uk Kim     UINT32                  Offset;
2894c52cad2SJung-uk Kim     char                    *Token;
2904c52cad2SJung-uk Kim     char                    *ReplaceString;
2914c52cad2SJung-uk Kim     PR_DEFINE_INFO          *DefineInfo;
2924c52cad2SJung-uk Kim     ACPI_SIZE               TokenOffset;
2934c52cad2SJung-uk Kim     BOOLEAN                 IgnoringThisCodeBlock = FALSE;
2944c52cad2SJung-uk Kim     char                    *Next;
2954c52cad2SJung-uk Kim     int                     OffsetAdjust;
2964c52cad2SJung-uk Kim 
2974c52cad2SJung-uk Kim 
2984c52cad2SJung-uk Kim     /* Scan line-by-line. Comments and blank lines are skipped by this function */
2994c52cad2SJung-uk Kim 
3004c52cad2SJung-uk Kim     while ((Offset = DtGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF)
3014c52cad2SJung-uk Kim     {
3024c52cad2SJung-uk Kim         /* Need a copy of the input line for strok() */
3034c52cad2SJung-uk Kim 
3044c52cad2SJung-uk Kim         strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer);
3054c52cad2SJung-uk Kim         Token = PrGetNextToken (Gbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next);
3064c52cad2SJung-uk Kim         OffsetAdjust = 0;
3074c52cad2SJung-uk Kim 
3084c52cad2SJung-uk Kim         /* All preprocessor directives must begin with '#' */
3094c52cad2SJung-uk Kim 
3104c52cad2SJung-uk Kim         if (Token && (*Token == '#'))
3114c52cad2SJung-uk Kim         {
3124c52cad2SJung-uk Kim             if (strlen (Token) == 1)
3134c52cad2SJung-uk Kim             {
3144c52cad2SJung-uk Kim                 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
3154c52cad2SJung-uk Kim             }
3164c52cad2SJung-uk Kim             else
3174c52cad2SJung-uk Kim             {
3184c52cad2SJung-uk Kim                 Token++;    /* Skip leading # */
3194c52cad2SJung-uk Kim             }
3204c52cad2SJung-uk Kim 
3214c52cad2SJung-uk Kim             /* Execute the directive, do not write line to output file */
3224c52cad2SJung-uk Kim 
3234c52cad2SJung-uk Kim             PrDoDirective (Token, &Next, &IgnoringThisCodeBlock);
3244c52cad2SJung-uk Kim             continue;
3254c52cad2SJung-uk Kim         }
3264c52cad2SJung-uk Kim 
3274c52cad2SJung-uk Kim         /*
3284c52cad2SJung-uk Kim          * If we are currently within the part of an IF/ELSE block that is
3294c52cad2SJung-uk Kim          * FALSE, ignore the line and do not write it to the output file.
3304c52cad2SJung-uk Kim          * This continues until an #else or #endif is encountered.
3314c52cad2SJung-uk Kim          */
3324c52cad2SJung-uk Kim         if (IgnoringThisCodeBlock == TRUE)
3334c52cad2SJung-uk Kim         {
3344c52cad2SJung-uk Kim             continue;
3354c52cad2SJung-uk Kim         }
3364c52cad2SJung-uk Kim 
3374c52cad2SJung-uk Kim         /* Match and replace all #defined names within this source line */
3384c52cad2SJung-uk Kim 
3394c52cad2SJung-uk Kim         while (Token)
3404c52cad2SJung-uk Kim         {
3414c52cad2SJung-uk Kim             DefineInfo = PrMatchDefine (Token);
3424c52cad2SJung-uk Kim             if (DefineInfo)
3434c52cad2SJung-uk Kim             {
3444c52cad2SJung-uk Kim                 if (DefineInfo->Body)
3454c52cad2SJung-uk Kim                 {
3464c52cad2SJung-uk Kim                     /* This is a macro */
3474c52cad2SJung-uk Kim 
3484c52cad2SJung-uk Kim                     DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
3494c52cad2SJung-uk Kim                         "Matched Macro: %s->%s\n",
3504c52cad2SJung-uk Kim                         Gbl_CurrentLineNumber, DefineInfo->Identifier,
3514c52cad2SJung-uk Kim                         DefineInfo->Replacement);
3524c52cad2SJung-uk Kim 
3534c52cad2SJung-uk Kim                     PrDoMacroInvocation (Gbl_MainTokenBuffer, Token,
3544c52cad2SJung-uk Kim                         DefineInfo, &Next);
3554c52cad2SJung-uk Kim                 }
3564c52cad2SJung-uk Kim                 else
3574c52cad2SJung-uk Kim                 {
3584c52cad2SJung-uk Kim                     ReplaceString = DefineInfo->Replacement;
3594c52cad2SJung-uk Kim 
3604c52cad2SJung-uk Kim                     /* Replace the name in the original line buffer */
3614c52cad2SJung-uk Kim 
3624c52cad2SJung-uk Kim                     TokenOffset = Token - Gbl_MainTokenBuffer + OffsetAdjust;
3634c52cad2SJung-uk Kim                     PrReplaceData (
3644c52cad2SJung-uk Kim                         &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token),
3654c52cad2SJung-uk Kim                         ReplaceString, strlen (ReplaceString));
3664c52cad2SJung-uk Kim 
3674c52cad2SJung-uk Kim                     /* Adjust for length difference between old and new name length */
3684c52cad2SJung-uk Kim 
3694c52cad2SJung-uk Kim                     OffsetAdjust += strlen (ReplaceString) - strlen (Token);
3704c52cad2SJung-uk Kim 
3714c52cad2SJung-uk Kim                     DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
3724c52cad2SJung-uk Kim                         "Matched #define: %s->%s\n",
3734c52cad2SJung-uk Kim                         Gbl_CurrentLineNumber, Token,
3744c52cad2SJung-uk Kim                         *ReplaceString ? ReplaceString : "(NULL STRING)");
3754c52cad2SJung-uk Kim                 }
3764c52cad2SJung-uk Kim             }
3774c52cad2SJung-uk Kim 
3784c52cad2SJung-uk Kim             Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
3794c52cad2SJung-uk Kim         }
3804c52cad2SJung-uk Kim 
3814c52cad2SJung-uk Kim #if 0
3824c52cad2SJung-uk Kim /* Line prefix */
3834c52cad2SJung-uk Kim         FlPrintFile (ASL_FILE_PREPROCESSOR, "/* %14s  %.5u  i:%.5u */ ",
3844c52cad2SJung-uk Kim             Gbl_Files[ASL_FILE_INPUT].Filename,
3854c52cad2SJung-uk Kim             Gbl_CurrentLineNumber, Gbl_PreprocessorLineNumber);
3864c52cad2SJung-uk Kim #endif
3874c52cad2SJung-uk Kim 
388*eef1b955SJung-uk Kim         /*
389*eef1b955SJung-uk Kim          * Emit a #line directive if necessary, to keep the line numbers in
390*eef1b955SJung-uk Kim          * the (.i) file synchronized with the original source code file, so
391*eef1b955SJung-uk Kim          * that the correct line number appears in any error messages
392*eef1b955SJung-uk Kim          * generated by the actual compiler.
393*eef1b955SJung-uk Kim          */
394*eef1b955SJung-uk Kim         if (Gbl_CurrentLineNumber > (Gbl_PreviousLineNumber + 1))
395*eef1b955SJung-uk Kim         {
396*eef1b955SJung-uk Kim             FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u\n",
397*eef1b955SJung-uk Kim                 Gbl_CurrentLineNumber);
398*eef1b955SJung-uk Kim         }
399*eef1b955SJung-uk Kim 
400*eef1b955SJung-uk Kim         Gbl_PreviousLineNumber = Gbl_CurrentLineNumber;
401*eef1b955SJung-uk Kim         Gbl_PreprocessorLineNumber++;
402*eef1b955SJung-uk Kim 
403*eef1b955SJung-uk Kim         /*
404*eef1b955SJung-uk Kim          * Now we can write the possibly modified source line to the
405*eef1b955SJung-uk Kim          * preprocessor (.i) file
406*eef1b955SJung-uk Kim          */
4074c52cad2SJung-uk Kim         FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer,
4084c52cad2SJung-uk Kim             strlen (Gbl_CurrentLineBuffer));
4094c52cad2SJung-uk Kim     }
4104c52cad2SJung-uk Kim }
4114c52cad2SJung-uk Kim 
4124c52cad2SJung-uk Kim 
4134c52cad2SJung-uk Kim /*******************************************************************************
4144c52cad2SJung-uk Kim  *
4154c52cad2SJung-uk Kim  * FUNCTION:    PrDoDirective
4164c52cad2SJung-uk Kim  *
4174c52cad2SJung-uk Kim  * PARAMETERS:  Directive               - Pointer to directive name token
4184c52cad2SJung-uk Kim  *              Next                    - "Next" buffer from GetNextToken
4194c52cad2SJung-uk Kim  *              IgnoringThisCodeBlock   - Where the "ignore code" flag is
4204c52cad2SJung-uk Kim  *                                        returned.
4214c52cad2SJung-uk Kim  *
4224c52cad2SJung-uk Kim  * RETURN:      IgnoringThisCodeBlock: Set to TRUE if we are skipping the FALSE
4234c52cad2SJung-uk Kim  *              part of an #if or #else block. Set to FALSE when the
4244c52cad2SJung-uk Kim  *              corresponding #else or #endif is encountered.
4254c52cad2SJung-uk Kim  *
4264c52cad2SJung-uk Kim  * DESCRIPTION: Main processing for all preprocessor directives
4274c52cad2SJung-uk Kim  *
4284c52cad2SJung-uk Kim  ******************************************************************************/
4294c52cad2SJung-uk Kim 
4304c52cad2SJung-uk Kim static void
4314c52cad2SJung-uk Kim PrDoDirective (
4324c52cad2SJung-uk Kim     char                    *DirectiveToken,
4334c52cad2SJung-uk Kim     char                    **Next,
4344c52cad2SJung-uk Kim     BOOLEAN                 *IgnoringThisCodeBlock)
4354c52cad2SJung-uk Kim {
4364c52cad2SJung-uk Kim     char                    *Token = Gbl_MainTokenBuffer;
4374c52cad2SJung-uk Kim     char                    *Token2;
4384c52cad2SJung-uk Kim     char                    *End;
4394c52cad2SJung-uk Kim     UINT64                  Value;
4404c52cad2SJung-uk Kim     ACPI_SIZE               TokenOffset;
4414c52cad2SJung-uk Kim     int                     Directive;
4424c52cad2SJung-uk Kim     ACPI_STATUS             Status;
4434c52cad2SJung-uk Kim 
4444c52cad2SJung-uk Kim 
4454c52cad2SJung-uk Kim     if (!DirectiveToken)
4464c52cad2SJung-uk Kim     {
4474c52cad2SJung-uk Kim         goto SyntaxError;
4484c52cad2SJung-uk Kim     }
4494c52cad2SJung-uk Kim 
4504c52cad2SJung-uk Kim     Directive = PrMatchDirective (DirectiveToken);
4514c52cad2SJung-uk Kim     if (Directive == ASL_DIRECTIVE_NOT_FOUND)
4524c52cad2SJung-uk Kim     {
4534c52cad2SJung-uk Kim         PrError (ASL_ERROR, ASL_MSG_UNKNOWN_DIRECTIVE,
4544c52cad2SJung-uk Kim             THIS_TOKEN_OFFSET (DirectiveToken));
4554c52cad2SJung-uk Kim 
4564c52cad2SJung-uk Kim         DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
4574c52cad2SJung-uk Kim             "#%s: Unknown directive\n",
4584c52cad2SJung-uk Kim             Gbl_CurrentLineNumber, DirectiveToken);
4594c52cad2SJung-uk Kim         return;
4604c52cad2SJung-uk Kim     }
4614c52cad2SJung-uk Kim 
4624c52cad2SJung-uk Kim     /* TBD: Need a faster way to do this: */
4634c52cad2SJung-uk Kim 
4644c52cad2SJung-uk Kim     if ((Directive == PR_DIRECTIVE_ELIF) ||
4654c52cad2SJung-uk Kim         (Directive == PR_DIRECTIVE_ELSE) ||
4664c52cad2SJung-uk Kim         (Directive == PR_DIRECTIVE_ENDIF))
4674c52cad2SJung-uk Kim     {
4684c52cad2SJung-uk Kim         DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Begin #%s\n",
4694c52cad2SJung-uk Kim             Gbl_CurrentLineNumber, Gbl_DirectiveInfo[Directive].Name);
4704c52cad2SJung-uk Kim     }
4714c52cad2SJung-uk Kim 
4724c52cad2SJung-uk Kim     /*
4734c52cad2SJung-uk Kim      * Need to always check for #else, #elif, #endif regardless of
4744c52cad2SJung-uk Kim      * whether we are ignoring the current code block, since these
4754c52cad2SJung-uk Kim      * are conditional code block terminators.
4764c52cad2SJung-uk Kim      */
4774c52cad2SJung-uk Kim     switch (Directive)
4784c52cad2SJung-uk Kim     {
4794c52cad2SJung-uk Kim     case PR_DIRECTIVE_ELIF:
4804c52cad2SJung-uk Kim         *IgnoringThisCodeBlock = !(*IgnoringThisCodeBlock);
4814c52cad2SJung-uk Kim         if (*IgnoringThisCodeBlock == TRUE)
4824c52cad2SJung-uk Kim         {
4834c52cad2SJung-uk Kim             /* Not executing the ELSE part -- all done here */
4844c52cad2SJung-uk Kim             return;
4854c52cad2SJung-uk Kim         }
4864c52cad2SJung-uk Kim 
4874c52cad2SJung-uk Kim         /* Will execute the ELSE..IF part */
4884c52cad2SJung-uk Kim 
4894c52cad2SJung-uk Kim         DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
4904c52cad2SJung-uk Kim             "#elif - Executing else block\n",
4914c52cad2SJung-uk Kim             Gbl_CurrentLineNumber);
4924c52cad2SJung-uk Kim         Directive = PR_DIRECTIVE_IF;
4934c52cad2SJung-uk Kim         break;
4944c52cad2SJung-uk Kim 
4954c52cad2SJung-uk Kim     case PR_DIRECTIVE_ELSE:
4964c52cad2SJung-uk Kim         *IgnoringThisCodeBlock = !(*IgnoringThisCodeBlock);
4974c52cad2SJung-uk Kim         return;
4984c52cad2SJung-uk Kim 
4994c52cad2SJung-uk Kim     case PR_DIRECTIVE_ENDIF:
5004c52cad2SJung-uk Kim         *IgnoringThisCodeBlock = FALSE;
5014c52cad2SJung-uk Kim         Gbl_IfDepth--;
5024c52cad2SJung-uk Kim         if (Gbl_IfDepth < 0)
5034c52cad2SJung-uk Kim         {
5044c52cad2SJung-uk Kim             PrError (ASL_ERROR, ASL_MSG_ENDIF_MISMATCH,
5054c52cad2SJung-uk Kim                 THIS_TOKEN_OFFSET (DirectiveToken));
5064c52cad2SJung-uk Kim             Gbl_IfDepth = 0;
5074c52cad2SJung-uk Kim         }
5084c52cad2SJung-uk Kim         return;
5094c52cad2SJung-uk Kim 
5104c52cad2SJung-uk Kim     default:
5114c52cad2SJung-uk Kim         break;
5124c52cad2SJung-uk Kim     }
5134c52cad2SJung-uk Kim 
5144c52cad2SJung-uk Kim     /*
5154c52cad2SJung-uk Kim      * At this point, if we are ignoring the current code block,
5164c52cad2SJung-uk Kim      * do not process any more directives (i.e., ignore them also.)
5174c52cad2SJung-uk Kim      */
5184c52cad2SJung-uk Kim     if (*IgnoringThisCodeBlock == TRUE)
5194c52cad2SJung-uk Kim     {
5204c52cad2SJung-uk Kim         return;
5214c52cad2SJung-uk Kim     }
5224c52cad2SJung-uk Kim 
5234c52cad2SJung-uk Kim     DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Begin #%s\n",
5244c52cad2SJung-uk Kim         Gbl_CurrentLineNumber, Gbl_DirectiveInfo[Directive].Name);
5254c52cad2SJung-uk Kim 
5264c52cad2SJung-uk Kim     /* Most directives have at least one argument */
5274c52cad2SJung-uk Kim 
5284c52cad2SJung-uk Kim     if (Gbl_DirectiveInfo[Directive].ArgCount == 1)
5294c52cad2SJung-uk Kim     {
5304c52cad2SJung-uk Kim         Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
5314c52cad2SJung-uk Kim         if (!Token)
5324c52cad2SJung-uk Kim         {
5334c52cad2SJung-uk Kim             goto SyntaxError;
5344c52cad2SJung-uk Kim         }
5354c52cad2SJung-uk Kim     }
5364c52cad2SJung-uk Kim 
5374c52cad2SJung-uk Kim     switch (Directive)
5384c52cad2SJung-uk Kim     {
5394c52cad2SJung-uk Kim     case PR_DIRECTIVE_DEFINE:
5404c52cad2SJung-uk Kim         /*
5414c52cad2SJung-uk Kim          * By definition, if first char after the name is a paren,
5424c52cad2SJung-uk Kim          * this is a function macro.
5434c52cad2SJung-uk Kim          */
5444c52cad2SJung-uk Kim         TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token);
5454c52cad2SJung-uk Kim         if (*(&Gbl_CurrentLineBuffer[TokenOffset]) == '(')
5464c52cad2SJung-uk Kim         {
5474c52cad2SJung-uk Kim #ifndef MACROS_SUPPORTED
548*eef1b955SJung-uk Kim             AcpiOsPrintf ("%s ERROR - line %u: #define macros are not supported yet\n",
549*eef1b955SJung-uk Kim                 Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber);
550*eef1b955SJung-uk Kim             exit(1);
5514c52cad2SJung-uk Kim #else
5524c52cad2SJung-uk Kim             PrAddMacro (Token, Next);
5534c52cad2SJung-uk Kim #endif
5544c52cad2SJung-uk Kim         }
5554c52cad2SJung-uk Kim         else
5564c52cad2SJung-uk Kim         {
5574c52cad2SJung-uk Kim             /* Use the remainder of the line for the #define */
5584c52cad2SJung-uk Kim 
5594c52cad2SJung-uk Kim             Token2 = *Next;
5604c52cad2SJung-uk Kim             if (Token2)
5614c52cad2SJung-uk Kim             {
5624c52cad2SJung-uk Kim                 while ((*Token2 == ' ') || (*Token2 == '\t'))
5634c52cad2SJung-uk Kim                 {
5644c52cad2SJung-uk Kim                     Token2++;
5654c52cad2SJung-uk Kim                 }
5664c52cad2SJung-uk Kim                 End = Token2;
5674c52cad2SJung-uk Kim                 while (*End != '\n')
5684c52cad2SJung-uk Kim                 {
5694c52cad2SJung-uk Kim                     End++;
5704c52cad2SJung-uk Kim                 }
5714c52cad2SJung-uk Kim                 *End = 0;
5724c52cad2SJung-uk Kim             }
5734c52cad2SJung-uk Kim             else
5744c52cad2SJung-uk Kim             {
5754c52cad2SJung-uk Kim                 Token2 = "";
5764c52cad2SJung-uk Kim             }
5774c52cad2SJung-uk Kim #if 0
5784c52cad2SJung-uk Kim             Token2 = PrGetNextToken (NULL, "\n", /*PR_TOKEN_SEPARATORS,*/ Next);
5794c52cad2SJung-uk Kim             if (!Token2)
5804c52cad2SJung-uk Kim             {
5814c52cad2SJung-uk Kim                 Token2 = "";
5824c52cad2SJung-uk Kim             }
5834c52cad2SJung-uk Kim #endif
5844c52cad2SJung-uk Kim             DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
5854c52cad2SJung-uk Kim                 "New #define: %s->%s\n",
5864c52cad2SJung-uk Kim                 Gbl_CurrentLineNumber, Token, Token2);
5874c52cad2SJung-uk Kim 
5884c52cad2SJung-uk Kim             PrAddDefine (Token, Token2, FALSE);
5894c52cad2SJung-uk Kim         }
5904c52cad2SJung-uk Kim         break;
5914c52cad2SJung-uk Kim 
5924c52cad2SJung-uk Kim     case PR_DIRECTIVE_ERROR:
5934c52cad2SJung-uk Kim         /* TBD compiler should abort */
5944c52cad2SJung-uk Kim         /* Note: No macro expansion */
5954c52cad2SJung-uk Kim 
5964c52cad2SJung-uk Kim         PrError (ASL_ERROR, ASL_MSG_ERROR_DIRECTIVE,
5974c52cad2SJung-uk Kim             THIS_TOKEN_OFFSET (Token));
5984c52cad2SJung-uk Kim         break;
5994c52cad2SJung-uk Kim 
6004c52cad2SJung-uk Kim     case PR_DIRECTIVE_IF:
6014c52cad2SJung-uk Kim         TokenOffset = Token - Gbl_MainTokenBuffer;
6024c52cad2SJung-uk Kim 
6034c52cad2SJung-uk Kim         /* Need to expand #define macros in the expression string first */
6044c52cad2SJung-uk Kim 
6054c52cad2SJung-uk Kim         Status = PrResolveIntegerExpression (
6064c52cad2SJung-uk Kim             &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
6074c52cad2SJung-uk Kim         if (ACPI_FAILURE (Status))
6084c52cad2SJung-uk Kim         {
6094c52cad2SJung-uk Kim             return;
6104c52cad2SJung-uk Kim         }
6114c52cad2SJung-uk Kim 
6124c52cad2SJung-uk Kim         if (!Value)
6134c52cad2SJung-uk Kim         {
6144c52cad2SJung-uk Kim             *IgnoringThisCodeBlock = TRUE;
6154c52cad2SJung-uk Kim         }
6164c52cad2SJung-uk Kim 
6174c52cad2SJung-uk Kim         DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
6184c52cad2SJung-uk Kim             "Resolved #if: %8.8X%8.8X %s\n",
6194c52cad2SJung-uk Kim             Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value),
6204c52cad2SJung-uk Kim             *IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>");
6214c52cad2SJung-uk Kim 
6224c52cad2SJung-uk Kim         Gbl_IfDepth++;
6234c52cad2SJung-uk Kim         break;
6244c52cad2SJung-uk Kim 
6254c52cad2SJung-uk Kim     case PR_DIRECTIVE_IFDEF:
6264c52cad2SJung-uk Kim         if (!PrMatchDefine (Token))
6274c52cad2SJung-uk Kim         {
6284c52cad2SJung-uk Kim             *IgnoringThisCodeBlock = TRUE;
6294c52cad2SJung-uk Kim         }
6304c52cad2SJung-uk Kim 
6314c52cad2SJung-uk Kim         Gbl_IfDepth++;
6324c52cad2SJung-uk Kim         DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
6334c52cad2SJung-uk Kim             "Start #ifdef %s\n", Gbl_CurrentLineNumber,
6344c52cad2SJung-uk Kim             *IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>");
6354c52cad2SJung-uk Kim         break;
6364c52cad2SJung-uk Kim 
6374c52cad2SJung-uk Kim     case PR_DIRECTIVE_IFNDEF:
6384c52cad2SJung-uk Kim         if (PrMatchDefine (Token))
6394c52cad2SJung-uk Kim         {
6404c52cad2SJung-uk Kim             *IgnoringThisCodeBlock = TRUE;
6414c52cad2SJung-uk Kim         }
6424c52cad2SJung-uk Kim 
6434c52cad2SJung-uk Kim         Gbl_IfDepth++;
6444c52cad2SJung-uk Kim         DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
6454c52cad2SJung-uk Kim             "Start #ifndef %2.2X\n", Gbl_CurrentLineNumber,
6464c52cad2SJung-uk Kim             *IgnoringThisCodeBlock, Gbl_CurrentLineNumber);
6474c52cad2SJung-uk Kim         break;
6484c52cad2SJung-uk Kim 
6494c52cad2SJung-uk Kim     case PR_DIRECTIVE_INCLUDE:
6504c52cad2SJung-uk Kim         Token = PrGetNextToken (NULL, " \"<>", Next);
6514c52cad2SJung-uk Kim         if (!Token)
6524c52cad2SJung-uk Kim         {
6534c52cad2SJung-uk Kim             goto SyntaxError;
6544c52cad2SJung-uk Kim         }
6554c52cad2SJung-uk Kim 
6564c52cad2SJung-uk Kim         DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
6574c52cad2SJung-uk Kim             "Start #include file %s\n", Gbl_CurrentLineNumber,
6584c52cad2SJung-uk Kim             Token, Gbl_CurrentLineNumber);
6594c52cad2SJung-uk Kim 
6604c52cad2SJung-uk Kim         PrOpenIncludeFile (Token);
6614c52cad2SJung-uk Kim         break;
6624c52cad2SJung-uk Kim 
663*eef1b955SJung-uk Kim     case PR_DIRECTIVE_LINE:
664*eef1b955SJung-uk Kim         TokenOffset = Token - Gbl_MainTokenBuffer;
665*eef1b955SJung-uk Kim 
666*eef1b955SJung-uk Kim         Status = PrResolveIntegerExpression (
667*eef1b955SJung-uk Kim             &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
668*eef1b955SJung-uk Kim         if (ACPI_FAILURE (Status))
669*eef1b955SJung-uk Kim         {
670*eef1b955SJung-uk Kim             return;
671*eef1b955SJung-uk Kim         }
672*eef1b955SJung-uk Kim 
673*eef1b955SJung-uk Kim         DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
674*eef1b955SJung-uk Kim             "User #line invocation %s\n", Gbl_CurrentLineNumber,
675*eef1b955SJung-uk Kim             Token);
676*eef1b955SJung-uk Kim 
677*eef1b955SJung-uk Kim         /* Update local line numbers */
678*eef1b955SJung-uk Kim 
679*eef1b955SJung-uk Kim         Gbl_CurrentLineNumber = (UINT32) Value;
680*eef1b955SJung-uk Kim         Gbl_PreviousLineNumber = 0;
681*eef1b955SJung-uk Kim 
682*eef1b955SJung-uk Kim         /* Emit #line into the preprocessor file */
683*eef1b955SJung-uk Kim 
684*eef1b955SJung-uk Kim         FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n",
685*eef1b955SJung-uk Kim             Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename);
686*eef1b955SJung-uk Kim         break;
687*eef1b955SJung-uk Kim 
6884c52cad2SJung-uk Kim     case PR_DIRECTIVE_PRAGMA:
6894c52cad2SJung-uk Kim         /* Only "#pragma message" supported at this time */
6904c52cad2SJung-uk Kim 
6914c52cad2SJung-uk Kim         if (strcmp (Token, "message"))
6924c52cad2SJung-uk Kim         {
6934c52cad2SJung-uk Kim             PrError (ASL_ERROR, ASL_MSG_UNKNOWN_PRAGMA,
6944c52cad2SJung-uk Kim                 THIS_TOKEN_OFFSET (Token));
6954c52cad2SJung-uk Kim             return;
6964c52cad2SJung-uk Kim         }
6974c52cad2SJung-uk Kim 
6984c52cad2SJung-uk Kim         Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
6994c52cad2SJung-uk Kim         if (!Token)
7004c52cad2SJung-uk Kim         {
7014c52cad2SJung-uk Kim             goto SyntaxError;
7024c52cad2SJung-uk Kim         }
7034c52cad2SJung-uk Kim 
7044c52cad2SJung-uk Kim         TokenOffset = Token - Gbl_MainTokenBuffer;
7054c52cad2SJung-uk Kim         AcpiOsPrintf ("%s\n", &Gbl_CurrentLineBuffer[TokenOffset]);
7064c52cad2SJung-uk Kim         break;
7074c52cad2SJung-uk Kim 
7084c52cad2SJung-uk Kim     case PR_DIRECTIVE_UNDEF:
7094c52cad2SJung-uk Kim         DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
7104c52cad2SJung-uk Kim             "#undef: %s\n", Gbl_CurrentLineNumber, Token);
7114c52cad2SJung-uk Kim 
7124c52cad2SJung-uk Kim         PrRemoveDefine (Token);
7134c52cad2SJung-uk Kim         break;
7144c52cad2SJung-uk Kim 
7154c52cad2SJung-uk Kim     case PR_DIRECTIVE_WARNING:
7164c52cad2SJung-uk Kim         PrError (ASL_WARNING, ASL_MSG_ERROR_DIRECTIVE,
7174c52cad2SJung-uk Kim             THIS_TOKEN_OFFSET (Token));
7184c52cad2SJung-uk Kim         break;
7194c52cad2SJung-uk Kim 
7204c52cad2SJung-uk Kim     default:
7214c52cad2SJung-uk Kim         /* Should never get here */
7224c52cad2SJung-uk Kim         DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
7234c52cad2SJung-uk Kim             "Unrecognized directive: %u\n",
7244c52cad2SJung-uk Kim             Gbl_CurrentLineNumber, Directive);
7254c52cad2SJung-uk Kim         break;
7264c52cad2SJung-uk Kim     }
7274c52cad2SJung-uk Kim 
7284c52cad2SJung-uk Kim     return;
7294c52cad2SJung-uk Kim 
7304c52cad2SJung-uk Kim 
7314c52cad2SJung-uk Kim SyntaxError:
7324c52cad2SJung-uk Kim 
7334c52cad2SJung-uk Kim     PrError (ASL_ERROR, ASL_MSG_DIRECTIVE_SYNTAX,
7344c52cad2SJung-uk Kim         THIS_TOKEN_OFFSET (DirectiveToken));
7354c52cad2SJung-uk Kim     return;
7364c52cad2SJung-uk Kim }
7374c52cad2SJung-uk Kim 
7384c52cad2SJung-uk Kim 
7394c52cad2SJung-uk Kim /*******************************************************************************
7404c52cad2SJung-uk Kim  *
7414c52cad2SJung-uk Kim  * FUNCTION:    PrMatchDirective
7424c52cad2SJung-uk Kim  *
7434c52cad2SJung-uk Kim  * PARAMETERS:  Directive           - Pointer to directive name token
7444c52cad2SJung-uk Kim  *
7454c52cad2SJung-uk Kim  * RETURN:      Index into command array, -1 if not found
7464c52cad2SJung-uk Kim  *
7474c52cad2SJung-uk Kim  * DESCRIPTION: Lookup the incoming directive in the known directives table.
7484c52cad2SJung-uk Kim  *
7494c52cad2SJung-uk Kim  ******************************************************************************/
7504c52cad2SJung-uk Kim 
7514c52cad2SJung-uk Kim static int
7524c52cad2SJung-uk Kim PrMatchDirective (
7534c52cad2SJung-uk Kim     char                    *Directive)
7544c52cad2SJung-uk Kim {
7554c52cad2SJung-uk Kim     int                     i;
7564c52cad2SJung-uk Kim 
7574c52cad2SJung-uk Kim 
7584c52cad2SJung-uk Kim     if (!Directive || Directive[0] == 0)
7594c52cad2SJung-uk Kim     {
7604c52cad2SJung-uk Kim         return (ASL_DIRECTIVE_NOT_FOUND);
7614c52cad2SJung-uk Kim     }
7624c52cad2SJung-uk Kim 
7634c52cad2SJung-uk Kim     for (i = 0; Gbl_DirectiveInfo[i].Name; i++)
7644c52cad2SJung-uk Kim     {
7654c52cad2SJung-uk Kim         if (!strcmp (Gbl_DirectiveInfo[i].Name, Directive))
7664c52cad2SJung-uk Kim         {
7674c52cad2SJung-uk Kim             return (i);
7684c52cad2SJung-uk Kim         }
7694c52cad2SJung-uk Kim     }
7704c52cad2SJung-uk Kim 
7714c52cad2SJung-uk Kim     return (ASL_DIRECTIVE_NOT_FOUND);    /* Command not recognized */
7724c52cad2SJung-uk Kim }
773