aslmain.c revision 229989
1356843Sdim
2356843Sdim/******************************************************************************
3356843Sdim *
4356843Sdim * Module Name: aslmain - compiler main and utilities
5356843Sdim *
6356843Sdim *****************************************************************************/
7356843Sdim
8356843Sdim/*
9356843Sdim * Copyright (C) 2000 - 2012, Intel Corp.
10356843Sdim * All rights reserved.
11356843Sdim *
12356843Sdim * Redistribution and use in source and binary forms, with or without
13356843Sdim * modification, are permitted provided that the following conditions
14356843Sdim * are met:
15356843Sdim * 1. Redistributions of source code must retain the above copyright
16356843Sdim *    notice, this list of conditions, and the following disclaimer,
17356843Sdim *    without modification.
18356843Sdim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19356843Sdim *    substantially similar to the "NO WARRANTY" disclaimer below
20356843Sdim *    ("Disclaimer") and any redistribution must be conditioned upon
21356843Sdim *    including a substantially similar Disclaimer requirement for further
22356843Sdim *    binary redistribution.
23356843Sdim * 3. Neither the names of the above-listed copyright holders nor the names
24356843Sdim *    of any contributors may be used to endorse or promote products derived
25356843Sdim *    from this software without specific prior written permission.
26356843Sdim *
27356843Sdim * Alternatively, this software may be distributed under the terms of the
28356843Sdim * GNU General Public License ("GPL") version 2 as published by the Free
29356843Sdim * Software Foundation.
30356843Sdim *
31356843Sdim * NO WARRANTY
32356843Sdim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33356843Sdim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34356843Sdim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35356843Sdim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36356843Sdim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37356843Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38356843Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39356843Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40356843Sdim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41356843Sdim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42356843Sdim * POSSIBILITY OF SUCH DAMAGES.
43356843Sdim */
44356843Sdim
45356843Sdim
46356843Sdim#define _DECLARE_GLOBALS
47356843Sdim
48356843Sdim#include <contrib/dev/acpica/compiler/aslcompiler.h>
49356843Sdim#include <contrib/dev/acpica/include/acapps.h>
50356843Sdim#include <contrib/dev/acpica/include/acdisasm.h>
51356843Sdim
52356843Sdim#ifdef _DEBUG
53356843Sdim#include <crtdbg.h>
54356843Sdim#endif
55356843Sdim
56356843Sdim#define _COMPONENT          ACPI_COMPILER
57356843Sdim        ACPI_MODULE_NAME    ("aslmain")
58356843Sdim
59356843Sdim/* Local prototypes */
60356843Sdim
61356843Sdimstatic void
62356843SdimOptions (
63356843Sdim    void);
64356843Sdim
65356843Sdimstatic void
66356843SdimHelpMessage (
67356843Sdim    void);
68356843Sdim
69356843Sdimstatic void
70356843SdimUsage (
71356843Sdim    void);
72356843Sdim
73356843Sdimstatic void
74356843SdimAslInitialize (
75356843Sdim    void);
76356843Sdim
77356843Sdimstatic int
78356843SdimAslCommandLine (
79356843Sdim    int                     argc,
80356843Sdim    char                    **argv);
81356843Sdim
82356843Sdimstatic int
83356843SdimAslDoOptions (
84356843Sdim    int                     argc,
85356843Sdim    char                    **argv,
86356843Sdim    BOOLEAN                 IsResponseFile);
87356843Sdim
88356843Sdimstatic void
89356843SdimAslMergeOptionTokens (
90356843Sdim    char                    *InBuffer,
91356843Sdim    char                    *OutBuffer);
92356843Sdim
93356843Sdimstatic int
94356843SdimAslDoResponseFile (
95356843Sdim    char                    *Filename);
96356843Sdim
97356843Sdim
98356843Sdim#define ASL_TOKEN_SEPARATORS    " \t\n"
99356843Sdim#define ASL_SUPPORTED_OPTIONS   "@:2b:c:d^e:fgh^i^I:l^mno:p:r:s:t:T:G^v:w:x:z"
100356843Sdim
101356843Sdim
102356843Sdim/*******************************************************************************
103356843Sdim *
104356843Sdim * FUNCTION:    Options
105356843Sdim *
106356843Sdim * PARAMETERS:  None
107356843Sdim *
108356843Sdim * RETURN:      None
109356843Sdim *
110356843Sdim * DESCRIPTION: Display option help message
111356843Sdim *
112356843Sdim ******************************************************************************/
113356843Sdim
114356843Sdimstatic void
115356843SdimOptions (
116356843Sdim    void)
117356843Sdim{
118356843Sdim
119356843Sdim    printf ("\nGlobal:\n");
120356843Sdim    ACPI_OPTION ("-@ <file>",       "Specify command file");
121356843Sdim    ACPI_OPTION ("-I <dir>",        "Specify additional include directory");
122356843Sdim
123356843Sdim    printf ("\nGeneral Output:\n");
124356843Sdim    ACPI_OPTION ("-p <prefix>",     "Specify path/filename prefix for all output files");
125356843Sdim    ACPI_OPTION ("-va",             "Disable all errors and warnings (summary only)");
126356843Sdim    ACPI_OPTION ("-vi",             "Less verbose errors and warnings for use with IDEs");
127356843Sdim    ACPI_OPTION ("-vo",             "Enable optimization comments");
128356843Sdim    ACPI_OPTION ("-vr",             "Disable remarks");
129356843Sdim    ACPI_OPTION ("-vs",             "Disable signon");
130356843Sdim    ACPI_OPTION ("-w <1|2|3>",      "Set warning reporting level");
131356843Sdim
132356843Sdim    printf ("\nAML Output Files:\n");
133356843Sdim    ACPI_OPTION ("-s <a|c>",        "Create AML in assembler or C source file (*.asm or *.c)");
134356843Sdim    ACPI_OPTION ("-i <a|c>",        "Create assembler or C include file (*.inc or *.h)");
135356843Sdim    ACPI_OPTION ("-t <a|c|s>",      "Create AML in assembler, C, or ASL hex table (*.hex)");
136356843Sdim
137356843Sdim    printf ("\nAML Code Generation:\n");
138356843Sdim    ACPI_OPTION ("-oa",             "Disable all optimizations (compatibility mode)");
139356843Sdim    ACPI_OPTION ("-of",             "Disable constant folding");
140356843Sdim    ACPI_OPTION ("-oi",             "Disable integer optimization to Zero/One/Ones");
141356843Sdim    ACPI_OPTION ("-on",             "Disable named reference string optimization");
142356843Sdim    ACPI_OPTION ("-cr",             "Disable Resource Descriptor error checking");
143356843Sdim    ACPI_OPTION ("-r <revision>",   "Override table header Revision (1-255)");
144356843Sdim
145356843Sdim    printf ("\nASL Listing Files:\n");
146356843Sdim    ACPI_OPTION ("-l",              "Create mixed listing file (ASL source and AML) (*.lst)");
147356843Sdim    ACPI_OPTION ("-ln",             "Create namespace file (*.nsp)");
148356843Sdim    ACPI_OPTION ("-ls",             "Create combined source file (expanded includes) (*.src)");
149356843Sdim
150356843Sdim    printf ("\nACPI Data Tables:\n");
151356843Sdim    ACPI_OPTION ("-G",              "Compile custom table containing generic operators");
152356843Sdim    ACPI_OPTION ("-T <sig>|ALL|*",  "Create table template file(s) for <Sig>");
153356843Sdim    ACPI_OPTION ("-vt",             "Create verbose templates (full disassembly)");
154356843Sdim
155356843Sdim    printf ("\nAML Disassembler:\n");
156356843Sdim    ACPI_OPTION ("-d  [file]",      "Disassemble or decode binary ACPI table to file (*.dsl)");
157356843Sdim    ACPI_OPTION ("-da [f1,f2]",     "Disassemble multiple tables from single namespace");
158356843Sdim    ACPI_OPTION ("-dc [file]",      "Disassemble AML and immediately compile it");
159356843Sdim    ACPI_OPTION ("",                "(Obtain DSDT from current system if no input file)");
160356843Sdim    ACPI_OPTION ("-e  [f1,f2]",     "Include ACPI table(s) for external symbol resolution");
161356843Sdim    ACPI_OPTION ("-m",              "Do not translate Buffers to Resource Templates");
162356843Sdim    ACPI_OPTION ("-2",              "Emit ACPI 2.0 compatible ASL code");
163356843Sdim    ACPI_OPTION ("-g",              "Get ACPI tables and write to files (*.dat)");
164356843Sdim
165356843Sdim    printf ("\nHelp:\n");
166356843Sdim    ACPI_OPTION ("-h",              "Additional help and compiler debug options");
167356843Sdim    ACPI_OPTION ("-hc",             "Display operators allowed in constant expressions");
168356843Sdim    ACPI_OPTION ("-hr",             "Display ACPI reserved method names");
169356843Sdim    ACPI_OPTION ("-ht",             "Display currently supported ACPI table names");
170356843Sdim}
171356843Sdim
172356843Sdim
173356843Sdim/*******************************************************************************
174356843Sdim *
175356843Sdim * FUNCTION:    HelpMessage
176356843Sdim *
177356843Sdim * PARAMETERS:  None
178356843Sdim *
179356843Sdim * RETURN:      None
180356843Sdim *
181356843Sdim * DESCRIPTION: Display help message
182356843Sdim *
183356843Sdim ******************************************************************************/
184356843Sdim
185356843Sdimstatic void
186356843SdimHelpMessage (
187356843Sdim    void)
188356843Sdim{
189356843Sdim
190356843Sdim    printf ("\nAML output filename generation:\n");
191356843Sdim    printf ("  Output filenames are generated by appending an extension to a common\n");
192356843Sdim    printf ("  filename prefix.  The filename prefix is obtained via one of the\n");
193356843Sdim    printf ("  following methods (in priority order):\n");
194356843Sdim    printf ("    1) The -p option specifies the prefix\n");
195356843Sdim    printf ("    2) The prefix of the AMLFileName in the ASL Definition Block\n");
196356843Sdim    printf ("    3) The prefix of the input filename\n");
197356843Sdim    printf ("\n");
198356843Sdim
199356843Sdim    Options ();
200356843Sdim
201356843Sdim    printf ("\nCompiler/Disassembler Debug Options:\n");
202356843Sdim    ACPI_OPTION ("-b<p|t|b>",       "Create compiler debug/trace file (*.txt)");
203356843Sdim    ACPI_OPTION ("",                "Types: Parse/Tree/Both");
204356843Sdim    ACPI_OPTION ("-f",              "Ignore errors, force creation of AML output file(s)");
205356843Sdim    ACPI_OPTION ("-n",              "Parse only, no output generation");
206356843Sdim    ACPI_OPTION ("-ot",             "Display compile times");
207356843Sdim    ACPI_OPTION ("-x<level>",       "Set debug level for trace output");
208356843Sdim    ACPI_OPTION ("-z",              "Do not insert new compiler ID for DataTables");
209356843Sdim}
210356843Sdim
211356843Sdim
212356843Sdim/*******************************************************************************
213356843Sdim *
214356843Sdim * FUNCTION:    Usage
215356843Sdim *
216356843Sdim * PARAMETERS:  None
217356843Sdim *
218356843Sdim * RETURN:      None
219356843Sdim *
220356843Sdim * DESCRIPTION: Display usage and option message
221356843Sdim *
222356843Sdim ******************************************************************************/
223356843Sdim
224356843Sdimstatic void
225356843SdimUsage (
226356843Sdim    void)
227356843Sdim{
228356843Sdim
229356843Sdim    printf ("%s\n\n", ASL_COMPLIANCE);
230356843Sdim    ACPI_USAGE_HEADER ("iasl [Options] [Files]");
231356843Sdim    Options ();
232356843Sdim}
233356843Sdim
234356843Sdim
235356843Sdim/*******************************************************************************
236356843Sdim *
237356843Sdim * FUNCTION:    AslInitialize
238356843Sdim *
239356843Sdim * PARAMETERS:  None
240356843Sdim *
241356843Sdim * RETURN:      None
242356843Sdim *
243356843Sdim * DESCRIPTION: Initialize compiler globals
244356843Sdim *
245356843Sdim ******************************************************************************/
246356843Sdim
247356843Sdimstatic void
248356843SdimAslInitialize (
249356843Sdim    void)
250356843Sdim{
251356843Sdim    UINT32                  i;
252356843Sdim
253356843Sdim
254356843Sdim#ifdef _DEBUG
255356843Sdim    _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
256356843Sdim#endif
257356843Sdim
258356843Sdim    AcpiDbgLevel = 0;
259356843Sdim
260356843Sdim    for (i = 0; i < ASL_NUM_FILES; i++)
261356843Sdim    {
262356843Sdim        Gbl_Files[i].Handle = NULL;
263356843Sdim        Gbl_Files[i].Filename = NULL;
264356843Sdim    }
265356843Sdim
266356843Sdim    Gbl_Files[ASL_FILE_STDOUT].Handle   = stdout;
267356843Sdim    Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
268356843Sdim
269356843Sdim    Gbl_Files[ASL_FILE_STDERR].Handle   = stderr;
270356843Sdim    Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
271356843Sdim}
272356843Sdim
273356843Sdim
274356843Sdim/*******************************************************************************
275356843Sdim *
276356843Sdim * FUNCTION:    AslMergeOptionTokens
277356843Sdim *
278356843Sdim * PARAMETERS:  InBuffer            - Input containing an option string
279356843Sdim *              OutBuffer           - Merged output buffer
280356843Sdim *
281356843Sdim * RETURN:      None
282356843Sdim *
283356843Sdim * DESCRIPTION: Remove all whitespace from an option string.
284356843Sdim *
285356843Sdim ******************************************************************************/
286356843Sdim
287356843Sdimstatic void
288356843SdimAslMergeOptionTokens (
289356843Sdim    char                    *InBuffer,
290356843Sdim    char                    *OutBuffer)
291356843Sdim{
292356843Sdim    char                    *Token;
293356843Sdim
294356843Sdim
295356843Sdim    *OutBuffer = 0;
296356843Sdim
297356843Sdim    Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
298356843Sdim    while (Token)
299356843Sdim    {
300356843Sdim        strcat (OutBuffer, Token);
301356843Sdim        Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
302356843Sdim    }
303356843Sdim}
304356843Sdim
305356843Sdim
306356843Sdim/*******************************************************************************
307356843Sdim *
308356843Sdim * FUNCTION:    AslDoResponseFile
309356843Sdim *
310356843Sdim * PARAMETERS:  Filename        - Name of the response file
311356843Sdim *
312356843Sdim * RETURN:      Status
313356843Sdim *
314356843Sdim * DESCRIPTION: Open a response file and process all options within.
315356843Sdim *
316356843Sdim ******************************************************************************/
317356843Sdim
318356843Sdimstatic int
319356843SdimAslDoResponseFile (
320356843Sdim    char                    *Filename)
321356843Sdim{
322356843Sdim    char                    *argv = StringBuffer2;
323356843Sdim    FILE                    *ResponseFile;
324356843Sdim    int                     OptStatus = 0;
325356843Sdim    int                     Opterr;
326356843Sdim    int                     Optind;
327356843Sdim
328356843Sdim
329356843Sdim    ResponseFile = fopen (Filename, "r");
330356843Sdim    if (!ResponseFile)
331356843Sdim    {
332356843Sdim        printf ("Could not open command file %s, %s\n",
333356843Sdim            Filename, strerror (errno));
334356843Sdim        return -1;
335356843Sdim    }
336356843Sdim
337356843Sdim    /* Must save the current GetOpt globals */
338356843Sdim
339356843Sdim    Opterr = AcpiGbl_Opterr;
340356843Sdim    Optind = AcpiGbl_Optind;
341356843Sdim
342356843Sdim    /*
343356843Sdim     * Process all lines in the response file. There must be one complete
344356843Sdim     * option per line
345356843Sdim     */
346356843Sdim    while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
347356843Sdim    {
348356843Sdim        /* Compress all tokens, allowing us to use a single argv entry */
349356843Sdim
350356843Sdim        AslMergeOptionTokens (StringBuffer, StringBuffer2);
351356843Sdim
352356843Sdim        /* Process the option */
353356843Sdim
354356843Sdim        AcpiGbl_Opterr = 0;
355356843Sdim        AcpiGbl_Optind = 0;
356356843Sdim
357356843Sdim        OptStatus = AslDoOptions (1, &argv, TRUE);
358356843Sdim        if (OptStatus)
359356843Sdim        {
360356843Sdim            printf ("Invalid option in command file %s: %s\n",
361356843Sdim                Filename, StringBuffer);
362356843Sdim            break;
363356843Sdim        }
364356843Sdim    }
365356843Sdim
366356843Sdim    /* Restore the GetOpt globals */
367356843Sdim
368356843Sdim    AcpiGbl_Opterr = Opterr;
369356843Sdim    AcpiGbl_Optind = Optind;
370356843Sdim
371356843Sdim    fclose (ResponseFile);
372356843Sdim    return (OptStatus);
373356843Sdim}
374356843Sdim
375356843Sdim
376356843Sdim/*******************************************************************************
377356843Sdim *
378356843Sdim * FUNCTION:    AslDoOptions
379356843Sdim *
380356843Sdim * PARAMETERS:  argc/argv           - Standard argc/argv
381356843Sdim *              IsResponseFile      - TRUE if executing a response file.
382356843Sdim *
383356843Sdim * RETURN:      Status
384356843Sdim *
385356843Sdim * DESCRIPTION: Command line option processing
386356843Sdim *
387356843Sdim ******************************************************************************/
388356843Sdim
389356843Sdimstatic int
390356843SdimAslDoOptions (
391356843Sdim    int                     argc,
392356843Sdim    char                    **argv,
393356843Sdim    BOOLEAN                 IsResponseFile)
394356843Sdim{
395356843Sdim    int                     j;
396356843Sdim    ACPI_STATUS             Status;
397356843Sdim
398356843Sdim
399356843Sdim    /* Get the command line options */
400356843Sdim
401356843Sdim    while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
402356843Sdim    {
403356843Sdim    case '@':   /* Begin a response file */
404356843Sdim
405356843Sdim        if (IsResponseFile)
406356843Sdim        {
407356843Sdim            printf ("Nested command files are not supported\n");
408356843Sdim            return -1;
409356843Sdim        }
410356843Sdim
411356843Sdim        if (AslDoResponseFile (AcpiGbl_Optarg))
412356843Sdim        {
413356843Sdim            return -1;
414356843Sdim        }
415356843Sdim        break;
416356843Sdim
417356843Sdim
418356843Sdim    case '2':
419356843Sdim
420356843Sdim        Gbl_Acpi2 = TRUE;
421356843Sdim        break;
422356843Sdim
423356843Sdim
424356843Sdim    case 'b':
425356843Sdim
426356843Sdim        switch (AcpiGbl_Optarg[0])
427356843Sdim        {
428356843Sdim        case 'b':
429356843Sdim            AslCompilerdebug = 1; /* same as yydebug */
430356843Sdim            DtParserdebug = 1;
431356843Sdim            break;
432356843Sdim
433356843Sdim        case 'p':
434356843Sdim            AslCompilerdebug = 1; /* same as yydebug */
435356843Sdim            DtParserdebug = 1;
436356843Sdim            break;
437356843Sdim
438356843Sdim        case 't':
439356843Sdim            break;
440356843Sdim
441356843Sdim        default:
442356843Sdim            printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
443356843Sdim            return (-1);
444356843Sdim        }
445356843Sdim
446356843Sdim        /* Produce debug output file */
447356843Sdim
448356843Sdim        Gbl_DebugFlag = TRUE;
449356843Sdim        break;
450356843Sdim
451356843Sdim
452356843Sdim    case 'c':
453356843Sdim        switch (AcpiGbl_Optarg[0])
454356843Sdim        {
455356843Sdim        case 'r':
456356843Sdim            Gbl_NoResourceChecking = TRUE;
457356843Sdim            break;
458356843Sdim
459356843Sdim        default:
460356843Sdim            printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
461356843Sdim            return (-1);
462356843Sdim        }
463356843Sdim        break;
464356843Sdim
465356843Sdim
466356843Sdim    case 'd':
467356843Sdim        switch (AcpiGbl_Optarg[0])
468356843Sdim        {
469356843Sdim        case '^':
470356843Sdim            Gbl_DoCompile = FALSE;
471356843Sdim            break;
472356843Sdim
473356843Sdim        case 'a':
474356843Sdim            Gbl_DoCompile = FALSE;
475356843Sdim            Gbl_DisassembleAll = TRUE;
476356843Sdim            break;
477356843Sdim
478356843Sdim        case 'c':
479356843Sdim            break;
480356843Sdim
481356843Sdim        default:
482356843Sdim            printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
483356843Sdim            return (-1);
484356843Sdim        }
485356843Sdim
486356843Sdim        Gbl_DisasmFlag = TRUE;
487356843Sdim        break;
488356843Sdim
489356843Sdim
490356843Sdim    case 'e':
491356843Sdim        Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg);
492356843Sdim        if (ACPI_FAILURE (Status))
493356843Sdim        {
494356843Sdim            printf ("Could not add %s to external list\n", AcpiGbl_Optarg);
495356843Sdim            return (-1);
496356843Sdim        }
497356843Sdim        break;
498356843Sdim
499356843Sdim
500356843Sdim    case 'f':
501356843Sdim
502356843Sdim        /* Ignore errors and force creation of aml file */
503356843Sdim
504356843Sdim        Gbl_IgnoreErrors = TRUE;
505356843Sdim        break;
506356843Sdim
507356843Sdim
508356843Sdim    case 'g':
509356843Sdim
510356843Sdim        /* Get all ACPI tables */
511356843Sdim
512356843Sdim        Gbl_GetAllTables = TRUE;
513356843Sdim        Gbl_DoCompile = FALSE;
514356843Sdim        break;
515356843Sdim
516356843Sdim
517356843Sdim    case 'h':
518356843Sdim
519356843Sdim        switch (AcpiGbl_Optarg[0])
520356843Sdim        {
521356843Sdim        case '^':
522356843Sdim            HelpMessage ();
523356843Sdim            exit (0);
524356843Sdim
525356843Sdim        case 'c':
526356843Sdim            UtDisplayConstantOpcodes ();
527356843Sdim            exit (0);
528356843Sdim
529356843Sdim        case 'r':
530356843Sdim            /* reserved names */
531356843Sdim
532356843Sdim            ApDisplayReservedNames ();
533356843Sdim            exit (0);
534356843Sdim
535356843Sdim        case 't':
536356843Sdim            UtDisplaySupportedTables ();
537356843Sdim            exit (0);
538356843Sdim
539356843Sdim        default:
540356843Sdim            printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
541356843Sdim            return (-1);
542356843Sdim        }
543356843Sdim
544356843Sdim
545356843Sdim    case 'I': /* Add an include file search directory */
546356843Sdim
547356843Sdim        FlAddIncludeDirectory (AcpiGbl_Optarg);
548356843Sdim        break;
549356843Sdim
550356843Sdim
551356843Sdim    case 'i':
552356843Sdim
553356843Sdim        switch (AcpiGbl_Optarg[0])
554356843Sdim        {
555356843Sdim        case 'a':
556356843Sdim
557356843Sdim            /* Produce assembly code include file */
558
559            Gbl_AsmIncludeOutputFlag = TRUE;
560            break;
561
562        case 'c':
563
564            /* Produce C include file */
565
566            Gbl_C_IncludeOutputFlag = TRUE;
567            break;
568
569        default:
570            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
571            return (-1);
572        }
573        break;
574
575
576    case 'l':
577
578        switch (AcpiGbl_Optarg[0])
579        {
580        case '^':
581            /* Produce listing file (Mixed source/aml) */
582
583            Gbl_ListingFlag = TRUE;
584            break;
585
586        case 'n':
587            /* Produce namespace file */
588
589            Gbl_NsOutputFlag = TRUE;
590            break;
591
592        case 's':
593            /* Produce combined source file */
594
595            Gbl_SourceOutputFlag = TRUE;
596            break;
597
598        default:
599            printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
600            return (-1);
601        }
602        break;
603
604
605    case 'm':
606
607        AcpiGbl_NoResourceDisassembly = TRUE;
608        break;
609
610
611    case 'n':
612
613        /* Parse only */
614
615        Gbl_ParseOnlyFlag = TRUE;
616        break;
617
618
619    case 'o':
620
621        switch (AcpiGbl_Optarg[0])
622        {
623        case 'a':
624
625            /* Disable all optimizations */
626
627            Gbl_FoldConstants = FALSE;
628            Gbl_IntegerOptimizationFlag = FALSE;
629            Gbl_ReferenceOptimizationFlag = FALSE;
630            break;
631
632        case 'f':
633
634            /* Disable folding on "normal" expressions */
635
636            Gbl_FoldConstants = FALSE;
637            break;
638
639        case 'i':
640
641            /* Disable integer optimization to constants */
642
643            Gbl_IntegerOptimizationFlag = FALSE;
644            break;
645
646        case 'n':
647
648            /* Disable named reference optimization */
649
650            Gbl_ReferenceOptimizationFlag = FALSE;
651            break;
652
653        case 't':
654
655            /* Display compile time(s) */
656
657            Gbl_CompileTimesFlag = TRUE;
658            break;
659
660        default:
661            printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
662            return (-1);
663        }
664        break;
665
666
667    case 'p':
668
669        /* Override default AML output filename */
670
671        Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
672        Gbl_UseDefaultAmlFilename = FALSE;
673        break;
674
675
676    case 'r':
677        Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
678        break;
679
680
681    case 's':
682
683        switch (AcpiGbl_Optarg[0])
684        {
685        case 'a':
686
687            /* Produce assembly code output file */
688
689            Gbl_AsmOutputFlag = TRUE;
690            break;
691
692        case 'c':
693
694            /* Produce C hex output file */
695
696            Gbl_C_OutputFlag = TRUE;
697            break;
698
699        default:
700            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
701            return (-1);
702        }
703        break;
704
705
706    case 't':
707
708        /* Produce hex table output file */
709
710        switch (AcpiGbl_Optarg[0])
711        {
712        case 'a':
713            Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
714            break;
715
716        case 'c':
717            Gbl_HexOutputFlag = HEX_OUTPUT_C;
718            break;
719
720        case 's':
721            Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
722            break;
723
724        default:
725            printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
726            return (-1);
727        }
728        break;
729
730
731    case 'G':
732        Gbl_CompileGeneric = TRUE;
733        break;
734
735
736    case 'T':
737        Gbl_DoTemplates = TRUE;
738        Gbl_TemplateSignature = AcpiGbl_Optarg;
739        break;
740
741
742    case 'v':
743
744        switch (AcpiGbl_Optarg[0])
745        {
746        case 'a':
747            /* Disable All error/warning messages */
748
749            Gbl_NoErrors = TRUE;
750            break;
751
752        case 'i':
753            /* Less verbose error messages */
754
755            Gbl_VerboseErrors = FALSE;
756            break;
757
758        case 'o':
759            Gbl_DisplayOptimizations = TRUE;
760            break;
761
762        case 'r':
763            Gbl_DisplayRemarks = FALSE;
764            break;
765
766        case 's':
767            Gbl_DoSignon = FALSE;
768            break;
769
770        case 't':
771            Gbl_VerboseTemplates = TRUE;
772            break;
773
774        default:
775            printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
776            return (-1);
777        }
778        break;
779
780
781    case 'w': /* Set warning levels */
782
783        switch (AcpiGbl_Optarg[0])
784        {
785        case '1':
786            Gbl_WarningLevel = ASL_WARNING;
787            break;
788
789        case '2':
790            Gbl_WarningLevel = ASL_WARNING2;
791            break;
792
793        case '3':
794            Gbl_WarningLevel = ASL_WARNING3;
795            break;
796
797        default:
798            printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
799            return (-1);
800        }
801        break;
802
803
804    case 'x':
805
806        AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
807        break;
808
809
810    case 'z':
811
812        Gbl_UseOriginalCompilerId = TRUE;
813        break;
814
815
816    default:
817
818        return (-1);
819    }
820
821    return (0);
822}
823
824
825/*******************************************************************************
826 *
827 * FUNCTION:    AslCommandLine
828 *
829 * PARAMETERS:  argc/argv
830 *
831 * RETURN:      Last argv index
832 *
833 * DESCRIPTION: Command line processing
834 *
835 ******************************************************************************/
836
837static int
838AslCommandLine (
839    int                     argc,
840    char                    **argv)
841{
842    int                     BadCommandLine = 0;
843    ACPI_STATUS             Status;
844
845
846    /* Minimum command line contains at least the command and an input file */
847
848    if (argc < 2)
849    {
850        printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
851        Usage ();
852        exit (1);
853    }
854
855    /* Process all command line options */
856
857    BadCommandLine = AslDoOptions (argc, argv, FALSE);
858
859    if (Gbl_DoTemplates)
860    {
861        Status = DtCreateTemplates (Gbl_TemplateSignature);
862        if (ACPI_FAILURE (Status))
863        {
864            exit (-1);
865        }
866        exit (1);
867    }
868
869    /* Next parameter must be the input filename */
870
871    if (!argv[AcpiGbl_Optind] &&
872        !Gbl_DisasmFlag &&
873        !Gbl_GetAllTables)
874    {
875        printf ("Missing input filename\n");
876        BadCommandLine = TRUE;
877    }
878
879    if (Gbl_DoSignon)
880    {
881        printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
882        if (Gbl_IgnoreErrors)
883        {
884            printf ("Ignoring all errors, forcing AML file generation\n\n");
885        }
886    }
887
888    /* Abort if anything went wrong on the command line */
889
890    if (BadCommandLine)
891    {
892        printf ("\n");
893        Usage ();
894        exit (1);
895    }
896
897    return (AcpiGbl_Optind);
898}
899
900
901/*******************************************************************************
902 *
903 * FUNCTION:    main
904 *
905 * PARAMETERS:  Standard argc/argv
906 *
907 * RETURN:      Program termination code
908 *
909 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
910 *              options and begin the compile for each file on the command line
911 *
912 ******************************************************************************/
913
914int ACPI_SYSTEM_XFACE
915main (
916    int                     argc,
917    char                    **argv)
918{
919    ACPI_STATUS             Status;
920    int                     Index1;
921    int                     Index2;
922
923
924    AcpiGbl_ExternalFileList = NULL;
925
926#ifdef _DEBUG
927    _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
928                    _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
929#endif
930
931    /* Init and command line */
932
933    AslInitialize ();
934    Index1 = Index2 = AslCommandLine (argc, argv);
935
936    /* Options that have no additional parameters or pathnames */
937
938    if (Gbl_GetAllTables)
939    {
940        Status = AslDoOneFile (NULL);
941        if (ACPI_FAILURE (Status))
942        {
943            return (-1);
944        }
945        return (0);
946    }
947
948    if (Gbl_DisassembleAll)
949    {
950        while (argv[Index1])
951        {
952            Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList);
953            if (ACPI_FAILURE (Status))
954            {
955                return (-1);
956            }
957
958            Index1++;
959        }
960    }
961
962    /* Process each pathname/filename in the list, with possible wildcards */
963
964    while (argv[Index2])
965    {
966        Status = AslDoOnePathname (argv[Index2], AslDoOneFile);
967        if (ACPI_FAILURE (Status))
968        {
969            return (-1);
970        }
971
972        Index2++;
973    }
974
975    if (AcpiGbl_ExternalFileList)
976    {
977        AcpiDmClearExternalFileList();
978    }
979
980    return (0);
981}
982
983
984