Home | History | Annotate | Line # | Download | only in compiler
aslcompile.c revision 1.15
      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  christos  * Copyright (C) 2000 - 2018, 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.1    jruoho 
     74   1.1    jruoho /*******************************************************************************
     75   1.1    jruoho  *
     76   1.1    jruoho  * FUNCTION:    CmDoCompile
     77   1.1    jruoho  *
     78   1.1    jruoho  * PARAMETERS:  None
     79   1.1    jruoho  *
     80   1.1    jruoho  * RETURN:      Status (0 = OK)
     81   1.1    jruoho  *
     82   1.1    jruoho  * DESCRIPTION: This procedure performs the entire compile
     83   1.1    jruoho  *
     84   1.1    jruoho  ******************************************************************************/
     85   1.1    jruoho 
     86   1.1    jruoho int
     87   1.1    jruoho CmDoCompile (
     88   1.1    jruoho     void)
     89   1.1    jruoho {
     90   1.1    jruoho     ACPI_STATUS             Status;
     91   1.1    jruoho     UINT8                   FullCompile;
     92   1.1    jruoho     UINT8                   Event;
     93   1.1    jruoho 
     94   1.1    jruoho 
     95   1.1    jruoho     FullCompile = UtBeginEvent ("*** Total Compile time ***");
     96   1.1    jruoho     Event = UtBeginEvent ("Open input and output files");
     97   1.1    jruoho     UtEndEvent (Event);
     98   1.1    jruoho 
     99   1.4  christos     Event = UtBeginEvent ("Preprocess input file");
    100  1.15  christos     if (AslGbl_PreprocessFlag)
    101   1.4  christos     {
    102   1.7  christos         /* Enter compiler name as a #define */
    103   1.7  christos 
    104   1.7  christos         PrAddDefine (ASL_DEFINE, "", FALSE);
    105   1.7  christos 
    106   1.4  christos         /* Preprocessor */
    107   1.4  christos 
    108   1.4  christos         PrDoPreprocess ();
    109  1.15  christos         AslGbl_CurrentLineNumber = 1;
    110  1.15  christos         AslGbl_LogicalLineNumber = 1;
    111   1.7  christos 
    112  1.15  christos         if (AslGbl_PreprocessOnly)
    113   1.4  christos         {
    114   1.4  christos             UtEndEvent (Event);
    115   1.4  christos             CmCleanupAndExit ();
    116   1.4  christos             return (0);
    117   1.4  christos         }
    118   1.4  christos     }
    119   1.4  christos     UtEndEvent (Event);
    120   1.4  christos 
    121   1.7  christos 
    122   1.1    jruoho     /* Build the parse tree */
    123   1.1    jruoho 
    124   1.1    jruoho     Event = UtBeginEvent ("Parse source code and build parse tree");
    125   1.1    jruoho     AslCompilerparse();
    126   1.1    jruoho     UtEndEvent (Event);
    127   1.1    jruoho 
    128   1.6  christos     /* Check for parser-detected syntax errors */
    129   1.1    jruoho 
    130  1.15  christos     if (AslGbl_SyntaxError)
    131   1.4  christos     {
    132   1.8  christos         fprintf (stderr,
    133   1.8  christos             "Compiler aborting due to parser-detected syntax error(s)\n");
    134   1.4  christos         LsDumpParseTree ();
    135   1.4  christos         goto ErrorExit;
    136   1.4  christos     }
    137   1.1    jruoho 
    138   1.1    jruoho     /* Did the parse tree get successfully constructed? */
    139   1.1    jruoho 
    140  1.15  christos     if (!AslGbl_ParseTreeRoot)
    141   1.1    jruoho     {
    142   1.4  christos         /*
    143   1.4  christos          * If there are no errors, then we have some sort of
    144   1.4  christos          * internal problem.
    145   1.4  christos          */
    146   1.4  christos         AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
    147   1.4  christos             NULL, "- Could not resolve parse tree root node");
    148   1.4  christos 
    149   1.4  christos         goto ErrorExit;
    150   1.1    jruoho     }
    151   1.1    jruoho 
    152   1.4  christos     /* Flush out any remaining source after parse tree is complete */
    153   1.4  christos 
    154   1.4  christos     Event = UtBeginEvent ("Flush source input");
    155   1.4  christos     CmFlushSourceCode ();
    156   1.4  christos 
    157   1.6  christos     /* Prune the parse tree if requested (debug purposes only) */
    158   1.6  christos 
    159  1.15  christos     if (AslGbl_PruneParseTree)
    160   1.6  christos     {
    161  1.15  christos         AslPruneParseTree (AslGbl_PruneDepth, AslGbl_PruneType);
    162   1.6  christos     }
    163   1.6  christos 
    164   1.1    jruoho     /* Optional parse tree dump, compiler debug output only */
    165   1.1    jruoho 
    166   1.1    jruoho     LsDumpParseTree ();
    167   1.1    jruoho 
    168  1.15  christos     OpcGetIntegerWidth (AslGbl_ParseTreeRoot->Asl.Child);
    169   1.1    jruoho     UtEndEvent (Event);
    170   1.1    jruoho 
    171   1.1    jruoho     /* Pre-process parse tree for any operator transforms */
    172   1.1    jruoho 
    173   1.1    jruoho     Event = UtBeginEvent ("Parse tree transforms");
    174   1.1    jruoho     DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n");
    175  1.15  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
    176   1.9  christos         TrAmlTransformWalkBegin, TrAmlTransformWalkEnd, NULL);
    177   1.1    jruoho     UtEndEvent (Event);
    178   1.1    jruoho 
    179   1.1    jruoho     /* Generate AML opcodes corresponding to the parse tokens */
    180   1.1    jruoho 
    181   1.1    jruoho     Event = UtBeginEvent ("Generate AML opcodes");
    182   1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Generating AML opcodes\n\n");
    183  1.15  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
    184   1.1    jruoho         OpcAmlOpcodeWalk, NULL);
    185   1.1    jruoho     UtEndEvent (Event);
    186   1.1    jruoho 
    187   1.1    jruoho     /*
    188   1.1    jruoho      * Now that the input is parsed, we can open the AML output file.
    189   1.8  christos      * Note: by default, the name of this file comes from the table
    190   1.8  christos      * descriptor within the input file.
    191   1.1    jruoho      */
    192   1.1    jruoho     Event = UtBeginEvent ("Open AML output file");
    193  1.15  christos     Status = FlOpenAmlOutputFile (AslGbl_OutputFilenamePrefix);
    194   1.4  christos     UtEndEvent (Event);
    195   1.1    jruoho     if (ACPI_FAILURE (Status))
    196   1.1    jruoho     {
    197   1.1    jruoho         AePrintErrorLog (ASL_FILE_STDERR);
    198   1.4  christos         return (-1);
    199   1.1    jruoho     }
    200   1.1    jruoho 
    201   1.1    jruoho     /* Interpret and generate all compile-time constants */
    202   1.1    jruoho 
    203   1.1    jruoho     Event = UtBeginEvent ("Constant folding via AML interpreter");
    204   1.1    jruoho     DbgPrint (ASL_DEBUG_OUTPUT,
    205   1.9  christos         "Interpreting compile-time constant expressions\n\n");
    206   1.6  christos 
    207  1.15  christos     if (AslGbl_FoldConstants)
    208   1.6  christos     {
    209  1.15  christos         TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
    210   1.9  christos             NULL, OpcAmlConstantWalk, NULL);
    211   1.6  christos     }
    212   1.6  christos     else
    213   1.6  christos     {
    214   1.6  christos         DbgPrint (ASL_PARSE_OUTPUT, "    Optional folding disabled\n");
    215   1.6  christos     }
    216   1.1    jruoho     UtEndEvent (Event);
    217   1.1    jruoho 
    218   1.1    jruoho     /* Update AML opcodes if necessary, after constant folding */
    219   1.1    jruoho 
    220   1.1    jruoho     Event = UtBeginEvent ("Updating AML opcodes after constant folding");
    221   1.1    jruoho     DbgPrint (ASL_DEBUG_OUTPUT,
    222   1.9  christos         "Updating AML opcodes after constant folding\n\n");
    223  1.15  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
    224   1.1    jruoho         NULL, OpcAmlOpcodeUpdateWalk, NULL);
    225   1.1    jruoho     UtEndEvent (Event);
    226   1.1    jruoho 
    227   1.1    jruoho     /* Calculate all AML package lengths */
    228   1.1    jruoho 
    229   1.1    jruoho     Event = UtBeginEvent ("Generate AML package lengths");
    230   1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");
    231  1.15  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
    232   1.1    jruoho         LnPackageLengthWalk, NULL);
    233   1.1    jruoho     UtEndEvent (Event);
    234   1.1    jruoho 
    235  1.15  christos     if (AslGbl_ParseOnlyFlag)
    236   1.1    jruoho     {
    237   1.4  christos         AePrintErrorLog (ASL_FILE_STDERR);
    238   1.4  christos         UtDisplaySummary (ASL_FILE_STDERR);
    239  1.15  christos         if (AslGbl_DebugFlag)
    240   1.1    jruoho         {
    241   1.4  christos             /* Print error summary to the stdout also */
    242   1.1    jruoho 
    243   1.4  christos             AePrintErrorLog (ASL_FILE_STDOUT);
    244   1.4  christos             UtDisplaySummary (ASL_FILE_STDOUT);
    245   1.1    jruoho         }
    246   1.4  christos         UtEndEvent (FullCompile);
    247   1.4  christos         return (0);
    248   1.1    jruoho     }
    249   1.1    jruoho 
    250   1.1    jruoho     /*
    251   1.1    jruoho      * Create an internal namespace and use it as a symbol table
    252   1.1    jruoho      */
    253   1.1    jruoho 
    254   1.1    jruoho     /* Namespace loading */
    255   1.1    jruoho 
    256   1.1    jruoho     Event = UtBeginEvent ("Create ACPI Namespace");
    257   1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Creating ACPI Namespace\n\n");
    258  1.15  christos     Status = LdLoadNamespace (AslGbl_ParseTreeRoot);
    259   1.1    jruoho     UtEndEvent (Event);
    260   1.1    jruoho     if (ACPI_FAILURE (Status))
    261   1.1    jruoho     {
    262   1.4  christos         goto ErrorExit;
    263   1.1    jruoho     }
    264   1.1    jruoho 
    265   1.1    jruoho     /* Namespace cross-reference */
    266   1.1    jruoho 
    267   1.8  christos     AslGbl_NamespaceEvent = UtBeginEvent (
    268   1.8  christos         "Cross reference parse tree and Namespace");
    269   1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Cross referencing namespace\n\n");
    270   1.4  christos     Status = XfCrossReferenceNamespace ();
    271   1.1    jruoho     if (ACPI_FAILURE (Status))
    272   1.1    jruoho     {
    273   1.4  christos         goto ErrorExit;
    274   1.1    jruoho     }
    275   1.1    jruoho 
    276   1.1    jruoho     /* Namespace - Check for non-referenced objects */
    277   1.1    jruoho 
    278   1.1    jruoho     LkFindUnreferencedObjects ();
    279   1.1    jruoho     UtEndEvent (AslGbl_NamespaceEvent);
    280   1.1    jruoho 
    281   1.9  christos     /* Resolve External Declarations */
    282   1.9  christos 
    283  1.15  christos     Event = UtBeginEvent ("Resolve all Externals");
    284  1.15  christos     DbgPrint (ASL_DEBUG_OUTPUT, "\nResolve Externals\n\n");
    285  1.15  christos 
    286  1.15  christos     if (AslGbl_DoExternalsInPlace)
    287  1.15  christos     {
    288  1.15  christos         TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
    289  1.15  christos             ExAmlExternalWalkBegin, NULL, NULL);
    290  1.15  christos     }
    291  1.15  christos     else
    292   1.9  christos     {
    293  1.15  christos         TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
    294  1.15  christos             ExAmlExternalWalkBegin, ExAmlExternalWalkEnd, NULL);
    295   1.9  christos     }
    296  1.15  christos     UtEndEvent (Event);
    297   1.9  christos 
    298   1.1    jruoho     /*
    299   1.4  christos      * Semantic analysis. This can happen only after the
    300   1.1    jruoho      * namespace has been loaded and cross-referenced.
    301   1.1    jruoho      *
    302   1.1    jruoho      * part one - check control methods
    303   1.1    jruoho      */
    304   1.1    jruoho     Event = UtBeginEvent ("Analyze control method return types");
    305  1.15  christos     AslGbl_AnalysisWalkInfo.MethodStack = NULL;
    306   1.1    jruoho 
    307   1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method analysis\n\n");
    308   1.9  christos 
    309  1.15  christos     if (AslGbl_CrossReferenceOutput)
    310   1.9  christos     {
    311   1.9  christos         OtPrintHeaders ("Part 1: Object Reference Map "
    312   1.9  christos             "(Object references from within each control method)");
    313   1.9  christos     }
    314   1.9  christos 
    315  1.15  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
    316   1.4  christos         MtMethodAnalysisWalkBegin,
    317  1.15  christos         MtMethodAnalysisWalkEnd, &AslGbl_AnalysisWalkInfo);
    318   1.1    jruoho     UtEndEvent (Event);
    319   1.1    jruoho 
    320   1.9  christos     /* Generate the object cross-reference file if requested */
    321   1.9  christos 
    322   1.9  christos     Event = UtBeginEvent ("Generate cross-reference file");
    323   1.9  christos     OtCreateXrefFile ();
    324   1.9  christos     UtEndEvent (Event);
    325   1.9  christos 
    326   1.1    jruoho     /* Semantic error checking part two - typing of method returns */
    327   1.1    jruoho 
    328   1.1    jruoho     Event = UtBeginEvent ("Determine object types returned by methods");
    329   1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method typing\n\n");
    330  1.15  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
    331   1.3    jruoho         NULL, AnMethodTypingWalkEnd, NULL);
    332   1.1    jruoho     UtEndEvent (Event);
    333   1.1    jruoho 
    334   1.1    jruoho     /* Semantic error checking part three - operand type checking */
    335   1.1    jruoho 
    336   1.1    jruoho     Event = UtBeginEvent ("Analyze AML operand types");
    337   1.8  christos     DbgPrint (ASL_DEBUG_OUTPUT,
    338   1.9  christos         "Semantic analysis - Operand type checking\n\n");
    339  1.15  christos     if (AslGbl_DoTypechecking)
    340   1.8  christos     {
    341  1.15  christos         TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
    342  1.15  christos             NULL, AnOperandTypecheckWalkEnd, &AslGbl_AnalysisWalkInfo);
    343   1.8  christos     }
    344   1.1    jruoho     UtEndEvent (Event);
    345   1.1    jruoho 
    346   1.1    jruoho     /* Semantic error checking part four - other miscellaneous checks */
    347   1.1    jruoho 
    348   1.1    jruoho     Event = UtBeginEvent ("Miscellaneous analysis");
    349   1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - miscellaneous\n\n");
    350  1.15  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
    351   1.1    jruoho         AnOtherSemanticAnalysisWalkBegin,
    352  1.15  christos         NULL, &AslGbl_AnalysisWalkInfo);
    353   1.1    jruoho     UtEndEvent (Event);
    354   1.1    jruoho 
    355  1.11  christos     /*
    356  1.11  christos      * ASL-/ASL+ converter: Gbl_ParseTreeRoot->CommentList contains the
    357  1.11  christos      * very last comment of a given ASL file because it's the last constructed
    358  1.11  christos      * node during compilation. We take the very last comment and save it in a
    359  1.11  christos      * global for it to be used by the disassembler.
    360  1.11  christos      */
    361  1.14  christos     if (AcpiGbl_CaptureComments)
    362  1.11  christos     {
    363  1.15  christos         AcpiGbl_LastListHead = AslGbl_ParseTreeRoot->Asl.CommentList;
    364  1.15  christos         AslGbl_ParseTreeRoot->Asl.CommentList = NULL;
    365  1.11  christos     }
    366  1.11  christos 
    367   1.1    jruoho     /* Calculate all AML package lengths */
    368   1.1    jruoho 
    369   1.1    jruoho     Event = UtBeginEvent ("Finish AML package length generation");
    370   1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");
    371  1.15  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
    372   1.1    jruoho         LnInitLengthsWalk, NULL);
    373  1.15  christos     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
    374   1.1    jruoho         LnPackageLengthWalk, NULL);
    375   1.1    jruoho     UtEndEvent (Event);
    376   1.1    jruoho 
    377   1.1    jruoho     /* Code generation - emit the AML */
    378   1.1    jruoho 
    379   1.1    jruoho     Event = UtBeginEvent ("Generate AML code and write output files");
    380   1.9  christos     DbgPrint (ASL_DEBUG_OUTPUT, "Writing AML byte code\n\n");
    381   1.1    jruoho     CgGenerateAmlOutput ();
    382   1.1    jruoho     UtEndEvent (Event);
    383   1.1    jruoho 
    384   1.1    jruoho     Event = UtBeginEvent ("Write optional output files");
    385   1.1    jruoho     CmDoOutputFiles ();
    386   1.1    jruoho     UtEndEvent (Event);
    387   1.1    jruoho 
    388   1.1    jruoho     UtEndEvent (FullCompile);
    389   1.1    jruoho     CmCleanupAndExit ();
    390   1.4  christos     return (0);
    391   1.4  christos 
    392   1.4  christos ErrorExit:
    393   1.4  christos     UtEndEvent (FullCompile);
    394   1.4  christos     CmCleanupAndExit ();
    395   1.4  christos     return (-1);
    396   1.1    jruoho }
    397   1.1    jruoho 
    398   1.1    jruoho 
    399   1.1    jruoho /*******************************************************************************
    400   1.1    jruoho  *
    401   1.5  christos  * FUNCTION:    AslCompilerSignon
    402   1.5  christos  *
    403   1.5  christos  * PARAMETERS:  FileId      - ID of the output file
    404   1.5  christos  *
    405   1.5  christos  * RETURN:      None
    406   1.5  christos  *
    407   1.5  christos  * DESCRIPTION: Display compiler signon
    408   1.5  christos  *
    409   1.5  christos  ******************************************************************************/
    410   1.5  christos 
    411   1.5  christos void
    412   1.5  christos AslCompilerSignon (
    413   1.5  christos     UINT32                  FileId)
    414   1.5  christos {
    415   1.5  christos     char                    *Prefix = "";
    416   1.5  christos     char                    *UtilityName;
    417   1.5  christos 
    418   1.5  christos 
    419   1.5  christos     /* Set line prefix depending on the destination file type */
    420   1.5  christos 
    421   1.5  christos     switch (FileId)
    422   1.5  christos     {
    423   1.5  christos     case ASL_FILE_ASM_SOURCE_OUTPUT:
    424   1.5  christos     case ASL_FILE_ASM_INCLUDE_OUTPUT:
    425   1.5  christos 
    426   1.5  christos         Prefix = "; ";
    427   1.5  christos         break;
    428   1.5  christos 
    429   1.5  christos     case ASL_FILE_HEX_OUTPUT:
    430   1.5  christos 
    431  1.15  christos         if (AslGbl_HexOutputFlag == HEX_OUTPUT_ASM)
    432   1.5  christos         {
    433   1.5  christos             Prefix = "; ";
    434   1.5  christos         }
    435  1.15  christos         else if ((AslGbl_HexOutputFlag == HEX_OUTPUT_C) ||
    436  1.15  christos                  (AslGbl_HexOutputFlag == HEX_OUTPUT_ASL))
    437   1.5  christos         {
    438   1.5  christos             FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
    439   1.5  christos             Prefix = " * ";
    440   1.5  christos         }
    441   1.5  christos         break;
    442   1.5  christos 
    443   1.5  christos     case ASL_FILE_C_SOURCE_OUTPUT:
    444   1.5  christos     case ASL_FILE_C_OFFSET_OUTPUT:
    445   1.5  christos     case ASL_FILE_C_INCLUDE_OUTPUT:
    446   1.5  christos 
    447   1.5  christos         Prefix = " * ";
    448   1.5  christos         break;
    449   1.5  christos 
    450   1.5  christos     default:
    451   1.5  christos 
    452   1.5  christos         /* No other output types supported */
    453   1.5  christos 
    454   1.5  christos         break;
    455   1.5  christos     }
    456   1.5  christos 
    457   1.5  christos     /* Running compiler or disassembler? */
    458   1.5  christos 
    459  1.12  christos     if (AcpiGbl_DisasmFlag)
    460   1.5  christos     {
    461   1.5  christos         UtilityName = AML_DISASSEMBLER_NAME;
    462   1.5  christos     }
    463   1.5  christos     else
    464   1.5  christos     {
    465   1.5  christos         UtilityName = ASL_COMPILER_NAME;
    466   1.5  christos     }
    467   1.5  christos 
    468   1.5  christos     /* Compiler signon with copyright */
    469   1.5  christos 
    470   1.5  christos     FlPrintFile (FileId, "%s\n", Prefix);
    471   1.5  christos     FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix));
    472   1.5  christos }
    473   1.5  christos 
    474   1.5  christos 
    475   1.5  christos /*******************************************************************************
    476   1.5  christos  *
    477   1.5  christos  * FUNCTION:    AslCompilerFileHeader
    478   1.5  christos  *
    479   1.5  christos  * PARAMETERS:  FileId      - ID of the output file
    480   1.5  christos  *
    481   1.5  christos  * RETURN:      None
    482   1.5  christos  *
    483   1.5  christos  * DESCRIPTION: Header used at the beginning of output files
    484   1.5  christos  *
    485   1.5  christos  ******************************************************************************/
    486   1.5  christos 
    487   1.5  christos void
    488   1.5  christos AslCompilerFileHeader (
    489   1.5  christos     UINT32                  FileId)
    490   1.5  christos {
    491   1.5  christos     struct tm               *NewTime;
    492   1.5  christos     time_t                  Aclock;
    493   1.5  christos     char                    *Prefix = "";
    494   1.5  christos 
    495   1.5  christos 
    496   1.5  christos     /* Set line prefix depending on the destination file type */
    497   1.5  christos 
    498   1.5  christos     switch (FileId)
    499   1.5  christos     {
    500   1.5  christos     case ASL_FILE_ASM_SOURCE_OUTPUT:
    501   1.5  christos     case ASL_FILE_ASM_INCLUDE_OUTPUT:
    502   1.5  christos 
    503   1.5  christos         Prefix = "; ";
    504   1.5  christos         break;
    505   1.5  christos 
    506   1.5  christos     case ASL_FILE_HEX_OUTPUT:
    507   1.5  christos 
    508  1.15  christos         if (AslGbl_HexOutputFlag == HEX_OUTPUT_ASM)
    509   1.5  christos         {
    510   1.5  christos             Prefix = "; ";
    511   1.5  christos         }
    512  1.15  christos         else if ((AslGbl_HexOutputFlag == HEX_OUTPUT_C) ||
    513  1.15  christos                  (AslGbl_HexOutputFlag == HEX_OUTPUT_ASL))
    514   1.5  christos         {
    515   1.5  christos             Prefix = " * ";
    516   1.5  christos         }
    517   1.5  christos         break;
    518   1.5  christos 
    519   1.5  christos     case ASL_FILE_C_SOURCE_OUTPUT:
    520   1.5  christos     case ASL_FILE_C_OFFSET_OUTPUT:
    521   1.5  christos     case ASL_FILE_C_INCLUDE_OUTPUT:
    522   1.5  christos 
    523   1.5  christos         Prefix = " * ";
    524   1.5  christos         break;
    525   1.5  christos 
    526   1.5  christos     default:
    527   1.5  christos 
    528   1.5  christos         /* No other output types supported */
    529   1.5  christos 
    530   1.5  christos         break;
    531   1.5  christos     }
    532   1.5  christos 
    533   1.5  christos     /* Compilation header with timestamp */
    534   1.5  christos 
    535   1.5  christos     (void) time (&Aclock);
    536   1.5  christos     NewTime = localtime (&Aclock);
    537   1.5  christos 
    538   1.5  christos     FlPrintFile (FileId,
    539   1.5  christos         "%sCompilation of \"%s\" - %s%s\n",
    540  1.15  christos         Prefix, AslGbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime),
    541   1.5  christos         Prefix);
    542   1.5  christos 
    543   1.5  christos     switch (FileId)
    544   1.5  christos     {
    545   1.5  christos     case ASL_FILE_C_SOURCE_OUTPUT:
    546   1.5  christos     case ASL_FILE_C_OFFSET_OUTPUT:
    547   1.5  christos     case ASL_FILE_C_INCLUDE_OUTPUT:
    548   1.5  christos 
    549   1.5  christos         FlPrintFile (FileId, " */\n");
    550   1.5  christos         break;
    551   1.5  christos 
    552   1.5  christos     default:
    553   1.5  christos 
    554   1.5  christos         /* Nothing to do for other output types */
    555   1.5  christos 
    556   1.5  christos         break;
    557   1.5  christos     }
    558   1.5  christos }
    559   1.5  christos 
    560   1.5  christos 
    561   1.5  christos /*******************************************************************************
    562   1.5  christos  *
    563   1.5  christos  * FUNCTION:    CmFlushSourceCode
    564   1.5  christos  *
    565   1.5  christos  * PARAMETERS:  None
    566   1.5  christos  *
    567   1.5  christos  * RETURN:      None
    568   1.5  christos  *
    569   1.5  christos  * DESCRIPTION: Read in any remaining source code after the parse tree
    570   1.5  christos  *              has been constructed.
    571   1.5  christos  *
    572   1.5  christos  ******************************************************************************/
    573   1.5  christos 
    574   1.5  christos static void
    575   1.5  christos CmFlushSourceCode (
    576   1.5  christos     void)
    577   1.5  christos {
    578   1.5  christos     char                    Buffer;
    579   1.5  christos 
    580   1.5  christos 
    581   1.5  christos     while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)
    582   1.5  christos     {
    583   1.5  christos         AslInsertLineBuffer ((int) Buffer);
    584   1.5  christos     }
    585   1.5  christos 
    586   1.5  christos     AslResetCurrentLineBuffer ();
    587   1.5  christos }
    588   1.5  christos 
    589   1.5  christos 
    590   1.5  christos /*******************************************************************************
    591   1.5  christos  *
    592   1.1    jruoho  * FUNCTION:    CmDoOutputFiles
    593   1.1    jruoho  *
    594   1.1    jruoho  * PARAMETERS:  None
    595   1.1    jruoho  *
    596   1.1    jruoho  * RETURN:      None.
    597   1.1    jruoho  *
    598   1.1    jruoho  * DESCRIPTION: Create all "listing" type files
    599   1.1    jruoho  *
    600   1.1    jruoho  ******************************************************************************/
    601   1.1    jruoho 
    602   1.1    jruoho void
    603   1.1    jruoho CmDoOutputFiles (
    604   1.1    jruoho     void)
    605   1.1    jruoho {
    606   1.1    jruoho 
    607   1.1    jruoho     /* Create listings and hex files */
    608   1.1    jruoho 
    609   1.1    jruoho     LsDoListings ();
    610   1.4  christos     HxDoHexOutput ();
    611   1.1    jruoho 
    612   1.1    jruoho     /* Dump the namespace to the .nsp file if requested */
    613   1.1    jruoho 
    614   1.4  christos     (void) NsDisplayNamespace ();
    615   1.5  christos 
    616   1.5  christos     /* Dump the device mapping file */
    617   1.5  christos 
    618   1.5  christos     MpEmitMappingInfo ();
    619   1.1    jruoho }
    620   1.1    jruoho 
    621   1.1    jruoho 
    622   1.1    jruoho /*******************************************************************************
    623   1.1    jruoho  *
    624   1.4  christos  * FUNCTION:    CmDumpAllEvents
    625   1.1    jruoho  *
    626   1.4  christos  * PARAMETERS:  None
    627   1.1    jruoho  *
    628   1.1    jruoho  * RETURN:      None.
    629   1.1    jruoho  *
    630   1.4  christos  * DESCRIPTION: Dump all compiler events
    631   1.1    jruoho  *
    632   1.1    jruoho  ******************************************************************************/
    633   1.1    jruoho 
    634   1.1    jruoho static void
    635   1.4  christos CmDumpAllEvents (
    636   1.4  christos     void)
    637   1.1    jruoho {
    638   1.4  christos     ASL_EVENT_INFO          *Event;
    639   1.1    jruoho     UINT32                  Delta;
    640   1.8  christos     UINT32                  MicroSeconds;
    641   1.8  christos     UINT32                  MilliSeconds;
    642   1.4  christos     UINT32                  i;
    643   1.4  christos 
    644   1.1    jruoho 
    645   1.4  christos     Event = AslGbl_Events;
    646   1.4  christos 
    647   1.4  christos     DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");
    648  1.15  christos     if (AslGbl_CompileTimesFlag)
    649   1.1    jruoho     {
    650   1.4  christos         printf ("\nElapsed time for major events\n\n");
    651   1.1    jruoho     }
    652   1.1    jruoho 
    653   1.4  christos     for (i = 0; i < AslGbl_NextEvent; i++)
    654   1.4  christos     {
    655   1.4  christos         if (Event->Valid)
    656   1.4  christos         {
    657   1.4  christos             /* Delta will be in 100-nanosecond units */
    658   1.1    jruoho 
    659   1.4  christos             Delta = (UINT32) (Event->EndTime - Event->StartTime);
    660   1.1    jruoho 
    661   1.8  christos             MicroSeconds = Delta / ACPI_100NSEC_PER_USEC;
    662   1.8  christos             MilliSeconds = Delta / ACPI_100NSEC_PER_MSEC;
    663   1.1    jruoho 
    664   1.4  christos             /* Round milliseconds up */
    665   1.1    jruoho 
    666   1.8  christos             if ((MicroSeconds - (MilliSeconds * ACPI_USEC_PER_MSEC)) >= 500)
    667   1.4  christos             {
    668   1.8  christos                 MilliSeconds++;
    669   1.4  christos             }
    670   1.4  christos 
    671   1.4  christos             DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",
    672   1.8  christos                 MicroSeconds, MilliSeconds, Event->EventName);
    673   1.4  christos 
    674  1.15  christos             if (AslGbl_CompileTimesFlag)
    675   1.4  christos             {
    676   1.4  christos                 printf ("%8u usec %8u msec - %s\n",
    677   1.8  christos                     MicroSeconds, MilliSeconds, Event->EventName);
    678   1.4  christos             }
    679   1.4  christos         }
    680   1.4  christos 
    681   1.4  christos         Event++;
    682   1.1    jruoho     }
    683   1.1    jruoho }
    684   1.1    jruoho 
    685   1.1    jruoho 
    686   1.1    jruoho /*******************************************************************************
    687   1.1    jruoho  *
    688   1.1    jruoho  * FUNCTION:    CmCleanupAndExit
    689   1.1    jruoho  *
    690   1.1    jruoho  * PARAMETERS:  None
    691   1.1    jruoho  *
    692   1.1    jruoho  * RETURN:      None.
    693   1.1    jruoho  *
    694   1.1    jruoho  * DESCRIPTION: Close all open files and exit the compiler
    695   1.1    jruoho  *
    696   1.1    jruoho  ******************************************************************************/
    697   1.1    jruoho 
    698   1.1    jruoho void
    699   1.1    jruoho CmCleanupAndExit (
    700   1.1    jruoho     void)
    701   1.1    jruoho {
    702   1.1    jruoho     UINT32                  i;
    703   1.4  christos     BOOLEAN                 DeleteAmlFile = FALSE;
    704   1.1    jruoho 
    705   1.1    jruoho 
    706  1.12  christos     AslCheckExpectedExceptions ();
    707   1.4  christos     AePrintErrorLog (ASL_FILE_STDERR);
    708  1.15  christos     if (AslGbl_DebugFlag)
    709   1.1    jruoho     {
    710   1.4  christos         /* Print error summary to stdout also */
    711   1.1    jruoho 
    712   1.4  christos         AePrintErrorLog (ASL_FILE_STDOUT);
    713   1.1    jruoho     }
    714   1.1    jruoho 
    715   1.4  christos     /* Emit compile times if enabled */
    716   1.4  christos 
    717   1.4  christos     CmDumpAllEvents ();
    718   1.1    jruoho 
    719  1.15  christos     if (AslGbl_CompileTimesFlag)
    720   1.1    jruoho     {
    721   1.1    jruoho         printf ("\nMiscellaneous compile statistics\n\n");
    722  1.15  christos         printf ("%11u : %s\n", AslGbl_TotalParseNodes, "Parse nodes");
    723  1.15  christos         printf ("%11u : %s\n", AslGbl_NsLookupCount, "Namespace searches");
    724  1.15  christos         printf ("%11u : %s\n", AslGbl_TotalNamedObjects, "Named objects");
    725  1.15  christos         printf ("%11u : %s\n", AslGbl_TotalMethods, "Control methods");
    726  1.15  christos         printf ("%11u : %s\n", AslGbl_TotalAllocations, "Memory Allocations");
    727  1.15  christos         printf ("%11u : %s\n", AslGbl_TotalAllocated, "Total allocated memory");
    728  1.15  christos         printf ("%11u : %s\n", AslGbl_TotalFolds, "Constant subtrees folded");
    729   1.1    jruoho         printf ("\n");
    730   1.1    jruoho     }
    731   1.1    jruoho 
    732  1.15  christos     if (AslGbl_NsLookupCount)
    733   1.1    jruoho     {
    734   1.1    jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
    735   1.1    jruoho             "\n\nMiscellaneous compile statistics\n\n");
    736   1.1    jruoho 
    737   1.1    jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
    738   1.1    jruoho             "%32s : %u\n", "Total Namespace searches",
    739  1.15  christos             AslGbl_NsLookupCount);
    740   1.1    jruoho 
    741   1.1    jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
    742   1.1    jruoho             "%32s : %u usec\n", "Time per search", ((UINT32)
    743   1.1    jruoho             (AslGbl_Events[AslGbl_NamespaceEvent].EndTime -
    744   1.1    jruoho                 AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) /
    745  1.15  christos                 AslGbl_NsLookupCount);
    746   1.1    jruoho     }
    747   1.1    jruoho 
    748  1.15  christos     if (AslGbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
    749   1.1    jruoho     {
    750  1.15  christos         printf ("\nMaximum error count (%d) exceeded\n",
    751   1.1    jruoho             ASL_MAX_ERROR_COUNT);
    752   1.1    jruoho     }
    753   1.1    jruoho 
    754   1.1    jruoho     UtDisplaySummary (ASL_FILE_STDOUT);
    755   1.1    jruoho 
    756   1.4  christos     /*
    757   1.4  christos      * We will delete the AML file if there are errors and the
    758   1.4  christos      * force AML output option has not been used.
    759   1.4  christos      */
    760  1.15  christos     if ((AslGbl_ExceptionCount[ASL_ERROR] > 0) &&
    761  1.15  christos         (!AslGbl_IgnoreErrors) &&
    762  1.15  christos         AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle)
    763   1.4  christos     {
    764   1.4  christos         DeleteAmlFile = TRUE;
    765   1.4  christos     }
    766   1.4  christos 
    767   1.1    jruoho     /* Close all open files */
    768   1.1    jruoho 
    769   1.4  christos     /*
    770   1.7  christos      * Take care with the preprocessor file (.pre), it might be the same
    771   1.4  christos      * as the "input" file, depending on where the compiler has terminated
    772   1.4  christos      * or aborted. Prevent attempt to close the same file twice in
    773   1.4  christos      * loop below.
    774   1.4  christos      */
    775  1.15  christos     if (AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle ==
    776  1.15  christos         AslGbl_Files[ASL_FILE_INPUT].Handle)
    777   1.4  christos     {
    778  1.15  christos         AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL;
    779   1.4  christos     }
    780   1.4  christos 
    781   1.4  christos     /* Close the standard I/O files */
    782   1.4  christos 
    783   1.4  christos     for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
    784   1.1    jruoho     {
    785   1.1    jruoho         FlCloseFile (i);
    786   1.1    jruoho     }
    787   1.1    jruoho 
    788   1.1    jruoho     /* Delete AML file if there are errors */
    789   1.1    jruoho 
    790   1.4  christos     if (DeleteAmlFile)
    791   1.4  christos     {
    792   1.4  christos         FlDeleteFile (ASL_FILE_AML_OUTPUT);
    793   1.4  christos     }
    794   1.4  christos 
    795   1.7  christos     /* Delete the preprocessor temp file unless full debug was specified */
    796   1.4  christos 
    797  1.15  christos     if (AslGbl_PreprocessFlag && !AslGbl_KeepPreprocessorTempFile)
    798   1.1    jruoho     {
    799   1.4  christos         FlDeleteFile (ASL_FILE_PREPROCESSOR);
    800   1.1    jruoho     }
    801   1.1    jruoho 
    802   1.1    jruoho     /*
    803   1.1    jruoho      * Delete intermediate ("combined") source file (if -ls flag not set)
    804   1.3    jruoho      * This file is created during normal ASL/AML compiles. It is not
    805   1.3    jruoho      * created by the data table compiler.
    806   1.3    jruoho      *
    807   1.3    jruoho      * If the -ls flag is set, then the .SRC file should not be deleted.
    808   1.3    jruoho      * In this case, Gbl_SourceOutputFlag is set to TRUE.
    809   1.3    jruoho      *
    810   1.3    jruoho      * Note: Handles are cleared by FlCloseFile above, so we look at the
    811   1.3    jruoho      * filename instead, to determine if the .SRC file was actually
    812   1.3    jruoho      * created.
    813   1.1    jruoho      */
    814  1.15  christos     if (!AslGbl_SourceOutputFlag)
    815   1.1    jruoho     {
    816   1.4  christos         FlDeleteFile (ASL_FILE_SOURCE_OUTPUT);
    817   1.1    jruoho     }
    818   1.5  christos 
    819   1.5  christos     /* Final cleanup after compiling one file */
    820   1.5  christos 
    821  1.15  christos     if (!AslGbl_DoAslConversion)
    822  1.11  christos     {
    823  1.13  christos         UtDeleteLocalCaches ();
    824  1.11  christos     }
    825   1.5  christos }
    826