aslmain.c revision 245582
1/******************************************************************************
2 *
3 * Module Name: aslmain - compiler main and utilities
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions, and the following disclaimer,
16 *    without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 *    substantially similar to the "NO WARRANTY" disclaimer below
19 *    ("Disclaimer") and any redistribution must be conditioned upon
20 *    including a substantially similar Disclaimer requirement for further
21 *    binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 *    of any contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44
45#define _DECLARE_GLOBALS
46
47#include <contrib/dev/acpica/compiler/aslcompiler.h>
48#include <contrib/dev/acpica/include/acapps.h>
49#include <contrib/dev/acpica/include/acdisasm.h>
50#include <signal.h>
51
52#ifdef _DEBUG
53#include <crtdbg.h>
54#endif
55
56#define _COMPONENT          ACPI_COMPILER
57        ACPI_MODULE_NAME    ("aslmain")
58
59/* Local prototypes */
60
61static void
62Options (
63    void);
64
65static void
66FilenameHelp (
67    void);
68
69static void
70Usage (
71    void);
72
73static void ACPI_SYSTEM_XFACE
74AslSignalHandler (
75    int                     Sig);
76
77static void
78AslInitialize (
79    void);
80
81static int
82AslCommandLine (
83    int                     argc,
84    char                    **argv);
85
86static int
87AslDoOptions (
88    int                     argc,
89    char                    **argv,
90    BOOLEAN                 IsResponseFile);
91
92static void
93AslMergeOptionTokens (
94    char                    *InBuffer,
95    char                    *OutBuffer);
96
97static int
98AslDoResponseFile (
99    char                    *Filename);
100
101
102#define ASL_TOKEN_SEPARATORS    " \t\n"
103#define ASL_SUPPORTED_OPTIONS   "@:b|c|d^D:e:fgh^i|I:l^m:no|p:P^r:s|t|T:G^v^w|x:z"
104
105
106/*******************************************************************************
107 *
108 * FUNCTION:    Options
109 *
110 * PARAMETERS:  None
111 *
112 * RETURN:      None
113 *
114 * DESCRIPTION: Display option help message
115 *
116 ******************************************************************************/
117
118static void
119Options (
120    void)
121{
122
123    printf ("\nGlobal:\n");
124    ACPI_OPTION ("-@ <file>",       "Specify command file");
125    ACPI_OPTION ("-I <dir>",        "Specify additional include directory");
126    ACPI_OPTION ("-T <sig>|ALL|*",  "Create table template file for ACPI <Sig>");
127    ACPI_OPTION ("-v",              "Display compiler version");
128
129    printf ("\nPreprocessor:\n");
130    ACPI_OPTION ("-D <symbol>",     "Define symbol for preprocessor use");
131    ACPI_OPTION ("-li",             "Create preprocessed output file (*.i)");
132    ACPI_OPTION ("-P",              "Preprocess only and create preprocessor output file (*.i)");
133    ACPI_OPTION ("-Pn",             "Disable preprocessor");
134
135    printf ("\nGeneral Output:\n");
136    ACPI_OPTION ("-p <prefix>",     "Specify path/filename prefix for all output files");
137    ACPI_OPTION ("-va",             "Disable all errors and warnings (summary only)");
138    ACPI_OPTION ("-vi",             "Less verbose errors and warnings for use with IDEs");
139    ACPI_OPTION ("-vo",             "Enable optimization comments");
140    ACPI_OPTION ("-vr",             "Disable remarks");
141    ACPI_OPTION ("-vs",             "Disable signon");
142    ACPI_OPTION ("-w1 -w2 -w3",     "Set warning reporting level");
143    ACPI_OPTION ("-we",             "Report warnings as errors");
144
145    printf ("\nAML and Data Output Files:\n");
146    ACPI_OPTION ("-sa -sc",         "Create assembler or C source file (*.asm or *.c)");
147    ACPI_OPTION ("-ia -ic",         "Create assembler or C include file (*.inc or *.h)");
148    ACPI_OPTION ("-ta -tc -ts",     "Create assembler, C, or ASL hex table (*.hex)");
149
150    printf ("\nAML Code Generation:\n");
151    ACPI_OPTION ("-oa",             "Disable all optimizations (compatibility mode)");
152    ACPI_OPTION ("-of",             "Disable constant folding");
153    ACPI_OPTION ("-oi",             "Disable integer optimization to Zero/One/Ones");
154    ACPI_OPTION ("-on",             "Disable named reference string optimization");
155    ACPI_OPTION ("-cr",             "Disable Resource Descriptor error checking");
156    ACPI_OPTION ("-in",             "Ignore NoOp operators");
157    ACPI_OPTION ("-r <revision>",   "Override table header Revision (1-255)");
158
159    printf ("\nASL Listing Files:\n");
160    ACPI_OPTION ("-l",              "Create mixed listing file (ASL source and AML) (*.lst)");
161    ACPI_OPTION ("-ln",             "Create namespace file (*.nsp)");
162    ACPI_OPTION ("-ls",             "Create combined source file (expanded includes) (*.src)");
163
164    printf ("\nACPI Data Tables:\n");
165    ACPI_OPTION ("-G",              "Compile custom table containing generic operators");
166    ACPI_OPTION ("-vt",             "Create verbose templates (full disassembly)");
167
168    printf ("\nAML Disassembler:\n");
169    ACPI_OPTION ("-d  [file]",      "Disassemble or decode binary ACPI table to file (*.dsl)");
170    ACPI_OPTION ("-da [f1,f2]",     "Disassemble multiple tables from single namespace");
171    ACPI_OPTION ("-db",             "Do not translate Buffers to Resource Templates");
172    ACPI_OPTION ("-dc [file]",      "Disassemble AML and immediately compile it");
173    ACPI_OPTION ("",                "(Obtain DSDT from current system if no input file)");
174    ACPI_OPTION ("-e  [f1,f2]",     "Include ACPI table(s) for external symbol resolution");
175    ACPI_OPTION ("-g",              "Get ACPI tables and write to files (*.dat)");
176    ACPI_OPTION ("-in",             "Ignore NoOp opcodes");
177    ACPI_OPTION ("-vt",             "Dump binary table data in hex format within output file");
178
179    printf ("\nHelp:\n");
180    ACPI_OPTION ("-h",              "This message");
181    ACPI_OPTION ("-hc",             "Display operators allowed in constant expressions");
182    ACPI_OPTION ("-hf",             "Display help for output filename generation");
183    ACPI_OPTION ("-hr",             "Display ACPI reserved method names");
184    ACPI_OPTION ("-ht",             "Display currently supported ACPI table names");
185
186    printf ("\nDebug Options:\n");
187    ACPI_OPTION ("-bf -bt",         "Create debug file (full or parse tree only) (*.txt)");
188    ACPI_OPTION ("-f",              "Ignore errors, force creation of AML output file(s)");
189    ACPI_OPTION ("-n",              "Parse only, no output generation");
190    ACPI_OPTION ("-ot",             "Display compile times and statistics");
191    ACPI_OPTION ("-x <level>",      "Set debug level for trace output");
192    ACPI_OPTION ("-z",              "Do not insert new compiler ID for DataTables");
193}
194
195
196/*******************************************************************************
197 *
198 * FUNCTION:    FilenameHelp
199 *
200 * PARAMETERS:  None
201 *
202 * RETURN:      None
203 *
204 * DESCRIPTION: Display help message for output filename generation
205 *
206 ******************************************************************************/
207
208static void
209FilenameHelp (
210    void)
211{
212
213    printf ("\nAML output filename generation:\n");
214    printf ("  Output filenames are generated by appending an extension to a common\n");
215    printf ("  filename prefix. The filename prefix is obtained via one of the\n");
216    printf ("  following methods (in priority order):\n");
217    printf ("    1) The -p option specifies the prefix\n");
218    printf ("    2) The prefix of the AMLFileName in the ASL Definition Block\n");
219    printf ("    3) The prefix of the input filename\n");
220    printf ("\n");
221}
222
223
224/*******************************************************************************
225 *
226 * FUNCTION:    Usage
227 *
228 * PARAMETERS:  None
229 *
230 * RETURN:      None
231 *
232 * DESCRIPTION: Display usage and option message
233 *
234 ******************************************************************************/
235
236static void
237Usage (
238    void)
239{
240
241    printf ("%s\n\n", ASL_COMPLIANCE);
242    ACPI_USAGE_HEADER ("iasl [Options] [Files]");
243    Options ();
244}
245
246
247/******************************************************************************
248 *
249 * FUNCTION:    AslSignalHandler
250 *
251 * PARAMETERS:  Sig                 - Signal that invoked this handler
252 *
253 * RETURN:      None
254 *
255 * DESCRIPTION: Control-C handler. Delete any intermediate files and any
256 *              output files that may be left in an indeterminate state.
257 *
258 *****************************************************************************/
259
260static void ACPI_SYSTEM_XFACE
261AslSignalHandler (
262    int                     Sig)
263{
264    UINT32                  i;
265
266
267    signal (Sig, SIG_IGN);
268    printf ("Aborting\n\n");
269
270    /* Close all open files */
271
272    Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL; /* the .i file is same as source file */
273
274    for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
275    {
276        FlCloseFile (i);
277    }
278
279    /* Delete any output files */
280
281    for (i = ASL_FILE_AML_OUTPUT; i < ASL_MAX_FILE_TYPE; i++)
282    {
283        FlDeleteFile (i);
284    }
285
286    exit (0);
287}
288
289
290/*******************************************************************************
291 *
292 * FUNCTION:    AslInitialize
293 *
294 * PARAMETERS:  None
295 *
296 * RETURN:      None
297 *
298 * DESCRIPTION: Initialize compiler globals
299 *
300 ******************************************************************************/
301
302static void
303AslInitialize (
304    void)
305{
306    UINT32                  i;
307
308
309#ifdef _DEBUG
310    _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
311#endif
312
313
314    for (i = 0; i < ASL_NUM_FILES; i++)
315    {
316        Gbl_Files[i].Handle = NULL;
317        Gbl_Files[i].Filename = NULL;
318    }
319
320    Gbl_Files[ASL_FILE_STDOUT].Handle   = stdout;
321    Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
322
323    Gbl_Files[ASL_FILE_STDERR].Handle   = stderr;
324    Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
325
326    /* Allocate the line buffer(s) */
327
328    Gbl_LineBufferSize /= 2;
329    UtExpandLineBuffers ();
330}
331
332
333/*******************************************************************************
334 *
335 * FUNCTION:    AslMergeOptionTokens
336 *
337 * PARAMETERS:  InBuffer            - Input containing an option string
338 *              OutBuffer           - Merged output buffer
339 *
340 * RETURN:      None
341 *
342 * DESCRIPTION: Remove all whitespace from an option string.
343 *
344 ******************************************************************************/
345
346static void
347AslMergeOptionTokens (
348    char                    *InBuffer,
349    char                    *OutBuffer)
350{
351    char                    *Token;
352
353
354    *OutBuffer = 0;
355
356    Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
357    while (Token)
358    {
359        strcat (OutBuffer, Token);
360        Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
361    }
362}
363
364
365/*******************************************************************************
366 *
367 * FUNCTION:    AslDoResponseFile
368 *
369 * PARAMETERS:  Filename        - Name of the response file
370 *
371 * RETURN:      Status
372 *
373 * DESCRIPTION: Open a response file and process all options within.
374 *
375 ******************************************************************************/
376
377static int
378AslDoResponseFile (
379    char                    *Filename)
380{
381    char                    *argv = StringBuffer2;
382    FILE                    *ResponseFile;
383    int                     OptStatus = 0;
384    int                     Opterr;
385    int                     Optind;
386
387
388    ResponseFile = fopen (Filename, "r");
389    if (!ResponseFile)
390    {
391        printf ("Could not open command file %s, %s\n",
392            Filename, strerror (errno));
393        return (-1);
394    }
395
396    /* Must save the current GetOpt globals */
397
398    Opterr = AcpiGbl_Opterr;
399    Optind = AcpiGbl_Optind;
400
401    /*
402     * Process all lines in the response file. There must be one complete
403     * option per line
404     */
405    while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
406    {
407        /* Compress all tokens, allowing us to use a single argv entry */
408
409        AslMergeOptionTokens (StringBuffer, StringBuffer2);
410
411        /* Process the option */
412
413        AcpiGbl_Opterr = 0;
414        AcpiGbl_Optind = 0;
415
416        OptStatus = AslDoOptions (1, &argv, TRUE);
417        if (OptStatus)
418        {
419            printf ("Invalid option in command file %s: %s\n",
420                Filename, StringBuffer);
421            break;
422        }
423    }
424
425    /* Restore the GetOpt globals */
426
427    AcpiGbl_Opterr = Opterr;
428    AcpiGbl_Optind = Optind;
429
430    fclose (ResponseFile);
431    return (OptStatus);
432}
433
434
435/*******************************************************************************
436 *
437 * FUNCTION:    AslDoOptions
438 *
439 * PARAMETERS:  argc/argv           - Standard argc/argv
440 *              IsResponseFile      - TRUE if executing a response file.
441 *
442 * RETURN:      Status
443 *
444 * DESCRIPTION: Command line option processing
445 *
446 ******************************************************************************/
447
448static int
449AslDoOptions (
450    int                     argc,
451    char                    **argv,
452    BOOLEAN                 IsResponseFile)
453{
454    int                     j;
455    ACPI_STATUS             Status;
456
457
458    /* Get the command line options */
459
460    while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
461    {
462    case '@':   /* Begin a response file */
463
464        if (IsResponseFile)
465        {
466            printf ("Nested command files are not supported\n");
467            return (-1);
468        }
469
470        if (AslDoResponseFile (AcpiGbl_Optarg))
471        {
472            return (-1);
473        }
474        break;
475
476
477    case 'b':   /* Debug output options */
478        switch (AcpiGbl_Optarg[0])
479        {
480        case 'f':
481            AslCompilerdebug = 1; /* same as yydebug */
482            DtParserdebug = 1;
483            PrParserdebug = 1;
484            break;
485
486        case 't':
487            break;
488
489        default:
490            printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
491            return (-1);
492        }
493
494        /* Produce debug output file */
495
496        Gbl_DebugFlag = TRUE;
497        break;
498
499
500    case 'c':
501        switch (AcpiGbl_Optarg[0])
502        {
503        case 'r':
504            Gbl_NoResourceChecking = TRUE;
505            break;
506
507        default:
508            printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
509            return (-1);
510        }
511        break;
512
513
514    case 'd':   /* Disassembler */
515        switch (AcpiGbl_Optarg[0])
516        {
517        case '^':
518            Gbl_DoCompile = FALSE;
519            break;
520
521        case 'a':
522            Gbl_DoCompile = FALSE;
523            Gbl_DisassembleAll = TRUE;
524            break;
525
526        case 'b':   /* Do not convert buffers to resource descriptors */
527            AcpiGbl_NoResourceDisassembly = TRUE;
528            break;
529
530        case 'c':
531            break;
532
533        default:
534            printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
535            return (-1);
536        }
537
538        Gbl_DisasmFlag = TRUE;
539        break;
540
541
542    case 'D':   /* Define a symbol */
543        PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
544        break;
545
546
547    case 'e':   /* External files for disassembler */
548        Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg);
549        if (ACPI_FAILURE (Status))
550        {
551            printf ("Could not add %s to external list\n", AcpiGbl_Optarg);
552            return (-1);
553        }
554        break;
555
556
557    case 'f':   /* Ignore errors and force creation of aml file */
558        Gbl_IgnoreErrors = TRUE;
559        break;
560
561
562    case 'G':
563        Gbl_CompileGeneric = TRUE;
564        break;
565
566
567    case 'g':   /* Get all ACPI tables */
568
569        Gbl_GetAllTables = TRUE;
570        Gbl_DoCompile = FALSE;
571        break;
572
573
574    case 'h':
575        switch (AcpiGbl_Optarg[0])
576        {
577        case '^':
578            Usage ();
579            exit (0);
580
581        case 'c':
582            UtDisplayConstantOpcodes ();
583            exit (0);
584
585        case 'f':
586            FilenameHelp ();
587            exit (0);
588
589        case 'r':
590            /* reserved names */
591
592            ApDisplayReservedNames ();
593            exit (0);
594
595        case 't':
596            UtDisplaySupportedTables ();
597            exit (0);
598
599        default:
600            printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
601            return (-1);
602        }
603
604
605    case 'I':   /* Add an include file search directory */
606        FlAddIncludeDirectory (AcpiGbl_Optarg);
607        break;
608
609
610    case 'i':   /* Output AML as an include file */
611        switch (AcpiGbl_Optarg[0])
612        {
613        case 'a':
614
615            /* Produce assembly code include file */
616
617            Gbl_AsmIncludeOutputFlag = TRUE;
618            break;
619
620        case 'c':
621
622            /* Produce C include file */
623
624            Gbl_C_IncludeOutputFlag = TRUE;
625            break;
626
627        case 'n':
628
629            /* Compiler/Disassembler: Ignore the NOOP operator */
630
631            AcpiGbl_IgnoreNoopOperator = TRUE;
632            break;
633
634        default:
635            printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
636            return (-1);
637        }
638        break;
639
640
641    case 'l':   /* Listing files */
642        switch (AcpiGbl_Optarg[0])
643        {
644        case '^':
645            /* Produce listing file (Mixed source/aml) */
646
647            Gbl_ListingFlag = TRUE;
648            break;
649
650        case 'i':
651            /* Produce preprocessor output file */
652
653            Gbl_PreprocessorOutputFlag = TRUE;
654            break;
655
656        case 'n':
657            /* Produce namespace file */
658
659            Gbl_NsOutputFlag = TRUE;
660            break;
661
662        case 's':
663            /* Produce combined source file */
664
665            Gbl_SourceOutputFlag = TRUE;
666            break;
667
668        default:
669            printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
670            return (-1);
671        }
672        break;
673
674
675    case 'm':   /* Set line buffer size */
676        Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
677        if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
678        {
679            Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
680        }
681        printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
682        break;
683
684
685    case 'n':   /* Parse only */
686        Gbl_ParseOnlyFlag = TRUE;
687        break;
688
689
690    case 'o':   /* Control compiler AML optimizations */
691        switch (AcpiGbl_Optarg[0])
692        {
693        case 'a':
694
695            /* Disable all optimizations */
696
697            Gbl_FoldConstants = FALSE;
698            Gbl_IntegerOptimizationFlag = FALSE;
699            Gbl_ReferenceOptimizationFlag = FALSE;
700            break;
701
702        case 'f':
703
704            /* Disable folding on "normal" expressions */
705
706            Gbl_FoldConstants = FALSE;
707            break;
708
709        case 'i':
710
711            /* Disable integer optimization to constants */
712
713            Gbl_IntegerOptimizationFlag = FALSE;
714            break;
715
716        case 'n':
717
718            /* Disable named reference optimization */
719
720            Gbl_ReferenceOptimizationFlag = FALSE;
721            break;
722
723        case 't':
724
725            /* Display compile time(s) */
726
727            Gbl_CompileTimesFlag = TRUE;
728            break;
729
730        default:
731            printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
732            return (-1);
733        }
734        break;
735
736
737    case 'P':   /* Preprocessor options */
738        switch (AcpiGbl_Optarg[0])
739        {
740        case '^':   /* Proprocess only, emit (.i) file */
741            Gbl_PreprocessOnly = TRUE;
742            Gbl_PreprocessorOutputFlag = TRUE;
743            break;
744
745        case 'n':   /* Disable preprocessor */
746            Gbl_PreprocessFlag = FALSE;
747            break;
748
749        default:
750            printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
751            return (-1);
752        }
753        break;
754
755
756    case 'p':   /* Override default AML output filename */
757        Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
758        Gbl_UseDefaultAmlFilename = FALSE;
759        break;
760
761
762    case 'r':   /* Override revision found in table header */
763        Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
764        break;
765
766
767    case 's':   /* Create AML in a source code file */
768        switch (AcpiGbl_Optarg[0])
769        {
770        case 'a':
771
772            /* Produce assembly code output file */
773
774            Gbl_AsmOutputFlag = TRUE;
775            break;
776
777        case 'c':
778
779            /* Produce C hex output file */
780
781            Gbl_C_OutputFlag = TRUE;
782            break;
783
784        default:
785            printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
786            return (-1);
787        }
788        break;
789
790
791    case 't':   /* Produce hex table output file */
792        switch (AcpiGbl_Optarg[0])
793        {
794        case 'a':
795            Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
796            break;
797
798        case 'c':
799            Gbl_HexOutputFlag = HEX_OUTPUT_C;
800            break;
801
802        case 's':
803            Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
804            break;
805
806        default:
807            printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
808            return (-1);
809        }
810        break;
811
812
813    case 'T':   /* Create a ACPI table template file */
814        Gbl_DoTemplates = TRUE;
815        Gbl_TemplateSignature = AcpiGbl_Optarg;
816        break;
817
818
819    case 'v':   /* Version and verbosity settings */
820        switch (AcpiGbl_Optarg[0])
821        {
822        case '^':
823            printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
824            exit (0);
825
826        case 'a':
827            /* Disable All error/warning messages */
828
829            Gbl_NoErrors = TRUE;
830            break;
831
832        case 'i':
833            /*
834             * Support for integrated development environment(s).
835             *
836             * 1) No compiler signon
837             * 2) Send stderr messages to stdout
838             * 3) Less verbose error messages (single line only for each)
839             * 4) Error/warning messages are formatted appropriately to
840             *    be recognized by MS Visual Studio
841             */
842            Gbl_VerboseErrors = FALSE;
843            Gbl_DoSignon = FALSE;
844            Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
845            break;
846
847        case 'o':
848            Gbl_DisplayOptimizations = TRUE;
849            break;
850
851        case 'r':
852            Gbl_DisplayRemarks = FALSE;
853            break;
854
855        case 's':
856            Gbl_DoSignon = FALSE;
857            break;
858
859        case 't':
860            Gbl_VerboseTemplates = TRUE;
861            break;
862
863        default:
864            printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
865            return (-1);
866        }
867        break;
868
869
870    case 'w': /* Set warning levels */
871        switch (AcpiGbl_Optarg[0])
872        {
873        case '1':
874            Gbl_WarningLevel = ASL_WARNING;
875            break;
876
877        case '2':
878            Gbl_WarningLevel = ASL_WARNING2;
879            break;
880
881        case '3':
882            Gbl_WarningLevel = ASL_WARNING3;
883            break;
884
885        case 'e':
886            Gbl_WarningsAsErrors = TRUE;
887            break;
888
889        default:
890            printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
891            return (-1);
892        }
893        break;
894
895
896    case 'x':   /* Set debug print output level */
897        AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
898        break;
899
900
901    case 'z':
902        Gbl_UseOriginalCompilerId = TRUE;
903        break;
904
905
906    default:
907        return (-1);
908    }
909
910    return (0);
911}
912
913
914/*******************************************************************************
915 *
916 * FUNCTION:    AslCommandLine
917 *
918 * PARAMETERS:  argc/argv
919 *
920 * RETURN:      Last argv index
921 *
922 * DESCRIPTION: Command line processing
923 *
924 ******************************************************************************/
925
926static int
927AslCommandLine (
928    int                     argc,
929    char                    **argv)
930{
931    int                     BadCommandLine = 0;
932    ACPI_STATUS             Status;
933
934
935    /* Minimum command line contains at least the command and an input file */
936
937    if (argc < 2)
938    {
939        printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
940        Usage ();
941        exit (1);
942    }
943
944    /* Process all command line options */
945
946    BadCommandLine = AslDoOptions (argc, argv, FALSE);
947
948    if (Gbl_DoTemplates)
949    {
950        Status = DtCreateTemplates (Gbl_TemplateSignature);
951        if (ACPI_FAILURE (Status))
952        {
953            exit (-1);
954        }
955        exit (1);
956    }
957
958    /* Next parameter must be the input filename */
959
960    if (!argv[AcpiGbl_Optind] &&
961        !Gbl_DisasmFlag &&
962        !Gbl_GetAllTables)
963    {
964        printf ("Missing input filename\n");
965        BadCommandLine = TRUE;
966    }
967
968    if (Gbl_DoSignon)
969    {
970        printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
971        if (Gbl_IgnoreErrors)
972        {
973            printf ("Ignoring all errors, forcing AML file generation\n\n");
974        }
975    }
976
977    /* Abort if anything went wrong on the command line */
978
979    if (BadCommandLine)
980    {
981        printf ("\n");
982        Usage ();
983        exit (1);
984    }
985
986    return (AcpiGbl_Optind);
987}
988
989
990/*******************************************************************************
991 *
992 * FUNCTION:    main
993 *
994 * PARAMETERS:  Standard argc/argv
995 *
996 * RETURN:      Program termination code
997 *
998 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
999 *              options and begin the compile for each file on the command line
1000 *
1001 ******************************************************************************/
1002
1003int ACPI_SYSTEM_XFACE
1004main (
1005    int                     argc,
1006    char                    **argv)
1007{
1008    ACPI_STATUS             Status;
1009    int                     Index1;
1010    int                     Index2;
1011
1012
1013    signal (SIGINT, AslSignalHandler);
1014
1015    AcpiGbl_ExternalFileList = NULL;
1016    AcpiDbgLevel = 0;
1017
1018#ifdef _DEBUG
1019    _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
1020                    _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
1021#endif
1022
1023    /* Init and command line */
1024
1025    Index1 = Index2 = AslCommandLine (argc, argv);
1026
1027    AslInitialize ();
1028    PrInitializePreprocessor ();
1029
1030    /* Options that have no additional parameters or pathnames */
1031
1032    if (Gbl_GetAllTables)
1033    {
1034        Status = AslDoOneFile (NULL);
1035        if (ACPI_FAILURE (Status))
1036        {
1037            return (-1);
1038        }
1039        return (0);
1040    }
1041
1042    if (Gbl_DisassembleAll)
1043    {
1044        while (argv[Index1])
1045        {
1046            Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList);
1047            if (ACPI_FAILURE (Status))
1048            {
1049                return (-1);
1050            }
1051
1052            Index1++;
1053        }
1054    }
1055
1056    /* Process each pathname/filename in the list, with possible wildcards */
1057
1058    while (argv[Index2])
1059    {
1060        Status = AslDoOnePathname (argv[Index2], AslDoOneFile);
1061        if (ACPI_FAILURE (Status))
1062        {
1063            return (-1);
1064        }
1065
1066        Index2++;
1067    }
1068
1069    if (AcpiGbl_ExternalFileList)
1070    {
1071        AcpiDmClearExternalFileList();
1072    }
1073
1074    return (0);
1075}
1076