aslcompile.c revision 123315
1118611Snjl 2118611Snjl/****************************************************************************** 3118611Snjl * 4118611Snjl * Module Name: aslcompile - top level compile module 5123315Snjl * $Revision: 72 $ 6118611Snjl * 7118611Snjl *****************************************************************************/ 8118611Snjl 9118611Snjl/****************************************************************************** 10118611Snjl * 11118611Snjl * 1. Copyright Notice 12118611Snjl * 13118611Snjl * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp. 14118611Snjl * All rights reserved. 15118611Snjl * 16118611Snjl * 2. License 17118611Snjl * 18118611Snjl * 2.1. This is your license from Intel Corp. under its intellectual property 19118611Snjl * rights. You may have additional license terms from the party that provided 20118611Snjl * you this software, covering your right to use that party's intellectual 21118611Snjl * property rights. 22118611Snjl * 23118611Snjl * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 24118611Snjl * copy of the source code appearing in this file ("Covered Code") an 25118611Snjl * irrevocable, perpetual, worldwide license under Intel's copyrights in the 26118611Snjl * base code distributed originally by Intel ("Original Intel Code") to copy, 27118611Snjl * make derivatives, distribute, use and display any portion of the Covered 28118611Snjl * Code in any form, with the right to sublicense such rights; and 29118611Snjl * 30118611Snjl * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 31118611Snjl * license (with the right to sublicense), under only those claims of Intel 32118611Snjl * patents that are infringed by the Original Intel Code, to make, use, sell, 33118611Snjl * offer to sell, and import the Covered Code and derivative works thereof 34118611Snjl * solely to the minimum extent necessary to exercise the above copyright 35118611Snjl * license, and in no event shall the patent license extend to any additions 36118611Snjl * to or modifications of the Original Intel Code. No other license or right 37118611Snjl * is granted directly or by implication, estoppel or otherwise; 38118611Snjl * 39118611Snjl * The above copyright and patent license is granted only if the following 40118611Snjl * conditions are met: 41118611Snjl * 42118611Snjl * 3. Conditions 43118611Snjl * 44118611Snjl * 3.1. Redistribution of Source with Rights to Further Distribute Source. 45118611Snjl * Redistribution of source code of any substantial portion of the Covered 46118611Snjl * Code or modification with rights to further distribute source must include 47118611Snjl * the above Copyright Notice, the above License, this list of Conditions, 48118611Snjl * and the following Disclaimer and Export Compliance provision. In addition, 49118611Snjl * Licensee must cause all Covered Code to which Licensee contributes to 50118611Snjl * contain a file documenting the changes Licensee made to create that Covered 51118611Snjl * Code and the date of any change. Licensee must include in that file the 52118611Snjl * documentation of any changes made by any predecessor Licensee. Licensee 53118611Snjl * must include a prominent statement that the modification is derived, 54118611Snjl * directly or indirectly, from Original Intel Code. 55118611Snjl * 56118611Snjl * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 57118611Snjl * Redistribution of source code of any substantial portion of the Covered 58118611Snjl * Code or modification without rights to further distribute source must 59118611Snjl * include the following Disclaimer and Export Compliance provision in the 60118611Snjl * documentation and/or other materials provided with distribution. In 61118611Snjl * addition, Licensee may not authorize further sublicense of source of any 62118611Snjl * portion of the Covered Code, and must include terms to the effect that the 63118611Snjl * license from Licensee to its licensee is limited to the intellectual 64118611Snjl * property embodied in the software Licensee provides to its licensee, and 65118611Snjl * not to intellectual property embodied in modifications its licensee may 66118611Snjl * make. 67118611Snjl * 68118611Snjl * 3.3. Redistribution of Executable. Redistribution in executable form of any 69118611Snjl * substantial portion of the Covered Code or modification must reproduce the 70118611Snjl * above Copyright Notice, and the following Disclaimer and Export Compliance 71118611Snjl * provision in the documentation and/or other materials provided with the 72118611Snjl * distribution. 73118611Snjl * 74118611Snjl * 3.4. Intel retains all right, title, and interest in and to the Original 75118611Snjl * Intel Code. 76118611Snjl * 77118611Snjl * 3.5. Neither the name Intel nor any other trademark owned or controlled by 78118611Snjl * Intel shall be used in advertising or otherwise to promote the sale, use or 79118611Snjl * other dealings in products derived from or relating to the Covered Code 80118611Snjl * without prior written authorization from Intel. 81118611Snjl * 82118611Snjl * 4. Disclaimer and Export Compliance 83118611Snjl * 84118611Snjl * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 85118611Snjl * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 86118611Snjl * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 87118611Snjl * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 88118611Snjl * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 89118611Snjl * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 90118611Snjl * PARTICULAR PURPOSE. 91118611Snjl * 92118611Snjl * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 93118611Snjl * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 94118611Snjl * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 95118611Snjl * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 96118611Snjl * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 97118611Snjl * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 98118611Snjl * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 99118611Snjl * LIMITED REMEDY. 100118611Snjl * 101118611Snjl * 4.3. Licensee shall not export, either directly or indirectly, any of this 102118611Snjl * software or system incorporating such software without first obtaining any 103118611Snjl * required license or other approval from the U. S. Department of Commerce or 104118611Snjl * any other agency or department of the United States Government. In the 105118611Snjl * event Licensee exports any such software from the United States or 106118611Snjl * re-exports any such software from a foreign destination, Licensee shall 107118611Snjl * ensure that the distribution and export/re-export of the software is in 108118611Snjl * compliance with all laws, regulations, orders, or other restrictions of the 109118611Snjl * U.S. Export Administration Regulations. Licensee agrees that neither it nor 110118611Snjl * any of its subsidiaries will export/re-export any technical data, process, 111118611Snjl * software, or service, directly or indirectly, to any country for which the 112118611Snjl * United States government or any agency thereof requires an export license, 113118611Snjl * other governmental approval, or letter of assurance, without first obtaining 114118611Snjl * such license, approval or letter. 115118611Snjl * 116118611Snjl *****************************************************************************/ 117118611Snjl 118118611Snjl#include <stdio.h> 119118611Snjl#include "aslcompiler.h" 120118611Snjl 121118611Snjl#define _COMPONENT ACPI_COMPILER 122118611Snjl ACPI_MODULE_NAME ("aslcompile") 123118611Snjl 124118611Snjl 125118611Snjl/******************************************************************************* 126118611Snjl * 127118611Snjl * FUNCTION: AslCompilerSignon 128118611Snjl * 129118611Snjl * PARAMETERS: FileId - ID of the output file 130118611Snjl * 131118611Snjl * RETURN: None 132118611Snjl * 133118611Snjl * DESCRIPTION: Display compiler signon 134118611Snjl * 135118611Snjl ******************************************************************************/ 136118611Snjl 137118611Snjlvoid 138118611SnjlAslCompilerSignon ( 139118611Snjl UINT32 FileId) 140118611Snjl{ 141118611Snjl char *Prefix = ""; 142118611Snjl 143118611Snjl 144118611Snjl /* 145118611Snjl * Set line prefix depending on the destination file type 146118611Snjl */ 147118611Snjl switch (FileId) 148118611Snjl { 149118611Snjl case ASL_FILE_ASM_SOURCE_OUTPUT: 150118611Snjl case ASL_FILE_ASM_INCLUDE_OUTPUT: 151118611Snjl 152118611Snjl Prefix = "; "; 153118611Snjl break; 154118611Snjl 155118611Snjl case ASL_FILE_HEX_OUTPUT: 156118611Snjl 157118611Snjl if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) 158118611Snjl { 159118611Snjl Prefix = "; "; 160118611Snjl } 161118611Snjl else if (Gbl_HexOutputFlag == HEX_OUTPUT_C) 162118611Snjl { 163118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n"); 164118611Snjl Prefix = " * "; 165118611Snjl } 166118611Snjl break; 167118611Snjl 168118611Snjl case ASL_FILE_C_SOURCE_OUTPUT: 169118611Snjl case ASL_FILE_C_INCLUDE_OUTPUT: 170118611Snjl 171118611Snjl Prefix = " * "; 172118611Snjl break; 173118611Snjl 174118611Snjl default: 175118611Snjl /* No other output types supported */ 176118611Snjl break; 177118611Snjl } 178118611Snjl 179118611Snjl /* Compiler signon with copyright */ 180118611Snjl 181118611Snjl FlPrintFile (FileId, 182123315Snjl "%s\n%s%s\n%s%s version %X [%s]\n%s%s\n%sSupports ACPI Specification Revision 2.0c\n%s\n", 183118611Snjl Prefix, 184118611Snjl Prefix, IntelAcpiCA, 185118611Snjl Prefix, CompilerId, ACPI_CA_VERSION, __DATE__, 186118611Snjl Prefix, CompilerCopyright, 187118611Snjl Prefix, 188118611Snjl Prefix); 189118611Snjl} 190118611Snjl 191118611Snjl 192118611Snjl/******************************************************************************* 193118611Snjl * 194118611Snjl * FUNCTION: AslCompilerFileHeader 195118611Snjl * 196118611Snjl * PARAMETERS: FileId - ID of the output file 197118611Snjl * 198118611Snjl * RETURN: None 199118611Snjl * 200118611Snjl * DESCRIPTION: Header used at the beginning of output files 201118611Snjl * 202118611Snjl ******************************************************************************/ 203118611Snjl 204118611Snjlvoid 205118611SnjlAslCompilerFileHeader ( 206118611Snjl UINT32 FileId) 207118611Snjl{ 208118611Snjl struct tm *NewTime; 209118611Snjl time_t Aclock; 210118611Snjl char *Prefix = ""; 211118611Snjl 212118611Snjl 213118611Snjl /* 214118611Snjl * Set line prefix depending on the destination file type 215118611Snjl */ 216118611Snjl switch (FileId) 217118611Snjl { 218118611Snjl case ASL_FILE_ASM_SOURCE_OUTPUT: 219118611Snjl case ASL_FILE_ASM_INCLUDE_OUTPUT: 220118611Snjl 221118611Snjl Prefix = "; "; 222118611Snjl break; 223118611Snjl 224118611Snjl case ASL_FILE_HEX_OUTPUT: 225118611Snjl 226118611Snjl if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) 227118611Snjl { 228118611Snjl Prefix = "; "; 229118611Snjl } 230118611Snjl else if (Gbl_HexOutputFlag == HEX_OUTPUT_C) 231118611Snjl { 232118611Snjl Prefix = " * "; 233118611Snjl } 234118611Snjl break; 235118611Snjl 236118611Snjl case ASL_FILE_C_SOURCE_OUTPUT: 237118611Snjl case ASL_FILE_C_INCLUDE_OUTPUT: 238118611Snjl 239118611Snjl Prefix = " * "; 240118611Snjl break; 241118611Snjl 242118611Snjl default: 243118611Snjl /* No other output types supported */ 244118611Snjl break; 245118611Snjl } 246118611Snjl 247118611Snjl /* Compilation header with timestamp */ 248118611Snjl 249118611Snjl (void) time (&Aclock); 250118611Snjl NewTime = localtime (&Aclock); 251118611Snjl 252118611Snjl FlPrintFile (FileId, 253118611Snjl "%sCompilation of \"%s\" - %s%s\n", 254118611Snjl Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime), 255118611Snjl Prefix); 256118611Snjl 257118611Snjl switch (FileId) 258118611Snjl { 259118611Snjl case ASL_FILE_C_SOURCE_OUTPUT: 260118611Snjl case ASL_FILE_C_INCLUDE_OUTPUT: 261118611Snjl FlPrintFile (FileId, " */\n"); 262118611Snjl break; 263118611Snjl 264118611Snjl default: 265118611Snjl /* Nothing to do for other output types */ 266118611Snjl break; 267118611Snjl } 268118611Snjl} 269118611Snjl 270118611Snjl 271118611Snjl/******************************************************************************* 272118611Snjl * 273118611Snjl * FUNCTION: CmFlushSourceCode 274118611Snjl * 275118611Snjl * PARAMETERS: None 276118611Snjl * 277118611Snjl * RETURN: None 278118611Snjl * 279118611Snjl * DESCRIPTION: Read in any remaining source code after the parse tree 280118611Snjl * has been constructed. 281118611Snjl * 282118611Snjl ******************************************************************************/ 283118611Snjl 284118611Snjlvoid 285118611SnjlCmFlushSourceCode (void) 286118611Snjl{ 287118611Snjl char Buffer; 288118611Snjl 289118611Snjl 290118611Snjl while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR) 291118611Snjl { 292118611Snjl InsertLineBuffer ((int) Buffer); 293118611Snjl } 294118611Snjl 295118611Snjl ResetCurrentLineBuffer (); 296118611Snjl} 297118611Snjl 298118611Snjl 299118611Snjl/******************************************************************************* 300118611Snjl * 301123315Snjl * FUNCTION: FlCheckForAscii 302123315Snjl * 303123315Snjl * PARAMETERS: FileInfo - Points to an open input file 304123315Snjl * 305123315Snjl * RETURN: Status (0 = OK) 306123315Snjl * 307123315Snjl * DESCRIPTION: Verify that the input file is entirely ASCII. 308123315Snjl * 309123315Snjl ******************************************************************************/ 310123315Snjl 311123315SnjlACPI_STATUS 312123315SnjlFlCheckForAscii ( 313123315Snjl ASL_FILE_INFO *FileInfo) 314123315Snjl{ 315123315Snjl UINT8 Byte; 316123315Snjl ACPI_SIZE BadBytes = 0; 317123315Snjl ACPI_SIZE Offset = 0; 318123315Snjl 319123315Snjl 320123315Snjl /* Read the entire file */ 321123315Snjl 322123315Snjl while (fread (&Byte, 1, 1, FileInfo->Handle)) 323123315Snjl { 324123315Snjl /* Check for an ASCII character */ 325123315Snjl 326123315Snjl if (!isascii (Byte)) 327123315Snjl { 328123315Snjl if (BadBytes < 10) 329123315Snjl { 330123315Snjl AcpiOsPrintf ("Non-ASCII character: 0x%2.2X at offset 0x%X\n", Byte, Offset); 331123315Snjl } 332123315Snjl BadBytes++; 333123315Snjl } 334123315Snjl Offset++; 335123315Snjl } 336123315Snjl 337123315Snjl /* Were there any non-ASCII characters in the file? */ 338123315Snjl 339123315Snjl if (BadBytes) 340123315Snjl { 341123315Snjl AcpiOsPrintf ("%d non-ASCII characters found in input file, appears to be binary\n", BadBytes); 342123315Snjl AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, FileInfo->Filename); 343123315Snjl return (AE_BAD_CHARACTER); 344123315Snjl } 345123315Snjl 346123315Snjl /* File is OK, seek back to the beginning */ 347123315Snjl 348123315Snjl fseek (FileInfo->Handle, 0, SEEK_SET); 349123315Snjl return (AE_OK); 350123315Snjl} 351123315Snjl 352123315Snjl 353123315Snjl/******************************************************************************* 354123315Snjl * 355118611Snjl * FUNCTION: CmDoCompile 356118611Snjl * 357118611Snjl * PARAMETERS: None 358118611Snjl * 359118611Snjl * RETURN: Status (0 = OK) 360118611Snjl * 361118611Snjl * DESCRIPTION: This procedure performs the entire compile 362118611Snjl * 363118611Snjl ******************************************************************************/ 364118611Snjl 365118611Snjlint 366118611SnjlCmDoCompile (void) 367118611Snjl{ 368118611Snjl ACPI_STATUS Status; 369118611Snjl UINT32 i = 0; 370118611Snjl 371118611Snjl 372118611Snjl UtBeginEvent (12, "Total Compile time"); 373118611Snjl UtBeginEvent (i, "Initialize"); 374118611Snjl 375118611Snjl /* Open the required input and output files */ 376118611Snjl 377118611Snjl Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename); 378118611Snjl if (ACPI_FAILURE (Status)) 379118611Snjl { 380118611Snjl AePrintErrorLog (ASL_FILE_STDERR); 381118611Snjl return -1; 382118611Snjl } 383118611Snjl 384123315Snjl /* Ensure that the input file is 100% ASCII text */ 385123315Snjl 386123315Snjl Status = FlCheckForAscii (&Gbl_Files[ASL_FILE_INPUT]); 387123315Snjl if (ACPI_FAILURE (Status)) 388123315Snjl { 389123315Snjl AePrintErrorLog (ASL_FILE_STDERR); 390123315Snjl return -1; 391123315Snjl } 392123315Snjl 393118611Snjl Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix); 394118611Snjl if (ACPI_FAILURE (Status)) 395118611Snjl { 396118611Snjl AePrintErrorLog (ASL_FILE_STDERR); 397118611Snjl return -1; 398118611Snjl } 399118611Snjl 400118611Snjl UtEndEvent (i++); 401118611Snjl 402118611Snjl /* Build the parse tree */ 403118611Snjl 404118611Snjl UtBeginEvent (i, "Parse source code and build parse tree"); 405118611Snjl AslCompilerparse(); 406118611Snjl UtEndEvent (i++); 407118611Snjl 408118611Snjl /* Flush out any remaining source after parse tree is complete */ 409118611Snjl 410118611Snjl CmFlushSourceCode (); 411118611Snjl 412118611Snjl /* Did the parse tree get successfully constructed? */ 413118611Snjl 414118611Snjl if (!RootNode) 415118611Snjl { 416118611Snjl CmCleanupAndExit (); 417118611Snjl return -1; 418118611Snjl } 419118611Snjl 420118611Snjl OpcGetIntegerWidth (RootNode); 421118611Snjl 422118611Snjl /* Pre-process parse tree for any operator transforms */ 423118611Snjl 424118611Snjl UtBeginEvent (i, "Generate AML opcodes"); 425118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n"); 426118611Snjl TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, TrAmlTransformWalk, NULL, NULL); 427118611Snjl 428118611Snjl /* Generate AML opcodes corresponding to the parse tokens */ 429118611Snjl 430118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n"); 431118611Snjl TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, OpcAmlOpcodeWalk, NULL); 432118611Snjl UtEndEvent (i++); 433118611Snjl 434118611Snjl /* 435118611Snjl * Now that the input is parsed, we can open the AML output file. 436118611Snjl * Note: by default, the name of this file comes from the table descriptor 437118611Snjl * within the input file. 438118611Snjl */ 439118611Snjl Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix); 440118611Snjl if (ACPI_FAILURE (Status)) 441118611Snjl { 442118611Snjl AePrintErrorLog (ASL_FILE_STDERR); 443118611Snjl return -1; 444118611Snjl } 445118611Snjl 446118611Snjl /* Interpret and generate all compile-time constants */ 447118611Snjl 448118611Snjl UtBeginEvent (i, "Constant folding via AML interpreter"); 449118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nInterpreting compile-time constant expressions\n\n"); 450118611Snjl TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, OpcAmlConstantWalk, NULL, NULL); 451118611Snjl UtEndEvent (i++); 452118611Snjl 453118611Snjl /* Calculate all AML package lengths */ 454118611Snjl 455118611Snjl UtBeginEvent (i, "Generate AML package lengths"); 456118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 457118611Snjl TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, LnPackageLengthWalk, NULL); 458118611Snjl UtEndEvent (i++); 459118611Snjl 460118611Snjl if (Gbl_ParseOnlyFlag) 461118611Snjl { 462118611Snjl AePrintErrorLog (ASL_FILE_STDOUT); 463118611Snjl UtDisplaySummary (ASL_FILE_STDOUT); 464118611Snjl if (Gbl_DebugFlag) 465118611Snjl { 466118611Snjl /* Print error summary to the debug file */ 467118611Snjl 468118611Snjl AePrintErrorLog (ASL_FILE_STDERR); 469118611Snjl UtDisplaySummary (ASL_FILE_STDERR); 470118611Snjl } 471118611Snjl return 0; 472118611Snjl } 473118611Snjl 474118611Snjl /* 475118611Snjl * Create an internal namespace and use it as a symbol table 476118611Snjl */ 477118611Snjl 478118611Snjl /* Namespace loading */ 479118611Snjl 480118611Snjl UtBeginEvent (i, "Create ACPI Namespace"); 481118611Snjl Status = LdLoadNamespace (RootNode); 482118611Snjl UtEndEvent (i++); 483118611Snjl if (ACPI_FAILURE (Status)) 484118611Snjl { 485118611Snjl return -1; 486118611Snjl } 487118611Snjl 488118611Snjl /* Namespace lookup */ 489118611Snjl 490118611Snjl UtBeginEvent (i, "Cross reference parse tree and Namespace"); 491118611Snjl Status = LkCrossReferenceNamespace (); 492118611Snjl UtEndEvent (i++); 493118611Snjl UtEndEvent (i++); 494118611Snjl if (ACPI_FAILURE (Status)) 495118611Snjl { 496118611Snjl return -1; 497118611Snjl } 498118611Snjl 499118611Snjl /* 500118611Snjl * Semantic analysis. This can happen only after the 501118611Snjl * namespace has been loaded and cross-referenced. 502118611Snjl * 503118611Snjl * part one - check control methods 504118611Snjl */ 505118611Snjl UtBeginEvent (i, "Analyze control method return types"); 506118611Snjl AnalysisWalkInfo.MethodStack = NULL; 507118611Snjl 508118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n"); 509118611Snjl TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, AnMethodAnalysisWalkBegin, 510118611Snjl AnMethodAnalysisWalkEnd, &AnalysisWalkInfo); 511118611Snjl UtEndEvent (i++); 512118611Snjl 513118611Snjl /* Semantic error checking part two - typing of method returns */ 514118611Snjl 515118611Snjl UtBeginEvent (i, "Determine object types returned by methods"); 516118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing \n\n"); 517118611Snjl TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, AnMethodTypingWalkBegin, 518118611Snjl AnMethodTypingWalkEnd, NULL); 519118611Snjl UtEndEvent (i++); 520118611Snjl 521118611Snjl /* Semantic error checking part three - operand type checking */ 522118611Snjl 523118611Snjl UtBeginEvent (i, "Analyze AML operand types"); 524118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking \n\n"); 525118611Snjl TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, AnOperandTypecheckWalkBegin, 526118611Snjl AnOperandTypecheckWalkEnd, &AnalysisWalkInfo); 527118611Snjl UtEndEvent (i++); 528118611Snjl 529118611Snjl /* Semantic error checking part four - other miscellaneous checks */ 530118611Snjl 531118611Snjl UtBeginEvent (i, "Miscellaneous analysis"); 532118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous \n\n"); 533118611Snjl TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, AnOtherSemanticAnalysisWalkBegin, 534118611Snjl AnOtherSemanticAnalysisWalkEnd, &AnalysisWalkInfo); 535118611Snjl UtEndEvent (i++); 536118611Snjl 537118611Snjl /* Calculate all AML package lengths */ 538118611Snjl 539118611Snjl UtBeginEvent (i, "Finish AML package length generation"); 540118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 541118611Snjl TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, LnInitLengthsWalk, NULL); 542118611Snjl TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, LnPackageLengthWalk, NULL); 543118611Snjl UtEndEvent (i++); 544118611Snjl 545118611Snjl 546118611Snjl /* Code generation - emit the AML */ 547118611Snjl 548118611Snjl UtBeginEvent (i, "Generate AML code and write output files"); 549118611Snjl CgGenerateAmlOutput (); 550118611Snjl UtEndEvent (i++); 551118611Snjl 552118611Snjl UtBeginEvent (i, "Write optional output files"); 553118611Snjl CmDoOutputFiles (); 554118611Snjl UtEndEvent (i++); 555118611Snjl 556118611Snjl UtEndEvent (13); 557118611Snjl CmCleanupAndExit (); 558118611Snjl return 0; 559118611Snjl} 560118611Snjl 561118611Snjlvoid 562118611SnjlCmDoOutputFiles (void) 563118611Snjl{ 564118611Snjl 565118611Snjl /* Create listings and hex files */ 566118611Snjl 567118611Snjl LsDoListings (); 568118611Snjl LsDoHexOutput (); 569118611Snjl 570118611Snjl /* Dump the namespace to the .nsp file if requested */ 571118611Snjl 572118611Snjl LsDisplayNamespace (); 573118611Snjl} 574118611Snjl 575118611Snjl 576118611Snjl/******************************************************************************* 577118611Snjl * 578118611Snjl * FUNCTION: CmCleanupAndExit 579118611Snjl * 580118611Snjl * PARAMETERS: None 581118611Snjl * 582118611Snjl * RETURN: None. 583118611Snjl * 584118611Snjl * DESCRIPTION: Close all open files and exit the compiler 585118611Snjl * 586118611Snjl ******************************************************************************/ 587118611Snjl 588118611Snjlvoid 589118611SnjlCmCleanupAndExit (void) 590118611Snjl{ 591118611Snjl UINT32 i; 592118611Snjl 593118611Snjl 594118611Snjl AePrintErrorLog (ASL_FILE_STDOUT); 595118611Snjl if (Gbl_DebugFlag) 596118611Snjl { 597118611Snjl /* Print error summary to the debug file */ 598118611Snjl 599118611Snjl AePrintErrorLog (ASL_FILE_STDERR); 600118611Snjl } 601118611Snjl 602118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n"); 603118611Snjl for (i = 0; i < 13; i++) 604118611Snjl { 605118611Snjl if (AslGbl_Events[i].Valid) 606118611Snjl { 607118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "%8lu ms - %s\n", 608118611Snjl AslGbl_Events[i].EndTime - 609118611Snjl AslGbl_Events[i].StartTime, 610118611Snjl AslGbl_Events[i].EventName); 611118611Snjl } 612118611Snjl } 613118611Snjl 614118611Snjl if (Gbl_CompileTimesFlag) 615118611Snjl { 616118611Snjl printf ("\nElapsed time for major events\n\n"); 617118611Snjl for (i = 0; i < 13; i++) 618118611Snjl { 619118611Snjl if (AslGbl_Events[i].Valid) 620118611Snjl { 621118611Snjl printf ("%8lu ms : %s\n", 622118611Snjl AslGbl_Events[i].EndTime - 623118611Snjl AslGbl_Events[i].StartTime, 624118611Snjl AslGbl_Events[i].EventName); 625118611Snjl } 626118611Snjl } 627118611Snjl printf ("\nMiscellaneous compile statistics\n\n"); 628118611Snjl printf ("%11u : %s\n", TotalParseNodes, "Parse nodes"); 629118611Snjl printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches"); 630118611Snjl printf ("%11u : %s\n", TotalNamedObjects, "Named objects"); 631118611Snjl printf ("%11u : %s\n", TotalMethods, "Control methods"); 632118611Snjl printf ("%11u : %s\n", TotalAllocations, "Memory Allocations"); 633118611Snjl printf ("%11u : %s\n", TotalAllocated, "Total allocated memory"); 634118611Snjl printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded"); 635118611Snjl printf ("\n"); 636118611Snjl } 637118611Snjl 638118611Snjl if (Gbl_NsLookupCount) 639118611Snjl { 640118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\n\nMiscellaneous compile statistics\n\n"); 641118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "%32s : %d\n", "Total Namespace searches", Gbl_NsLookupCount); 642118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "%32s : %d\n", "Time per search", 643118611Snjl ((UINT32) (AslGbl_Events[7].EndTime - AslGbl_Events[7].StartTime) * 1000) / 644118611Snjl Gbl_NsLookupCount); 645118611Snjl } 646118611Snjl 647118611Snjl /* Close all open files */ 648118611Snjl 649118611Snjl for (i = 2; i < ASL_MAX_FILE_TYPE; i++) 650118611Snjl { 651118611Snjl FlCloseFile (i); 652118611Snjl } 653118611Snjl 654118611Snjl /* 655118611Snjl * TBD: SourceOutput should be .TMP, then rename if we want to keep it? 656118611Snjl */ 657118611Snjl if (!Gbl_SourceOutputFlag) 658118611Snjl { 659118611Snjl unlink (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename); 660118611Snjl } 661118611Snjl 662118611Snjl /* Delete AML file if there are errors */ 663118611Snjl 664118611Snjl if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors)) 665118611Snjl { 666118611Snjl unlink (Gbl_Files[ASL_FILE_AML_OUTPUT].Filename); 667118611Snjl } 668118611Snjl 669118611Snjl if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) 670118611Snjl { 671118611Snjl printf ("\nMaximum error count (%d) exceeded.\n", ASL_MAX_ERROR_COUNT); 672118611Snjl } 673118611Snjl 674118611Snjl UtDisplaySummary (ASL_FILE_STDOUT); 675118611Snjl exit (0); 676118611Snjl} 677118611Snjl 678118611Snjl 679