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