1 /******************************************************************************
3 * Module Name: prscan - Preprocessor start-up and file scan module
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define _DECLARE_PR_GLOBALS
46 #include "aslcompiler.h"
47 #include "dtcompiler.h"
52 * No nested macros, maybe never
53 * Implement ASL "Include" as well as "#include" here?
55 #define _COMPONENT ASL_PREPROCESSOR
56 ACPI_MODULE_NAME ("prscan")
59 /* Local prototypes */
62 PrPreprocessInputFile (
107 * Supported preprocessor directives
108 * Each entry is of the form "Name, ArgumentCount"
110 static const PR_DIRECTIVE_INFO Gbl_DirectiveInfo[] =
113 {"elif", 0}, /* Converted to #else..#if internally */
120 {"include", 0}, /* Argument is not standard format, so just use 0 here */
121 {"includebuffer", 0}, /* Argument is not standard format, so just use 0 here */
129 /* This table must match ordering of above table exactly */
131 enum Gbl_DirectiveIndexes
133 PR_DIRECTIVE_DEFINE = 0,
141 PR_DIRECTIVE_INCLUDE,
142 PR_DIRECTIVE_INCLUDEBUFFER,
149 #define ASL_DIRECTIVE_NOT_FOUND -1
152 /*******************************************************************************
154 * FUNCTION: PrInitializePreprocessor
160 * DESCRIPTION: Startup initialization for the Preprocessor.
162 ******************************************************************************/
165 PrInitializePreprocessor (
168 /* Init globals and the list of #defines */
170 PrInitializeGlobals ();
171 Gbl_DefineList = NULL;
175 /*******************************************************************************
177 * FUNCTION: PrInitializeGlobals
183 * DESCRIPTION: Initialize globals for the Preprocessor. Used for startuup
184 * initialization and re-initialization between compiles during
185 * a multiple source file compile.
187 ******************************************************************************/
190 PrInitializeGlobals (
195 Gbl_InputFileList = NULL;
196 Gbl_CurrentLineNumber = 1;
197 Gbl_PreprocessorLineNumber = 1;
198 Gbl_PreprocessorError = FALSE;
200 /* These are used to track #if/#else blocks (possibly nested) */
203 Gbl_IgnoringThisCodeBlock = FALSE;
204 Gbl_DirectiveStack = NULL;
208 /*******************************************************************************
210 * FUNCTION: PrTerminatePreprocessor
216 * DESCRIPTION: Termination of the preprocessor. Delete lists. Keep any
217 * defines that were specified on the command line, in order to
218 * support multiple compiles with a single compiler invocation.
220 ******************************************************************************/
223 PrTerminatePreprocessor (
226 PR_DEFINE_INFO *DefineInfo;
230 * The persistent defines (created on the command line) are always at the
231 * end of the list. We save them.
233 while ((Gbl_DefineList) && (!Gbl_DefineList->Persist))
235 DefineInfo = Gbl_DefineList;
236 Gbl_DefineList = DefineInfo->Next;
238 ACPI_FREE (DefineInfo->Replacement);
239 ACPI_FREE (DefineInfo->Identifier);
240 ACPI_FREE (DefineInfo);
245 /*******************************************************************************
247 * FUNCTION: PrDoPreprocess
253 * DESCRIPTION: Main entry point for the iASL Preprocessor. Input file must
254 * be already open. Handles multiple input files via the
255 * #include directive.
257 ******************************************************************************/
263 BOOLEAN MoreInputFiles;
266 DbgPrint (ASL_DEBUG_OUTPUT, "Starting preprocessing phase\n\n");
269 FlSeekFile (ASL_FILE_INPUT, 0);
270 PrDumpPredefinedNames ();
272 /* Main preprocessor loop, handles include files */
276 PrPreprocessInputFile ();
277 MoreInputFiles = PrPopInputFileStack ();
279 } while (MoreInputFiles);
281 /* Point compiler input to the new preprocessor output file (.pre) */
283 FlCloseFile (ASL_FILE_INPUT);
284 Gbl_Files[ASL_FILE_INPUT].Handle = Gbl_Files[ASL_FILE_PREPROCESSOR].Handle;
285 AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
287 /* Reset globals to allow compiler to run */
289 FlSeekFile (ASL_FILE_INPUT, 0);
290 if (!Gbl_PreprocessOnly)
292 Gbl_CurrentLineNumber = 0;
295 DbgPrint (ASL_DEBUG_OUTPUT, "Preprocessing phase complete \n\n");
299 /*******************************************************************************
301 * FUNCTION: PrPreprocessInputFile
307 * DESCRIPTION: Preprocess one entire file, line-by-line.
309 * Input: Raw user ASL from ASL_FILE_INPUT
310 * Output: Preprocessed file written to ASL_FILE_PREPROCESSOR and
311 * (optionally) ASL_FILE_PREPROCESSOR_USER
313 ******************************************************************************/
316 PrPreprocessInputFile (
322 PR_DEFINE_INFO *DefineInfo;
323 ACPI_SIZE TokenOffset;
328 PrGetNextLineInit ();
330 /* Scan source line-by-line and process directives. Then write the .i file */
332 while ((Status = PrGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF)
334 Gbl_CurrentLineNumber++;
335 Gbl_LogicalLineNumber++;
337 if ((Status == ASL_WITHIN_COMMENT) ||
338 (Status == ASL_BLANK_LINE))
340 goto WriteEntireLine;
343 /* Need a copy of the input line for strok() */
345 strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer);
346 Token = PrGetNextToken (Gbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next);
349 /* All preprocessor directives must begin with '#' */
351 if (Token && (*Token == '#'))
353 if (strlen (Token) == 1)
355 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
359 Token++; /* Skip leading # */
362 /* Execute the directive, do not write line to output file */
364 PrDoDirective (Token, &Next);
369 * If we are currently within the part of an IF/ELSE block that is
370 * FALSE, ignore the line and do not write it to the output file.
371 * This continues until an #else or #endif is encountered.
373 if (Gbl_IgnoringThisCodeBlock)
378 /* Match and replace all #defined names within this source line */
382 DefineInfo = PrMatchDefine (Token);
385 if (DefineInfo->Body)
387 /* This is a macro */
389 DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
390 "Matched Macro: %s->%s\n",
391 Gbl_CurrentLineNumber, DefineInfo->Identifier,
392 DefineInfo->Replacement);
394 PrDoMacroInvocation (Gbl_MainTokenBuffer, Token,
399 ReplaceString = DefineInfo->Replacement;
401 /* Replace the name in the original line buffer */
403 TokenOffset = Token - Gbl_MainTokenBuffer + OffsetAdjust;
405 &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token),
406 ReplaceString, strlen (ReplaceString));
408 /* Adjust for length difference between old and new name length */
410 OffsetAdjust += strlen (ReplaceString) - strlen (Token);
412 DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
413 "Matched #define: %s->%s\n",
414 Gbl_CurrentLineNumber, Token,
415 *ReplaceString ? ReplaceString : "(NULL STRING)");
419 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
422 Gbl_PreprocessorLineNumber++;
427 * Now we can write the possibly modified source line to the
428 * preprocessor file(s).
430 FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer,
431 strlen (Gbl_CurrentLineBuffer));
436 /*******************************************************************************
438 * FUNCTION: PrDoDirective
440 * PARAMETERS: Directive - Pointer to directive name token
441 * Next - "Next" buffer from GetNextToken
445 * DESCRIPTION: Main processing for all preprocessor directives
447 ******************************************************************************/
451 char *DirectiveToken,
454 char *Token = Gbl_MainTokenBuffer;
458 ACPI_SIZE TokenOffset;
468 Directive = PrMatchDirective (DirectiveToken);
469 if (Directive == ASL_DIRECTIVE_NOT_FOUND)
471 PrError (ASL_ERROR, ASL_MSG_UNKNOWN_DIRECTIVE,
472 THIS_TOKEN_OFFSET (DirectiveToken));
474 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
475 "#%s: Unknown directive\n",
476 Gbl_CurrentLineNumber, DirectiveToken);
481 * Emit a line directive into the preprocessor file (.pre) after
482 * every matched directive. This is passed through to the compiler
483 * so that error/warning messages are kept in sync with the
484 * original source file.
486 FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\" // #%s\n",
487 Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename,
488 Gbl_DirectiveInfo[Directive].Name);
491 * If we are currently ignoring this block and we encounter a #else or
492 * #elif, we must ignore their blocks also if the parent block is also
495 if (Gbl_IgnoringThisCodeBlock)
499 case PR_DIRECTIVE_ELSE:
500 case PR_DIRECTIVE_ELIF:
502 if (Gbl_DirectiveStack &&
503 Gbl_DirectiveStack->IgnoringThisCodeBlock)
505 PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name);
516 * Need to always check for #else, #elif, #endif regardless of
517 * whether we are ignoring the current code block, since these
518 * are conditional code block terminators.
522 case PR_DIRECTIVE_ELSE:
524 Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock);
525 PrDbgPrint ("Executing", "else block");
528 case PR_DIRECTIVE_ELIF:
530 Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock);
531 Directive = PR_DIRECTIVE_IF;
533 if (Gbl_IgnoringThisCodeBlock == TRUE)
535 /* Not executing the ELSE part -- all done here */
536 PrDbgPrint ("Ignoring", "elif block");
541 * After this, we will execute the IF part further below.
542 * First, however, pop off the original #if directive.
544 if (ACPI_FAILURE (PrPopDirective ()))
546 PrError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
547 THIS_TOKEN_OFFSET (DirectiveToken));
550 PrDbgPrint ("Executing", "elif block");
553 case PR_DIRECTIVE_ENDIF:
555 PrDbgPrint ("Executing", "endif");
557 /* Pop the owning #if/#ifdef/#ifndef */
559 if (ACPI_FAILURE (PrPopDirective ()))
561 PrError (ASL_ERROR, ASL_MSG_ENDIF_MISMATCH,
562 THIS_TOKEN_OFFSET (DirectiveToken));
570 /* Most directives have at least one argument */
572 if (Gbl_DirectiveInfo[Directive].ArgCount >= 1)
574 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
581 if (Gbl_DirectiveInfo[Directive].ArgCount >= 2)
583 Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
591 * At this point, if we are ignoring the current code block,
592 * do not process any more directives (i.e., ignore them also.)
593 * For "if" style directives, open/push a new block anyway. We
594 * must do this to keep track of #endif directives
596 if (Gbl_IgnoringThisCodeBlock)
600 case PR_DIRECTIVE_IF:
601 case PR_DIRECTIVE_IFDEF:
602 case PR_DIRECTIVE_IFNDEF:
604 PrPushDirective (Directive, Token);
605 PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name);
616 * Execute the directive
618 PrDbgPrint ("Begin execution", Gbl_DirectiveInfo[Directive].Name);
622 case PR_DIRECTIVE_IF:
624 TokenOffset = Token - Gbl_MainTokenBuffer;
626 /* Need to expand #define macros in the expression string first */
628 Status = PrResolveIntegerExpression (
629 &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
630 if (ACPI_FAILURE (Status))
635 PrPushDirective (Directive, Token);
638 Gbl_IgnoringThisCodeBlock = TRUE;
641 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
642 "Resolved #if: %8.8X%8.8X %s\n",
643 Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value),
644 Gbl_IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>");
647 case PR_DIRECTIVE_IFDEF:
649 PrPushDirective (Directive, Token);
650 if (!PrMatchDefine (Token))
652 Gbl_IgnoringThisCodeBlock = TRUE;
655 PrDbgPrint ("Evaluated", "ifdef");
658 case PR_DIRECTIVE_IFNDEF:
660 PrPushDirective (Directive, Token);
661 if (PrMatchDefine (Token))
663 Gbl_IgnoringThisCodeBlock = TRUE;
666 PrDbgPrint ("Evaluated", "ifndef");
669 case PR_DIRECTIVE_DEFINE:
671 * By definition, if first char after the name is a paren,
672 * this is a function macro.
674 TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token);
675 if (*(&Gbl_CurrentLineBuffer[TokenOffset]) == '(')
677 #ifndef MACROS_SUPPORTED
679 "%s ERROR - line %u: #define macros are not supported yet\n",
680 Gbl_CurrentLineBuffer, Gbl_LogicalLineNumber);
683 PrAddMacro (Token, Next);
688 /* Use the remainder of the line for the #define */
693 while ((*Token2 == ' ') || (*Token2 == '\t'))
711 Token2 = PrGetNextToken (NULL, "\n", /*PR_TOKEN_SEPARATORS,*/ Next);
717 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
718 "New #define: %s->%s\n",
719 Gbl_LogicalLineNumber, Token, Token2);
721 PrAddDefine (Token, Token2, FALSE);
725 case PR_DIRECTIVE_ERROR:
727 /* Note: No macro expansion */
729 PrError (ASL_ERROR, ASL_MSG_ERROR_DIRECTIVE,
730 THIS_TOKEN_OFFSET (Token));
733 Gbl_NextError = Gbl_ErrorLog;
737 case PR_DIRECTIVE_INCLUDE:
739 Token = PrGetNextToken (NULL, " \"<>", Next);
745 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
746 "Start #include file \"%s\"\n", Gbl_CurrentLineNumber,
747 Token, Gbl_CurrentLineNumber);
749 PrDoIncludeFile (Token);
752 case PR_DIRECTIVE_INCLUDEBUFFER:
754 Token = PrGetNextToken (NULL, " \"<>", Next);
760 Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
766 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
767 "Start #includebuffer input from file \"%s\", buffer name %s\n",
768 Gbl_CurrentLineNumber, Token, Token2);
770 PrDoIncludeBuffer (Token, Token2);
773 case PR_DIRECTIVE_LINE:
775 TokenOffset = Token - Gbl_MainTokenBuffer;
777 Status = PrResolveIntegerExpression (
778 &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
779 if (ACPI_FAILURE (Status))
784 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
785 "User #line invocation %s\n", Gbl_CurrentLineNumber,
788 Gbl_CurrentLineNumber = (UINT32) Value;
790 /* Emit #line into the preprocessor file */
792 FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n",
793 Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename);
796 case PR_DIRECTIVE_PRAGMA:
798 if (!strcmp (Token, "disable"))
800 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
806 TokenOffset = Token - Gbl_MainTokenBuffer;
807 AslDisableException (&Gbl_CurrentLineBuffer[TokenOffset]);
809 else if (!strcmp (Token, "message"))
811 Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
817 TokenOffset = Token - Gbl_MainTokenBuffer;
818 AcpiOsPrintf ("%s\n", &Gbl_CurrentLineBuffer[TokenOffset]);
822 PrError (ASL_ERROR, ASL_MSG_UNKNOWN_PRAGMA,
823 THIS_TOKEN_OFFSET (Token));
829 case PR_DIRECTIVE_UNDEF:
831 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
832 "#undef: %s\n", Gbl_CurrentLineNumber, Token);
834 PrRemoveDefine (Token);
837 case PR_DIRECTIVE_WARNING:
839 PrError (ASL_WARNING, ASL_MSG_WARNING_DIRECTIVE,
840 THIS_TOKEN_OFFSET (Token));
843 Gbl_NextError = Gbl_ErrorLog;
848 /* Should never get here */
849 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
850 "Unrecognized directive: %u\n",
851 Gbl_CurrentLineNumber, Directive);
859 PrError (ASL_ERROR, ASL_MSG_DIRECTIVE_SYNTAX,
860 THIS_TOKEN_OFFSET (DirectiveToken));
865 /*******************************************************************************
867 * FUNCTION: PrGetNextLine, PrGetNextLineInit
869 * PARAMETERS: Handle - Open file handle for the source file
871 * RETURN: Status of the GetLine operation:
872 * AE_OK - Normal line, OK status
873 * ASL_WITHIN_COMMENT - Line is part of a multi-line comment
874 * ASL_EOF - End-of-file reached
876 * DESCRIPTION: Get the next text line from the input file. Does not strip
879 ******************************************************************************/
881 #define PR_NORMAL_TEXT 0
882 #define PR_MULTI_LINE_COMMENT 1
883 #define PR_SINGLE_LINE_COMMENT 2
884 #define PR_QUOTED_STRING 3
886 static UINT8 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
892 AcpiGbl_LineScanState = 0;
904 /* Always clear the global line buffer */
906 memset (Gbl_CurrentLineBuffer, 0, Gbl_LineBufferSize);
910 * If line is too long, expand the line buffers. Also increases
911 * Gbl_LineBufferSize.
913 if (i >= Gbl_LineBufferSize)
915 UtExpandLineBuffers ();
925 /* Update state machine as necessary */
927 switch (AcpiGbl_LineScanState)
931 /* Check for multi-line comment start */
933 if ((PreviousChar == '/') && (c == '*'))
935 AcpiGbl_LineScanState = PR_MULTI_LINE_COMMENT;
938 /* Check for single-line comment start */
940 else if ((PreviousChar == '/') && (c == '/'))
942 AcpiGbl_LineScanState = PR_SINGLE_LINE_COMMENT;
945 /* Check for quoted string start */
947 else if (PreviousChar == '"')
949 AcpiGbl_LineScanState = PR_QUOTED_STRING;
953 case PR_QUOTED_STRING:
955 if (PreviousChar == '"')
957 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
961 case PR_MULTI_LINE_COMMENT:
963 /* Check for multi-line comment end */
965 if ((PreviousChar == '*') && (c == '/'))
967 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
971 case PR_SINGLE_LINE_COMMENT: /* Just ignore text until EOL */
976 /* Always copy the character into line buffer */
978 Gbl_CurrentLineBuffer[i] = (char) c;
981 /* Always exit on end-of-line */
985 /* Handle multi-line comments */
987 if (AcpiGbl_LineScanState == PR_MULTI_LINE_COMMENT)
989 return (ASL_WITHIN_COMMENT);
992 /* End of single-line comment */
994 if (AcpiGbl_LineScanState == PR_SINGLE_LINE_COMMENT)
996 AcpiGbl_LineScanState = PR_NORMAL_TEXT;
1004 return (ASL_BLANK_LINE);
1013 /*******************************************************************************
1015 * FUNCTION: PrMatchDirective
1017 * PARAMETERS: Directive - Pointer to directive name token
1019 * RETURN: Index into command array, -1 if not found
1021 * DESCRIPTION: Lookup the incoming directive in the known directives table.
1023 ******************************************************************************/
1032 if (!Directive || Directive[0] == 0)
1034 return (ASL_DIRECTIVE_NOT_FOUND);
1037 for (i = 0; Gbl_DirectiveInfo[i].Name; i++)
1039 if (!strcmp (Gbl_DirectiveInfo[i].Name, Directive))
1045 return (ASL_DIRECTIVE_NOT_FOUND); /* Command not recognized */
1049 /*******************************************************************************
1051 * FUNCTION: PrPushDirective
1053 * PARAMETERS: Directive - Encoded directive ID
1054 * Argument - String containing argument to the
1059 * DESCRIPTION: Push an item onto the directive stack. Used for processing
1060 * nested #if/#else type conditional compilation directives.
1061 * Specifically: Used on detection of #if/#ifdef/#ifndef to open
1064 ******************************************************************************/
1071 DIRECTIVE_INFO *Info;
1074 /* Allocate and populate a stack info item */
1076 Info = ACPI_ALLOCATE (sizeof (DIRECTIVE_INFO));
1078 Info->Next = Gbl_DirectiveStack;
1079 Info->Directive = Directive;
1080 Info->IgnoringThisCodeBlock = Gbl_IgnoringThisCodeBlock;
1081 strncpy (Info->Argument, Argument, MAX_ARGUMENT_LENGTH);
1083 DbgPrint (ASL_DEBUG_OUTPUT,
1084 "Pr(%.4u) - [%u %s] %*s Pushed [#%s %s]: IgnoreFlag = %s\n",
1085 Gbl_CurrentLineNumber, Gbl_IfDepth,
1086 Gbl_IgnoringThisCodeBlock ? "I" : "E",
1087 Gbl_IfDepth * 4, " ",
1088 Gbl_DirectiveInfo[Directive].Name,
1089 Argument, Gbl_IgnoringThisCodeBlock ? "TRUE" : "FALSE");
1093 Gbl_DirectiveStack = Info;
1098 /*******************************************************************************
1100 * FUNCTION: PrPopDirective
1104 * RETURN: Status. Error if the stack is empty.
1106 * DESCRIPTION: Pop an item off the directive stack. Used for processing
1107 * nested #if/#else type conditional compilation directives.
1108 * Specifically: Used on detection of #elif and #endif to remove
1109 * the original #if/#ifdef/#ifndef from the stack and close
1112 ******************************************************************************/
1118 DIRECTIVE_INFO *Info;
1121 /* Check for empty stack */
1123 Info = Gbl_DirectiveStack;
1129 /* Pop one item, keep globals up-to-date */
1132 Gbl_IgnoringThisCodeBlock = Info->IgnoringThisCodeBlock;
1133 Gbl_DirectiveStack = Info->Next;
1135 DbgPrint (ASL_DEBUG_OUTPUT,
1136 "Pr(%.4u) - [%u %s] %*s Popped [#%s %s]: IgnoreFlag now = %s\n",
1137 Gbl_CurrentLineNumber, Gbl_IfDepth,
1138 Gbl_IgnoringThisCodeBlock ? "I" : "E",
1139 Gbl_IfDepth * 4, " ",
1140 Gbl_DirectiveInfo[Info->Directive].Name,
1141 Info->Argument, Gbl_IgnoringThisCodeBlock ? "TRUE" : "FALSE");
1148 /*******************************************************************************
1150 * FUNCTION: PrDbgPrint
1152 * PARAMETERS: Action - Action being performed
1153 * DirectiveName - Directive being processed
1157 * DESCRIPTION: Special debug print for directive processing.
1159 ******************************************************************************/
1164 char *DirectiveName)
1167 DbgPrint (ASL_DEBUG_OUTPUT, "Pr(%.4u) - [%u %s] "
1168 "%*s %s #%s, IfDepth %u\n",
1169 Gbl_CurrentLineNumber, Gbl_IfDepth,
1170 Gbl_IgnoringThisCodeBlock ? "I" : "E",
1171 Gbl_IfDepth * 4, " ",
1172 Action, DirectiveName, Gbl_IfDepth);
1176 /*******************************************************************************
1178 * FUNCTION: PrDoIncludeFile
1180 * PARAMETERS: Pathname - Name of the input file
1184 * DESCRIPTION: Open an include file, from #include.
1186 ******************************************************************************/
1195 (void) PrOpenIncludeFile (Pathname, "r", &FullPathname);
1199 /*******************************************************************************
1201 * FUNCTION: PrDoIncludeBuffer
1203 * PARAMETERS: Pathname - Name of the input binary file
1204 * BufferName - ACPI namepath of the buffer
1208 * DESCRIPTION: Create an ACPI buffer object from a binary file. The contents
1209 * of the file are emitted into the buffer object as ascii
1210 * hex data. From #includebuffer.
1212 ******************************************************************************/
1220 FILE *BinaryBufferFile;
1225 BinaryBufferFile = PrOpenIncludeFile (Pathname, "rb", &FullPathname);
1226 if (!BinaryBufferFile)
1231 /* Emit "Name (XXXX, Buffer() {" header */
1233 FlPrintFile (ASL_FILE_PREPROCESSOR, "Name (%s, Buffer()\n{", BufferName);
1235 /* Dump the entire file in ascii hex format */
1237 while (fread (&c, 1, 1, BinaryBufferFile))
1241 FlPrintFile (ASL_FILE_PREPROCESSOR, "\n ", c);
1244 FlPrintFile (ASL_FILE_PREPROCESSOR, " 0x%2.2X,", c);
1248 DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID
1249 "#includebuffer: read %u bytes from %s\n",
1250 Gbl_CurrentLineNumber, i, FullPathname);
1252 /* Close the Name() operator */
1254 FlPrintFile (ASL_FILE_PREPROCESSOR, "\n})\n", BufferName);
1255 fclose (BinaryBufferFile);