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