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