Home | History | Annotate | Line # | Download | only in compiler
aslstartup.c revision 1.1.1.22
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: aslstartup - Compiler startup routines, called from main
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8  1.1.1.22  christos  * Copyright (C) 2000 - 2023, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13   1.1.1.2    jruoho  * are met:
     14   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.1.1.2    jruoho  *    without modification.
     17   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.1.1.2    jruoho  *    binary redistribution.
     22   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25   1.1.1.2    jruoho  *
     26   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.1.1.2    jruoho  * Software Foundation.
     29   1.1.1.2    jruoho  *
     30   1.1.1.2    jruoho  * NO WARRANTY
     31   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.18  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.1.1.2    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "aslcompiler.h"
     45       1.1    jruoho #include "actables.h"
     46   1.1.1.3  christos #include "acdisasm.h"
     47       1.1    jruoho #include "acapps.h"
     48   1.1.1.9  christos #include "acconvert.h"
     49       1.1    jruoho 
     50       1.1    jruoho #define _COMPONENT          ACPI_COMPILER
     51       1.1    jruoho         ACPI_MODULE_NAME    ("aslstartup")
     52       1.1    jruoho 
     53       1.1    jruoho 
     54       1.1    jruoho /* Local prototypes */
     55       1.1    jruoho 
     56   1.1.1.2    jruoho static UINT8
     57       1.1    jruoho AslDetectSourceFileType (
     58       1.1    jruoho     ASL_FILE_INFO           *Info);
     59       1.1    jruoho 
     60   1.1.1.3  christos 
     61   1.1.1.3  christos /* Globals */
     62   1.1.1.3  christos 
     63   1.1.1.3  christos static BOOLEAN          AslToFile = TRUE;
     64   1.1.1.3  christos 
     65       1.1    jruoho 
     66       1.1    jruoho /*******************************************************************************
     67       1.1    jruoho  *
     68       1.1    jruoho  * FUNCTION:    AslInitializeGlobals
     69       1.1    jruoho  *
     70       1.1    jruoho  * PARAMETERS:  None
     71       1.1    jruoho  *
     72       1.1    jruoho  * RETURN:      None
     73       1.1    jruoho  *
     74       1.1    jruoho  * DESCRIPTION: Re-initialize globals needed to restart the compiler. This
     75       1.1    jruoho  *              allows multiple files to be disassembled and/or compiled.
     76       1.1    jruoho  *
     77       1.1    jruoho  ******************************************************************************/
     78       1.1    jruoho 
     79   1.1.1.2    jruoho void
     80       1.1    jruoho AslInitializeGlobals (
     81       1.1    jruoho     void)
     82       1.1    jruoho {
     83       1.1    jruoho     UINT32                  i;
     84       1.1    jruoho 
     85       1.1    jruoho 
     86       1.1    jruoho     /* Init compiler globals */
     87       1.1    jruoho 
     88  1.1.1.13  christos     AslGbl_SyntaxError = 0;
     89  1.1.1.13  christos     AslGbl_CurrentColumn = 0;
     90  1.1.1.13  christos     AslGbl_CurrentLineNumber = 1;
     91  1.1.1.13  christos     AslGbl_LogicalLineNumber = 1;
     92  1.1.1.13  christos     AslGbl_CurrentLineOffset = 0;
     93  1.1.1.13  christos     AslGbl_InputFieldCount = 0;
     94  1.1.1.13  christos     AslGbl_InputByteCount = 0;
     95  1.1.1.13  christos     AslGbl_NsLookupCount = 0;
     96  1.1.1.13  christos     AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer;
     97  1.1.1.13  christos 
     98  1.1.1.13  christos     AslGbl_ErrorLog = NULL;
     99  1.1.1.13  christos     AslGbl_NextError = NULL;
    100  1.1.1.13  christos     AslGbl_Signature = NULL;
    101  1.1.1.13  christos     AslGbl_FileType = 0;
    102  1.1.1.13  christos 
    103  1.1.1.13  christos     AslGbl_TotalExecutableOpcodes = 0;
    104  1.1.1.13  christos     AslGbl_TotalNamedObjects = 0;
    105  1.1.1.13  christos     AslGbl_TotalKeywords = 0;
    106  1.1.1.13  christos     AslGbl_TotalParseNodes = 0;
    107  1.1.1.13  christos     AslGbl_TotalMethods = 0;
    108  1.1.1.13  christos     AslGbl_TotalAllocations = 0;
    109  1.1.1.13  christos     AslGbl_TotalAllocated = 0;
    110  1.1.1.13  christos     AslGbl_TotalFolds = 0;
    111   1.1.1.3  christos 
    112       1.1    jruoho     AslGbl_NextEvent = 0;
    113       1.1    jruoho     for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++)
    114       1.1    jruoho     {
    115  1.1.1.13  christos         AslGbl_ExceptionCount[i] = 0;
    116       1.1    jruoho     }
    117       1.1    jruoho 
    118  1.1.1.12  christos     if (AcpiGbl_CaptureComments)
    119   1.1.1.9  christos     {
    120  1.1.1.13  christos         AslGbl_CommentState.SpacesBefore          = 0;
    121  1.1.1.13  christos         AslGbl_CommentState.CommentType           = 1;
    122  1.1.1.13  christos         AslGbl_CommentState.LatestParseOp         = NULL;
    123  1.1.1.13  christos         AslGbl_CommentState.ParsingParenBraceNode = NULL;
    124  1.1.1.13  christos         AslGbl_CommentState.CaptureComments       = TRUE;
    125   1.1.1.9  christos     }
    126       1.1    jruoho }
    127       1.1    jruoho 
    128       1.1    jruoho 
    129       1.1    jruoho /*******************************************************************************
    130       1.1    jruoho  *
    131       1.1    jruoho  * FUNCTION:    AslDetectSourceFileType
    132       1.1    jruoho  *
    133       1.1    jruoho  * PARAMETERS:  Info            - Name/Handle for the file (must be open)
    134       1.1    jruoho  *
    135       1.1    jruoho  * RETURN:      File Type
    136       1.1    jruoho  *
    137       1.1    jruoho  * DESCRIPTION: Determine the type of the input file. Either binary (contains
    138       1.1    jruoho  *              non-ASCII characters), ASL file, or an ACPI Data Table file.
    139       1.1    jruoho  *
    140       1.1    jruoho  ******************************************************************************/
    141       1.1    jruoho 
    142   1.1.1.2    jruoho static UINT8
    143       1.1    jruoho AslDetectSourceFileType (
    144       1.1    jruoho     ASL_FILE_INFO           *Info)
    145       1.1    jruoho {
    146       1.1    jruoho     char                    *FileChar;
    147   1.1.1.7  christos     UINT8                   Type = ASL_INPUT_TYPE_ASCII_DATA; /* default */
    148       1.1    jruoho     ACPI_STATUS             Status;
    149       1.1    jruoho 
    150       1.1    jruoho 
    151   1.1.1.7  christos     /* Check for 100% ASCII source file (comments are ignored) */
    152   1.1.1.3  christos 
    153   1.1.1.7  christos     Status = FlIsFileAsciiSource (Info->Filename, FALSE);
    154   1.1.1.3  christos     if (ACPI_SUCCESS (Status))
    155   1.1.1.3  christos     {
    156   1.1.1.7  christos         /*
    157   1.1.1.7  christos          * File contains ASCII source code. Determine if this is an ASL
    158   1.1.1.7  christos          * file or an ACPI data table file.
    159   1.1.1.7  christos          */
    160  1.1.1.13  christos         while (fgets (AslGbl_CurrentLineBuffer, AslGbl_LineBufferSize, Info->Handle))
    161   1.1.1.7  christos         {
    162   1.1.1.7  christos             /* Uppercase the buffer for caseless compare */
    163   1.1.1.3  christos 
    164  1.1.1.13  christos             FileChar = AslGbl_CurrentLineBuffer;
    165   1.1.1.7  christos             while (*FileChar)
    166   1.1.1.7  christos             {
    167   1.1.1.7  christos                 *FileChar = (char) toupper ((int) *FileChar);
    168   1.1.1.7  christos                 FileChar++;
    169   1.1.1.7  christos             }
    170       1.1    jruoho 
    171   1.1.1.7  christos             /* Presence of "DefinitionBlock" indicates actual ASL code */
    172   1.1.1.3  christos 
    173  1.1.1.13  christos             if (strstr (AslGbl_CurrentLineBuffer, "DEFINITIONBLOCK"))
    174   1.1.1.7  christos             {
    175   1.1.1.7  christos                 /* Appears to be an ASL file */
    176   1.1.1.7  christos 
    177   1.1.1.7  christos                 Type = ASL_INPUT_TYPE_ASCII_ASL;
    178   1.1.1.7  christos                 goto Cleanup;
    179   1.1.1.7  christos             }
    180   1.1.1.3  christos         }
    181       1.1    jruoho 
    182   1.1.1.7  christos         /* Appears to be an ASCII data table source file */
    183       1.1    jruoho 
    184   1.1.1.7  christos         Type = ASL_INPUT_TYPE_ASCII_DATA;
    185   1.1.1.7  christos         goto Cleanup;
    186   1.1.1.7  christos     }
    187       1.1    jruoho 
    188  1.1.1.19  christos     /*
    189  1.1.1.19  christos      * We have some sort of binary table; reopen in binary mode, then
    190  1.1.1.19  christos      * check for valid ACPI table
    191  1.1.1.19  christos      */
    192  1.1.1.19  christos     fclose (Info->Handle);
    193  1.1.1.19  christos     Info->Handle = fopen (Info->Filename, "rb");
    194  1.1.1.19  christos     if (!Info->Handle)
    195  1.1.1.19  christos     {
    196  1.1.1.19  christos         fprintf (stderr, "Could not open input file %s\n",
    197  1.1.1.19  christos             Info->Filename);
    198  1.1.1.19  christos     }
    199       1.1    jruoho 
    200   1.1.1.7  christos     Status = AcValidateTableHeader (Info->Handle, 0);
    201   1.1.1.7  christos     if (ACPI_SUCCESS (Status))
    202   1.1.1.7  christos     {
    203   1.1.1.7  christos         fprintf (stderr,
    204   1.1.1.7  christos             "Binary file appears to be a valid ACPI table, disassembling\n");
    205   1.1.1.7  christos 
    206   1.1.1.7  christos         Type = ASL_INPUT_TYPE_BINARY_ACPI_TABLE;
    207   1.1.1.7  christos         goto Cleanup;
    208       1.1    jruoho     }
    209  1.1.1.10  christos     else
    210  1.1.1.10  christos     {
    211  1.1.1.10  christos         fprintf (stderr,
    212  1.1.1.21  christos             "Binary file does not contain a valid standard ACPI table\n");
    213  1.1.1.10  christos     }
    214       1.1    jruoho 
    215   1.1.1.7  christos     Type = ASL_INPUT_TYPE_BINARY;
    216       1.1    jruoho 
    217       1.1    jruoho 
    218       1.1    jruoho Cleanup:
    219       1.1    jruoho 
    220       1.1    jruoho     /* Must seek back to the start of the file */
    221       1.1    jruoho 
    222       1.1    jruoho     fseek (Info->Handle, 0, SEEK_SET);
    223       1.1    jruoho     return (Type);
    224       1.1    jruoho }
    225       1.1    jruoho 
    226       1.1    jruoho 
    227       1.1    jruoho /*******************************************************************************
    228       1.1    jruoho  *
    229   1.1.1.3  christos  * FUNCTION:    AslDoDisassembly
    230   1.1.1.3  christos  *
    231   1.1.1.3  christos  * PARAMETERS:  None
    232   1.1.1.3  christos  *
    233   1.1.1.3  christos  * RETURN:      Status
    234   1.1.1.3  christos  *
    235   1.1.1.3  christos  * DESCRIPTION: Initiate AML file disassembly. Uses ACPICA subsystem to build
    236  1.1.1.14  christos  *              namespace. This function assumes that the ACPI subsystem has
    237  1.1.1.14  christos  *              been initialized. The caller of the initialization will also
    238  1.1.1.14  christos  *              terminate the ACPI subsystem.
    239   1.1.1.3  christos  *
    240   1.1.1.3  christos  ******************************************************************************/
    241   1.1.1.3  christos 
    242  1.1.1.14  christos ACPI_STATUS
    243   1.1.1.3  christos AslDoDisassembly (
    244   1.1.1.3  christos     void)
    245   1.1.1.3  christos {
    246   1.1.1.3  christos     ACPI_STATUS             Status;
    247   1.1.1.3  christos 
    248   1.1.1.3  christos 
    249   1.1.1.3  christos     Status = AcpiAllocateRootTable (4);
    250   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    251   1.1.1.3  christos     {
    252   1.1.1.3  christos         AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n",
    253   1.1.1.3  christos             AcpiFormatException (Status));
    254   1.1.1.3  christos         return (Status);
    255   1.1.1.3  christos     }
    256   1.1.1.3  christos 
    257   1.1.1.3  christos     /* This is where the disassembly happens */
    258   1.1.1.3  christos 
    259   1.1.1.7  christos     AcpiGbl_DmOpt_Disasm = TRUE;
    260   1.1.1.3  christos     Status = AdAmlDisassemble (AslToFile,
    261  1.1.1.13  christos         AslGbl_Files[ASL_FILE_INPUT].Filename, AslGbl_OutputFilenamePrefix,
    262  1.1.1.13  christos         &AslGbl_Files[ASL_FILE_INPUT].Filename);
    263   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    264   1.1.1.3  christos     {
    265   1.1.1.3  christos         return (Status);
    266   1.1.1.3  christos     }
    267   1.1.1.3  christos 
    268   1.1.1.3  christos     /* Check if any control methods were unresolved */
    269   1.1.1.3  christos 
    270   1.1.1.3  christos     AcpiDmUnresolvedWarning (0);
    271   1.1.1.3  christos 
    272  1.1.1.14  christos     /* Clear Error log */
    273   1.1.1.3  christos 
    274   1.1.1.3  christos     AeClearErrorLog ();
    275   1.1.1.3  christos 
    276   1.1.1.3  christos     /*
    277  1.1.1.13  christos      * AslGbl_Files[ASL_FILE_INPUT].Filename was replaced with the
    278   1.1.1.3  christos      * .DSL disassembly file, which can now be compiled if requested
    279   1.1.1.3  christos      */
    280  1.1.1.13  christos     if (AslGbl_DoCompile)
    281   1.1.1.3  christos     {
    282   1.1.1.3  christos         AcpiOsPrintf ("\nCompiling \"%s\"\n",
    283  1.1.1.13  christos             AslGbl_Files[ASL_FILE_INPUT].Filename);
    284   1.1.1.3  christos         return (AE_CTRL_CONTINUE);
    285   1.1.1.3  christos     }
    286   1.1.1.3  christos 
    287   1.1.1.3  christos     return (AE_OK);
    288   1.1.1.3  christos }
    289   1.1.1.3  christos 
    290   1.1.1.3  christos 
    291   1.1.1.3  christos /*******************************************************************************
    292   1.1.1.3  christos  *
    293       1.1    jruoho  * FUNCTION:    AslDoOneFile
    294       1.1    jruoho  *
    295       1.1    jruoho  * PARAMETERS:  Filename        - Name of the file
    296       1.1    jruoho  *
    297       1.1    jruoho  * RETURN:      Status
    298       1.1    jruoho  *
    299       1.1    jruoho  * DESCRIPTION: Process a single file - either disassemble, compile, or both
    300       1.1    jruoho  *
    301       1.1    jruoho  ******************************************************************************/
    302       1.1    jruoho 
    303       1.1    jruoho ACPI_STATUS
    304       1.1    jruoho AslDoOneFile (
    305       1.1    jruoho     char                    *Filename)
    306       1.1    jruoho {
    307       1.1    jruoho     ACPI_STATUS             Status;
    308  1.1.1.14  christos     UINT8                   Event;
    309  1.1.1.14  christos     ASL_GLOBAL_FILE_NODE    *FileNode;
    310       1.1    jruoho 
    311       1.1    jruoho 
    312   1.1.1.3  christos     /* Re-initialize "some" compiler/preprocessor globals */
    313       1.1    jruoho 
    314       1.1    jruoho     AslInitializeGlobals ();
    315   1.1.1.3  christos     PrInitializeGlobals ();
    316       1.1    jruoho 
    317       1.1    jruoho     /*
    318   1.1.1.3  christos      * Extract the directory path. This path is used for possible include
    319   1.1.1.3  christos      * files and the optional AML filename embedded in the input file
    320   1.1.1.3  christos      * DefinitionBlock declaration.
    321       1.1    jruoho      */
    322  1.1.1.13  christos     Status = FlSplitInputPathname (Filename, &AslGbl_DirectoryPath, NULL);
    323   1.1.1.3  christos     if (ACPI_FAILURE (Status))
    324       1.1    jruoho     {
    325   1.1.1.3  christos         return (Status);
    326   1.1.1.3  christos     }
    327       1.1    jruoho 
    328  1.1.1.14  christos     /*
    329  1.1.1.14  christos      * There was an input file detected at this point. Each input ASL file is
    330  1.1.1.14  christos      * associated with one global file node consisting of the input file and
    331  1.1.1.14  christos      * all output files associated with it. This is useful when compiling
    332  1.1.1.14  christos      * multiple files in one command.
    333  1.1.1.14  christos      */
    334  1.1.1.14  christos     Status = FlInitOneFile(Filename);
    335  1.1.1.14  christos     if (ACPI_FAILURE (Status))
    336  1.1.1.14  christos     {
    337  1.1.1.14  christos         return (AE_ERROR);
    338  1.1.1.14  christos     }
    339  1.1.1.14  christos 
    340   1.1.1.4  christos     /* Take a copy of the input filename, convert any backslashes */
    341   1.1.1.4  christos 
    342  1.1.1.13  christos     AslGbl_Files[ASL_FILE_INPUT].Filename =
    343  1.1.1.11  christos         UtLocalCacheCalloc (strlen (Filename) + 1);
    344   1.1.1.4  christos 
    345  1.1.1.13  christos     strcpy (AslGbl_Files[ASL_FILE_INPUT].Filename, Filename);
    346  1.1.1.13  christos     UtConvertBackslashes (AslGbl_Files[ASL_FILE_INPUT].Filename);
    347       1.1    jruoho 
    348   1.1.1.3  christos     /*
    349  1.1.1.19  christos      * Open the input file. Here, this could be an ASCII source file,
    350  1.1.1.19  christos      * either an ASL file or a Data Table file, or a binary AML file
    351  1.1.1.19  christos      * or binary data table file (For disassembly).
    352       1.1    jruoho      */
    353  1.1.1.13  christos     Status = FlOpenInputFile (AslGbl_Files[ASL_FILE_INPUT].Filename);
    354       1.1    jruoho     if (ACPI_FAILURE (Status))
    355       1.1    jruoho     {
    356       1.1    jruoho         AePrintErrorLog (ASL_FILE_STDERR);
    357       1.1    jruoho         return (AE_ERROR);
    358       1.1    jruoho     }
    359       1.1    jruoho 
    360  1.1.1.14  christos     FileNode = FlGetCurrentFileNode();
    361  1.1.1.14  christos 
    362       1.1    jruoho     /* Determine input file type */
    363       1.1    jruoho 
    364  1.1.1.13  christos     AslGbl_FileType = AslDetectSourceFileType (&AslGbl_Files[ASL_FILE_INPUT]);
    365  1.1.1.15  christos     FileNode->FileType = AslGbl_FileType;
    366  1.1.1.13  christos     if (AslGbl_FileType == ASL_INPUT_TYPE_BINARY)
    367       1.1    jruoho     {
    368       1.1    jruoho         return (AE_ERROR);
    369       1.1    jruoho     }
    370       1.1    jruoho 
    371  1.1.1.19  christos     FileNode->OriginalInputFileSize = FlGetFileSize (ASL_FILE_INPUT);
    372  1.1.1.19  christos 
    373       1.1    jruoho     /*
    374       1.1    jruoho      * If -p not specified, we will use the input filename as the
    375       1.1    jruoho      * output filename prefix
    376       1.1    jruoho      */
    377  1.1.1.13  christos     if (AslGbl_UseDefaultAmlFilename)
    378       1.1    jruoho     {
    379  1.1.1.13  christos         AslGbl_OutputFilenamePrefix = AslGbl_Files[ASL_FILE_INPUT].Filename;
    380       1.1    jruoho     }
    381       1.1    jruoho 
    382  1.1.1.14  christos     /*
    383  1.1.1.14  christos      * Open the output file. Note: by default, the name of this file comes from
    384  1.1.1.14  christos      * the table descriptor within the input file.
    385  1.1.1.14  christos      */
    386  1.1.1.14  christos     if (AslGbl_FileType == ASL_INPUT_TYPE_ASCII_ASL)
    387  1.1.1.14  christos     {
    388  1.1.1.14  christos         Event = UtBeginEvent ("Open AML output file");
    389  1.1.1.14  christos         Status = FlOpenAmlOutputFile (AslGbl_OutputFilenamePrefix);
    390  1.1.1.14  christos         UtEndEvent (Event);
    391  1.1.1.14  christos         if (ACPI_FAILURE (Status))
    392  1.1.1.14  christos         {
    393  1.1.1.14  christos             AePrintErrorLog (ASL_FILE_STDERR);
    394  1.1.1.14  christos             return (AE_ERROR);
    395  1.1.1.14  christos         }
    396  1.1.1.14  christos     }
    397  1.1.1.14  christos 
    398       1.1    jruoho     /* Open the optional output files (listings, etc.) */
    399       1.1    jruoho 
    400  1.1.1.13  christos     Status = FlOpenMiscOutputFiles (AslGbl_OutputFilenamePrefix);
    401       1.1    jruoho     if (ACPI_FAILURE (Status))
    402       1.1    jruoho     {
    403       1.1    jruoho         AePrintErrorLog (ASL_FILE_STDERR);
    404       1.1    jruoho         return (AE_ERROR);
    405       1.1    jruoho     }
    406       1.1    jruoho 
    407       1.1    jruoho     /*
    408       1.1    jruoho      * Compilation of ASL source versus DataTable source uses different
    409       1.1    jruoho      * compiler subsystems
    410       1.1    jruoho      */
    411  1.1.1.13  christos     switch (AslGbl_FileType)
    412       1.1    jruoho     {
    413       1.1    jruoho     /*
    414       1.1    jruoho      * Data Table Compilation
    415       1.1    jruoho      */
    416       1.1    jruoho     case ASL_INPUT_TYPE_ASCII_DATA:
    417       1.1    jruoho 
    418       1.1    jruoho         Status = DtDoCompile ();
    419   1.1.1.3  christos         if (ACPI_FAILURE (Status))
    420   1.1.1.3  christos         {
    421   1.1.1.3  christos             return (Status);
    422   1.1.1.3  christos         }
    423       1.1    jruoho 
    424  1.1.1.13  christos         if (AslGbl_Signature)
    425       1.1    jruoho         {
    426  1.1.1.13  christos             AslGbl_Signature = NULL;
    427       1.1    jruoho         }
    428   1.1.1.3  christos 
    429   1.1.1.3  christos         /* Check if any errors occurred during compile */
    430   1.1.1.3  christos 
    431   1.1.1.3  christos         Status = AslCheckForErrorExit ();
    432   1.1.1.3  christos         if (ACPI_FAILURE (Status))
    433   1.1.1.3  christos         {
    434   1.1.1.3  christos             return (Status);
    435   1.1.1.3  christos         }
    436   1.1.1.3  christos 
    437   1.1.1.3  christos         /* Cleanup (for next source file) and exit */
    438   1.1.1.3  christos 
    439       1.1    jruoho         AeClearErrorLog ();
    440   1.1.1.3  christos         PrTerminatePreprocessor ();
    441       1.1    jruoho         return (Status);
    442       1.1    jruoho 
    443       1.1    jruoho     /*
    444   1.1.1.3  christos      * ASL Compilation
    445       1.1    jruoho      */
    446       1.1    jruoho     case ASL_INPUT_TYPE_ASCII_ASL:
    447       1.1    jruoho 
    448  1.1.1.14  christos         Status = CmDoCompile ();
    449   1.1.1.3  christos         if (ACPI_FAILURE (Status))
    450       1.1    jruoho         {
    451  1.1.1.15  christos             PrTerminatePreprocessor ();
    452   1.1.1.3  christos             return (Status);
    453       1.1    jruoho         }
    454       1.1    jruoho 
    455  1.1.1.14  christos         /*
    456  1.1.1.14  christos          * At this point, we know how many lines are in the input file. Save it
    457  1.1.1.14  christos          * to display for post-compilation summary.
    458  1.1.1.14  christos          */
    459  1.1.1.14  christos         FileNode->TotalLineCount = AslGbl_CurrentLineNumber;
    460       1.1    jruoho         return (AE_OK);
    461       1.1    jruoho 
    462   1.1.1.3  christos     /*
    463   1.1.1.3  christos      * Binary ACPI table was auto-detected, disassemble it
    464   1.1.1.3  christos      */
    465   1.1.1.7  christos     case ASL_INPUT_TYPE_BINARY_ACPI_TABLE:
    466   1.1.1.3  christos 
    467   1.1.1.3  christos         /* We have what appears to be an ACPI table, disassemble it */
    468   1.1.1.3  christos 
    469   1.1.1.3  christos         FlCloseFile (ASL_FILE_INPUT);
    470  1.1.1.13  christos         AslGbl_DoCompile = FALSE;
    471  1.1.1.10  christos         AcpiGbl_DisasmFlag = TRUE;
    472   1.1.1.3  christos         Status = AslDoDisassembly ();
    473   1.1.1.3  christos         return (Status);
    474   1.1.1.3  christos 
    475   1.1.1.3  christos     /* Unknown binary table */
    476   1.1.1.3  christos 
    477       1.1    jruoho     case ASL_INPUT_TYPE_BINARY:
    478       1.1    jruoho 
    479       1.1    jruoho         AePrintErrorLog (ASL_FILE_STDERR);
    480       1.1    jruoho         return (AE_ERROR);
    481       1.1    jruoho 
    482       1.1    jruoho     default:
    483   1.1.1.3  christos 
    484  1.1.1.13  christos         printf ("Unknown file type %X\n", AslGbl_FileType);
    485       1.1    jruoho         return (AE_ERROR);
    486       1.1    jruoho     }
    487       1.1    jruoho }
    488       1.1    jruoho 
    489       1.1    jruoho 
    490       1.1    jruoho /*******************************************************************************
    491       1.1    jruoho  *
    492   1.1.1.3  christos  * FUNCTION:    AslCheckForErrorExit
    493       1.1    jruoho  *
    494   1.1.1.3  christos  * PARAMETERS:  None. Examines global exception count array
    495       1.1    jruoho  *
    496       1.1    jruoho  * RETURN:      Status
    497       1.1    jruoho  *
    498   1.1.1.3  christos  * DESCRIPTION: Determine if compiler should abort with error status
    499       1.1    jruoho  *
    500       1.1    jruoho  ******************************************************************************/
    501       1.1    jruoho 
    502       1.1    jruoho ACPI_STATUS
    503   1.1.1.3  christos AslCheckForErrorExit (
    504   1.1.1.3  christos     void)
    505       1.1    jruoho {
    506       1.1    jruoho 
    507   1.1.1.3  christos     /*
    508   1.1.1.3  christos      * Return non-zero exit code if there have been errors, unless the
    509   1.1.1.3  christos      * global ignore error flag has been set
    510   1.1.1.3  christos      */
    511  1.1.1.13  christos     if (!AslGbl_IgnoreErrors)
    512       1.1    jruoho     {
    513  1.1.1.13  christos         if (AslGbl_ExceptionCount[ASL_ERROR] > 0)
    514       1.1    jruoho         {
    515   1.1.1.3  christos             return (AE_ERROR);
    516       1.1    jruoho         }
    517       1.1    jruoho 
    518   1.1.1.3  christos         /* Optionally treat warnings as errors */
    519       1.1    jruoho 
    520  1.1.1.13  christos         if (AslGbl_WarningsAsErrors)
    521   1.1.1.3  christos         {
    522  1.1.1.13  christos             if ((AslGbl_ExceptionCount[ASL_WARNING] > 0)  ||
    523  1.1.1.13  christos                 (AslGbl_ExceptionCount[ASL_WARNING2] > 0) ||
    524  1.1.1.13  christos                 (AslGbl_ExceptionCount[ASL_WARNING3] > 0))
    525   1.1.1.3  christos             {
    526  1.1.1.14  christos                 AslError (ASL_ERROR, ASL_MSG_WARNING_AS_ERROR, NULL,
    527  1.1.1.14  christos                     "(reporting warnings as errors)");
    528   1.1.1.3  christos                 return (AE_ERROR);
    529   1.1.1.3  christos             }
    530   1.1.1.3  christos         }
    531       1.1    jruoho     }
    532       1.1    jruoho 
    533   1.1.1.3  christos     return (AE_OK);
    534       1.1    jruoho }
    535