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