xref: /freebsd/sys/contrib/dev/acpica/compiler/aslmain.c (revision 675be9115aae86ad6b3d877155d4fd7822892105)
1 
2 /******************************************************************************
3  *
4  * Module Name: aslmain - compiler main and utilities
5  *
6  *****************************************************************************/
7 
8 /*
9  * Copyright (C) 2000 - 2011, 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 HelpMessage (
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^e:fgh^i^I:l^mno: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 ("\nGeneral Output:\n");
124     ACPI_OPTION ("-p <prefix>",     "Specify path/filename prefix for all output files");
125     ACPI_OPTION ("-va",             "Disable all errors and warnings (summary only)");
126     ACPI_OPTION ("-vi",             "Less verbose errors and warnings for use with IDEs");
127     ACPI_OPTION ("-vo",             "Enable optimization comments");
128     ACPI_OPTION ("-vr",             "Disable remarks");
129     ACPI_OPTION ("-vs",             "Disable signon");
130     ACPI_OPTION ("-w <1|2|3>",      "Set warning reporting level");
131 
132     printf ("\nAML Output Files:\n");
133     ACPI_OPTION ("-s <a|c>",        "Create AML in assembler or C source file (*.asm or *.c)");
134     ACPI_OPTION ("-i <a|c>",        "Create assembler or C include file (*.inc or *.h)");
135     ACPI_OPTION ("-t <a|c|s>",      "Create AML in assembler, C, or ASL hex table (*.hex)");
136 
137     printf ("\nAML Code Generation:\n");
138     ACPI_OPTION ("-oa",             "Disable all optimizations (compatibility mode)");
139     ACPI_OPTION ("-of",             "Disable constant folding");
140     ACPI_OPTION ("-oi",             "Disable integer optimization to Zero/One/Ones");
141     ACPI_OPTION ("-on",             "Disable named reference string optimization");
142     ACPI_OPTION ("-cr",             "Disable Resource Descriptor error checking");
143     ACPI_OPTION ("-r <revision>",   "Override table header Revision (1-255)");
144 
145     printf ("\nASL Listing Files:\n");
146     ACPI_OPTION ("-l",              "Create mixed listing file (ASL source and AML) (*.lst)");
147     ACPI_OPTION ("-ln",             "Create namespace file (*.nsp)");
148     ACPI_OPTION ("-ls",             "Create combined source file (expanded includes) (*.src)");
149 
150     printf ("\nACPI Data Tables:\n");
151     ACPI_OPTION ("-G",              "Compile custom table containing generic operators");
152     ACPI_OPTION ("-T <sig>|ALL|*",  "Create table template file(s) for <Sig>");
153     ACPI_OPTION ("-vt",             "Create verbose templates (full disassembly)");
154 
155     printf ("\nAML Disassembler:\n");
156     ACPI_OPTION ("-d  [file]",      "Disassemble or decode binary ACPI table to file (*.dsl)");
157     ACPI_OPTION ("-da [f1,f2]",     "Disassemble multiple tables from single namespace");
158     ACPI_OPTION ("-dc [file]",      "Disassemble AML and immediately compile it");
159     ACPI_OPTION ("",                "(Obtain DSDT from current system if no input file)");
160     ACPI_OPTION ("-e  [f1,f2]",     "Include ACPI table(s) for external symbol resolution");
161     ACPI_OPTION ("-m",              "Do not translate Buffers to Resource Templates");
162     ACPI_OPTION ("-2",              "Emit ACPI 2.0 compatible ASL code");
163     ACPI_OPTION ("-g",              "Get ACPI tables and write to files (*.dat)");
164 
165     printf ("\nHelp:\n");
166     ACPI_OPTION ("-h",              "Additional help and compiler debug options");
167     ACPI_OPTION ("-hc",             "Display operators allowed in constant expressions");
168     ACPI_OPTION ("-hr",             "Display ACPI reserved method names");
169     ACPI_OPTION ("-ht",             "Display currently supported ACPI table names");
170 }
171 
172 
173 /*******************************************************************************
174  *
175  * FUNCTION:    HelpMessage
176  *
177  * PARAMETERS:  None
178  *
179  * RETURN:      None
180  *
181  * DESCRIPTION: Display help message
182  *
183  ******************************************************************************/
184 
185 static void
186 HelpMessage (
187     void)
188 {
189 
190     printf ("\nAML output filename generation:\n");
191     printf ("  Output filenames are generated by appending an extension to a common\n");
192     printf ("  filename prefix.  The filename prefix is obtained via one of the\n");
193     printf ("  following methods (in priority order):\n");
194     printf ("    1) The -p option specifies the prefix\n");
195     printf ("    2) The prefix of the AMLFileName in the ASL Definition Block\n");
196     printf ("    3) The prefix of the input filename\n");
197     printf ("\n");
198 
199     Options ();
200 
201     printf ("\nCompiler/Disassembler Debug Options:\n");
202     ACPI_OPTION ("-b<p|t|b>",       "Create compiler debug/trace file (*.txt)");
203     ACPI_OPTION ("",                "Types: Parse/Tree/Both");
204     ACPI_OPTION ("-f",              "Ignore errors, force creation of AML output file(s)");
205     ACPI_OPTION ("-n",              "Parse only, no output generation");
206     ACPI_OPTION ("-ot",             "Display compile times");
207     ACPI_OPTION ("-x<level>",       "Set debug level for trace output");
208     ACPI_OPTION ("-z",              "Do not insert new compiler ID for DataTables");
209 }
210 
211 
212 /*******************************************************************************
213  *
214  * FUNCTION:    Usage
215  *
216  * PARAMETERS:  None
217  *
218  * RETURN:      None
219  *
220  * DESCRIPTION: Display usage and option message
221  *
222  ******************************************************************************/
223 
224 static void
225 Usage (
226     void)
227 {
228 
229     printf ("%s\n\n", ASL_COMPLIANCE);
230     ACPI_USAGE_HEADER ("iasl [Options] [Files]");
231     Options ();
232 }
233 
234 
235 /*******************************************************************************
236  *
237  * FUNCTION:    AslInitialize
238  *
239  * PARAMETERS:  None
240  *
241  * RETURN:      None
242  *
243  * DESCRIPTION: Initialize compiler globals
244  *
245  ******************************************************************************/
246 
247 static void
248 AslInitialize (
249     void)
250 {
251     UINT32                  i;
252 
253 
254 #ifdef _DEBUG
255     _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0));
256 #endif
257 
258     AcpiDbgLevel = 0;
259 
260     for (i = 0; i < ASL_NUM_FILES; i++)
261     {
262         Gbl_Files[i].Handle = NULL;
263         Gbl_Files[i].Filename = NULL;
264     }
265 
266     Gbl_Files[ASL_FILE_STDOUT].Handle   = stdout;
267     Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
268 
269     Gbl_Files[ASL_FILE_STDERR].Handle   = stderr;
270     Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
271 }
272 
273 
274 /*******************************************************************************
275  *
276  * FUNCTION:    AslMergeOptionTokens
277  *
278  * PARAMETERS:  InBuffer            - Input containing an option string
279  *              OutBuffer           - Merged output buffer
280  *
281  * RETURN:      None
282  *
283  * DESCRIPTION: Remove all whitespace from an option string.
284  *
285  ******************************************************************************/
286 
287 static void
288 AslMergeOptionTokens (
289     char                    *InBuffer,
290     char                    *OutBuffer)
291 {
292     char                    *Token;
293 
294 
295     *OutBuffer = 0;
296 
297     Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
298     while (Token)
299     {
300         strcat (OutBuffer, Token);
301         Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
302     }
303 }
304 
305 
306 /*******************************************************************************
307  *
308  * FUNCTION:    AslDoResponseFile
309  *
310  * PARAMETERS:  Filename        - Name of the response file
311  *
312  * RETURN:      Status
313  *
314  * DESCRIPTION: Open a response file and process all options within.
315  *
316  ******************************************************************************/
317 
318 static int
319 AslDoResponseFile (
320     char                    *Filename)
321 {
322     char                    *argv = StringBuffer2;
323     FILE                    *ResponseFile;
324     int                     OptStatus = 0;
325     int                     Opterr;
326     int                     Optind;
327 
328 
329     ResponseFile = fopen (Filename, "r");
330     if (!ResponseFile)
331     {
332         printf ("Could not open command file %s, %s\n",
333             Filename, strerror (errno));
334         return -1;
335     }
336 
337     /* Must save the current GetOpt globals */
338 
339     Opterr = AcpiGbl_Opterr;
340     Optind = AcpiGbl_Optind;
341 
342     /*
343      * Process all lines in the response file. There must be one complete
344      * option per line
345      */
346     while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
347     {
348         /* Compress all tokens, allowing us to use a single argv entry */
349 
350         AslMergeOptionTokens (StringBuffer, StringBuffer2);
351 
352         /* Process the option */
353 
354         AcpiGbl_Opterr = 0;
355         AcpiGbl_Optind = 0;
356 
357         OptStatus = AslDoOptions (1, &argv, TRUE);
358         if (OptStatus)
359         {
360             printf ("Invalid option in command file %s: %s\n",
361                 Filename, StringBuffer);
362             break;
363         }
364     }
365 
366     /* Restore the GetOpt globals */
367 
368     AcpiGbl_Opterr = Opterr;
369     AcpiGbl_Optind = Optind;
370 
371     fclose (ResponseFile);
372     return (OptStatus);
373 }
374 
375 
376 /*******************************************************************************
377  *
378  * FUNCTION:    AslDoOptions
379  *
380  * PARAMETERS:  argc/argv           - Standard argc/argv
381  *              IsResponseFile      - TRUE if executing a response file.
382  *
383  * RETURN:      Status
384  *
385  * DESCRIPTION: Command line option processing
386  *
387  ******************************************************************************/
388 
389 static int
390 AslDoOptions (
391     int                     argc,
392     char                    **argv,
393     BOOLEAN                 IsResponseFile)
394 {
395     int                     j;
396     ACPI_STATUS             Status;
397 
398 
399     /* Get the command line options */
400 
401     while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
402     {
403     case '@':   /* Begin a response file */
404 
405         if (IsResponseFile)
406         {
407             printf ("Nested command files are not supported\n");
408             return -1;
409         }
410 
411         if (AslDoResponseFile (AcpiGbl_Optarg))
412         {
413             return -1;
414         }
415         break;
416 
417 
418     case '2':
419 
420         Gbl_Acpi2 = TRUE;
421         break;
422 
423 
424     case 'b':
425 
426         switch (AcpiGbl_Optarg[0])
427         {
428         case 'b':
429             AslCompilerdebug = 1; /* same as yydebug */
430             DtParserdebug = 1;
431             break;
432 
433         case 'p':
434             AslCompilerdebug = 1; /* same as yydebug */
435             DtParserdebug = 1;
436             break;
437 
438         case 't':
439             break;
440 
441         default:
442             printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
443             return (-1);
444         }
445 
446         /* Produce debug output file */
447 
448         Gbl_DebugFlag = TRUE;
449         break;
450 
451 
452     case 'c':
453         switch (AcpiGbl_Optarg[0])
454         {
455         case 'r':
456             Gbl_NoResourceChecking = TRUE;
457             break;
458 
459         default:
460             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
461             return (-1);
462         }
463         break;
464 
465 
466     case 'd':
467         switch (AcpiGbl_Optarg[0])
468         {
469         case '^':
470             Gbl_DoCompile = FALSE;
471             break;
472 
473         case 'a':
474             Gbl_DoCompile = FALSE;
475             Gbl_DisassembleAll = TRUE;
476             break;
477 
478         case 'c':
479             break;
480 
481         default:
482             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
483             return (-1);
484         }
485 
486         Gbl_DisasmFlag = TRUE;
487         break;
488 
489 
490     case 'e':
491         Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg);
492         if (ACPI_FAILURE (Status))
493         {
494             printf ("Could not add %s to external list\n", AcpiGbl_Optarg);
495             return (-1);
496         }
497         break;
498 
499 
500     case 'f':
501 
502         /* Ignore errors and force creation of aml file */
503 
504         Gbl_IgnoreErrors = TRUE;
505         break;
506 
507 
508     case 'g':
509 
510         /* Get all ACPI tables */
511 
512         Gbl_GetAllTables = TRUE;
513         Gbl_DoCompile = FALSE;
514         break;
515 
516 
517     case 'h':
518 
519         switch (AcpiGbl_Optarg[0])
520         {
521         case '^':
522             HelpMessage ();
523             exit (0);
524 
525         case 'c':
526             UtDisplayConstantOpcodes ();
527             exit (0);
528 
529         case 'r':
530             /* reserved names */
531 
532             ApDisplayReservedNames ();
533             exit (0);
534 
535         case 't':
536             UtDisplaySupportedTables ();
537             exit (0);
538 
539         default:
540             printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
541             return (-1);
542         }
543 
544 
545     case 'I': /* Add an include file search directory */
546 
547         FlAddIncludeDirectory (AcpiGbl_Optarg);
548         break;
549 
550 
551     case 'i':
552 
553         switch (AcpiGbl_Optarg[0])
554         {
555         case 'a':
556 
557             /* 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 
837 static int
838 AslCommandLine (
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     }
883 
884     /* Abort if anything went wrong on the command line */
885 
886     if (BadCommandLine)
887     {
888         printf ("\n");
889         Usage ();
890         exit (1);
891     }
892 
893     return (AcpiGbl_Optind);
894 }
895 
896 
897 /*******************************************************************************
898  *
899  * FUNCTION:    main
900  *
901  * PARAMETERS:  Standard argc/argv
902  *
903  * RETURN:      Program termination code
904  *
905  * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
906  *              options and begin the compile for each file on the command line
907  *
908  ******************************************************************************/
909 
910 int ACPI_SYSTEM_XFACE
911 main (
912     int                     argc,
913     char                    **argv)
914 {
915     ACPI_STATUS             Status;
916     int                     Index1;
917     int                     Index2;
918 
919 
920     AcpiGbl_ExternalFileList = NULL;
921 
922 #ifdef _DEBUG
923     _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
924                     _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
925 #endif
926 
927     /* Init and command line */
928 
929     AslInitialize ();
930     Index1 = Index2 = AslCommandLine (argc, argv);
931 
932     /* Options that have no additional parameters or pathnames */
933 
934     if (Gbl_GetAllTables)
935     {
936         Status = AslDoOneFile (NULL);
937         if (ACPI_FAILURE (Status))
938         {
939             return (-1);
940         }
941         return (0);
942     }
943 
944     if (Gbl_DisassembleAll)
945     {
946         while (argv[Index1])
947         {
948             Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList);
949             if (ACPI_FAILURE (Status))
950             {
951                 return (-1);
952             }
953 
954             Index1++;
955         }
956     }
957 
958     /* Process each pathname/filename in the list, with possible wildcards */
959 
960     while (argv[Index2])
961     {
962         Status = AslDoOnePathname (argv[Index2], AslDoOneFile);
963         if (ACPI_FAILURE (Status))
964         {
965             return (-1);
966         }
967 
968         Index2++;
969     }
970 
971     if (AcpiGbl_ExternalFileList)
972     {
973         AcpiDmClearExternalFileList();
974     }
975 
976     return (0);
977 }
978 
979 
980