Sync usage with man page.
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / compiler / aslcompile.c
blob07de1fe63c9b2dc9b1780e786aa8e0d54533efde
2 /******************************************************************************
4 * Module Name: aslcompile - top level compile module
6 *****************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13 * All rights reserved.
15 * 2. License
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.
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
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;
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
41 * 3. Conditions
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.
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.
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.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
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.
81 * 4. Disclaimer and Export Compliance
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.
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.
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.
115 *****************************************************************************/
117 #include <stdio.h>
118 #include <time.h>
119 #include "aslcompiler.h"
121 #define _COMPONENT ACPI_COMPILER
122 ACPI_MODULE_NAME ("aslcompile")
124 /* Local prototypes */
126 static void
127 CmFlushSourceCode (
128 void);
130 static ACPI_STATUS
131 FlCheckForAscii (
132 ASL_FILE_INFO *FileInfo);
134 void
135 FlConsumeAnsiComment (
136 ASL_FILE_INFO *FileInfo,
137 ASL_FILE_STATUS *Status);
139 void
140 FlConsumeNewComment (
141 ASL_FILE_INFO *FileInfo,
142 ASL_FILE_STATUS *Status);
145 /*******************************************************************************
147 * FUNCTION: AslCompilerSignon
149 * PARAMETERS: FileId - ID of the output file
151 * RETURN: None
153 * DESCRIPTION: Display compiler signon
155 ******************************************************************************/
157 void
158 AslCompilerSignon (
159 UINT32 FileId)
161 char *Prefix = "";
164 /* Set line prefix depending on the destination file type */
166 switch (FileId)
168 case ASL_FILE_ASM_SOURCE_OUTPUT:
169 case ASL_FILE_ASM_INCLUDE_OUTPUT:
171 Prefix = "; ";
172 break;
174 case ASL_FILE_HEX_OUTPUT:
176 if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
178 Prefix = "; ";
180 else if (Gbl_HexOutputFlag == HEX_OUTPUT_C)
182 FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
183 Prefix = " * ";
185 break;
187 case ASL_FILE_C_SOURCE_OUTPUT:
188 case ASL_FILE_C_INCLUDE_OUTPUT:
190 Prefix = " * ";
191 break;
193 default:
194 /* No other output types supported */
195 break;
199 * Compiler signon with copyright
201 FlPrintFile (FileId,
202 "%s\n%s%s\n%s",
203 Prefix,
204 Prefix, IntelAcpiCA,
205 Prefix);
207 /* Running compiler or disassembler? */
209 if (Gbl_DisasmFlag)
211 FlPrintFile (FileId,
212 "%s", DisassemblerId);
214 else
216 FlPrintFile (FileId,
217 "%s", CompilerId);
220 /* Version, build date, copyright, compliance */
222 FlPrintFile (FileId,
223 " version %X [%s]\n%s%s\n%s%s\n%s\n",
224 (UINT32) ACPI_CA_VERSION, __DATE__,
225 Prefix, CompilerCopyright,
226 Prefix, CompilerCompliance,
227 Prefix);
231 /*******************************************************************************
233 * FUNCTION: AslCompilerFileHeader
235 * PARAMETERS: FileId - ID of the output file
237 * RETURN: None
239 * DESCRIPTION: Header used at the beginning of output files
241 ******************************************************************************/
243 void
244 AslCompilerFileHeader (
245 UINT32 FileId)
247 struct tm *NewTime;
248 time_t Aclock;
249 char *Prefix = "";
252 /* Set line prefix depending on the destination file type */
254 switch (FileId)
256 case ASL_FILE_ASM_SOURCE_OUTPUT:
257 case ASL_FILE_ASM_INCLUDE_OUTPUT:
259 Prefix = "; ";
260 break;
262 case ASL_FILE_HEX_OUTPUT:
264 if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
266 Prefix = "; ";
268 else if (Gbl_HexOutputFlag == HEX_OUTPUT_C)
270 Prefix = " * ";
272 break;
274 case ASL_FILE_C_SOURCE_OUTPUT:
275 case ASL_FILE_C_INCLUDE_OUTPUT:
277 Prefix = " * ";
278 break;
280 default:
281 /* No other output types supported */
282 break;
285 /* Compilation header with timestamp */
287 (void) time (&Aclock);
288 NewTime = localtime (&Aclock);
290 FlPrintFile (FileId,
291 "%sCompilation of \"%s\" - %s%s\n",
292 Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime),
293 Prefix);
295 switch (FileId)
297 case ASL_FILE_C_SOURCE_OUTPUT:
298 case ASL_FILE_C_INCLUDE_OUTPUT:
299 FlPrintFile (FileId, " */\n");
300 break;
302 default:
303 /* Nothing to do for other output types */
304 break;
309 /*******************************************************************************
311 * FUNCTION: CmFlushSourceCode
313 * PARAMETERS: None
315 * RETURN: None
317 * DESCRIPTION: Read in any remaining source code after the parse tree
318 * has been constructed.
320 ******************************************************************************/
322 static void
323 CmFlushSourceCode (
324 void)
326 char Buffer;
329 while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)
331 InsertLineBuffer ((int) Buffer);
334 ResetCurrentLineBuffer ();
338 /*******************************************************************************
340 * FUNCTION: FlConsume*
342 * PARAMETERS: FileInfo - Points to an open input file
344 * RETURN: Number of lines consumed
346 * DESCRIPTION: Step over both types of comment during check for ascii chars
348 ******************************************************************************/
350 void
351 FlConsumeAnsiComment (
352 ASL_FILE_INFO *FileInfo,
353 ASL_FILE_STATUS *Status)
355 UINT8 Byte;
356 BOOLEAN ClosingComment = FALSE;
359 while (fread (&Byte, 1, 1, FileInfo->Handle))
361 /* Scan until comment close is found */
363 if (ClosingComment)
365 if (Byte == '/')
367 return;
370 if (Byte != '*')
372 /* Reset */
374 ClosingComment = FALSE;
377 else if (Byte == '*')
379 ClosingComment = TRUE;
382 /* Maintain line count */
384 if (Byte == 0x0A)
386 Status->Line++;
389 Status->Offset++;
394 void
395 FlConsumeNewComment (
396 ASL_FILE_INFO *FileInfo,
397 ASL_FILE_STATUS *Status)
399 UINT8 Byte;
402 while (fread (&Byte, 1, 1, FileInfo->Handle))
404 Status->Offset++;
406 /* Comment ends at newline */
408 if (Byte == 0x0A)
410 Status->Line++;
411 return;
417 /*******************************************************************************
419 * FUNCTION: FlCheckForAscii
421 * PARAMETERS: FileInfo - Points to an open input file
423 * RETURN: Status
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.
432 ******************************************************************************/
434 static ACPI_STATUS
435 FlCheckForAscii (
436 ASL_FILE_INFO *FileInfo)
438 UINT8 Byte;
439 ACPI_SIZE BadBytes = 0;
440 BOOLEAN OpeningComment = FALSE;
441 ASL_FILE_STATUS Status;
444 Status.Line = 1;
445 Status.Offset = 0;
447 /* Read the entire file */
449 while (fread (&Byte, 1, 1, FileInfo->Handle))
451 /* Ignore comment fields (allow non-ascii within) */
453 if (OpeningComment)
455 /* Check for second comment open delimiter */
457 if (Byte == '*')
459 FlConsumeAnsiComment (FileInfo, &Status);
462 if (Byte == '/')
464 FlConsumeNewComment (FileInfo, &Status);
467 /* Reset */
469 OpeningComment = FALSE;
471 else if (Byte == '/')
473 OpeningComment = TRUE;
476 /* Check for an ASCII character */
478 if (!ACPI_IS_ASCII (Byte))
480 if (BadBytes < 10)
482 AcpiOsPrintf (
483 "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n",
484 Byte, Status.Line, Status.Offset);
487 BadBytes++;
490 /* Update line counter */
492 else if (Byte == 0x0A)
494 Status.Line++;
497 Status.Offset++;
500 /* Seek back to the beginning of the source file */
502 fseek (FileInfo->Handle, 0, SEEK_SET);
504 /* Were there any non-ASCII characters in the file? */
506 if (BadBytes)
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);
515 /* File is OK */
517 return (AE_OK);
521 /*******************************************************************************
523 * FUNCTION: CmDoCompile
525 * PARAMETERS: None
527 * RETURN: Status (0 = OK)
529 * DESCRIPTION: This procedure performs the entire compile
531 ******************************************************************************/
534 CmDoCompile (
535 void)
537 ACPI_STATUS Status;
538 UINT8 FullCompile;
539 UINT8 Event;
542 FullCompile = UtBeginEvent ("*** Total Compile time ***");
543 Event = UtBeginEvent ("Open input and output files");
545 /* Open the required input and output files */
547 Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename);
548 if (ACPI_FAILURE (Status))
550 AePrintErrorLog (ASL_FILE_STDERR);
551 return -1;
554 /* Check for 100% ASCII source file (comments are ignored) */
556 Status = FlCheckForAscii (&Gbl_Files[ASL_FILE_INPUT]);
557 if (ACPI_FAILURE (Status))
559 AePrintErrorLog (ASL_FILE_STDERR);
560 return -1;
563 Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
564 if (ACPI_FAILURE (Status))
566 AePrintErrorLog (ASL_FILE_STDERR);
567 return -1;
569 UtEndEvent (Event);
571 /* Build the parse tree */
573 Event = UtBeginEvent ("Parse source code and build parse tree");
574 AslCompilerparse();
575 UtEndEvent (Event);
577 /* Flush out any remaining source after parse tree is complete */
579 Event = UtBeginEvent ("Flush source input");
580 CmFlushSourceCode ();
582 /* Did the parse tree get successfully constructed? */
584 if (!RootNode)
586 CmCleanupAndExit ();
587 return -1;
590 /* Optional parse tree dump, compiler debug output only */
592 LsDumpParseTree ();
594 OpcGetIntegerWidth (RootNode);
595 UtEndEvent (Event);
597 /* Pre-process parse tree for any operator transforms */
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);
605 /* Generate AML opcodes corresponding to the parse tokens */
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);
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.
618 Event = UtBeginEvent ("Open AML output file");
619 Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
620 if (ACPI_FAILURE (Status))
622 AePrintErrorLog (ASL_FILE_STDERR);
623 return -1;
625 UtEndEvent (Event);
627 /* Interpret and generate all compile-time constants */
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);
636 /* Update AML opcodes if necessary, after constant folding */
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);
645 /* Calculate all AML package lengths */
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);
653 if (Gbl_ParseOnlyFlag)
655 AePrintErrorLog (ASL_FILE_STDOUT);
656 UtDisplaySummary (ASL_FILE_STDOUT);
657 if (Gbl_DebugFlag)
659 /* Print error summary to the debug file */
661 AePrintErrorLog (ASL_FILE_STDERR);
662 UtDisplaySummary (ASL_FILE_STDERR);
664 return 0;
668 * Create an internal namespace and use it as a symbol table
671 /* Namespace loading */
673 Event = UtBeginEvent ("Create ACPI Namespace");
674 Status = LdLoadNamespace (RootNode);
675 UtEndEvent (Event);
676 if (ACPI_FAILURE (Status))
678 return -1;
681 /* Namespace cross-reference */
683 AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace");
684 Status = LkCrossReferenceNamespace ();
685 if (ACPI_FAILURE (Status))
687 return -1;
690 /* Namespace - Check for non-referenced objects */
692 LkFindUnreferencedObjects ();
693 UtEndEvent (AslGbl_NamespaceEvent);
696 * Semantic analysis. This can happen only after the
697 * namespace has been loaded and cross-referenced.
699 * part one - check control methods
701 Event = UtBeginEvent ("Analyze control method return types");
702 AnalysisWalkInfo.MethodStack = NULL;
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);
710 /* Semantic error checking part two - typing of method returns */
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);
719 /* Semantic error checking part three - operand type checking */
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);
728 /* Semantic error checking part four - other miscellaneous checks */
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);
737 /* Calculate all AML package lengths */
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);
747 /* Code generation - emit the AML */
749 Event = UtBeginEvent ("Generate AML code and write output files");
750 CgGenerateAmlOutput ();
751 UtEndEvent (Event);
753 Event = UtBeginEvent ("Write optional output files");
754 CmDoOutputFiles ();
755 UtEndEvent (Event);
757 UtEndEvent (FullCompile);
758 CmCleanupAndExit ();
759 return 0;
763 /*******************************************************************************
765 * FUNCTION: CmDoOutputFiles
767 * PARAMETERS: None
769 * RETURN: None.
771 * DESCRIPTION: Create all "listing" type files
773 ******************************************************************************/
775 void
776 CmDoOutputFiles (
777 void)
780 /* Create listings and hex files */
782 LsDoListings ();
783 LsDoHexOutput ();
785 /* Dump the namespace to the .nsp file if requested */
787 (void) LsDisplayNamespace ();
791 /*******************************************************************************
793 * FUNCTION: CmDumpEvent
795 * PARAMETERS: Event - A compiler event struct
797 * RETURN: None.
799 * DESCRIPTION: Dump a compiler event struct
801 ******************************************************************************/
803 static void
804 CmDumpEvent (
805 ASL_EVENT_INFO *Event)
807 UINT32 Delta;
808 UINT32 USec;
809 UINT32 MSec;
811 if (!Event->Valid)
813 return;
816 /* Delta will be in 100-nanosecond units */
818 Delta = (UINT32) (Event->EndTime - Event->StartTime);
820 USec = Delta / 10;
821 MSec = Delta / 10000;
823 /* Round milliseconds up */
825 if ((USec - (MSec * 1000)) >= 500)
827 MSec++;
830 DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",
831 USec, MSec, Event->EventName);
835 /*******************************************************************************
837 * FUNCTION: CmCleanupAndExit
839 * PARAMETERS: None
841 * RETURN: None.
843 * DESCRIPTION: Close all open files and exit the compiler
845 ******************************************************************************/
847 void
848 CmCleanupAndExit (
849 void)
851 UINT32 i;
854 AePrintErrorLog (ASL_FILE_STDOUT);
855 if (Gbl_DebugFlag)
857 /* Print error summary to the debug file */
859 AePrintErrorLog (ASL_FILE_STDERR);
862 DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");
863 for (i = 0; i < AslGbl_NextEvent; i++)
865 CmDumpEvent (&AslGbl_Events[i]);
868 if (Gbl_CompileTimesFlag)
870 printf ("\nElapsed time for major events\n\n");
871 for (i = 0; i < AslGbl_NextEvent; i++)
873 CmDumpEvent (&AslGbl_Events[i]);
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");
887 if (Gbl_NsLookupCount)
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);
898 /* Close all open files */
900 for (i = 2; i < ASL_MAX_FILE_TYPE; i++)
902 FlCloseFile (i);
906 * TBD: SourceOutput should be .TMP, then rename if we want to keep it?
908 if (!Gbl_SourceOutputFlag)
910 remove (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
913 /* Delete AML file if there are errors */
915 if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors))
917 remove (Gbl_Files[ASL_FILE_AML_OUTPUT].Filename);
920 if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
922 printf ("\nMaximum error count (%d) exceeded\n", ASL_MAX_ERROR_COUNT);
925 UtDisplaySummary (ASL_FILE_STDOUT);