aslmain.c revision 197104
1118611Snjl
2118611Snjl/******************************************************************************
3118611Snjl *
4118611Snjl * Module Name: aslmain - compiler main and utilities
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
118118611Snjl#define _DECLARE_GLOBALS
119118611Snjl
120151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
121193529Sjkim#include <contrib/dev/acpica/include/acapps.h>
122118611Snjl
123118611Snjl#ifdef _DEBUG
124118611Snjl#include <crtdbg.h>
125118611Snjl#endif
126118611Snjl
127118611Snjl#define _COMPONENT          ACPI_COMPILER
128118611Snjl        ACPI_MODULE_NAME    ("aslmain")
129118611Snjl
130151937Sjkim/* Local prototypes */
131118611Snjl
132151937Sjkimstatic void
133151937SjkimOptions (
134151937Sjkim    void);
135151937Sjkim
136151937Sjkimstatic void
137151937SjkimHelpMessage (
138151937Sjkim    void);
139151937Sjkim
140151937Sjkimstatic void
141151937SjkimUsage (
142151937Sjkim    void);
143151937Sjkim
144151937Sjkimstatic void
145151937SjkimAslInitialize (
146151937Sjkim    void);
147151937Sjkim
148193529Sjkimstatic int
149151937SjkimAslCommandLine (
150151937Sjkim    int                     argc,
151151937Sjkim    char                    **argv);
152151937Sjkim
153197104Sjkimstatic int
154197104SjkimAslDoOptions (
155197104Sjkim    int                     argc,
156197104Sjkim    char                    **argv,
157197104Sjkim    BOOLEAN                 IsResponseFile);
158151937Sjkim
159197104Sjkimstatic void
160197104SjkimAslMergeOptionTokens (
161197104Sjkim    char                    *InBuffer,
162197104Sjkim    char                    *OutBuffer);
163197104Sjkim
164197104Sjkimstatic int
165197104SjkimAslDoResponseFile (
166197104Sjkim    char                    *Filename);
167197104Sjkim
168197104Sjkimextern int   AcpiGbl_Opterr;
169197104Sjkimextern int   AcpiGbl_Optind;
170197104Sjkim
171197104Sjkim
172197104Sjkim#define ASL_TOKEN_SEPARATORS    " \t\n"
173197104Sjkim#define ASL_SUPPORTED_OPTIONS   "@:2b:cd^e:fgh^i^I:l^o:p:r:s:t:v:w:x:"
174197104Sjkim
175197104Sjkim
176118611Snjl/*******************************************************************************
177118611Snjl *
178118611Snjl * FUNCTION:    Options
179118611Snjl *
180118611Snjl * PARAMETERS:  None
181118611Snjl *
182118611Snjl * RETURN:      None
183118611Snjl *
184118611Snjl * DESCRIPTION: Display option help message
185118611Snjl *
186118611Snjl ******************************************************************************/
187118611Snjl
188151937Sjkimstatic void
189118611SnjlOptions (
190118611Snjl    void)
191118611Snjl{
192118611Snjl
193197104Sjkim    printf ("Global:\n");
194197104Sjkim    printf ("  -@<file>       Specify command file\n");
195197104Sjkim    printf ("  -I<dir>        Specify additional include directory\n");
196197104Sjkim
197197104Sjkim    printf ("\nGeneral Output:\n");
198197104Sjkim    printf ("  -p<prefix>     Specify path/filename prefix for all output files\n");
199193529Sjkim    printf ("  -va            Disable all errors and warnings (summary only)\n");
200118611Snjl    printf ("  -vi            Less verbose errors and warnings for use with IDEs\n");
201118611Snjl    printf ("  -vo            Enable optimization comments\n");
202118611Snjl    printf ("  -vr            Disable remarks\n");
203118611Snjl    printf ("  -vs            Disable signon\n");
204167802Sjkim    printf ("  -w<1|2|3>      Set warning reporting level\n");
205118611Snjl
206138287Smarks    printf ("\nAML Output Files:\n");
207118611Snjl    printf ("  -s<a|c>        Create AML in assembler or C source file (*.asm or *.c)\n");
208118611Snjl    printf ("  -i<a|c>        Create assembler or C include file (*.inc or *.h)\n");
209118611Snjl    printf ("  -t<a|c>        Create AML in assembler or C hex table (*.hex)\n");
210118611Snjl
211138287Smarks    printf ("\nAML Code Generation:\n");
212118611Snjl    printf ("  -oa            Disable all optimizations (compatibility mode)\n");
213118611Snjl    printf ("  -of            Disable constant folding\n");
214118611Snjl    printf ("  -oi            Disable integer optimization to Zero/One/Ones\n");
215118611Snjl    printf ("  -on            Disable named reference string optimization\n");
216138287Smarks    printf ("  -r<Revision>   Override table header Revision (1-255)\n");
217118611Snjl
218118611Snjl    printf ("\nListings:\n");
219118611Snjl    printf ("  -l             Create mixed listing file (ASL source and AML) (*.lst)\n");
220118611Snjl    printf ("  -ln            Create namespace file (*.nsp)\n");
221118611Snjl    printf ("  -ls            Create combined source file (expanded includes) (*.src)\n");
222118611Snjl
223118611Snjl    printf ("\nAML Disassembler:\n");
224167802Sjkim    printf ("  -d  [file]     Disassemble or decode binary ACPI table to file (*.dsl)\n");
225118611Snjl    printf ("  -dc [file]     Disassemble AML and immediately compile it\n");
226118611Snjl    printf ("                 (Obtain DSDT from current system if no input file)\n");
227193529Sjkim    printf ("  -e  [f1,f2]    Include ACPI table(s) for external symbol resolution\n");
228151937Sjkim    printf ("  -2             Emit ACPI 2.0 compatible ASL code\n");
229118611Snjl    printf ("  -g             Get ACPI tables and write to files (*.dat)\n");
230118611Snjl
231118611Snjl    printf ("\nHelp:\n");
232118611Snjl    printf ("  -h             Additional help and compiler debug options\n");
233118611Snjl    printf ("  -hc            Display operators allowed in constant expressions\n");
234118611Snjl    printf ("  -hr            Display ACPI reserved method names\n");
235118611Snjl}
236118611Snjl
237118611Snjl
238118611Snjl/*******************************************************************************
239118611Snjl *
240151937Sjkim * FUNCTION:    HelpMessage
241118611Snjl *
242118611Snjl * PARAMETERS:  None
243118611Snjl *
244118611Snjl * RETURN:      None
245118611Snjl *
246118611Snjl * DESCRIPTION: Display help message
247118611Snjl *
248118611Snjl ******************************************************************************/
249118611Snjl
250151937Sjkimstatic void
251118611SnjlHelpMessage (
252118611Snjl    void)
253118611Snjl{
254118611Snjl
255118611Snjl    printf ("AML output filename generation:\n");
256118611Snjl    printf ("  Output filenames are generated by appending an extension to a common\n");
257118611Snjl    printf ("  filename prefix.  The filename prefix is obtained via one of the\n");
258118611Snjl    printf ("  following methods (in priority order):\n");
259118611Snjl    printf ("    1) The -p option specifies the prefix\n");
260118611Snjl    printf ("    2) The prefix of the AMLFileName in the ASL Definition Block\n");
261118611Snjl    printf ("    3) The prefix of the input filename\n");
262118611Snjl    printf ("\n");
263118611Snjl
264118611Snjl    Options ();
265118611Snjl
266167802Sjkim    printf ("\nCompiler/Disassembler Debug Options:\n");
267118611Snjl    printf ("  -b<p|t|b>      Create compiler debug/trace file (*.txt)\n");
268118611Snjl    printf ("                   Types: Parse/Tree/Both\n");
269118611Snjl    printf ("  -f             Ignore errors, force creation of AML output file(s)\n");
270118611Snjl    printf ("  -c             Parse only, no output generation\n");
271118611Snjl    printf ("  -ot            Display compile times\n");
272118611Snjl    printf ("  -x<level>      Set debug level for trace output\n");
273118611Snjl}
274118611Snjl
275118611Snjl
276118611Snjl/*******************************************************************************
277118611Snjl *
278118611Snjl * FUNCTION:    Usage
279118611Snjl *
280118611Snjl * PARAMETERS:  None
281118611Snjl *
282118611Snjl * RETURN:      None
283118611Snjl *
284118611Snjl * DESCRIPTION: Display usage and option message
285118611Snjl *
286118611Snjl ******************************************************************************/
287118611Snjl
288151937Sjkimstatic void
289118611SnjlUsage (
290118611Snjl    void)
291118611Snjl{
292118611Snjl
293193529Sjkim    printf ("Usage:    %s [Options] [Files]\n\n", CompilerName);
294118611Snjl    Options ();
295118611Snjl}
296118611Snjl
297118611Snjl
298118611Snjl/*******************************************************************************
299118611Snjl *
300118611Snjl * FUNCTION:    AslInitialize
301118611Snjl *
302118611Snjl * PARAMETERS:  None
303118611Snjl *
304118611Snjl * RETURN:      None
305118611Snjl *
306118611Snjl * DESCRIPTION: Initialize compiler globals
307118611Snjl *
308118611Snjl ******************************************************************************/
309118611Snjl
310151937Sjkimstatic void
311151937SjkimAslInitialize (
312151937Sjkim    void)
313118611Snjl{
314118611Snjl    UINT32                  i;
315118611Snjl
316118611Snjl
317118611Snjl#ifdef _DEBUG
318118611Snjl    _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
319118611Snjl#endif
320118611Snjl
321118611Snjl    AcpiDbgLevel = 0;
322118611Snjl
323118611Snjl    for (i = 0; i < ASL_NUM_FILES; i++)
324118611Snjl    {
325118611Snjl        Gbl_Files[i].Handle = NULL;
326118611Snjl        Gbl_Files[i].Filename = NULL;
327118611Snjl    }
328118611Snjl
329118611Snjl    Gbl_Files[ASL_FILE_STDOUT].Handle   = stdout;
330118611Snjl    Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
331118611Snjl
332118611Snjl    Gbl_Files[ASL_FILE_STDERR].Handle   = stderr;
333118611Snjl    Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
334118611Snjl}
335118611Snjl
336118611Snjl
337118611Snjl/*******************************************************************************
338118611Snjl *
339197104Sjkim * FUNCTION:    AslMergeOptionTokens
340118611Snjl *
341197104Sjkim * PARAMETERS:  InBuffer            - Input containing an option string
342197104Sjkim *              OutBuffer           - Merged output buffer
343118611Snjl *
344118611Snjl * RETURN:      None
345118611Snjl *
346197104Sjkim * DESCRIPTION: Remove all whitespace from an option string.
347118611Snjl *
348118611Snjl ******************************************************************************/
349118611Snjl
350197104Sjkimstatic void
351197104SjkimAslMergeOptionTokens (
352197104Sjkim    char                    *InBuffer,
353197104Sjkim    char                    *OutBuffer)
354197104Sjkim{
355197104Sjkim    char                    *Token;
356197104Sjkim
357197104Sjkim
358197104Sjkim    *OutBuffer = 0;
359197104Sjkim
360197104Sjkim    Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
361197104Sjkim    while (Token)
362197104Sjkim    {
363197104Sjkim        strcat (OutBuffer, Token);
364197104Sjkim        Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
365197104Sjkim    }
366197104Sjkim}
367197104Sjkim
368197104Sjkim
369197104Sjkim/*******************************************************************************
370197104Sjkim *
371197104Sjkim * FUNCTION:    AslDoResponseFile
372197104Sjkim *
373197104Sjkim * PARAMETERS:  Filename        - Name of the response file
374197104Sjkim *
375197104Sjkim * RETURN:      Status
376197104Sjkim *
377197104Sjkim * DESCRIPTION: Open a response file and process all options within.
378197104Sjkim *
379197104Sjkim ******************************************************************************/
380197104Sjkim
381193529Sjkimstatic int
382197104SjkimAslDoResponseFile (
383197104Sjkim    char                    *Filename)
384118611Snjl{
385197104Sjkim    char                    *argv = StringBuffer2;
386197104Sjkim    FILE                    *ResponseFile;
387197104Sjkim    int                     OptStatus = 0;
388197104Sjkim    int                     Opterr;
389197104Sjkim    int                     Optind;
390118611Snjl
391118611Snjl
392197104Sjkim    ResponseFile = fopen (Filename, "r");
393197104Sjkim    if (!ResponseFile)
394197104Sjkim    {
395197104Sjkim        printf ("Could not open command file %s, %s\n",
396197104Sjkim            Filename, strerror (errno));
397197104Sjkim        return -1;
398197104Sjkim    }
399118611Snjl
400197104Sjkim    /* Must save the current GetOpt globals */
401197104Sjkim
402197104Sjkim    Opterr = AcpiGbl_Opterr;
403197104Sjkim    Optind = AcpiGbl_Optind;
404197104Sjkim
405197104Sjkim    /*
406197104Sjkim     * Process all lines in the response file. There must be one complete
407197104Sjkim     * option per line
408197104Sjkim     */
409197104Sjkim    while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
410118611Snjl    {
411197104Sjkim        /* Compress all tokens, allowing us to use a single argv entry */
412197104Sjkim
413197104Sjkim        AslMergeOptionTokens (StringBuffer, StringBuffer2);
414197104Sjkim
415197104Sjkim        /* Process the option */
416197104Sjkim
417197104Sjkim        AcpiGbl_Opterr = 0;
418197104Sjkim        AcpiGbl_Optind = 0;
419197104Sjkim
420197104Sjkim        OptStatus = AslDoOptions (1, &argv, TRUE);
421197104Sjkim        if (OptStatus)
422197104Sjkim        {
423197104Sjkim            printf ("Invalid option in command file %s: %s\n",
424197104Sjkim                Filename, StringBuffer);
425197104Sjkim            break;
426197104Sjkim        }
427118611Snjl    }
428118611Snjl
429197104Sjkim    /* Restore the GetOpt globals */
430197104Sjkim
431197104Sjkim    AcpiGbl_Opterr = Opterr;
432197104Sjkim    AcpiGbl_Optind = Optind;
433197104Sjkim
434197104Sjkim    fclose (ResponseFile);
435197104Sjkim    return (OptStatus);
436197104Sjkim}
437197104Sjkim
438197104Sjkim
439197104Sjkim/*******************************************************************************
440197104Sjkim *
441197104Sjkim * FUNCTION:    AslDoOptions
442197104Sjkim *
443197104Sjkim * PARAMETERS:  argc/argv           - Standard argc/argv
444197104Sjkim *              IsResponseFile      - TRUE if executing a response file.
445197104Sjkim *
446197104Sjkim * RETURN:      Status
447197104Sjkim *
448197104Sjkim * DESCRIPTION: Command line option processing
449197104Sjkim *
450197104Sjkim ******************************************************************************/
451197104Sjkim
452197104Sjkimstatic int
453197104SjkimAslDoOptions (
454197104Sjkim    int                     argc,
455197104Sjkim    char                    **argv,
456197104Sjkim    BOOLEAN                 IsResponseFile)
457197104Sjkim{
458197104Sjkim    int                     j;
459197104Sjkim
460197104Sjkim
461118611Snjl    /* Get the command line options */
462118611Snjl
463197104Sjkim    while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
464118611Snjl    {
465197104Sjkim    case '@':   /* Begin a response file */
466197104Sjkim
467197104Sjkim        if (IsResponseFile)
468197104Sjkim        {
469197104Sjkim            printf ("Nested command files are not supported\n");
470197104Sjkim            return -1;
471197104Sjkim        }
472197104Sjkim
473197104Sjkim        if (AslDoResponseFile (AcpiGbl_Optarg))
474197104Sjkim        {
475197104Sjkim            return -1;
476197104Sjkim        }
477197104Sjkim        break;
478197104Sjkim
479197104Sjkim
480151937Sjkim    case '2':
481197104Sjkim
482151937Sjkim        Gbl_Acpi2 = TRUE;
483151937Sjkim        break;
484151937Sjkim
485151937Sjkim
486118611Snjl    case 'b':
487118611Snjl
488118611Snjl        switch (AcpiGbl_Optarg[0])
489118611Snjl        {
490118611Snjl        case 'b':
491118611Snjl            AslCompilerdebug = 1; /* same as yydebug */
492118611Snjl            break;
493118611Snjl
494118611Snjl        case 'p':
495118611Snjl            AslCompilerdebug = 1; /* same as yydebug */
496118611Snjl            break;
497118611Snjl
498118611Snjl        case 't':
499118611Snjl            break;
500118611Snjl
501118611Snjl        default:
502118611Snjl            printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
503197104Sjkim            return (-1);
504118611Snjl        }
505118611Snjl
506118611Snjl        /* Produce debug output file */
507118611Snjl
508118611Snjl        Gbl_DebugFlag = TRUE;
509118611Snjl        break;
510118611Snjl
511118611Snjl
512118611Snjl    case 'c':
513118611Snjl
514118611Snjl        /* Parse only */
515118611Snjl
516118611Snjl        Gbl_ParseOnlyFlag = TRUE;
517118611Snjl        break;
518118611Snjl
519118611Snjl
520118611Snjl    case 'd':
521118611Snjl        switch (AcpiGbl_Optarg[0])
522118611Snjl        {
523118611Snjl        case '^':
524193529Sjkim            Gbl_DoCompile = FALSE;
525118611Snjl            break;
526118611Snjl
527118611Snjl        case 'c':
528118611Snjl            break;
529118611Snjl
530118611Snjl        default:
531118611Snjl            printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
532197104Sjkim            return (-1);
533118611Snjl        }
534118611Snjl
535118611Snjl        Gbl_DisasmFlag = TRUE;
536118611Snjl        break;
537118611Snjl
538118611Snjl
539118611Snjl    case 'e':
540167802Sjkim        Gbl_ExternalFilename = AcpiGbl_Optarg;
541118611Snjl        break;
542118611Snjl
543118611Snjl
544118611Snjl    case 'f':
545118611Snjl
546118611Snjl        /* Ignore errors and force creation of aml file */
547118611Snjl
548118611Snjl        Gbl_IgnoreErrors = TRUE;
549118611Snjl        break;
550118611Snjl
551118611Snjl
552118611Snjl    case 'g':
553118611Snjl
554118611Snjl        /* Get all ACPI tables */
555118611Snjl
556118611Snjl        Gbl_GetAllTables = TRUE;
557193529Sjkim        Gbl_DoCompile = FALSE;
558118611Snjl        break;
559118611Snjl
560118611Snjl
561118611Snjl    case 'h':
562118611Snjl
563118611Snjl        switch (AcpiGbl_Optarg[0])
564118611Snjl        {
565118611Snjl        case '^':
566118611Snjl            HelpMessage ();
567118611Snjl            exit (0);
568118611Snjl
569118611Snjl        case 'c':
570118611Snjl            UtDisplayConstantOpcodes ();
571118611Snjl            exit (0);
572118611Snjl
573118611Snjl        case 'r':
574118611Snjl            /* reserved names */
575118611Snjl
576118611Snjl            MpDisplayReservedNames ();
577118611Snjl            exit (0);
578118611Snjl
579118611Snjl        default:
580118611Snjl            printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
581197104Sjkim            return (-1);
582118611Snjl        }
583118611Snjl        break;
584118611Snjl
585118611Snjl
586197104Sjkim    case 'I': /* Add an include file search directory */
587197104Sjkim
588197104Sjkim        FlAddIncludeDirectory (AcpiGbl_Optarg);
589197104Sjkim        break;
590197104Sjkim
591197104Sjkim
592118611Snjl    case 'i':
593118611Snjl
594118611Snjl        switch (AcpiGbl_Optarg[0])
595118611Snjl        {
596118611Snjl        case 'a':
597118611Snjl
598118611Snjl            /* Produce assembly code include file */
599118611Snjl
600118611Snjl            Gbl_AsmIncludeOutputFlag = TRUE;
601118611Snjl            break;
602118611Snjl
603118611Snjl        case 'c':
604118611Snjl
605118611Snjl            /* Produce C include file */
606118611Snjl
607118611Snjl            Gbl_C_IncludeOutputFlag = TRUE;
608118611Snjl            break;
609118611Snjl
610118611Snjl        default:
611118611Snjl            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
612197104Sjkim            return (-1);
613118611Snjl        }
614118611Snjl        break;
615118611Snjl
616118611Snjl
617118611Snjl    case 'l':
618118611Snjl
619118611Snjl        switch (AcpiGbl_Optarg[0])
620118611Snjl        {
621118611Snjl        case '^':
622118611Snjl            /* Produce listing file (Mixed source/aml) */
623118611Snjl
624118611Snjl            Gbl_ListingFlag = TRUE;
625118611Snjl            break;
626118611Snjl
627118611Snjl        case 'n':
628118611Snjl            /* Produce namespace file */
629118611Snjl
630118611Snjl            Gbl_NsOutputFlag = TRUE;
631118611Snjl            break;
632118611Snjl
633118611Snjl        case 's':
634118611Snjl            /* Produce combined source file */
635118611Snjl
636118611Snjl            Gbl_SourceOutputFlag = TRUE;
637118611Snjl            break;
638118611Snjl
639118611Snjl        default:
640118611Snjl            printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
641197104Sjkim            return (-1);
642118611Snjl        }
643118611Snjl        break;
644118611Snjl
645118611Snjl
646118611Snjl    case 'o':
647118611Snjl
648118611Snjl        switch (AcpiGbl_Optarg[0])
649118611Snjl        {
650118611Snjl        case 'a':
651118611Snjl
652118611Snjl            /* Disable all optimizations */
653118611Snjl
654118611Snjl            Gbl_FoldConstants = FALSE;
655118611Snjl            Gbl_IntegerOptimizationFlag = FALSE;
656118611Snjl            Gbl_ReferenceOptimizationFlag = FALSE;
657118611Snjl            break;
658118611Snjl
659118611Snjl        case 'f':
660118611Snjl
661118611Snjl            /* Disable folding on "normal" expressions */
662118611Snjl
663118611Snjl            Gbl_FoldConstants = FALSE;
664118611Snjl            break;
665118611Snjl
666118611Snjl        case 'i':
667118611Snjl
668118611Snjl            /* Disable integer optimization to constants */
669118611Snjl
670118611Snjl            Gbl_IntegerOptimizationFlag = FALSE;
671118611Snjl            break;
672118611Snjl
673118611Snjl        case 'n':
674118611Snjl
675118611Snjl            /* Disable named reference optimization */
676118611Snjl
677118611Snjl            Gbl_ReferenceOptimizationFlag = FALSE;
678118611Snjl            break;
679118611Snjl
680118611Snjl        case 't':
681118611Snjl
682118611Snjl            /* Display compile time(s) */
683118611Snjl
684118611Snjl            Gbl_CompileTimesFlag = TRUE;
685118611Snjl            break;
686118611Snjl
687118611Snjl        default:
688118611Snjl            printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
689197104Sjkim            return (-1);
690118611Snjl        }
691118611Snjl        break;
692118611Snjl
693118611Snjl
694118611Snjl    case 'p':
695118611Snjl
696118611Snjl        /* Override default AML output filename */
697118611Snjl
698118611Snjl        Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
699118611Snjl        Gbl_UseDefaultAmlFilename = FALSE;
700118611Snjl        break;
701118611Snjl
702118611Snjl
703118611Snjl    case 'r':
704138287Smarks        Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
705118611Snjl        break;
706118611Snjl
707118611Snjl
708118611Snjl    case 's':
709118611Snjl
710118611Snjl        switch (AcpiGbl_Optarg[0])
711118611Snjl        {
712118611Snjl        case 'a':
713118611Snjl
714118611Snjl            /* Produce assembly code output file */
715118611Snjl
716118611Snjl            Gbl_AsmOutputFlag = TRUE;
717118611Snjl            break;
718118611Snjl
719118611Snjl        case 'c':
720118611Snjl
721118611Snjl            /* Produce C hex output file */
722118611Snjl
723118611Snjl            Gbl_C_OutputFlag = TRUE;
724118611Snjl            break;
725118611Snjl
726118611Snjl        default:
727118611Snjl            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
728197104Sjkim            return (-1);
729118611Snjl        }
730118611Snjl        break;
731118611Snjl
732118611Snjl
733118611Snjl    case 't':
734118611Snjl
735118611Snjl        /* Produce hex table output file */
736118611Snjl
737118611Snjl        switch (AcpiGbl_Optarg[0])
738118611Snjl        {
739118611Snjl        case 'a':
740118611Snjl            Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
741118611Snjl            break;
742118611Snjl
743118611Snjl        case 'c':
744118611Snjl            Gbl_HexOutputFlag = HEX_OUTPUT_C;
745118611Snjl            break;
746118611Snjl
747118611Snjl        default:
748118611Snjl            printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
749197104Sjkim            return (-1);
750118611Snjl        }
751118611Snjl        break;
752118611Snjl
753118611Snjl
754118611Snjl    case 'v':
755118611Snjl
756118611Snjl        switch (AcpiGbl_Optarg[0])
757118611Snjl        {
758193529Sjkim        case 'a':
759193529Sjkim            /* Disable All error/warning messages */
760193529Sjkim
761193529Sjkim            Gbl_NoErrors = TRUE;
762193529Sjkim            break;
763193529Sjkim
764118611Snjl        case 'i':
765118611Snjl            /* Less verbose error messages */
766118611Snjl
767118611Snjl            Gbl_VerboseErrors = FALSE;
768118611Snjl            break;
769118611Snjl
770118611Snjl        case 'o':
771118611Snjl            Gbl_DisplayOptimizations = TRUE;
772118611Snjl            break;
773118611Snjl
774118611Snjl        case 'r':
775118611Snjl            Gbl_DisplayRemarks = FALSE;
776118611Snjl            break;
777118611Snjl
778118611Snjl        case 's':
779193529Sjkim            Gbl_DoSignon = FALSE;
780118611Snjl            break;
781118611Snjl
782118611Snjl        default:
783118611Snjl            printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
784197104Sjkim            return (-1);
785118611Snjl        }
786118611Snjl        break;
787118611Snjl
788118611Snjl
789167802Sjkim    case 'w': /* Set warning levels */
790167802Sjkim
791167802Sjkim        switch (AcpiGbl_Optarg[0])
792167802Sjkim        {
793167802Sjkim        case '1':
794167802Sjkim            Gbl_WarningLevel = ASL_WARNING;
795167802Sjkim            break;
796167802Sjkim
797167802Sjkim        case '2':
798167802Sjkim            Gbl_WarningLevel = ASL_WARNING2;
799167802Sjkim            break;
800167802Sjkim
801167802Sjkim        case '3':
802167802Sjkim            Gbl_WarningLevel = ASL_WARNING3;
803167802Sjkim            break;
804167802Sjkim
805167802Sjkim        default:
806167802Sjkim            printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
807197104Sjkim            return (-1);
808167802Sjkim        }
809167802Sjkim        break;
810167802Sjkim
811167802Sjkim
812118611Snjl    case 'x':
813118611Snjl
814118611Snjl        AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
815118611Snjl        break;
816118611Snjl
817118611Snjl
818118611Snjl    default:
819118611Snjl
820197104Sjkim        return (-1);
821118611Snjl    }
822118611Snjl
823197104Sjkim    return (0);
824197104Sjkim}
825197104Sjkim
826197104Sjkim
827197104Sjkim/*******************************************************************************
828197104Sjkim *
829197104Sjkim * FUNCTION:    AslCommandLine
830197104Sjkim *
831197104Sjkim * PARAMETERS:  argc/argv
832197104Sjkim *
833197104Sjkim * RETURN:      Last argv index
834197104Sjkim *
835197104Sjkim * DESCRIPTION: Command line processing
836197104Sjkim *
837197104Sjkim ******************************************************************************/
838197104Sjkim
839197104Sjkimstatic int
840197104SjkimAslCommandLine (
841197104Sjkim    int                     argc,
842197104Sjkim    char                    **argv)
843197104Sjkim{
844197104Sjkim    int                     BadCommandLine = 0;
845197104Sjkim
846197104Sjkim
847197104Sjkim    /* Minimum command line contains at least the command and an input file */
848197104Sjkim
849197104Sjkim    if (argc < 2)
850197104Sjkim    {
851197104Sjkim        AslCompilerSignon (ASL_FILE_STDOUT);
852197104Sjkim        Usage ();
853197104Sjkim        exit (1);
854197104Sjkim    }
855197104Sjkim
856197104Sjkim    /* Process all command line options */
857197104Sjkim
858197104Sjkim    BadCommandLine = AslDoOptions (argc, argv, FALSE);
859197104Sjkim
860118611Snjl    /* Next parameter must be the input filename */
861118611Snjl
862193529Sjkim    if (!argv[AcpiGbl_Optind] &&
863151937Sjkim        !Gbl_DisasmFlag &&
864151937Sjkim        !Gbl_GetAllTables)
865118611Snjl    {
866118611Snjl        printf ("Missing input filename\n");
867118611Snjl        BadCommandLine = TRUE;
868118611Snjl    }
869118611Snjl
870193529Sjkim    if (Gbl_DoSignon)
871118611Snjl    {
872118611Snjl        AslCompilerSignon (ASL_FILE_STDOUT);
873118611Snjl    }
874118611Snjl
875118611Snjl    /* Abort if anything went wrong on the command line */
876118611Snjl
877118611Snjl    if (BadCommandLine)
878118611Snjl    {
879118611Snjl        printf ("\n");
880118611Snjl        Usage ();
881118611Snjl        exit (1);
882118611Snjl    }
883118611Snjl
884193529Sjkim    return (AcpiGbl_Optind);
885118611Snjl}
886118611Snjl
887118611Snjl
888118611Snjl/*******************************************************************************
889118611Snjl *
890118611Snjl * FUNCTION:    main
891118611Snjl *
892118611Snjl * PARAMETERS:  Standard argc/argv
893118611Snjl *
894118611Snjl * RETURN:      Program termination code
895118611Snjl *
896193529Sjkim * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
897193529Sjkim *              options and begin the compile for each file on the command line
898118611Snjl *
899118611Snjl ******************************************************************************/
900118611Snjl
901118611Snjlint ACPI_SYSTEM_XFACE
902118611Snjlmain (
903118611Snjl    int                     argc,
904118611Snjl    char                    **argv)
905118611Snjl{
906118611Snjl    ACPI_STATUS             Status;
907193529Sjkim    int                     Index;
908118611Snjl
909118611Snjl
910151937Sjkim#ifdef _DEBUG
911151937Sjkim    _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
912151937Sjkim                    _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
913151937Sjkim#endif
914151937Sjkim
915118611Snjl    /* Init and command line */
916118611Snjl
917118611Snjl    AslInitialize ();
918193529Sjkim    Index = AslCommandLine (argc, argv);
919118611Snjl
920193529Sjkim    /* Options that have no additional parameters or pathnames */
921118611Snjl
922193529Sjkim    if (Gbl_GetAllTables)
923118611Snjl    {
924193529Sjkim        Status = AslDoOneFile (NULL);
925118611Snjl        if (ACPI_FAILURE (Status))
926118611Snjl        {
927193529Sjkim            return (-1);
928118611Snjl        }
929193529Sjkim        return (0);
930193529Sjkim    }
931118611Snjl
932193529Sjkim    /* Process each pathname/filename in the list, with possible wildcards */
933118611Snjl
934193529Sjkim    while (argv[Index])
935118611Snjl    {
936193529Sjkim        Status = AslDoOnePathname (argv[Index]);
937151937Sjkim        if (ACPI_FAILURE (Status))
938151937Sjkim        {
939193529Sjkim            return (-1);
940151937Sjkim        }
941118611Snjl
942193529Sjkim        Index++;
943118611Snjl    }
944118611Snjl
945118611Snjl    return (0);
946118611Snjl}
947118611Snjl
948118611Snjl
949