prscan.c revision 233237
11573Srgrimes/******************************************************************************
21573Srgrimes *
31573Srgrimes * Module Name: prscan - Preprocessor start-up and file scan module
41573Srgrimes *
51573Srgrimes *****************************************************************************/
61573Srgrimes
71573Srgrimes/*
81573Srgrimes * Copyright (C) 2000 - 2012, Intel Corp.
91573Srgrimes * All rights reserved.
101573Srgrimes *
111573Srgrimes * Redistribution and use in source and binary forms, with or without
121573Srgrimes * modification, are permitted provided that the following conditions
131573Srgrimes * are met:
141573Srgrimes * 1. Redistributions of source code must retain the above copyright
151573Srgrimes *    notice, this list of conditions, and the following disclaimer,
16249808Semaste *    without modification.
171573Srgrimes * 2. Redistributions in binary form must reproduce at minimum a disclaimer
181573Srgrimes *    substantially similar to the "NO WARRANTY" disclaimer below
191573Srgrimes *    ("Disclaimer") and any redistribution must be conditioned upon
201573Srgrimes *    including a substantially similar Disclaimer requirement for further
211573Srgrimes *    binary redistribution.
221573Srgrimes * 3. Neither the names of the above-listed copyright holders nor the names
231573Srgrimes *    of any contributors may be used to endorse or promote products derived
241573Srgrimes *    from this software without specific prior written permission.
251573Srgrimes *
261573Srgrimes * Alternatively, this software may be distributed under the terms of the
271573Srgrimes * GNU General Public License ("GPL") version 2 as published by the Free
281573Srgrimes * Software Foundation.
291573Srgrimes *
301573Srgrimes * NO WARRANTY
311573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
321573Srgrimes * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
331573Srgrimes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
341573Srgrimes * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
351573Srgrimes * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3692986Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3792986Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
381573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3971579Sdeischen * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4081666Sache * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
411573Srgrimes * POSSIBILITY OF SUCH DAMAGES.
4282838Sache */
4382653Sache
44108866Stjr#define _DECLARE_PR_GLOBALS
451573Srgrimes
4671579Sdeischen#include "aslcompiler.h"
471573Srgrimes#include "dtcompiler.h"
481573Srgrimes
491573Srgrimes/*
501573Srgrimes * TBDs:
511573Srgrimes *
5216586Sjraynard * No nested macros, maybe never
53249810Semaste * Implement ASL "Include" as well as "#include" here?
541573Srgrimes */
5592889Sobrien#define _COMPONENT          ASL_PREPROCESSOR
568870Srgrimes        ACPI_MODULE_NAME    ("prscan")
5782807Sache
581573Srgrimes
591573Srgrimes/* Local prototypes */
6016586Sjraynard
61249810Semastestatic void
621573SrgrimesPrPreprocessInputFile (
6392889Sobrien    void);
641573Srgrimes
6556698Sjasonestatic void
661573SrgrimesPrDoDirective (
671573Srgrimes    char                    *DirectiveToken,
681573Srgrimes    char                    **Next,
69249810Semaste    BOOLEAN                 *IgnoringThisCodeBlock);
701573Srgrimes
7192889Sobrienstatic int
728870SrgrimesPrMatchDirective (
7382807Sache    char                    *Directive);
741573Srgrimes
751573Srgrimes/*
7616586Sjraynard * Supported preprocessor directives
77249810Semaste */
781573Srgrimesstatic const PR_DIRECTIVE_INFO      Gbl_DirectiveInfo[] =
791573Srgrimes{
8056698Sjasone    {"define",  1},
811573Srgrimes    {"elif",    0}, /* Converted to #else..#if internally */
8282838Sache    {"else",    0},
8382838Sache    {"endif",   0},
8482838Sache    {"error",   1},
8582838Sache    {"if",      1},
8682838Sache    {"ifdef",   1},
87249810Semaste    {"ifndef",  1},
8882838Sache    {"include", 0}, /* Argument is not standard format, so 0 */
8982838Sache    {"line",    1},
9082838Sache    {"pragma",  1},
9182838Sache    {"undef",   1},
9282838Sache    {"warning", 1},
9382838Sache    {NULL,      0}
9482838Sache};
9582838Sache
9682838Sacheenum Gbl_DirectiveIndexes
9782838Sache{
9882838Sache    PR_DIRECTIVE_DEFINE = 0,
9982838Sache    PR_DIRECTIVE_ELIF,
10082838Sache    PR_DIRECTIVE_ELSE,
10182838Sache    PR_DIRECTIVE_ENDIF,
10282838Sache    PR_DIRECTIVE_ERROR,
10382838Sache    PR_DIRECTIVE_IF,
10482838Sache    PR_DIRECTIVE_IFDEF,
105249810Semaste    PR_DIRECTIVE_IFNDEF,
10682838Sache    PR_DIRECTIVE_INCLUDE,
10782838Sache    PR_DIRECTIVE_LINE,
10883211Sache    PR_DIRECTIVE_PRAGMA,
10982838Sache    PR_DIRECTIVE_UNDEF,
11083211Sache    PR_DIRECTIVE_WARNING,
11183211Sache};
11283211Sache
11383211Sache#define ASL_DIRECTIVE_NOT_FOUND     -1
11483211Sache
11583211Sache
11683211Sache/*******************************************************************************
11782838Sache *
11882838Sache * FUNCTION:    PrInitializePreprocessor
11982838Sache *
120290544Sache * PARAMETERS:  None
12182838Sache *
12282838Sache * RETURN:      None
12382838Sache *
12482838Sache * DESCRIPTION: Startup initialization for the Preprocessor.
12582838Sache *
12682838Sache ******************************************************************************/
12782838Sache
12882838Sachevoid
12982838SachePrInitializePreprocessor (
13082838Sache    void)
13182838Sache{
132249810Semaste    /* Init globals and the list of #defines */
13382838Sache
13482838Sache    PrInitializeGlobals ();
13582838Sache    Gbl_DefineList = NULL;
13682838Sache}
13782838Sache
13882838Sache
13982838Sache/*******************************************************************************
14082838Sache *
14182838Sache * FUNCTION:    PrInitializeGlobals
14282838Sache *
14382838Sache * PARAMETERS:  None
14482838Sache *
14582838Sache * RETURN:      None
14682838Sache *
14782838Sache * DESCRIPTION: Initialize globals for the Preprocessor. Used for startuup
14882838Sache *              initialization and re-initialization between compiles during
14982838Sache *              a multiple source file compile.
15085418Sache *
15185418Sache ******************************************************************************/
15285418Sache
15385418Sachevoid
15485418SachePrInitializeGlobals (
15585418Sache    void)
15685418Sache{
15782838Sache    /* Init globals */
15882838Sache
15983211Sache    Gbl_IfDepth = 0;
16083211Sache    Gbl_InputFileList = NULL;
16182838Sache    Gbl_CurrentLineNumber = 0;
16282838Sache    Gbl_PreprocessorLineNumber = 1;
16382838Sache    Gbl_PreprocessorError = FALSE;
16482838Sache
16582838Sache    Gbl_MapBlockHead = UtLocalCalloc (sizeof (PR_LINE_MAPPING));
16682838Sache    Gbl_MapBlockHead->Map = UtLocalCalloc (PR_LINES_PER_BLOCK * sizeof (UINT32));
16782838Sache}
16882838Sache
169321074Skib
170321074Skib/*******************************************************************************
171321074Skib *
172321074Skib * FUNCTION:    PrTerminatePreprocessor
173321074Skib *
174321074Skib * PARAMETERS:  None
175321074Skib *
176321074Skib * RETURN:      None
177 *
178 * DESCRIPTION: Termination of the preprocessor. Delete lists. Keep any
179 *              defines that were specified on the command line, in order to
180 *              support multiple compiles with a single compiler invocation.
181 *
182 ******************************************************************************/
183
184void
185PrTerminatePreprocessor (
186    void)
187{
188    PR_DEFINE_INFO          *DefineInfo;
189    PR_LINE_MAPPING         *MapInfo;
190
191
192    /*
193     * The persistent defines (created on the command line) are always at the
194     * end of the list. We save them.
195     */
196    while ((Gbl_DefineList) && (!Gbl_DefineList->Persist))
197    {
198        DefineInfo = Gbl_DefineList;
199        Gbl_DefineList = DefineInfo->Next;
200
201        ACPI_FREE (DefineInfo->Replacement);
202        ACPI_FREE (DefineInfo->Identifier);
203        ACPI_FREE (DefineInfo);
204    }
205
206    /* Clear the line number mappings */
207
208    while (Gbl_MapBlockHead)
209    {
210        MapInfo = Gbl_MapBlockHead;
211        Gbl_MapBlockHead = MapInfo->Next;
212
213        ACPI_FREE (MapInfo->Map);
214        ACPI_FREE (MapInfo);
215    }
216}
217
218
219/*******************************************************************************
220 *
221 * FUNCTION:    PrDoPreprocess
222 *
223 * PARAMETERS:  None
224 *
225 * RETURN:      Error Status. TRUE if error, FALSE if OK.
226 *
227 * DESCRIPTION: Main entry point for the iASL Preprocessor. Input file must
228 *              be already open. Handles multiple input files via the
229 *              #include directive.
230 *
231 ******************************************************************************/
232
233BOOLEAN
234PrDoPreprocess (
235    void)
236{
237    BOOLEAN                 MoreInputFiles;
238
239
240    DbgPrint (ASL_DEBUG_OUTPUT, "Starting preprocessing phase\n\n");
241
242
243    FlSeekFile (ASL_FILE_INPUT, 0);
244    PrDumpPredefinedNames ();
245
246    /* Main preprocessor loop, handles include files */
247
248    do
249    {
250        PrPreprocessInputFile ();
251        MoreInputFiles = PrPopInputFileStack ();
252
253    } while (MoreInputFiles);
254
255
256    /*
257     * TBD: is this necessary? (Do we abort on any preprocessing errors?)
258     */
259    if (Gbl_PreprocessorError)
260    {
261        /* TBD: can't use source_output file for preprocessor error reporting */
262
263        Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle = NULL;
264        PrTerminatePreprocessor ();
265        return (TRUE);
266    }
267
268    /* Point compiler input to the new preprocessor file (.i) */
269
270    FlCloseFile (ASL_FILE_INPUT);
271    Gbl_Files[ASL_FILE_INPUT].Handle = Gbl_Files[ASL_FILE_PREPROCESSOR].Handle;
272    AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
273
274    /* Reset globals to allow compiler to run */
275
276    FlSeekFile (ASL_FILE_INPUT, 0);
277    Gbl_CurrentLineNumber = 1;
278
279    DbgPrint (ASL_DEBUG_OUTPUT, "Preprocessing phase complete \n\n");
280    return (FALSE);
281}
282
283
284/*******************************************************************************
285 *
286 * FUNCTION:    PrPreprocessInputFile
287 *
288 * PARAMETERS:  None
289 *
290 * RETURN:      None
291 *
292 * DESCRIPTION: Preprocess one entire file, line-by-line.
293 *
294 * Input:  Raw user ASL from ASL_FILE_INPUT
295 * Output: Preprocessed file written to ASL_FILE_PREPROCESSOR
296 *
297 ******************************************************************************/
298
299static void
300PrPreprocessInputFile (
301    void)
302{
303    UINT32                  Offset;
304    char                    *Token;
305    char                    *ReplaceString;
306    PR_DEFINE_INFO          *DefineInfo;
307    ACPI_SIZE               TokenOffset;
308    BOOLEAN                 IgnoringThisCodeBlock = FALSE;
309    char                    *Next;
310    int                     OffsetAdjust;
311
312
313    /* Scan line-by-line. Comments and blank lines are skipped by this function */
314
315    while ((Offset = DtGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF)
316    {
317        /* Need a copy of the input line for strok() */
318
319        strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer);
320        Token = PrGetNextToken (Gbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next);
321        OffsetAdjust = 0;
322
323        /* All preprocessor directives must begin with '#' */
324
325        if (Token && (*Token == '#'))
326        {
327            if (strlen (Token) == 1)
328            {
329                Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
330            }
331            else
332            {
333                Token++;    /* Skip leading # */
334            }
335
336            /* Execute the directive, do not write line to output file */
337
338            PrDoDirective (Token, &Next, &IgnoringThisCodeBlock);
339            continue;
340        }
341
342        /*
343         * If we are currently within the part of an IF/ELSE block that is
344         * FALSE, ignore the line and do not write it to the output file.
345         * This continues until an #else or #endif is encountered.
346         */
347        if (IgnoringThisCodeBlock == TRUE)
348        {
349            continue;
350        }
351
352        /* Match and replace all #defined names within this source line */
353
354        while (Token)
355        {
356            DefineInfo = PrMatchDefine (Token);
357            if (DefineInfo)
358            {
359                if (DefineInfo->Body)
360                {
361                    /* This is a macro */
362
363                    DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
364                        "Matched Macro: %s->%s\n",
365                        Gbl_CurrentLineNumber, DefineInfo->Identifier,
366                        DefineInfo->Replacement);
367
368                    PrDoMacroInvocation (Gbl_MainTokenBuffer, Token,
369                        DefineInfo, &Next);
370                }
371                else
372                {
373                    ReplaceString = DefineInfo->Replacement;
374
375                    /* Replace the name in the original line buffer */
376
377                    TokenOffset = Token - Gbl_MainTokenBuffer + OffsetAdjust;
378                    PrReplaceData (
379                        &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token),
380                        ReplaceString, strlen (ReplaceString));
381
382                    /* Adjust for length difference between old and new name length */
383
384                    OffsetAdjust += strlen (ReplaceString) - strlen (Token);
385
386                    DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
387                        "Matched #define: %s->%s\n",
388                        Gbl_CurrentLineNumber, Token,
389                        *ReplaceString ? ReplaceString : "(NULL STRING)");
390                }
391            }
392
393            Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
394        }
395
396        /* Write the possibly modified line to the .i file*/
397
398#if 0
399/* Line prefix */
400        FlPrintFile (ASL_FILE_PREPROCESSOR, "/* %14s  %.5u  i:%.5u */ ",
401            Gbl_Files[ASL_FILE_INPUT].Filename,
402            Gbl_CurrentLineNumber, Gbl_PreprocessorLineNumber);
403#endif
404
405        FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer,
406            strlen (Gbl_CurrentLineBuffer));
407
408        PrSetLineNumber (Gbl_CurrentLineNumber, Gbl_PreprocessorLineNumber);
409        Gbl_PreprocessorLineNumber++;
410    }
411}
412
413
414/*******************************************************************************
415 *
416 * FUNCTION:    PrDoDirective
417 *
418 * PARAMETERS:  Directive               - Pointer to directive name token
419 *              Next                    - "Next" buffer from GetNextToken
420 *              IgnoringThisCodeBlock   - Where the "ignore code" flag is
421 *                                        returned.
422 *
423 * RETURN:      IgnoringThisCodeBlock: Set to TRUE if we are skipping the FALSE
424 *              part of an #if or #else block. Set to FALSE when the
425 *              corresponding #else or #endif is encountered.
426 *
427 * DESCRIPTION: Main processing for all preprocessor directives
428 *
429 ******************************************************************************/
430
431static void
432PrDoDirective (
433    char                    *DirectiveToken,
434    char                    **Next,
435    BOOLEAN                 *IgnoringThisCodeBlock)
436{
437    char                    *Token = Gbl_MainTokenBuffer;
438    char                    *Token2;
439    char                    *End;
440    UINT64                  Value;
441    ACPI_SIZE               TokenOffset;
442    int                     Directive;
443    ACPI_STATUS             Status;
444
445
446    if (!DirectiveToken)
447    {
448        goto SyntaxError;
449    }
450
451    Directive = PrMatchDirective (DirectiveToken);
452    if (Directive == ASL_DIRECTIVE_NOT_FOUND)
453    {
454        PrError (ASL_ERROR, ASL_MSG_UNKNOWN_DIRECTIVE,
455            THIS_TOKEN_OFFSET (DirectiveToken));
456
457        DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
458            "#%s: Unknown directive\n",
459            Gbl_CurrentLineNumber, DirectiveToken);
460        return;
461    }
462
463    /* TBD: Need a faster way to do this: */
464
465    if ((Directive == PR_DIRECTIVE_ELIF) ||
466        (Directive == PR_DIRECTIVE_ELSE) ||
467        (Directive == PR_DIRECTIVE_ENDIF))
468    {
469        DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Begin #%s\n",
470            Gbl_CurrentLineNumber, Gbl_DirectiveInfo[Directive].Name);
471    }
472
473    /*
474     * Need to always check for #else, #elif, #endif regardless of
475     * whether we are ignoring the current code block, since these
476     * are conditional code block terminators.
477     */
478    switch (Directive)
479    {
480    case PR_DIRECTIVE_ELIF:
481        *IgnoringThisCodeBlock = !(*IgnoringThisCodeBlock);
482        if (*IgnoringThisCodeBlock == TRUE)
483        {
484            /* Not executing the ELSE part -- all done here */
485            return;
486        }
487
488        /* Will execute the ELSE..IF part */
489
490        DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
491            "#elif - Executing else block\n",
492            Gbl_CurrentLineNumber);
493        Directive = PR_DIRECTIVE_IF;
494        break;
495
496    case PR_DIRECTIVE_ELSE:
497        *IgnoringThisCodeBlock = !(*IgnoringThisCodeBlock);
498        return;
499
500    case PR_DIRECTIVE_ENDIF:
501        *IgnoringThisCodeBlock = FALSE;
502        Gbl_IfDepth--;
503        if (Gbl_IfDepth < 0)
504        {
505            PrError (ASL_ERROR, ASL_MSG_ENDIF_MISMATCH,
506                THIS_TOKEN_OFFSET (DirectiveToken));
507            Gbl_IfDepth = 0;
508        }
509        return;
510
511    default:
512        break;
513    }
514
515    /*
516     * At this point, if we are ignoring the current code block,
517     * do not process any more directives (i.e., ignore them also.)
518     */
519    if (*IgnoringThisCodeBlock == TRUE)
520    {
521        return;
522    }
523
524    DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Begin #%s\n",
525        Gbl_CurrentLineNumber, Gbl_DirectiveInfo[Directive].Name);
526
527    /* Most directives have at least one argument */
528
529    if (Gbl_DirectiveInfo[Directive].ArgCount == 1)
530    {
531        Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
532        if (!Token)
533        {
534            goto SyntaxError;
535        }
536    }
537
538    switch (Directive)
539    {
540    case PR_DIRECTIVE_DEFINE:
541        /*
542         * By definition, if first char after the name is a paren,
543         * this is a function macro.
544         */
545        TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token);
546        if (*(&Gbl_CurrentLineBuffer[TokenOffset]) == '(')
547        {
548#ifndef MACROS_SUPPORTED
549            AcpiOsPrintf ("#define macros not supported\n");
550            goto SyntaxError;
551#else
552            PrAddMacro (Token, Next);
553#endif
554        }
555        else
556        {
557            /* Use the remainder of the line for the #define */
558
559            Token2 = *Next;
560            if (Token2)
561            {
562                while ((*Token2 == ' ') || (*Token2 == '\t'))
563                {
564                    Token2++;
565                }
566                End = Token2;
567                while (*End != '\n')
568                {
569                    End++;
570                }
571                *End = 0;
572            }
573            else
574            {
575                Token2 = "";
576            }
577#if 0
578            Token2 = PrGetNextToken (NULL, "\n", /*PR_TOKEN_SEPARATORS,*/ Next);
579            if (!Token2)
580            {
581                Token2 = "";
582            }
583#endif
584            DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
585                "New #define: %s->%s\n",
586                Gbl_CurrentLineNumber, Token, Token2);
587
588            PrAddDefine (Token, Token2, FALSE);
589        }
590        break;
591
592    case PR_DIRECTIVE_ERROR:
593        /* TBD compiler should abort */
594        /* Note: No macro expansion */
595
596        PrError (ASL_ERROR, ASL_MSG_ERROR_DIRECTIVE,
597            THIS_TOKEN_OFFSET (Token));
598        break;
599
600    case PR_DIRECTIVE_IF:
601        TokenOffset = Token - Gbl_MainTokenBuffer;
602
603        /* Need to expand #define macros in the expression string first */
604
605        Status = PrResolveIntegerExpression (
606            &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
607        if (ACPI_FAILURE (Status))
608        {
609            return;
610        }
611
612        if (!Value)
613        {
614            *IgnoringThisCodeBlock = TRUE;
615        }
616
617        DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
618            "Resolved #if: %8.8X%8.8X %s\n",
619            Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value),
620            *IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>");
621
622        Gbl_IfDepth++;
623        break;
624
625    case PR_DIRECTIVE_IFDEF:
626        if (!PrMatchDefine (Token))
627        {
628            *IgnoringThisCodeBlock = TRUE;
629        }
630
631        Gbl_IfDepth++;
632        DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
633            "Start #ifdef %s\n", Gbl_CurrentLineNumber,
634            *IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>");
635        break;
636
637    case PR_DIRECTIVE_IFNDEF:
638        if (PrMatchDefine (Token))
639        {
640            *IgnoringThisCodeBlock = TRUE;
641        }
642
643        Gbl_IfDepth++;
644        DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
645            "Start #ifndef %2.2X\n", Gbl_CurrentLineNumber,
646            *IgnoringThisCodeBlock, Gbl_CurrentLineNumber);
647        break;
648
649    case PR_DIRECTIVE_INCLUDE:
650        Token = PrGetNextToken (NULL, " \"<>", Next);
651        if (!Token)
652        {
653            goto SyntaxError;
654        }
655
656        DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
657            "Start #include file %s\n", Gbl_CurrentLineNumber,
658            Token, Gbl_CurrentLineNumber);
659
660        PrOpenIncludeFile (Token);
661        break;
662
663    case PR_DIRECTIVE_PRAGMA:
664        /* Only "#pragma message" supported at this time */
665
666        if (strcmp (Token, "message"))
667        {
668            PrError (ASL_ERROR, ASL_MSG_UNKNOWN_PRAGMA,
669                THIS_TOKEN_OFFSET (Token));
670            return;
671        }
672
673        Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
674        if (!Token)
675        {
676            goto SyntaxError;
677        }
678
679        TokenOffset = Token - Gbl_MainTokenBuffer;
680        AcpiOsPrintf ("%s\n", &Gbl_CurrentLineBuffer[TokenOffset]);
681        break;
682
683    case PR_DIRECTIVE_UNDEF:
684        DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
685            "#undef: %s\n", Gbl_CurrentLineNumber, Token);
686
687        PrRemoveDefine (Token);
688        break;
689
690    case PR_DIRECTIVE_WARNING:
691        PrError (ASL_WARNING, ASL_MSG_ERROR_DIRECTIVE,
692            THIS_TOKEN_OFFSET (Token));
693        break;
694
695    case PR_DIRECTIVE_LINE:
696        /* TBD: set line number -- or, do this in main compiler */
697    default:
698        /* Should never get here */
699        DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
700            "Unrecognized directive: %u\n",
701            Gbl_CurrentLineNumber, Directive);
702        break;
703    }
704
705    return;
706
707
708SyntaxError:
709
710    PrError (ASL_ERROR, ASL_MSG_DIRECTIVE_SYNTAX,
711        THIS_TOKEN_OFFSET (DirectiveToken));
712    return;
713}
714
715
716/*******************************************************************************
717 *
718 * FUNCTION:    PrMatchDirective
719 *
720 * PARAMETERS:  Directive           - Pointer to directive name token
721 *
722 * RETURN:      Index into command array, -1 if not found
723 *
724 * DESCRIPTION: Lookup the incoming directive in the known directives table.
725 *
726 ******************************************************************************/
727
728static int
729PrMatchDirective (
730    char                    *Directive)
731{
732    int                     i;
733
734
735    if (!Directive || Directive[0] == 0)
736    {
737        return (ASL_DIRECTIVE_NOT_FOUND);
738    }
739
740    for (i = 0; Gbl_DirectiveInfo[i].Name; i++)
741    {
742        if (!strcmp (Gbl_DirectiveInfo[i].Name, Directive))
743        {
744            return (i);
745        }
746    }
747
748    return (ASL_DIRECTIVE_NOT_FOUND);    /* Command not recognized */
749}
750