Home | History | Annotate | Line # | Download | only in compiler
aslcompile.c revision 1.3.10.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.3.10.1    yamt  * Copyright (C) 2000 - 2013, 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.3.10.1    yamt #include "dtcompiler.h"
     46       1.1  jruoho 
     47       1.1  jruoho #include <stdio.h>
     48       1.1  jruoho #include <time.h>
     49       1.3  jruoho #include <acapps.h>
     50       1.1  jruoho 
     51       1.1  jruoho #define _COMPONENT          ACPI_COMPILER
     52       1.1  jruoho         ACPI_MODULE_NAME    ("aslcompile")
     53       1.1  jruoho 
     54  1.3.10.1    yamt /*
     55  1.3.10.1    yamt  * Main parser entry
     56  1.3.10.1    yamt  * External is here in case the parser emits the same external in the
     57  1.3.10.1    yamt  * generated header. (Newer versions of Bison)
     58  1.3.10.1    yamt  */
     59  1.3.10.1    yamt int
     60  1.3.10.1    yamt AslCompilerparse(
     61  1.3.10.1    yamt     void);
     62  1.3.10.1    yamt 
     63       1.1  jruoho /* Local prototypes */
     64       1.1  jruoho 
     65       1.1  jruoho static void
     66       1.1  jruoho CmFlushSourceCode (
     67       1.1  jruoho     void);
     68       1.1  jruoho 
     69       1.3  jruoho static void
     70       1.1  jruoho FlConsumeAnsiComment (
     71  1.3.10.1    yamt     FILE                    *Handle,
     72       1.1  jruoho     ASL_FILE_STATUS         *Status);
     73       1.1  jruoho 
     74       1.3  jruoho static void
     75       1.1  jruoho FlConsumeNewComment (
     76  1.3.10.1    yamt     FILE                    *Handle,
     77       1.1  jruoho     ASL_FILE_STATUS         *Status);
     78       1.1  jruoho 
     79  1.3.10.1    yamt static void
     80  1.3.10.1    yamt CmDumpAllEvents (
     81  1.3.10.1    yamt     void);
     82  1.3.10.1    yamt 
     83       1.1  jruoho 
     84       1.1  jruoho /*******************************************************************************
     85       1.1  jruoho  *
     86       1.1  jruoho  * FUNCTION:    AslCompilerSignon
     87       1.1  jruoho  *
     88       1.1  jruoho  * PARAMETERS:  FileId      - ID of the output file
     89       1.1  jruoho  *
     90       1.1  jruoho  * RETURN:      None
     91       1.1  jruoho  *
     92       1.1  jruoho  * DESCRIPTION: Display compiler signon
     93       1.1  jruoho  *
     94       1.1  jruoho  ******************************************************************************/
     95       1.1  jruoho 
     96       1.1  jruoho void
     97       1.1  jruoho AslCompilerSignon (
     98       1.1  jruoho     UINT32                  FileId)
     99       1.1  jruoho {
    100       1.1  jruoho     char                    *Prefix = "";
    101       1.3  jruoho     char                    *UtilityName;
    102       1.1  jruoho 
    103       1.1  jruoho 
    104       1.1  jruoho     /* Set line prefix depending on the destination file type */
    105       1.1  jruoho 
    106       1.1  jruoho     switch (FileId)
    107       1.1  jruoho     {
    108       1.1  jruoho     case ASL_FILE_ASM_SOURCE_OUTPUT:
    109       1.1  jruoho     case ASL_FILE_ASM_INCLUDE_OUTPUT:
    110       1.1  jruoho 
    111       1.1  jruoho         Prefix = "; ";
    112       1.1  jruoho         break;
    113       1.1  jruoho 
    114       1.1  jruoho     case ASL_FILE_HEX_OUTPUT:
    115       1.1  jruoho 
    116       1.1  jruoho         if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
    117       1.1  jruoho         {
    118       1.1  jruoho             Prefix = "; ";
    119       1.1  jruoho         }
    120       1.1  jruoho         else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
    121       1.1  jruoho                  (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
    122       1.1  jruoho         {
    123       1.1  jruoho             FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
    124       1.1  jruoho             Prefix = " * ";
    125       1.1  jruoho         }
    126       1.1  jruoho         break;
    127       1.1  jruoho 
    128       1.1  jruoho     case ASL_FILE_C_SOURCE_OUTPUT:
    129  1.3.10.1    yamt     case ASL_FILE_C_OFFSET_OUTPUT:
    130       1.1  jruoho     case ASL_FILE_C_INCLUDE_OUTPUT:
    131       1.1  jruoho 
    132       1.1  jruoho         Prefix = " * ";
    133       1.1  jruoho         break;
    134       1.1  jruoho 
    135       1.1  jruoho     default:
    136  1.3.10.1    yamt 
    137       1.1  jruoho         /* No other output types supported */
    138  1.3.10.1    yamt 
    139       1.1  jruoho         break;
    140       1.1  jruoho     }
    141       1.1  jruoho 
    142       1.1  jruoho     /* Running compiler or disassembler? */
    143       1.1  jruoho 
    144       1.1  jruoho     if (Gbl_DisasmFlag)
    145       1.1  jruoho     {
    146       1.3  jruoho         UtilityName = AML_DISASSEMBLER_NAME;
    147       1.1  jruoho     }
    148       1.1  jruoho     else
    149       1.1  jruoho     {
    150       1.3  jruoho         UtilityName = ASL_COMPILER_NAME;
    151       1.1  jruoho     }
    152       1.1  jruoho 
    153       1.3  jruoho     /* Compiler signon with copyright */
    154       1.1  jruoho 
    155       1.3  jruoho     FlPrintFile (FileId, "%s\n", Prefix);
    156       1.3  jruoho     FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix));
    157       1.1  jruoho }
    158       1.1  jruoho 
    159       1.1  jruoho 
    160       1.1  jruoho /*******************************************************************************
    161       1.1  jruoho  *
    162       1.1  jruoho  * FUNCTION:    AslCompilerFileHeader
    163       1.1  jruoho  *
    164       1.1  jruoho  * PARAMETERS:  FileId      - ID of the output file
    165       1.1  jruoho  *
    166       1.1  jruoho  * RETURN:      None
    167       1.1  jruoho  *
    168       1.1  jruoho  * DESCRIPTION: Header used at the beginning of output files
    169       1.1  jruoho  *
    170       1.1  jruoho  ******************************************************************************/
    171       1.1  jruoho 
    172       1.1  jruoho void
    173       1.1  jruoho AslCompilerFileHeader (
    174       1.1  jruoho     UINT32                  FileId)
    175       1.1  jruoho {
    176       1.1  jruoho     struct tm               *NewTime;
    177       1.1  jruoho     time_t                  Aclock;
    178       1.1  jruoho     char                    *Prefix = "";
    179       1.1  jruoho 
    180       1.1  jruoho 
    181       1.1  jruoho     /* Set line prefix depending on the destination file type */
    182       1.1  jruoho 
    183       1.1  jruoho     switch (FileId)
    184       1.1  jruoho     {
    185       1.1  jruoho     case ASL_FILE_ASM_SOURCE_OUTPUT:
    186       1.1  jruoho     case ASL_FILE_ASM_INCLUDE_OUTPUT:
    187       1.1  jruoho 
    188       1.1  jruoho         Prefix = "; ";
    189       1.1  jruoho         break;
    190       1.1  jruoho 
    191       1.1  jruoho     case ASL_FILE_HEX_OUTPUT:
    192       1.1  jruoho 
    193       1.1  jruoho         if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
    194       1.1  jruoho         {
    195       1.1  jruoho             Prefix = "; ";
    196       1.1  jruoho         }
    197       1.1  jruoho         else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
    198       1.1  jruoho                  (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
    199       1.1  jruoho         {
    200       1.1  jruoho             Prefix = " * ";
    201       1.1  jruoho         }
    202       1.1  jruoho         break;
    203       1.1  jruoho 
    204       1.1  jruoho     case ASL_FILE_C_SOURCE_OUTPUT:
    205  1.3.10.1    yamt     case ASL_FILE_C_OFFSET_OUTPUT:
    206       1.1  jruoho     case ASL_FILE_C_INCLUDE_OUTPUT:
    207       1.1  jruoho 
    208       1.1  jruoho         Prefix = " * ";
    209       1.1  jruoho         break;
    210       1.1  jruoho 
    211       1.1  jruoho     default:
    212  1.3.10.1    yamt 
    213       1.1  jruoho         /* No other output types supported */
    214  1.3.10.1    yamt 
    215       1.1  jruoho         break;
    216       1.1  jruoho     }
    217       1.1  jruoho 
    218       1.1  jruoho     /* Compilation header with timestamp */
    219       1.1  jruoho 
    220       1.1  jruoho     (void) time (&Aclock);
    221       1.1  jruoho     NewTime = localtime (&Aclock);
    222       1.1  jruoho 
    223       1.1  jruoho     FlPrintFile (FileId,
    224       1.1  jruoho         "%sCompilation of \"%s\" - %s%s\n",
    225       1.1  jruoho         Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime),
    226       1.1  jruoho         Prefix);
    227       1.1  jruoho 
    228       1.1  jruoho     switch (FileId)
    229       1.1  jruoho     {
    230       1.1  jruoho     case ASL_FILE_C_SOURCE_OUTPUT:
    231  1.3.10.1    yamt     case ASL_FILE_C_OFFSET_OUTPUT:
    232       1.1  jruoho     case ASL_FILE_C_INCLUDE_OUTPUT:
    233  1.3.10.1    yamt 
    234       1.1  jruoho         FlPrintFile (FileId, " */\n");
    235       1.1  jruoho         break;
    236       1.1  jruoho 
    237       1.1  jruoho     default:
    238  1.3.10.1    yamt 
    239       1.1  jruoho         /* Nothing to do for other output types */
    240  1.3.10.1    yamt 
    241       1.1  jruoho         break;
    242       1.1  jruoho     }
    243       1.1  jruoho }
    244       1.1  jruoho 
    245       1.1  jruoho 
    246       1.1  jruoho /*******************************************************************************
    247       1.1  jruoho  *
    248       1.1  jruoho  * FUNCTION:    CmFlushSourceCode
    249       1.1  jruoho  *
    250       1.1  jruoho  * PARAMETERS:  None
    251       1.1  jruoho  *
    252       1.1  jruoho  * RETURN:      None
    253       1.1  jruoho  *
    254       1.1  jruoho  * DESCRIPTION: Read in any remaining source code after the parse tree
    255       1.1  jruoho  *              has been constructed.
    256       1.1  jruoho  *
    257       1.1  jruoho  ******************************************************************************/
    258       1.1  jruoho 
    259       1.1  jruoho static void
    260       1.1  jruoho CmFlushSourceCode (
    261       1.1  jruoho     void)
    262       1.1  jruoho {
    263       1.1  jruoho     char                    Buffer;
    264       1.1  jruoho 
    265       1.1  jruoho 
    266       1.1  jruoho     while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)
    267       1.1  jruoho     {
    268  1.3.10.1    yamt         AslInsertLineBuffer ((int) Buffer);
    269       1.1  jruoho     }
    270       1.1  jruoho 
    271  1.3.10.1    yamt     AslResetCurrentLineBuffer ();
    272       1.1  jruoho }
    273       1.1  jruoho 
    274       1.1  jruoho 
    275       1.1  jruoho /*******************************************************************************
    276       1.1  jruoho  *
    277       1.1  jruoho  * FUNCTION:    FlConsume*
    278       1.1  jruoho  *
    279  1.3.10.1    yamt  * PARAMETERS:  Handle              - Open input file
    280  1.3.10.1    yamt  *              Status              - File current status struct
    281       1.1  jruoho  *
    282       1.1  jruoho  * RETURN:      Number of lines consumed
    283       1.1  jruoho  *
    284       1.1  jruoho  * DESCRIPTION: Step over both types of comment during check for ascii chars
    285       1.1  jruoho  *
    286       1.1  jruoho  ******************************************************************************/
    287       1.1  jruoho 
    288       1.3  jruoho static void
    289       1.1  jruoho FlConsumeAnsiComment (
    290  1.3.10.1    yamt     FILE                    *Handle,
    291       1.1  jruoho     ASL_FILE_STATUS         *Status)
    292       1.1  jruoho {
    293       1.1  jruoho     UINT8                   Byte;
    294       1.1  jruoho     BOOLEAN                 ClosingComment = FALSE;
    295       1.1  jruoho 
    296       1.1  jruoho 
    297  1.3.10.1    yamt     while (fread (&Byte, 1, 1, Handle) == 1)
    298       1.1  jruoho     {
    299       1.1  jruoho         /* Scan until comment close is found */
    300       1.1  jruoho 
    301       1.1  jruoho         if (ClosingComment)
    302       1.1  jruoho         {
    303       1.1  jruoho             if (Byte == '/')
    304       1.1  jruoho             {
    305       1.1  jruoho                 return;
    306       1.1  jruoho             }
    307       1.1  jruoho 
    308       1.1  jruoho             if (Byte != '*')
    309       1.1  jruoho             {
    310       1.1  jruoho                 /* Reset */
    311       1.1  jruoho 
    312       1.1  jruoho                 ClosingComment = FALSE;
    313       1.1  jruoho             }
    314       1.1  jruoho         }
    315       1.1  jruoho         else if (Byte == '*')
    316       1.1  jruoho         {
    317       1.1  jruoho             ClosingComment = TRUE;
    318       1.1  jruoho         }
    319       1.1  jruoho 
    320       1.1  jruoho         /* Maintain line count */
    321       1.1  jruoho 
    322       1.1  jruoho         if (Byte == 0x0A)
    323       1.1  jruoho         {
    324       1.1  jruoho             Status->Line++;
    325       1.1  jruoho         }
    326       1.1  jruoho 
    327       1.1  jruoho         Status->Offset++;
    328       1.1  jruoho     }
    329       1.1  jruoho }
    330       1.1  jruoho 
    331       1.1  jruoho 
    332       1.3  jruoho static void
    333       1.1  jruoho FlConsumeNewComment (
    334  1.3.10.1    yamt     FILE                    *Handle,
    335       1.1  jruoho     ASL_FILE_STATUS         *Status)
    336       1.1  jruoho {
    337       1.1  jruoho     UINT8                   Byte;
    338       1.1  jruoho 
    339       1.1  jruoho 
    340  1.3.10.1    yamt     while (fread (&Byte, 1, 1, Handle) == 1)
    341       1.1  jruoho     {
    342       1.1  jruoho         Status->Offset++;
    343       1.1  jruoho 
    344       1.1  jruoho         /* Comment ends at newline */
    345       1.1  jruoho 
    346       1.1  jruoho         if (Byte == 0x0A)
    347       1.1  jruoho         {
    348       1.1  jruoho             Status->Line++;
    349       1.1  jruoho             return;
    350       1.1  jruoho         }
    351       1.1  jruoho     }
    352       1.1  jruoho }
    353       1.1  jruoho 
    354       1.1  jruoho 
    355       1.1  jruoho /*******************************************************************************
    356       1.1  jruoho  *
    357  1.3.10.1    yamt  * FUNCTION:    FlCheckForAcpiTable
    358  1.3.10.1    yamt  *
    359  1.3.10.1    yamt  * PARAMETERS:  Handle              - Open input file
    360  1.3.10.1    yamt  *
    361  1.3.10.1    yamt  * RETURN:      Status
    362  1.3.10.1    yamt  *
    363  1.3.10.1    yamt  * DESCRIPTION: Determine if a file seems to be a binary ACPI table, via the
    364  1.3.10.1    yamt  *              following checks on what would be the table header:
    365  1.3.10.1    yamt  *              0) File must be at least as long as an ACPI_TABLE_HEADER
    366  1.3.10.1    yamt  *              1) The header length field must match the file size
    367  1.3.10.1    yamt  *              2) Signature, OemId, OemTableId, AslCompilerId must be ASCII
    368  1.3.10.1    yamt  *
    369  1.3.10.1    yamt  ******************************************************************************/
    370  1.3.10.1    yamt 
    371  1.3.10.1    yamt ACPI_STATUS
    372  1.3.10.1    yamt FlCheckForAcpiTable (
    373  1.3.10.1    yamt     FILE                    *Handle)
    374  1.3.10.1    yamt {
    375  1.3.10.1    yamt     ACPI_TABLE_HEADER       Table;
    376  1.3.10.1    yamt     UINT32                  FileSize;
    377  1.3.10.1    yamt     size_t                  Actual;
    378  1.3.10.1    yamt     UINT32                  i;
    379  1.3.10.1    yamt 
    380  1.3.10.1    yamt 
    381  1.3.10.1    yamt     /* Read a potential table header */
    382  1.3.10.1    yamt 
    383  1.3.10.1    yamt     Actual = fread (&Table, 1, sizeof (ACPI_TABLE_HEADER), Handle);
    384  1.3.10.1    yamt     fseek (Handle, 0, SEEK_SET);
    385  1.3.10.1    yamt 
    386  1.3.10.1    yamt     if (Actual < sizeof (ACPI_TABLE_HEADER))
    387  1.3.10.1    yamt     {
    388  1.3.10.1    yamt         return (AE_ERROR);
    389  1.3.10.1    yamt     }
    390  1.3.10.1    yamt 
    391  1.3.10.1    yamt     /* Header length field must match the file size */
    392  1.3.10.1    yamt 
    393  1.3.10.1    yamt     FileSize = DtGetFileSize (Handle);
    394  1.3.10.1    yamt     if (Table.Length != FileSize)
    395  1.3.10.1    yamt     {
    396  1.3.10.1    yamt         return (AE_ERROR);
    397  1.3.10.1    yamt     }
    398  1.3.10.1    yamt 
    399  1.3.10.1    yamt     /*
    400  1.3.10.1    yamt      * These fields must be ASCII:
    401  1.3.10.1    yamt      * Signature, OemId, OemTableId, AslCompilerId.
    402  1.3.10.1    yamt      * We allow a NULL terminator in OemId and OemTableId.
    403  1.3.10.1    yamt      */
    404  1.3.10.1    yamt     for (i = 0; i < ACPI_NAME_SIZE; i++)
    405  1.3.10.1    yamt     {
    406  1.3.10.1    yamt         if (!ACPI_IS_ASCII ((UINT8) Table.Signature[i]))
    407  1.3.10.1    yamt         {
    408  1.3.10.1    yamt             return (AE_ERROR);
    409  1.3.10.1    yamt         }
    410  1.3.10.1    yamt 
    411  1.3.10.1    yamt         if (!ACPI_IS_ASCII ((UINT8) Table.AslCompilerId[i]))
    412  1.3.10.1    yamt         {
    413  1.3.10.1    yamt             return (AE_ERROR);
    414  1.3.10.1    yamt         }
    415  1.3.10.1    yamt     }
    416  1.3.10.1    yamt 
    417  1.3.10.1    yamt     for (i = 0; (i < ACPI_OEM_ID_SIZE) && (Table.OemId[i]); i++)
    418  1.3.10.1    yamt     {
    419  1.3.10.1    yamt         if (!ACPI_IS_ASCII ((UINT8) Table.OemId[i]))
    420  1.3.10.1    yamt         {
    421  1.3.10.1    yamt             return (AE_ERROR);
    422  1.3.10.1    yamt         }
    423  1.3.10.1    yamt     }
    424  1.3.10.1    yamt 
    425  1.3.10.1    yamt     for (i = 0; (i < ACPI_OEM_TABLE_ID_SIZE) && (Table.OemTableId[i]); i++)
    426  1.3.10.1    yamt     {
    427  1.3.10.1    yamt         if (!ACPI_IS_ASCII ((UINT8) Table.OemTableId[i]))
    428  1.3.10.1    yamt         {
    429  1.3.10.1    yamt             return (AE_ERROR);
    430  1.3.10.1    yamt         }
    431  1.3.10.1    yamt     }
    432  1.3.10.1    yamt 
    433  1.3.10.1    yamt     printf ("Binary file appears to be a valid ACPI table, disassembling\n");
    434  1.3.10.1    yamt     return (AE_OK);
    435  1.3.10.1    yamt }
    436  1.3.10.1    yamt 
    437  1.3.10.1    yamt 
    438  1.3.10.1    yamt /*******************************************************************************
    439  1.3.10.1    yamt  *
    440       1.1  jruoho  * FUNCTION:    FlCheckForAscii
    441       1.1  jruoho  *
    442  1.3.10.1    yamt  * PARAMETERS:  Handle              - Open input file
    443  1.3.10.1    yamt  *              Filename            - Input filename
    444  1.3.10.1    yamt  *              DisplayErrors       - TRUE if error messages desired
    445       1.1  jruoho  *
    446       1.1  jruoho  * RETURN:      Status
    447       1.1  jruoho  *
    448       1.1  jruoho  * DESCRIPTION: Verify that the input file is entirely ASCII. Ignores characters
    449       1.1  jruoho  *              within comments. Note: does not handle nested comments and does
    450       1.1  jruoho  *              not handle comment delimiters within string literals. However,
    451       1.1  jruoho  *              on the rare chance this happens and an invalid character is
    452       1.1  jruoho  *              missed, the parser will catch the error by failing in some
    453       1.1  jruoho  *              spectactular manner.
    454       1.1  jruoho  *
    455       1.1  jruoho  ******************************************************************************/
    456       1.1  jruoho 
    457       1.1  jruoho ACPI_STATUS
    458       1.1  jruoho FlCheckForAscii (
    459  1.3.10.1    yamt     FILE                    *Handle,
    460  1.3.10.1    yamt     char                    *Filename,
    461  1.3.10.1    yamt     BOOLEAN                 DisplayErrors)
    462       1.1  jruoho {
    463       1.1  jruoho     UINT8                   Byte;
    464       1.1  jruoho     ACPI_SIZE               BadBytes = 0;
    465       1.1  jruoho     BOOLEAN                 OpeningComment = FALSE;
    466       1.1  jruoho     ASL_FILE_STATUS         Status;
    467       1.1  jruoho 
    468       1.1  jruoho 
    469       1.1  jruoho     Status.Line = 1;
    470       1.1  jruoho     Status.Offset = 0;
    471       1.1  jruoho 
    472       1.1  jruoho     /* Read the entire file */
    473       1.1  jruoho 
    474  1.3.10.1    yamt     while (fread (&Byte, 1, 1, Handle) == 1)
    475       1.1  jruoho     {
    476       1.1  jruoho         /* Ignore comment fields (allow non-ascii within) */
    477       1.1  jruoho 
    478       1.1  jruoho         if (OpeningComment)
    479       1.1  jruoho         {
    480       1.1  jruoho             /* Check for second comment open delimiter */
    481       1.1  jruoho 
    482       1.1  jruoho             if (Byte == '*')
    483       1.1  jruoho             {
    484  1.3.10.1    yamt                 FlConsumeAnsiComment (Handle, &Status);
    485       1.1  jruoho             }
    486       1.1  jruoho 
    487       1.1  jruoho             if (Byte == '/')
    488       1.1  jruoho             {
    489  1.3.10.1    yamt                 FlConsumeNewComment (Handle, &Status);
    490       1.1  jruoho             }
    491       1.1  jruoho 
    492       1.1  jruoho             /* Reset */
    493       1.1  jruoho 
    494       1.1  jruoho             OpeningComment = FALSE;
    495       1.1  jruoho         }
    496       1.1  jruoho         else if (Byte == '/')
    497       1.1  jruoho         {
    498       1.1  jruoho             OpeningComment = TRUE;
    499       1.1  jruoho         }
    500       1.1  jruoho 
    501       1.1  jruoho         /* Check for an ASCII character */
    502       1.1  jruoho 
    503       1.1  jruoho         if (!ACPI_IS_ASCII (Byte))
    504       1.1  jruoho         {
    505  1.3.10.1    yamt             if ((BadBytes < 10) && (DisplayErrors))
    506       1.1  jruoho             {
    507       1.1  jruoho                 AcpiOsPrintf (
    508       1.1  jruoho                     "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n",
    509       1.1  jruoho                     Byte, Status.Line, Status.Offset);
    510       1.1  jruoho             }
    511       1.1  jruoho 
    512       1.1  jruoho             BadBytes++;
    513       1.1  jruoho         }
    514       1.1  jruoho 
    515       1.1  jruoho         /* Update line counter */
    516       1.1  jruoho 
    517       1.1  jruoho         else if (Byte == 0x0A)
    518       1.1  jruoho         {
    519       1.1  jruoho             Status.Line++;
    520       1.1  jruoho         }
    521       1.1  jruoho 
    522       1.1  jruoho         Status.Offset++;
    523       1.1  jruoho     }
    524       1.1  jruoho 
    525       1.1  jruoho     /* Seek back to the beginning of the source file */
    526       1.1  jruoho 
    527  1.3.10.1    yamt     fseek (Handle, 0, SEEK_SET);
    528       1.1  jruoho 
    529       1.1  jruoho     /* Were there any non-ASCII characters in the file? */
    530       1.1  jruoho 
    531       1.1  jruoho     if (BadBytes)
    532       1.1  jruoho     {
    533  1.3.10.1    yamt         if (DisplayErrors)
    534  1.3.10.1    yamt         {
    535  1.3.10.1    yamt             AcpiOsPrintf (
    536  1.3.10.1    yamt                 "%u non-ASCII characters found in input source text, could be a binary file\n",
    537  1.3.10.1    yamt                 BadBytes);
    538  1.3.10.1    yamt             AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, Filename);
    539  1.3.10.1    yamt         }
    540  1.3.10.1    yamt 
    541       1.1  jruoho         return (AE_BAD_CHARACTER);
    542       1.1  jruoho     }
    543       1.1  jruoho 
    544  1.3.10.1    yamt     /* File is OK (100% ASCII) */
    545       1.1  jruoho 
    546       1.1  jruoho     return (AE_OK);
    547       1.1  jruoho }
    548       1.1  jruoho 
    549       1.1  jruoho 
    550       1.1  jruoho /*******************************************************************************
    551       1.1  jruoho  *
    552       1.1  jruoho  * FUNCTION:    CmDoCompile
    553       1.1  jruoho  *
    554       1.1  jruoho  * PARAMETERS:  None
    555       1.1  jruoho  *
    556       1.1  jruoho  * RETURN:      Status (0 = OK)
    557       1.1  jruoho  *
    558       1.1  jruoho  * DESCRIPTION: This procedure performs the entire compile
    559       1.1  jruoho  *
    560       1.1  jruoho  ******************************************************************************/
    561       1.1  jruoho 
    562       1.1  jruoho int
    563       1.1  jruoho CmDoCompile (
    564       1.1  jruoho     void)
    565       1.1  jruoho {
    566       1.1  jruoho     ACPI_STATUS             Status;
    567       1.1  jruoho     UINT8                   FullCompile;
    568       1.1  jruoho     UINT8                   Event;
    569       1.1  jruoho 
    570       1.1  jruoho 
    571       1.1  jruoho     FullCompile = UtBeginEvent ("*** Total Compile time ***");
    572       1.1  jruoho     Event = UtBeginEvent ("Open input and output files");
    573       1.1  jruoho     UtEndEvent (Event);
    574       1.1  jruoho 
    575  1.3.10.1    yamt     Event = UtBeginEvent ("Preprocess input file");
    576  1.3.10.1    yamt     if (Gbl_PreprocessFlag)
    577  1.3.10.1    yamt     {
    578  1.3.10.1    yamt         /* Preprocessor */
    579  1.3.10.1    yamt 
    580  1.3.10.1    yamt         PrDoPreprocess ();
    581  1.3.10.1    yamt         if (Gbl_PreprocessOnly)
    582  1.3.10.1    yamt         {
    583  1.3.10.1    yamt             UtEndEvent (Event);
    584  1.3.10.1    yamt             CmCleanupAndExit ();
    585  1.3.10.1    yamt             return (0);
    586  1.3.10.1    yamt         }
    587  1.3.10.1    yamt     }
    588  1.3.10.1    yamt     UtEndEvent (Event);
    589  1.3.10.1    yamt 
    590       1.1  jruoho     /* Build the parse tree */
    591       1.1  jruoho 
    592       1.1  jruoho     Event = UtBeginEvent ("Parse source code and build parse tree");
    593       1.1  jruoho     AslCompilerparse();
    594       1.1  jruoho     UtEndEvent (Event);
    595       1.1  jruoho 
    596  1.3.10.1    yamt     /* Check for parse errors */
    597       1.1  jruoho 
    598  1.3.10.1    yamt     Status = AslCheckForErrorExit ();
    599  1.3.10.1    yamt     if (ACPI_FAILURE (Status))
    600  1.3.10.1    yamt     {
    601  1.3.10.1    yamt         fprintf (stderr, "Compiler aborting due to parser-detected syntax error(s)\n");
    602  1.3.10.1    yamt         LsDumpParseTree ();
    603  1.3.10.1    yamt         goto ErrorExit;
    604  1.3.10.1    yamt     }
    605       1.1  jruoho 
    606       1.1  jruoho     /* Did the parse tree get successfully constructed? */
    607       1.1  jruoho 
    608       1.1  jruoho     if (!RootNode)
    609       1.1  jruoho     {
    610  1.3.10.1    yamt         /*
    611  1.3.10.1    yamt          * If there are no errors, then we have some sort of
    612  1.3.10.1    yamt          * internal problem.
    613  1.3.10.1    yamt          */
    614  1.3.10.1    yamt         AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
    615  1.3.10.1    yamt             NULL, "- Could not resolve parse tree root node");
    616  1.3.10.1    yamt 
    617  1.3.10.1    yamt         goto ErrorExit;
    618       1.1  jruoho     }
    619       1.1  jruoho 
    620  1.3.10.1    yamt 
    621  1.3.10.1    yamt     /* Flush out any remaining source after parse tree is complete */
    622  1.3.10.1    yamt 
    623  1.3.10.1    yamt     Event = UtBeginEvent ("Flush source input");
    624  1.3.10.1    yamt     CmFlushSourceCode ();
    625  1.3.10.1    yamt 
    626       1.1  jruoho     /* Optional parse tree dump, compiler debug output only */
    627       1.1  jruoho 
    628       1.1  jruoho     LsDumpParseTree ();
    629       1.1  jruoho 
    630       1.1  jruoho     OpcGetIntegerWidth (RootNode);
    631       1.1  jruoho     UtEndEvent (Event);
    632       1.1  jruoho 
    633       1.1  jruoho     /* Pre-process parse tree for any operator transforms */
    634       1.1  jruoho 
    635       1.1  jruoho     Event = UtBeginEvent ("Parse tree transforms");
    636       1.1  jruoho     DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n");
    637       1.1  jruoho     TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
    638       1.1  jruoho         TrAmlTransformWalk, NULL, NULL);
    639       1.1  jruoho     UtEndEvent (Event);
    640       1.1  jruoho 
    641       1.1  jruoho     /* Generate AML opcodes corresponding to the parse tokens */
    642       1.1  jruoho 
    643       1.1  jruoho     Event = UtBeginEvent ("Generate AML opcodes");
    644       1.1  jruoho     DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n");
    645       1.1  jruoho     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
    646       1.1  jruoho         OpcAmlOpcodeWalk, NULL);
    647       1.1  jruoho     UtEndEvent (Event);
    648       1.1  jruoho 
    649       1.1  jruoho     /*
    650       1.1  jruoho      * Now that the input is parsed, we can open the AML output file.
    651       1.1  jruoho      * Note: by default, the name of this file comes from the table descriptor
    652       1.1  jruoho      * within the input file.
    653       1.1  jruoho      */
    654       1.1  jruoho     Event = UtBeginEvent ("Open AML output file");
    655       1.1  jruoho     Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
    656  1.3.10.1    yamt     UtEndEvent (Event);
    657       1.1  jruoho     if (ACPI_FAILURE (Status))
    658       1.1  jruoho     {
    659       1.1  jruoho         AePrintErrorLog (ASL_FILE_STDERR);
    660  1.3.10.1    yamt         return (-1);
    661       1.1  jruoho     }
    662       1.1  jruoho 
    663       1.1  jruoho     /* Interpret and generate all compile-time constants */
    664       1.1  jruoho 
    665       1.1  jruoho     Event = UtBeginEvent ("Constant folding via AML interpreter");
    666       1.1  jruoho     DbgPrint (ASL_DEBUG_OUTPUT,
    667       1.1  jruoho         "\nInterpreting compile-time constant expressions\n\n");
    668       1.1  jruoho     TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
    669       1.1  jruoho         OpcAmlConstantWalk, NULL, NULL);
    670       1.1  jruoho     UtEndEvent (Event);
    671       1.1  jruoho 
    672       1.1  jruoho     /* Update AML opcodes if necessary, after constant folding */
    673       1.1  jruoho 
    674       1.1  jruoho     Event = UtBeginEvent ("Updating AML opcodes after constant folding");
    675       1.1  jruoho     DbgPrint (ASL_DEBUG_OUTPUT,
    676       1.1  jruoho         "\nUpdating AML opcodes after constant folding\n\n");
    677       1.1  jruoho     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD,
    678       1.1  jruoho         NULL, OpcAmlOpcodeUpdateWalk, NULL);
    679       1.1  jruoho     UtEndEvent (Event);
    680       1.1  jruoho 
    681       1.1  jruoho     /* Calculate all AML package lengths */
    682       1.1  jruoho 
    683       1.1  jruoho     Event = UtBeginEvent ("Generate AML package lengths");
    684       1.1  jruoho     DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n");
    685       1.1  jruoho     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
    686       1.1  jruoho         LnPackageLengthWalk, NULL);
    687       1.1  jruoho     UtEndEvent (Event);
    688       1.1  jruoho 
    689       1.1  jruoho     if (Gbl_ParseOnlyFlag)
    690       1.1  jruoho     {
    691  1.3.10.1    yamt         AePrintErrorLog (ASL_FILE_STDERR);
    692  1.3.10.1    yamt         UtDisplaySummary (ASL_FILE_STDERR);
    693       1.1  jruoho         if (Gbl_DebugFlag)
    694       1.1  jruoho         {
    695  1.3.10.1    yamt             /* Print error summary to the stdout also */
    696       1.1  jruoho 
    697  1.3.10.1    yamt             AePrintErrorLog (ASL_FILE_STDOUT);
    698  1.3.10.1    yamt             UtDisplaySummary (ASL_FILE_STDOUT);
    699       1.1  jruoho         }
    700  1.3.10.1    yamt         UtEndEvent (FullCompile);
    701  1.3.10.1    yamt         return (0);
    702       1.1  jruoho     }
    703       1.1  jruoho 
    704       1.1  jruoho     /*
    705       1.1  jruoho      * Create an internal namespace and use it as a symbol table
    706       1.1  jruoho      */
    707       1.1  jruoho 
    708       1.1  jruoho     /* Namespace loading */
    709       1.1  jruoho 
    710       1.1  jruoho     Event = UtBeginEvent ("Create ACPI Namespace");
    711       1.1  jruoho     Status = LdLoadNamespace (RootNode);
    712       1.1  jruoho     UtEndEvent (Event);
    713       1.1  jruoho     if (ACPI_FAILURE (Status))
    714       1.1  jruoho     {
    715  1.3.10.1    yamt         goto ErrorExit;
    716       1.1  jruoho     }
    717       1.1  jruoho 
    718       1.1  jruoho     /* Namespace cross-reference */
    719       1.1  jruoho 
    720       1.1  jruoho     AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace");
    721  1.3.10.1    yamt     Status = XfCrossReferenceNamespace ();
    722       1.1  jruoho     if (ACPI_FAILURE (Status))
    723       1.1  jruoho     {
    724  1.3.10.1    yamt         goto ErrorExit;
    725       1.1  jruoho     }
    726       1.1  jruoho 
    727       1.1  jruoho     /* Namespace - Check for non-referenced objects */
    728       1.1  jruoho 
    729       1.1  jruoho     LkFindUnreferencedObjects ();
    730       1.1  jruoho     UtEndEvent (AslGbl_NamespaceEvent);
    731       1.1  jruoho 
    732       1.1  jruoho     /*
    733  1.3.10.1    yamt      * Semantic analysis. This can happen only after the
    734       1.1  jruoho      * namespace has been loaded and cross-referenced.
    735       1.1  jruoho      *
    736       1.1  jruoho      * part one - check control methods
    737       1.1  jruoho      */
    738       1.1  jruoho     Event = UtBeginEvent ("Analyze control method return types");
    739       1.1  jruoho     AnalysisWalkInfo.MethodStack = NULL;
    740       1.1  jruoho 
    741       1.1  jruoho     DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n");
    742       1.1  jruoho     TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE,
    743  1.3.10.1    yamt         MtMethodAnalysisWalkBegin,
    744  1.3.10.1    yamt         MtMethodAnalysisWalkEnd, &AnalysisWalkInfo);
    745       1.1  jruoho     UtEndEvent (Event);
    746       1.1  jruoho 
    747       1.1  jruoho     /* Semantic error checking part two - typing of method returns */
    748       1.1  jruoho 
    749       1.1  jruoho     Event = UtBeginEvent ("Determine object types returned by methods");
    750       1.1  jruoho     DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing\n\n");
    751       1.3  jruoho     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD,
    752       1.3  jruoho         NULL, AnMethodTypingWalkEnd, NULL);
    753       1.1  jruoho     UtEndEvent (Event);
    754       1.1  jruoho 
    755       1.1  jruoho     /* Semantic error checking part three - operand type checking */
    756       1.1  jruoho 
    757       1.1  jruoho     Event = UtBeginEvent ("Analyze AML operand types");
    758       1.1  jruoho     DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking\n\n");
    759       1.3  jruoho     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD,
    760       1.3  jruoho         NULL, AnOperandTypecheckWalkEnd, &AnalysisWalkInfo);
    761       1.1  jruoho     UtEndEvent (Event);
    762       1.1  jruoho 
    763       1.1  jruoho     /* Semantic error checking part four - other miscellaneous checks */
    764       1.1  jruoho 
    765       1.1  jruoho     Event = UtBeginEvent ("Miscellaneous analysis");
    766       1.1  jruoho     DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous\n\n");
    767       1.3  jruoho     TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
    768       1.1  jruoho         AnOtherSemanticAnalysisWalkBegin,
    769       1.3  jruoho         NULL, &AnalysisWalkInfo);
    770       1.1  jruoho     UtEndEvent (Event);
    771       1.1  jruoho 
    772       1.1  jruoho     /* Calculate all AML package lengths */
    773       1.1  jruoho 
    774       1.1  jruoho     Event = UtBeginEvent ("Finish AML package length generation");
    775       1.1  jruoho     DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n");
    776       1.1  jruoho     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
    777       1.1  jruoho         LnInitLengthsWalk, NULL);
    778       1.1  jruoho     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
    779       1.1  jruoho         LnPackageLengthWalk, NULL);
    780       1.1  jruoho     UtEndEvent (Event);
    781       1.1  jruoho 
    782       1.1  jruoho     /* Code generation - emit the AML */
    783       1.1  jruoho 
    784       1.1  jruoho     Event = UtBeginEvent ("Generate AML code and write output files");
    785       1.1  jruoho     CgGenerateAmlOutput ();
    786       1.1  jruoho     UtEndEvent (Event);
    787       1.1  jruoho 
    788       1.1  jruoho     Event = UtBeginEvent ("Write optional output files");
    789       1.1  jruoho     CmDoOutputFiles ();
    790       1.1  jruoho     UtEndEvent (Event);
    791       1.1  jruoho 
    792       1.1  jruoho     UtEndEvent (FullCompile);
    793       1.1  jruoho     CmCleanupAndExit ();
    794  1.3.10.1    yamt     return (0);
    795  1.3.10.1    yamt 
    796  1.3.10.1    yamt ErrorExit:
    797  1.3.10.1    yamt     UtEndEvent (FullCompile);
    798  1.3.10.1    yamt     CmCleanupAndExit ();
    799  1.3.10.1    yamt     return (-1);
    800       1.1  jruoho }
    801       1.1  jruoho 
    802       1.1  jruoho 
    803       1.1  jruoho /*******************************************************************************
    804       1.1  jruoho  *
    805       1.1  jruoho  * FUNCTION:    CmDoOutputFiles
    806       1.1  jruoho  *
    807       1.1  jruoho  * PARAMETERS:  None
    808       1.1  jruoho  *
    809       1.1  jruoho  * RETURN:      None.
    810       1.1  jruoho  *
    811       1.1  jruoho  * DESCRIPTION: Create all "listing" type files
    812       1.1  jruoho  *
    813       1.1  jruoho  ******************************************************************************/
    814       1.1  jruoho 
    815       1.1  jruoho void
    816       1.1  jruoho CmDoOutputFiles (
    817       1.1  jruoho     void)
    818       1.1  jruoho {
    819       1.1  jruoho 
    820       1.1  jruoho     /* Create listings and hex files */
    821       1.1  jruoho 
    822       1.1  jruoho     LsDoListings ();
    823  1.3.10.1    yamt     HxDoHexOutput ();
    824       1.1  jruoho 
    825       1.1  jruoho     /* Dump the namespace to the .nsp file if requested */
    826       1.1  jruoho 
    827  1.3.10.1    yamt     (void) NsDisplayNamespace ();
    828       1.1  jruoho }
    829       1.1  jruoho 
    830       1.1  jruoho 
    831       1.1  jruoho /*******************************************************************************
    832       1.1  jruoho  *
    833  1.3.10.1    yamt  * FUNCTION:    CmDumpAllEvents
    834       1.1  jruoho  *
    835  1.3.10.1    yamt  * PARAMETERS:  None
    836       1.1  jruoho  *
    837       1.1  jruoho  * RETURN:      None.
    838       1.1  jruoho  *
    839  1.3.10.1    yamt  * DESCRIPTION: Dump all compiler events
    840       1.1  jruoho  *
    841       1.1  jruoho  ******************************************************************************/
    842       1.1  jruoho 
    843       1.1  jruoho static void
    844  1.3.10.1    yamt CmDumpAllEvents (
    845  1.3.10.1    yamt     void)
    846       1.1  jruoho {
    847  1.3.10.1    yamt     ASL_EVENT_INFO          *Event;
    848       1.1  jruoho     UINT32                  Delta;
    849       1.1  jruoho     UINT32                  USec;
    850       1.1  jruoho     UINT32                  MSec;
    851  1.3.10.1    yamt     UINT32                  i;
    852  1.3.10.1    yamt 
    853       1.1  jruoho 
    854  1.3.10.1    yamt     Event = AslGbl_Events;
    855  1.3.10.1    yamt 
    856  1.3.10.1    yamt     DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");
    857  1.3.10.1    yamt     if (Gbl_CompileTimesFlag)
    858       1.1  jruoho     {
    859  1.3.10.1    yamt         printf ("\nElapsed time for major events\n\n");
    860       1.1  jruoho     }
    861       1.1  jruoho 
    862  1.3.10.1    yamt     for (i = 0; i < AslGbl_NextEvent; i++)
    863  1.3.10.1    yamt     {
    864  1.3.10.1    yamt         if (Event->Valid)
    865  1.3.10.1    yamt         {
    866  1.3.10.1    yamt             /* Delta will be in 100-nanosecond units */
    867       1.1  jruoho 
    868  1.3.10.1    yamt             Delta = (UINT32) (Event->EndTime - Event->StartTime);
    869       1.1  jruoho 
    870  1.3.10.1    yamt             USec = Delta / ACPI_100NSEC_PER_USEC;
    871  1.3.10.1    yamt             MSec = Delta / ACPI_100NSEC_PER_MSEC;
    872       1.1  jruoho 
    873  1.3.10.1    yamt             /* Round milliseconds up */
    874       1.1  jruoho 
    875  1.3.10.1    yamt             if ((USec - (MSec * ACPI_USEC_PER_MSEC)) >= 500)
    876  1.3.10.1    yamt             {
    877  1.3.10.1    yamt                 MSec++;
    878  1.3.10.1    yamt             }
    879  1.3.10.1    yamt 
    880  1.3.10.1    yamt             DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",
    881  1.3.10.1    yamt                 USec, MSec, Event->EventName);
    882  1.3.10.1    yamt 
    883  1.3.10.1    yamt             if (Gbl_CompileTimesFlag)
    884  1.3.10.1    yamt             {
    885  1.3.10.1    yamt                 printf ("%8u usec %8u msec - %s\n",
    886  1.3.10.1    yamt                     USec, MSec, Event->EventName);
    887  1.3.10.1    yamt             }
    888  1.3.10.1    yamt         }
    889       1.1  jruoho 
    890  1.3.10.1    yamt         Event++;
    891  1.3.10.1    yamt     }
    892       1.1  jruoho }
    893       1.1  jruoho 
    894       1.1  jruoho 
    895       1.1  jruoho /*******************************************************************************
    896       1.1  jruoho  *
    897       1.1  jruoho  * FUNCTION:    CmCleanupAndExit
    898       1.1  jruoho  *
    899       1.1  jruoho  * PARAMETERS:  None
    900       1.1  jruoho  *
    901       1.1  jruoho  * RETURN:      None.
    902       1.1  jruoho  *
    903       1.1  jruoho  * DESCRIPTION: Close all open files and exit the compiler
    904       1.1  jruoho  *
    905       1.1  jruoho  ******************************************************************************/
    906       1.1  jruoho 
    907       1.1  jruoho void
    908       1.1  jruoho CmCleanupAndExit (
    909       1.1  jruoho     void)
    910       1.1  jruoho {
    911       1.1  jruoho     UINT32                  i;
    912  1.3.10.1    yamt     BOOLEAN                 DeleteAmlFile = FALSE;
    913       1.1  jruoho 
    914       1.1  jruoho 
    915  1.3.10.1    yamt     AePrintErrorLog (ASL_FILE_STDERR);
    916       1.1  jruoho     if (Gbl_DebugFlag)
    917       1.1  jruoho     {
    918  1.3.10.1    yamt         /* Print error summary to stdout also */
    919       1.1  jruoho 
    920  1.3.10.1    yamt         AePrintErrorLog (ASL_FILE_STDOUT);
    921       1.1  jruoho     }
    922       1.1  jruoho 
    923  1.3.10.1    yamt     /* Emit compile times if enabled */
    924  1.3.10.1    yamt 
    925  1.3.10.1    yamt     CmDumpAllEvents ();
    926       1.1  jruoho 
    927       1.1  jruoho     if (Gbl_CompileTimesFlag)
    928       1.1  jruoho     {
    929       1.1  jruoho         printf ("\nMiscellaneous compile statistics\n\n");
    930       1.1  jruoho         printf ("%11u : %s\n", TotalParseNodes, "Parse nodes");
    931       1.1  jruoho         printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches");
    932       1.1  jruoho         printf ("%11u : %s\n", TotalNamedObjects, "Named objects");
    933       1.1  jruoho         printf ("%11u : %s\n", TotalMethods, "Control methods");
    934       1.1  jruoho         printf ("%11u : %s\n", TotalAllocations, "Memory Allocations");
    935       1.1  jruoho         printf ("%11u : %s\n", TotalAllocated, "Total allocated memory");
    936       1.1  jruoho         printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded");
    937       1.1  jruoho         printf ("\n");
    938       1.1  jruoho     }
    939       1.1  jruoho 
    940       1.1  jruoho     if (Gbl_NsLookupCount)
    941       1.1  jruoho     {
    942       1.1  jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
    943       1.1  jruoho             "\n\nMiscellaneous compile statistics\n\n");
    944       1.1  jruoho 
    945       1.1  jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
    946       1.1  jruoho             "%32s : %u\n", "Total Namespace searches",
    947       1.1  jruoho             Gbl_NsLookupCount);
    948       1.1  jruoho 
    949       1.1  jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
    950       1.1  jruoho             "%32s : %u usec\n", "Time per search", ((UINT32)
    951       1.1  jruoho             (AslGbl_Events[AslGbl_NamespaceEvent].EndTime -
    952       1.1  jruoho                 AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) /
    953       1.1  jruoho                 Gbl_NsLookupCount);
    954       1.1  jruoho     }
    955       1.1  jruoho 
    956       1.1  jruoho     if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
    957       1.1  jruoho     {
    958       1.1  jruoho         printf ("\nMaximum error count (%u) exceeded\n",
    959       1.1  jruoho             ASL_MAX_ERROR_COUNT);
    960       1.1  jruoho     }
    961       1.1  jruoho 
    962       1.1  jruoho     UtDisplaySummary (ASL_FILE_STDOUT);
    963       1.1  jruoho 
    964  1.3.10.1    yamt     /*
    965  1.3.10.1    yamt      * We will delete the AML file if there are errors and the
    966  1.3.10.1    yamt      * force AML output option has not been used.
    967  1.3.10.1    yamt      */
    968  1.3.10.1    yamt     if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors) &&
    969  1.3.10.1    yamt         Gbl_Files[ASL_FILE_AML_OUTPUT].Handle)
    970  1.3.10.1    yamt     {
    971  1.3.10.1    yamt         DeleteAmlFile = TRUE;
    972  1.3.10.1    yamt     }
    973  1.3.10.1    yamt 
    974       1.1  jruoho     /* Close all open files */
    975       1.1  jruoho 
    976  1.3.10.1    yamt     /*
    977  1.3.10.1    yamt      * Take care with the preprocessor file (.i), it might be the same
    978  1.3.10.1    yamt      * as the "input" file, depending on where the compiler has terminated
    979  1.3.10.1    yamt      * or aborted. Prevent attempt to close the same file twice in
    980  1.3.10.1    yamt      * loop below.
    981  1.3.10.1    yamt      */
    982  1.3.10.1    yamt     if (Gbl_Files[ASL_FILE_PREPROCESSOR].Handle ==
    983  1.3.10.1    yamt         Gbl_Files[ASL_FILE_INPUT].Handle)
    984  1.3.10.1    yamt     {
    985  1.3.10.1    yamt         Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL;
    986  1.3.10.1    yamt     }
    987  1.3.10.1    yamt 
    988  1.3.10.1    yamt     /* Close the standard I/O files */
    989  1.3.10.1    yamt 
    990  1.3.10.1    yamt     for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
    991       1.1  jruoho     {
    992       1.1  jruoho         FlCloseFile (i);
    993       1.1  jruoho     }
    994       1.1  jruoho 
    995       1.1  jruoho     /* Delete AML file if there are errors */
    996       1.1  jruoho 
    997  1.3.10.1    yamt     if (DeleteAmlFile)
    998       1.1  jruoho     {
    999  1.3.10.1    yamt         FlDeleteFile (ASL_FILE_AML_OUTPUT);
   1000  1.3.10.1    yamt     }
   1001  1.3.10.1    yamt 
   1002  1.3.10.1    yamt     /* Delete the preprocessor output file (.i) unless -li flag is set */
   1003  1.3.10.1    yamt 
   1004  1.3.10.1    yamt     if (!Gbl_PreprocessorOutputFlag &&
   1005  1.3.10.1    yamt         Gbl_PreprocessFlag)
   1006  1.3.10.1    yamt     {
   1007  1.3.10.1    yamt         FlDeleteFile (ASL_FILE_PREPROCESSOR);
   1008       1.1  jruoho     }
   1009       1.1  jruoho 
   1010       1.1  jruoho     /*
   1011       1.1  jruoho      * Delete intermediate ("combined") source file (if -ls flag not set)
   1012       1.3  jruoho      * This file is created during normal ASL/AML compiles. It is not
   1013       1.3  jruoho      * created by the data table compiler.
   1014       1.3  jruoho      *
   1015       1.3  jruoho      * If the -ls flag is set, then the .SRC file should not be deleted.
   1016       1.3  jruoho      * In this case, Gbl_SourceOutputFlag is set to TRUE.
   1017       1.3  jruoho      *
   1018       1.3  jruoho      * Note: Handles are cleared by FlCloseFile above, so we look at the
   1019       1.3  jruoho      * filename instead, to determine if the .SRC file was actually
   1020       1.3  jruoho      * created.
   1021       1.1  jruoho      *
   1022       1.1  jruoho      * TBD: SourceOutput should be .TMP, then rename if we want to keep it?
   1023       1.1  jruoho      */
   1024  1.3.10.1    yamt     if (!Gbl_SourceOutputFlag)
   1025       1.1  jruoho     {
   1026  1.3.10.1    yamt         FlDeleteFile (ASL_FILE_SOURCE_OUTPUT);
   1027       1.1  jruoho     }
   1028       1.1  jruoho }
   1029