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