]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/compiler/asloptions.c
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r307894, and update
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / compiler / asloptions.c
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 - 2017, 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
156 #define _COMPONENT          ACPI_COMPILER
157         ACPI_MODULE_NAME    ("asloption")
158
159
160 /* Local prototypes */
161
162 static int
163 AslDoOptions (
164     int                     argc,
165     char                    **argv,
166     BOOLEAN                 IsResponseFile);
167
168 static void
169 AslMergeOptionTokens (
170     char                    *InBuffer,
171     char                    *OutBuffer);
172
173 static int
174 AslDoResponseFile (
175     char                    *Filename);
176
177
178 #define ASL_TOKEN_SEPARATORS    " \t\n"
179 #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"
180
181
182 /*******************************************************************************
183  *
184  * FUNCTION:    AslCommandLine
185  *
186  * PARAMETERS:  argc/argv
187  *
188  * RETURN:      Last argv index
189  *
190  * DESCRIPTION: Command line processing
191  *
192  ******************************************************************************/
193
194 int
195 AslCommandLine (
196     int                     argc,
197     char                    **argv)
198 {
199     int                     BadCommandLine = 0;
200     ACPI_STATUS             Status;
201
202
203     /* Minimum command line contains at least the command and an input file */
204
205     if (argc < 2)
206     {
207         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
208         Usage ();
209         exit (1);
210     }
211
212     /* Process all command line options */
213
214     BadCommandLine = AslDoOptions (argc, argv, FALSE);
215
216     if (Gbl_DoTemplates)
217     {
218         Status = DtCreateTemplates (argv);
219         if (ACPI_FAILURE (Status))
220         {
221             exit (-1);
222         }
223         exit (1);
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 (Gbl_DoSignon)
236     {
237         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
238         if (Gbl_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     UINT32                  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             Gbl_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             Gbl_DoAslConversion = TRUE;
323             Gbl_FoldConstants = FALSE;
324             Gbl_IntegerOptimizationFlag = FALSE;
325             Gbl_ReferenceOptimizationFlag = FALSE;
326             Gbl_OptimizeTrivialParseNodes = FALSE;
327             Gbl_CaptureComments = TRUE;
328             AcpiGbl_DoDisassemblerOptimizations = FALSE;
329             AcpiGbl_DebugAslConversion = TRUE;
330             AcpiGbl_DmEmitExternalOpcodes = TRUE;
331             Gbl_DoExternalsInPlace = TRUE;
332
333             return (0);
334
335         case 'f':
336
337             AslCompilerdebug = 1; /* same as yydebug */
338             DtParserdebug = 1;
339             PrParserdebug = 1;
340             Gbl_DebugFlag = TRUE;
341             Gbl_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             Gbl_PruneParseTree = TRUE;
354             Gbl_PruneDepth = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
355             break;
356
357         case 's':
358
359             Gbl_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
371             Gbl_PruneType = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
372             break;
373
374         default:
375
376             printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
377             return (-1);
378         }
379
380         break;
381
382     case 'c':
383
384         switch (AcpiGbl_Optarg[0])
385         {
386
387         case 'a':
388
389             printf ("Convert ASL to ASL+ with comments\n");
390             Gbl_DoAslConversion = TRUE;
391             Gbl_FoldConstants = FALSE;
392             Gbl_IntegerOptimizationFlag = FALSE;
393             Gbl_ReferenceOptimizationFlag = FALSE;
394             Gbl_OptimizeTrivialParseNodes = FALSE;
395             Gbl_CaptureComments = TRUE;
396             AcpiGbl_DoDisassemblerOptimizations = FALSE;
397             AcpiGbl_DmEmitExternalOpcodes = TRUE;
398             Gbl_DoExternalsInPlace = TRUE;
399
400             return (0);
401
402         case 'r':
403
404             Gbl_NoResourceChecking = TRUE;
405             break;
406
407         default:
408
409             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
410             return (-1);
411         }
412         break;
413
414     case 'd':   /* Disassembler */
415
416         switch (AcpiGbl_Optarg[0])
417         {
418         case '^':
419
420             /* Get the required argument */
421
422             if (AcpiGetoptArgument (argc, argv))
423             {
424                 return (-1);
425             }
426
427             Gbl_DoCompile = FALSE;
428             break;
429
430         case 'a':
431
432             /* Get the required argument */
433
434             if (AcpiGetoptArgument (argc, argv))
435             {
436                 return (-1);
437             }
438
439             Gbl_DoCompile = FALSE;
440             Gbl_DisassembleAll = TRUE;
441             break;
442
443         case 'b':   /* Do not convert buffers to resource descriptors */
444
445             AcpiGbl_NoResourceDisassembly = TRUE;
446             break;
447
448         case 'c':
449
450             break;
451
452         case 'f':
453
454             AcpiGbl_ForceAmlDisassembly = TRUE;
455             break;
456
457         case 'l':   /* Use legacy ASL code (not ASL+) for disassembly */
458
459             Gbl_DoCompile = FALSE;
460             AcpiGbl_CstyleDisassembly = FALSE;
461             break;
462
463         default:
464
465             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
466             return (-1);
467         }
468
469         AcpiGbl_DisasmFlag = TRUE;
470         break;
471
472     case 'D':   /* Define a symbol */
473
474         PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
475         break;
476
477     case 'e':   /* External files for disassembler */
478
479         /* Get entire list of external files */
480
481         AcpiGbl_Optind--;
482         argv[AcpiGbl_Optind] = AcpiGbl_Optarg;
483
484         while (argv[AcpiGbl_Optind] &&
485               (argv[AcpiGbl_Optind][0] != '-'))
486         {
487             Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
488             if (ACPI_FAILURE (Status))
489             {
490                 printf ("Could not add %s to external list\n",
491                     argv[AcpiGbl_Optind]);
492                 return (-1);
493             }
494
495             AcpiGbl_Optind++;
496         }
497         break;
498
499     case 'f':
500
501         switch (AcpiGbl_Optarg[0])
502         {
503         case '^':   /* Ignore errors and force creation of aml file */
504
505             Gbl_IgnoreErrors = TRUE;
506             break;
507
508         case 'e':   /* Disassembler: Get external declaration file */
509
510             if (AcpiGetoptArgument (argc, argv))
511             {
512                 return (-1);
513             }
514
515             Gbl_ExternalRefFilename = AcpiGbl_Optarg;
516             break;
517
518         default:
519
520             printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
521             return (-1);
522         }
523         break;
524
525     case 'G':
526
527         Gbl_CompileGeneric = TRUE;
528         break;
529
530     case 'g':   /* Get all ACPI tables */
531
532         printf ("-g option is deprecated, use acpidump utility instead\n");
533         exit (1);
534
535     case 'h':
536
537         switch (AcpiGbl_Optarg[0])
538         {
539         case '^':
540
541             printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
542             Usage ();
543             exit (0);
544
545         case 'c':
546
547             UtDisplayConstantOpcodes ();
548             exit (0);
549
550         case 'd':
551
552             AslDisassemblyHelp ();
553             exit (0);
554
555         case 'f':
556
557             AslFilenameHelp ();
558             exit (0);
559
560         case 'r':
561
562             /* reserved names */
563
564             ApDisplayReservedNames ();
565             exit (0);
566
567         case 't':
568
569             UtDisplaySupportedTables ();
570             exit (0);
571
572         default:
573
574             printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
575             return (-1);
576         }
577
578     case 'I':   /* Add an include file search directory */
579
580         FlAddIncludeDirectory (AcpiGbl_Optarg);
581         break;
582
583     case 'i':   /* Output AML as an include file */
584
585         switch (AcpiGbl_Optarg[0])
586         {
587         case 'a':
588
589             /* Produce assembly code include file */
590
591             Gbl_AsmIncludeOutputFlag = TRUE;
592             break;
593
594         case 'c':
595
596             /* Produce C include file */
597
598             Gbl_C_IncludeOutputFlag = TRUE;
599             break;
600
601         case 'n':
602
603             /* Compiler/Disassembler: Ignore the NOOP operator */
604
605             AcpiGbl_IgnoreNoopOperator = TRUE;
606             break;
607
608         default:
609
610             printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
611             return (-1);
612         }
613         break;
614
615     case 'l':   /* Listing files */
616
617         switch (AcpiGbl_Optarg[0])
618         {
619         case '^':
620
621             /* Produce listing file (Mixed source/aml) */
622
623             Gbl_ListingFlag = TRUE;
624             AcpiGbl_DmOpt_Listing = TRUE;
625             break;
626
627         case 'i':
628
629             /* Produce preprocessor output file */
630
631             Gbl_PreprocessorOutputFlag = TRUE;
632             break;
633
634         case 'm':
635
636             /* Produce hardware map summary file */
637
638             Gbl_MapfileFlag = TRUE;
639             break;
640
641         case 'n':
642
643             /* Produce namespace file */
644
645             Gbl_NsOutputFlag = TRUE;
646             break;
647
648         case 's':
649
650             /* Produce combined source file */
651
652             Gbl_SourceOutputFlag = TRUE;
653             break;
654
655         case 'x':
656
657             /* Produce cross-reference file */
658
659             Gbl_CrossReferenceOutput = TRUE;
660             break;
661
662         default:
663
664             printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
665             return (-1);
666         }
667         break;
668
669     case 'm':   /* Set line buffer size */
670
671         Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
672         if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
673         {
674             Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
675         }
676         printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
677         break;
678
679     case 'n':   /* Parse only */
680
681         Gbl_ParseOnlyFlag = TRUE;
682         break;
683
684     case 'o':   /* Control compiler AML optimizations */
685
686         switch (AcpiGbl_Optarg[0])
687         {
688         case 'a':
689
690             /* Disable all optimizations */
691
692             Gbl_FoldConstants = FALSE;
693             Gbl_IntegerOptimizationFlag = FALSE;
694             Gbl_ReferenceOptimizationFlag = FALSE;
695             Gbl_OptimizeTrivialParseNodes = FALSE;
696
697             break;
698
699         case 'c':
700
701             /* Display compile time(s) */
702
703             Gbl_CompileTimesFlag = TRUE;
704             break;
705
706         case 'd':
707
708             /* Disable disassembler code optimizations */
709
710             AcpiGbl_DoDisassemblerOptimizations = FALSE;
711             break;
712
713         case 'e':
714
715             /* Disassembler: Emit embedded external operators */
716
717             AcpiGbl_DmEmitExternalOpcodes = TRUE;
718             break;
719
720         case 'E':
721
722             /*
723              * iASL: keep External opcodes in place.
724              * No affect if Gbl_DoExternals is false.
725              */
726
727             Gbl_DoExternalsInPlace = TRUE;
728             break;
729
730         case 'f':
731
732             /* Disable folding on "normal" expressions */
733
734             Gbl_FoldConstants = FALSE;
735             break;
736
737         case 'i':
738
739             /* Disable integer optimization to constants */
740
741             Gbl_IntegerOptimizationFlag = FALSE;
742             break;
743
744         case 'n':
745
746             /* Disable named reference optimization */
747
748             Gbl_ReferenceOptimizationFlag = FALSE;
749             break;
750
751         case 't':
752
753             /* Disable heavy typechecking */
754
755             Gbl_DoTypechecking = FALSE;
756             break;
757
758         default:
759
760             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
761             return (-1);
762         }
763         break;
764
765     case 'P':   /* Preprocessor options */
766
767         switch (AcpiGbl_Optarg[0])
768         {
769         case '^':   /* Proprocess only, emit (.i) file */
770
771             Gbl_PreprocessOnly = TRUE;
772             Gbl_PreprocessorOutputFlag = TRUE;
773             break;
774
775         case 'n':   /* Disable preprocessor */
776
777             Gbl_PreprocessFlag = FALSE;
778             break;
779
780         default:
781
782             printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
783             return (-1);
784         }
785         break;
786
787     case 'p':   /* Override default AML output filename */
788
789         Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
790         UtConvertBackslashes (Gbl_OutputFilenamePrefix);
791         Gbl_UseDefaultAmlFilename = FALSE;
792         break;
793
794     case 'q':   /* ASL/ASl+ converter: compile only and leave badaml. */
795
796         printf ("Convert ASL to ASL+ with comments\n");
797         Gbl_FoldConstants = FALSE;
798         Gbl_IntegerOptimizationFlag = FALSE;
799         Gbl_ReferenceOptimizationFlag = FALSE;
800         Gbl_OptimizeTrivialParseNodes = FALSE;
801         Gbl_CaptureComments = TRUE;
802         Gbl_DoExternalsInPlace = TRUE;
803         return (0);
804
805     case 'r':   /* Override revision found in table header */
806
807         Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
808         break;
809
810     case 's':   /* Create AML in a source code file */
811
812         switch (AcpiGbl_Optarg[0])
813         {
814         case 'a':
815
816             /* Produce assembly code output file */
817
818             Gbl_AsmOutputFlag = TRUE;
819             break;
820
821         case 'c':
822
823             /* Produce C hex output file */
824
825             Gbl_C_OutputFlag = TRUE;
826             break;
827
828         case 'o':
829
830             /* Produce AML offset table in C */
831
832             Gbl_C_OffsetTableFlag = TRUE;
833             break;
834
835         default:
836
837             printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
838             return (-1);
839         }
840         break;
841
842     case 't':   /* Produce hex table output file */
843
844         switch (AcpiGbl_Optarg[0])
845         {
846         case 'a':
847
848             Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
849             break;
850
851         case 'c':
852
853             Gbl_HexOutputFlag = HEX_OUTPUT_C;
854             break;
855
856         case 's':
857
858             Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
859             break;
860
861         default:
862
863             printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
864             return (-1);
865         }
866         break;
867
868     case 'T':   /* Create a ACPI table template file */
869
870         Gbl_DoTemplates = TRUE;
871         break;
872
873     case 'v':   /* Version and verbosity settings */
874
875         switch (AcpiGbl_Optarg[0])
876         {
877         case '^':
878
879             printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
880             exit (0);
881
882         case 'a':
883
884             /* Disable all error/warning/remark messages */
885
886             Gbl_NoErrors = TRUE;
887             break;
888
889         case 'e':
890
891             /* Disable all warning/remark messages (errors only) */
892
893             Gbl_DisplayRemarks = FALSE;
894             Gbl_DisplayWarnings = FALSE;
895             break;
896
897         case 'i':
898             /*
899              * Support for integrated development environment(s).
900              *
901              * 1) No compiler signon
902              * 2) Send stderr messages to stdout
903              * 3) Less verbose error messages (single line only for each)
904              * 4) Error/warning messages are formatted appropriately to
905              *    be recognized by MS Visual Studio
906              */
907             Gbl_VerboseErrors = FALSE;
908             Gbl_DoSignon = FALSE;
909             Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
910             break;
911
912         case 'o':
913
914             Gbl_DisplayOptimizations = TRUE;
915             break;
916
917         case 'r':
918
919             Gbl_DisplayRemarks = FALSE;
920             break;
921
922         case 's':
923
924             Gbl_DoSignon = FALSE;
925             break;
926
927         case 't':
928
929             Gbl_VerboseTemplates = TRUE;
930             break;
931
932         case 'w':
933
934             /* Get the required argument */
935
936             if (AcpiGetoptArgument (argc, argv))
937             {
938                 return (-1);
939             }
940
941             Status = AslDisableException (AcpiGbl_Optarg);
942             if (ACPI_FAILURE (Status))
943             {
944                 return (-1);
945             }
946             break;
947
948         default:
949
950             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
951             return (-1);
952         }
953         break;
954
955     case 'w': /* Set warning levels */
956
957         switch (AcpiGbl_Optarg[0])
958         {
959         case '1':
960
961             Gbl_WarningLevel = ASL_WARNING;
962             break;
963
964         case '2':
965
966             Gbl_WarningLevel = ASL_WARNING2;
967             break;
968
969         case '3':
970
971             Gbl_WarningLevel = ASL_WARNING3;
972             break;
973
974         case 'e':
975
976             Gbl_WarningsAsErrors = TRUE;
977             break;
978
979         default:
980
981             printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
982             return (-1);
983         }
984         break;
985
986     case 'x':   /* Set debug print output level */
987
988         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
989         break;
990
991     case 'z':
992
993         Gbl_UseOriginalCompilerId = TRUE;
994         break;
995
996     default:
997
998         return (-1);
999     }
1000
1001     return (0);
1002 }
1003
1004
1005 /*******************************************************************************
1006  *
1007  * FUNCTION:    AslMergeOptionTokens
1008  *
1009  * PARAMETERS:  InBuffer            - Input containing an option string
1010  *              OutBuffer           - Merged output buffer
1011  *
1012  * RETURN:      None
1013  *
1014  * DESCRIPTION: Remove all whitespace from an option string.
1015  *
1016  ******************************************************************************/
1017
1018 static void
1019 AslMergeOptionTokens (
1020     char                    *InBuffer,
1021     char                    *OutBuffer)
1022 {
1023     char                    *Token;
1024
1025
1026     *OutBuffer = 0;
1027
1028     Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
1029     while (Token)
1030     {
1031         strcat (OutBuffer, Token);
1032         Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
1033     }
1034 }
1035
1036
1037 /*******************************************************************************
1038  *
1039  * FUNCTION:    AslDoResponseFile
1040  *
1041  * PARAMETERS:  Filename        - Name of the response file
1042  *
1043  * RETURN:      Status
1044  *
1045  * DESCRIPTION: Open a response file and process all options within.
1046  *
1047  ******************************************************************************/
1048
1049 static int
1050 AslDoResponseFile (
1051     char                    *Filename)
1052 {
1053     char                    *argv = StringBuffer2;
1054     FILE                    *ResponseFile;
1055     int                     OptStatus = 0;
1056     int                     Opterr;
1057     int                     Optind;
1058
1059
1060     ResponseFile = fopen (Filename, "r");
1061     if (!ResponseFile)
1062     {
1063         printf ("Could not open command file %s, %s\n",
1064             Filename, strerror (errno));
1065         return (-1);
1066     }
1067
1068     /* Must save the current GetOpt globals */
1069
1070     Opterr = AcpiGbl_Opterr;
1071     Optind = AcpiGbl_Optind;
1072
1073     /*
1074      * Process all lines in the response file. There must be one complete
1075      * option per line
1076      */
1077     while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
1078     {
1079         /* Compress all tokens, allowing us to use a single argv entry */
1080
1081         AslMergeOptionTokens (StringBuffer, StringBuffer2);
1082
1083         /* Process the option */
1084
1085         AcpiGbl_Opterr = 0;
1086         AcpiGbl_Optind = 0;
1087
1088         OptStatus = AslDoOptions (1, &argv, TRUE);
1089         if (OptStatus)
1090         {
1091             printf ("Invalid option in command file %s: %s\n",
1092                 Filename, StringBuffer);
1093             break;
1094         }
1095     }
1096
1097     /* Restore the GetOpt globals */
1098
1099     AcpiGbl_Opterr = Opterr;
1100     AcpiGbl_Optind = Optind;
1101
1102     fclose (ResponseFile);
1103     return (OptStatus);
1104 }