static void PrDoDirective ( char *DirectiveToken, char **Next) { char *Token = Gbl_MainTokenBuffer; char *Token2 = NULL; char *End; UINT64 Value; ACPI_SIZE TokenOffset; int Directive; ACPI_STATUS Status; if (!DirectiveToken) { goto SyntaxError; } Directive = PrMatchDirective (DirectiveToken); if (Directive == ASL_DIRECTIVE_NOT_FOUND) { PrError (ASL_ERROR, ASL_MSG_UNKNOWN_DIRECTIVE, THIS_TOKEN_OFFSET (DirectiveToken)); DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "#%s: Unknown directive\n", Gbl_CurrentLineNumber, DirectiveToken); return; } /* * Emit a line directive into the preprocessor file (.pre) after * every matched directive. This is passed through to the compiler * so that error/warning messages are kept in sync with the * original source file. */ FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\" // #%s\n", Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_DirectiveInfo[Directive].Name); /* * If we are currently ignoring this block and we encounter a #else or * #elif, we must ignore their blocks also if the parent block is also * being ignored. */ if (Gbl_IgnoringThisCodeBlock) { switch (Directive) { case PR_DIRECTIVE_ELSE: case PR_DIRECTIVE_ELIF: if (Gbl_DirectiveStack && Gbl_DirectiveStack->IgnoringThisCodeBlock) { PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name); return; } break; default: break; } } /* * Need to always check for #else, #elif, #endif regardless of * whether we are ignoring the current code block, since these * are conditional code block terminators. */ switch (Directive) { case PR_DIRECTIVE_ELSE: Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock); PrDbgPrint ("Executing", "else block"); return; case PR_DIRECTIVE_ELIF: Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock); Directive = PR_DIRECTIVE_IF; if (Gbl_IgnoringThisCodeBlock == TRUE) { /* Not executing the ELSE part -- all done here */ PrDbgPrint ("Ignoring", "elif block"); return; } /* * After this, we will execute the IF part further below. * First, however, pop off the original #if directive. */ if (ACPI_FAILURE (PrPopDirective ())) { PrError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, THIS_TOKEN_OFFSET (DirectiveToken)); } PrDbgPrint ("Executing", "elif block"); break; case PR_DIRECTIVE_ENDIF: PrDbgPrint ("Executing", "endif"); /* Pop the owning #if/#ifdef/#ifndef */ if (ACPI_FAILURE (PrPopDirective ())) { PrError (ASL_ERROR, ASL_MSG_ENDIF_MISMATCH, THIS_TOKEN_OFFSET (DirectiveToken)); } return; default: break; } /* Most directives have at least one argument */ if (Gbl_DirectiveInfo[Directive].ArgCount >= 1) { Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token) { goto SyntaxError; } } if (Gbl_DirectiveInfo[Directive].ArgCount >= 2) { Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token2) { goto SyntaxError; } } /* * At this point, if we are ignoring the current code block, * do not process any more directives (i.e., ignore them also.) * For "if" style directives, open/push a new block anyway. We * must do this to keep track of #endif directives */ if (Gbl_IgnoringThisCodeBlock) { switch (Directive) { case PR_DIRECTIVE_IF: case PR_DIRECTIVE_IFDEF: case PR_DIRECTIVE_IFNDEF: PrPushDirective (Directive, Token); PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name); break; default: break; } return; } /* * Execute the directive */ PrDbgPrint ("Begin execution", Gbl_DirectiveInfo[Directive].Name); switch (Directive) { case PR_DIRECTIVE_IF: TokenOffset = Token - Gbl_MainTokenBuffer; /* Need to expand #define macros in the expression string first */ Status = PrResolveIntegerExpression ( &Gbl_CurrentLineBuffer[TokenOffset-1], &Value); if (ACPI_FAILURE (Status)) { return; } PrPushDirective (Directive, Token); if (!Value) { Gbl_IgnoringThisCodeBlock = TRUE; } DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "Resolved #if: %8.8X%8.8X %s\n", Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value), Gbl_IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>"); break; case PR_DIRECTIVE_IFDEF: PrPushDirective (Directive, Token); if (!PrMatchDefine (Token)) { Gbl_IgnoringThisCodeBlock = TRUE; } PrDbgPrint ("Evaluated", "ifdef"); break; case PR_DIRECTIVE_IFNDEF: PrPushDirective (Directive, Token); if (PrMatchDefine (Token)) { Gbl_IgnoringThisCodeBlock = TRUE; } PrDbgPrint ("Evaluated", "ifndef"); break; case PR_DIRECTIVE_DEFINE: /* * By definition, if first char after the name is a paren, * this is a function macro. */ TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token); if (*(&Gbl_CurrentLineBuffer[TokenOffset]) == '(') { #ifndef MACROS_SUPPORTED AcpiOsPrintf ( "%s ERROR - line %u: #define macros are not supported yet\n", Gbl_CurrentLineBuffer, Gbl_LogicalLineNumber); exit(1); #else PrAddMacro (Token, Next); #endif } else { /* Use the remainder of the line for the #define */ Token2 = *Next; if (Token2) { while ((*Token2 == ' ') || (*Token2 == '\t')) { Token2++; } End = Token2; while (*End != '\n') { End++; } *End = 0; } else { Token2 = ""; } #if 0 Token2 = PrGetNextToken (NULL, "\n", /*PR_TOKEN_SEPARATORS,*/ Next); if (!Token2) { Token2 = ""; } #endif DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "New #define: %s->%s\n", Gbl_LogicalLineNumber, Token, Token2); PrAddDefine (Token, Token2, FALSE); } break; case PR_DIRECTIVE_ERROR: /* Note: No macro expansion */ PrError (ASL_ERROR, ASL_MSG_ERROR_DIRECTIVE, THIS_TOKEN_OFFSET (Token)); Gbl_SourceLine = 0; Gbl_NextError = Gbl_ErrorLog; CmCleanupAndExit (); exit(1); case PR_DIRECTIVE_INCLUDE: Token = PrGetNextToken (NULL, " \"<>", Next); if (!Token) { goto SyntaxError; } DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "Start #include file \"%s\"\n", Gbl_CurrentLineNumber, Token, Gbl_CurrentLineNumber); PrDoIncludeFile (Token); break; case PR_DIRECTIVE_INCLUDEBUFFER: Token = PrGetNextToken (NULL, " \"<>", Next); if (!Token) { goto SyntaxError; } Token2 = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token2) { goto SyntaxError; } DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "Start #includebuffer input from file \"%s\", buffer name %s\n", Gbl_CurrentLineNumber, Token, Token2); PrDoIncludeBuffer (Token, Token2); break; case PR_DIRECTIVE_LINE: TokenOffset = Token - Gbl_MainTokenBuffer; Status = PrResolveIntegerExpression ( &Gbl_CurrentLineBuffer[TokenOffset-1], &Value); if (ACPI_FAILURE (Status)) { return; } DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "User #line invocation %s\n", Gbl_CurrentLineNumber, Token); Gbl_CurrentLineNumber = (UINT32) Value; /* Emit #line into the preprocessor file */ FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n", Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename); break; case PR_DIRECTIVE_PRAGMA: if (!strcmp (Token, "disable")) { Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token) { goto SyntaxError; } TokenOffset = Token - Gbl_MainTokenBuffer; AslDisableException (&Gbl_CurrentLineBuffer[TokenOffset]); } else if (!strcmp (Token, "message")) { Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token) { goto SyntaxError; } TokenOffset = Token - Gbl_MainTokenBuffer; AcpiOsPrintf ("%s\n", &Gbl_CurrentLineBuffer[TokenOffset]); } else { PrError (ASL_ERROR, ASL_MSG_UNKNOWN_PRAGMA, THIS_TOKEN_OFFSET (Token)); return; } break; case PR_DIRECTIVE_UNDEF: DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "#undef: %s\n", Gbl_CurrentLineNumber, Token); PrRemoveDefine (Token); break; case PR_DIRECTIVE_WARNING: PrError (ASL_WARNING, ASL_MSG_WARNING_DIRECTIVE, THIS_TOKEN_OFFSET (Token)); Gbl_SourceLine = 0; Gbl_NextError = Gbl_ErrorLog; break; default: /* Should never get here */ DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "Unrecognized directive: %u\n", Gbl_CurrentLineNumber, Directive); break; } return; SyntaxError: PrError (ASL_ERROR, ASL_MSG_DIRECTIVE_SYNTAX, THIS_TOKEN_OFFSET (DirectiveToken)); return; }
static void PrDoDirective ( char *DirectiveToken, char **Next, BOOLEAN *IgnoringThisCodeBlock) { char *Token = Gbl_MainTokenBuffer; char *Token2; char *End; UINT64 Value; ACPI_SIZE TokenOffset; int Directive; ACPI_STATUS Status; if (!DirectiveToken) { goto SyntaxError; } Directive = PrMatchDirective (DirectiveToken); if (Directive == ASL_DIRECTIVE_NOT_FOUND) { PrError (ASL_ERROR, ASL_MSG_UNKNOWN_DIRECTIVE, THIS_TOKEN_OFFSET (DirectiveToken)); DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "#%s: Unknown directive\n", Gbl_CurrentLineNumber, DirectiveToken); return; } /* TBD: Need a faster way to do this: */ if ((Directive == PR_DIRECTIVE_ELIF) || (Directive == PR_DIRECTIVE_ELSE) || (Directive == PR_DIRECTIVE_ENDIF)) { DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Begin #%s\n", Gbl_CurrentLineNumber, Gbl_DirectiveInfo[Directive].Name); } /* * Need to always check for #else, #elif, #endif regardless of * whether we are ignoring the current code block, since these * are conditional code block terminators. */ switch (Directive) { case PR_DIRECTIVE_ELIF: *IgnoringThisCodeBlock = !(*IgnoringThisCodeBlock); if (*IgnoringThisCodeBlock == TRUE) { /* Not executing the ELSE part -- all done here */ return; } /* Will execute the ELSE..IF part */ DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "#elif - Executing else block\n", Gbl_CurrentLineNumber); Directive = PR_DIRECTIVE_IF; break; case PR_DIRECTIVE_ELSE: *IgnoringThisCodeBlock = !(*IgnoringThisCodeBlock); return; case PR_DIRECTIVE_ENDIF: *IgnoringThisCodeBlock = FALSE; Gbl_IfDepth--; if (Gbl_IfDepth < 0) { PrError (ASL_ERROR, ASL_MSG_ENDIF_MISMATCH, THIS_TOKEN_OFFSET (DirectiveToken)); Gbl_IfDepth = 0; } return; default: break; } /* * At this point, if we are ignoring the current code block, * do not process any more directives (i.e., ignore them also.) */ if (*IgnoringThisCodeBlock == TRUE) { return; } DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Begin #%s\n", Gbl_CurrentLineNumber, Gbl_DirectiveInfo[Directive].Name); /* Most directives have at least one argument */ if (Gbl_DirectiveInfo[Directive].ArgCount == 1) { Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token) { goto SyntaxError; } } switch (Directive) { case PR_DIRECTIVE_DEFINE: /* * By definition, if first char after the name is a paren, * this is a function macro. */ TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token); if (*(&Gbl_CurrentLineBuffer[TokenOffset]) == '(') { #ifndef MACROS_SUPPORTED AcpiOsPrintf ("%s ERROR - line %u: #define macros are not supported yet\n", Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber); exit(1); #else PrAddMacro (Token, Next); #endif } else { /* Use the remainder of the line for the #define */ Token2 = *Next; if (Token2) { while ((*Token2 == ' ') || (*Token2 == '\t')) { Token2++; } End = Token2; while (*End != '\n') { End++; } *End = 0; } else { Token2 = ""; } #if 0 Token2 = PrGetNextToken (NULL, "\n", /*PR_TOKEN_SEPARATORS,*/ Next); if (!Token2) { Token2 = ""; } #endif DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "New #define: %s->%s\n", Gbl_CurrentLineNumber, Token, Token2); PrAddDefine (Token, Token2, FALSE); } break; case PR_DIRECTIVE_ERROR: /* TBD compiler should abort */ /* Note: No macro expansion */ PrError (ASL_ERROR, ASL_MSG_ERROR_DIRECTIVE, THIS_TOKEN_OFFSET (Token)); break; case PR_DIRECTIVE_IF: TokenOffset = Token - Gbl_MainTokenBuffer; /* Need to expand #define macros in the expression string first */ Status = PrResolveIntegerExpression ( &Gbl_CurrentLineBuffer[TokenOffset-1], &Value); if (ACPI_FAILURE (Status)) { return; } if (!Value) { *IgnoringThisCodeBlock = TRUE; } DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Resolved #if: %8.8X%8.8X %s\n", Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value), *IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>"); Gbl_IfDepth++; break; case PR_DIRECTIVE_IFDEF: if (!PrMatchDefine (Token)) { *IgnoringThisCodeBlock = TRUE; } Gbl_IfDepth++; DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Start #ifdef %s\n", Gbl_CurrentLineNumber, *IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>"); break; case PR_DIRECTIVE_IFNDEF: if (PrMatchDefine (Token)) { *IgnoringThisCodeBlock = TRUE; } Gbl_IfDepth++; DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Start #ifndef %2.2X\n", Gbl_CurrentLineNumber, *IgnoringThisCodeBlock, Gbl_CurrentLineNumber); break; case PR_DIRECTIVE_INCLUDE: Token = PrGetNextToken (NULL, " \"<>", Next); if (!Token) { goto SyntaxError; } DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Start #include file \"%s\"\n", Gbl_CurrentLineNumber, Token, Gbl_CurrentLineNumber); PrOpenIncludeFile (Token); break; case PR_DIRECTIVE_LINE: TokenOffset = Token - Gbl_MainTokenBuffer; Status = PrResolveIntegerExpression ( &Gbl_CurrentLineBuffer[TokenOffset-1], &Value); if (ACPI_FAILURE (Status)) { return; } DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "User #line invocation %s\n", Gbl_CurrentLineNumber, Token); /* Update local line numbers */ Gbl_CurrentLineNumber = (UINT32) Value; Gbl_PreviousLineNumber = 0; /* Emit #line into the preprocessor file */ FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n", Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename); break; case PR_DIRECTIVE_PRAGMA: /* Only "#pragma message" supported at this time */ if (strcmp (Token, "message")) { PrError (ASL_ERROR, ASL_MSG_UNKNOWN_PRAGMA, THIS_TOKEN_OFFSET (Token)); return; } Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); if (!Token) { goto SyntaxError; } TokenOffset = Token - Gbl_MainTokenBuffer; AcpiOsPrintf ("%s\n", &Gbl_CurrentLineBuffer[TokenOffset]); break; case PR_DIRECTIVE_UNDEF: DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "#undef: %s\n", Gbl_CurrentLineNumber, Token); PrRemoveDefine (Token); break; case PR_DIRECTIVE_WARNING: PrError (ASL_WARNING, ASL_MSG_ERROR_DIRECTIVE, THIS_TOKEN_OFFSET (Token)); break; default: /* Should never get here */ DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Unrecognized directive: %u\n", Gbl_CurrentLineNumber, Directive); break; } return; SyntaxError: PrError (ASL_ERROR, ASL_MSG_DIRECTIVE_SYNTAX, THIS_TOKEN_OFFSET (DirectiveToken)); return; }