1 /******************************************************************************
3 * Module Name: prscan - Preprocessor start-up and file scan module
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #define _DECLARE_PR_GLOBALS
154 #include <contrib/dev/acpica/compiler/aslcompiler.h>
155 #include <contrib/dev/acpica/compiler/dtcompiler.h>
160 * No nested macros, maybe never
161 * Implement ASL "Include" as well as "#include" here?
163 #define _COMPONENT ASL_PREPROCESSOR
164 ACPI_MODULE_NAME ("prscan")
167 /* Local prototypes */
170 PrPreprocessInputFile (
175 char *DirectiveToken,
202 char *DirectiveName);
215 * Supported preprocessor directives
216 * Each entry is of the form "Name, ArgumentCount"
218 static const PR_DIRECTIVE_INFO Gbl_DirectiveInfo[] =
221 {"elif", 0}, /* Converted to #else..#if internally */
228 {"include", 0}, /* Argument is not standard format, so just use 0 here */
229 {"includebuffer", 0}, /* Argument is not standard format, so just use 0 here */
237 /* This table must match ordering of above table exactly */
239 enum Gbl_DirectiveIndexes
241 PR_DIRECTIVE_DEFINE = 0,
249 PR_DIRECTIVE_INCLUDE,
250 PR_DIRECTIVE_INCLUDEBUFFER,
257 #define ASL_DIRECTIVE_NOT_FOUND -1
260 /*******************************************************************************
262 * FUNCTION: PrInitializePreprocessor
268 * DESCRIPTION: Startup initialization for the Preprocessor.
270 ******************************************************************************/
273 PrInitializePreprocessor (
276 /* Init globals and the list of #defines */
278 PrInitializeGlobals ();
279 Gbl_DefineList = NULL;
283 /*******************************************************************************
285 * FUNCTION: PrInitializeGlobals
291 * DESCRIPTION: Initialize globals for the Preprocessor. Used for startuup
292 * initialization and re-initialization between compiles during
293 * a multiple source file compile.
295 ******************************************************************************/
298 PrInitializeGlobals (
303 Gbl_InputFileList = NULL;
304 Gbl_CurrentLineNumber = 1;
305 Gbl_PreprocessorLineNumber = 1;
306 Gbl_PreprocessorError = FALSE;
308 /* These are used to track #if/#else blocks (possibly nested) */
311 Gbl_IgnoringThisCodeBlock = FALSE;
312 Gbl_DirectiveStack = NULL;
316 /*******************************************************************************
318 * FUNCTION: PrTerminatePreprocessor
324 * DESCRIPTION: Termination of the preprocessor. Delete lists. Keep any
325 * defines that were specified on the command line, in order to
326 * support multiple compiles with a single compiler invocation.
328 ******************************************************************************/
331 PrTerminatePreprocessor (
334 PR_DEFINE_INFO *DefineInfo;
338 * The persistent defines (created on the command line) are always at the
339 * end of the list. We save them.
341 while ((Gbl_DefineList) && (!Gbl_DefineList->Persist))
343 DefineInfo = Gbl_DefineList;
344 Gbl_DefineList = DefineInfo->Next;
346 ACPI_FREE (DefineInfo->Replacement);
347 ACPI_FREE (DefineInfo->Identifier);
348 ACPI_FREE (DefineInfo);
353 /*******************************************************************************
355 * FUNCTION: PrDoPreprocess
361 * DESCRIPTION: Main entry point for the iASL Preprocessor. Input file must
362 * be already open. Handles multiple input files via the
363 * #include directive.
365 ******************************************************************************/
371 BOOLEAN MoreInputFiles;
374 DbgPrint (ASL_DEBUG_OUTPUT, "Starting preprocessing phase\n\n");
377 FlSeekFile (ASL_FILE_INPUT, 0);
378 PrDumpPredefinedNames ();
380 /* Main preprocessor loop, handles include files */
384 PrPreprocessInputFile ();
385 MoreInputFiles = PrPopInputFileStack ();
387 } while (MoreInputFiles);
389 /* Point compiler input to the new preprocessor output file (.pre) */
391 FlCloseFile (ASL_FILE_INPUT);
392 Gbl_Files[ASL_FILE_INPUT].Handle = Gbl_Files[ASL_FILE_PREPROCESSOR].Handle;
393 AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
395 /* Reset globals to allow compiler to run */
397 FlSeekFile (ASL_FILE_INPUT, 0);
398 if (!Gbl_PreprocessOnly)
400 Gbl_CurrentLineNumber = 0;
403 DbgPrint (ASL_DEBUG_OUTPUT, "Preprocessing phase complete \n\n");
407 /*******************************************************************************
409 * FUNCTION: PrPreprocessInputFile
415 * DESCRIPTION: Preprocess one entire file, line-by-line.
417 * Input: Raw user ASL from ASL_FILE_INPUT
418 * Output: Preprocessed file written to ASL_FILE_PREPROCESSOR and
419 * (optionally) ASL_FILE_PREPROCESSOR_USER
421 ******************************************************************************/
424 PrPreprocessInputFile (
430 PR_DEFINE_INFO *DefineInfo;
431 ACPI_SIZE TokenOffset;
436 PrGetNextLineInit ();
438 /* Scan source line-by-line and process directives. Then write the .i file */
440 while ((Status = PrGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF)
442 Gbl_CurrentLineNumber++;
443 Gbl_LogicalLineNumber++;
445 if (Status == ASL_IGNORE_LINE)
447 goto WriteEntireLine;
450 /* Need a copy of the input line for strok() */
452 strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer);
453 Token = PrGetNextToken (Gbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next);
456 /* All preprocessor directives must begin with '#' */
458 if (Token && (*Token == '#'))
460 if (strlen (Token) == 1)
462 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
466 Token++; /* Skip leading # */
469 /* Execute the directive, do not write line to output file */
471 PrDoDirective (Token, &Next);
476 * If we are currently within the part of an IF/ELSE block that is
477 * FALSE, ignore the line and do not write it to the output file.
478 * This continues until an #else or #endif is encountered.
480 if (Gbl_IgnoringThisCodeBlock)
485 /* Match and replace all #defined names within this source line */
489 DefineInfo = PrMatchDefine (Token);
492 if (DefineInfo->Body)
494 /* This is a macro */
496 DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
497 "Matched Macro: %s->%s\n",
498 Gbl_CurrentLineNumber, DefineInfo->Identifier,
499 DefineInfo->Replacement);
501 PrDoMacroInvocation (Gbl_MainTokenBuffer, Token,
506 ReplaceString = DefineInfo->Replacement;
508 /* Replace the name in the original line buffer */
510 TokenOffset = Token - Gbl_MainTokenBuffer + OffsetAdjust;
512 &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token),
513 ReplaceString, strlen (ReplaceString));
515 /* Adjust for length difference between old and new name length */
517 OffsetAdjust += strlen (ReplaceString) - strlen (Token);
519 DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
520 "Matched #define: %s->%s\n",
521 Gbl_CurrentLineNumber, Token,
522 *ReplaceString ? ReplaceString : "(NULL STRING)");
526 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
529 Gbl_PreprocessorLineNumber++;
534 * Now we can write the possibly modified source line to the
535 * preprocessor file(s).
537 FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer,
538 strlen (Gbl_CurrentLineBuffer));
543 /*******************************************************************************
545 * FUNCTION: PrDoDirective
547 * PARAMETERS: Directive - Pointer to directive name token
548 * Next - "Next" buffer from GetNextToken
552 * DESCRIPTION: Main processing for all preprocessor directives
554 ******************************************************************************/
558 char *DirectiveToken,
561 char *Token = Gbl_MainTokenBuffer;
565 ACPI_SIZE TokenOffset;
575 Directive = PrMatchDirective (DirectiveToken);
576 if (Directive == ASL_DIRECTIVE_NOT_FOUND)
578 PrError (ASL_ERROR, ASL_MSG_UNKNOWN_DIRECTIVE,
579 THIS_TOKEN_OFFSET (DirectiveToken));
581 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
582 "#%s: Unknown directive\n",
583 Gbl_CurrentLineNumber, DirectiveToken);
588 * Emit a line directive into the preprocessor file (.pre) after
589 * every matched directive. This is passed through to the compiler
590 * so that error/warning messages are kept in sync with the
591 * original source file.
593 FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\" // #%s\n",
594 Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename,
595 Gbl_DirectiveInfo[Directive].Name);
598 * If we are currently ignoring this block and we encounter a #else or
599 * #elif, we must ignore their blocks also if the parent block is also
602 if (Gbl_IgnoringThisCodeBlock)
606 case PR_DIRECTIVE_ELSE:
607 case PR_DIRECTIVE_ELIF:
609 if (Gbl_DirectiveStack &&
610 Gbl_DirectiveStack->IgnoringThisCodeBlock)
612 PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name);
623 * Need to always check for #else, #elif, #endif regardless of
624 * whether we are ignoring the current code block, since these
625 * are conditional code block terminators.
629 case PR_DIRECTIVE_ELSE:
631 Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock);
632 PrDbgPrint ("Executing", "else block");
635 case PR_DIRECTIVE_ELIF:
637 Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock);
638 Directive = PR_DIRECTIVE_IF;
640 if (Gbl_IgnoringThisCodeBlock == TRUE)
642 /* Not executing the ELSE part -- all done here */
643 PrDbgPrint ("Ignoring", "elif block");
648 * After this, we will execute the IF part further below.
649 * First, however, pop off the original #if directive.
651 if (ACPI_FAILURE (PrPopDirective ()))
653 PrError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
654 THIS_TOKEN_OFFSET (DirectiveToken));
657 PrDbgPrint ("Executing", "elif block");
660 case PR_DIRECTIVE_ENDIF:
662 PrDbgPrint ("Executing", "endif");
664 /* Pop the owning #if/#ifdef/#ifndef */
666 if (ACPI_FAILURE (PrPopDirective ()))
668 PrError (ASL_ERROR, ASL_MSG_ENDIF_MISMATCH,
669 THIS_TOKEN_OFFSET (DirectiveToken));
677 /* Most directives have at least one argument */
679 if (Gbl_DirectiveInfo[Directive].ArgCount >= 1)
681 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
688 if (Gbl_DirectiveInfo[Directive].ArgCount >= 2)
690 Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
698 * At this point, if we are ignoring the current code block,
699 * do not process any more directives (i.e., ignore them also.)
700 * For "if" style directives, open/push a new block anyway. We
701 * must do this to keep track of #endif directives
703 if (Gbl_IgnoringThisCodeBlock)
707 case PR_DIRECTIVE_IF:
708 case PR_DIRECTIVE_IFDEF:
709 case PR_DIRECTIVE_IFNDEF:
711 PrPushDirective (Directive, Token);
712 PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name);
723 * Execute the directive
725 PrDbgPrint ("Begin execution", Gbl_DirectiveInfo[Directive].Name);
729 case PR_DIRECTIVE_IF:
731 TokenOffset = Token - Gbl_MainTokenBuffer;
733 /* Need to expand #define macros in the expression string first */
735 Status = PrResolveIntegerExpression (
736 &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
737 if (ACPI_FAILURE (Status))
742 PrPushDirective (Directive, Token);
745 Gbl_IgnoringThisCodeBlock = TRUE;
748 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
749 "Resolved #if: %8.8X%8.8X %s\n",
750 Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value),
751 Gbl_IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>");
754 case PR_DIRECTIVE_IFDEF:
756 PrPushDirective (Directive, Token);
757 if (!PrMatchDefine (Token))
759 Gbl_IgnoringThisCodeBlock = TRUE;
762 PrDbgPrint ("Evaluated", "ifdef");
765 case PR_DIRECTIVE_IFNDEF:
767 PrPushDirective (Directive, Token);
768 if (PrMatchDefine (Token))
770 Gbl_IgnoringThisCodeBlock = TRUE;
773 PrDbgPrint ("Evaluated", "ifndef");
776 case PR_DIRECTIVE_DEFINE:
778 * By definition, if first char after the name is a paren,
779 * this is a function macro.
781 TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token);
782 if (*(&Gbl_CurrentLineBuffer[TokenOffset]) == '(')
784 #ifndef MACROS_SUPPORTED
786 "%s ERROR - line %u: #define macros are not supported yet\n",
787 Gbl_CurrentLineBuffer, Gbl_LogicalLineNumber);
790 PrAddMacro (Token, Next);
795 /* Use the remainder of the line for the #define */
800 while ((*Token2 == ' ') || (*Token2 == '\t'))
818 Token2 = PrGetNextToken (NULL, "\n", /*PR_TOKEN_SEPARATORS,*/ Next);
824 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
825 "New #define: %s->%s\n",
826 Gbl_LogicalLineNumber, Token, Token2);
828 PrAddDefine (Token, Token2, FALSE);
832 case PR_DIRECTIVE_ERROR:
834 /* Note: No macro expansion */
836 PrError (ASL_ERROR, ASL_MSG_ERROR_DIRECTIVE,
837 THIS_TOKEN_OFFSET (Token));
840 Gbl_NextError = Gbl_ErrorLog;
844 case PR_DIRECTIVE_INCLUDE:
846 Token = PrGetNextToken (NULL, " \"<>", Next);
852 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
853 "Start #include file \"%s\"\n", Gbl_CurrentLineNumber,
854 Token, Gbl_CurrentLineNumber);
856 PrDoIncludeFile (Token);
859 case PR_DIRECTIVE_INCLUDEBUFFER:
861 Token = PrGetNextToken (NULL, " \"<>", Next);
867 Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
873 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
874 "Start #includebuffer input from file \"%s\", buffer name %s\n",
875 Gbl_CurrentLineNumber, Token, Token2);
877 PrDoIncludeBuffer (Token, Token2);
880 case PR_DIRECTIVE_LINE:
882 TokenOffset = Token - Gbl_MainTokenBuffer;
884 Status = PrResolveIntegerExpression (
885 &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
886 if (ACPI_FAILURE (Status))
891 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
892 "User #line invocation %s\n", Gbl_CurrentLineNumber,
895 Gbl_CurrentLineNumber = (UINT32) Value;
897 /* Emit #line into the preprocessor file */
899 FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n",
900 Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename);
903 case PR_DIRECTIVE_PRAGMA:
905 if (!strcmp (Token, "disable"))
907 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
913 TokenOffset = Token - Gbl_MainTokenBuffer;
914 AslDisableException (&Gbl_CurrentLineBuffer[TokenOffset]);
916 else if (!strcmp (Token, "message"))
918 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
924 TokenOffset = Token - Gbl_MainTokenBuffer;
925 AcpiOsPrintf ("%s\n", &Gbl_CurrentLineBuffer[TokenOffset]);
929 PrError (ASL_ERROR, ASL_MSG_UNKNOWN_PRAGMA,
930 THIS_TOKEN_OFFSET (Token));
936 case PR_DIRECTIVE_UNDEF:
938 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
939 "#undef: %s\n", Gbl_CurrentLineNumber, Token);
941 PrRemoveDefine (Token);
944 case PR_DIRECTIVE_WARNING:
946 PrError (ASL_WARNING, ASL_MSG_WARNING_DIRECTIVE,
947 THIS_TOKEN_OFFSET (Token));
950 Gbl_NextError = Gbl_ErrorLog;
955 /* Should never get here */
956 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
957 "Unrecognized directive: %u\n",
958 Gbl_CurrentLineNumber, Directive);
966 PrError (ASL_ERROR, ASL_MSG_DIRECTIVE_SYNTAX,
967 THIS_TOKEN_OFFSET (DirectiveToken));
972 /*******************************************************************************
974 * FUNCTION: PrGetNextLine, PrGetNextLineInit
976 * PARAMETERS: Handle - Open file handle for the source file
978 * RETURN: Status of the GetLine operation:
979 * AE_OK - Normal line, OK status
980 * ASL_IGNORE_LINE - Line is blank or part of a multi-line
982 * ASL_EOF - End-of-file reached
984 * DESCRIPTION: Get the next text line from the input file. Does not strip
987 ******************************************************************************/
989 #define PR_NORMAL_TEXT 0
990 #define PR_MULTI_LINE_COMMENT 1
991 #define PR_SINGLE_LINE_COMMENT 2
992 #define PR_QUOTED_STRING 3
994 static UINT8 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
1000 AcpiGbl_LineScanState = 0;
1012 /* Always clear the global line buffer */
1014 memset (Gbl_CurrentLineBuffer, 0, Gbl_LineBufferSize);
1018 * If line is too long, expand the line buffers. Also increases
1019 * Gbl_LineBufferSize.
1021 if (i >= Gbl_LineBufferSize)
1023 UtExpandLineBuffers ();
1031 * On EOF: If there is anything in the line buffer, terminate
1032 * it with a newline, and catch the EOF on the next call
1037 Gbl_CurrentLineBuffer[i] = '\n';
1044 /* Update state machine as necessary */
1046 switch (AcpiGbl_LineScanState)
1048 case PR_NORMAL_TEXT:
1050 /* Check for multi-line comment start */
1052 if ((PreviousChar == '/') && (c == '*'))
1054 AcpiGbl_LineScanState = PR_MULTI_LINE_COMMENT;
1057 /* Check for single-line comment start */
1059 else if ((PreviousChar == '/') && (c == '/'))
1061 AcpiGbl_LineScanState = PR_SINGLE_LINE_COMMENT;
1064 /* Check for quoted string start */
1066 else if (PreviousChar == '"')
1068 AcpiGbl_LineScanState = PR_QUOTED_STRING;
1072 case PR_QUOTED_STRING:
1074 if (PreviousChar == '"')
1076 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
1080 case PR_MULTI_LINE_COMMENT:
1082 /* Check for multi-line comment end */
1084 if ((PreviousChar == '*') && (c == '/'))
1086 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
1090 case PR_SINGLE_LINE_COMMENT: /* Just ignore text until EOL */
1095 /* Always copy the character into line buffer */
1097 Gbl_CurrentLineBuffer[i] = (char) c;
1100 /* Always exit on end-of-line */
1104 /* Handle multi-line comments */
1106 if (AcpiGbl_LineScanState == PR_MULTI_LINE_COMMENT)
1108 return (ASL_IGNORE_LINE);
1111 /* End of single-line comment */
1113 if (AcpiGbl_LineScanState == PR_SINGLE_LINE_COMMENT)
1115 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
1123 return (ASL_IGNORE_LINE);
1132 /*******************************************************************************
1134 * FUNCTION: PrMatchDirective
1136 * PARAMETERS: Directive - Pointer to directive name token
1138 * RETURN: Index into command array, -1 if not found
1140 * DESCRIPTION: Lookup the incoming directive in the known directives table.
1142 ******************************************************************************/
1151 if (!Directive || Directive[0] == 0)
1153 return (ASL_DIRECTIVE_NOT_FOUND);
1156 for (i = 0; Gbl_DirectiveInfo[i].Name; i++)
1158 if (!strcmp (Gbl_DirectiveInfo[i].Name, Directive))
1164 return (ASL_DIRECTIVE_NOT_FOUND); /* Command not recognized */
1168 /*******************************************************************************
1170 * FUNCTION: PrPushDirective
1172 * PARAMETERS: Directive - Encoded directive ID
1173 * Argument - String containing argument to the
1178 * DESCRIPTION: Push an item onto the directive stack. Used for processing
1179 * nested #if/#else type conditional compilation directives.
1180 * Specifically: Used on detection of #if/#ifdef/#ifndef to open
1183 ******************************************************************************/
1190 DIRECTIVE_INFO *Info;
1193 /* Allocate and populate a stack info item */
1195 Info = ACPI_ALLOCATE (sizeof (DIRECTIVE_INFO));
1197 Info->Next = Gbl_DirectiveStack;
1198 Info->Directive = Directive;
1199 Info->IgnoringThisCodeBlock = Gbl_IgnoringThisCodeBlock;
1200 strncpy (Info->Argument, Argument, MAX_ARGUMENT_LENGTH);
1202 DbgPrint (ASL_DEBUG_OUTPUT,
1203 "Pr(%.4u) - [%u %s] %*s Pushed [#%s %s]: IgnoreFlag = %s\n",
1204 Gbl_CurrentLineNumber, Gbl_IfDepth,
1205 Gbl_IgnoringThisCodeBlock ? "I" : "E",
1206 Gbl_IfDepth * 4, " ",
1207 Gbl_DirectiveInfo[Directive].Name,
1208 Argument, Gbl_IgnoringThisCodeBlock ? "TRUE" : "FALSE");
1212 Gbl_DirectiveStack = Info;
1217 /*******************************************************************************
1219 * FUNCTION: PrPopDirective
1223 * RETURN: Status. Error if the stack is empty.
1225 * DESCRIPTION: Pop an item off the directive stack. Used for processing
1226 * nested #if/#else type conditional compilation directives.
1227 * Specifically: Used on detection of #elif and #endif to remove
1228 * the original #if/#ifdef/#ifndef from the stack and close
1231 ******************************************************************************/
1237 DIRECTIVE_INFO *Info;
1240 /* Check for empty stack */
1242 Info = Gbl_DirectiveStack;
1248 /* Pop one item, keep globals up-to-date */
1251 Gbl_IgnoringThisCodeBlock = Info->IgnoringThisCodeBlock;
1252 Gbl_DirectiveStack = Info->Next;
1254 DbgPrint (ASL_DEBUG_OUTPUT,
1255 "Pr(%.4u) - [%u %s] %*s Popped [#%s %s]: IgnoreFlag now = %s\n",
1256 Gbl_CurrentLineNumber, Gbl_IfDepth,
1257 Gbl_IgnoringThisCodeBlock ? "I" : "E",
1258 Gbl_IfDepth * 4, " ",
1259 Gbl_DirectiveInfo[Info->Directive].Name,
1260 Info->Argument, Gbl_IgnoringThisCodeBlock ? "TRUE" : "FALSE");
1267 /*******************************************************************************
1269 * FUNCTION: PrDbgPrint
1271 * PARAMETERS: Action - Action being performed
1272 * DirectiveName - Directive being processed
1276 * DESCRIPTION: Special debug print for directive processing.
1278 ******************************************************************************/
1283 char *DirectiveName)
1286 DbgPrint (ASL_DEBUG_OUTPUT, "Pr(%.4u) - [%u %s] "
1287 "%*s %s #%s, IfDepth %u\n",
1288 Gbl_CurrentLineNumber, Gbl_IfDepth,
1289 Gbl_IgnoringThisCodeBlock ? "I" : "E",
1290 Gbl_IfDepth * 4, " ",
1291 Action, DirectiveName, Gbl_IfDepth);
1295 /*******************************************************************************
1297 * FUNCTION: PrDoIncludeFile
1299 * PARAMETERS: Pathname - Name of the input file
1303 * DESCRIPTION: Open an include file, from #include.
1305 ******************************************************************************/
1314 (void) PrOpenIncludeFile (Pathname, "r", &FullPathname);
1318 /*******************************************************************************
1320 * FUNCTION: PrDoIncludeBuffer
1322 * PARAMETERS: Pathname - Name of the input binary file
1323 * BufferName - ACPI namepath of the buffer
1327 * DESCRIPTION: Create an ACPI buffer object from a binary file. The contents
1328 * of the file are emitted into the buffer object as ascii
1329 * hex data. From #includebuffer.
1331 ******************************************************************************/
1339 FILE *BinaryBufferFile;
1344 BinaryBufferFile = PrOpenIncludeFile (Pathname, "rb", &FullPathname);
1345 if (!BinaryBufferFile)
1350 /* Emit "Name (XXXX, Buffer() {" header */
1352 FlPrintFile (ASL_FILE_PREPROCESSOR, "Name (%s, Buffer()\n{", BufferName);
1354 /* Dump the entire file in ascii hex format */
1356 while (fread (&c, 1, 1, BinaryBufferFile))
1360 FlPrintFile (ASL_FILE_PREPROCESSOR, "\n ", c);
1363 FlPrintFile (ASL_FILE_PREPROCESSOR, " 0x%2.2X,", c);
1367 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
1368 "#includebuffer: read %u bytes from %s\n",
1369 Gbl_CurrentLineNumber, i, FullPathname);
1371 /* Close the Name() operator */
1373 FlPrintFile (ASL_FILE_PREPROCESSOR, "\n})\n", BufferName);
1374 fclose (BinaryBufferFile);