1 /******************************************************************************
3 * Module Name: prscan - Preprocessor start-up and file scan module
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, 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 "aslcompiler.h"
159 * No nested macros, maybe never
160 * Implement ASL "Include" as well as "#include" here?
162 #define _COMPONENT ASL_PREPROCESSOR
163 ACPI_MODULE_NAME ("prscan")
166 /* Local prototypes */
169 PrPreprocessInputFile (
174 char *DirectiveToken
,
201 char *DirectiveName
);
214 * Supported preprocessor directives
215 * Each entry is of the form "Name, ArgumentCount"
217 static const PR_DIRECTIVE_INFO AslGbl_DirectiveInfo
[] =
220 {"elif", 0}, /* Converted to #else..#if internally */
227 {"include", 0}, /* Argument is not standard format, so just use 0 here */
228 {"includebuffer", 0}, /* Argument is not standard format, so just use 0 here */
236 /* This table must match ordering of above table exactly */
238 enum Gbl_DirectiveIndexes
240 PR_DIRECTIVE_DEFINE
= 0,
248 PR_DIRECTIVE_INCLUDE
,
249 PR_DIRECTIVE_INCLUDEBUFFER
,
256 #define ASL_DIRECTIVE_NOT_FOUND -1
259 /*******************************************************************************
261 * FUNCTION: PrInitializePreprocessor
267 * DESCRIPTION: Startup initialization for the Preprocessor.
269 ******************************************************************************/
272 PrInitializePreprocessor (
275 /* Init globals and the list of #defines */
277 PrInitializeGlobals ();
278 AslGbl_DefineList
= NULL
;
282 /*******************************************************************************
284 * FUNCTION: PrInitializeGlobals
290 * DESCRIPTION: Initialize globals for the Preprocessor. Used for startuup
291 * initialization and re-initialization between compiles during
292 * a multiple source file compile.
294 ******************************************************************************/
297 PrInitializeGlobals (
302 AslGbl_InputFileList
= NULL
;
303 AslGbl_CurrentLineNumber
= 1;
304 AslGbl_PreprocessorLineNumber
= 1;
305 AslGbl_PreprocessorError
= FALSE
;
307 /* These are used to track #if/#else blocks (possibly nested) */
310 AslGbl_IgnoringThisCodeBlock
= FALSE
;
311 AslGbl_DirectiveStack
= NULL
;
315 /*******************************************************************************
317 * FUNCTION: PrTerminatePreprocessor
323 * DESCRIPTION: Termination of the preprocessor. Delete lists. Keep any
324 * defines that were specified on the command line, in order to
325 * support multiple compiles with a single compiler invocation.
327 ******************************************************************************/
330 PrTerminatePreprocessor (
333 PR_DEFINE_INFO
*DefineInfo
;
337 * The persistent defines (created on the command line) are always at the
338 * end of the list. We save them.
340 while ((AslGbl_DefineList
) && (!AslGbl_DefineList
->Persist
))
342 DefineInfo
= AslGbl_DefineList
;
343 AslGbl_DefineList
= DefineInfo
->Next
;
345 ACPI_FREE (DefineInfo
->Replacement
);
346 ACPI_FREE (DefineInfo
->Identifier
);
347 ACPI_FREE (DefineInfo
);
352 /*******************************************************************************
354 * FUNCTION: PrDoPreprocess
360 * DESCRIPTION: Main entry point for the iASL Preprocessor. Input file must
361 * be already open. Handles multiple input files via the
362 * #include directive.
364 ******************************************************************************/
370 BOOLEAN MoreInputFiles
;
373 DbgPrint (ASL_DEBUG_OUTPUT
, "Starting preprocessing phase\n\n");
376 FlSeekFile (ASL_FILE_INPUT
, 0);
377 PrDumpPredefinedNames ();
379 /* Main preprocessor loop, handles include files */
383 PrPreprocessInputFile ();
384 MoreInputFiles
= PrPopInputFileStack ();
386 } while (MoreInputFiles
);
388 /* Point compiler input to the new preprocessor output file (.pre) */
390 FlCloseFile (ASL_FILE_INPUT
);
391 AslGbl_Files
[ASL_FILE_INPUT
].Handle
= AslGbl_Files
[ASL_FILE_PREPROCESSOR
].Handle
;
392 AslCompilerin
= AslGbl_Files
[ASL_FILE_INPUT
].Handle
;
394 /* Reset globals to allow compiler to run */
396 FlSeekFile (ASL_FILE_INPUT
, 0);
397 if (!AslGbl_PreprocessOnly
)
399 AslGbl_CurrentLineNumber
= 0;
402 DbgPrint (ASL_DEBUG_OUTPUT
, "Preprocessing phase complete \n\n");
406 /*******************************************************************************
408 * FUNCTION: PrPreprocessInputFile
414 * DESCRIPTION: Preprocess one entire file, line-by-line.
416 * Input: Raw user ASL from ASL_FILE_INPUT
417 * Output: Preprocessed file written to ASL_FILE_PREPROCESSOR and
418 * (optionally) ASL_FILE_PREPROCESSOR_USER
420 ******************************************************************************/
423 PrPreprocessInputFile (
429 PR_DEFINE_INFO
*DefineInfo
;
430 ACPI_SIZE TokenOffset
;
435 PrGetNextLineInit ();
437 /* Scan source line-by-line and process directives. Then write the .i file */
439 while ((Status
= PrGetNextLine (AslGbl_Files
[ASL_FILE_INPUT
].Handle
)) != ASL_EOF
)
441 AslGbl_CurrentLineNumber
++;
442 AslGbl_LogicalLineNumber
++;
444 if (Status
== ASL_IGNORE_LINE
)
446 goto WriteEntireLine
;
449 /* Need a copy of the input line for strok() */
451 strcpy (AslGbl_MainTokenBuffer
, AslGbl_CurrentLineBuffer
);
452 Token
= PrGetNextToken (AslGbl_MainTokenBuffer
, PR_TOKEN_SEPARATORS
, &Next
);
455 /* All preprocessor directives must begin with '#' */
457 if (Token
&& (*Token
== '#'))
459 if (strlen (Token
) == 1)
461 Token
= PrGetNextToken (NULL
, PR_TOKEN_SEPARATORS
, &Next
);
465 Token
++; /* Skip leading # */
468 /* Execute the directive, do not write line to output file */
470 PrDoDirective (Token
, &Next
);
475 * If we are currently within the part of an IF/ELSE block that is
476 * FALSE, ignore the line and do not write it to the output file.
477 * This continues until an #else or #endif is encountered.
479 if (AslGbl_IgnoringThisCodeBlock
)
484 /* Match and replace all #defined names within this source line */
488 DefineInfo
= PrMatchDefine (Token
);
491 if (DefineInfo
->Body
)
493 /* This is a macro */
495 DbgPrint (ASL_DEBUG_OUTPUT
, PR_PREFIX_ID
496 "Matched Macro: %s->%s\n",
497 AslGbl_CurrentLineNumber
, DefineInfo
->Identifier
,
498 DefineInfo
->Replacement
);
500 PrDoMacroInvocation (AslGbl_MainTokenBuffer
, Token
,
505 ReplaceString
= DefineInfo
->Replacement
;
507 /* Replace the name in the original line buffer */
509 TokenOffset
= Token
- AslGbl_MainTokenBuffer
+ OffsetAdjust
;
511 &AslGbl_CurrentLineBuffer
[TokenOffset
], strlen (Token
),
512 ReplaceString
, strlen (ReplaceString
));
514 /* Adjust for length difference between old and new name length */
516 OffsetAdjust
+= strlen (ReplaceString
) - strlen (Token
);
518 DbgPrint (ASL_DEBUG_OUTPUT
, PR_PREFIX_ID
519 "Matched #define: %s->%s\n",
520 AslGbl_CurrentLineNumber
, Token
,
521 *ReplaceString
? ReplaceString
: "(NULL STRING)");
525 Token
= PrGetNextToken (NULL
, PR_TOKEN_SEPARATORS
, &Next
);
528 AslGbl_PreprocessorLineNumber
++;
533 * Now we can write the possibly modified source line to the
534 * preprocessor file(s).
536 FlWriteFile (ASL_FILE_PREPROCESSOR
, AslGbl_CurrentLineBuffer
,
537 strlen (AslGbl_CurrentLineBuffer
));
542 /*******************************************************************************
544 * FUNCTION: PrDoDirective
546 * PARAMETERS: Directive - Pointer to directive name token
547 * Next - "Next" buffer from GetNextToken
551 * DESCRIPTION: Main processing for all preprocessor directives
553 ******************************************************************************/
557 char *DirectiveToken
,
560 char *Token
= AslGbl_MainTokenBuffer
;
564 ACPI_SIZE TokenOffset
;
574 Directive
= PrMatchDirective (DirectiveToken
);
575 if (Directive
== ASL_DIRECTIVE_NOT_FOUND
)
577 PrError (ASL_ERROR
, ASL_MSG_UNKNOWN_DIRECTIVE
,
578 THIS_TOKEN_OFFSET (DirectiveToken
));
580 DbgPrint (ASL_PARSE_OUTPUT
, PR_PREFIX_ID
581 "#%s: Unknown directive\n",
582 AslGbl_CurrentLineNumber
, DirectiveToken
);
587 * Emit a line directive into the preprocessor file (.pre) after
588 * every matched directive. This is passed through to the compiler
589 * so that error/warning messages are kept in sync with the
590 * original source file.
592 FlPrintFile (ASL_FILE_PREPROCESSOR
, "#line %u \"%s\" // #%s\n",
593 AslGbl_CurrentLineNumber
, AslGbl_Files
[ASL_FILE_INPUT
].Filename
,
594 AslGbl_DirectiveInfo
[Directive
].Name
);
597 * If we are currently ignoring this block and we encounter a #else or
598 * #elif, we must ignore their blocks also if the parent block is also
601 if (AslGbl_IgnoringThisCodeBlock
)
605 case PR_DIRECTIVE_ELSE
:
606 case PR_DIRECTIVE_ELIF
:
608 if (AslGbl_DirectiveStack
&&
609 AslGbl_DirectiveStack
->IgnoringThisCodeBlock
)
611 PrDbgPrint ("Ignoring", AslGbl_DirectiveInfo
[Directive
].Name
);
622 * Need to always check for #else, #elif, #endif regardless of
623 * whether we are ignoring the current code block, since these
624 * are conditional code block terminators.
628 case PR_DIRECTIVE_ELSE
:
630 AslGbl_IgnoringThisCodeBlock
= !(AslGbl_IgnoringThisCodeBlock
);
631 PrDbgPrint ("Executing", "else block");
634 case PR_DIRECTIVE_ELIF
:
636 AslGbl_IgnoringThisCodeBlock
= !(AslGbl_IgnoringThisCodeBlock
);
637 Directive
= PR_DIRECTIVE_IF
;
639 if (AslGbl_IgnoringThisCodeBlock
== TRUE
)
641 /* Not executing the ELSE part -- all done here */
642 PrDbgPrint ("Ignoring", "elif block");
647 * After this, we will execute the IF part further below.
648 * First, however, pop off the original #if directive.
650 if (ACPI_FAILURE (PrPopDirective ()))
652 PrError (ASL_ERROR
, ASL_MSG_COMPILER_INTERNAL
,
653 THIS_TOKEN_OFFSET (DirectiveToken
));
656 PrDbgPrint ("Executing", "elif block");
659 case PR_DIRECTIVE_ENDIF
:
661 PrDbgPrint ("Executing", "endif");
663 /* Pop the owning #if/#ifdef/#ifndef */
665 if (ACPI_FAILURE (PrPopDirective ()))
667 PrError (ASL_ERROR
, ASL_MSG_ENDIF_MISMATCH
,
668 THIS_TOKEN_OFFSET (DirectiveToken
));
676 /* Most directives have at least one argument */
678 if (AslGbl_DirectiveInfo
[Directive
].ArgCount
>= 1)
680 Token
= PrGetNextToken (NULL
, PR_TOKEN_SEPARATORS
, Next
);
687 if (AslGbl_DirectiveInfo
[Directive
].ArgCount
>= 2)
689 Token2
= PrGetNextToken (NULL
, PR_TOKEN_SEPARATORS
, Next
);
697 * At this point, if we are ignoring the current code block,
698 * do not process any more directives (i.e., ignore them also.)
699 * For "if" style directives, open/push a new block anyway. We
700 * must do this to keep track of #endif directives
702 if (AslGbl_IgnoringThisCodeBlock
)
706 case PR_DIRECTIVE_IF
:
707 case PR_DIRECTIVE_IFDEF
:
708 case PR_DIRECTIVE_IFNDEF
:
710 PrPushDirective (Directive
, Token
);
711 PrDbgPrint ("Ignoring", AslGbl_DirectiveInfo
[Directive
].Name
);
722 * Execute the directive
724 PrDbgPrint ("Begin execution", AslGbl_DirectiveInfo
[Directive
].Name
);
728 case PR_DIRECTIVE_IF
:
730 TokenOffset
= Token
- AslGbl_MainTokenBuffer
;
732 /* Need to expand #define macros in the expression string first */
734 Status
= PrResolveIntegerExpression (
735 &AslGbl_CurrentLineBuffer
[TokenOffset
-1], &Value
);
736 if (ACPI_FAILURE (Status
))
741 PrPushDirective (Directive
, Token
);
744 AslGbl_IgnoringThisCodeBlock
= TRUE
;
747 DbgPrint (ASL_PARSE_OUTPUT
, PR_PREFIX_ID
748 "Resolved #if: %8.8X%8.8X %s\n",
749 AslGbl_CurrentLineNumber
, ACPI_FORMAT_UINT64 (Value
),
750 AslGbl_IgnoringThisCodeBlock
? "<Skipping Block>" : "<Executing Block>");
753 case PR_DIRECTIVE_IFDEF
:
755 PrPushDirective (Directive
, Token
);
756 if (!PrMatchDefine (Token
))
758 AslGbl_IgnoringThisCodeBlock
= TRUE
;
761 PrDbgPrint ("Evaluated", "ifdef");
764 case PR_DIRECTIVE_IFNDEF
:
766 PrPushDirective (Directive
, Token
);
767 if (PrMatchDefine (Token
))
769 AslGbl_IgnoringThisCodeBlock
= TRUE
;
772 PrDbgPrint ("Evaluated", "ifndef");
775 case PR_DIRECTIVE_DEFINE
:
777 * By definition, if first char after the name is a paren,
778 * this is a function macro.
780 TokenOffset
= Token
- AslGbl_MainTokenBuffer
+ strlen (Token
);
781 if (*(&AslGbl_CurrentLineBuffer
[TokenOffset
]) == '(')
783 #ifndef MACROS_SUPPORTED
785 "%s ERROR - line %u: #define macros are not supported yet\n",
786 AslGbl_CurrentLineBuffer
, AslGbl_LogicalLineNumber
);
789 PrAddMacro (Token
, Next
);
794 /* Use the remainder of the line for the #define */
799 while ((*Token2
== ' ') || (*Token2
== '\t'))
817 Token2
= PrGetNextToken (NULL
, "\n", /*PR_TOKEN_SEPARATORS,*/ Next
);
823 DbgPrint (ASL_PARSE_OUTPUT
, PR_PREFIX_ID
824 "New #define: %s->%s\n",
825 AslGbl_LogicalLineNumber
, Token
, Token2
);
827 PrAddDefine (Token
, Token2
, FALSE
);
831 case PR_DIRECTIVE_ERROR
:
833 /* Note: No macro expansion */
835 PrError (ASL_ERROR
, ASL_MSG_ERROR_DIRECTIVE
,
836 THIS_TOKEN_OFFSET (Token
));
838 AslGbl_SourceLine
= 0;
839 AslGbl_NextError
= AslGbl_ErrorLog
;
843 case PR_DIRECTIVE_INCLUDE
:
845 Token
= PrGetNextToken (NULL
, " \"<>", Next
);
851 DbgPrint (ASL_PARSE_OUTPUT
, PR_PREFIX_ID
852 "Start #include file \"%s\"\n", AslGbl_CurrentLineNumber
,
853 Token
, AslGbl_CurrentLineNumber
);
855 PrDoIncludeFile (Token
);
858 case PR_DIRECTIVE_INCLUDEBUFFER
:
860 Token
= PrGetNextToken (NULL
, " \"<>", Next
);
866 Token2
= PrGetNextToken (NULL
, PR_TOKEN_SEPARATORS
, Next
);
872 DbgPrint (ASL_PARSE_OUTPUT
, PR_PREFIX_ID
873 "Start #includebuffer input from file \"%s\", buffer name %s\n",
874 AslGbl_CurrentLineNumber
, Token
, Token2
);
876 PrDoIncludeBuffer (Token
, Token2
);
879 case PR_DIRECTIVE_LINE
:
881 TokenOffset
= Token
- AslGbl_MainTokenBuffer
;
883 Status
= PrResolveIntegerExpression (
884 &AslGbl_CurrentLineBuffer
[TokenOffset
-1], &Value
);
885 if (ACPI_FAILURE (Status
))
890 DbgPrint (ASL_PARSE_OUTPUT
, PR_PREFIX_ID
891 "User #line invocation %s\n", AslGbl_CurrentLineNumber
,
894 AslGbl_CurrentLineNumber
= (UINT32
) Value
;
896 /* Emit #line into the preprocessor file */
898 FlPrintFile (ASL_FILE_PREPROCESSOR
, "#line %u \"%s\"\n",
899 AslGbl_CurrentLineNumber
, AslGbl_Files
[ASL_FILE_INPUT
].Filename
);
902 case PR_DIRECTIVE_PRAGMA
:
904 if (!strcmp (Token
, "disable"))
906 Token
= PrGetNextToken (NULL
, PR_TOKEN_SEPARATORS
, Next
);
912 TokenOffset
= Token
- AslGbl_MainTokenBuffer
;
913 AslDisableException (&AslGbl_CurrentLineBuffer
[TokenOffset
]);
915 else if (!strcmp (Token
, "message"))
917 Token
= PrGetNextToken (NULL
, PR_TOKEN_SEPARATORS
, Next
);
923 TokenOffset
= Token
- AslGbl_MainTokenBuffer
;
924 AcpiOsPrintf ("%s\n", &AslGbl_CurrentLineBuffer
[TokenOffset
]);
928 PrError (ASL_ERROR
, ASL_MSG_UNKNOWN_PRAGMA
,
929 THIS_TOKEN_OFFSET (Token
));
935 case PR_DIRECTIVE_UNDEF
:
937 DbgPrint (ASL_PARSE_OUTPUT
, PR_PREFIX_ID
938 "#undef: %s\n", AslGbl_CurrentLineNumber
, Token
);
940 PrRemoveDefine (Token
);
943 case PR_DIRECTIVE_WARNING
:
945 PrError (ASL_WARNING
, ASL_MSG_WARNING_DIRECTIVE
,
946 THIS_TOKEN_OFFSET (Token
));
948 AslGbl_SourceLine
= 0;
949 AslGbl_NextError
= AslGbl_ErrorLog
;
954 /* Should never get here */
955 DbgPrint (ASL_PARSE_OUTPUT
, PR_PREFIX_ID
956 "Unrecognized directive: %u\n",
957 AslGbl_CurrentLineNumber
, Directive
);
965 PrError (ASL_ERROR
, ASL_MSG_DIRECTIVE_SYNTAX
,
966 THIS_TOKEN_OFFSET (DirectiveToken
));
971 /*******************************************************************************
973 * FUNCTION: PrGetNextLine, PrGetNextLineInit
975 * PARAMETERS: Handle - Open file handle for the source file
977 * RETURN: Status of the GetLine operation:
978 * AE_OK - Normal line, OK status
979 * ASL_IGNORE_LINE - Line is blank or part of a multi-line
981 * ASL_EOF - End-of-file reached
983 * DESCRIPTION: Get the next text line from the input file. Does not strip
986 ******************************************************************************/
988 #define PR_NORMAL_TEXT 0
989 #define PR_MULTI_LINE_COMMENT 1
990 #define PR_SINGLE_LINE_COMMENT 2
991 #define PR_QUOTED_STRING 3
993 static UINT8 AcpiGbl_LineScanState
= PR_NORMAL_TEXT
;
999 AcpiGbl_LineScanState
= 0;
1011 /* Always clear the global line buffer */
1013 memset (AslGbl_CurrentLineBuffer
, 0, AslGbl_LineBufferSize
);
1017 * If line is too long, expand the line buffers. Also increases
1018 * AslGbl_LineBufferSize.
1020 if (i
>= AslGbl_LineBufferSize
)
1022 UtExpandLineBuffers ();
1030 * On EOF: If there is anything in the line buffer, terminate
1031 * it with a newline, and catch the EOF on the next call
1036 AslGbl_CurrentLineBuffer
[i
] = '\n';
1043 /* Update state machine as necessary */
1045 switch (AcpiGbl_LineScanState
)
1047 case PR_NORMAL_TEXT
:
1049 /* Check for multi-line comment start */
1051 if ((PreviousChar
== '/') && (c
== '*'))
1053 AcpiGbl_LineScanState
= PR_MULTI_LINE_COMMENT
;
1056 /* Check for single-line comment start */
1058 else if ((PreviousChar
== '/') && (c
== '/'))
1060 AcpiGbl_LineScanState
= PR_SINGLE_LINE_COMMENT
;
1063 /* Check for quoted string start */
1065 else if (PreviousChar
== '"')
1067 AcpiGbl_LineScanState
= PR_QUOTED_STRING
;
1071 case PR_QUOTED_STRING
:
1073 if (PreviousChar
== '"')
1075 AcpiGbl_LineScanState
= PR_NORMAL_TEXT
;
1079 case PR_MULTI_LINE_COMMENT
:
1081 /* Check for multi-line comment end */
1083 if ((PreviousChar
== '*') && (c
== '/'))
1085 AcpiGbl_LineScanState
= PR_NORMAL_TEXT
;
1089 case PR_SINGLE_LINE_COMMENT
: /* Just ignore text until EOL */
1094 /* Always copy the character into line buffer */
1096 AslGbl_CurrentLineBuffer
[i
] = (char) c
;
1099 /* Always exit on end-of-line */
1103 /* Handle multi-line comments */
1105 if (AcpiGbl_LineScanState
== PR_MULTI_LINE_COMMENT
)
1107 return (ASL_IGNORE_LINE
);
1110 /* End of single-line comment */
1112 if (AcpiGbl_LineScanState
== PR_SINGLE_LINE_COMMENT
)
1114 AcpiGbl_LineScanState
= PR_NORMAL_TEXT
;
1122 return (ASL_IGNORE_LINE
);
1131 /*******************************************************************************
1133 * FUNCTION: PrMatchDirective
1135 * PARAMETERS: Directive - Pointer to directive name token
1137 * RETURN: Index into command array, -1 if not found
1139 * DESCRIPTION: Lookup the incoming directive in the known directives table.
1141 ******************************************************************************/
1150 if (!Directive
|| Directive
[0] == 0)
1152 return (ASL_DIRECTIVE_NOT_FOUND
);
1155 for (i
= 0; AslGbl_DirectiveInfo
[i
].Name
; i
++)
1157 if (!strcmp (AslGbl_DirectiveInfo
[i
].Name
, Directive
))
1163 return (ASL_DIRECTIVE_NOT_FOUND
); /* Command not recognized */
1167 /*******************************************************************************
1169 * FUNCTION: PrPushDirective
1171 * PARAMETERS: Directive - Encoded directive ID
1172 * Argument - String containing argument to the
1177 * DESCRIPTION: Push an item onto the directive stack. Used for processing
1178 * nested #if/#else type conditional compilation directives.
1179 * Specifically: Used on detection of #if/#ifdef/#ifndef to open
1182 ******************************************************************************/
1189 DIRECTIVE_INFO
*Info
;
1192 /* Allocate and populate a stack info item */
1194 Info
= ACPI_CAST_PTR (DIRECTIVE_INFO
,
1195 UtLocalCacheCalloc (sizeof (DIRECTIVE_INFO
)));
1197 Info
->Next
= AslGbl_DirectiveStack
;
1198 Info
->Directive
= Directive
;
1199 Info
->IgnoringThisCodeBlock
= AslGbl_IgnoringThisCodeBlock
;
1200 AcpiUtSafeStrncpy (Info
->Argument
, Argument
, MAX_ARGUMENT_LENGTH
);
1202 DbgPrint (ASL_DEBUG_OUTPUT
,
1203 "Pr(%.4u) - [%u %s] %*s Pushed [#%s %s]: IgnoreFlag = %s\n",
1204 AslGbl_CurrentLineNumber
, AslGbl_IfDepth
,
1205 AslGbl_IgnoringThisCodeBlock
? "I" : "E",
1206 AslGbl_IfDepth
* 4, " ",
1207 AslGbl_DirectiveInfo
[Directive
].Name
,
1208 Argument
, AslGbl_IgnoringThisCodeBlock
? "TRUE" : "FALSE");
1212 AslGbl_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
= AslGbl_DirectiveStack
;
1248 /* Pop one item, keep globals up-to-date */
1251 AslGbl_IgnoringThisCodeBlock
= Info
->IgnoringThisCodeBlock
;
1252 AslGbl_DirectiveStack
= Info
->Next
;
1254 DbgPrint (ASL_DEBUG_OUTPUT
,
1255 "Pr(%.4u) - [%u %s] %*s Popped [#%s %s]: IgnoreFlag now = %s\n",
1256 AslGbl_CurrentLineNumber
, AslGbl_IfDepth
,
1257 AslGbl_IgnoringThisCodeBlock
? "I" : "E",
1258 AslGbl_IfDepth
* 4, " ",
1259 AslGbl_DirectiveInfo
[Info
->Directive
].Name
,
1260 Info
->Argument
, AslGbl_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 AslGbl_CurrentLineNumber
, AslGbl_IfDepth
,
1289 AslGbl_IgnoringThisCodeBlock
? "I" : "E",
1290 AslGbl_IfDepth
* 4, " ",
1291 Action
, DirectiveName
, AslGbl_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 AslGbl_CurrentLineNumber
, i
, FullPathname
);
1371 /* Close the Name() operator */
1373 FlPrintFile (ASL_FILE_PREPROCESSOR
, "\n})\n", BufferName
);
1374 fclose (BinaryBufferFile
);