1/******************************************************************************
2 *
3 * Module Name: aslcompile - top level compile module
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2016, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************/
115
116#include "aslcompiler.h"
117#include "dtcompiler.h"
118#include "acnamesp.h"
119
120#include <stdio.h>
121#include <time.h>
122#include <acapps.h>
123
124#define _COMPONENT          ACPI_COMPILER
125        ACPI_MODULE_NAME    ("aslcompile")
126
127/*
128 * Main parser entry
129 * External is here in case the parser emits the same external in the
130 * generated header. (Newer versions of Bison)
131 */
132int
133AslCompilerparse(
134    void);
135
136/* Local prototypes */
137
138static void
139CmFlushSourceCode (
140    void);
141
142static void
143CmDumpAllEvents (
144    void);
145
146
147/*******************************************************************************
148 *
149 * FUNCTION:    CmDoCompile
150 *
151 * PARAMETERS:  None
152 *
153 * RETURN:      Status (0 = OK)
154 *
155 * DESCRIPTION: This procedure performs the entire compile
156 *
157 ******************************************************************************/
158
159int
160CmDoCompile (
161    void)
162{
163    ACPI_STATUS             Status;
164    UINT8                   FullCompile;
165    UINT8                   Event;
166
167
168    FullCompile = UtBeginEvent ("*** Total Compile time ***");
169    Event = UtBeginEvent ("Open input and output files");
170    UtEndEvent (Event);
171
172    Event = UtBeginEvent ("Preprocess input file");
173    if (Gbl_PreprocessFlag)
174    {
175        /* Enter compiler name as a #define */
176
177        PrAddDefine (ASL_DEFINE, "", FALSE);
178
179        /* Preprocessor */
180
181        PrDoPreprocess ();
182        Gbl_CurrentLineNumber = 1;
183        Gbl_LogicalLineNumber = 1;
184
185        if (Gbl_PreprocessOnly)
186        {
187            UtEndEvent (Event);
188            CmCleanupAndExit ();
189            return (0);
190        }
191    }
192    UtEndEvent (Event);
193
194
195    /* Build the parse tree */
196
197    Event = UtBeginEvent ("Parse source code and build parse tree");
198    AslCompilerparse();
199    UtEndEvent (Event);
200
201    /* Check for parser-detected syntax errors */
202
203    if (Gbl_SyntaxError)
204    {
205        fprintf (stderr,
206            "Compiler aborting due to parser-detected syntax error(s)\n");
207        LsDumpParseTree ();
208        goto ErrorExit;
209    }
210
211    /* Did the parse tree get successfully constructed? */
212
213    if (!Gbl_ParseTreeRoot)
214    {
215        /*
216         * If there are no errors, then we have some sort of
217         * internal problem.
218         */
219        AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
220            NULL, "- Could not resolve parse tree root node");
221
222        goto ErrorExit;
223    }
224
225    /* Flush out any remaining source after parse tree is complete */
226
227    Event = UtBeginEvent ("Flush source input");
228    CmFlushSourceCode ();
229
230    /* Prune the parse tree if requested (debug purposes only) */
231
232    if (Gbl_PruneParseTree)
233    {
234        AslPruneParseTree (Gbl_PruneDepth, Gbl_PruneType);
235    }
236
237    /* Optional parse tree dump, compiler debug output only */
238
239    LsDumpParseTree ();
240
241    OpcGetIntegerWidth (Gbl_ParseTreeRoot->Asl.Child);
242    UtEndEvent (Event);
243
244    /* Pre-process parse tree for any operator transforms */
245
246    Event = UtBeginEvent ("Parse tree transforms");
247    DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n");
248    TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
249        TrAmlTransformWalkBegin, TrAmlTransformWalkEnd, NULL);
250    UtEndEvent (Event);
251
252    /* Generate AML opcodes corresponding to the parse tokens */
253
254    Event = UtBeginEvent ("Generate AML opcodes");
255    DbgPrint (ASL_DEBUG_OUTPUT, "Generating AML opcodes\n\n");
256    TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
257        OpcAmlOpcodeWalk, NULL);
258    UtEndEvent (Event);
259
260    /*
261     * Now that the input is parsed, we can open the AML output file.
262     * Note: by default, the name of this file comes from the table
263     * descriptor within the input file.
264     */
265    Event = UtBeginEvent ("Open AML output file");
266    Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
267    UtEndEvent (Event);
268    if (ACPI_FAILURE (Status))
269    {
270        AePrintErrorLog (ASL_FILE_STDERR);
271        return (-1);
272    }
273
274    /* Interpret and generate all compile-time constants */
275
276    Event = UtBeginEvent ("Constant folding via AML interpreter");
277    DbgPrint (ASL_DEBUG_OUTPUT,
278        "Interpreting compile-time constant expressions\n\n");
279
280    if (Gbl_FoldConstants)
281    {
282        TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
283            NULL, OpcAmlConstantWalk, NULL);
284    }
285    else
286    {
287        DbgPrint (ASL_PARSE_OUTPUT, "    Optional folding disabled\n");
288    }
289    UtEndEvent (Event);
290
291    /* Update AML opcodes if necessary, after constant folding */
292
293    Event = UtBeginEvent ("Updating AML opcodes after constant folding");
294    DbgPrint (ASL_DEBUG_OUTPUT,
295        "Updating AML opcodes after constant folding\n\n");
296    TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
297        NULL, OpcAmlOpcodeUpdateWalk, NULL);
298    UtEndEvent (Event);
299
300    /* Calculate all AML package lengths */
301
302    Event = UtBeginEvent ("Generate AML package lengths");
303    DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");
304    TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
305        LnPackageLengthWalk, NULL);
306    UtEndEvent (Event);
307
308    if (Gbl_ParseOnlyFlag)
309    {
310        AePrintErrorLog (ASL_FILE_STDERR);
311        UtDisplaySummary (ASL_FILE_STDERR);
312        if (Gbl_DebugFlag)
313        {
314            /* Print error summary to the stdout also */
315
316            AePrintErrorLog (ASL_FILE_STDOUT);
317            UtDisplaySummary (ASL_FILE_STDOUT);
318        }
319        UtEndEvent (FullCompile);
320        return (0);
321    }
322
323    /*
324     * Create an internal namespace and use it as a symbol table
325     */
326
327    /* Namespace loading */
328
329    Event = UtBeginEvent ("Create ACPI Namespace");
330    DbgPrint (ASL_DEBUG_OUTPUT, "Creating ACPI Namespace\n\n");
331    Status = LdLoadNamespace (Gbl_ParseTreeRoot);
332    UtEndEvent (Event);
333    if (ACPI_FAILURE (Status))
334    {
335        goto ErrorExit;
336    }
337
338    /* Namespace cross-reference */
339
340    AslGbl_NamespaceEvent = UtBeginEvent (
341        "Cross reference parse tree and Namespace");
342    DbgPrint (ASL_DEBUG_OUTPUT, "Cross referencing namespace\n\n");
343    Status = XfCrossReferenceNamespace ();
344    if (ACPI_FAILURE (Status))
345    {
346        goto ErrorExit;
347    }
348
349    /* Namespace - Check for non-referenced objects */
350
351    LkFindUnreferencedObjects ();
352    UtEndEvent (AslGbl_NamespaceEvent);
353
354    /* Resolve External Declarations */
355
356    if (Gbl_DoExternals)
357    {
358        Event = UtBeginEvent ("Resolve all Externals");
359        DbgPrint (ASL_DEBUG_OUTPUT, "\nResolve Externals\n\n");
360        TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
361            ExAmlExternalWalkBegin, ExAmlExternalWalkEnd, NULL);
362        UtEndEvent (Event);
363    }
364
365    /*
366     * Semantic analysis. This can happen only after the
367     * namespace has been loaded and cross-referenced.
368     *
369     * part one - check control methods
370     */
371    Event = UtBeginEvent ("Analyze control method return types");
372    AnalysisWalkInfo.MethodStack = NULL;
373
374    DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method analysis\n\n");
375
376    if (Gbl_CrossReferenceOutput)
377    {
378        OtPrintHeaders ("Part 1: Object Reference Map "
379            "(Object references from within each control method)");
380    }
381
382    TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
383        MtMethodAnalysisWalkBegin,
384        MtMethodAnalysisWalkEnd, &AnalysisWalkInfo);
385    UtEndEvent (Event);
386
387    /* Generate the object cross-reference file if requested */
388
389    Event = UtBeginEvent ("Generate cross-reference file");
390    OtCreateXrefFile ();
391    UtEndEvent (Event);
392
393    /* Semantic error checking part two - typing of method returns */
394
395    Event = UtBeginEvent ("Determine object types returned by methods");
396    DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method typing\n\n");
397    TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
398        NULL, AnMethodTypingWalkEnd, NULL);
399    UtEndEvent (Event);
400
401    /* Semantic error checking part three - operand type checking */
402
403    Event = UtBeginEvent ("Analyze AML operand types");
404    DbgPrint (ASL_DEBUG_OUTPUT,
405        "Semantic analysis - Operand type checking\n\n");
406    if (Gbl_DoTypechecking)
407    {
408        TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
409            NULL, AnOperandTypecheckWalkEnd, &AnalysisWalkInfo);
410    }
411    UtEndEvent (Event);
412
413    /* Semantic error checking part four - other miscellaneous checks */
414
415    Event = UtBeginEvent ("Miscellaneous analysis");
416    DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - miscellaneous\n\n");
417    TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
418        AnOtherSemanticAnalysisWalkBegin,
419        NULL, &AnalysisWalkInfo);
420    UtEndEvent (Event);
421
422    /* Calculate all AML package lengths */
423
424    Event = UtBeginEvent ("Finish AML package length generation");
425    DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");
426    TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
427        LnInitLengthsWalk, NULL);
428    TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
429        LnPackageLengthWalk, NULL);
430    UtEndEvent (Event);
431
432    /* Code generation - emit the AML */
433
434    Event = UtBeginEvent ("Generate AML code and write output files");
435    DbgPrint (ASL_DEBUG_OUTPUT, "Writing AML byte code\n\n");
436    CgGenerateAmlOutput ();
437    UtEndEvent (Event);
438
439    Event = UtBeginEvent ("Write optional output files");
440    CmDoOutputFiles ();
441    UtEndEvent (Event);
442
443    UtEndEvent (FullCompile);
444    CmCleanupAndExit ();
445    return (0);
446
447ErrorExit:
448    UtEndEvent (FullCompile);
449    CmCleanupAndExit ();
450    return (-1);
451}
452
453
454/*******************************************************************************
455 *
456 * FUNCTION:    AslCompilerSignon
457 *
458 * PARAMETERS:  FileId      - ID of the output file
459 *
460 * RETURN:      None
461 *
462 * DESCRIPTION: Display compiler signon
463 *
464 ******************************************************************************/
465
466void
467AslCompilerSignon (
468    UINT32                  FileId)
469{
470    char                    *Prefix = "";
471    char                    *UtilityName;
472
473
474    /* Set line prefix depending on the destination file type */
475
476    switch (FileId)
477    {
478    case ASL_FILE_ASM_SOURCE_OUTPUT:
479    case ASL_FILE_ASM_INCLUDE_OUTPUT:
480
481        Prefix = "; ";
482        break;
483
484    case ASL_FILE_HEX_OUTPUT:
485
486        if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
487        {
488            Prefix = "; ";
489        }
490        else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
491                 (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
492        {
493            FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
494            Prefix = " * ";
495        }
496        break;
497
498    case ASL_FILE_C_SOURCE_OUTPUT:
499    case ASL_FILE_C_OFFSET_OUTPUT:
500    case ASL_FILE_C_INCLUDE_OUTPUT:
501
502        Prefix = " * ";
503        break;
504
505    default:
506
507        /* No other output types supported */
508
509        break;
510    }
511
512    /* Running compiler or disassembler? */
513
514    if (Gbl_DisasmFlag)
515    {
516        UtilityName = AML_DISASSEMBLER_NAME;
517    }
518    else
519    {
520        UtilityName = ASL_COMPILER_NAME;
521    }
522
523    /* Compiler signon with copyright */
524
525    FlPrintFile (FileId, "%s\n", Prefix);
526    FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix));
527}
528
529
530/*******************************************************************************
531 *
532 * FUNCTION:    AslCompilerFileHeader
533 *
534 * PARAMETERS:  FileId      - ID of the output file
535 *
536 * RETURN:      None
537 *
538 * DESCRIPTION: Header used at the beginning of output files
539 *
540 ******************************************************************************/
541
542void
543AslCompilerFileHeader (
544    UINT32                  FileId)
545{
546    struct tm               *NewTime;
547    time_t                  Aclock;
548    char                    *Prefix = "";
549
550
551    /* Set line prefix depending on the destination file type */
552
553    switch (FileId)
554    {
555    case ASL_FILE_ASM_SOURCE_OUTPUT:
556    case ASL_FILE_ASM_INCLUDE_OUTPUT:
557
558        Prefix = "; ";
559        break;
560
561    case ASL_FILE_HEX_OUTPUT:
562
563        if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
564        {
565            Prefix = "; ";
566        }
567        else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
568                 (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
569        {
570            Prefix = " * ";
571        }
572        break;
573
574    case ASL_FILE_C_SOURCE_OUTPUT:
575    case ASL_FILE_C_OFFSET_OUTPUT:
576    case ASL_FILE_C_INCLUDE_OUTPUT:
577
578        Prefix = " * ";
579        break;
580
581    default:
582
583        /* No other output types supported */
584
585        break;
586    }
587
588    /* Compilation header with timestamp */
589
590    (void) time (&Aclock);
591    NewTime = localtime (&Aclock);
592
593    FlPrintFile (FileId,
594        "%sCompilation of \"%s\" - %s%s\n",
595        Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime),
596        Prefix);
597
598    switch (FileId)
599    {
600    case ASL_FILE_C_SOURCE_OUTPUT:
601    case ASL_FILE_C_OFFSET_OUTPUT:
602    case ASL_FILE_C_INCLUDE_OUTPUT:
603
604        FlPrintFile (FileId, " */\n");
605        break;
606
607    default:
608
609        /* Nothing to do for other output types */
610
611        break;
612    }
613}
614
615
616/*******************************************************************************
617 *
618 * FUNCTION:    CmFlushSourceCode
619 *
620 * PARAMETERS:  None
621 *
622 * RETURN:      None
623 *
624 * DESCRIPTION: Read in any remaining source code after the parse tree
625 *              has been constructed.
626 *
627 ******************************************************************************/
628
629static void
630CmFlushSourceCode (
631    void)
632{
633    char                    Buffer;
634
635
636    while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)
637    {
638        AslInsertLineBuffer ((int) Buffer);
639    }
640
641    AslResetCurrentLineBuffer ();
642}
643
644
645/*******************************************************************************
646 *
647 * FUNCTION:    CmDoOutputFiles
648 *
649 * PARAMETERS:  None
650 *
651 * RETURN:      None.
652 *
653 * DESCRIPTION: Create all "listing" type files
654 *
655 ******************************************************************************/
656
657void
658CmDoOutputFiles (
659    void)
660{
661
662    /* Create listings and hex files */
663
664    LsDoListings ();
665    HxDoHexOutput ();
666
667    /* Dump the namespace to the .nsp file if requested */
668
669    (void) NsDisplayNamespace ();
670
671    /* Dump the device mapping file */
672
673    MpEmitMappingInfo ();
674}
675
676
677/*******************************************************************************
678 *
679 * FUNCTION:    CmDumpAllEvents
680 *
681 * PARAMETERS:  None
682 *
683 * RETURN:      None.
684 *
685 * DESCRIPTION: Dump all compiler events
686 *
687 ******************************************************************************/
688
689static void
690CmDumpAllEvents (
691    void)
692{
693    ASL_EVENT_INFO          *Event;
694    UINT32                  Delta;
695    UINT32                  MicroSeconds;
696    UINT32                  MilliSeconds;
697    UINT32                  i;
698
699
700    Event = AslGbl_Events;
701
702    DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");
703    if (Gbl_CompileTimesFlag)
704    {
705        printf ("\nElapsed time for major events\n\n");
706    }
707
708    for (i = 0; i < AslGbl_NextEvent; i++)
709    {
710        if (Event->Valid)
711        {
712            /* Delta will be in 100-nanosecond units */
713
714            Delta = (UINT32) (Event->EndTime - Event->StartTime);
715
716            MicroSeconds = Delta / ACPI_100NSEC_PER_USEC;
717            MilliSeconds = Delta / ACPI_100NSEC_PER_MSEC;
718
719            /* Round milliseconds up */
720
721            if ((MicroSeconds - (MilliSeconds * ACPI_USEC_PER_MSEC)) >= 500)
722            {
723                MilliSeconds++;
724            }
725
726            DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",
727                MicroSeconds, MilliSeconds, Event->EventName);
728
729            if (Gbl_CompileTimesFlag)
730            {
731                printf ("%8u usec %8u msec - %s\n",
732                    MicroSeconds, MilliSeconds, Event->EventName);
733            }
734        }
735
736        Event++;
737    }
738}
739
740
741/*******************************************************************************
742 *
743 * FUNCTION:    CmCleanupAndExit
744 *
745 * PARAMETERS:  None
746 *
747 * RETURN:      None.
748 *
749 * DESCRIPTION: Close all open files and exit the compiler
750 *
751 ******************************************************************************/
752
753void
754CmCleanupAndExit (
755    void)
756{
757    UINT32                  i;
758    BOOLEAN                 DeleteAmlFile = FALSE;
759
760
761    AePrintErrorLog (ASL_FILE_STDERR);
762    if (Gbl_DebugFlag)
763    {
764        /* Print error summary to stdout also */
765
766        AePrintErrorLog (ASL_FILE_STDOUT);
767    }
768
769    /* Emit compile times if enabled */
770
771    CmDumpAllEvents ();
772
773    if (Gbl_CompileTimesFlag)
774    {
775        printf ("\nMiscellaneous compile statistics\n\n");
776        printf ("%11u : %s\n", TotalParseNodes, "Parse nodes");
777        printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches");
778        printf ("%11u : %s\n", TotalNamedObjects, "Named objects");
779        printf ("%11u : %s\n", TotalMethods, "Control methods");
780        printf ("%11u : %s\n", TotalAllocations, "Memory Allocations");
781        printf ("%11u : %s\n", TotalAllocated, "Total allocated memory");
782        printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded");
783        printf ("\n");
784    }
785
786    if (Gbl_NsLookupCount)
787    {
788        DbgPrint (ASL_DEBUG_OUTPUT,
789            "\n\nMiscellaneous compile statistics\n\n");
790
791        DbgPrint (ASL_DEBUG_OUTPUT,
792            "%32s : %u\n", "Total Namespace searches",
793            Gbl_NsLookupCount);
794
795        DbgPrint (ASL_DEBUG_OUTPUT,
796            "%32s : %u usec\n", "Time per search", ((UINT32)
797            (AslGbl_Events[AslGbl_NamespaceEvent].EndTime -
798                AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) /
799                Gbl_NsLookupCount);
800    }
801
802    if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
803    {
804        printf ("\nMaximum error count (%u) exceeded\n",
805            ASL_MAX_ERROR_COUNT);
806    }
807
808    UtDisplaySummary (ASL_FILE_STDOUT);
809
810    /*
811     * We will delete the AML file if there are errors and the
812     * force AML output option has not been used.
813     */
814    if ((Gbl_ExceptionCount[ASL_ERROR] > 0) &&
815        (!Gbl_IgnoreErrors) &&
816        Gbl_Files[ASL_FILE_AML_OUTPUT].Handle)
817    {
818        DeleteAmlFile = TRUE;
819    }
820
821    /* Close all open files */
822
823    /*
824     * Take care with the preprocessor file (.pre), it might be the same
825     * as the "input" file, depending on where the compiler has terminated
826     * or aborted. Prevent attempt to close the same file twice in
827     * loop below.
828     */
829    if (Gbl_Files[ASL_FILE_PREPROCESSOR].Handle ==
830        Gbl_Files[ASL_FILE_INPUT].Handle)
831    {
832        Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL;
833    }
834
835    /* Close the standard I/O files */
836
837    for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
838    {
839        FlCloseFile (i);
840    }
841
842    /* Delete AML file if there are errors */
843
844    if (DeleteAmlFile)
845    {
846        FlDeleteFile (ASL_FILE_AML_OUTPUT);
847    }
848
849    /* Delete the preprocessor temp file unless full debug was specified */
850
851    if (Gbl_PreprocessFlag && !Gbl_KeepPreprocessorTempFile)
852    {
853        FlDeleteFile (ASL_FILE_PREPROCESSOR);
854    }
855
856    /*
857     * Delete intermediate ("combined") source file (if -ls flag not set)
858     * This file is created during normal ASL/AML compiles. It is not
859     * created by the data table compiler.
860     *
861     * If the -ls flag is set, then the .SRC file should not be deleted.
862     * In this case, Gbl_SourceOutputFlag is set to TRUE.
863     *
864     * Note: Handles are cleared by FlCloseFile above, so we look at the
865     * filename instead, to determine if the .SRC file was actually
866     * created.
867     */
868    if (!Gbl_SourceOutputFlag)
869    {
870        FlDeleteFile (ASL_FILE_SOURCE_OUTPUT);
871    }
872
873    /* Final cleanup after compiling one file */
874
875    CmDeleteCaches ();
876}
877
878
879/*******************************************************************************
880 *
881 * FUNCTION:    CmDeleteCaches
882 *
883 * PARAMETERS:  None
884 *
885 * RETURN:      None
886 *
887 * DESCRIPTION: Delete all local cache buffer blocks
888 *
889 ******************************************************************************/
890
891void
892CmDeleteCaches (
893    void)
894{
895    UINT32                  BufferCount;
896    ASL_CACHE_INFO          *Next;
897
898
899    /* Parse Op cache */
900
901    BufferCount = 0;
902    while (Gbl_ParseOpCacheList)
903    {
904        Next = Gbl_ParseOpCacheList->Next;
905        ACPI_FREE (Gbl_ParseOpCacheList);
906        Gbl_ParseOpCacheList = Next;
907        BufferCount++;
908    }
909
910    DbgPrint (ASL_DEBUG_OUTPUT,
911        "%u ParseOps, Buffer size: %u ops (%u bytes), %u Buffers\n",
912        Gbl_ParseOpCount, ASL_PARSEOP_CACHE_SIZE,
913        (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE), BufferCount);
914
915    Gbl_ParseOpCount = 0;
916    Gbl_ParseOpCacheNext = NULL;
917    Gbl_ParseOpCacheLast = NULL;
918    Gbl_ParseTreeRoot = NULL;
919
920    /* Generic string cache */
921
922    BufferCount = 0;
923    while (Gbl_StringCacheList)
924    {
925        Next = Gbl_StringCacheList->Next;
926        ACPI_FREE (Gbl_StringCacheList);
927        Gbl_StringCacheList = Next;
928        BufferCount++;
929    }
930
931    DbgPrint (ASL_DEBUG_OUTPUT,
932        "%u Strings (%u bytes), Buffer size: %u bytes, %u Buffers\n",
933        Gbl_StringCount, Gbl_StringSize, ASL_STRING_CACHE_SIZE, BufferCount);
934
935    Gbl_StringSize = 0;
936    Gbl_StringCount = 0;
937    Gbl_StringCacheNext = NULL;
938    Gbl_StringCacheLast = NULL;
939}
940