1 /******************************************************************************
2  *
3  * Module Name: aslcompile - top level compile module
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2016, 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 "aslcompiler.h"
45 #include "dtcompiler.h"
46 #include "acnamesp.h"
47 
48 #include <stdio.h>
49 #include <time.h>
50 #include <acapps.h>
51 
52 #define _COMPONENT          ACPI_COMPILER
53         ACPI_MODULE_NAME    ("aslcompile")
54 
55 /*
56  * Main parser entry
57  * External is here in case the parser emits the same external in the
58  * generated header. (Newer versions of Bison)
59  */
60 int
61 AslCompilerparse(
62     void);
63 
64 /* Local prototypes */
65 
66 static void
67 CmFlushSourceCode (
68     void);
69 
70 static void
71 CmDumpAllEvents (
72     void);
73 
74 
75 /*******************************************************************************
76  *
77  * FUNCTION:    CmDoCompile
78  *
79  * PARAMETERS:  None
80  *
81  * RETURN:      Status (0 = OK)
82  *
83  * DESCRIPTION: This procedure performs the entire compile
84  *
85  ******************************************************************************/
86 
87 int
88 CmDoCompile (
89     void)
90 {
91     ACPI_STATUS             Status;
92     UINT8                   FullCompile;
93     UINT8                   Event;
94 
95 
96     FullCompile = UtBeginEvent ("*** Total Compile time ***");
97     Event = UtBeginEvent ("Open input and output files");
98     UtEndEvent (Event);
99 
100     Event = UtBeginEvent ("Preprocess input file");
101     if (Gbl_PreprocessFlag)
102     {
103         /* Enter compiler name as a #define */
104 
105         PrAddDefine (ASL_DEFINE, "", FALSE);
106 
107         /* Preprocessor */
108 
109         PrDoPreprocess ();
110         Gbl_CurrentLineNumber = 1;
111         Gbl_LogicalLineNumber = 1;
112 
113         if (Gbl_PreprocessOnly)
114         {
115             UtEndEvent (Event);
116             CmCleanupAndExit ();
117             return (0);
118         }
119     }
120     UtEndEvent (Event);
121 
122 
123     /* Build the parse tree */
124 
125     Event = UtBeginEvent ("Parse source code and build parse tree");
126     AslCompilerparse();
127     UtEndEvent (Event);
128 
129     /* Check for parser-detected syntax errors */
130 
131     if (Gbl_SyntaxError)
132     {
133         fprintf (stderr,
134             "Compiler aborting due to parser-detected syntax error(s)\n");
135         LsDumpParseTree ();
136         goto ErrorExit;
137     }
138 
139     /* Did the parse tree get successfully constructed? */
140 
141     if (!Gbl_ParseTreeRoot)
142     {
143         /*
144          * If there are no errors, then we have some sort of
145          * internal problem.
146          */
147         AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
148             NULL, "- Could not resolve parse tree root node");
149 
150         goto ErrorExit;
151     }
152 
153     /* Flush out any remaining source after parse tree is complete */
154 
155     Event = UtBeginEvent ("Flush source input");
156     CmFlushSourceCode ();
157 
158     /* Prune the parse tree if requested (debug purposes only) */
159 
160     if (Gbl_PruneParseTree)
161     {
162         AslPruneParseTree (Gbl_PruneDepth, Gbl_PruneType);
163     }
164 
165     /* Optional parse tree dump, compiler debug output only */
166 
167     LsDumpParseTree ();
168 
169     OpcGetIntegerWidth (Gbl_ParseTreeRoot->Asl.Child);
170     UtEndEvent (Event);
171 
172     /* Pre-process parse tree for any operator transforms */
173 
174     Event = UtBeginEvent ("Parse tree transforms");
175     DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n");
176     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
177         TrAmlTransformWalkBegin, TrAmlTransformWalkEnd, NULL);
178     UtEndEvent (Event);
179 
180     /* Generate AML opcodes corresponding to the parse tokens */
181 
182     Event = UtBeginEvent ("Generate AML opcodes");
183     DbgPrint (ASL_DEBUG_OUTPUT, "Generating AML opcodes\n\n");
184     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
185         OpcAmlOpcodeWalk, NULL);
186     UtEndEvent (Event);
187 
188     /*
189      * Now that the input is parsed, we can open the AML output file.
190      * Note: by default, the name of this file comes from the table
191      * descriptor within the input file.
192      */
193     Event = UtBeginEvent ("Open AML output file");
194     Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
195     UtEndEvent (Event);
196     if (ACPI_FAILURE (Status))
197     {
198         AePrintErrorLog (ASL_FILE_STDERR);
199         return (-1);
200     }
201 
202     /* Interpret and generate all compile-time constants */
203 
204     Event = UtBeginEvent ("Constant folding via AML interpreter");
205     DbgPrint (ASL_DEBUG_OUTPUT,
206         "Interpreting compile-time constant expressions\n\n");
207 
208     if (Gbl_FoldConstants)
209     {
210         TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
211             OpcAmlConstantWalk, NULL, NULL);
212     }
213     else
214     {
215         DbgPrint (ASL_PARSE_OUTPUT, "    Optional folding disabled\n");
216     }
217     UtEndEvent (Event);
218 
219     /* Update AML opcodes if necessary, after constant folding */
220 
221     Event = UtBeginEvent ("Updating AML opcodes after constant folding");
222     DbgPrint (ASL_DEBUG_OUTPUT,
223         "Updating AML opcodes after constant folding\n\n");
224     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
225         NULL, OpcAmlOpcodeUpdateWalk, NULL);
226     UtEndEvent (Event);
227 
228     /* Calculate all AML package lengths */
229 
230     Event = UtBeginEvent ("Generate AML package lengths");
231     DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");
232     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
233         LnPackageLengthWalk, NULL);
234     UtEndEvent (Event);
235 
236     if (Gbl_ParseOnlyFlag)
237     {
238         AePrintErrorLog (ASL_FILE_STDERR);
239         UtDisplaySummary (ASL_FILE_STDERR);
240         if (Gbl_DebugFlag)
241         {
242             /* Print error summary to the stdout also */
243 
244             AePrintErrorLog (ASL_FILE_STDOUT);
245             UtDisplaySummary (ASL_FILE_STDOUT);
246         }
247         UtEndEvent (FullCompile);
248         return (0);
249     }
250 
251     /*
252      * Create an internal namespace and use it as a symbol table
253      */
254 
255     /* Namespace loading */
256 
257     Event = UtBeginEvent ("Create ACPI Namespace");
258     DbgPrint (ASL_DEBUG_OUTPUT, "Creating ACPI Namespace\n\n");
259     Status = LdLoadNamespace (Gbl_ParseTreeRoot);
260     UtEndEvent (Event);
261     if (ACPI_FAILURE (Status))
262     {
263         goto ErrorExit;
264     }
265 
266     /* Namespace cross-reference */
267 
268     AslGbl_NamespaceEvent = UtBeginEvent (
269         "Cross reference parse tree and Namespace");
270     DbgPrint (ASL_DEBUG_OUTPUT, "Cross referencing namespace\n\n");
271     Status = XfCrossReferenceNamespace ();
272     if (ACPI_FAILURE (Status))
273     {
274         goto ErrorExit;
275     }
276 
277     /* Namespace - Check for non-referenced objects */
278 
279     LkFindUnreferencedObjects ();
280     UtEndEvent (AslGbl_NamespaceEvent);
281 
282     /* Resolve External Declarations */
283 
284     Event = UtBeginEvent ("Resolve all Externals");
285     DbgPrint (ASL_DEBUG_OUTPUT, "\nResolve Externals\n\n");
286     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
287         ExAmlExternalWalkBegin, ExAmlExternalWalkEnd, NULL);
288     UtEndEvent (Event);
289 
290     /*
291      * Semantic analysis. This can happen only after the
292      * namespace has been loaded and cross-referenced.
293      *
294      * part one - check control methods
295      */
296     Event = UtBeginEvent ("Analyze control method return types");
297     AnalysisWalkInfo.MethodStack = NULL;
298 
299     DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method analysis\n\n");
300 
301     if (Gbl_CrossReferenceOutput)
302     {
303         OtPrintHeaders ("Part 1: Object Reference Map "
304             "(Object references from within each control method)");
305     }
306 
307     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
308         MtMethodAnalysisWalkBegin,
309         MtMethodAnalysisWalkEnd, &AnalysisWalkInfo);
310     UtEndEvent (Event);
311 
312     /* Generate the object cross-reference file if requested */
313 
314     Event = UtBeginEvent ("Generate cross-reference file");
315     OtCreateXrefFile ();
316     UtEndEvent (Event);
317 
318     /* Semantic error checking part two - typing of method returns */
319 
320     Event = UtBeginEvent ("Determine object types returned by methods");
321     DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method typing\n\n");
322     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
323         NULL, AnMethodTypingWalkEnd, NULL);
324     UtEndEvent (Event);
325 
326     /* Semantic error checking part three - operand type checking */
327 
328     Event = UtBeginEvent ("Analyze AML operand types");
329     DbgPrint (ASL_DEBUG_OUTPUT,
330         "Semantic analysis - Operand type checking\n\n");
331     if (Gbl_DoTypechecking)
332     {
333         TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
334             NULL, AnOperandTypecheckWalkEnd, &AnalysisWalkInfo);
335     }
336     UtEndEvent (Event);
337 
338     /* Semantic error checking part four - other miscellaneous checks */
339 
340     Event = UtBeginEvent ("Miscellaneous analysis");
341     DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - miscellaneous\n\n");
342     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
343         AnOtherSemanticAnalysisWalkBegin,
344         NULL, &AnalysisWalkInfo);
345     UtEndEvent (Event);
346 
347     /* Calculate all AML package lengths */
348 
349     Event = UtBeginEvent ("Finish AML package length generation");
350     DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");
351     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
352         LnInitLengthsWalk, NULL);
353     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
354         LnPackageLengthWalk, NULL);
355     UtEndEvent (Event);
356 
357     /* Code generation - emit the AML */
358 
359     Event = UtBeginEvent ("Generate AML code and write output files");
360     DbgPrint (ASL_DEBUG_OUTPUT, "Writing AML byte code\n\n");
361     CgGenerateAmlOutput ();
362     UtEndEvent (Event);
363 
364     Event = UtBeginEvent ("Write optional output files");
365     CmDoOutputFiles ();
366     UtEndEvent (Event);
367 
368     UtEndEvent (FullCompile);
369     CmCleanupAndExit ();
370     return (0);
371 
372 ErrorExit:
373     UtEndEvent (FullCompile);
374     CmCleanupAndExit ();
375     return (-1);
376 }
377 
378 
379 /*******************************************************************************
380  *
381  * FUNCTION:    AslCompilerSignon
382  *
383  * PARAMETERS:  FileId      - ID of the output file
384  *
385  * RETURN:      None
386  *
387  * DESCRIPTION: Display compiler signon
388  *
389  ******************************************************************************/
390 
391 void
392 AslCompilerSignon (
393     UINT32                  FileId)
394 {
395     char                    *Prefix = "";
396     char                    *UtilityName;
397 
398 
399     /* Set line prefix depending on the destination file type */
400 
401     switch (FileId)
402     {
403     case ASL_FILE_ASM_SOURCE_OUTPUT:
404     case ASL_FILE_ASM_INCLUDE_OUTPUT:
405 
406         Prefix = "; ";
407         break;
408 
409     case ASL_FILE_HEX_OUTPUT:
410 
411         if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
412         {
413             Prefix = "; ";
414         }
415         else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
416                  (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
417         {
418             FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
419             Prefix = " * ";
420         }
421         break;
422 
423     case ASL_FILE_C_SOURCE_OUTPUT:
424     case ASL_FILE_C_OFFSET_OUTPUT:
425     case ASL_FILE_C_INCLUDE_OUTPUT:
426 
427         Prefix = " * ";
428         break;
429 
430     default:
431 
432         /* No other output types supported */
433 
434         break;
435     }
436 
437     /* Running compiler or disassembler? */
438 
439     if (Gbl_DisasmFlag)
440     {
441         UtilityName = AML_DISASSEMBLER_NAME;
442     }
443     else
444     {
445         UtilityName = ASL_COMPILER_NAME;
446     }
447 
448     /* Compiler signon with copyright */
449 
450     FlPrintFile (FileId, "%s\n", Prefix);
451     FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix));
452 }
453 
454 
455 /*******************************************************************************
456  *
457  * FUNCTION:    AslCompilerFileHeader
458  *
459  * PARAMETERS:  FileId      - ID of the output file
460  *
461  * RETURN:      None
462  *
463  * DESCRIPTION: Header used at the beginning of output files
464  *
465  ******************************************************************************/
466 
467 void
468 AslCompilerFileHeader (
469     UINT32                  FileId)
470 {
471     struct tm               *NewTime;
472     time_t                  Aclock;
473     char                    *Prefix = "";
474 
475 
476     /* Set line prefix depending on the destination file type */
477 
478     switch (FileId)
479     {
480     case ASL_FILE_ASM_SOURCE_OUTPUT:
481     case ASL_FILE_ASM_INCLUDE_OUTPUT:
482 
483         Prefix = "; ";
484         break;
485 
486     case ASL_FILE_HEX_OUTPUT:
487 
488         if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
489         {
490             Prefix = "; ";
491         }
492         else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
493                  (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
494         {
495             Prefix = " * ";
496         }
497         break;
498 
499     case ASL_FILE_C_SOURCE_OUTPUT:
500     case ASL_FILE_C_OFFSET_OUTPUT:
501     case ASL_FILE_C_INCLUDE_OUTPUT:
502 
503         Prefix = " * ";
504         break;
505 
506     default:
507 
508         /* No other output types supported */
509 
510         break;
511     }
512 
513     /* Compilation header with timestamp */
514 
515     (void) time (&Aclock);
516     NewTime = localtime (&Aclock);
517 
518     FlPrintFile (FileId,
519         "%sCompilation of \"%s\" - %s%s\n",
520         Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime),
521         Prefix);
522 
523     switch (FileId)
524     {
525     case ASL_FILE_C_SOURCE_OUTPUT:
526     case ASL_FILE_C_OFFSET_OUTPUT:
527     case ASL_FILE_C_INCLUDE_OUTPUT:
528 
529         FlPrintFile (FileId, " */\n");
530         break;
531 
532     default:
533 
534         /* Nothing to do for other output types */
535 
536         break;
537     }
538 }
539 
540 
541 /*******************************************************************************
542  *
543  * FUNCTION:    CmFlushSourceCode
544  *
545  * PARAMETERS:  None
546  *
547  * RETURN:      None
548  *
549  * DESCRIPTION: Read in any remaining source code after the parse tree
550  *              has been constructed.
551  *
552  ******************************************************************************/
553 
554 static void
555 CmFlushSourceCode (
556     void)
557 {
558     char                    Buffer;
559 
560 
561     while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)
562     {
563         AslInsertLineBuffer ((int) Buffer);
564     }
565 
566     AslResetCurrentLineBuffer ();
567 }
568 
569 
570 /*******************************************************************************
571  *
572  * FUNCTION:    CmDoOutputFiles
573  *
574  * PARAMETERS:  None
575  *
576  * RETURN:      None.
577  *
578  * DESCRIPTION: Create all "listing" type files
579  *
580  ******************************************************************************/
581 
582 void
583 CmDoOutputFiles (
584     void)
585 {
586 
587     /* Create listings and hex files */
588 
589     LsDoListings ();
590     HxDoHexOutput ();
591 
592     /* Dump the namespace to the .nsp file if requested */
593 
594     (void) NsDisplayNamespace ();
595 
596     /* Dump the device mapping file */
597 
598     MpEmitMappingInfo ();
599 }
600 
601 
602 /*******************************************************************************
603  *
604  * FUNCTION:    CmDumpAllEvents
605  *
606  * PARAMETERS:  None
607  *
608  * RETURN:      None.
609  *
610  * DESCRIPTION: Dump all compiler events
611  *
612  ******************************************************************************/
613 
614 static void
615 CmDumpAllEvents (
616     void)
617 {
618     ASL_EVENT_INFO          *Event;
619     UINT32                  Delta;
620     UINT32                  MicroSeconds;
621     UINT32                  MilliSeconds;
622     UINT32                  i;
623 
624 
625     Event = AslGbl_Events;
626 
627     DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");
628     if (Gbl_CompileTimesFlag)
629     {
630         printf ("\nElapsed time for major events\n\n");
631     }
632 
633     for (i = 0; i < AslGbl_NextEvent; i++)
634     {
635         if (Event->Valid)
636         {
637             /* Delta will be in 100-nanosecond units */
638 
639             Delta = (UINT32) (Event->EndTime - Event->StartTime);
640 
641             MicroSeconds = Delta / ACPI_100NSEC_PER_USEC;
642             MilliSeconds = Delta / ACPI_100NSEC_PER_MSEC;
643 
644             /* Round milliseconds up */
645 
646             if ((MicroSeconds - (MilliSeconds * ACPI_USEC_PER_MSEC)) >= 500)
647             {
648                 MilliSeconds++;
649             }
650 
651             DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",
652                 MicroSeconds, MilliSeconds, Event->EventName);
653 
654             if (Gbl_CompileTimesFlag)
655             {
656                 printf ("%8u usec %8u msec - %s\n",
657                     MicroSeconds, MilliSeconds, Event->EventName);
658             }
659         }
660 
661         Event++;
662     }
663 }
664 
665 
666 /*******************************************************************************
667  *
668  * FUNCTION:    CmCleanupAndExit
669  *
670  * PARAMETERS:  None
671  *
672  * RETURN:      None.
673  *
674  * DESCRIPTION: Close all open files and exit the compiler
675  *
676  ******************************************************************************/
677 
678 void
679 CmCleanupAndExit (
680     void)
681 {
682     UINT32                  i;
683     BOOLEAN                 DeleteAmlFile = FALSE;
684 
685 
686     AePrintErrorLog (ASL_FILE_STDERR);
687     if (Gbl_DebugFlag)
688     {
689         /* Print error summary to stdout also */
690 
691         AePrintErrorLog (ASL_FILE_STDOUT);
692     }
693 
694     /* Emit compile times if enabled */
695 
696     CmDumpAllEvents ();
697 
698     if (Gbl_CompileTimesFlag)
699     {
700         printf ("\nMiscellaneous compile statistics\n\n");
701         printf ("%11u : %s\n", TotalParseNodes, "Parse nodes");
702         printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches");
703         printf ("%11u : %s\n", TotalNamedObjects, "Named objects");
704         printf ("%11u : %s\n", TotalMethods, "Control methods");
705         printf ("%11u : %s\n", TotalAllocations, "Memory Allocations");
706         printf ("%11u : %s\n", TotalAllocated, "Total allocated memory");
707         printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded");
708         printf ("\n");
709     }
710 
711     if (Gbl_NsLookupCount)
712     {
713         DbgPrint (ASL_DEBUG_OUTPUT,
714             "\n\nMiscellaneous compile statistics\n\n");
715 
716         DbgPrint (ASL_DEBUG_OUTPUT,
717             "%32s : %u\n", "Total Namespace searches",
718             Gbl_NsLookupCount);
719 
720         DbgPrint (ASL_DEBUG_OUTPUT,
721             "%32s : %u usec\n", "Time per search", ((UINT32)
722             (AslGbl_Events[AslGbl_NamespaceEvent].EndTime -
723                 AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) /
724                 Gbl_NsLookupCount);
725     }
726 
727     if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
728     {
729         printf ("\nMaximum error count (%u) exceeded\n",
730             ASL_MAX_ERROR_COUNT);
731     }
732 
733     UtDisplaySummary (ASL_FILE_STDOUT);
734 
735     /*
736      * We will delete the AML file if there are errors and the
737      * force AML output option has not been used.
738      */
739     if ((Gbl_ExceptionCount[ASL_ERROR] > 0) &&
740         (!Gbl_IgnoreErrors) &&
741         Gbl_Files[ASL_FILE_AML_OUTPUT].Handle)
742     {
743         DeleteAmlFile = TRUE;
744     }
745 
746     /* Close all open files */
747 
748     /*
749      * Take care with the preprocessor file (.pre), it might be the same
750      * as the "input" file, depending on where the compiler has terminated
751      * or aborted. Prevent attempt to close the same file twice in
752      * loop below.
753      */
754     if (Gbl_Files[ASL_FILE_PREPROCESSOR].Handle ==
755         Gbl_Files[ASL_FILE_INPUT].Handle)
756     {
757         Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL;
758     }
759 
760     /* Close the standard I/O files */
761 
762     for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
763     {
764         FlCloseFile (i);
765     }
766 
767     /* Delete AML file if there are errors */
768 
769     if (DeleteAmlFile)
770     {
771         FlDeleteFile (ASL_FILE_AML_OUTPUT);
772     }
773 
774     /* Delete the preprocessor temp file unless full debug was specified */
775 
776     if (Gbl_PreprocessFlag && !Gbl_KeepPreprocessorTempFile)
777     {
778         FlDeleteFile (ASL_FILE_PREPROCESSOR);
779     }
780 
781     /*
782      * Delete intermediate ("combined") source file (if -ls flag not set)
783      * This file is created during normal ASL/AML compiles. It is not
784      * created by the data table compiler.
785      *
786      * If the -ls flag is set, then the .SRC file should not be deleted.
787      * In this case, Gbl_SourceOutputFlag is set to TRUE.
788      *
789      * Note: Handles are cleared by FlCloseFile above, so we look at the
790      * filename instead, to determine if the .SRC file was actually
791      * created.
792      */
793     if (!Gbl_SourceOutputFlag)
794     {
795         FlDeleteFile (ASL_FILE_SOURCE_OUTPUT);
796     }
797 
798     /* Final cleanup after compiling one file */
799 
800     CmDeleteCaches ();
801 }
802 
803 
804 /*******************************************************************************
805  *
806  * FUNCTION:    CmDeleteCaches
807  *
808  * PARAMETERS:  None
809  *
810  * RETURN:      None
811  *
812  * DESCRIPTION: Delete all local cache buffer blocks
813  *
814  ******************************************************************************/
815 
816 void
817 CmDeleteCaches (
818     void)
819 {
820     UINT32                  BufferCount;
821     ASL_CACHE_INFO          *Next;
822 
823 
824     /* Parse Op cache */
825 
826     BufferCount = 0;
827     while (Gbl_ParseOpCacheList)
828     {
829         Next = Gbl_ParseOpCacheList->Next;
830         ACPI_FREE (Gbl_ParseOpCacheList);
831         Gbl_ParseOpCacheList = Next;
832         BufferCount++;
833     }
834 
835     DbgPrint (ASL_DEBUG_OUTPUT,
836         "%u ParseOps, Buffer size: %u ops (%u bytes), %u Buffers\n",
837         Gbl_ParseOpCount, ASL_PARSEOP_CACHE_SIZE,
838         (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE), BufferCount);
839 
840     Gbl_ParseOpCount = 0;
841     Gbl_ParseOpCacheNext = NULL;
842     Gbl_ParseOpCacheLast = NULL;
843     Gbl_ParseTreeRoot = NULL;
844 
845     /* Generic string cache */
846 
847     BufferCount = 0;
848     while (Gbl_StringCacheList)
849     {
850         Next = Gbl_StringCacheList->Next;
851         ACPI_FREE (Gbl_StringCacheList);
852         Gbl_StringCacheList = Next;
853         BufferCount++;
854     }
855 
856     DbgPrint (ASL_DEBUG_OUTPUT,
857         "%u Strings (%u bytes), Buffer size: %u bytes, %u Buffers\n",
858         Gbl_StringCount, Gbl_StringSize, ASL_STRING_CACHE_SIZE, BufferCount);
859 
860     Gbl_StringSize = 0;
861     Gbl_StringCount = 0;
862     Gbl_StringCacheNext = NULL;
863     Gbl_StringCacheLast = NULL;
864 }
865