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 - 2010, 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 <stdio.h> 118 #include <time.h> 119 #include <contrib/dev/acpica/compiler/aslcompiler.h> 120 121 #define _COMPONENT ACPI_COMPILER 122 ACPI_MODULE_NAME ("aslcompile") 123 124 /* Local prototypes */ 125 126 static void 127 CmFlushSourceCode ( 128 void); 129 130 static ACPI_STATUS 131 FlCheckForAscii ( 132 ASL_FILE_INFO *FileInfo); 133 134 void 135 FlConsumeAnsiComment ( 136 ASL_FILE_INFO *FileInfo, 137 ASL_FILE_STATUS *Status); 138 139 void 140 FlConsumeNewComment ( 141 ASL_FILE_INFO *FileInfo, 142 ASL_FILE_STATUS *Status); 143 144 145 /******************************************************************************* 146 * 147 * FUNCTION: AslCompilerSignon 148 * 149 * PARAMETERS: FileId - ID of the output file 150 * 151 * RETURN: None 152 * 153 * DESCRIPTION: Display compiler signon 154 * 155 ******************************************************************************/ 156 157 void 158 AslCompilerSignon ( 159 UINT32 FileId) 160 { 161 char *Prefix = ""; 162 163 164 /* Set line prefix depending on the destination file type */ 165 166 switch (FileId) 167 { 168 case ASL_FILE_ASM_SOURCE_OUTPUT: 169 case ASL_FILE_ASM_INCLUDE_OUTPUT: 170 171 Prefix = "; "; 172 break; 173 174 case ASL_FILE_HEX_OUTPUT: 175 176 if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) 177 { 178 Prefix = "; "; 179 } 180 else if (Gbl_HexOutputFlag == HEX_OUTPUT_C) 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 /* 199 * Compiler signon with copyright 200 */ 201 FlPrintFile (FileId, 202 "%s\n%s%s\n%s", 203 Prefix, 204 Prefix, IntelAcpiCA, 205 Prefix); 206 207 /* Running compiler or disassembler? */ 208 209 if (Gbl_DisasmFlag) 210 { 211 FlPrintFile (FileId, 212 "%s", DisassemblerId); 213 } 214 else 215 { 216 FlPrintFile (FileId, 217 "%s", CompilerId); 218 } 219 220 /* Version, copyright, compliance */ 221 222 FlPrintFile (FileId, 223 " version %X\n%s%s\n%s%s\n%s\n", 224 (UINT32) ACPI_CA_VERSION, 225 Prefix, CompilerCopyright, 226 Prefix, CompilerCompliance, 227 Prefix); 228 } 229 230 231 /******************************************************************************* 232 * 233 * FUNCTION: AslCompilerFileHeader 234 * 235 * PARAMETERS: FileId - ID of the output file 236 * 237 * RETURN: None 238 * 239 * DESCRIPTION: Header used at the beginning of output files 240 * 241 ******************************************************************************/ 242 243 void 244 AslCompilerFileHeader ( 245 UINT32 FileId) 246 { 247 struct tm *NewTime; 248 time_t Aclock; 249 char *Prefix = ""; 250 251 252 /* Set line prefix depending on the destination file type */ 253 254 switch (FileId) 255 { 256 case ASL_FILE_ASM_SOURCE_OUTPUT: 257 case ASL_FILE_ASM_INCLUDE_OUTPUT: 258 259 Prefix = "; "; 260 break; 261 262 case ASL_FILE_HEX_OUTPUT: 263 264 if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) 265 { 266 Prefix = "; "; 267 } 268 else if (Gbl_HexOutputFlag == HEX_OUTPUT_C) 269 { 270 Prefix = " * "; 271 } 272 break; 273 274 case ASL_FILE_C_SOURCE_OUTPUT: 275 case ASL_FILE_C_INCLUDE_OUTPUT: 276 277 Prefix = " * "; 278 break; 279 280 default: 281 /* No other output types supported */ 282 break; 283 } 284 285 /* Compilation header with timestamp */ 286 287 (void) time (&Aclock); 288 NewTime = localtime (&Aclock); 289 290 FlPrintFile (FileId, 291 "%sCompilation of \"%s\" - %s%s\n", 292 Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime), 293 Prefix); 294 295 switch (FileId) 296 { 297 case ASL_FILE_C_SOURCE_OUTPUT: 298 case ASL_FILE_C_INCLUDE_OUTPUT: 299 FlPrintFile (FileId, " */\n"); 300 break; 301 302 default: 303 /* Nothing to do for other output types */ 304 break; 305 } 306 } 307 308 309 /******************************************************************************* 310 * 311 * FUNCTION: CmFlushSourceCode 312 * 313 * PARAMETERS: None 314 * 315 * RETURN: None 316 * 317 * DESCRIPTION: Read in any remaining source code after the parse tree 318 * has been constructed. 319 * 320 ******************************************************************************/ 321 322 static void 323 CmFlushSourceCode ( 324 void) 325 { 326 char Buffer; 327 328 329 while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR) 330 { 331 InsertLineBuffer ((int) Buffer); 332 } 333 334 ResetCurrentLineBuffer (); 335 } 336 337 338 /******************************************************************************* 339 * 340 * FUNCTION: FlConsume* 341 * 342 * PARAMETERS: FileInfo - Points to an open input file 343 * 344 * RETURN: Number of lines consumed 345 * 346 * DESCRIPTION: Step over both types of comment during check for ascii chars 347 * 348 ******************************************************************************/ 349 350 void 351 FlConsumeAnsiComment ( 352 ASL_FILE_INFO *FileInfo, 353 ASL_FILE_STATUS *Status) 354 { 355 UINT8 Byte; 356 BOOLEAN ClosingComment = FALSE; 357 358 359 while (fread (&Byte, 1, 1, FileInfo->Handle)) 360 { 361 /* Scan until comment close is found */ 362 363 if (ClosingComment) 364 { 365 if (Byte == '/') 366 { 367 return; 368 } 369 370 if (Byte != '*') 371 { 372 /* Reset */ 373 374 ClosingComment = FALSE; 375 } 376 } 377 else if (Byte == '*') 378 { 379 ClosingComment = TRUE; 380 } 381 382 /* Maintain line count */ 383 384 if (Byte == 0x0A) 385 { 386 Status->Line++; 387 } 388 389 Status->Offset++; 390 } 391 } 392 393 394 void 395 FlConsumeNewComment ( 396 ASL_FILE_INFO *FileInfo, 397 ASL_FILE_STATUS *Status) 398 { 399 UINT8 Byte; 400 401 402 while (fread (&Byte, 1, 1, FileInfo->Handle)) 403 { 404 Status->Offset++; 405 406 /* Comment ends at newline */ 407 408 if (Byte == 0x0A) 409 { 410 Status->Line++; 411 return; 412 } 413 } 414 } 415 416 417 /******************************************************************************* 418 * 419 * FUNCTION: FlCheckForAscii 420 * 421 * PARAMETERS: FileInfo - Points to an open input file 422 * 423 * RETURN: Status 424 * 425 * DESCRIPTION: Verify that the input file is entirely ASCII. Ignores characters 426 * within comments. Note: does not handle nested comments and does 427 * not handle comment delimiters within string literals. However, 428 * on the rare chance this happens and an invalid character is 429 * missed, the parser will catch the error by failing in some 430 * spectactular manner. 431 * 432 ******************************************************************************/ 433 434 static ACPI_STATUS 435 FlCheckForAscii ( 436 ASL_FILE_INFO *FileInfo) 437 { 438 UINT8 Byte; 439 ACPI_SIZE BadBytes = 0; 440 BOOLEAN OpeningComment = FALSE; 441 ASL_FILE_STATUS Status; 442 443 444 Status.Line = 1; 445 Status.Offset = 0; 446 447 /* Read the entire file */ 448 449 while (fread (&Byte, 1, 1, FileInfo->Handle)) 450 { 451 /* Ignore comment fields (allow non-ascii within) */ 452 453 if (OpeningComment) 454 { 455 /* Check for second comment open delimiter */ 456 457 if (Byte == '*') 458 { 459 FlConsumeAnsiComment (FileInfo, &Status); 460 } 461 462 if (Byte == '/') 463 { 464 FlConsumeNewComment (FileInfo, &Status); 465 } 466 467 /* Reset */ 468 469 OpeningComment = FALSE; 470 } 471 else if (Byte == '/') 472 { 473 OpeningComment = TRUE; 474 } 475 476 /* Check for an ASCII character */ 477 478 if (!ACPI_IS_ASCII (Byte)) 479 { 480 if (BadBytes < 10) 481 { 482 AcpiOsPrintf ( 483 "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n", 484 Byte, Status.Line, Status.Offset); 485 } 486 487 BadBytes++; 488 } 489 490 /* Update line counter */ 491 492 else if (Byte == 0x0A) 493 { 494 Status.Line++; 495 } 496 497 Status.Offset++; 498 } 499 500 /* Seek back to the beginning of the source file */ 501 502 fseek (FileInfo->Handle, 0, SEEK_SET); 503 504 /* Were there any non-ASCII characters in the file? */ 505 506 if (BadBytes) 507 { 508 AcpiOsPrintf ( 509 "%u non-ASCII characters found in input source text, could be a binary file\n", 510 BadBytes); 511 AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, FileInfo->Filename); 512 return (AE_BAD_CHARACTER); 513 } 514 515 /* File is OK */ 516 517 return (AE_OK); 518 } 519 520 521 /******************************************************************************* 522 * 523 * FUNCTION: CmDoCompile 524 * 525 * PARAMETERS: None 526 * 527 * RETURN: Status (0 = OK) 528 * 529 * DESCRIPTION: This procedure performs the entire compile 530 * 531 ******************************************************************************/ 532 533 int 534 CmDoCompile ( 535 void) 536 { 537 ACPI_STATUS Status; 538 UINT8 FullCompile; 539 UINT8 Event; 540 541 542 FullCompile = UtBeginEvent ("*** Total Compile time ***"); 543 Event = UtBeginEvent ("Open input and output files"); 544 545 /* Open the required input and output files */ 546 547 Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename); 548 if (ACPI_FAILURE (Status)) 549 { 550 AePrintErrorLog (ASL_FILE_STDERR); 551 return -1; 552 } 553 554 /* Check for 100% ASCII source file (comments are ignored) */ 555 556 Status = FlCheckForAscii (&Gbl_Files[ASL_FILE_INPUT]); 557 if (ACPI_FAILURE (Status)) 558 { 559 AePrintErrorLog (ASL_FILE_STDERR); 560 return -1; 561 } 562 563 Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix); 564 if (ACPI_FAILURE (Status)) 565 { 566 AePrintErrorLog (ASL_FILE_STDERR); 567 return -1; 568 } 569 UtEndEvent (Event); 570 571 /* Build the parse tree */ 572 573 Event = UtBeginEvent ("Parse source code and build parse tree"); 574 AslCompilerparse(); 575 UtEndEvent (Event); 576 577 /* Flush out any remaining source after parse tree is complete */ 578 579 Event = UtBeginEvent ("Flush source input"); 580 CmFlushSourceCode (); 581 582 /* Did the parse tree get successfully constructed? */ 583 584 if (!RootNode) 585 { 586 CmCleanupAndExit (); 587 return -1; 588 } 589 590 /* Optional parse tree dump, compiler debug output only */ 591 592 LsDumpParseTree (); 593 594 OpcGetIntegerWidth (RootNode); 595 UtEndEvent (Event); 596 597 /* Pre-process parse tree for any operator transforms */ 598 599 Event = UtBeginEvent ("Parse tree transforms"); 600 DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n"); 601 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 602 TrAmlTransformWalk, NULL, NULL); 603 UtEndEvent (Event); 604 605 /* Generate AML opcodes corresponding to the parse tokens */ 606 607 Event = UtBeginEvent ("Generate AML opcodes"); 608 DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n"); 609 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 610 OpcAmlOpcodeWalk, NULL); 611 UtEndEvent (Event); 612 613 /* 614 * Now that the input is parsed, we can open the AML output file. 615 * Note: by default, the name of this file comes from the table descriptor 616 * within the input file. 617 */ 618 Event = UtBeginEvent ("Open AML output file"); 619 Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix); 620 if (ACPI_FAILURE (Status)) 621 { 622 AePrintErrorLog (ASL_FILE_STDERR); 623 return -1; 624 } 625 UtEndEvent (Event); 626 627 /* Interpret and generate all compile-time constants */ 628 629 Event = UtBeginEvent ("Constant folding via AML interpreter"); 630 DbgPrint (ASL_DEBUG_OUTPUT, 631 "\nInterpreting compile-time constant expressions\n\n"); 632 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 633 OpcAmlConstantWalk, NULL, NULL); 634 UtEndEvent (Event); 635 636 /* Update AML opcodes if necessary, after constant folding */ 637 638 Event = UtBeginEvent ("Updating AML opcodes after constant folding"); 639 DbgPrint (ASL_DEBUG_OUTPUT, 640 "\nUpdating AML opcodes after constant folding\n\n"); 641 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, 642 NULL, OpcAmlOpcodeUpdateWalk, NULL); 643 UtEndEvent (Event); 644 645 /* Calculate all AML package lengths */ 646 647 Event = UtBeginEvent ("Generate AML package lengths"); 648 DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 649 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 650 LnPackageLengthWalk, NULL); 651 UtEndEvent (Event); 652 653 if (Gbl_ParseOnlyFlag) 654 { 655 AePrintErrorLog (ASL_FILE_STDOUT); 656 UtDisplaySummary (ASL_FILE_STDOUT); 657 if (Gbl_DebugFlag) 658 { 659 /* Print error summary to the debug file */ 660 661 AePrintErrorLog (ASL_FILE_STDERR); 662 UtDisplaySummary (ASL_FILE_STDERR); 663 } 664 return 0; 665 } 666 667 /* 668 * Create an internal namespace and use it as a symbol table 669 */ 670 671 /* Namespace loading */ 672 673 Event = UtBeginEvent ("Create ACPI Namespace"); 674 Status = LdLoadNamespace (RootNode); 675 UtEndEvent (Event); 676 if (ACPI_FAILURE (Status)) 677 { 678 return -1; 679 } 680 681 /* Namespace cross-reference */ 682 683 AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace"); 684 Status = LkCrossReferenceNamespace (); 685 if (ACPI_FAILURE (Status)) 686 { 687 return -1; 688 } 689 690 /* Namespace - Check for non-referenced objects */ 691 692 LkFindUnreferencedObjects (); 693 UtEndEvent (AslGbl_NamespaceEvent); 694 695 /* 696 * Semantic analysis. This can happen only after the 697 * namespace has been loaded and cross-referenced. 698 * 699 * part one - check control methods 700 */ 701 Event = UtBeginEvent ("Analyze control method return types"); 702 AnalysisWalkInfo.MethodStack = NULL; 703 704 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n"); 705 TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, 706 AnMethodAnalysisWalkBegin, 707 AnMethodAnalysisWalkEnd, &AnalysisWalkInfo); 708 UtEndEvent (Event); 709 710 /* Semantic error checking part two - typing of method returns */ 711 712 Event = UtBeginEvent ("Determine object types returned by methods"); 713 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing\n\n"); 714 TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, 715 AnMethodTypingWalkBegin, 716 AnMethodTypingWalkEnd, NULL); 717 UtEndEvent (Event); 718 719 /* Semantic error checking part three - operand type checking */ 720 721 Event = UtBeginEvent ("Analyze AML operand types"); 722 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking\n\n"); 723 TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, 724 AnOperandTypecheckWalkBegin, 725 AnOperandTypecheckWalkEnd, &AnalysisWalkInfo); 726 UtEndEvent (Event); 727 728 /* Semantic error checking part four - other miscellaneous checks */ 729 730 Event = UtBeginEvent ("Miscellaneous analysis"); 731 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous\n\n"); 732 TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, 733 AnOtherSemanticAnalysisWalkBegin, 734 AnOtherSemanticAnalysisWalkEnd, &AnalysisWalkInfo); 735 UtEndEvent (Event); 736 737 /* Calculate all AML package lengths */ 738 739 Event = UtBeginEvent ("Finish AML package length generation"); 740 DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 741 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 742 LnInitLengthsWalk, NULL); 743 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 744 LnPackageLengthWalk, NULL); 745 UtEndEvent (Event); 746 747 /* Code generation - emit the AML */ 748 749 Event = UtBeginEvent ("Generate AML code and write output files"); 750 CgGenerateAmlOutput (); 751 UtEndEvent (Event); 752 753 Event = UtBeginEvent ("Write optional output files"); 754 CmDoOutputFiles (); 755 UtEndEvent (Event); 756 757 UtEndEvent (FullCompile); 758 CmCleanupAndExit (); 759 return 0; 760 } 761 762 763 /******************************************************************************* 764 * 765 * FUNCTION: CmDoOutputFiles 766 * 767 * PARAMETERS: None 768 * 769 * RETURN: None. 770 * 771 * DESCRIPTION: Create all "listing" type files 772 * 773 ******************************************************************************/ 774 775 void 776 CmDoOutputFiles ( 777 void) 778 { 779 780 /* Create listings and hex files */ 781 782 LsDoListings (); 783 LsDoHexOutput (); 784 785 /* Dump the namespace to the .nsp file if requested */ 786 787 (void) LsDisplayNamespace (); 788 } 789 790 791 /******************************************************************************* 792 * 793 * FUNCTION: CmDumpEvent 794 * 795 * PARAMETERS: Event - A compiler event struct 796 * 797 * RETURN: None. 798 * 799 * DESCRIPTION: Dump a compiler event struct 800 * 801 ******************************************************************************/ 802 803 static void 804 CmDumpEvent ( 805 ASL_EVENT_INFO *Event) 806 { 807 UINT32 Delta; 808 UINT32 USec; 809 UINT32 MSec; 810 811 if (!Event->Valid) 812 { 813 return; 814 } 815 816 /* Delta will be in 100-nanosecond units */ 817 818 Delta = (UINT32) (Event->EndTime - Event->StartTime); 819 820 USec = Delta / 10; 821 MSec = Delta / 10000; 822 823 /* Round milliseconds up */ 824 825 if ((USec - (MSec * 1000)) >= 500) 826 { 827 MSec++; 828 } 829 830 DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n", 831 USec, MSec, Event->EventName); 832 } 833 834 835 /******************************************************************************* 836 * 837 * FUNCTION: CmCleanupAndExit 838 * 839 * PARAMETERS: None 840 * 841 * RETURN: None. 842 * 843 * DESCRIPTION: Close all open files and exit the compiler 844 * 845 ******************************************************************************/ 846 847 void 848 CmCleanupAndExit ( 849 void) 850 { 851 UINT32 i; 852 853 854 AePrintErrorLog (ASL_FILE_STDOUT); 855 if (Gbl_DebugFlag) 856 { 857 /* Print error summary to the debug file */ 858 859 AePrintErrorLog (ASL_FILE_STDERR); 860 } 861 862 DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n"); 863 for (i = 0; i < AslGbl_NextEvent; i++) 864 { 865 CmDumpEvent (&AslGbl_Events[i]); 866 } 867 868 if (Gbl_CompileTimesFlag) 869 { 870 printf ("\nElapsed time for major events\n\n"); 871 for (i = 0; i < AslGbl_NextEvent; i++) 872 { 873 CmDumpEvent (&AslGbl_Events[i]); 874 } 875 876 printf ("\nMiscellaneous compile statistics\n\n"); 877 printf ("%11u : %s\n", TotalParseNodes, "Parse nodes"); 878 printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches"); 879 printf ("%11u : %s\n", TotalNamedObjects, "Named objects"); 880 printf ("%11u : %s\n", TotalMethods, "Control methods"); 881 printf ("%11u : %s\n", TotalAllocations, "Memory Allocations"); 882 printf ("%11u : %s\n", TotalAllocated, "Total allocated memory"); 883 printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded"); 884 printf ("\n"); 885 } 886 887 if (Gbl_NsLookupCount) 888 { 889 DbgPrint (ASL_DEBUG_OUTPUT, "\n\nMiscellaneous compile statistics\n\n"); 890 DbgPrint (ASL_DEBUG_OUTPUT, "%32s : %d\n", "Total Namespace searches", 891 Gbl_NsLookupCount); 892 DbgPrint (ASL_DEBUG_OUTPUT, "%32s : %d usec\n", "Time per search", 893 ((UINT32) (AslGbl_Events[AslGbl_NamespaceEvent].EndTime - 894 AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 895 10) / Gbl_NsLookupCount); 896 } 897 898 899 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) 900 { 901 printf ("\nMaximum error count (%d) exceeded\n", ASL_MAX_ERROR_COUNT); 902 } 903 904 UtDisplaySummary (ASL_FILE_STDOUT); 905 906 /* Close all open files */ 907 908 for (i = 2; i < ASL_MAX_FILE_TYPE; i++) 909 { 910 FlCloseFile (i); 911 } 912 913 /* Delete AML file if there are errors */ 914 915 if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors)) 916 { 917 remove (Gbl_Files[ASL_FILE_AML_OUTPUT].Filename); 918 } 919 920 /* 921 * Delete intermediate ("combined") source file (if -ls flag not set) 922 * 923 * TBD: SourceOutput should be .TMP, then rename if we want to keep it? 924 */ 925 if (!Gbl_SourceOutputFlag) 926 { 927 if (remove (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename)) 928 { 929 printf ("Could not remove SRC file, %s\n", 930 Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename); 931 } 932 } 933 } 934 935 936