xref: /freebsd/sys/contrib/dev/acpica/compiler/asloptions.c (revision a8089ea5aee578e08acab2438e82fc9a9ae50ed8)
1 /******************************************************************************
2  *
3  * Module Name: asloptions - compiler command line processing
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include <contrib/dev/acpica/compiler/aslcompiler.h>
153 #include <contrib/dev/acpica/include/acapps.h>
154 #include <contrib/dev/acpica/include/acdisasm.h>
155 #include <contrib/dev/acpica/include/acglobal.h>
156 
157 #define _COMPONENT          ACPI_COMPILER
158         ACPI_MODULE_NAME    ("asloption")
159 
160 
161 /* Local prototypes */
162 
163 static int
164 AslDoOptions (
165     int                     argc,
166     char                    **argv,
167     BOOLEAN                 IsResponseFile);
168 
169 static void
170 AslMergeOptionTokens (
171     char                    *InBuffer,
172     char                    *OutBuffer);
173 
174 static int
175 AslDoResponseFile (
176     char                    *Filename);
177 
178 
179 #define ASL_TOKEN_SEPARATORS    " \t\n"
180 #define ASL_SUPPORTED_OPTIONS   "@:a:b|c|d^D:e:f^gh^i|I:l^m:no|p:P^q^r:s|:t|T+G^v^w|x:z"
181 
182 
183 /*******************************************************************************
184  *
185  * FUNCTION:    AslCommandLine
186  *
187  * PARAMETERS:  argc/argv
188  *
189  * RETURN:      Last argv index
190  *
191  * DESCRIPTION: Command line processing
192  *
193  ******************************************************************************/
194 
195 int
196 AslCommandLine (
197     int                     argc,
198     char                    **argv)
199 {
200     int                     BadCommandLine = 0;
201     ACPI_STATUS             Status;
202 
203 
204     /* Minimum command line contains at least the command and an input file */
205 
206     if (argc < 2)
207     {
208         Usage ();
209         exit (1);
210     }
211 
212     /* Process all command line options */
213 
214     BadCommandLine = AslDoOptions (argc, argv, FALSE);
215 
216     if (AslGbl_DoTemplates)
217     {
218         Status = DtCreateTemplates (argv);
219         if (ACPI_FAILURE (Status))
220         {
221             exit (-1);
222         }
223         exit (0);
224     }
225 
226     /* Next parameter must be the input filename */
227 
228     if (!argv[AcpiGbl_Optind] &&
229         !AcpiGbl_DisasmFlag)
230     {
231         printf ("Missing input filename\n");
232         BadCommandLine = TRUE;
233     }
234 
235     if (AslGbl_DoSignon)
236     {
237         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
238         if (AslGbl_IgnoreErrors)
239         {
240             printf ("Ignoring all errors, forcing AML file generation\n\n");
241         }
242     }
243 
244     if (BadCommandLine)
245     {
246         printf ("Use -h option for help information\n");
247         exit (1);
248     }
249 
250     return (AcpiGbl_Optind);
251 }
252 
253 
254 /*******************************************************************************
255  *
256  * FUNCTION:    AslDoOptions
257  *
258  * PARAMETERS:  argc/argv           - Standard argc/argv
259  *              IsResponseFile      - TRUE if executing a response file.
260  *
261  * RETURN:      Status
262  *
263  * DESCRIPTION: Command line option processing
264  *
265  ******************************************************************************/
266 
267 static int
268 AslDoOptions (
269     int                     argc,
270     char                    **argv,
271     BOOLEAN                 IsResponseFile)
272 {
273     ACPI_STATUS             Status;
274     INT32                  j;
275 
276 
277     /* Get the command line options */
278 
279     while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
280     {
281     case '@':   /* Begin a response file */
282 
283         if (IsResponseFile)
284         {
285             printf ("Nested command files are not supported\n");
286             return (-1);
287         }
288 
289         if (AslDoResponseFile (AcpiGbl_Optarg))
290         {
291             return (-1);
292         }
293         break;
294 
295     case 'a':   /* Debug options */
296 
297         switch (AcpiGbl_Optarg[0])
298         {
299         case 'r':
300 
301             AslGbl_EnableReferenceTypechecking = TRUE;
302             break;
303 
304         default:
305 
306             printf ("Unknown option: -a%s\n", AcpiGbl_Optarg);
307             return (-1);
308         }
309 
310         break;
311 
312 
313     case 'b':   /* Debug options */
314 
315         switch (AcpiGbl_Optarg[0])
316         {
317 
318         case 'c':
319 
320             printf ("Debug ASL to ASL+ conversion\n");
321 
322             AslGbl_DoAslConversion = TRUE;
323             AslGbl_FoldConstants = FALSE;
324             AslGbl_IntegerOptimizationFlag = FALSE;
325             AslGbl_ReferenceOptimizationFlag = FALSE;
326             AslGbl_OptimizeTrivialParseNodes = FALSE;
327             AcpiGbl_CaptureComments = TRUE;
328             AcpiGbl_DoDisassemblerOptimizations = FALSE;
329             AcpiGbl_DebugAslConversion = TRUE;
330             AcpiGbl_DmEmitExternalOpcodes = TRUE;
331             AslGbl_DoExternalsInPlace = TRUE;
332 
333             return (0);
334 
335         case 'f':
336 
337             AslCompilerdebug = 1; /* same as yydebug */
338             DtParserdebug = 1;
339             PrParserdebug = 1;
340             AslGbl_DebugFlag = TRUE;
341             AslGbl_KeepPreprocessorTempFile = TRUE;
342             break;
343 
344         case 'p':   /* Prune ASL parse tree */
345 
346             /* Get the required argument */
347 
348             if (AcpiGetoptArgument (argc, argv))
349             {
350                 return (-1);
351             }
352 
353             AslGbl_PruneParseTree = TRUE;
354             AslGbl_PruneDepth = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
355             break;
356 
357         case 's':
358 
359             AslGbl_DebugFlag = TRUE;
360             break;
361 
362         case 't':
363 
364             /* Get the required argument */
365 
366             if (AcpiGetoptArgument (argc, argv))
367             {
368                 return (-1);
369             }
370             AslGbl_PruneType = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
371             break;
372 
373         default:
374 
375             printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
376             return (-1);
377         }
378 
379         break;
380 
381     case 'c':
382 
383         switch (AcpiGbl_Optarg[0])
384         {
385 
386         case 'a':
387 
388             printf ("Convert ASL to ASL+ with comments\n");
389             AslGbl_DoAslConversion = TRUE;
390             AslGbl_FoldConstants = FALSE;
391             AslGbl_IntegerOptimizationFlag = FALSE;
392             AslGbl_ReferenceOptimizationFlag = FALSE;
393             AslGbl_OptimizeTrivialParseNodes = FALSE;
394             AcpiGbl_CaptureComments = TRUE;
395             AcpiGbl_DoDisassemblerOptimizations = FALSE;
396             AcpiGbl_DmEmitExternalOpcodes = TRUE;
397             AslGbl_DoExternalsInPlace = TRUE;
398 
399             return (0);
400 
401         case 'r':
402 
403             AslGbl_NoResourceChecking = TRUE;
404             break;
405 
406         default:
407 
408             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
409             return (-1);
410         }
411         break;
412 
413     case 'd':   /* Disassembler */
414 
415         switch (AcpiGbl_Optarg[0])
416         {
417         case '^':
418 
419             AslGbl_DoCompile = FALSE;
420             break;
421 
422         case 'a':
423 
424             AslGbl_DoCompile = FALSE;
425             AslGbl_DisassembleAll = TRUE;
426             break;
427 
428         case 'b':   /* Do not convert buffers to resource descriptors */
429 
430             AcpiGbl_NoResourceDisassembly = TRUE;
431             break;
432 
433         case 'c':
434 
435             break;
436 
437         case 'f':
438 
439             AcpiGbl_ForceAmlDisassembly = TRUE;
440             break;
441 
442         case 'l':   /* Use legacy ASL code (not ASL+) for disassembly */
443 
444             AslGbl_DoCompile = FALSE;
445             AcpiGbl_CstyleDisassembly = FALSE;
446             break;
447 
448         case 's':   /* Specify table signature (Only supported for CDAT table) */
449 
450             /* Get the required argument */
451 
452             if (AcpiGetoptArgument (argc, argv))
453             {
454                 return (-1);
455             }
456 
457             /* Check for exact string "CDAT" (upper or lower case) */
458 
459             AcpiGbl_CDAT = ACPI_CAST_PTR (char, &AcpiGbl_Optarg);
460             if (AcpiUtStricmp (AcpiGbl_Optarg, ACPI_SIG_CDAT))
461             {
462                 printf ("\nUnknown table signature: %s\n", AcpiGbl_Optarg);
463                 return (-1);
464             }
465 
466             AcpiGbl_CDAT = malloc (5);
467             AcpiUtSafeStrncpy ((char *) AcpiGbl_CDAT, ACPI_SIG_CDAT, 5);
468             break;
469 
470         default:
471 
472             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
473             return (-1);
474         }
475 
476         AcpiGbl_DisasmFlag = TRUE;
477         break;
478 
479     case 'D':   /* Define a symbol */
480 
481         PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
482         break;
483 
484     case 'e':   /* External files for disassembler */
485 
486         /* Get entire list of external files */
487 
488         AcpiGbl_Optind--;
489         argv[AcpiGbl_Optind] = AcpiGbl_Optarg;
490 
491         while (argv[AcpiGbl_Optind] &&
492               (argv[AcpiGbl_Optind][0] != '-'))
493         {
494             Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
495             if (ACPI_FAILURE (Status))
496             {
497                 printf ("Could not add %s to external list\n",
498                     argv[AcpiGbl_Optind]);
499                 return (-1);
500             }
501 
502             AcpiGbl_Optind++;
503         }
504         break;
505 
506     case 'f':
507 
508         switch (AcpiGbl_Optarg[0])
509         {
510         case '^':   /* Ignore errors and force creation of aml file */
511 
512             AslGbl_IgnoreErrors = TRUE;
513             break;
514 
515         case 'e':   /* Disassembler: Get external declaration file */
516 
517             if (AcpiGetoptArgument (argc, argv))
518             {
519                 return (-1);
520             }
521 
522             AslGbl_ExternalRefFilename = AcpiGbl_Optarg;
523             break;
524 
525         default:
526 
527             printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
528             return (-1);
529         }
530         break;
531 
532     case 'G':
533 
534         AslGbl_CompileGeneric = TRUE;
535         break;
536 
537     case 'g':   /* Get all ACPI tables */
538 
539         printf ("-g option is deprecated, use acpidump utility instead\n");
540         exit (1);
541 
542     case 'h':
543 
544         switch (AcpiGbl_Optarg[0])
545         {
546         case '^':
547 
548             Usage ();
549             exit (0);
550 
551         case 'c':
552 
553             UtDisplayConstantOpcodes ();
554             exit (0);
555 
556         case 'd':
557 
558             AslDisassemblyHelp ();
559             exit (0);
560 
561         case 'f':
562 
563             AslFilenameHelp ();
564             exit (0);
565 
566         case 'r':
567 
568             /* reserved names */
569 
570             ApDisplayReservedNames ();
571             exit (0);
572 
573         case 't':
574 
575             UtDisplaySupportedTables ();
576             exit (0);
577 
578         default:
579 
580             printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
581             return (-1);
582         }
583 
584     case 'I':   /* Add an include file search directory */
585 
586         FlAddIncludeDirectory (AcpiGbl_Optarg);
587         break;
588 
589     case 'i':   /* Output AML as an include file */
590 
591         switch (AcpiGbl_Optarg[0])
592         {
593         case 'a':
594 
595             /* Produce assembly code include file */
596 
597             AslGbl_AsmIncludeOutputFlag = TRUE;
598             break;
599 
600         case 'c':
601 
602             /* Produce C include file */
603 
604             AslGbl_C_IncludeOutputFlag = TRUE;
605             break;
606 
607         case 'n':
608 
609             /* Compiler/Disassembler: Ignore the NOOP operator */
610 
611             AcpiGbl_IgnoreNoopOperator = TRUE;
612             break;
613 
614         default:
615 
616             printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
617             return (-1);
618         }
619         break;
620 
621     case 'l':   /* Listing files */
622 
623         switch (AcpiGbl_Optarg[0])
624         {
625         case '^':
626 
627             /* Produce listing file (Mixed source/aml) */
628 
629             AslGbl_ListingFlag = TRUE;
630             AcpiGbl_DmOpt_Listing = TRUE;
631             break;
632 
633         case 'i':
634 
635             /* Produce preprocessor output file */
636 
637             AslGbl_PreprocessorOutputFlag = TRUE;
638             break;
639 
640         case 'm':
641 
642             /* Produce hardware map summary file */
643 
644             AslGbl_MapfileFlag = TRUE;
645             break;
646 
647         case 'n':
648 
649             /* Produce namespace file */
650 
651             AslGbl_NsOutputFlag = TRUE;
652             break;
653 
654         case 's':
655 
656             /* Produce combined source file */
657 
658             AslGbl_SourceOutputFlag = TRUE;
659             break;
660 
661         case 'x':
662 
663             /* Produce cross-reference file */
664 
665             AslGbl_CrossReferenceOutput = TRUE;
666             break;
667 
668         default:
669 
670             printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
671             return (-1);
672         }
673         break;
674 
675     case 'm':   /* Set line buffer size */
676 
677         AslGbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
678         if (AslGbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
679         {
680             AslGbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
681         }
682         printf ("Line Buffer Size: %u\n", AslGbl_LineBufferSize);
683         break;
684 
685     case 'n':   /* Parse only */
686 
687         AslGbl_ParseOnlyFlag = TRUE;
688         break;
689 
690     case 'o':   /* Control compiler AML optimizations */
691 
692         switch (AcpiGbl_Optarg[0])
693         {
694         case 'a':
695 
696             /* Disable all optimizations */
697 
698             AslGbl_FoldConstants = FALSE;
699             AslGbl_IntegerOptimizationFlag = FALSE;
700             AslGbl_ReferenceOptimizationFlag = FALSE;
701             AslGbl_OptimizeTrivialParseNodes = FALSE;
702 
703             break;
704 
705         case 'c':
706 
707             /* Display compile time(s) */
708 
709             AslGbl_CompileTimesFlag = TRUE;
710             break;
711 
712         case 'd':
713 
714             /* Disable disassembler code optimizations */
715 
716             AcpiGbl_DoDisassemblerOptimizations = FALSE;
717             break;
718 
719         case 'e':
720 
721             /* Disassembler: Emit embedded external operators */
722 
723             AcpiGbl_DmEmitExternalOpcodes = TRUE;
724             break;
725 
726         case 'E':
727 
728             /*
729              * iASL: keep External opcodes in place.
730              * No affect if Gbl_DoExternals is false.
731              */
732 
733             AslGbl_DoExternalsInPlace = TRUE;
734             break;
735 
736         case 'f':
737 
738             /* Disable folding on "normal" expressions */
739 
740             AslGbl_FoldConstants = FALSE;
741             break;
742 
743         case 'i':
744 
745             /* Disable integer optimization to constants */
746 
747             AslGbl_IntegerOptimizationFlag = FALSE;
748             break;
749 
750         case 'n':
751 
752             /* Disable named reference optimization */
753 
754             AslGbl_ReferenceOptimizationFlag = FALSE;
755             break;
756 
757         case 't':
758 
759             /* Disable heavy typechecking */
760 
761             AslGbl_DoTypechecking = FALSE;
762             break;
763 
764         default:
765 
766             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
767             return (-1);
768         }
769         break;
770 
771     case 'P':   /* Preprocessor options */
772 
773         switch (AcpiGbl_Optarg[0])
774         {
775         case '^':   /* Proprocess only, emit (.i) file */
776 
777             AslGbl_PreprocessOnly = TRUE;
778             AslGbl_PreprocessorOutputFlag = TRUE;
779             break;
780 
781         case 'n':   /* Disable preprocessor */
782 
783             AslGbl_PreprocessFlag = FALSE;
784             break;
785 
786         default:
787 
788             printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
789             return (-1);
790         }
791         break;
792 
793     case 'p':   /* Override default AML output filename */
794 
795         AslGbl_OutputFilenamePrefix = AcpiGbl_Optarg;
796         UtConvertBackslashes (AslGbl_OutputFilenamePrefix);
797         AslGbl_UseDefaultAmlFilename = FALSE;
798         break;
799 
800     case 'q':   /* ASL/ASl+ converter: compile only and leave badaml. */
801 
802         printf ("Convert ASL to ASL+ with comments\n");
803         AslGbl_FoldConstants = FALSE;
804         AslGbl_IntegerOptimizationFlag = FALSE;
805         AslGbl_ReferenceOptimizationFlag = FALSE;
806         AslGbl_OptimizeTrivialParseNodes = FALSE;
807         AslGbl_DoExternalsInPlace = TRUE;
808         AcpiGbl_CaptureComments = TRUE;
809         return (0);
810 
811     case 'r':   /* Override revision found in table header */
812 
813         AslGbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
814         break;
815 
816     case 's':   /* Create AML in a source code file */
817 
818         switch (AcpiGbl_Optarg[0])
819         {
820         case 'a':
821 
822             /* Produce assembly code output file */
823 
824             AslGbl_AsmOutputFlag = TRUE;
825             break;
826 
827         case 'c':
828 
829             /* Produce C hex output file */
830 
831             AslGbl_C_OutputFlag = TRUE;
832             break;
833 
834         case 'o':
835 
836             /* Produce AML offset table in C */
837 
838             AslGbl_C_OffsetTableFlag = TRUE;
839             break;
840 
841         default:
842 
843             printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
844             return (-1);
845         }
846         break;
847 
848     case 't':   /* Produce hex table output file */
849 
850         switch (AcpiGbl_Optarg[0])
851         {
852         case 'a':
853 
854             AslGbl_HexOutputFlag = HEX_OUTPUT_ASM;
855             break;
856 
857         case 'c':
858 
859             AslGbl_HexOutputFlag = HEX_OUTPUT_C;
860             break;
861 
862         case 'p': /* data table flex/bison prototype */
863 
864             AslGbl_DtLexBisonPrototype = TRUE;
865             break;
866 
867         case 's':
868 
869             AslGbl_HexOutputFlag = HEX_OUTPUT_ASL;
870             break;
871 
872         default:
873 
874             printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
875             return (-1);
876         }
877         break;
878 
879     case 'T':   /* Create a ACPI table template file */
880 
881         AslGbl_DoTemplates = TRUE;
882         break;
883 
884     case 'v':   /* Version and verbosity settings */
885 
886         switch (AcpiGbl_Optarg[0])
887         {
888         case '^':
889 
890             printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
891             exit (0);
892 
893         case 'a':
894 
895             /* Disable all error/warning/remark messages */
896 
897             AslGbl_NoErrors = TRUE;
898             break;
899 
900         case 'e':
901 
902             /* Disable all warning/remark messages (errors only) */
903 
904             AslGbl_DisplayRemarks = FALSE;
905             AslGbl_DisplayWarnings = FALSE;
906             break;
907 
908         case 'i':
909             /*
910              * Support for integrated development environment(s).
911              *
912              * 1) No compiler signon
913              * 2) Send stderr messages to stdout
914              * 3) Less verbose error messages (single line only for each)
915              * 4) Error/warning messages are formatted appropriately to
916              *    be recognized by MS Visual Studio
917              */
918             AslGbl_VerboseErrors = FALSE;
919             AslGbl_DoSignon = FALSE;
920             break;
921 
922         case 'o':
923 
924             AslGbl_DisplayOptimizations = TRUE;
925             break;
926 
927         case 'r':
928 
929             AslGbl_DisplayRemarks = FALSE;
930             break;
931 
932         case 's':
933 
934             AslGbl_DoSignon = FALSE;
935             break;
936 
937         case 't':
938 
939             AslGbl_VerboseTemplates = TRUE;
940             break;
941 
942         case 'w':
943 
944             /* Get the required argument */
945 
946             if (AcpiGetoptArgument (argc, argv))
947             {
948                 return (-1);
949             }
950 
951             Status = AslDisableException (AcpiGbl_Optarg);
952             if (ACPI_FAILURE (Status))
953             {
954                 return (-1);
955             }
956             break;
957 
958         case 'x':
959 
960             /* Get the required argument */
961 
962             if (AcpiGetoptArgument (argc, argv))
963             {
964                 return (-1);
965             }
966 
967             Status = AslLogExpectedException (AcpiGbl_Optarg);
968             if (ACPI_FAILURE (Status))
969             {
970                 return (-1);
971             }
972             break;
973 
974         default:
975 
976             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
977             return (-1);
978         }
979         break;
980 
981     case 'w': /* Set warning levels */
982 
983         switch (AcpiGbl_Optarg[0])
984         {
985         case '1':
986 
987             AslGbl_WarningLevel = ASL_WARNING;
988             break;
989 
990         case '2':
991 
992             AslGbl_WarningLevel = ASL_WARNING2;
993             break;
994 
995         case '3':
996 
997             AslGbl_WarningLevel = ASL_WARNING3;
998             break;
999 
1000         case 'e':
1001 
1002             AslGbl_WarningsAsErrors = TRUE;
1003             break;
1004 
1005         case 'w':
1006 
1007             /* Get the required argument */
1008 
1009             if (AcpiGetoptArgument (argc, argv))
1010             {
1011                 return (-1);
1012             }
1013 
1014             Status = AslElevateException (AcpiGbl_Optarg);
1015             if (ACPI_FAILURE (Status))
1016             {
1017                 return (-1);
1018             }
1019             break;
1020 
1021 
1022         default:
1023 
1024             printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
1025             return (-1);
1026         }
1027         break;
1028 
1029     case 'x':   /* Set debug print output level */
1030 
1031         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
1032         break;
1033 
1034     case 'z':
1035 
1036         AslGbl_UseOriginalCompilerId = TRUE;
1037         break;
1038 
1039     default:
1040 
1041         return (-1);
1042     }
1043 
1044     return (0);
1045 }
1046 
1047 
1048 /*******************************************************************************
1049  *
1050  * FUNCTION:    AslMergeOptionTokens
1051  *
1052  * PARAMETERS:  InBuffer            - Input containing an option string
1053  *              OutBuffer           - Merged output buffer
1054  *
1055  * RETURN:      None
1056  *
1057  * DESCRIPTION: Remove all whitespace from an option string.
1058  *
1059  ******************************************************************************/
1060 
1061 static void
1062 AslMergeOptionTokens (
1063     char                    *InBuffer,
1064     char                    *OutBuffer)
1065 {
1066     char                    *Token;
1067 
1068 
1069     *OutBuffer = 0;
1070 
1071     Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
1072     while (Token)
1073     {
1074         strcat (OutBuffer, Token);
1075         Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
1076     }
1077 }
1078 
1079 
1080 /*******************************************************************************
1081  *
1082  * FUNCTION:    AslDoResponseFile
1083  *
1084  * PARAMETERS:  Filename        - Name of the response file
1085  *
1086  * RETURN:      Status
1087  *
1088  * DESCRIPTION: Open a response file and process all options within.
1089  *
1090  ******************************************************************************/
1091 
1092 static int
1093 AslDoResponseFile (
1094     char                    *Filename)
1095 {
1096     char                    *argv = AslGbl_StringBuffer2;
1097     FILE                    *ResponseFile;
1098     int                     OptStatus = 0;
1099     int                     Opterr;
1100     int                     Optind;
1101 
1102 
1103     ResponseFile = fopen (Filename, "r");
1104     if (!ResponseFile)
1105     {
1106         printf ("Could not open command file %s, %s\n",
1107             Filename, strerror (errno));
1108         return (-1);
1109     }
1110 
1111     /* Must save the current GetOpt globals */
1112 
1113     Opterr = AcpiGbl_Opterr;
1114     Optind = AcpiGbl_Optind;
1115 
1116     /*
1117      * Process all lines in the response file. There must be one complete
1118      * option per line
1119      */
1120     while (fgets (AslGbl_StringBuffer, ASL_STRING_BUFFER_SIZE, ResponseFile))
1121     {
1122         /* Compress all tokens, allowing us to use a single argv entry */
1123 
1124         AslMergeOptionTokens (AslGbl_StringBuffer, AslGbl_StringBuffer2);
1125 
1126         /* Process the option */
1127 
1128         AcpiGbl_Opterr = 0;
1129         AcpiGbl_Optind = 0;
1130 
1131         OptStatus = AslDoOptions (1, &argv, TRUE);
1132         if (OptStatus)
1133         {
1134             printf ("Invalid option in command file %s: %s\n",
1135                 Filename, AslGbl_StringBuffer);
1136             break;
1137         }
1138     }
1139 
1140     /* Restore the GetOpt globals */
1141 
1142     AcpiGbl_Opterr = Opterr;
1143     AcpiGbl_Optind = Optind;
1144 
1145     fclose (ResponseFile);
1146     return (OptStatus);
1147 }
1148