Home | History | Annotate | Line # | Download | only in compiler
aslcompile.c revision 1.14.2.2
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: aslcompile - top level compile module
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7       1.3    jruoho /*
      8  1.14.2.2    martin  * Copyright (C) 2000 - 2020, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11       1.3    jruoho  * Redistribution and use in source and binary forms, with or without
     12       1.3    jruoho  * modification, are permitted provided that the following conditions
     13       1.3    jruoho  * are met:
     14       1.3    jruoho  * 1. Redistributions of source code must retain the above copyright
     15       1.3    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16       1.3    jruoho  *    without modification.
     17       1.3    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.3    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.3    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.3    jruoho  *    including a substantially similar Disclaimer requirement for further
     21       1.3    jruoho  *    binary redistribution.
     22       1.3    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.3    jruoho  *    of any contributors may be used to endorse or promote products derived
     24       1.3    jruoho  *    from this software without specific prior written permission.
     25       1.3    jruoho  *
     26       1.3    jruoho  * Alternatively, this software may be distributed under the terms of the
     27       1.3    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.3    jruoho  * Software Foundation.
     29       1.3    jruoho  *
     30       1.3    jruoho  * NO WARRANTY
     31       1.3    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.3    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33       1.3    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34       1.3    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.3    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.3    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.3    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.3    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.3    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.3    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.3    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42       1.3    jruoho  */
     43       1.3    jruoho 
     44       1.3    jruoho #include "aslcompiler.h"
     45       1.5  christos #include "acnamesp.h"
     46       1.1    jruoho 
     47       1.1    jruoho #include <stdio.h>
     48       1.1    jruoho #include <time.h>
     49       1.3    jruoho #include <acapps.h>
     50       1.1    jruoho 
     51       1.1    jruoho #define _COMPONENT          ACPI_COMPILER
     52       1.1    jruoho         ACPI_MODULE_NAME    ("aslcompile")
     53       1.1    jruoho 
     54       1.4  christos /*
     55       1.4  christos  * Main parser entry
     56       1.4  christos  * External is here in case the parser emits the same external in the
     57       1.4  christos  * generated header. (Newer versions of Bison)
     58       1.4  christos  */
     59       1.4  christos int
     60       1.4  christos AslCompilerparse(
     61       1.4  christos     void);
     62       1.4  christos 
     63       1.1    jruoho /* Local prototypes */
     64       1.1    jruoho 
     65       1.1    jruoho static void
     66       1.1    jruoho CmFlushSourceCode (
     67       1.1    jruoho     void);
     68       1.1    jruoho 
     69       1.3    jruoho static void
     70       1.4  christos CmDumpAllEvents (
     71       1.4  christos     void);
     72       1.4  christos 
     73  1.14.2.1  christos static void
     74  1.14.2.1  christos CmFinishFiles(
     75  1.14.2.1  christos     BOOLEAN                 DeleteAmlFile);
     76  1.14.2.1  christos 
     77       1.1    jruoho 
     78       1.1    jruoho /*******************************************************************************
     79       1.1    jruoho  *
     80       1.1    jruoho  * FUNCTION:    CmDoCompile
     81       1.1    jruoho  *
     82       1.1    jruoho  * PARAMETERS:  None
     83       1.1    jruoho  *
     84       1.1    jruoho  * RETURN:      Status (0 = OK)
     85       1.1    jruoho  *
     86       1.1    jruoho  * DESCRIPTION: This procedure performs the entire compile
     87       1.1    jruoho  *
     88       1.1    jruoho  ******************************************************************************/
     89       1.1    jruoho 
     90  1.14.2.1  christos ACPI_STATUS
     91       1.1    jruoho CmDoCompile (
     92       1.1    jruoho     void)
     93       1.1    jruoho {
     94       1.1    jruoho     UINT8                   FullCompile;
     95       1.1    jruoho     UINT8                   Event;
     96  1.14.2.1  christos     ASL_GLOBAL_FILE_NODE    *FileNode;
     97       1.1    jruoho 
     98       1.1    jruoho 
     99       1.1    jruoho     FullCompile = UtBeginEvent ("*** Total Compile time ***");
    100       1.1    jruoho     Event = UtBeginEvent ("Open input and output files");
    101       1.1    jruoho     UtEndEvent (Event);
    102       1.1    jruoho 
    103       1.4  christos     Event = UtBeginEvent ("Preprocess input file");
    104  1.14.2.1  christos     if (AslGbl_PreprocessFlag)
    105       1.4  christos     {
    106       1.7  christos         /* Enter compiler name as a #define */
    107       1.7  christos 
    108       1.7  christos         PrAddDefine (ASL_DEFINE, "", FALSE);
    109       1.7  christos 
    110       1.4  christos         /* Preprocessor */
    111       1.4  christos 
    112       1.4  christos         PrDoPreprocess ();
    113  1.14.2.1  christos         AslGbl_CurrentLineNumber = 1;
    114  1.14.2.1  christos         AslGbl_LogicalLineNumber = 1;
    115  1.14.2.2    martin         AslGbl_CurrentLineOffset = 0;
    116       1.7  christos 
    117  1.14.2.1  christos         if (AslGbl_PreprocessOnly)
    118       1.4  christos         {
    119       1.4  christos             UtEndEvent (Event);
    120       1.4  christos             CmCleanupAndExit ();
    121  1.14.2.1  christos             return (AE_OK);
    122       1.4  christos         }
    123       1.4  christos     }
    124       1.4  christos     UtEndEvent (Event);
    125       1.4  christos 
    126       1.7  christos 
    127       1.1    jruoho     /* Build the parse tree */
    128       1.1    jruoho 
    129       1.1    jruoho     Event = UtBeginEvent ("Parse source code and build parse tree");
    130       1.1    jruoho     AslCompilerparse();
    131       1.1    jruoho     UtEndEvent (Event);
    132       1.1    jruoho 
    133       1.6  christos     /* Check for parser-detected syntax errors */
    134       1.1    jruoho 
    135  1.14.2.1  christos     if (AslGbl_SyntaxError)
    136       1.4  christos     {
    137       1.8  christos         fprintf (stderr,
    138       1.8  christos             "Compiler aborting due to parser-detected syntax error(s)\n");
    139  1.14.2.1  christos 
    140  1.14.2.1  christos         /* Flag this error in the FileNode for compilation summary */
    141  1.14.2.1  christos 
    142  1.14.2.1  christos         FileNode = FlGetCurrentFileNode ();
    143  1.14.2.1  christos         FileNode->ParserErrorDetected = TRUE;
    144  1.14.2.1  christos         AslGbl_ParserErrorDetected = TRUE;
    145       1.4  christos         LsDumpParseTree ();
    146       1.4  christos         goto ErrorExit;
    147       1.4  christos     }
    148       1.1    jruoho 
    149       1.1    jruoho     /* Did the parse tree get successfully constructed? */
    150       1.1    jruoho 
    151  1.14.2.1  christos     if (!AslGbl_ParseTreeRoot)
    152       1.1    jruoho     {
    153       1.4  christos         /*
    154       1.4  christos          * If there are no errors, then we have some sort of
    155       1.4  christos          * internal problem.
    156       1.4  christos          */
    157       1.4  christos         AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
    158       1.4  christos             NULL, "- Could not resolve parse tree root node");
    159       1.4  christos 
    160       1.4  christos         goto ErrorExit;
    161       1.1    jruoho     }
    162       1.1    jruoho 
    163       1.4  christos     /* Flush out any remaining source after parse tree is complete */
    164       1.4  christos 
    165       1.4  christos     Event = UtBeginEvent ("Flush source input");
    166       1.4  christos     CmFlushSourceCode ();
    167       1.4  christos 
    168       1.6  christos     /* Prune the parse tree if requested (debug purposes only) */
    169       1.6  christos 
    170  1.14.2.1  christos     if (AslGbl_PruneParseTree)
    171       1.6  christos     {
    172  1.14.2.1  christos         AslPruneParseTree (AslGbl_PruneDepth, AslGbl_PruneType);
    173       1.6  christos     }
    174       1.6  christos 
    175       1.1    jruoho     /* Optional parse tree dump, compiler debug output only */
    176       1.1    jruoho 
    177       1.1    jruoho     LsDumpParseTree ();
    178       1.1    jruoho 
    179       1.1    jruoho     UtEndEvent (Event);
    180  1.14.2.1  christos     UtEndEvent (FullCompile);
    181  1.14.2.1  christos     return (AE_OK);
    182  1.14.2.1  christos 
    183  1.14.2.1  christos ErrorExit:
    184  1.14.2.1  christos     UtEndEvent (FullCompile);
    185  1.14.2.1  christos     return (AE_ERROR);
    186  1.14.2.1  christos }
    187  1.14.2.1  christos 
    188  1.14.2.1  christos 
    189  1.14.2.1  christos /*******************************************************************************
    190  1.14.2.1  christos  *
    191  1.14.2.1  christos  * FUNCTION:    CmDoAslMiddleAndBackEnd
    192  1.14.2.1  christos  *
    193  1.14.2.1  christos  * PARAMETERS:  None
    194  1.14.2.1  christos  *
    195  1.14.2.1  christos  * RETURN:      Status of middle-end and back-end
    196  1.14.2.1  christos  *
    197  1.14.2.1  christos  * DESCRIPTION: Perform compiler middle-end (type checking and semantic
    198  1.14.2.1  christos  *              analysis) and back-end (code generation)
    199  1.14.2.1  christos  *
    200  1.14.2.1  christos  ******************************************************************************/
    201  1.14.2.1  christos 
    202  1.14.2.1  christos int
    203  1.14.2.1  christos CmDoAslMiddleAndBackEnd (
    204  1.14.2.1  christos     void)
    205  1.14.2.1  christos {
    206  1.14.2.1  christos     UINT8                   Event;
    207  1.14.2.1  christos     ACPI_STATUS             Status;
    208  1.14.2.1  christos 
    209       1.1    jruoho 
    210  1.14.2.2    martin     OpcGetIntegerWidth (AslGbl_ParseTreeRoot->Asl.Child);
    211  1.14.2.2    martin 
    212  1.14.2.2    martin     /* Pre-process parse tree for any operator transforms */
    213  1.14.2.2    martin 
    214  1.14.2.2    martin     Event = UtBeginEvent ("Parse tree transforms");
    215  1.14.2.2    martin     DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n");
    216  1.14.2.2    martin     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
    217  1.14.2.2    martin         TrAmlTransformWalkBegin, TrAmlTransformWalkEnd, NULL);
    218  1.14.2.2    martin     UtEndEvent (Event);
    219  1.14.2.2    martin 
    220  1.14.2.2    martin     /* Generate AML opcodes corresponding to the parse tokens */
    221  1.14.2.2    martin 
    222  1.14.2.2    martin     Event = UtBeginEvent ("Generate AML opcodes");
    223  1.14.2.2    martin     DbgPrint (ASL_DEBUG_OUTPUT, "Generating AML opcodes\n\n");
    224  1.14.2.2    martin     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
    225  1.14.2.2    martin         NULL, OpcAmlOpcodeWalk, NULL);
    226  1.14.2.2    martin     UtEndEvent (Event);
    227  1.14.2.2    martin 
    228  1.14.2.2    martin 
    229       1.1    jruoho     /* Interpret and generate all compile-time constants */
    230       1.1    jruoho 
    231       1.1    jruoho     Event = UtBeginEvent ("Constant folding via AML interpreter");
    232       1.1    jruoho     DbgPrint (ASL_DEBUG_OUTPUT,
    233       1.9  christos         "Interpreting compile-time constant expressions\n\n");
    234       1.6  christos 
    235  1.14.2.1  christos     if (AslGbl_FoldConstants)
    236       1.6  christos     {
    237  1.14.2.1  christos         TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
    238       1.9  christos             NULL, OpcAmlConstantWalk, NULL);
    239       1.6  christos     }
    240       1.6  christos     else
    241       1.6  christos     {
    242       1.6  christos         DbgPrint (ASL_PARSE_OUTPUT, "    Optional folding disabled\n");
    243       1.6  christos     }
    244       1.1    jruoho     UtEndEvent (Event);
    245       1.1    jruoho 
    246       1.1    jruoho     /* Update AML opcodes if necessary, after constant folding */
    247       1.1    jruoho 
    248       1.1    jruoho     Event = UtBeginEvent ("Updating AML opcodes after constant folding");
    249       1.1    jruoho     DbgPrint (ASL_DEBUG_OUTPUT,
    250       1.9  christos         "Updating AML opcodes after constant folding\n\n");
    251  1.14.2.1  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
    252       1.1    jruoho         NULL, OpcAmlOpcodeUpdateWalk, NULL);
    253       1.1    jruoho     UtEndEvent (Event);
    254       1.1    jruoho 
    255       1.1    jruoho     /* Calculate all AML package lengths */
    256       1.1    jruoho 
    257       1.1    jruoho     Event = UtBeginEvent ("Generate AML package lengths");
    258       1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");
    259  1.14.2.1  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
    260       1.1    jruoho         LnPackageLengthWalk, NULL);
    261       1.1    jruoho     UtEndEvent (Event);
    262       1.1    jruoho 
    263  1.14.2.1  christos     if (AslGbl_ParseOnlyFlag)
    264       1.1    jruoho     {
    265       1.4  christos         AePrintErrorLog (ASL_FILE_STDERR);
    266       1.4  christos         UtDisplaySummary (ASL_FILE_STDERR);
    267  1.14.2.1  christos         if (AslGbl_DebugFlag)
    268       1.1    jruoho         {
    269       1.4  christos             /* Print error summary to the stdout also */
    270       1.1    jruoho 
    271       1.4  christos             AePrintErrorLog (ASL_FILE_STDOUT);
    272       1.4  christos             UtDisplaySummary (ASL_FILE_STDOUT);
    273       1.1    jruoho         }
    274       1.4  christos         return (0);
    275       1.1    jruoho     }
    276       1.1    jruoho 
    277       1.1    jruoho     /*
    278       1.1    jruoho      * Create an internal namespace and use it as a symbol table
    279       1.1    jruoho      */
    280       1.1    jruoho 
    281       1.1    jruoho     /* Namespace loading */
    282       1.1    jruoho 
    283       1.1    jruoho     Event = UtBeginEvent ("Create ACPI Namespace");
    284       1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Creating ACPI Namespace\n\n");
    285  1.14.2.1  christos     Status = LdLoadNamespace (AslGbl_ParseTreeRoot);
    286       1.1    jruoho     UtEndEvent (Event);
    287       1.1    jruoho     if (ACPI_FAILURE (Status))
    288       1.1    jruoho     {
    289  1.14.2.1  christos         return (-1);
    290       1.1    jruoho     }
    291       1.1    jruoho 
    292       1.1    jruoho     /* Namespace cross-reference */
    293       1.1    jruoho 
    294       1.8  christos     AslGbl_NamespaceEvent = UtBeginEvent (
    295       1.8  christos         "Cross reference parse tree and Namespace");
    296       1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Cross referencing namespace\n\n");
    297       1.4  christos     Status = XfCrossReferenceNamespace ();
    298       1.1    jruoho     if (ACPI_FAILURE (Status))
    299       1.1    jruoho     {
    300  1.14.2.1  christos         return (-1);
    301       1.1    jruoho     }
    302       1.1    jruoho 
    303       1.1    jruoho     /* Namespace - Check for non-referenced objects */
    304       1.1    jruoho 
    305       1.1    jruoho     LkFindUnreferencedObjects ();
    306       1.1    jruoho     UtEndEvent (AslGbl_NamespaceEvent);
    307       1.1    jruoho 
    308       1.9  christos     /* Resolve External Declarations */
    309       1.9  christos 
    310  1.14.2.1  christos     Event = UtBeginEvent ("Resolve all Externals");
    311  1.14.2.1  christos     DbgPrint (ASL_DEBUG_OUTPUT, "\nResolve Externals\n\n");
    312      1.11  christos 
    313  1.14.2.1  christos     if (AslGbl_DoExternalsInPlace)
    314  1.14.2.1  christos     {
    315  1.14.2.1  christos         TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
    316  1.14.2.1  christos             ExAmlExternalWalkBegin, NULL, NULL);
    317  1.14.2.1  christos     }
    318  1.14.2.1  christos     else
    319  1.14.2.1  christos     {
    320  1.14.2.1  christos         TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
    321  1.14.2.1  christos             ExAmlExternalWalkBegin, ExAmlExternalWalkEnd, NULL);
    322       1.9  christos     }
    323  1.14.2.1  christos     UtEndEvent (Event);
    324       1.9  christos 
    325       1.1    jruoho     /*
    326       1.4  christos      * Semantic analysis. This can happen only after the
    327       1.1    jruoho      * namespace has been loaded and cross-referenced.
    328       1.1    jruoho      *
    329       1.1    jruoho      * part one - check control methods
    330       1.1    jruoho      */
    331       1.1    jruoho     Event = UtBeginEvent ("Analyze control method return types");
    332  1.14.2.1  christos     AslGbl_AnalysisWalkInfo.MethodStack = NULL;
    333       1.1    jruoho 
    334       1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method analysis\n\n");
    335       1.9  christos 
    336  1.14.2.1  christos     if (AslGbl_CrossReferenceOutput)
    337       1.9  christos     {
    338       1.9  christos         OtPrintHeaders ("Part 1: Object Reference Map "
    339       1.9  christos             "(Object references from within each control method)");
    340       1.9  christos     }
    341       1.9  christos 
    342  1.14.2.1  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
    343       1.4  christos         MtMethodAnalysisWalkBegin,
    344  1.14.2.1  christos         MtMethodAnalysisWalkEnd, &AslGbl_AnalysisWalkInfo);
    345       1.1    jruoho     UtEndEvent (Event);
    346       1.1    jruoho 
    347       1.9  christos     /* Generate the object cross-reference file if requested */
    348       1.9  christos 
    349       1.9  christos     Event = UtBeginEvent ("Generate cross-reference file");
    350       1.9  christos     OtCreateXrefFile ();
    351       1.9  christos     UtEndEvent (Event);
    352       1.9  christos 
    353       1.1    jruoho     /* Semantic error checking part two - typing of method returns */
    354       1.1    jruoho 
    355       1.1    jruoho     Event = UtBeginEvent ("Determine object types returned by methods");
    356       1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method typing\n\n");
    357  1.14.2.1  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
    358       1.3    jruoho         NULL, AnMethodTypingWalkEnd, NULL);
    359       1.1    jruoho     UtEndEvent (Event);
    360       1.1    jruoho 
    361       1.1    jruoho     /* Semantic error checking part three - operand type checking */
    362       1.1    jruoho 
    363       1.1    jruoho     Event = UtBeginEvent ("Analyze AML operand types");
    364       1.8  christos     DbgPrint (ASL_DEBUG_OUTPUT,
    365       1.9  christos         "Semantic analysis - Operand type checking\n\n");
    366  1.14.2.1  christos     if (AslGbl_DoTypechecking)
    367       1.8  christos     {
    368  1.14.2.1  christos         TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
    369  1.14.2.1  christos             NULL, AnOperandTypecheckWalkEnd, &AslGbl_AnalysisWalkInfo);
    370       1.8  christos     }
    371       1.1    jruoho     UtEndEvent (Event);
    372       1.1    jruoho 
    373       1.1    jruoho     /* Semantic error checking part four - other miscellaneous checks */
    374       1.1    jruoho 
    375       1.1    jruoho     Event = UtBeginEvent ("Miscellaneous analysis");
    376       1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - miscellaneous\n\n");
    377  1.14.2.1  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
    378       1.1    jruoho         AnOtherSemanticAnalysisWalkBegin,
    379  1.14.2.1  christos         NULL, &AslGbl_AnalysisWalkInfo);
    380       1.1    jruoho     UtEndEvent (Event);
    381       1.1    jruoho 
    382      1.11  christos     /*
    383      1.11  christos      * ASL-/ASL+ converter: Gbl_ParseTreeRoot->CommentList contains the
    384      1.11  christos      * very last comment of a given ASL file because it's the last constructed
    385      1.11  christos      * node during compilation. We take the very last comment and save it in a
    386      1.11  christos      * global for it to be used by the disassembler.
    387      1.11  christos      */
    388      1.14  christos     if (AcpiGbl_CaptureComments)
    389      1.11  christos     {
    390  1.14.2.1  christos         AcpiGbl_LastListHead = AslGbl_ParseTreeRoot->Asl.CommentList;
    391  1.14.2.1  christos         AslGbl_ParseTreeRoot->Asl.CommentList = NULL;
    392      1.11  christos     }
    393      1.11  christos 
    394       1.1    jruoho     /* Calculate all AML package lengths */
    395       1.1    jruoho 
    396       1.1    jruoho     Event = UtBeginEvent ("Finish AML package length generation");
    397       1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");
    398  1.14.2.1  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
    399       1.1    jruoho         LnInitLengthsWalk, NULL);
    400  1.14.2.1  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
    401       1.1    jruoho         LnPackageLengthWalk, NULL);
    402       1.1    jruoho     UtEndEvent (Event);
    403       1.1    jruoho 
    404       1.1    jruoho     /* Code generation - emit the AML */
    405       1.1    jruoho 
    406       1.1    jruoho     Event = UtBeginEvent ("Generate AML code and write output files");
    407       1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Writing AML byte code\n\n");
    408  1.14.2.1  christos 
    409  1.14.2.1  christos     AslGbl_CurrentDB = AslGbl_ParseTreeRoot->Asl.Child;
    410  1.14.2.1  christos 
    411  1.14.2.1  christos     while (AslGbl_CurrentDB)
    412  1.14.2.1  christos     {
    413  1.14.2.1  christos         switch  (FlSwitchFileSet(AslGbl_CurrentDB->Asl.Filename))
    414  1.14.2.1  christos         {
    415  1.14.2.1  christos             case SWITCH_TO_DIFFERENT_FILE:
    416  1.14.2.1  christos                 /*
    417  1.14.2.1  christos                  * Reset these parameters when definition blocks belong in
    418  1.14.2.1  christos                  * different files. If they belong in the same file, there is
    419  1.14.2.1  christos                  * no need to reset these parameters
    420  1.14.2.1  christos                  */
    421  1.14.2.1  christos                 FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
    422  1.14.2.1  christos                 AslGbl_SourceLine = 0;
    423  1.14.2.1  christos                 AslGbl_NextError = AslGbl_ErrorLog;
    424  1.14.2.1  christos 
    425  1.14.2.1  christos                 /* fall-through */
    426  1.14.2.1  christos 
    427  1.14.2.1  christos             case SWITCH_TO_SAME_FILE:
    428  1.14.2.1  christos 
    429  1.14.2.1  christos                 CgGenerateAmlOutput ();
    430  1.14.2.1  christos                 CmDoOutputFiles ();
    431  1.14.2.1  christos                 AslGbl_CurrentDB = AslGbl_CurrentDB->Asl.Next;
    432  1.14.2.1  christos 
    433  1.14.2.1  christos                 break;
    434  1.14.2.1  christos 
    435  1.14.2.1  christos             default: /* FILE_NOT_FOUND */
    436  1.14.2.1  christos 
    437  1.14.2.1  christos                 /* The requested file could not be found. Get out of here */
    438  1.14.2.1  christos 
    439  1.14.2.1  christos                 AslGbl_CurrentDB = NULL;
    440  1.14.2.1  christos                 break;
    441  1.14.2.1  christos         }
    442  1.14.2.1  christos     }
    443       1.1    jruoho     UtEndEvent (Event);
    444       1.1    jruoho 
    445       1.1    jruoho     Event = UtBeginEvent ("Write optional output files");
    446       1.1    jruoho     UtEndEvent (Event);
    447       1.1    jruoho 
    448       1.4  christos     return (0);
    449       1.1    jruoho }
    450       1.1    jruoho 
    451       1.1    jruoho 
    452       1.1    jruoho /*******************************************************************************
    453       1.1    jruoho  *
    454       1.5  christos  * FUNCTION:    AslCompilerSignon
    455       1.5  christos  *
    456       1.5  christos  * PARAMETERS:  FileId      - ID of the output file
    457       1.5  christos  *
    458       1.5  christos  * RETURN:      None
    459       1.5  christos  *
    460       1.5  christos  * DESCRIPTION: Display compiler signon
    461       1.5  christos  *
    462       1.5  christos  ******************************************************************************/
    463       1.5  christos 
    464       1.5  christos void
    465       1.5  christos AslCompilerSignon (
    466       1.5  christos     UINT32                  FileId)
    467       1.5  christos {
    468       1.5  christos     char                    *Prefix = "";
    469       1.5  christos     char                    *UtilityName;
    470       1.5  christos 
    471       1.5  christos 
    472       1.5  christos     /* Set line prefix depending on the destination file type */
    473       1.5  christos 
    474       1.5  christos     switch (FileId)
    475       1.5  christos     {
    476       1.5  christos     case ASL_FILE_ASM_SOURCE_OUTPUT:
    477       1.5  christos     case ASL_FILE_ASM_INCLUDE_OUTPUT:
    478       1.5  christos 
    479       1.5  christos         Prefix = "; ";
    480       1.5  christos         break;
    481       1.5  christos 
    482       1.5  christos     case ASL_FILE_HEX_OUTPUT:
    483       1.5  christos 
    484  1.14.2.1  christos         if (AslGbl_HexOutputFlag == HEX_OUTPUT_ASM)
    485       1.5  christos         {
    486       1.5  christos             Prefix = "; ";
    487       1.5  christos         }
    488  1.14.2.1  christos         else if ((AslGbl_HexOutputFlag == HEX_OUTPUT_C) ||
    489  1.14.2.1  christos                  (AslGbl_HexOutputFlag == HEX_OUTPUT_ASL))
    490       1.5  christos         {
    491       1.5  christos             FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
    492       1.5  christos             Prefix = " * ";
    493       1.5  christos         }
    494       1.5  christos         break;
    495       1.5  christos 
    496       1.5  christos     case ASL_FILE_C_SOURCE_OUTPUT:
    497       1.5  christos     case ASL_FILE_C_OFFSET_OUTPUT:
    498       1.5  christos     case ASL_FILE_C_INCLUDE_OUTPUT:
    499       1.5  christos 
    500       1.5  christos         Prefix = " * ";
    501       1.5  christos         break;
    502       1.5  christos 
    503       1.5  christos     default:
    504       1.5  christos 
    505       1.5  christos         /* No other output types supported */
    506       1.5  christos 
    507       1.5  christos         break;
    508       1.5  christos     }
    509       1.5  christos 
    510       1.5  christos     /* Running compiler or disassembler? */
    511       1.5  christos 
    512      1.12  christos     if (AcpiGbl_DisasmFlag)
    513       1.5  christos     {
    514       1.5  christos         UtilityName = AML_DISASSEMBLER_NAME;
    515       1.5  christos     }
    516       1.5  christos     else
    517       1.5  christos     {
    518       1.5  christos         UtilityName = ASL_COMPILER_NAME;
    519       1.5  christos     }
    520       1.5  christos 
    521       1.5  christos     /* Compiler signon with copyright */
    522       1.5  christos 
    523       1.5  christos     FlPrintFile (FileId, "%s\n", Prefix);
    524       1.5  christos     FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix));
    525       1.5  christos }
    526       1.5  christos 
    527       1.5  christos 
    528       1.5  christos /*******************************************************************************
    529       1.5  christos  *
    530       1.5  christos  * FUNCTION:    AslCompilerFileHeader
    531       1.5  christos  *
    532       1.5  christos  * PARAMETERS:  FileId      - ID of the output file
    533       1.5  christos  *
    534       1.5  christos  * RETURN:      None
    535       1.5  christos  *
    536       1.5  christos  * DESCRIPTION: Header used at the beginning of output files
    537       1.5  christos  *
    538       1.5  christos  ******************************************************************************/
    539       1.5  christos 
    540       1.5  christos void
    541       1.5  christos AslCompilerFileHeader (
    542       1.5  christos     UINT32                  FileId)
    543       1.5  christos {
    544  1.14.2.2    martin     char                    *NewTime;
    545       1.5  christos     time_t                  Aclock;
    546       1.5  christos     char                    *Prefix = "";
    547       1.5  christos 
    548       1.5  christos 
    549       1.5  christos     /* Set line prefix depending on the destination file type */
    550       1.5  christos 
    551       1.5  christos     switch (FileId)
    552       1.5  christos     {
    553       1.5  christos     case ASL_FILE_ASM_SOURCE_OUTPUT:
    554       1.5  christos     case ASL_FILE_ASM_INCLUDE_OUTPUT:
    555       1.5  christos 
    556       1.5  christos         Prefix = "; ";
    557       1.5  christos         break;
    558       1.5  christos 
    559       1.5  christos     case ASL_FILE_HEX_OUTPUT:
    560       1.5  christos 
    561  1.14.2.1  christos         if (AslGbl_HexOutputFlag == HEX_OUTPUT_ASM)
    562       1.5  christos         {
    563       1.5  christos             Prefix = "; ";
    564       1.5  christos         }
    565  1.14.2.1  christos         else if ((AslGbl_HexOutputFlag == HEX_OUTPUT_C) ||
    566  1.14.2.1  christos                  (AslGbl_HexOutputFlag == HEX_OUTPUT_ASL))
    567       1.5  christos         {
    568       1.5  christos             Prefix = " * ";
    569       1.5  christos         }
    570       1.5  christos         break;
    571       1.5  christos 
    572       1.5  christos     case ASL_FILE_C_SOURCE_OUTPUT:
    573       1.5  christos     case ASL_FILE_C_OFFSET_OUTPUT:
    574       1.5  christos     case ASL_FILE_C_INCLUDE_OUTPUT:
    575       1.5  christos 
    576       1.5  christos         Prefix = " * ";
    577       1.5  christos         break;
    578       1.5  christos 
    579       1.5  christos     default:
    580       1.5  christos 
    581       1.5  christos         /* No other output types supported */
    582       1.5  christos 
    583       1.5  christos         break;
    584       1.5  christos     }
    585       1.5  christos 
    586       1.5  christos     /* Compilation header with timestamp */
    587       1.5  christos 
    588  1.14.2.2    martin     Aclock = time (NULL);
    589  1.14.2.2    martin     NewTime = ctime (&Aclock);
    590       1.5  christos 
    591       1.5  christos     FlPrintFile (FileId,
    592  1.14.2.2    martin         "%sCompilation of \"%s\" -",
    593  1.14.2.2    martin         Prefix, AslGbl_Files[ASL_FILE_INPUT].Filename);
    594  1.14.2.2    martin 
    595  1.14.2.2    martin     if (NewTime)
    596  1.14.2.2    martin     {
    597  1.14.2.2    martin         FlPrintFile (FileId, " %s%s\n", NewTime, Prefix);
    598  1.14.2.2    martin     }
    599       1.5  christos 
    600       1.5  christos     switch (FileId)
    601       1.5  christos     {
    602       1.5  christos     case ASL_FILE_C_SOURCE_OUTPUT:
    603       1.5  christos     case ASL_FILE_C_OFFSET_OUTPUT:
    604       1.5  christos     case ASL_FILE_C_INCLUDE_OUTPUT:
    605       1.5  christos 
    606       1.5  christos         FlPrintFile (FileId, " */\n");
    607       1.5  christos         break;
    608       1.5  christos 
    609       1.5  christos     default:
    610       1.5  christos 
    611       1.5  christos         /* Nothing to do for other output types */
    612       1.5  christos 
    613       1.5  christos         break;
    614       1.5  christos     }
    615       1.5  christos }
    616       1.5  christos 
    617       1.5  christos 
    618       1.5  christos /*******************************************************************************
    619       1.5  christos  *
    620       1.5  christos  * FUNCTION:    CmFlushSourceCode
    621       1.5  christos  *
    622       1.5  christos  * PARAMETERS:  None
    623       1.5  christos  *
    624       1.5  christos  * RETURN:      None
    625       1.5  christos  *
    626       1.5  christos  * DESCRIPTION: Read in any remaining source code after the parse tree
    627       1.5  christos  *              has been constructed.
    628       1.5  christos  *
    629       1.5  christos  ******************************************************************************/
    630       1.5  christos 
    631       1.5  christos static void
    632       1.5  christos CmFlushSourceCode (
    633       1.5  christos     void)
    634       1.5  christos {
    635       1.5  christos     char                    Buffer;
    636       1.5  christos 
    637       1.5  christos 
    638       1.5  christos     while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)
    639       1.5  christos     {
    640       1.5  christos         AslInsertLineBuffer ((int) Buffer);
    641       1.5  christos     }
    642       1.5  christos 
    643       1.5  christos     AslResetCurrentLineBuffer ();
    644       1.5  christos }
    645       1.5  christos 
    646       1.5  christos 
    647       1.5  christos /*******************************************************************************
    648       1.5  christos  *
    649       1.1    jruoho  * FUNCTION:    CmDoOutputFiles
    650       1.1    jruoho  *
    651       1.1    jruoho  * PARAMETERS:  None
    652       1.1    jruoho  *
    653       1.1    jruoho  * RETURN:      None.
    654       1.1    jruoho  *
    655       1.1    jruoho  * DESCRIPTION: Create all "listing" type files
    656       1.1    jruoho  *
    657       1.1    jruoho  ******************************************************************************/
    658       1.1    jruoho 
    659       1.1    jruoho void
    660       1.1    jruoho CmDoOutputFiles (
    661       1.1    jruoho     void)
    662       1.1    jruoho {
    663       1.1    jruoho 
    664       1.1    jruoho     /* Create listings and hex files */
    665       1.1    jruoho 
    666       1.1    jruoho     LsDoListings ();
    667       1.4  christos     HxDoHexOutput ();
    668       1.1    jruoho 
    669       1.1    jruoho     /* Dump the namespace to the .nsp file if requested */
    670       1.1    jruoho 
    671       1.4  christos     (void) NsDisplayNamespace ();
    672       1.5  christos 
    673       1.5  christos     /* Dump the device mapping file */
    674       1.5  christos 
    675       1.5  christos     MpEmitMappingInfo ();
    676       1.1    jruoho }
    677       1.1    jruoho 
    678       1.1    jruoho 
    679       1.1    jruoho /*******************************************************************************
    680       1.1    jruoho  *
    681       1.4  christos  * FUNCTION:    CmDumpAllEvents
    682       1.1    jruoho  *
    683       1.4  christos  * PARAMETERS:  None
    684       1.1    jruoho  *
    685       1.1    jruoho  * RETURN:      None.
    686       1.1    jruoho  *
    687       1.4  christos  * DESCRIPTION: Dump all compiler events
    688       1.1    jruoho  *
    689       1.1    jruoho  ******************************************************************************/
    690       1.1    jruoho 
    691       1.1    jruoho static void
    692       1.4  christos CmDumpAllEvents (
    693       1.4  christos     void)
    694       1.1    jruoho {
    695       1.4  christos     ASL_EVENT_INFO          *Event;
    696       1.1    jruoho     UINT32                  Delta;
    697       1.8  christos     UINT32                  MicroSeconds;
    698       1.8  christos     UINT32                  MilliSeconds;
    699       1.4  christos     UINT32                  i;
    700       1.4  christos 
    701       1.1    jruoho 
    702       1.4  christos     Event = AslGbl_Events;
    703       1.4  christos 
    704       1.4  christos     DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");
    705  1.14.2.1  christos     if (AslGbl_CompileTimesFlag)
    706       1.1    jruoho     {
    707       1.4  christos         printf ("\nElapsed time for major events\n\n");
    708       1.1    jruoho     }
    709       1.1    jruoho 
    710       1.4  christos     for (i = 0; i < AslGbl_NextEvent; i++)
    711       1.4  christos     {
    712       1.4  christos         if (Event->Valid)
    713       1.4  christos         {
    714       1.4  christos             /* Delta will be in 100-nanosecond units */
    715       1.1    jruoho 
    716       1.4  christos             Delta = (UINT32) (Event->EndTime - Event->StartTime);
    717       1.1    jruoho 
    718       1.8  christos             MicroSeconds = Delta / ACPI_100NSEC_PER_USEC;
    719       1.8  christos             MilliSeconds = Delta / ACPI_100NSEC_PER_MSEC;
    720       1.1    jruoho 
    721       1.4  christos             /* Round milliseconds up */
    722       1.1    jruoho 
    723       1.8  christos             if ((MicroSeconds - (MilliSeconds * ACPI_USEC_PER_MSEC)) >= 500)
    724       1.4  christos             {
    725       1.8  christos                 MilliSeconds++;
    726       1.4  christos             }
    727       1.4  christos 
    728       1.4  christos             DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",
    729       1.8  christos                 MicroSeconds, MilliSeconds, Event->EventName);
    730       1.4  christos 
    731  1.14.2.1  christos             if (AslGbl_CompileTimesFlag)
    732       1.4  christos             {
    733       1.4  christos                 printf ("%8u usec %8u msec - %s\n",
    734       1.8  christos                     MicroSeconds, MilliSeconds, Event->EventName);
    735       1.4  christos             }
    736       1.4  christos         }
    737       1.4  christos 
    738       1.4  christos         Event++;
    739       1.1    jruoho     }
    740       1.1    jruoho }
    741       1.1    jruoho 
    742       1.1    jruoho 
    743       1.1    jruoho /*******************************************************************************
    744       1.1    jruoho  *
    745       1.1    jruoho  * FUNCTION:    CmCleanupAndExit
    746       1.1    jruoho  *
    747       1.1    jruoho  * PARAMETERS:  None
    748       1.1    jruoho  *
    749       1.1    jruoho  * RETURN:      None.
    750       1.1    jruoho  *
    751       1.1    jruoho  * DESCRIPTION: Close all open files and exit the compiler
    752       1.1    jruoho  *
    753       1.1    jruoho  ******************************************************************************/
    754       1.1    jruoho 
    755       1.1    jruoho void
    756       1.1    jruoho CmCleanupAndExit (
    757       1.1    jruoho     void)
    758       1.1    jruoho {
    759       1.4  christos     BOOLEAN                 DeleteAmlFile = FALSE;
    760  1.14.2.1  christos     ASL_GLOBAL_FILE_NODE    *CurrentFileNode = AslGbl_FilesList;
    761  1.14.2.1  christos 
    762  1.14.2.1  christos 
    763  1.14.2.1  christos     /* Check if any errors occurred during compile */
    764       1.1    jruoho 
    765  1.14.2.1  christos     (void) AslCheckForErrorExit ();
    766       1.1    jruoho 
    767       1.4  christos     AePrintErrorLog (ASL_FILE_STDERR);
    768  1.14.2.1  christos     if (AslGbl_DebugFlag)
    769       1.1    jruoho     {
    770       1.4  christos         /* Print error summary to stdout also */
    771       1.1    jruoho 
    772       1.4  christos         AePrintErrorLog (ASL_FILE_STDOUT);
    773       1.1    jruoho     }
    774       1.1    jruoho 
    775       1.4  christos     /* Emit compile times if enabled */
    776       1.4  christos 
    777       1.4  christos     CmDumpAllEvents ();
    778       1.1    jruoho 
    779  1.14.2.1  christos     if (AslGbl_CompileTimesFlag)
    780       1.1    jruoho     {
    781       1.1    jruoho         printf ("\nMiscellaneous compile statistics\n\n");
    782  1.14.2.1  christos         printf ("%11u : %s\n", AslGbl_TotalParseNodes, "Parse nodes");
    783  1.14.2.1  christos         printf ("%11u : %s\n", AslGbl_NsLookupCount, "Namespace searches");
    784  1.14.2.1  christos         printf ("%11u : %s\n", AslGbl_TotalNamedObjects, "Named objects");
    785  1.14.2.1  christos         printf ("%11u : %s\n", AslGbl_TotalMethods, "Control methods");
    786  1.14.2.1  christos         printf ("%11u : %s\n", AslGbl_TotalAllocations, "Memory Allocations");
    787  1.14.2.1  christos         printf ("%11u : %s\n", AslGbl_TotalAllocated, "Total allocated memory");
    788  1.14.2.1  christos         printf ("%11u : %s\n", AslGbl_TotalFolds, "Constant subtrees folded");
    789       1.1    jruoho         printf ("\n");
    790       1.1    jruoho     }
    791       1.1    jruoho 
    792  1.14.2.1  christos     if (AslGbl_NsLookupCount)
    793       1.1    jruoho     {
    794       1.1    jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
    795       1.1    jruoho             "\n\nMiscellaneous compile statistics\n\n");
    796       1.1    jruoho 
    797       1.1    jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
    798       1.1    jruoho             "%32s : %u\n", "Total Namespace searches",
    799  1.14.2.1  christos             AslGbl_NsLookupCount);
    800       1.1    jruoho 
    801       1.1    jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
    802       1.1    jruoho             "%32s : %u usec\n", "Time per search", ((UINT32)
    803       1.1    jruoho             (AslGbl_Events[AslGbl_NamespaceEvent].EndTime -
    804       1.1    jruoho                 AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) /
    805  1.14.2.1  christos                 AslGbl_NsLookupCount);
    806       1.1    jruoho     }
    807       1.1    jruoho 
    808  1.14.2.1  christos     if (AslGbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
    809       1.1    jruoho     {
    810  1.14.2.1  christos         printf ("\nMaximum error count (%d) exceeded\n",
    811       1.1    jruoho             ASL_MAX_ERROR_COUNT);
    812       1.1    jruoho     }
    813       1.1    jruoho 
    814       1.1    jruoho     UtDisplaySummary (ASL_FILE_STDOUT);
    815       1.1    jruoho 
    816       1.4  christos     /*
    817       1.4  christos      * We will delete the AML file if there are errors and the
    818       1.4  christos      * force AML output option has not been used.
    819       1.4  christos      */
    820  1.14.2.1  christos     if (AslGbl_ParserErrorDetected || ((AslGbl_ExceptionCount[ASL_ERROR] > 0) &&
    821  1.14.2.1  christos         (!AslGbl_IgnoreErrors) &&
    822  1.14.2.1  christos         AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle))
    823       1.4  christos     {
    824       1.4  christos         DeleteAmlFile = TRUE;
    825       1.4  christos     }
    826       1.4  christos 
    827       1.1    jruoho     /* Close all open files */
    828       1.1    jruoho 
    829  1.14.2.1  christos     while (CurrentFileNode)
    830  1.14.2.1  christos     {
    831  1.14.2.1  christos         switch  (FlSwitchFileSet (CurrentFileNode->Files[ASL_FILE_INPUT].Filename))
    832  1.14.2.1  christos         {
    833  1.14.2.1  christos             case SWITCH_TO_SAME_FILE:
    834  1.14.2.1  christos             case SWITCH_TO_DIFFERENT_FILE:
    835  1.14.2.1  christos 
    836  1.14.2.1  christos                 CmFinishFiles (DeleteAmlFile);
    837  1.14.2.1  christos                 CurrentFileNode = CurrentFileNode->Next;
    838  1.14.2.1  christos                 break;
    839  1.14.2.1  christos 
    840  1.14.2.1  christos             case FILE_NOT_FOUND:
    841  1.14.2.1  christos             default:
    842  1.14.2.1  christos 
    843  1.14.2.1  christos                 CurrentFileNode = NULL;
    844  1.14.2.1  christos                 break;
    845  1.14.2.1  christos         }
    846  1.14.2.1  christos     }
    847  1.14.2.1  christos 
    848  1.14.2.1  christos     /* Final cleanup after compiling one file */
    849  1.14.2.1  christos 
    850  1.14.2.1  christos     if (!AslGbl_DoAslConversion)
    851  1.14.2.1  christos     {
    852  1.14.2.1  christos         UtDeleteLocalCaches ();
    853  1.14.2.1  christos     }
    854  1.14.2.1  christos }
    855  1.14.2.1  christos 
    856  1.14.2.1  christos 
    857  1.14.2.1  christos /*******************************************************************************
    858  1.14.2.1  christos  *
    859  1.14.2.1  christos  * FUNCTION:    CmFinishFiles
    860  1.14.2.1  christos  *
    861  1.14.2.1  christos  * PARAMETERS:  DeleteAmlFile
    862  1.14.2.1  christos  *
    863  1.14.2.1  christos  * RETURN:      None.
    864  1.14.2.1  christos  *
    865  1.14.2.1  christos  * DESCRIPTION: Close all open files, delete AML files depending on the
    866  1.14.2.1  christos  *              function parameter is true.
    867  1.14.2.1  christos  *
    868  1.14.2.1  christos  ******************************************************************************/
    869  1.14.2.1  christos 
    870  1.14.2.1  christos static void
    871  1.14.2.1  christos CmFinishFiles(
    872  1.14.2.1  christos     BOOLEAN                 DeleteAmlFile)
    873  1.14.2.1  christos {
    874  1.14.2.1  christos     UINT32                  i;
    875  1.14.2.1  christos 
    876  1.14.2.1  christos 
    877       1.4  christos     /*
    878       1.7  christos      * Take care with the preprocessor file (.pre), it might be the same
    879       1.4  christos      * as the "input" file, depending on where the compiler has terminated
    880       1.4  christos      * or aborted. Prevent attempt to close the same file twice in
    881       1.4  christos      * loop below.
    882       1.4  christos      */
    883  1.14.2.1  christos     if (AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle ==
    884  1.14.2.1  christos         AslGbl_Files[ASL_FILE_INPUT].Handle)
    885       1.4  christos     {
    886  1.14.2.1  christos         AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL;
    887       1.4  christos     }
    888       1.4  christos 
    889       1.4  christos     /* Close the standard I/O files */
    890       1.4  christos 
    891       1.4  christos     for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
    892       1.1    jruoho     {
    893  1.14.2.1  christos         /*
    894  1.14.2.1  christos          * Some files such as debug output files could be pointing to
    895  1.14.2.1  christos          * stderr or stdout. Leave these alone.
    896  1.14.2.1  christos          */
    897  1.14.2.1  christos         if (AslGbl_Files[i].Handle != stderr &&
    898  1.14.2.1  christos             AslGbl_Files[i].Handle != stdout)
    899  1.14.2.1  christos         {
    900  1.14.2.1  christos             FlCloseFile (i);
    901  1.14.2.1  christos         }
    902       1.1    jruoho     }
    903       1.1    jruoho 
    904       1.1    jruoho     /* Delete AML file if there are errors */
    905       1.1    jruoho 
    906       1.4  christos     if (DeleteAmlFile)
    907       1.4  christos     {
    908       1.4  christos         FlDeleteFile (ASL_FILE_AML_OUTPUT);
    909       1.4  christos     }
    910       1.4  christos 
    911       1.7  christos     /* Delete the preprocessor temp file unless full debug was specified */
    912       1.4  christos 
    913  1.14.2.1  christos     if (AslGbl_PreprocessFlag && !AslGbl_KeepPreprocessorTempFile)
    914       1.1    jruoho     {
    915       1.4  christos         FlDeleteFile (ASL_FILE_PREPROCESSOR);
    916       1.1    jruoho     }
    917       1.1    jruoho 
    918       1.1    jruoho     /*
    919       1.1    jruoho      * Delete intermediate ("combined") source file (if -ls flag not set)
    920       1.3    jruoho      * This file is created during normal ASL/AML compiles. It is not
    921       1.3    jruoho      * created by the data table compiler.
    922       1.3    jruoho      *
    923       1.3    jruoho      * If the -ls flag is set, then the .SRC file should not be deleted.
    924       1.3    jruoho      * In this case, Gbl_SourceOutputFlag is set to TRUE.
    925       1.3    jruoho      *
    926       1.3    jruoho      * Note: Handles are cleared by FlCloseFile above, so we look at the
    927       1.3    jruoho      * filename instead, to determine if the .SRC file was actually
    928       1.3    jruoho      * created.
    929       1.1    jruoho      */
    930  1.14.2.1  christos     if (!AslGbl_SourceOutputFlag)
    931       1.1    jruoho     {
    932       1.4  christos         FlDeleteFile (ASL_FILE_SOURCE_OUTPUT);
    933       1.1    jruoho     }
    934       1.5  christos }
    935