aslcompile.c revision 200553
1118611Snjl
2118611Snjl/******************************************************************************
3118611Snjl *
4118611Snjl * Module Name: aslcompile - top level compile module
5118611Snjl *
6118611Snjl *****************************************************************************/
7118611Snjl
8118611Snjl/******************************************************************************
9118611Snjl *
10118611Snjl * 1. Copyright Notice
11118611Snjl *
12193529Sjkim * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13118611Snjl * All rights reserved.
14118611Snjl *
15118611Snjl * 2. License
16118611Snjl *
17118611Snjl * 2.1. This is your license from Intel Corp. under its intellectual property
18118611Snjl * rights.  You may have additional license terms from the party that provided
19118611Snjl * you this software, covering your right to use that party's intellectual
20118611Snjl * property rights.
21118611Snjl *
22118611Snjl * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23118611Snjl * copy of the source code appearing in this file ("Covered Code") an
24118611Snjl * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25118611Snjl * base code distributed originally by Intel ("Original Intel Code") to copy,
26118611Snjl * make derivatives, distribute, use and display any portion of the Covered
27118611Snjl * Code in any form, with the right to sublicense such rights; and
28118611Snjl *
29118611Snjl * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30118611Snjl * license (with the right to sublicense), under only those claims of Intel
31118611Snjl * patents that are infringed by the Original Intel Code, to make, use, sell,
32118611Snjl * offer to sell, and import the Covered Code and derivative works thereof
33118611Snjl * solely to the minimum extent necessary to exercise the above copyright
34118611Snjl * license, and in no event shall the patent license extend to any additions
35118611Snjl * to or modifications of the Original Intel Code.  No other license or right
36118611Snjl * is granted directly or by implication, estoppel or otherwise;
37118611Snjl *
38118611Snjl * The above copyright and patent license is granted only if the following
39118611Snjl * conditions are met:
40118611Snjl *
41118611Snjl * 3. Conditions
42118611Snjl *
43118611Snjl * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44118611Snjl * Redistribution of source code of any substantial portion of the Covered
45118611Snjl * Code or modification with rights to further distribute source must include
46118611Snjl * the above Copyright Notice, the above License, this list of Conditions,
47118611Snjl * and the following Disclaimer and Export Compliance provision.  In addition,
48118611Snjl * Licensee must cause all Covered Code to which Licensee contributes to
49118611Snjl * contain a file documenting the changes Licensee made to create that Covered
50118611Snjl * Code and the date of any change.  Licensee must include in that file the
51118611Snjl * documentation of any changes made by any predecessor Licensee.  Licensee
52118611Snjl * must include a prominent statement that the modification is derived,
53118611Snjl * directly or indirectly, from Original Intel Code.
54118611Snjl *
55118611Snjl * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56118611Snjl * Redistribution of source code of any substantial portion of the Covered
57118611Snjl * Code or modification without rights to further distribute source must
58118611Snjl * include the following Disclaimer and Export Compliance provision in the
59118611Snjl * documentation and/or other materials provided with distribution.  In
60118611Snjl * addition, Licensee may not authorize further sublicense of source of any
61118611Snjl * portion of the Covered Code, and must include terms to the effect that the
62118611Snjl * license from Licensee to its licensee is limited to the intellectual
63118611Snjl * property embodied in the software Licensee provides to its licensee, and
64118611Snjl * not to intellectual property embodied in modifications its licensee may
65118611Snjl * make.
66118611Snjl *
67118611Snjl * 3.3. Redistribution of Executable. Redistribution in executable form of any
68118611Snjl * substantial portion of the Covered Code or modification must reproduce the
69118611Snjl * above Copyright Notice, and the following Disclaimer and Export Compliance
70118611Snjl * provision in the documentation and/or other materials provided with the
71118611Snjl * distribution.
72118611Snjl *
73118611Snjl * 3.4. Intel retains all right, title, and interest in and to the Original
74118611Snjl * Intel Code.
75118611Snjl *
76118611Snjl * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77118611Snjl * Intel shall be used in advertising or otherwise to promote the sale, use or
78118611Snjl * other dealings in products derived from or relating to the Covered Code
79118611Snjl * without prior written authorization from Intel.
80118611Snjl *
81118611Snjl * 4. Disclaimer and Export Compliance
82118611Snjl *
83118611Snjl * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84118611Snjl * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85118611Snjl * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86118611Snjl * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87118611Snjl * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88118611Snjl * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89118611Snjl * PARTICULAR PURPOSE.
90118611Snjl *
91118611Snjl * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92118611Snjl * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93118611Snjl * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94118611Snjl * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95118611Snjl * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96118611Snjl * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97118611Snjl * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98118611Snjl * LIMITED REMEDY.
99118611Snjl *
100118611Snjl * 4.3. Licensee shall not export, either directly or indirectly, any of this
101118611Snjl * software or system incorporating such software without first obtaining any
102118611Snjl * required license or other approval from the U. S. Department of Commerce or
103118611Snjl * any other agency or department of the United States Government.  In the
104118611Snjl * event Licensee exports any such software from the United States or
105118611Snjl * re-exports any such software from a foreign destination, Licensee shall
106118611Snjl * ensure that the distribution and export/re-export of the software is in
107118611Snjl * compliance with all laws, regulations, orders, or other restrictions of the
108118611Snjl * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109118611Snjl * any of its subsidiaries will export/re-export any technical data, process,
110118611Snjl * software, or service, directly or indirectly, to any country for which the
111118611Snjl * United States government or any agency thereof requires an export license,
112118611Snjl * other governmental approval, or letter of assurance, without first obtaining
113118611Snjl * such license, approval or letter.
114118611Snjl *
115118611Snjl *****************************************************************************/
116118611Snjl
117118611Snjl#include <stdio.h>
118151937Sjkim#include <time.h>
119151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
120118611Snjl
121118611Snjl#define _COMPONENT          ACPI_COMPILER
122118611Snjl        ACPI_MODULE_NAME    ("aslcompile")
123118611Snjl
124151937Sjkim/* Local prototypes */
125118611Snjl
126151937Sjkimstatic void
127151937SjkimCmFlushSourceCode (
128151937Sjkim    void);
129151937Sjkim
130151937Sjkimstatic ACPI_STATUS
131151937SjkimFlCheckForAscii (
132151937Sjkim    ASL_FILE_INFO           *FileInfo);
133151937Sjkim
134193529Sjkimvoid
135193529SjkimFlConsumeAnsiComment (
136193529Sjkim    ASL_FILE_INFO           *FileInfo,
137193529Sjkim    ASL_FILE_STATUS         *Status);
138151937Sjkim
139193529Sjkimvoid
140193529SjkimFlConsumeNewComment (
141193529Sjkim    ASL_FILE_INFO           *FileInfo,
142193529Sjkim    ASL_FILE_STATUS         *Status);
143193529Sjkim
144193529Sjkim
145118611Snjl/*******************************************************************************
146118611Snjl *
147118611Snjl * FUNCTION:    AslCompilerSignon
148118611Snjl *
149118611Snjl * PARAMETERS:  FileId      - ID of the output file
150118611Snjl *
151118611Snjl * RETURN:      None
152118611Snjl *
153118611Snjl * DESCRIPTION: Display compiler signon
154118611Snjl *
155118611Snjl ******************************************************************************/
156118611Snjl
157118611Snjlvoid
158118611SnjlAslCompilerSignon (
159118611Snjl    UINT32                  FileId)
160118611Snjl{
161118611Snjl    char                    *Prefix = "";
162118611Snjl
163118611Snjl
164151937Sjkim    /* Set line prefix depending on the destination file type */
165151937Sjkim
166118611Snjl    switch (FileId)
167118611Snjl    {
168118611Snjl    case ASL_FILE_ASM_SOURCE_OUTPUT:
169118611Snjl    case ASL_FILE_ASM_INCLUDE_OUTPUT:
170118611Snjl
171118611Snjl        Prefix = "; ";
172118611Snjl        break;
173118611Snjl
174118611Snjl    case ASL_FILE_HEX_OUTPUT:
175118611Snjl
176118611Snjl        if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
177118611Snjl        {
178118611Snjl            Prefix = "; ";
179118611Snjl        }
180118611Snjl        else if (Gbl_HexOutputFlag == HEX_OUTPUT_C)
181118611Snjl        {
182118611Snjl            FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
183118611Snjl            Prefix = " * ";
184118611Snjl        }
185118611Snjl        break;
186118611Snjl
187118611Snjl    case ASL_FILE_C_SOURCE_OUTPUT:
188118611Snjl    case ASL_FILE_C_INCLUDE_OUTPUT:
189118611Snjl
190118611Snjl        Prefix = " * ";
191118611Snjl        break;
192118611Snjl
193118611Snjl    default:
194118611Snjl        /* No other output types supported */
195118611Snjl        break;
196118611Snjl    }
197118611Snjl
198151937Sjkim    /*
199151937Sjkim     * Compiler signon with copyright
200151937Sjkim     */
201118611Snjl    FlPrintFile (FileId,
202151937Sjkim        "%s\n%s%s\n%s",
203118611Snjl        Prefix,
204118611Snjl        Prefix, IntelAcpiCA,
205151937Sjkim        Prefix);
206151937Sjkim
207151937Sjkim    /* Running compiler or disassembler? */
208151937Sjkim
209151937Sjkim    if (Gbl_DisasmFlag)
210151937Sjkim    {
211151937Sjkim        FlPrintFile (FileId,
212151937Sjkim            "%s", DisassemblerId);
213151937Sjkim    }
214151937Sjkim    else
215151937Sjkim    {
216151937Sjkim        FlPrintFile (FileId,
217151937Sjkim            "%s", CompilerId);
218151937Sjkim    }
219151937Sjkim
220195626Scperciva    /* Version, copyright, compliance */
221151937Sjkim
222151937Sjkim    FlPrintFile (FileId,
223195626Scperciva        " version %X\n%s%s\n%s%s\n%s\n",
224195626Scperciva        (UINT32) ACPI_CA_VERSION,
225118611Snjl        Prefix, CompilerCopyright,
226151937Sjkim        Prefix, CompilerCompliance,
227118611Snjl        Prefix);
228118611Snjl}
229118611Snjl
230118611Snjl
231118611Snjl/*******************************************************************************
232118611Snjl *
233118611Snjl * FUNCTION:    AslCompilerFileHeader
234118611Snjl *
235118611Snjl * PARAMETERS:  FileId      - ID of the output file
236118611Snjl *
237118611Snjl * RETURN:      None
238118611Snjl *
239118611Snjl * DESCRIPTION: Header used at the beginning of output files
240118611Snjl *
241118611Snjl ******************************************************************************/
242118611Snjl
243118611Snjlvoid
244118611SnjlAslCompilerFileHeader (
245118611Snjl    UINT32                  FileId)
246118611Snjl{
247118611Snjl    struct tm               *NewTime;
248118611Snjl    time_t                  Aclock;
249118611Snjl    char                    *Prefix = "";
250118611Snjl
251118611Snjl
252151937Sjkim    /* Set line prefix depending on the destination file type */
253151937Sjkim
254118611Snjl    switch (FileId)
255118611Snjl    {
256118611Snjl    case ASL_FILE_ASM_SOURCE_OUTPUT:
257118611Snjl    case ASL_FILE_ASM_INCLUDE_OUTPUT:
258118611Snjl
259118611Snjl        Prefix = "; ";
260118611Snjl        break;
261118611Snjl
262118611Snjl    case ASL_FILE_HEX_OUTPUT:
263118611Snjl
264118611Snjl        if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
265118611Snjl        {
266118611Snjl            Prefix = "; ";
267118611Snjl        }
268118611Snjl        else if (Gbl_HexOutputFlag == HEX_OUTPUT_C)
269118611Snjl        {
270118611Snjl            Prefix = " * ";
271118611Snjl        }
272118611Snjl        break;
273118611Snjl
274118611Snjl    case ASL_FILE_C_SOURCE_OUTPUT:
275118611Snjl    case ASL_FILE_C_INCLUDE_OUTPUT:
276118611Snjl
277118611Snjl        Prefix = " * ";
278118611Snjl        break;
279118611Snjl
280118611Snjl    default:
281118611Snjl        /* No other output types supported */
282118611Snjl        break;
283118611Snjl    }
284118611Snjl
285118611Snjl    /* Compilation header with timestamp */
286118611Snjl
287118611Snjl    (void) time (&Aclock);
288118611Snjl    NewTime = localtime (&Aclock);
289118611Snjl
290118611Snjl    FlPrintFile (FileId,
291118611Snjl        "%sCompilation of \"%s\" - %s%s\n",
292118611Snjl        Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime),
293118611Snjl        Prefix);
294118611Snjl
295118611Snjl    switch (FileId)
296118611Snjl    {
297118611Snjl    case ASL_FILE_C_SOURCE_OUTPUT:
298118611Snjl    case ASL_FILE_C_INCLUDE_OUTPUT:
299118611Snjl        FlPrintFile (FileId, " */\n");
300118611Snjl        break;
301118611Snjl
302118611Snjl    default:
303118611Snjl        /* Nothing to do for other output types */
304118611Snjl        break;
305118611Snjl    }
306118611Snjl}
307118611Snjl
308118611Snjl
309118611Snjl/*******************************************************************************
310118611Snjl *
311118611Snjl * FUNCTION:    CmFlushSourceCode
312118611Snjl *
313118611Snjl * PARAMETERS:  None
314118611Snjl *
315118611Snjl * RETURN:      None
316118611Snjl *
317118611Snjl * DESCRIPTION: Read in any remaining source code after the parse tree
318118611Snjl *              has been constructed.
319118611Snjl *
320118611Snjl ******************************************************************************/
321118611Snjl
322151937Sjkimstatic void
323151937SjkimCmFlushSourceCode (
324151937Sjkim    void)
325118611Snjl{
326118611Snjl    char                    Buffer;
327118611Snjl
328118611Snjl
329118611Snjl    while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)
330118611Snjl    {
331118611Snjl        InsertLineBuffer ((int) Buffer);
332118611Snjl    }
333118611Snjl
334118611Snjl    ResetCurrentLineBuffer ();
335118611Snjl}
336118611Snjl
337118611Snjl
338118611Snjl/*******************************************************************************
339118611Snjl *
340167802Sjkim * FUNCTION:    FlConsume*
341167802Sjkim *
342167802Sjkim * PARAMETERS:  FileInfo        - Points to an open input file
343167802Sjkim *
344167802Sjkim * RETURN:      Number of lines consumed
345167802Sjkim *
346167802Sjkim * DESCRIPTION: Step over both types of comment during check for ascii chars
347167802Sjkim *
348167802Sjkim ******************************************************************************/
349167802Sjkim
350167802Sjkimvoid
351167802SjkimFlConsumeAnsiComment (
352167802Sjkim    ASL_FILE_INFO           *FileInfo,
353167802Sjkim    ASL_FILE_STATUS         *Status)
354167802Sjkim{
355167802Sjkim    UINT8                   Byte;
356167802Sjkim    BOOLEAN                 ClosingComment = FALSE;
357167802Sjkim
358167802Sjkim
359167802Sjkim    while (fread (&Byte, 1, 1, FileInfo->Handle))
360167802Sjkim    {
361167802Sjkim        /* Scan until comment close is found */
362167802Sjkim
363167802Sjkim        if (ClosingComment)
364167802Sjkim        {
365167802Sjkim            if (Byte == '/')
366167802Sjkim            {
367167802Sjkim                return;
368167802Sjkim            }
369167802Sjkim
370167802Sjkim            if (Byte != '*')
371167802Sjkim            {
372167802Sjkim                /* Reset */
373167802Sjkim
374167802Sjkim                ClosingComment = FALSE;
375167802Sjkim            }
376167802Sjkim        }
377167802Sjkim        else if (Byte == '*')
378167802Sjkim        {
379167802Sjkim            ClosingComment = TRUE;
380167802Sjkim        }
381167802Sjkim
382167802Sjkim        /* Maintain line count */
383167802Sjkim
384167802Sjkim        if (Byte == 0x0A)
385167802Sjkim        {
386167802Sjkim            Status->Line++;
387167802Sjkim        }
388167802Sjkim
389167802Sjkim        Status->Offset++;
390167802Sjkim    }
391167802Sjkim}
392167802Sjkim
393167802Sjkim
394167802Sjkimvoid
395167802SjkimFlConsumeNewComment (
396167802Sjkim    ASL_FILE_INFO           *FileInfo,
397167802Sjkim    ASL_FILE_STATUS         *Status)
398167802Sjkim{
399167802Sjkim    UINT8                   Byte;
400167802Sjkim
401167802Sjkim
402167802Sjkim    while (fread (&Byte, 1, 1, FileInfo->Handle))
403167802Sjkim    {
404167802Sjkim        Status->Offset++;
405167802Sjkim
406167802Sjkim        /* Comment ends at newline */
407167802Sjkim
408167802Sjkim        if (Byte == 0x0A)
409167802Sjkim        {
410167802Sjkim            Status->Line++;
411167802Sjkim            return;
412167802Sjkim        }
413167802Sjkim    }
414167802Sjkim}
415167802Sjkim
416167802Sjkim
417167802Sjkim/*******************************************************************************
418167802Sjkim *
419123315Snjl * FUNCTION:    FlCheckForAscii
420123315Snjl *
421123315Snjl * PARAMETERS:  FileInfo        - Points to an open input file
422123315Snjl *
423151937Sjkim * RETURN:      Status
424123315Snjl *
425167802Sjkim * DESCRIPTION: Verify that the input file is entirely ASCII. Ignores characters
426167802Sjkim *              within comments. Note: does not handle nested comments and does
427167802Sjkim *              not handle comment delimiters within string literals. However,
428167802Sjkim *              on the rare chance this happens and an invalid character is
429167802Sjkim *              missed, the parser will catch the error by failing in some
430167802Sjkim *              spectactular manner.
431123315Snjl *
432123315Snjl ******************************************************************************/
433123315Snjl
434151937Sjkimstatic ACPI_STATUS
435123315SnjlFlCheckForAscii (
436123315Snjl    ASL_FILE_INFO           *FileInfo)
437123315Snjl{
438123315Snjl    UINT8                   Byte;
439123315Snjl    ACPI_SIZE               BadBytes = 0;
440167802Sjkim    BOOLEAN                 OpeningComment = FALSE;
441167802Sjkim    ASL_FILE_STATUS         Status;
442123315Snjl
443123315Snjl
444167802Sjkim    Status.Line = 1;
445167802Sjkim    Status.Offset = 0;
446167802Sjkim
447123315Snjl    /* Read the entire file */
448123315Snjl
449123315Snjl    while (fread (&Byte, 1, 1, FileInfo->Handle))
450123315Snjl    {
451167802Sjkim        /* Ignore comment fields (allow non-ascii within) */
452167802Sjkim
453167802Sjkim        if (OpeningComment)
454167802Sjkim        {
455167802Sjkim            /* Check for second comment open delimiter */
456167802Sjkim
457167802Sjkim            if (Byte == '*')
458167802Sjkim            {
459167802Sjkim                FlConsumeAnsiComment (FileInfo, &Status);
460167802Sjkim            }
461167802Sjkim
462167802Sjkim            if (Byte == '/')
463167802Sjkim            {
464167802Sjkim                FlConsumeNewComment (FileInfo, &Status);
465167802Sjkim            }
466167802Sjkim
467167802Sjkim            /* Reset */
468167802Sjkim
469167802Sjkim            OpeningComment = FALSE;
470167802Sjkim        }
471167802Sjkim        else if (Byte == '/')
472167802Sjkim        {
473167802Sjkim            OpeningComment = TRUE;
474167802Sjkim        }
475167802Sjkim
476123315Snjl        /* Check for an ASCII character */
477123315Snjl
478193529Sjkim        if (!ACPI_IS_ASCII (Byte))
479123315Snjl        {
480123315Snjl            if (BadBytes < 10)
481123315Snjl            {
482151937Sjkim                AcpiOsPrintf (
483167802Sjkim                    "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n",
484167802Sjkim                    Byte, Status.Line, Status.Offset);
485123315Snjl            }
486167802Sjkim
487123315Snjl            BadBytes++;
488123315Snjl        }
489167802Sjkim
490167802Sjkim        /* Update line counter */
491167802Sjkim
492167802Sjkim        else if (Byte == 0x0A)
493167802Sjkim        {
494167802Sjkim            Status.Line++;
495167802Sjkim        }
496167802Sjkim
497167802Sjkim        Status.Offset++;
498123315Snjl    }
499123315Snjl
500151937Sjkim    /* Seek back to the beginning of the source file */
501151937Sjkim
502151937Sjkim    fseek (FileInfo->Handle, 0, SEEK_SET);
503151937Sjkim
504123315Snjl    /* Were there any non-ASCII characters in the file? */
505123315Snjl
506123315Snjl    if (BadBytes)
507123315Snjl    {
508151937Sjkim        AcpiOsPrintf (
509167802Sjkim            "%u non-ASCII characters found in input source text, could be a binary file\n",
510151937Sjkim            BadBytes);
511167802Sjkim        AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, FileInfo->Filename);
512123315Snjl        return (AE_BAD_CHARACTER);
513123315Snjl    }
514123315Snjl
515151937Sjkim    /* File is OK */
516123315Snjl
517123315Snjl    return (AE_OK);
518123315Snjl}
519123315Snjl
520123315Snjl
521123315Snjl/*******************************************************************************
522123315Snjl *
523118611Snjl * FUNCTION:    CmDoCompile
524118611Snjl *
525118611Snjl * PARAMETERS:  None
526118611Snjl *
527118611Snjl * RETURN:      Status (0 = OK)
528118611Snjl *
529118611Snjl * DESCRIPTION: This procedure performs the entire compile
530118611Snjl *
531118611Snjl ******************************************************************************/
532118611Snjl
533118611Snjlint
534151937SjkimCmDoCompile (
535151937Sjkim    void)
536118611Snjl{
537118611Snjl    ACPI_STATUS             Status;
538151937Sjkim    UINT8                   FullCompile;
539151937Sjkim    UINT8                   Event;
540118611Snjl
541118611Snjl
542151937Sjkim    FullCompile = UtBeginEvent ("*** Total Compile time ***");
543151937Sjkim    Event = UtBeginEvent ("Open input and output files");
544118611Snjl
545118611Snjl    /* Open the required input and output files */
546118611Snjl
547118611Snjl    Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename);
548118611Snjl    if (ACPI_FAILURE (Status))
549118611Snjl    {
550118611Snjl        AePrintErrorLog (ASL_FILE_STDERR);
551118611Snjl        return -1;
552118611Snjl    }
553118611Snjl
554167802Sjkim    /* Check for 100% ASCII source file (comments are ignored) */
555123315Snjl
556167802Sjkim    Status = FlCheckForAscii (&Gbl_Files[ASL_FILE_INPUT]);
557167802Sjkim    if (ACPI_FAILURE (Status))
558123315Snjl    {
559167802Sjkim        AePrintErrorLog (ASL_FILE_STDERR);
560167802Sjkim        return -1;
561123315Snjl    }
562123315Snjl
563118611Snjl    Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix);
564118611Snjl    if (ACPI_FAILURE (Status))
565118611Snjl    {
566118611Snjl        AePrintErrorLog (ASL_FILE_STDERR);
567118611Snjl        return -1;
568118611Snjl    }
569151937Sjkim    UtEndEvent (Event);
570118611Snjl
571118611Snjl    /* Build the parse tree */
572118611Snjl
573151937Sjkim    Event = UtBeginEvent ("Parse source code and build parse tree");
574118611Snjl    AslCompilerparse();
575151937Sjkim    UtEndEvent (Event);
576118611Snjl
577118611Snjl    /* Flush out any remaining source after parse tree is complete */
578118611Snjl
579151937Sjkim    Event = UtBeginEvent ("Flush source input");
580118611Snjl    CmFlushSourceCode ();
581118611Snjl
582118611Snjl    /* Did the parse tree get successfully constructed? */
583118611Snjl
584118611Snjl    if (!RootNode)
585118611Snjl    {
586118611Snjl        CmCleanupAndExit ();
587118611Snjl        return -1;
588118611Snjl    }
589118611Snjl
590167802Sjkim    /* Optional parse tree dump, compiler debug output only */
591167802Sjkim
592167802Sjkim    LsDumpParseTree ();
593167802Sjkim
594118611Snjl    OpcGetIntegerWidth (RootNode);
595151937Sjkim    UtEndEvent (Event);
596118611Snjl
597118611Snjl    /* Pre-process parse tree for any operator transforms */
598118611Snjl
599151937Sjkim    Event = UtBeginEvent ("Parse tree transforms");
600118611Snjl    DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n");
601151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
602151937Sjkim        TrAmlTransformWalk, NULL, NULL);
603151937Sjkim    UtEndEvent (Event);
604118611Snjl
605118611Snjl    /* Generate AML opcodes corresponding to the parse tokens */
606118611Snjl
607151937Sjkim    Event = UtBeginEvent ("Generate AML opcodes");
608118611Snjl    DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n");
609151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
610151937Sjkim        OpcAmlOpcodeWalk, NULL);
611151937Sjkim    UtEndEvent (Event);
612118611Snjl
613118611Snjl    /*
614118611Snjl     * Now that the input is parsed, we can open the AML output file.
615118611Snjl     * Note: by default, the name of this file comes from the table descriptor
616118611Snjl     * within the input file.
617118611Snjl     */
618151937Sjkim    Event = UtBeginEvent ("Open AML output file");
619118611Snjl    Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
620118611Snjl    if (ACPI_FAILURE (Status))
621118611Snjl    {
622118611Snjl        AePrintErrorLog (ASL_FILE_STDERR);
623118611Snjl        return -1;
624118611Snjl    }
625151937Sjkim    UtEndEvent (Event);
626118611Snjl
627118611Snjl    /* Interpret and generate all compile-time constants */
628118611Snjl
629151937Sjkim    Event = UtBeginEvent ("Constant folding via AML interpreter");
630151937Sjkim    DbgPrint (ASL_DEBUG_OUTPUT,
631151937Sjkim        "\nInterpreting compile-time constant expressions\n\n");
632151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
633151937Sjkim        OpcAmlConstantWalk, NULL, NULL);
634151937Sjkim    UtEndEvent (Event);
635118611Snjl
636151937Sjkim    /* Update AML opcodes if necessary, after constant folding */
637151937Sjkim
638151937Sjkim    Event = UtBeginEvent ("Updating AML opcodes after constant folding");
639151937Sjkim    DbgPrint (ASL_DEBUG_OUTPUT,
640151937Sjkim        "\nUpdating AML opcodes after constant folding\n\n");
641151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD,
642151937Sjkim        NULL, OpcAmlOpcodeUpdateWalk, NULL);
643151937Sjkim    UtEndEvent (Event);
644151937Sjkim
645118611Snjl    /* Calculate all AML package lengths */
646118611Snjl
647151937Sjkim    Event = UtBeginEvent ("Generate AML package lengths");
648118611Snjl    DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n");
649151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
650151937Sjkim        LnPackageLengthWalk, NULL);
651151937Sjkim    UtEndEvent (Event);
652118611Snjl
653118611Snjl    if (Gbl_ParseOnlyFlag)
654118611Snjl    {
655118611Snjl        AePrintErrorLog (ASL_FILE_STDOUT);
656118611Snjl        UtDisplaySummary (ASL_FILE_STDOUT);
657118611Snjl        if (Gbl_DebugFlag)
658118611Snjl        {
659118611Snjl            /* Print error summary to the debug file */
660118611Snjl
661118611Snjl            AePrintErrorLog (ASL_FILE_STDERR);
662118611Snjl            UtDisplaySummary (ASL_FILE_STDERR);
663118611Snjl        }
664118611Snjl        return 0;
665118611Snjl    }
666118611Snjl
667118611Snjl    /*
668118611Snjl     * Create an internal namespace and use it as a symbol table
669118611Snjl     */
670118611Snjl
671118611Snjl    /* Namespace loading */
672118611Snjl
673151937Sjkim    Event = UtBeginEvent ("Create ACPI Namespace");
674118611Snjl    Status = LdLoadNamespace (RootNode);
675151937Sjkim    UtEndEvent (Event);
676118611Snjl    if (ACPI_FAILURE (Status))
677118611Snjl    {
678118611Snjl        return -1;
679118611Snjl    }
680118611Snjl
681167802Sjkim    /* Namespace cross-reference */
682118611Snjl
683151937Sjkim    AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace");
684118611Snjl    Status = LkCrossReferenceNamespace ();
685118611Snjl    if (ACPI_FAILURE (Status))
686118611Snjl    {
687118611Snjl        return -1;
688118611Snjl    }
689118611Snjl
690167802Sjkim    /* Namespace - Check for non-referenced objects */
691167802Sjkim
692167802Sjkim    LkFindUnreferencedObjects ();
693167802Sjkim    UtEndEvent (AslGbl_NamespaceEvent);
694167802Sjkim
695118611Snjl    /*
696118611Snjl     * Semantic analysis.  This can happen only after the
697118611Snjl     * namespace has been loaded and cross-referenced.
698118611Snjl     *
699118611Snjl     * part one - check control methods
700118611Snjl     */
701151937Sjkim    Event = UtBeginEvent ("Analyze control method return types");
702118611Snjl    AnalysisWalkInfo.MethodStack = NULL;
703118611Snjl
704118611Snjl    DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n");
705151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE,
706151937Sjkim        AnMethodAnalysisWalkBegin,
707151937Sjkim        AnMethodAnalysisWalkEnd, &AnalysisWalkInfo);
708151937Sjkim    UtEndEvent (Event);
709118611Snjl
710118611Snjl    /* Semantic error checking part two - typing of method returns */
711118611Snjl
712151937Sjkim    Event = UtBeginEvent ("Determine object types returned by methods");
713151937Sjkim    DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing\n\n");
714151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE,
715151937Sjkim        AnMethodTypingWalkBegin,
716151937Sjkim        AnMethodTypingWalkEnd, NULL);
717151937Sjkim    UtEndEvent (Event);
718118611Snjl
719118611Snjl    /* Semantic error checking part three - operand type checking */
720118611Snjl
721151937Sjkim    Event = UtBeginEvent ("Analyze AML operand types");
722151937Sjkim    DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking\n\n");
723151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE,
724151937Sjkim        AnOperandTypecheckWalkBegin,
725151937Sjkim        AnOperandTypecheckWalkEnd, &AnalysisWalkInfo);
726151937Sjkim    UtEndEvent (Event);
727118611Snjl
728118611Snjl    /* Semantic error checking part four - other miscellaneous checks */
729118611Snjl
730151937Sjkim    Event = UtBeginEvent ("Miscellaneous analysis");
731151937Sjkim    DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous\n\n");
732151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE,
733151937Sjkim        AnOtherSemanticAnalysisWalkBegin,
734151937Sjkim        AnOtherSemanticAnalysisWalkEnd, &AnalysisWalkInfo);
735151937Sjkim    UtEndEvent (Event);
736118611Snjl
737118611Snjl    /* Calculate all AML package lengths */
738118611Snjl
739151937Sjkim    Event = UtBeginEvent ("Finish AML package length generation");
740118611Snjl    DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n");
741151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
742151937Sjkim        LnInitLengthsWalk, NULL);
743151937Sjkim    TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
744151937Sjkim        LnPackageLengthWalk, NULL);
745151937Sjkim    UtEndEvent (Event);
746118611Snjl
747118611Snjl    /* Code generation - emit the AML */
748118611Snjl
749151937Sjkim    Event = UtBeginEvent ("Generate AML code and write output files");
750118611Snjl    CgGenerateAmlOutput ();
751151937Sjkim    UtEndEvent (Event);
752118611Snjl
753151937Sjkim    Event = UtBeginEvent ("Write optional output files");
754118611Snjl    CmDoOutputFiles ();
755151937Sjkim    UtEndEvent (Event);
756118611Snjl
757151937Sjkim    UtEndEvent (FullCompile);
758118611Snjl    CmCleanupAndExit ();
759118611Snjl    return 0;
760118611Snjl}
761118611Snjl
762151937Sjkim
763151937Sjkim/*******************************************************************************
764151937Sjkim *
765151937Sjkim * FUNCTION:    CmDoOutputFiles
766151937Sjkim *
767151937Sjkim * PARAMETERS:  None
768151937Sjkim *
769151937Sjkim * RETURN:      None.
770151937Sjkim *
771151937Sjkim * DESCRIPTION: Create all "listing" type files
772151937Sjkim *
773151937Sjkim ******************************************************************************/
774151937Sjkim
775118611Snjlvoid
776151937SjkimCmDoOutputFiles (
777151937Sjkim    void)
778118611Snjl{
779118611Snjl
780118611Snjl    /* Create listings and hex files */
781118611Snjl
782118611Snjl    LsDoListings ();
783118611Snjl    LsDoHexOutput ();
784118611Snjl
785118611Snjl    /* Dump the namespace to the .nsp file if requested */
786118611Snjl
787151937Sjkim    (void) LsDisplayNamespace ();
788118611Snjl}
789118611Snjl
790118611Snjl
791118611Snjl/*******************************************************************************
792118611Snjl *
793151937Sjkim * FUNCTION:    CmDumpEvent
794151937Sjkim *
795151937Sjkim * PARAMETERS:  Event           - A compiler event struct
796151937Sjkim *
797151937Sjkim * RETURN:      None.
798151937Sjkim *
799151937Sjkim * DESCRIPTION: Dump a compiler event struct
800151937Sjkim *
801151937Sjkim ******************************************************************************/
802151937Sjkim
803151937Sjkimstatic void
804151937SjkimCmDumpEvent (
805151937Sjkim    ASL_EVENT_INFO          *Event)
806151937Sjkim{
807151937Sjkim    UINT32                  Delta;
808151937Sjkim    UINT32                  USec;
809151937Sjkim    UINT32                  MSec;
810151937Sjkim
811151937Sjkim    if (!Event->Valid)
812151937Sjkim    {
813151937Sjkim        return;
814151937Sjkim    }
815151937Sjkim
816151937Sjkim    /* Delta will be in 100-nanosecond units */
817151937Sjkim
818151937Sjkim    Delta = (UINT32) (Event->EndTime - Event->StartTime);
819151937Sjkim
820151937Sjkim    USec = Delta / 10;
821151937Sjkim    MSec = Delta / 10000;
822151937Sjkim
823151937Sjkim    /* Round milliseconds up */
824151937Sjkim
825151937Sjkim    if ((USec - (MSec * 1000)) >= 500)
826151937Sjkim    {
827151937Sjkim        MSec++;
828151937Sjkim    }
829151937Sjkim
830151937Sjkim    DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",
831151937Sjkim        USec, MSec, Event->EventName);
832151937Sjkim}
833151937Sjkim
834151937Sjkim
835151937Sjkim/*******************************************************************************
836151937Sjkim *
837118611Snjl * FUNCTION:    CmCleanupAndExit
838118611Snjl *
839118611Snjl * PARAMETERS:  None
840118611Snjl *
841118611Snjl * RETURN:      None.
842118611Snjl *
843118611Snjl * DESCRIPTION: Close all open files and exit the compiler
844118611Snjl *
845118611Snjl ******************************************************************************/
846118611Snjl
847118611Snjlvoid
848151937SjkimCmCleanupAndExit (
849151937Sjkim    void)
850118611Snjl{
851118611Snjl    UINT32                  i;
852118611Snjl
853118611Snjl
854118611Snjl    AePrintErrorLog (ASL_FILE_STDOUT);
855118611Snjl    if (Gbl_DebugFlag)
856118611Snjl    {
857118611Snjl        /* Print error summary to the debug file */
858118611Snjl
859118611Snjl        AePrintErrorLog (ASL_FILE_STDERR);
860118611Snjl    }
861118611Snjl
862118611Snjl    DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");
863151937Sjkim    for (i = 0; i < AslGbl_NextEvent; i++)
864118611Snjl    {
865151937Sjkim        CmDumpEvent (&AslGbl_Events[i]);
866118611Snjl    }
867118611Snjl
868118611Snjl    if (Gbl_CompileTimesFlag)
869118611Snjl    {
870118611Snjl        printf ("\nElapsed time for major events\n\n");
871151937Sjkim        for (i = 0; i < AslGbl_NextEvent; i++)
872118611Snjl        {
873151937Sjkim            CmDumpEvent (&AslGbl_Events[i]);
874118611Snjl        }
875151937Sjkim
876118611Snjl        printf ("\nMiscellaneous compile statistics\n\n");
877118611Snjl        printf ("%11u : %s\n", TotalParseNodes, "Parse nodes");
878118611Snjl        printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches");
879118611Snjl        printf ("%11u : %s\n", TotalNamedObjects, "Named objects");
880118611Snjl        printf ("%11u : %s\n", TotalMethods, "Control methods");
881118611Snjl        printf ("%11u : %s\n", TotalAllocations, "Memory Allocations");
882118611Snjl        printf ("%11u : %s\n", TotalAllocated, "Total allocated memory");
883118611Snjl        printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded");
884118611Snjl        printf ("\n");
885118611Snjl    }
886118611Snjl
887118611Snjl    if (Gbl_NsLookupCount)
888118611Snjl    {
889118611Snjl        DbgPrint (ASL_DEBUG_OUTPUT, "\n\nMiscellaneous compile statistics\n\n");
890151937Sjkim        DbgPrint (ASL_DEBUG_OUTPUT, "%32s : %d\n", "Total Namespace searches",
891151937Sjkim            Gbl_NsLookupCount);
892151937Sjkim        DbgPrint (ASL_DEBUG_OUTPUT, "%32s : %d usec\n", "Time per search",
893151937Sjkim            ((UINT32) (AslGbl_Events[AslGbl_NamespaceEvent].EndTime -
894151937Sjkim                        AslGbl_Events[AslGbl_NamespaceEvent].StartTime) /
895151937Sjkim                        10) / Gbl_NsLookupCount);
896118611Snjl    }
897118611Snjl
898118611Snjl
899118611Snjl    if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
900118611Snjl    {
901167802Sjkim        printf ("\nMaximum error count (%d) exceeded\n", ASL_MAX_ERROR_COUNT);
902118611Snjl    }
903118611Snjl
904118611Snjl    UtDisplaySummary (ASL_FILE_STDOUT);
905199337Sjkim
906199337Sjkim    /* Close all open files */
907199337Sjkim
908199337Sjkim    for (i = 2; i < ASL_MAX_FILE_TYPE; i++)
909199337Sjkim    {
910199337Sjkim        FlCloseFile (i);
911199337Sjkim    }
912200553Sjkim
913200553Sjkim    /* Delete AML file if there are errors */
914200553Sjkim
915200553Sjkim    if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors))
916200553Sjkim    {
917200553Sjkim        remove (Gbl_Files[ASL_FILE_AML_OUTPUT].Filename);
918200553Sjkim    }
919200553Sjkim
920200553Sjkim    /*
921200553Sjkim     * Delete intermediate ("combined") source file (if -ls flag not set)
922200553Sjkim     *
923200553Sjkim     * TBD: SourceOutput should be .TMP, then rename if we want to keep it?
924200553Sjkim     */
925200553Sjkim    if (!Gbl_SourceOutputFlag)
926200553Sjkim    {
927200553Sjkim        if (remove (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename))
928200553Sjkim        {
929200553Sjkim            printf ("Could not remove SRC file, %s\n",
930200553Sjkim                Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
931200553Sjkim        }
932200553Sjkim    }
933118611Snjl}
934118611Snjl
935118611Snjl
936