Subversion Repositories Kolibri OS

Rev

Rev 1498 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. /******************************************************************************
  3.  *
  4.  * Module Name: aslcompile - top level compile module
  5.  *
  6.  *****************************************************************************/
  7.  
  8. /******************************************************************************
  9.  *
  10.  * 1. Copyright Notice
  11.  *
  12.  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
  13.  * All rights reserved.
  14.  *
  15.  * 2. License
  16.  *
  17.  * 2.1. This is your license from Intel Corp. under its intellectual property
  18.  * rights.  You may have additional license terms from the party that provided
  19.  * you this software, covering your right to use that party's intellectual
  20.  * property rights.
  21.  *
  22.  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
  23.  * copy of the source code appearing in this file ("Covered Code") an
  24.  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
  25.  * base code distributed originally by Intel ("Original Intel Code") to copy,
  26.  * make derivatives, distribute, use and display any portion of the Covered
  27.  * Code in any form, with the right to sublicense such rights; and
  28.  *
  29.  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
  30.  * license (with the right to sublicense), under only those claims of Intel
  31.  * patents that are infringed by the Original Intel Code, to make, use, sell,
  32.  * offer to sell, and import the Covered Code and derivative works thereof
  33.  * solely to the minimum extent necessary to exercise the above copyright
  34.  * license, and in no event shall the patent license extend to any additions
  35.  * to or modifications of the Original Intel Code.  No other license or right
  36.  * is granted directly or by implication, estoppel or otherwise;
  37.  *
  38.  * The above copyright and patent license is granted only if the following
  39.  * conditions are met:
  40.  *
  41.  * 3. Conditions
  42.  *
  43.  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
  44.  * Redistribution of source code of any substantial portion of the Covered
  45.  * Code or modification with rights to further distribute source must include
  46.  * the above Copyright Notice, the above License, this list of Conditions,
  47.  * and the following Disclaimer and Export Compliance provision.  In addition,
  48.  * Licensee must cause all Covered Code to which Licensee contributes to
  49.  * contain a file documenting the changes Licensee made to create that Covered
  50.  * Code and the date of any change.  Licensee must include in that file the
  51.  * documentation of any changes made by any predecessor Licensee.  Licensee
  52.  * must include a prominent statement that the modification is derived,
  53.  * directly or indirectly, from Original Intel Code.
  54.  *
  55.  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
  56.  * Redistribution of source code of any substantial portion of the Covered
  57.  * Code or modification without rights to further distribute source must
  58.  * include the following Disclaimer and Export Compliance provision in the
  59.  * documentation and/or other materials provided with distribution.  In
  60.  * addition, Licensee may not authorize further sublicense of source of any
  61.  * portion of the Covered Code, and must include terms to the effect that the
  62.  * license from Licensee to its licensee is limited to the intellectual
  63.  * property embodied in the software Licensee provides to its licensee, and
  64.  * not to intellectual property embodied in modifications its licensee may
  65.  * make.
  66.  *
  67.  * 3.3. Redistribution of Executable. Redistribution in executable form of any
  68.  * substantial portion of the Covered Code or modification must reproduce the
  69.  * above Copyright Notice, and the following Disclaimer and Export Compliance
  70.  * provision in the documentation and/or other materials provided with the
  71.  * distribution.
  72.  *
  73.  * 3.4. Intel retains all right, title, and interest in and to the Original
  74.  * Intel Code.
  75.  *
  76.  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
  77.  * Intel shall be used in advertising or otherwise to promote the sale, use or
  78.  * other dealings in products derived from or relating to the Covered Code
  79.  * without prior written authorization from Intel.
  80.  *
  81.  * 4. Disclaimer and Export Compliance
  82.  *
  83.  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
  84.  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
  85.  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
  86.  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
  87.  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
  88.  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
  89.  * PARTICULAR PURPOSE.
  90.  *
  91.  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
  92.  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
  93.  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
  94.  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
  95.  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
  96.  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
  97.  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
  98.  * LIMITED REMEDY.
  99.  *
  100.  * 4.3. Licensee shall not export, either directly or indirectly, any of this
  101.  * software or system incorporating such software without first obtaining any
  102.  * required license or other approval from the U. S. Department of Commerce or
  103.  * any other agency or department of the United States Government.  In the
  104.  * event Licensee exports any such software from the United States or
  105.  * re-exports any such software from a foreign destination, Licensee shall
  106.  * ensure that the distribution and export/re-export of the software is in
  107.  * compliance with all laws, regulations, orders, or other restrictions of the
  108.  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
  109.  * any of its subsidiaries will export/re-export any technical data, process,
  110.  * software, or service, directly or indirectly, to any country for which the
  111.  * United States government or any agency thereof requires an export license,
  112.  * other governmental approval, or letter of assurance, without first obtaining
  113.  * such license, approval or letter.
  114.  *
  115.  *****************************************************************************/
  116.  
  117. #include "aslcompiler.h"
  118.  
  119. #include <stdio.h>
  120. #include <time.h>
  121. #include <acapps.h>
  122.  
  123. #define _COMPONENT          ACPI_COMPILER
  124.         ACPI_MODULE_NAME    ("aslcompile")
  125.  
  126. /* Local prototypes */
  127.  
  128. static void
  129. CmFlushSourceCode (
  130.     void);
  131.  
  132. static void
  133. FlConsumeAnsiComment (
  134.     ASL_FILE_INFO           *FileInfo,
  135.     ASL_FILE_STATUS         *Status);
  136.  
  137. static void
  138. FlConsumeNewComment (
  139.     ASL_FILE_INFO           *FileInfo,
  140.     ASL_FILE_STATUS         *Status);
  141.  
  142.  
  143. /*******************************************************************************
  144.  *
  145.  * FUNCTION:    AslCompilerSignon
  146.  *
  147.  * PARAMETERS:  FileId      - ID of the output file
  148.  *
  149.  * RETURN:      None
  150.  *
  151.  * DESCRIPTION: Display compiler signon
  152.  *
  153.  ******************************************************************************/
  154.  
  155. void
  156. AslCompilerSignon (
  157.     UINT32                  FileId)
  158. {
  159.     char                    *Prefix = "";
  160.     char                    *UtilityName;
  161.  
  162.  
  163.     /* Set line prefix depending on the destination file type */
  164.  
  165.     switch (FileId)
  166.     {
  167.     case ASL_FILE_ASM_SOURCE_OUTPUT:
  168.     case ASL_FILE_ASM_INCLUDE_OUTPUT:
  169.  
  170.         Prefix = "; ";
  171.         break;
  172.  
  173.     case ASL_FILE_HEX_OUTPUT:
  174.  
  175.         if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
  176.         {
  177.             Prefix = "; ";
  178.         }
  179.         else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
  180.                  (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
  181.         {
  182.             FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
  183.             Prefix = " * ";
  184.         }
  185.         break;
  186.  
  187.     case ASL_FILE_C_SOURCE_OUTPUT:
  188.     case ASL_FILE_C_INCLUDE_OUTPUT:
  189.  
  190.         Prefix = " * ";
  191.         break;
  192.  
  193.     default:
  194.         /* No other output types supported */
  195.         break;
  196.     }
  197.  
  198.     /* Running compiler or disassembler? */
  199.  
  200.     if (Gbl_DisasmFlag)
  201.     {
  202.         UtilityName = AML_DISASSEMBLER_NAME;
  203.     }
  204.     else
  205.     {
  206.         UtilityName = ASL_COMPILER_NAME;
  207.     }
  208.  
  209.     /* Compiler signon with copyright */
  210.  
  211.     FlPrintFile (FileId, "%s\n", Prefix);
  212.     FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix));
  213. }
  214.  
  215.  
  216. /*******************************************************************************
  217.  *
  218.  * FUNCTION:    AslCompilerFileHeader
  219.  *
  220.  * PARAMETERS:  FileId      - ID of the output file
  221.  *
  222.  * RETURN:      None
  223.  *
  224.  * DESCRIPTION: Header used at the beginning of output files
  225.  *
  226.  ******************************************************************************/
  227.  
  228. void
  229. AslCompilerFileHeader (
  230.     UINT32                  FileId)
  231. {
  232.     struct tm               *NewTime;
  233.     time_t                  Aclock;
  234.     char                    *Prefix = "";
  235.  
  236.  
  237.     /* Set line prefix depending on the destination file type */
  238.  
  239.     switch (FileId)
  240.     {
  241.     case ASL_FILE_ASM_SOURCE_OUTPUT:
  242.     case ASL_FILE_ASM_INCLUDE_OUTPUT:
  243.  
  244.         Prefix = "; ";
  245.         break;
  246.  
  247.     case ASL_FILE_HEX_OUTPUT:
  248.  
  249.         if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
  250.         {
  251.             Prefix = "; ";
  252.         }
  253.         else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
  254.                  (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
  255.         {
  256.             Prefix = " * ";
  257.         }
  258.         break;
  259.  
  260.     case ASL_FILE_C_SOURCE_OUTPUT:
  261.     case ASL_FILE_C_INCLUDE_OUTPUT:
  262.  
  263.         Prefix = " * ";
  264.         break;
  265.  
  266.     default:
  267.         /* No other output types supported */
  268.         break;
  269.     }
  270.  
  271.     /* Compilation header with timestamp */
  272.  
  273.     (void) time (&Aclock);
  274.     NewTime = localtime (&Aclock);
  275.  
  276.     FlPrintFile (FileId,
  277.         "%sCompilation of \"%s\" - %s%s\n",
  278.         Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime),
  279.         Prefix);
  280.  
  281.     switch (FileId)
  282.     {
  283.     case ASL_FILE_C_SOURCE_OUTPUT:
  284.     case ASL_FILE_C_INCLUDE_OUTPUT:
  285.         FlPrintFile (FileId, " */\n");
  286.         break;
  287.  
  288.     default:
  289.         /* Nothing to do for other output types */
  290.         break;
  291.     }
  292. }
  293.  
  294.  
  295. /*******************************************************************************
  296.  *
  297.  * FUNCTION:    CmFlushSourceCode
  298.  *
  299.  * PARAMETERS:  None
  300.  *
  301.  * RETURN:      None
  302.  *
  303.  * DESCRIPTION: Read in any remaining source code after the parse tree
  304.  *              has been constructed.
  305.  *
  306.  ******************************************************************************/
  307.  
  308. static void
  309. CmFlushSourceCode (
  310.     void)
  311. {
  312.     char                    Buffer;
  313.  
  314.  
  315.     while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)
  316.     {
  317.         InsertLineBuffer ((int) Buffer);
  318.     }
  319.  
  320.     ResetCurrentLineBuffer ();
  321. }
  322.  
  323.  
  324. /*******************************************************************************
  325.  *
  326.  * FUNCTION:    FlConsume*
  327.  *
  328.  * PARAMETERS:  FileInfo        - Points to an open input file
  329.  *
  330.  * RETURN:      Number of lines consumed
  331.  *
  332.  * DESCRIPTION: Step over both types of comment during check for ascii chars
  333.  *
  334.  ******************************************************************************/
  335.  
  336. static void
  337. FlConsumeAnsiComment (
  338.     ASL_FILE_INFO           *FileInfo,
  339.     ASL_FILE_STATUS         *Status)
  340. {
  341.     UINT8                   Byte;
  342.     BOOLEAN                 ClosingComment = FALSE;
  343.  
  344.  
  345.     while (fread (&Byte, 1, 1, FileInfo->Handle))
  346.     {
  347.         /* Scan until comment close is found */
  348.  
  349.         if (ClosingComment)
  350.         {
  351.             if (Byte == '/')
  352.             {
  353.                 return;
  354.             }
  355.  
  356.             if (Byte != '*')
  357.             {
  358.                 /* Reset */
  359.  
  360.                 ClosingComment = FALSE;
  361.             }
  362.         }
  363.         else if (Byte == '*')
  364.         {
  365.             ClosingComment = TRUE;
  366.         }
  367.  
  368.         /* Maintain line count */
  369.  
  370.         if (Byte == 0x0A)
  371.         {
  372.             Status->Line++;
  373.         }
  374.  
  375.         Status->Offset++;
  376.     }
  377. }
  378.  
  379.  
  380. static void
  381. FlConsumeNewComment (
  382.     ASL_FILE_INFO           *FileInfo,
  383.     ASL_FILE_STATUS         *Status)
  384. {
  385.     UINT8                   Byte;
  386.  
  387.  
  388.     while (fread (&Byte, 1, 1, FileInfo->Handle))
  389.     {
  390.         Status->Offset++;
  391.  
  392.         /* Comment ends at newline */
  393.  
  394.         if (Byte == 0x0A)
  395.         {
  396.             Status->Line++;
  397.             return;
  398.         }
  399.     }
  400. }
  401.  
  402.  
  403. /*******************************************************************************
  404.  *
  405.  * FUNCTION:    FlCheckForAscii
  406.  *
  407.  * PARAMETERS:  FileInfo        - Points to an open input file
  408.  *
  409.  * RETURN:      Status
  410.  *
  411.  * DESCRIPTION: Verify that the input file is entirely ASCII. Ignores characters
  412.  *              within comments. Note: does not handle nested comments and does
  413.  *              not handle comment delimiters within string literals. However,
  414.  *              on the rare chance this happens and an invalid character is
  415.  *              missed, the parser will catch the error by failing in some
  416.  *              spectactular manner.
  417.  *
  418.  ******************************************************************************/
  419.  
  420. ACPI_STATUS
  421. FlCheckForAscii (
  422.     ASL_FILE_INFO           *FileInfo)
  423. {
  424.     UINT8                   Byte;
  425.     ACPI_SIZE               BadBytes = 0;
  426.     BOOLEAN                 OpeningComment = FALSE;
  427.     ASL_FILE_STATUS         Status;
  428.  
  429.  
  430.     Status.Line = 1;
  431.     Status.Offset = 0;
  432.  
  433.     /* Read the entire file */
  434.  
  435.     while (fread (&Byte, 1, 1, FileInfo->Handle))
  436.     {
  437.         /* Ignore comment fields (allow non-ascii within) */
  438.  
  439.         if (OpeningComment)
  440.         {
  441.             /* Check for second comment open delimiter */
  442.  
  443.             if (Byte == '*')
  444.             {
  445.                 FlConsumeAnsiComment (FileInfo, &Status);
  446.             }
  447.  
  448.             if (Byte == '/')
  449.             {
  450.                 FlConsumeNewComment (FileInfo, &Status);
  451.             }
  452.  
  453.             /* Reset */
  454.  
  455.             OpeningComment = FALSE;
  456.         }
  457.         else if (Byte == '/')
  458.         {
  459.             OpeningComment = TRUE;
  460.         }
  461.  
  462.         /* Check for an ASCII character */
  463.  
  464.         if (!ACPI_IS_ASCII (Byte))
  465.         {
  466.             if (BadBytes < 10)
  467.             {
  468.                 AcpiOsPrintf (
  469.                     "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n",
  470.                     Byte, Status.Line, Status.Offset);
  471.             }
  472.  
  473.             BadBytes++;
  474.         }
  475.  
  476.         /* Update line counter */
  477.  
  478.         else if (Byte == 0x0A)
  479.         {
  480.             Status.Line++;
  481.         }
  482.  
  483.         Status.Offset++;
  484.     }
  485.  
  486.     /* Seek back to the beginning of the source file */
  487.  
  488.     fseek (FileInfo->Handle, 0, SEEK_SET);
  489.  
  490.     /* Were there any non-ASCII characters in the file? */
  491.  
  492.     if (BadBytes)
  493.     {
  494.         AcpiOsPrintf (
  495.             "%u non-ASCII characters found in input source text, could be a binary file\n",
  496.             BadBytes);
  497.         AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, FileInfo->Filename);
  498.         return (AE_BAD_CHARACTER);
  499.     }
  500.  
  501.     /* File is OK */
  502.  
  503.     return (AE_OK);
  504. }
  505.  
  506.  
  507. /*******************************************************************************
  508.  *
  509.  * FUNCTION:    CmDoCompile
  510.  *
  511.  * PARAMETERS:  None
  512.  *
  513.  * RETURN:      Status (0 = OK)
  514.  *
  515.  * DESCRIPTION: This procedure performs the entire compile
  516.  *
  517.  ******************************************************************************/
  518.  
  519. int
  520. CmDoCompile (
  521.     void)
  522. {
  523.     ACPI_STATUS             Status;
  524.     UINT8                   FullCompile;
  525.     UINT8                   Event;
  526.  
  527.  
  528.     FullCompile = UtBeginEvent ("*** Total Compile time ***");
  529.     Event = UtBeginEvent ("Open input and output files");
  530.     UtEndEvent (Event);
  531.  
  532.     /* Build the parse tree */
  533.  
  534.     Event = UtBeginEvent ("Parse source code and build parse tree");
  535.     AslCompilerparse();
  536.     UtEndEvent (Event);
  537.  
  538.     /* Flush out any remaining source after parse tree is complete */
  539.  
  540.     Event = UtBeginEvent ("Flush source input");
  541.     CmFlushSourceCode ();
  542.  
  543.     /* Did the parse tree get successfully constructed? */
  544.  
  545.     if (!RootNode)
  546.     {
  547.         CmCleanupAndExit ();
  548.         return -1;
  549.     }
  550.  
  551.     /* Optional parse tree dump, compiler debug output only */
  552.  
  553.     LsDumpParseTree ();
  554.  
  555.     OpcGetIntegerWidth (RootNode);
  556.     UtEndEvent (Event);
  557.  
  558.     /* Pre-process parse tree for any operator transforms */
  559.  
  560.     Event = UtBeginEvent ("Parse tree transforms");
  561.     DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n");
  562.     TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
  563.         TrAmlTransformWalk, NULL, NULL);
  564.     UtEndEvent (Event);
  565.  
  566.     /* Generate AML opcodes corresponding to the parse tokens */
  567.  
  568.     Event = UtBeginEvent ("Generate AML opcodes");
  569.     DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n");
  570.     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
  571.         OpcAmlOpcodeWalk, NULL);
  572.     UtEndEvent (Event);
  573.  
  574.     /*
  575.      * Now that the input is parsed, we can open the AML output file.
  576.      * Note: by default, the name of this file comes from the table descriptor
  577.      * within the input file.
  578.      */
  579.     Event = UtBeginEvent ("Open AML output file");
  580.     Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
  581.     if (ACPI_FAILURE (Status))
  582.     {
  583.         AePrintErrorLog (ASL_FILE_STDERR);
  584.         return -1;
  585.     }
  586.     UtEndEvent (Event);
  587.  
  588.     /* Interpret and generate all compile-time constants */
  589.  
  590.     Event = UtBeginEvent ("Constant folding via AML interpreter");
  591.     DbgPrint (ASL_DEBUG_OUTPUT,
  592.         "\nInterpreting compile-time constant expressions\n\n");
  593.     TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
  594.         OpcAmlConstantWalk, NULL, NULL);
  595.     UtEndEvent (Event);
  596.  
  597.     /* Update AML opcodes if necessary, after constant folding */
  598.  
  599.     Event = UtBeginEvent ("Updating AML opcodes after constant folding");
  600.     DbgPrint (ASL_DEBUG_OUTPUT,
  601.         "\nUpdating AML opcodes after constant folding\n\n");
  602.     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD,
  603.         NULL, OpcAmlOpcodeUpdateWalk, NULL);
  604.     UtEndEvent (Event);
  605.  
  606.     /* Calculate all AML package lengths */
  607.  
  608.     Event = UtBeginEvent ("Generate AML package lengths");
  609.     DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n");
  610.     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
  611.         LnPackageLengthWalk, NULL);
  612.     UtEndEvent (Event);
  613.  
  614.     if (Gbl_ParseOnlyFlag)
  615.     {
  616.         AePrintErrorLog (ASL_FILE_STDOUT);
  617.         UtDisplaySummary (ASL_FILE_STDOUT);
  618.         if (Gbl_DebugFlag)
  619.         {
  620.             /* Print error summary to the debug file */
  621.  
  622.             AePrintErrorLog (ASL_FILE_STDERR);
  623.             UtDisplaySummary (ASL_FILE_STDERR);
  624.         }
  625.         return 0;
  626.     }
  627.  
  628.     /*
  629.      * Create an internal namespace and use it as a symbol table
  630.      */
  631.  
  632.     /* Namespace loading */
  633.  
  634.     Event = UtBeginEvent ("Create ACPI Namespace");
  635.     Status = LdLoadNamespace (RootNode);
  636.     UtEndEvent (Event);
  637.     if (ACPI_FAILURE (Status))
  638.     {
  639.         return -1;
  640.     }
  641.  
  642.     /* Namespace cross-reference */
  643.  
  644.     AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace");
  645.     Status = LkCrossReferenceNamespace ();
  646.     if (ACPI_FAILURE (Status))
  647.     {
  648.         return -1;
  649.     }
  650.  
  651.     /* Namespace - Check for non-referenced objects */
  652.  
  653.     LkFindUnreferencedObjects ();
  654.     UtEndEvent (AslGbl_NamespaceEvent);
  655.  
  656.     /*
  657.      * Semantic analysis.  This can happen only after the
  658.      * namespace has been loaded and cross-referenced.
  659.      *
  660.      * part one - check control methods
  661.      */
  662.     Event = UtBeginEvent ("Analyze control method return types");
  663.     AnalysisWalkInfo.MethodStack = NULL;
  664.  
  665.     DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n");
  666.     TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE,
  667.         AnMethodAnalysisWalkBegin,
  668.         AnMethodAnalysisWalkEnd, &AnalysisWalkInfo);
  669.     UtEndEvent (Event);
  670.  
  671.     /* Semantic error checking part two - typing of method returns */
  672.  
  673.     Event = UtBeginEvent ("Determine object types returned by methods");
  674.     DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing\n\n");
  675.     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD,
  676.         NULL, AnMethodTypingWalkEnd, NULL);
  677.     UtEndEvent (Event);
  678.  
  679.     /* Semantic error checking part three - operand type checking */
  680.  
  681.     Event = UtBeginEvent ("Analyze AML operand types");
  682.     DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking\n\n");
  683.     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD,
  684.         NULL, AnOperandTypecheckWalkEnd, &AnalysisWalkInfo);
  685.     UtEndEvent (Event);
  686.  
  687.     /* Semantic error checking part four - other miscellaneous checks */
  688.  
  689.     Event = UtBeginEvent ("Miscellaneous analysis");
  690.     DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous\n\n");
  691.     TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
  692.         AnOtherSemanticAnalysisWalkBegin,
  693.         NULL, &AnalysisWalkInfo);
  694.     UtEndEvent (Event);
  695.  
  696.     /* Calculate all AML package lengths */
  697.  
  698.     Event = UtBeginEvent ("Finish AML package length generation");
  699.     DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n");
  700.     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
  701.         LnInitLengthsWalk, NULL);
  702.     TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
  703.         LnPackageLengthWalk, NULL);
  704.     UtEndEvent (Event);
  705.  
  706.     /* Code generation - emit the AML */
  707.  
  708.     Event = UtBeginEvent ("Generate AML code and write output files");
  709.     CgGenerateAmlOutput ();
  710.     UtEndEvent (Event);
  711.  
  712.     Event = UtBeginEvent ("Write optional output files");
  713.     CmDoOutputFiles ();
  714.     UtEndEvent (Event);
  715.  
  716.     UtEndEvent (FullCompile);
  717.     CmCleanupAndExit ();
  718.     return 0;
  719. }
  720.  
  721.  
  722. /*******************************************************************************
  723.  *
  724.  * FUNCTION:    CmDoOutputFiles
  725.  *
  726.  * PARAMETERS:  None
  727.  *
  728.  * RETURN:      None.
  729.  *
  730.  * DESCRIPTION: Create all "listing" type files
  731.  *
  732.  ******************************************************************************/
  733.  
  734. void
  735. CmDoOutputFiles (
  736.     void)
  737. {
  738.  
  739.     /* Create listings and hex files */
  740.  
  741.     LsDoListings ();
  742.     LsDoHexOutput ();
  743.  
  744.     /* Dump the namespace to the .nsp file if requested */
  745.  
  746.     (void) LsDisplayNamespace ();
  747. }
  748.  
  749.  
  750. /*******************************************************************************
  751.  *
  752.  * FUNCTION:    CmDumpEvent
  753.  *
  754.  * PARAMETERS:  Event           - A compiler event struct
  755.  *
  756.  * RETURN:      None.
  757.  *
  758.  * DESCRIPTION: Dump a compiler event struct
  759.  *
  760.  ******************************************************************************/
  761.  
  762. static void
  763. CmDumpEvent (
  764.     ASL_EVENT_INFO          *Event)
  765. {
  766.     UINT32                  Delta;
  767.     UINT32                  USec;
  768.     UINT32                  MSec;
  769.  
  770.     if (!Event->Valid)
  771.     {
  772.         return;
  773.     }
  774.  
  775.     /* Delta will be in 100-nanosecond units */
  776.  
  777.     Delta = (UINT32) (Event->EndTime - Event->StartTime);
  778.  
  779.     USec = Delta / 10;
  780.     MSec = Delta / 10000;
  781.  
  782.     /* Round milliseconds up */
  783.  
  784.     if ((USec - (MSec * 1000)) >= 500)
  785.     {
  786.         MSec++;
  787.     }
  788.  
  789.     DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",
  790.         USec, MSec, Event->EventName);
  791. }
  792.  
  793.  
  794. /*******************************************************************************
  795.  *
  796.  * FUNCTION:    CmCleanupAndExit
  797.  *
  798.  * PARAMETERS:  None
  799.  *
  800.  * RETURN:      None.
  801.  *
  802.  * DESCRIPTION: Close all open files and exit the compiler
  803.  *
  804.  ******************************************************************************/
  805.  
  806. void
  807. CmCleanupAndExit (
  808.     void)
  809. {
  810.     UINT32                  i;
  811.  
  812.  
  813.     AePrintErrorLog (ASL_FILE_STDOUT);
  814.     if (Gbl_DebugFlag)
  815.     {
  816.         /* Print error summary to the debug file */
  817.  
  818.         AePrintErrorLog (ASL_FILE_STDERR);
  819.     }
  820.  
  821.     DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");
  822.     for (i = 0; i < AslGbl_NextEvent; i++)
  823.     {
  824.         CmDumpEvent (&AslGbl_Events[i]);
  825.     }
  826.  
  827.     if (Gbl_CompileTimesFlag)
  828.     {
  829.         printf ("\nElapsed time for major events\n\n");
  830.         for (i = 0; i < AslGbl_NextEvent; i++)
  831.         {
  832.             CmDumpEvent (&AslGbl_Events[i]);
  833.         }
  834.  
  835.         printf ("\nMiscellaneous compile statistics\n\n");
  836.         printf ("%11u : %s\n", TotalParseNodes, "Parse nodes");
  837.         printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches");
  838.         printf ("%11u : %s\n", TotalNamedObjects, "Named objects");
  839.         printf ("%11u : %s\n", TotalMethods, "Control methods");
  840.         printf ("%11u : %s\n", TotalAllocations, "Memory Allocations");
  841.         printf ("%11u : %s\n", TotalAllocated, "Total allocated memory");
  842.         printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded");
  843.         printf ("\n");
  844.     }
  845.  
  846.     if (Gbl_NsLookupCount)
  847.     {
  848.         DbgPrint (ASL_DEBUG_OUTPUT,
  849.             "\n\nMiscellaneous compile statistics\n\n");
  850.  
  851.         DbgPrint (ASL_DEBUG_OUTPUT,
  852.             "%32s : %u\n", "Total Namespace searches",
  853.             Gbl_NsLookupCount);
  854.  
  855.         DbgPrint (ASL_DEBUG_OUTPUT,
  856.             "%32s : %u usec\n", "Time per search", ((UINT32)
  857.             (AslGbl_Events[AslGbl_NamespaceEvent].EndTime -
  858.                 AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) /
  859.                 Gbl_NsLookupCount);
  860.     }
  861.  
  862.     if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
  863.     {
  864.         printf ("\nMaximum error count (%u) exceeded\n",
  865.             ASL_MAX_ERROR_COUNT);
  866.     }
  867.  
  868.     UtDisplaySummary (ASL_FILE_STDOUT);
  869.  
  870.     /* Close all open files */
  871.  
  872.     for (i = 2; i < ASL_MAX_FILE_TYPE; i++)
  873.     {
  874.         FlCloseFile (i);
  875.     }
  876.  
  877.     /* Delete AML file if there are errors */
  878.  
  879.     if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors) &&
  880.         Gbl_Files[ASL_FILE_AML_OUTPUT].Handle)
  881.     {
  882.         if (remove (Gbl_Files[ASL_FILE_AML_OUTPUT].Filename))
  883.         {
  884.             printf ("%s: ",
  885.                 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename);
  886.             perror ("Could not delete AML file");
  887.         }
  888.     }
  889.  
  890.     /*
  891.      * Delete intermediate ("combined") source file (if -ls flag not set)
  892.      * This file is created during normal ASL/AML compiles. It is not
  893.      * created by the data table compiler.
  894.      *
  895.      * If the -ls flag is set, then the .SRC file should not be deleted.
  896.      * In this case, Gbl_SourceOutputFlag is set to TRUE.
  897.      *
  898.      * Note: Handles are cleared by FlCloseFile above, so we look at the
  899.      * filename instead, to determine if the .SRC file was actually
  900.      * created.
  901.      *
  902.      * TBD: SourceOutput should be .TMP, then rename if we want to keep it?
  903.      */
  904.     if (!Gbl_SourceOutputFlag && Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename)
  905.     {
  906.         if (remove (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename))
  907.         {
  908.             printf ("%s: ",
  909.                 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
  910.             perror ("Could not delete SRC file");
  911.         }
  912.     }
  913. }
  914.  
  915.  
  916.