1/****************************************************************************** 2 * 3 * Module Name: aslcompile - top level compile module 4 * 5 *****************************************************************************/ 6 7/* 8 * Copyright (C) 2000 - 2012, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44#include <contrib/dev/acpica/compiler/aslcompiler.h> 45 46#include <stdio.h> 47#include <time.h> 48#include <contrib/dev/acpica/include/acapps.h> 49 50#define _COMPONENT ACPI_COMPILER 51 ACPI_MODULE_NAME ("aslcompile") 52
| 1/****************************************************************************** 2 * 3 * Module Name: aslcompile - top level compile module 4 * 5 *****************************************************************************/ 6 7/* 8 * Copyright (C) 2000 - 2012, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44#include <contrib/dev/acpica/compiler/aslcompiler.h> 45 46#include <stdio.h> 47#include <time.h> 48#include <contrib/dev/acpica/include/acapps.h> 49 50#define _COMPONENT ACPI_COMPILER 51 ACPI_MODULE_NAME ("aslcompile") 52
|
372 { 373 /* Ignore comment fields (allow non-ascii within) */ 374 375 if (OpeningComment) 376 { 377 /* Check for second comment open delimiter */ 378 379 if (Byte == '*') 380 { 381 FlConsumeAnsiComment (Handle, &Status); 382 } 383 384 if (Byte == '/') 385 { 386 FlConsumeNewComment (Handle, &Status); 387 } 388 389 /* Reset */ 390 391 OpeningComment = FALSE; 392 } 393 else if (Byte == '/') 394 { 395 OpeningComment = TRUE; 396 } 397 398 /* Check for an ASCII character */ 399 400 if (!ACPI_IS_ASCII (Byte)) 401 { 402 if ((BadBytes < 10) && (DisplayErrors)) 403 { 404 AcpiOsPrintf ( 405 "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n", 406 Byte, Status.Line, Status.Offset); 407 } 408 409 BadBytes++; 410 } 411 412 /* Update line counter */ 413 414 else if (Byte == 0x0A) 415 { 416 Status.Line++; 417 } 418 419 Status.Offset++; 420 } 421 422 /* Seek back to the beginning of the source file */ 423 424 fseek (Handle, 0, SEEK_SET); 425 426 /* Were there any non-ASCII characters in the file? */ 427 428 if (BadBytes) 429 { 430 if (DisplayErrors) 431 { 432 AcpiOsPrintf ( 433 "%u non-ASCII characters found in input source text, could be a binary file\n", 434 BadBytes); 435 AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, Filename); 436 } 437 438 return (AE_BAD_CHARACTER); 439 } 440 441 /* File is OK (100% ASCII) */ 442 443 return (AE_OK); 444} 445 446 447/******************************************************************************* 448 * 449 * FUNCTION: CmDoCompile 450 * 451 * PARAMETERS: None 452 * 453 * RETURN: Status (0 = OK) 454 * 455 * DESCRIPTION: This procedure performs the entire compile 456 * 457 ******************************************************************************/ 458 459int 460CmDoCompile ( 461 void) 462{ 463 ACPI_STATUS Status; 464 UINT8 FullCompile; 465 UINT8 Event; 466 467 468 FullCompile = UtBeginEvent ("*** Total Compile time ***"); 469 Event = UtBeginEvent ("Open input and output files"); 470 UtEndEvent (Event); 471 472 Event = UtBeginEvent ("Preprocess input file"); 473 if (Gbl_PreprocessFlag) 474 { 475 /* Preprocessor */ 476 477 PrDoPreprocess (); 478 if (Gbl_PreprocessOnly) 479 { 480 UtEndEvent (Event); 481 CmCleanupAndExit (); 482 return (0); 483 } 484 } 485 UtEndEvent (Event); 486 487 /* Build the parse tree */ 488 489 Event = UtBeginEvent ("Parse source code and build parse tree"); 490 AslCompilerparse(); 491 UtEndEvent (Event); 492 493 /* Flush out any remaining source after parse tree is complete */ 494 495 Event = UtBeginEvent ("Flush source input"); 496 CmFlushSourceCode (); 497 498 /* Did the parse tree get successfully constructed? */ 499 500 if (!RootNode) 501 { 502 /* 503 * If there are no errors, then we have some sort of 504 * internal problem. 505 */ 506 Status = AslCheckForErrorExit (); 507 if (Status == AE_OK) 508 { 509 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, 510 NULL, "- Could not resolve parse tree root node"); 511 } 512 513 goto ErrorExit; 514 } 515 516 /* Optional parse tree dump, compiler debug output only */ 517 518 LsDumpParseTree (); 519 520 OpcGetIntegerWidth (RootNode); 521 UtEndEvent (Event); 522 523 /* Pre-process parse tree for any operator transforms */ 524 525 Event = UtBeginEvent ("Parse tree transforms"); 526 DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n"); 527 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 528 TrAmlTransformWalk, NULL, NULL); 529 UtEndEvent (Event); 530 531 /* Generate AML opcodes corresponding to the parse tokens */ 532 533 Event = UtBeginEvent ("Generate AML opcodes"); 534 DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n"); 535 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 536 OpcAmlOpcodeWalk, NULL); 537 UtEndEvent (Event); 538 539 /* 540 * Now that the input is parsed, we can open the AML output file. 541 * Note: by default, the name of this file comes from the table descriptor 542 * within the input file. 543 */ 544 Event = UtBeginEvent ("Open AML output file"); 545 Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix); 546 UtEndEvent (Event); 547 if (ACPI_FAILURE (Status)) 548 { 549 AePrintErrorLog (ASL_FILE_STDERR); 550 return (-1); 551 } 552 553 /* Interpret and generate all compile-time constants */ 554 555 Event = UtBeginEvent ("Constant folding via AML interpreter"); 556 DbgPrint (ASL_DEBUG_OUTPUT, 557 "\nInterpreting compile-time constant expressions\n\n"); 558 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 559 OpcAmlConstantWalk, NULL, NULL); 560 UtEndEvent (Event); 561 562 /* Update AML opcodes if necessary, after constant folding */ 563 564 Event = UtBeginEvent ("Updating AML opcodes after constant folding"); 565 DbgPrint (ASL_DEBUG_OUTPUT, 566 "\nUpdating AML opcodes after constant folding\n\n"); 567 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, 568 NULL, OpcAmlOpcodeUpdateWalk, NULL); 569 UtEndEvent (Event); 570 571 /* Calculate all AML package lengths */ 572 573 Event = UtBeginEvent ("Generate AML package lengths"); 574 DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 575 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 576 LnPackageLengthWalk, NULL); 577 UtEndEvent (Event); 578 579 if (Gbl_ParseOnlyFlag) 580 { 581 AePrintErrorLog (ASL_FILE_STDERR); 582 UtDisplaySummary (ASL_FILE_STDERR); 583 if (Gbl_DebugFlag) 584 { 585 /* Print error summary to the stdout also */ 586 587 AePrintErrorLog (ASL_FILE_STDOUT); 588 UtDisplaySummary (ASL_FILE_STDOUT); 589 } 590 UtEndEvent (FullCompile); 591 return (0); 592 } 593 594 /* 595 * Create an internal namespace and use it as a symbol table 596 */ 597 598 /* Namespace loading */ 599 600 Event = UtBeginEvent ("Create ACPI Namespace"); 601 Status = LdLoadNamespace (RootNode); 602 UtEndEvent (Event); 603 if (ACPI_FAILURE (Status)) 604 { 605 goto ErrorExit; 606 } 607 608 /* Namespace cross-reference */ 609 610 AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace"); 611 Status = LkCrossReferenceNamespace (); 612 if (ACPI_FAILURE (Status)) 613 { 614 goto ErrorExit; 615 } 616 617 /* Namespace - Check for non-referenced objects */ 618 619 LkFindUnreferencedObjects (); 620 UtEndEvent (AslGbl_NamespaceEvent); 621 622 /* 623 * Semantic analysis. This can happen only after the 624 * namespace has been loaded and cross-referenced. 625 * 626 * part one - check control methods 627 */ 628 Event = UtBeginEvent ("Analyze control method return types"); 629 AnalysisWalkInfo.MethodStack = NULL; 630 631 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n"); 632 TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, 633 AnMethodAnalysisWalkBegin, 634 AnMethodAnalysisWalkEnd, &AnalysisWalkInfo); 635 UtEndEvent (Event); 636 637 /* Semantic error checking part two - typing of method returns */ 638 639 Event = UtBeginEvent ("Determine object types returned by methods"); 640 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing\n\n"); 641 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, 642 NULL, AnMethodTypingWalkEnd, NULL); 643 UtEndEvent (Event); 644 645 /* Semantic error checking part three - operand type checking */ 646 647 Event = UtBeginEvent ("Analyze AML operand types"); 648 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking\n\n"); 649 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, 650 NULL, AnOperandTypecheckWalkEnd, &AnalysisWalkInfo); 651 UtEndEvent (Event); 652 653 /* Semantic error checking part four - other miscellaneous checks */ 654 655 Event = UtBeginEvent ("Miscellaneous analysis"); 656 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous\n\n"); 657 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 658 AnOtherSemanticAnalysisWalkBegin, 659 NULL, &AnalysisWalkInfo); 660 UtEndEvent (Event); 661 662 /* Calculate all AML package lengths */ 663 664 Event = UtBeginEvent ("Finish AML package length generation"); 665 DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 666 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 667 LnInitLengthsWalk, NULL); 668 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 669 LnPackageLengthWalk, NULL); 670 UtEndEvent (Event); 671 672 /* Code generation - emit the AML */ 673 674 Event = UtBeginEvent ("Generate AML code and write output files"); 675 CgGenerateAmlOutput (); 676 UtEndEvent (Event); 677 678 Event = UtBeginEvent ("Write optional output files"); 679 CmDoOutputFiles (); 680 UtEndEvent (Event); 681 682 UtEndEvent (FullCompile); 683 CmCleanupAndExit (); 684 return (0); 685 686ErrorExit: 687 UtEndEvent (FullCompile); 688 CmCleanupAndExit (); 689 return (-1); 690} 691 692 693/******************************************************************************* 694 * 695 * FUNCTION: CmDoOutputFiles 696 * 697 * PARAMETERS: None 698 * 699 * RETURN: None. 700 * 701 * DESCRIPTION: Create all "listing" type files 702 * 703 ******************************************************************************/ 704 705void 706CmDoOutputFiles ( 707 void) 708{ 709 710 /* Create listings and hex files */ 711 712 LsDoListings (); 713 LsDoHexOutput (); 714 715 /* Dump the namespace to the .nsp file if requested */ 716 717 (void) LsDisplayNamespace (); 718} 719 720 721/******************************************************************************* 722 * 723 * FUNCTION: CmDumpAllEvents 724 * 725 * PARAMETERS: None 726 * 727 * RETURN: None. 728 * 729 * DESCRIPTION: Dump all compiler events 730 * 731 ******************************************************************************/ 732 733static void 734CmDumpAllEvents ( 735 void) 736{ 737 ASL_EVENT_INFO *Event; 738 UINT32 Delta; 739 UINT32 USec; 740 UINT32 MSec; 741 UINT32 i; 742 743 744 Event = AslGbl_Events; 745 746 DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n"); 747 if (Gbl_CompileTimesFlag) 748 { 749 printf ("\nElapsed time for major events\n\n"); 750 } 751 752 for (i = 0; i < AslGbl_NextEvent; i++) 753 { 754 if (Event->Valid) 755 { 756 /* Delta will be in 100-nanosecond units */ 757 758 Delta = (UINT32) (Event->EndTime - Event->StartTime); 759 760 USec = Delta / 10; 761 MSec = Delta / 10000; 762 763 /* Round milliseconds up */ 764 765 if ((USec - (MSec * 1000)) >= 500) 766 { 767 MSec++; 768 } 769 770 DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n", 771 USec, MSec, Event->EventName); 772 773 if (Gbl_CompileTimesFlag) 774 { 775 printf ("%8u usec %8u msec - %s\n", 776 USec, MSec, Event->EventName); 777 } 778 } 779 780 Event++; 781 } 782} 783 784 785/******************************************************************************* 786 * 787 * FUNCTION: CmCleanupAndExit 788 * 789 * PARAMETERS: None 790 * 791 * RETURN: None. 792 * 793 * DESCRIPTION: Close all open files and exit the compiler 794 * 795 ******************************************************************************/ 796 797void 798CmCleanupAndExit ( 799 void) 800{ 801 UINT32 i; 802 BOOLEAN DeleteAmlFile = FALSE; 803 804 805 AePrintErrorLog (ASL_FILE_STDERR); 806 if (Gbl_DebugFlag) 807 { 808 /* Print error summary to stdout also */ 809 810 AePrintErrorLog (ASL_FILE_STDOUT); 811 } 812 813 /* Emit compile times if enabled */ 814 815 CmDumpAllEvents (); 816 817 if (Gbl_CompileTimesFlag) 818 { 819 printf ("\nMiscellaneous compile statistics\n\n"); 820 printf ("%11u : %s\n", TotalParseNodes, "Parse nodes"); 821 printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches"); 822 printf ("%11u : %s\n", TotalNamedObjects, "Named objects"); 823 printf ("%11u : %s\n", TotalMethods, "Control methods"); 824 printf ("%11u : %s\n", TotalAllocations, "Memory Allocations"); 825 printf ("%11u : %s\n", TotalAllocated, "Total allocated memory"); 826 printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded"); 827 printf ("\n"); 828 } 829 830 if (Gbl_NsLookupCount) 831 { 832 DbgPrint (ASL_DEBUG_OUTPUT, 833 "\n\nMiscellaneous compile statistics\n\n"); 834 835 DbgPrint (ASL_DEBUG_OUTPUT, 836 "%32s : %u\n", "Total Namespace searches", 837 Gbl_NsLookupCount); 838 839 DbgPrint (ASL_DEBUG_OUTPUT, 840 "%32s : %u usec\n", "Time per search", ((UINT32) 841 (AslGbl_Events[AslGbl_NamespaceEvent].EndTime - 842 AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) / 843 Gbl_NsLookupCount); 844 } 845 846 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) 847 { 848 printf ("\nMaximum error count (%u) exceeded\n", 849 ASL_MAX_ERROR_COUNT); 850 } 851 852 UtDisplaySummary (ASL_FILE_STDOUT); 853 854 /* 855 * We will delete the AML file if there are errors and the 856 * force AML output option has not been used. 857 */ 858 if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors) && 859 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle) 860 { 861 DeleteAmlFile = TRUE; 862 } 863 864 /* Close all open files */ 865 866 Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL; /* the .i file is same as source file */ 867 868 for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++) 869 { 870 FlCloseFile (i); 871 } 872 873 /* Delete AML file if there are errors */ 874 875 if (DeleteAmlFile) 876 { 877 FlDeleteFile (ASL_FILE_AML_OUTPUT); 878 } 879 880 /* Delete the preprocessor output file (.i) unless -li flag is set */ 881 882 if (!Gbl_PreprocessorOutputFlag && 883 Gbl_PreprocessFlag) 884 { 885 FlDeleteFile (ASL_FILE_PREPROCESSOR); 886 } 887 888 /* 889 * Delete intermediate ("combined") source file (if -ls flag not set) 890 * This file is created during normal ASL/AML compiles. It is not 891 * created by the data table compiler. 892 * 893 * If the -ls flag is set, then the .SRC file should not be deleted. 894 * In this case, Gbl_SourceOutputFlag is set to TRUE. 895 * 896 * Note: Handles are cleared by FlCloseFile above, so we look at the 897 * filename instead, to determine if the .SRC file was actually 898 * created. 899 * 900 * TBD: SourceOutput should be .TMP, then rename if we want to keep it? 901 */ 902 if (!Gbl_SourceOutputFlag) 903 { 904 FlDeleteFile (ASL_FILE_SOURCE_OUTPUT); 905 } 906}
| 381 { 382 /* Ignore comment fields (allow non-ascii within) */ 383 384 if (OpeningComment) 385 { 386 /* Check for second comment open delimiter */ 387 388 if (Byte == '*') 389 { 390 FlConsumeAnsiComment (Handle, &Status); 391 } 392 393 if (Byte == '/') 394 { 395 FlConsumeNewComment (Handle, &Status); 396 } 397 398 /* Reset */ 399 400 OpeningComment = FALSE; 401 } 402 else if (Byte == '/') 403 { 404 OpeningComment = TRUE; 405 } 406 407 /* Check for an ASCII character */ 408 409 if (!ACPI_IS_ASCII (Byte)) 410 { 411 if ((BadBytes < 10) && (DisplayErrors)) 412 { 413 AcpiOsPrintf ( 414 "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n", 415 Byte, Status.Line, Status.Offset); 416 } 417 418 BadBytes++; 419 } 420 421 /* Update line counter */ 422 423 else if (Byte == 0x0A) 424 { 425 Status.Line++; 426 } 427 428 Status.Offset++; 429 } 430 431 /* Seek back to the beginning of the source file */ 432 433 fseek (Handle, 0, SEEK_SET); 434 435 /* Were there any non-ASCII characters in the file? */ 436 437 if (BadBytes) 438 { 439 if (DisplayErrors) 440 { 441 AcpiOsPrintf ( 442 "%u non-ASCII characters found in input source text, could be a binary file\n", 443 BadBytes); 444 AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, Filename); 445 } 446 447 return (AE_BAD_CHARACTER); 448 } 449 450 /* File is OK (100% ASCII) */ 451 452 return (AE_OK); 453} 454 455 456/******************************************************************************* 457 * 458 * FUNCTION: CmDoCompile 459 * 460 * PARAMETERS: None 461 * 462 * RETURN: Status (0 = OK) 463 * 464 * DESCRIPTION: This procedure performs the entire compile 465 * 466 ******************************************************************************/ 467 468int 469CmDoCompile ( 470 void) 471{ 472 ACPI_STATUS Status; 473 UINT8 FullCompile; 474 UINT8 Event; 475 476 477 FullCompile = UtBeginEvent ("*** Total Compile time ***"); 478 Event = UtBeginEvent ("Open input and output files"); 479 UtEndEvent (Event); 480 481 Event = UtBeginEvent ("Preprocess input file"); 482 if (Gbl_PreprocessFlag) 483 { 484 /* Preprocessor */ 485 486 PrDoPreprocess (); 487 if (Gbl_PreprocessOnly) 488 { 489 UtEndEvent (Event); 490 CmCleanupAndExit (); 491 return (0); 492 } 493 } 494 UtEndEvent (Event); 495 496 /* Build the parse tree */ 497 498 Event = UtBeginEvent ("Parse source code and build parse tree"); 499 AslCompilerparse(); 500 UtEndEvent (Event); 501 502 /* Flush out any remaining source after parse tree is complete */ 503 504 Event = UtBeginEvent ("Flush source input"); 505 CmFlushSourceCode (); 506 507 /* Did the parse tree get successfully constructed? */ 508 509 if (!RootNode) 510 { 511 /* 512 * If there are no errors, then we have some sort of 513 * internal problem. 514 */ 515 Status = AslCheckForErrorExit (); 516 if (Status == AE_OK) 517 { 518 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, 519 NULL, "- Could not resolve parse tree root node"); 520 } 521 522 goto ErrorExit; 523 } 524 525 /* Optional parse tree dump, compiler debug output only */ 526 527 LsDumpParseTree (); 528 529 OpcGetIntegerWidth (RootNode); 530 UtEndEvent (Event); 531 532 /* Pre-process parse tree for any operator transforms */ 533 534 Event = UtBeginEvent ("Parse tree transforms"); 535 DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n"); 536 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 537 TrAmlTransformWalk, NULL, NULL); 538 UtEndEvent (Event); 539 540 /* Generate AML opcodes corresponding to the parse tokens */ 541 542 Event = UtBeginEvent ("Generate AML opcodes"); 543 DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n"); 544 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 545 OpcAmlOpcodeWalk, NULL); 546 UtEndEvent (Event); 547 548 /* 549 * Now that the input is parsed, we can open the AML output file. 550 * Note: by default, the name of this file comes from the table descriptor 551 * within the input file. 552 */ 553 Event = UtBeginEvent ("Open AML output file"); 554 Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix); 555 UtEndEvent (Event); 556 if (ACPI_FAILURE (Status)) 557 { 558 AePrintErrorLog (ASL_FILE_STDERR); 559 return (-1); 560 } 561 562 /* Interpret and generate all compile-time constants */ 563 564 Event = UtBeginEvent ("Constant folding via AML interpreter"); 565 DbgPrint (ASL_DEBUG_OUTPUT, 566 "\nInterpreting compile-time constant expressions\n\n"); 567 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 568 OpcAmlConstantWalk, NULL, NULL); 569 UtEndEvent (Event); 570 571 /* Update AML opcodes if necessary, after constant folding */ 572 573 Event = UtBeginEvent ("Updating AML opcodes after constant folding"); 574 DbgPrint (ASL_DEBUG_OUTPUT, 575 "\nUpdating AML opcodes after constant folding\n\n"); 576 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, 577 NULL, OpcAmlOpcodeUpdateWalk, NULL); 578 UtEndEvent (Event); 579 580 /* Calculate all AML package lengths */ 581 582 Event = UtBeginEvent ("Generate AML package lengths"); 583 DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 584 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 585 LnPackageLengthWalk, NULL); 586 UtEndEvent (Event); 587 588 if (Gbl_ParseOnlyFlag) 589 { 590 AePrintErrorLog (ASL_FILE_STDERR); 591 UtDisplaySummary (ASL_FILE_STDERR); 592 if (Gbl_DebugFlag) 593 { 594 /* Print error summary to the stdout also */ 595 596 AePrintErrorLog (ASL_FILE_STDOUT); 597 UtDisplaySummary (ASL_FILE_STDOUT); 598 } 599 UtEndEvent (FullCompile); 600 return (0); 601 } 602 603 /* 604 * Create an internal namespace and use it as a symbol table 605 */ 606 607 /* Namespace loading */ 608 609 Event = UtBeginEvent ("Create ACPI Namespace"); 610 Status = LdLoadNamespace (RootNode); 611 UtEndEvent (Event); 612 if (ACPI_FAILURE (Status)) 613 { 614 goto ErrorExit; 615 } 616 617 /* Namespace cross-reference */ 618 619 AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace"); 620 Status = LkCrossReferenceNamespace (); 621 if (ACPI_FAILURE (Status)) 622 { 623 goto ErrorExit; 624 } 625 626 /* Namespace - Check for non-referenced objects */ 627 628 LkFindUnreferencedObjects (); 629 UtEndEvent (AslGbl_NamespaceEvent); 630 631 /* 632 * Semantic analysis. This can happen only after the 633 * namespace has been loaded and cross-referenced. 634 * 635 * part one - check control methods 636 */ 637 Event = UtBeginEvent ("Analyze control method return types"); 638 AnalysisWalkInfo.MethodStack = NULL; 639 640 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n"); 641 TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, 642 AnMethodAnalysisWalkBegin, 643 AnMethodAnalysisWalkEnd, &AnalysisWalkInfo); 644 UtEndEvent (Event); 645 646 /* Semantic error checking part two - typing of method returns */ 647 648 Event = UtBeginEvent ("Determine object types returned by methods"); 649 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing\n\n"); 650 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, 651 NULL, AnMethodTypingWalkEnd, NULL); 652 UtEndEvent (Event); 653 654 /* Semantic error checking part three - operand type checking */ 655 656 Event = UtBeginEvent ("Analyze AML operand types"); 657 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking\n\n"); 658 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, 659 NULL, AnOperandTypecheckWalkEnd, &AnalysisWalkInfo); 660 UtEndEvent (Event); 661 662 /* Semantic error checking part four - other miscellaneous checks */ 663 664 Event = UtBeginEvent ("Miscellaneous analysis"); 665 DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous\n\n"); 666 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, 667 AnOtherSemanticAnalysisWalkBegin, 668 NULL, &AnalysisWalkInfo); 669 UtEndEvent (Event); 670 671 /* Calculate all AML package lengths */ 672 673 Event = UtBeginEvent ("Finish AML package length generation"); 674 DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); 675 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 676 LnInitLengthsWalk, NULL); 677 TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, 678 LnPackageLengthWalk, NULL); 679 UtEndEvent (Event); 680 681 /* Code generation - emit the AML */ 682 683 Event = UtBeginEvent ("Generate AML code and write output files"); 684 CgGenerateAmlOutput (); 685 UtEndEvent (Event); 686 687 Event = UtBeginEvent ("Write optional output files"); 688 CmDoOutputFiles (); 689 UtEndEvent (Event); 690 691 UtEndEvent (FullCompile); 692 CmCleanupAndExit (); 693 return (0); 694 695ErrorExit: 696 UtEndEvent (FullCompile); 697 CmCleanupAndExit (); 698 return (-1); 699} 700 701 702/******************************************************************************* 703 * 704 * FUNCTION: CmDoOutputFiles 705 * 706 * PARAMETERS: None 707 * 708 * RETURN: None. 709 * 710 * DESCRIPTION: Create all "listing" type files 711 * 712 ******************************************************************************/ 713 714void 715CmDoOutputFiles ( 716 void) 717{ 718 719 /* Create listings and hex files */ 720 721 LsDoListings (); 722 LsDoHexOutput (); 723 724 /* Dump the namespace to the .nsp file if requested */ 725 726 (void) LsDisplayNamespace (); 727} 728 729 730/******************************************************************************* 731 * 732 * FUNCTION: CmDumpAllEvents 733 * 734 * PARAMETERS: None 735 * 736 * RETURN: None. 737 * 738 * DESCRIPTION: Dump all compiler events 739 * 740 ******************************************************************************/ 741 742static void 743CmDumpAllEvents ( 744 void) 745{ 746 ASL_EVENT_INFO *Event; 747 UINT32 Delta; 748 UINT32 USec; 749 UINT32 MSec; 750 UINT32 i; 751 752 753 Event = AslGbl_Events; 754 755 DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n"); 756 if (Gbl_CompileTimesFlag) 757 { 758 printf ("\nElapsed time for major events\n\n"); 759 } 760 761 for (i = 0; i < AslGbl_NextEvent; i++) 762 { 763 if (Event->Valid) 764 { 765 /* Delta will be in 100-nanosecond units */ 766 767 Delta = (UINT32) (Event->EndTime - Event->StartTime); 768 769 USec = Delta / 10; 770 MSec = Delta / 10000; 771 772 /* Round milliseconds up */ 773 774 if ((USec - (MSec * 1000)) >= 500) 775 { 776 MSec++; 777 } 778 779 DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n", 780 USec, MSec, Event->EventName); 781 782 if (Gbl_CompileTimesFlag) 783 { 784 printf ("%8u usec %8u msec - %s\n", 785 USec, MSec, Event->EventName); 786 } 787 } 788 789 Event++; 790 } 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 806void 807CmCleanupAndExit ( 808 void) 809{ 810 UINT32 i; 811 BOOLEAN DeleteAmlFile = FALSE; 812 813 814 AePrintErrorLog (ASL_FILE_STDERR); 815 if (Gbl_DebugFlag) 816 { 817 /* Print error summary to stdout also */ 818 819 AePrintErrorLog (ASL_FILE_STDOUT); 820 } 821 822 /* Emit compile times if enabled */ 823 824 CmDumpAllEvents (); 825 826 if (Gbl_CompileTimesFlag) 827 { 828 printf ("\nMiscellaneous compile statistics\n\n"); 829 printf ("%11u : %s\n", TotalParseNodes, "Parse nodes"); 830 printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches"); 831 printf ("%11u : %s\n", TotalNamedObjects, "Named objects"); 832 printf ("%11u : %s\n", TotalMethods, "Control methods"); 833 printf ("%11u : %s\n", TotalAllocations, "Memory Allocations"); 834 printf ("%11u : %s\n", TotalAllocated, "Total allocated memory"); 835 printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded"); 836 printf ("\n"); 837 } 838 839 if (Gbl_NsLookupCount) 840 { 841 DbgPrint (ASL_DEBUG_OUTPUT, 842 "\n\nMiscellaneous compile statistics\n\n"); 843 844 DbgPrint (ASL_DEBUG_OUTPUT, 845 "%32s : %u\n", "Total Namespace searches", 846 Gbl_NsLookupCount); 847 848 DbgPrint (ASL_DEBUG_OUTPUT, 849 "%32s : %u usec\n", "Time per search", ((UINT32) 850 (AslGbl_Events[AslGbl_NamespaceEvent].EndTime - 851 AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) / 852 Gbl_NsLookupCount); 853 } 854 855 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) 856 { 857 printf ("\nMaximum error count (%u) exceeded\n", 858 ASL_MAX_ERROR_COUNT); 859 } 860 861 UtDisplaySummary (ASL_FILE_STDOUT); 862 863 /* 864 * We will delete the AML file if there are errors and the 865 * force AML output option has not been used. 866 */ 867 if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors) && 868 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle) 869 { 870 DeleteAmlFile = TRUE; 871 } 872 873 /* Close all open files */ 874 875 Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL; /* the .i file is same as source file */ 876 877 for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++) 878 { 879 FlCloseFile (i); 880 } 881 882 /* Delete AML file if there are errors */ 883 884 if (DeleteAmlFile) 885 { 886 FlDeleteFile (ASL_FILE_AML_OUTPUT); 887 } 888 889 /* Delete the preprocessor output file (.i) unless -li flag is set */ 890 891 if (!Gbl_PreprocessorOutputFlag && 892 Gbl_PreprocessFlag) 893 { 894 FlDeleteFile (ASL_FILE_PREPROCESSOR); 895 } 896 897 /* 898 * Delete intermediate ("combined") source file (if -ls flag not set) 899 * This file is created during normal ASL/AML compiles. It is not 900 * created by the data table compiler. 901 * 902 * If the -ls flag is set, then the .SRC file should not be deleted. 903 * In this case, Gbl_SourceOutputFlag is set to TRUE. 904 * 905 * Note: Handles are cleared by FlCloseFile above, so we look at the 906 * filename instead, to determine if the .SRC file was actually 907 * created. 908 * 909 * TBD: SourceOutput should be .TMP, then rename if we want to keep it? 910 */ 911 if (!Gbl_SourceOutputFlag) 912 { 913 FlDeleteFile (ASL_FILE_SOURCE_OUTPUT); 914 } 915}
|