aslcompile.c revision 209746
1118611Snjl 2118611Snjl/****************************************************************************** 3118611Snjl * 4118611Snjl * Module Name: aslcompile - top level compile module 5118611Snjl * 6118611Snjl *****************************************************************************/ 7118611Snjl 8118611Snjl/****************************************************************************** 9118611Snjl * 10118611Snjl * 1. Copyright Notice 11118611Snjl * 12202771Sjkim * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. 13118611Snjl * All rights reserved. 14118611Snjl * 15118611Snjl * 2. License 16118611Snjl * 17118611Snjl * 2.1. This is your license from Intel Corp. under its intellectual property 18118611Snjl * rights. You may have additional license terms from the party that provided 19118611Snjl * you this software, covering your right to use that party's intellectual 20118611Snjl * property rights. 21118611Snjl * 22118611Snjl * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23118611Snjl * copy of the source code appearing in this file ("Covered Code") an 24118611Snjl * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25118611Snjl * base code distributed originally by Intel ("Original Intel Code") to copy, 26118611Snjl * make derivatives, distribute, use and display any portion of the Covered 27118611Snjl * Code in any form, with the right to sublicense such rights; and 28118611Snjl * 29118611Snjl * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30118611Snjl * license (with the right to sublicense), under only those claims of Intel 31118611Snjl * patents that are infringed by the Original Intel Code, to make, use, sell, 32118611Snjl * offer to sell, and import the Covered Code and derivative works thereof 33118611Snjl * solely to the minimum extent necessary to exercise the above copyright 34118611Snjl * license, and in no event shall the patent license extend to any additions 35118611Snjl * to or modifications of the Original Intel Code. No other license or right 36118611Snjl * is granted directly or by implication, estoppel or otherwise; 37118611Snjl * 38118611Snjl * The above copyright and patent license is granted only if the following 39118611Snjl * conditions are met: 40118611Snjl * 41118611Snjl * 3. Conditions 42118611Snjl * 43118611Snjl * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44118611Snjl * Redistribution of source code of any substantial portion of the Covered 45118611Snjl * Code or modification with rights to further distribute source must include 46118611Snjl * the above Copyright Notice, the above License, this list of Conditions, 47118611Snjl * and the following Disclaimer and Export Compliance provision. In addition, 48118611Snjl * Licensee must cause all Covered Code to which Licensee contributes to 49118611Snjl * contain a file documenting the changes Licensee made to create that Covered 50118611Snjl * Code and the date of any change. Licensee must include in that file the 51118611Snjl * documentation of any changes made by any predecessor Licensee. Licensee 52118611Snjl * must include a prominent statement that the modification is derived, 53118611Snjl * directly or indirectly, from Original Intel Code. 54118611Snjl * 55118611Snjl * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56118611Snjl * Redistribution of source code of any substantial portion of the Covered 57118611Snjl * Code or modification without rights to further distribute source must 58118611Snjl * include the following Disclaimer and Export Compliance provision in the 59118611Snjl * documentation and/or other materials provided with distribution. In 60118611Snjl * addition, Licensee may not authorize further sublicense of source of any 61118611Snjl * portion of the Covered Code, and must include terms to the effect that the 62118611Snjl * license from Licensee to its licensee is limited to the intellectual 63118611Snjl * property embodied in the software Licensee provides to its licensee, and 64118611Snjl * not to intellectual property embodied in modifications its licensee may 65118611Snjl * make. 66118611Snjl * 67118611Snjl * 3.3. Redistribution of Executable. Redistribution in executable form of any 68118611Snjl * substantial portion of the Covered Code or modification must reproduce the 69118611Snjl * above Copyright Notice, and the following Disclaimer and Export Compliance 70118611Snjl * provision in the documentation and/or other materials provided with the 71118611Snjl * distribution. 72118611Snjl * 73118611Snjl * 3.4. Intel retains all right, title, and interest in and to the Original 74118611Snjl * Intel Code. 75118611Snjl * 76118611Snjl * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77118611Snjl * Intel shall be used in advertising or otherwise to promote the sale, use or 78118611Snjl * other dealings in products derived from or relating to the Covered Code 79118611Snjl * without prior written authorization from Intel. 80118611Snjl * 81118611Snjl * 4. Disclaimer and Export Compliance 82118611Snjl * 83118611Snjl * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84118611Snjl * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85118611Snjl * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86118611Snjl * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87118611Snjl * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88118611Snjl * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89118611Snjl * PARTICULAR PURPOSE. 90118611Snjl * 91118611Snjl * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92118611Snjl * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93118611Snjl * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94118611Snjl * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95118611Snjl * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96118611Snjl * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97118611Snjl * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98118611Snjl * LIMITED REMEDY. 99118611Snjl * 100118611Snjl * 4.3. Licensee shall not export, either directly or indirectly, any of this 101118611Snjl * software or system incorporating such software without first obtaining any 102118611Snjl * required license or other approval from the U. S. Department of Commerce or 103118611Snjl * any other agency or department of the United States Government. In the 104118611Snjl * event Licensee exports any such software from the United States or 105118611Snjl * re-exports any such software from a foreign destination, Licensee shall 106118611Snjl * ensure that the distribution and export/re-export of the software is in 107118611Snjl * compliance with all laws, regulations, orders, or other restrictions of the 108118611Snjl * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109118611Snjl * any of its subsidiaries will export/re-export any technical data, process, 110118611Snjl * software, or service, directly or indirectly, to any country for which the 111118611Snjl * United States government or any agency thereof requires an export license, 112118611Snjl * other governmental approval, or letter of assurance, without first obtaining 113118611Snjl * such license, approval or letter. 114118611Snjl * 115118611Snjl *****************************************************************************/ 116118611Snjl 117118611Snjl#include <stdio.h> 118151937Sjkim#include <time.h> 119151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 120118611Snjl 121118611Snjl#define _COMPONENT ACPI_COMPILER 122118611Snjl ACPI_MODULE_NAME ("aslcompile") 123118611Snjl 124151937Sjkim/* Local prototypes */ 125118611Snjl 126151937Sjkimstatic void 127151937SjkimCmFlushSourceCode ( 128151937Sjkim void); 129151937Sjkim 130193529Sjkimvoid 131193529SjkimFlConsumeAnsiComment ( 132193529Sjkim ASL_FILE_INFO *FileInfo, 133193529Sjkim ASL_FILE_STATUS *Status); 134151937Sjkim 135193529Sjkimvoid 136193529SjkimFlConsumeNewComment ( 137193529Sjkim ASL_FILE_INFO *FileInfo, 138193529Sjkim ASL_FILE_STATUS *Status); 139193529Sjkim 140193529Sjkim 141118611Snjl/******************************************************************************* 142118611Snjl * 143118611Snjl * FUNCTION: AslCompilerSignon 144118611Snjl * 145118611Snjl * PARAMETERS: FileId - ID of the output file 146118611Snjl * 147118611Snjl * RETURN: None 148118611Snjl * 149118611Snjl * DESCRIPTION: Display compiler signon 150118611Snjl * 151118611Snjl ******************************************************************************/ 152118611Snjl 153118611Snjlvoid 154118611SnjlAslCompilerSignon ( 155118611Snjl UINT32 FileId) 156118611Snjl{ 157118611Snjl char *Prefix = ""; 158118611Snjl 159118611Snjl 160151937Sjkim /* Set line prefix depending on the destination file type */ 161151937Sjkim 162118611Snjl switch (FileId) 163118611Snjl { 164118611Snjl case ASL_FILE_ASM_SOURCE_OUTPUT: 165118611Snjl case ASL_FILE_ASM_INCLUDE_OUTPUT: 166118611Snjl 167118611Snjl Prefix = "; "; 168118611Snjl break; 169118611Snjl 170118611Snjl case ASL_FILE_HEX_OUTPUT: 171118611Snjl 172118611Snjl if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) 173118611Snjl { 174118611Snjl Prefix = "; "; 175118611Snjl } 176207344Sjkim else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) || 177207344Sjkim (Gbl_HexOutputFlag == HEX_OUTPUT_ASL)) 178118611Snjl { 179118611Snjl FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n"); 180118611Snjl Prefix = " * "; 181118611Snjl } 182118611Snjl break; 183118611Snjl 184118611Snjl case ASL_FILE_C_SOURCE_OUTPUT: 185118611Snjl case ASL_FILE_C_INCLUDE_OUTPUT: 186118611Snjl 187118611Snjl Prefix = " * "; 188118611Snjl break; 189118611Snjl 190118611Snjl default: 191118611Snjl /* No other output types supported */ 192118611Snjl break; 193118611Snjl } 194118611Snjl 195151937Sjkim /* 196151937Sjkim * Compiler signon with copyright 197151937Sjkim */ 198118611Snjl FlPrintFile (FileId, 199151937Sjkim "%s\n%s%s\n%s", 200118611Snjl Prefix, 201118611Snjl Prefix, IntelAcpiCA, 202151937Sjkim Prefix); 203151937Sjkim 204151937Sjkim /* Running compiler or disassembler? */ 205151937Sjkim 206151937Sjkim if (Gbl_DisasmFlag) 207151937Sjkim { 208151937Sjkim FlPrintFile (FileId, 209151937Sjkim "%s", DisassemblerId); 210151937Sjkim } 211151937Sjkim else 212151937Sjkim { 213151937Sjkim FlPrintFile (FileId, 214151937Sjkim "%s", CompilerId); 215151937Sjkim } 216151937Sjkim 217195626Scperciva /* Version, copyright, compliance */ 218151937Sjkim 219151937Sjkim FlPrintFile (FileId, 220195626Scperciva " version %X\n%s%s\n%s%s\n%s\n", 221195626Scperciva (UINT32) ACPI_CA_VERSION, 222118611Snjl Prefix, CompilerCopyright, 223151937Sjkim Prefix, CompilerCompliance, 224118611Snjl Prefix); 225118611Snjl} 226118611Snjl 227118611Snjl 228118611Snjl/******************************************************************************* 229118611Snjl * 230118611Snjl * FUNCTION: AslCompilerFileHeader 231118611Snjl * 232118611Snjl * PARAMETERS: FileId - ID of the output file 233118611Snjl * 234118611Snjl * RETURN: None 235118611Snjl * 236118611Snjl * DESCRIPTION: Header used at the beginning of output files 237118611Snjl * 238118611Snjl ******************************************************************************/ 239118611Snjl 240118611Snjlvoid 241118611SnjlAslCompilerFileHeader ( 242118611Snjl UINT32 FileId) 243118611Snjl{ 244118611Snjl struct tm *NewTime; 245118611Snjl time_t Aclock; 246118611Snjl char *Prefix = ""; 247118611Snjl 248118611Snjl 249151937Sjkim /* Set line prefix depending on the destination file type */ 250151937Sjkim 251118611Snjl switch (FileId) 252118611Snjl { 253118611Snjl case ASL_FILE_ASM_SOURCE_OUTPUT: 254118611Snjl case ASL_FILE_ASM_INCLUDE_OUTPUT: 255118611Snjl 256118611Snjl Prefix = "; "; 257118611Snjl break; 258118611Snjl 259118611Snjl case ASL_FILE_HEX_OUTPUT: 260118611Snjl 261118611Snjl if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) 262118611Snjl { 263118611Snjl Prefix = "; "; 264118611Snjl } 265207344Sjkim else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) || 266207344Sjkim (Gbl_HexOutputFlag == HEX_OUTPUT_ASL)) 267118611Snjl { 268118611Snjl Prefix = " * "; 269118611Snjl } 270118611Snjl break; 271118611Snjl 272118611Snjl case ASL_FILE_C_SOURCE_OUTPUT: 273118611Snjl case ASL_FILE_C_INCLUDE_OUTPUT: 274118611Snjl 275118611Snjl Prefix = " * "; 276118611Snjl break; 277118611Snjl 278118611Snjl default: 279118611Snjl /* No other output types supported */ 280118611Snjl break; 281118611Snjl } 282118611Snjl 283118611Snjl /* Compilation header with timestamp */ 284118611Snjl 285118611Snjl (void) time (&Aclock); 286118611Snjl NewTime = localtime (&Aclock); 287118611Snjl 288118611Snjl FlPrintFile (FileId, 289118611Snjl "%sCompilation of \"%s\" - %s%s\n", 290118611Snjl Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime), 291118611Snjl Prefix); 292118611Snjl 293118611Snjl switch (FileId) 294118611Snjl { 295118611Snjl case ASL_FILE_C_SOURCE_OUTPUT: 296118611Snjl case ASL_FILE_C_INCLUDE_OUTPUT: 297118611Snjl FlPrintFile (FileId, " */\n"); 298118611Snjl break; 299118611Snjl 300118611Snjl default: 301118611Snjl /* Nothing to do for other output types */ 302118611Snjl break; 303118611Snjl } 304118611Snjl} 305118611Snjl 306118611Snjl 307118611Snjl/******************************************************************************* 308118611Snjl * 309118611Snjl * FUNCTION: CmFlushSourceCode 310118611Snjl * 311118611Snjl * PARAMETERS: None 312118611Snjl * 313118611Snjl * RETURN: None 314118611Snjl * 315118611Snjl * DESCRIPTION: Read in any remaining source code after the parse tree 316118611Snjl * has been constructed. 317118611Snjl * 318118611Snjl ******************************************************************************/ 319118611Snjl 320151937Sjkimstatic void 321151937SjkimCmFlushSourceCode ( 322151937Sjkim void) 323118611Snjl{ 324118611Snjl char Buffer; 325118611Snjl 326118611Snjl 327118611Snjl while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR) 328118611Snjl { 329118611Snjl InsertLineBuffer ((int) Buffer); 330118611Snjl } 331118611Snjl 332118611Snjl ResetCurrentLineBuffer (); 333118611Snjl} 334118611Snjl 335118611Snjl 336118611Snjl/******************************************************************************* 337118611Snjl * 338167802Sjkim * FUNCTION: FlConsume* 339167802Sjkim * 340167802Sjkim * PARAMETERS: FileInfo - Points to an open input file 341167802Sjkim * 342167802Sjkim * RETURN: Number of lines consumed 343167802Sjkim * 344167802Sjkim * DESCRIPTION: Step over both types of comment during check for ascii chars 345167802Sjkim * 346167802Sjkim ******************************************************************************/ 347167802Sjkim 348167802Sjkimvoid 349167802SjkimFlConsumeAnsiComment ( 350167802Sjkim ASL_FILE_INFO *FileInfo, 351167802Sjkim ASL_FILE_STATUS *Status) 352167802Sjkim{ 353167802Sjkim UINT8 Byte; 354167802Sjkim BOOLEAN ClosingComment = FALSE; 355167802Sjkim 356167802Sjkim 357167802Sjkim while (fread (&Byte, 1, 1, FileInfo->Handle)) 358167802Sjkim { 359167802Sjkim /* Scan until comment close is found */ 360167802Sjkim 361167802Sjkim if (ClosingComment) 362167802Sjkim { 363167802Sjkim if (Byte == '/') 364167802Sjkim { 365167802Sjkim return; 366167802Sjkim } 367167802Sjkim 368167802Sjkim if (Byte != '*') 369167802Sjkim { 370167802Sjkim /* Reset */ 371167802Sjkim 372167802Sjkim ClosingComment = FALSE; 373167802Sjkim } 374167802Sjkim } 375167802Sjkim else if (Byte == '*') 376167802Sjkim { 377167802Sjkim ClosingComment = TRUE; 378167802Sjkim } 379167802Sjkim 380167802Sjkim /* Maintain line count */ 381167802Sjkim 382167802Sjkim if (Byte == 0x0A) 383167802Sjkim { 384167802Sjkim Status->Line++; 385167802Sjkim } 386167802Sjkim 387167802Sjkim Status->Offset++; 388167802Sjkim } 389167802Sjkim} 390167802Sjkim 391167802Sjkim 392167802Sjkimvoid 393167802SjkimFlConsumeNewComment ( 394167802Sjkim ASL_FILE_INFO *FileInfo, 395167802Sjkim ASL_FILE_STATUS *Status) 396167802Sjkim{ 397167802Sjkim UINT8 Byte; 398167802Sjkim 399167802Sjkim 400167802Sjkim while (fread (&Byte, 1, 1, FileInfo->Handle)) 401167802Sjkim { 402167802Sjkim Status->Offset++; 403167802Sjkim 404167802Sjkim /* Comment ends at newline */ 405167802Sjkim 406167802Sjkim if (Byte == 0x0A) 407167802Sjkim { 408167802Sjkim Status->Line++; 409167802Sjkim return; 410167802Sjkim } 411167802Sjkim } 412167802Sjkim} 413167802Sjkim 414167802Sjkim 415167802Sjkim/******************************************************************************* 416167802Sjkim * 417123315Snjl * FUNCTION: FlCheckForAscii 418123315Snjl * 419123315Snjl * PARAMETERS: FileInfo - Points to an open input file 420123315Snjl * 421151937Sjkim * RETURN: Status 422123315Snjl * 423167802Sjkim * DESCRIPTION: Verify that the input file is entirely ASCII. Ignores characters 424167802Sjkim * within comments. Note: does not handle nested comments and does 425167802Sjkim * not handle comment delimiters within string literals. However, 426167802Sjkim * on the rare chance this happens and an invalid character is 427167802Sjkim * missed, the parser will catch the error by failing in some 428167802Sjkim * spectactular manner. 429123315Snjl * 430123315Snjl ******************************************************************************/ 431123315Snjl 432209746SjkimACPI_STATUS 433123315SnjlFlCheckForAscii ( 434123315Snjl ASL_FILE_INFO *FileInfo) 435123315Snjl{ 436123315Snjl UINT8 Byte; 437123315Snjl ACPI_SIZE BadBytes = 0; 438167802Sjkim BOOLEAN OpeningComment = FALSE; 439167802Sjkim ASL_FILE_STATUS Status; 440123315Snjl 441123315Snjl 442167802Sjkim Status.Line = 1; 443167802Sjkim Status.Offset = 0; 444167802Sjkim 445123315Snjl /* Read the entire file */ 446123315Snjl 447123315Snjl while (fread (&Byte, 1, 1, FileInfo->Handle)) 448123315Snjl { 449167802Sjkim /* Ignore comment fields (allow non-ascii within) */ 450167802Sjkim 451167802Sjkim if (OpeningComment) 452167802Sjkim { 453167802Sjkim /* Check for second comment open delimiter */ 454167802Sjkim 455167802Sjkim if (Byte == '*') 456167802Sjkim { 457167802Sjkim FlConsumeAnsiComment (FileInfo, &Status); 458167802Sjkim } 459167802Sjkim 460167802Sjkim if (Byte == '/') 461167802Sjkim { 462167802Sjkim FlConsumeNewComment (FileInfo, &Status); 463167802Sjkim } 464167802Sjkim 465167802Sjkim /* Reset */ 466167802Sjkim 467167802Sjkim OpeningComment = FALSE; 468167802Sjkim } 469167802Sjkim else if (Byte == '/') 470167802Sjkim { 471167802Sjkim OpeningComment = TRUE; 472167802Sjkim } 473167802Sjkim 474123315Snjl /* Check for an ASCII character */ 475123315Snjl 476193529Sjkim if (!ACPI_IS_ASCII (Byte)) 477123315Snjl { 478123315Snjl if (BadBytes < 10) 479123315Snjl { 480151937Sjkim AcpiOsPrintf ( 481167802Sjkim "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n", 482167802Sjkim Byte, Status.Line, Status.Offset); 483123315Snjl } 484167802Sjkim 485123315Snjl BadBytes++; 486123315Snjl } 487167802Sjkim 488167802Sjkim /* Update line counter */ 489167802Sjkim 490167802Sjkim else if (Byte == 0x0A) 491167802Sjkim { 492167802Sjkim Status.Line++; 493167802Sjkim } 494167802Sjkim 495167802Sjkim Status.Offset++; 496123315Snjl } 497123315Snjl 498151937Sjkim /* Seek back to the beginning of the source file */ 499151937Sjkim 500151937Sjkim fseek (FileInfo->Handle, 0, SEEK_SET); 501151937Sjkim 502123315Snjl /* Were there any non-ASCII characters in the file? */ 503123315Snjl 504123315Snjl if (BadBytes) 505123315Snjl { 506151937Sjkim AcpiOsPrintf ( 507167802Sjkim "%u non-ASCII characters found in input source text, could be a binary file\n", 508151937Sjkim BadBytes); 509167802Sjkim AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, FileInfo->Filename); 510123315Snjl return (AE_BAD_CHARACTER); 511123315Snjl } 512123315Snjl 513151937Sjkim /* File is OK */ 514123315Snjl 515123315Snjl return (AE_OK); 516123315Snjl} 517123315Snjl 518123315Snjl 519123315Snjl/******************************************************************************* 520123315Snjl * 521118611Snjl * FUNCTION: CmDoCompile 522118611Snjl * 523118611Snjl * PARAMETERS: None 524118611Snjl * 525118611Snjl * RETURN: Status (0 = OK) 526118611Snjl * 527118611Snjl * DESCRIPTION: This procedure performs the entire compile 528118611Snjl * 529118611Snjl ******************************************************************************/ 530118611Snjl 531118611Snjlint 532151937SjkimCmDoCompile ( 533151937Sjkim void) 534118611Snjl{ 535118611Snjl ACPI_STATUS Status; 536151937Sjkim UINT8 FullCompile; 537151937Sjkim UINT8 Event; 538118611Snjl 539118611Snjl 540151937Sjkim FullCompile = UtBeginEvent ("*** Total Compile time ***"); 541151937Sjkim Event = UtBeginEvent ("Open input and output files"); 542151937Sjkim UtEndEvent (Event); 543118611Snjl 544118611Snjl /* Build the parse tree */ 545118611Snjl 546151937Sjkim Event = UtBeginEvent ("Parse source code and build parse tree"); 547118611Snjl AslCompilerparse(); 548151937Sjkim UtEndEvent (Event); 549118611Snjl 550118611Snjl /* Flush out any remaining source after parse tree is complete */ 551118611Snjl 552151937Sjkim Event = UtBeginEvent ("Flush source input"); 553118611Snjl CmFlushSourceCode (); 554118611Snjl 555118611Snjl /* Did the parse tree get successfully constructed? */ 556118611Snjl 557118611Snjl if (!RootNode) 558118611Snjl { 559118611Snjl CmCleanupAndExit (); 560118611Snjl return -1; 561118611Snjl } 562118611Snjl 563167802Sjkim /* Optional parse tree dump, compiler debug output only */ 564167802Sjkim 565167802Sjkim LsDumpParseTree (); 566167802Sjkim 567118611Snjl OpcGetIntegerWidth (RootNode); 568151937Sjkim UtEndEvent (Event); 569118611Snjl 570118611Snjl /* Pre-process parse tree for any operator transforms */ 571118611Snjl 572151937Sjkim Event = UtBeginEvent ("Parse tree transforms"); 573118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n"); 574151937Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 575151937Sjkim TrAmlTransformWalk, NULL, NULL); 576151937Sjkim UtEndEvent (Event); 577118611Snjl 578118611Snjl /* Generate AML opcodes corresponding to the parse tokens */ 579118611Snjl 580151937Sjkim Event = UtBeginEvent ("Generate AML opcodes"); 581118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n"); 582151937Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 583151937Sjkim OpcAmlOpcodeWalk, NULL); 584151937Sjkim UtEndEvent (Event); 585118611Snjl 586118611Snjl /* 587118611Snjl * Now that the input is parsed, we can open the AML output file. 588118611Snjl * Note: by default, the name of this file comes from the table descriptor 589118611Snjl * within the input file. 590118611Snjl */ 591151937Sjkim Event = UtBeginEvent ("Open AML output file"); 592118611Snjl Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix); 593118611Snjl if (ACPI_FAILURE (Status)) 594118611Snjl { 595118611Snjl AePrintErrorLog (ASL_FILE_STDERR); 596118611Snjl return -1; 597118611Snjl } 598151937Sjkim UtEndEvent (Event); 599118611Snjl 600118611Snjl /* Interpret and generate all compile-time constants */ 601118611Snjl 602151937Sjkim Event = UtBeginEvent ("Constant folding via AML interpreter"); 603151937Sjkim DbgPrint (ASL_DEBUG_OUTPUT, 604151937Sjkim "\nInterpreting compile-time constant expressions\n\n"); 605151937Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 606151937Sjkim OpcAmlConstantWalk, NULL, NULL); 607151937Sjkim UtEndEvent (Event); 608118611Snjl 609151937Sjkim /* Update AML opcodes if necessary, after constant folding */ 610151937Sjkim 611151937Sjkim Event = UtBeginEvent ("Updating AML opcodes after constant folding"); 612151937Sjkim DbgPrint (ASL_DEBUG_OUTPUT, 613151937Sjkim "\nUpdating AML opcodes after constant folding\n\n"); 614151937Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, 615151937Sjkim NULL, OpcAmlOpcodeUpdateWalk, NULL); 616151937Sjkim UtEndEvent (Event); 617151937Sjkim 618118611Snjl /* Calculate all AML package lengths */ 619118611Snjl 620151937Sjkim Event = UtBeginEvent ("Generate AML package lengths"); 621118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 622151937Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 623151937Sjkim LnPackageLengthWalk, NULL); 624151937Sjkim UtEndEvent (Event); 625118611Snjl 626118611Snjl if (Gbl_ParseOnlyFlag) 627118611Snjl { 628118611Snjl AePrintErrorLog (ASL_FILE_STDOUT); 629118611Snjl UtDisplaySummary (ASL_FILE_STDOUT); 630118611Snjl if (Gbl_DebugFlag) 631118611Snjl { 632118611Snjl /* Print error summary to the debug file */ 633118611Snjl 634118611Snjl AePrintErrorLog (ASL_FILE_STDERR); 635118611Snjl UtDisplaySummary (ASL_FILE_STDERR); 636118611Snjl } 637118611Snjl return 0; 638118611Snjl } 639118611Snjl 640118611Snjl /* 641118611Snjl * Create an internal namespace and use it as a symbol table 642118611Snjl */ 643118611Snjl 644118611Snjl /* Namespace loading */ 645118611Snjl 646151937Sjkim Event = UtBeginEvent ("Create ACPI Namespace"); 647118611Snjl Status = LdLoadNamespace (RootNode); 648151937Sjkim UtEndEvent (Event); 649118611Snjl if (ACPI_FAILURE (Status)) 650118611Snjl { 651118611Snjl return -1; 652118611Snjl } 653118611Snjl 654167802Sjkim /* Namespace cross-reference */ 655118611Snjl 656151937Sjkim AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace"); 657118611Snjl Status = LkCrossReferenceNamespace (); 658118611Snjl if (ACPI_FAILURE (Status)) 659118611Snjl { 660118611Snjl return -1; 661118611Snjl } 662118611Snjl 663167802Sjkim /* Namespace - Check for non-referenced objects */ 664167802Sjkim 665167802Sjkim LkFindUnreferencedObjects (); 666167802Sjkim UtEndEvent (AslGbl_NamespaceEvent); 667167802Sjkim 668118611Snjl /* 669118611Snjl * Semantic analysis. This can happen only after the 670118611Snjl * namespace has been loaded and cross-referenced. 671118611Snjl * 672118611Snjl * part one - check control methods 673118611Snjl */ 674151937Sjkim Event = UtBeginEvent ("Analyze control method return types"); 675118611Snjl AnalysisWalkInfo.MethodStack = NULL; 676118611Snjl 677118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n"); 678151937Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, 679151937Sjkim AnMethodAnalysisWalkBegin, 680151937Sjkim AnMethodAnalysisWalkEnd, &AnalysisWalkInfo); 681151937Sjkim UtEndEvent (Event); 682118611Snjl 683118611Snjl /* Semantic error checking part two - typing of method returns */ 684118611Snjl 685151937Sjkim Event = UtBeginEvent ("Determine object types returned by methods"); 686151937Sjkim DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing\n\n"); 687151937Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, 688151937Sjkim AnMethodTypingWalkBegin, 689151937Sjkim AnMethodTypingWalkEnd, NULL); 690151937Sjkim UtEndEvent (Event); 691118611Snjl 692118611Snjl /* Semantic error checking part three - operand type checking */ 693118611Snjl 694151937Sjkim Event = UtBeginEvent ("Analyze AML operand types"); 695151937Sjkim DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking\n\n"); 696151937Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, 697151937Sjkim AnOperandTypecheckWalkBegin, 698151937Sjkim AnOperandTypecheckWalkEnd, &AnalysisWalkInfo); 699151937Sjkim UtEndEvent (Event); 700118611Snjl 701118611Snjl /* Semantic error checking part four - other miscellaneous checks */ 702118611Snjl 703151937Sjkim Event = UtBeginEvent ("Miscellaneous analysis"); 704151937Sjkim DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous\n\n"); 705151937Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, 706151937Sjkim AnOtherSemanticAnalysisWalkBegin, 707151937Sjkim AnOtherSemanticAnalysisWalkEnd, &AnalysisWalkInfo); 708151937Sjkim UtEndEvent (Event); 709118611Snjl 710118611Snjl /* Calculate all AML package lengths */ 711118611Snjl 712151937Sjkim Event = UtBeginEvent ("Finish AML package length generation"); 713118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 714151937Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 715151937Sjkim LnInitLengthsWalk, NULL); 716151937Sjkim TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 717151937Sjkim LnPackageLengthWalk, NULL); 718151937Sjkim UtEndEvent (Event); 719118611Snjl 720118611Snjl /* Code generation - emit the AML */ 721118611Snjl 722151937Sjkim Event = UtBeginEvent ("Generate AML code and write output files"); 723118611Snjl CgGenerateAmlOutput (); 724151937Sjkim UtEndEvent (Event); 725118611Snjl 726151937Sjkim Event = UtBeginEvent ("Write optional output files"); 727118611Snjl CmDoOutputFiles (); 728151937Sjkim UtEndEvent (Event); 729118611Snjl 730151937Sjkim UtEndEvent (FullCompile); 731118611Snjl CmCleanupAndExit (); 732118611Snjl return 0; 733118611Snjl} 734118611Snjl 735151937Sjkim 736151937Sjkim/******************************************************************************* 737151937Sjkim * 738151937Sjkim * FUNCTION: CmDoOutputFiles 739151937Sjkim * 740151937Sjkim * PARAMETERS: None 741151937Sjkim * 742151937Sjkim * RETURN: None. 743151937Sjkim * 744151937Sjkim * DESCRIPTION: Create all "listing" type files 745151937Sjkim * 746151937Sjkim ******************************************************************************/ 747151937Sjkim 748118611Snjlvoid 749151937SjkimCmDoOutputFiles ( 750151937Sjkim void) 751118611Snjl{ 752118611Snjl 753118611Snjl /* Create listings and hex files */ 754118611Snjl 755118611Snjl LsDoListings (); 756118611Snjl LsDoHexOutput (); 757118611Snjl 758118611Snjl /* Dump the namespace to the .nsp file if requested */ 759118611Snjl 760151937Sjkim (void) LsDisplayNamespace (); 761118611Snjl} 762118611Snjl 763118611Snjl 764118611Snjl/******************************************************************************* 765118611Snjl * 766151937Sjkim * FUNCTION: CmDumpEvent 767151937Sjkim * 768151937Sjkim * PARAMETERS: Event - A compiler event struct 769151937Sjkim * 770151937Sjkim * RETURN: None. 771151937Sjkim * 772151937Sjkim * DESCRIPTION: Dump a compiler event struct 773151937Sjkim * 774151937Sjkim ******************************************************************************/ 775151937Sjkim 776151937Sjkimstatic void 777151937SjkimCmDumpEvent ( 778151937Sjkim ASL_EVENT_INFO *Event) 779151937Sjkim{ 780151937Sjkim UINT32 Delta; 781151937Sjkim UINT32 USec; 782151937Sjkim UINT32 MSec; 783151937Sjkim 784151937Sjkim if (!Event->Valid) 785151937Sjkim { 786151937Sjkim return; 787151937Sjkim } 788151937Sjkim 789151937Sjkim /* Delta will be in 100-nanosecond units */ 790151937Sjkim 791151937Sjkim Delta = (UINT32) (Event->EndTime - Event->StartTime); 792151937Sjkim 793151937Sjkim USec = Delta / 10; 794151937Sjkim MSec = Delta / 10000; 795151937Sjkim 796151937Sjkim /* Round milliseconds up */ 797151937Sjkim 798151937Sjkim if ((USec - (MSec * 1000)) >= 500) 799151937Sjkim { 800151937Sjkim MSec++; 801151937Sjkim } 802151937Sjkim 803151937Sjkim DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n", 804151937Sjkim USec, MSec, Event->EventName); 805151937Sjkim} 806151937Sjkim 807151937Sjkim 808151937Sjkim/******************************************************************************* 809151937Sjkim * 810118611Snjl * FUNCTION: CmCleanupAndExit 811118611Snjl * 812118611Snjl * PARAMETERS: None 813118611Snjl * 814118611Snjl * RETURN: None. 815118611Snjl * 816118611Snjl * DESCRIPTION: Close all open files and exit the compiler 817118611Snjl * 818118611Snjl ******************************************************************************/ 819118611Snjl 820118611Snjlvoid 821151937SjkimCmCleanupAndExit ( 822151937Sjkim void) 823118611Snjl{ 824118611Snjl UINT32 i; 825118611Snjl 826118611Snjl 827118611Snjl AePrintErrorLog (ASL_FILE_STDOUT); 828118611Snjl if (Gbl_DebugFlag) 829118611Snjl { 830118611Snjl /* Print error summary to the debug file */ 831118611Snjl 832118611Snjl AePrintErrorLog (ASL_FILE_STDERR); 833118611Snjl } 834118611Snjl 835118611Snjl DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n"); 836151937Sjkim for (i = 0; i < AslGbl_NextEvent; i++) 837118611Snjl { 838151937Sjkim CmDumpEvent (&AslGbl_Events[i]); 839118611Snjl } 840118611Snjl 841118611Snjl if (Gbl_CompileTimesFlag) 842118611Snjl { 843118611Snjl printf ("\nElapsed time for major events\n\n"); 844151937Sjkim for (i = 0; i < AslGbl_NextEvent; i++) 845118611Snjl { 846151937Sjkim CmDumpEvent (&AslGbl_Events[i]); 847118611Snjl } 848151937Sjkim 849118611Snjl printf ("\nMiscellaneous compile statistics\n\n"); 850118611Snjl printf ("%11u : %s\n", TotalParseNodes, "Parse nodes"); 851118611Snjl printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches"); 852118611Snjl printf ("%11u : %s\n", TotalNamedObjects, "Named objects"); 853118611Snjl printf ("%11u : %s\n", TotalMethods, "Control methods"); 854118611Snjl printf ("%11u : %s\n", TotalAllocations, "Memory Allocations"); 855118611Snjl printf ("%11u : %s\n", TotalAllocated, "Total allocated memory"); 856118611Snjl printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded"); 857118611Snjl printf ("\n"); 858118611Snjl } 859118611Snjl 860118611Snjl if (Gbl_NsLookupCount) 861118611Snjl { 862209746Sjkim DbgPrint (ASL_DEBUG_OUTPUT, 863209746Sjkim "\n\nMiscellaneous compile statistics\n\n"); 864209746Sjkim 865209746Sjkim DbgPrint (ASL_DEBUG_OUTPUT, 866209746Sjkim "%32s : %u\n", "Total Namespace searches", 867151937Sjkim Gbl_NsLookupCount); 868209746Sjkim 869209746Sjkim DbgPrint (ASL_DEBUG_OUTPUT, 870209746Sjkim "%32s : %u usec\n", "Time per search", ((UINT32) 871209746Sjkim (AslGbl_Events[AslGbl_NamespaceEvent].EndTime - 872209746Sjkim AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) / 873209746Sjkim Gbl_NsLookupCount); 874118611Snjl } 875118611Snjl 876118611Snjl if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) 877118611Snjl { 878209746Sjkim printf ("\nMaximum error count (%u) exceeded\n", 879209746Sjkim ASL_MAX_ERROR_COUNT); 880118611Snjl } 881118611Snjl 882118611Snjl UtDisplaySummary (ASL_FILE_STDOUT); 883199337Sjkim 884199337Sjkim /* Close all open files */ 885199337Sjkim 886199337Sjkim for (i = 2; i < ASL_MAX_FILE_TYPE; i++) 887199337Sjkim { 888199337Sjkim FlCloseFile (i); 889199337Sjkim } 890200553Sjkim 891200553Sjkim /* Delete AML file if there are errors */ 892200553Sjkim 893209746Sjkim if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors) && 894209746Sjkim Gbl_Files[ASL_FILE_AML_OUTPUT].Handle) 895200553Sjkim { 896209746Sjkim if (remove (Gbl_Files[ASL_FILE_AML_OUTPUT].Filename)) 897209746Sjkim { 898209746Sjkim printf ("%s: ", 899209746Sjkim Gbl_Files[ASL_FILE_AML_OUTPUT].Filename); 900209746Sjkim perror ("Could not delete AML file"); 901209746Sjkim } 902200553Sjkim } 903200553Sjkim 904200553Sjkim /* 905200553Sjkim * Delete intermediate ("combined") source file (if -ls flag not set) 906209746Sjkim * This file is created during normal ASL/AML compiles. It is not 907209746Sjkim * created by the data table compiler. 908200553Sjkim * 909209746Sjkim * If the -ls flag is set, then the .SRC file should not be deleted. 910209746Sjkim * In this case, Gbl_SourceOutputFlag is set to TRUE. 911209746Sjkim * 912209746Sjkim * Note: Handles are cleared by FlCloseFile above, so we look at the 913209746Sjkim * filename instead, to determine if the .SRC file was actually 914209746Sjkim * created. 915209746Sjkim * 916200553Sjkim * TBD: SourceOutput should be .TMP, then rename if we want to keep it? 917200553Sjkim */ 918209746Sjkim if (!Gbl_SourceOutputFlag && Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename) 919200553Sjkim { 920200553Sjkim if (remove (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename)) 921200553Sjkim { 922209746Sjkim printf ("%s: ", 923200553Sjkim Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename); 924209746Sjkim perror ("Could not delete SRC file"); 925200553Sjkim } 926200553Sjkim } 927118611Snjl} 928118611Snjl 929118611Snjl 930