asloptions.c revision 1.1.1.2.2.2 1 /******************************************************************************
2 *
3 * Module Name: asloptions - compiler command line processing
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2015, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "aslcompiler.h"
45 #include "acapps.h"
46 #include "acdisasm.h"
47
48 #define _COMPONENT ACPI_COMPILER
49 ACPI_MODULE_NAME ("asloption")
50
51
52 /* Local prototypes */
53
54 static int
55 AslDoOptions (
56 int argc,
57 char **argv,
58 BOOLEAN IsResponseFile);
59
60 static void
61 AslMergeOptionTokens (
62 char *InBuffer,
63 char *OutBuffer);
64
65 static int
66 AslDoResponseFile (
67 char *Filename);
68
69
70 #define ASL_TOKEN_SEPARATORS " \t\n"
71 #define ASL_SUPPORTED_OPTIONS "@:b|c|d^D:e:f^gh^i|I:l^m:no|p:P^r:s|t|T+G^v^w|x:z"
72
73
74 /*******************************************************************************
75 *
76 * FUNCTION: AslCommandLine
77 *
78 * PARAMETERS: argc/argv
79 *
80 * RETURN: Last argv index
81 *
82 * DESCRIPTION: Command line processing
83 *
84 ******************************************************************************/
85
86 int
87 AslCommandLine (
88 int argc,
89 char **argv)
90 {
91 int BadCommandLine = 0;
92 ACPI_STATUS Status;
93
94
95 /* Minimum command line contains at least the command and an input file */
96
97 if (argc < 2)
98 {
99 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
100 Usage ();
101 exit (1);
102 }
103
104 /* Process all command line options */
105
106 BadCommandLine = AslDoOptions (argc, argv, FALSE);
107
108 if (Gbl_DoTemplates)
109 {
110 Status = DtCreateTemplates (Gbl_TemplateSignature);
111 if (ACPI_FAILURE (Status))
112 {
113 exit (-1);
114 }
115 exit (1);
116 }
117
118 /* Next parameter must be the input filename */
119
120 if (!argv[AcpiGbl_Optind] &&
121 !Gbl_DisasmFlag)
122 {
123 printf ("Missing input filename\n");
124 BadCommandLine = TRUE;
125 }
126
127 if (Gbl_DoSignon)
128 {
129 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
130 if (Gbl_IgnoreErrors)
131 {
132 printf ("Ignoring all errors, forcing AML file generation\n\n");
133 }
134 }
135
136 if (BadCommandLine)
137 {
138 printf ("Use -h option for help information\n");
139 exit (1);
140 }
141
142 return (AcpiGbl_Optind);
143 }
144
145
146 /*******************************************************************************
147 *
148 * FUNCTION: AslDoOptions
149 *
150 * PARAMETERS: argc/argv - Standard argc/argv
151 * IsResponseFile - TRUE if executing a response file.
152 *
153 * RETURN: Status
154 *
155 * DESCRIPTION: Command line option processing
156 *
157 ******************************************************************************/
158
159 static int
160 AslDoOptions (
161 int argc,
162 char **argv,
163 BOOLEAN IsResponseFile)
164 {
165 ACPI_STATUS Status;
166 UINT32 j;
167
168
169 /* Get the command line options */
170
171 while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
172 {
173 case '@': /* Begin a response file */
174
175 if (IsResponseFile)
176 {
177 printf ("Nested command files are not supported\n");
178 return (-1);
179 }
180
181 if (AslDoResponseFile (AcpiGbl_Optarg))
182 {
183 return (-1);
184 }
185 break;
186
187 case 'b': /* Debug options */
188
189 switch (AcpiGbl_Optarg[0])
190 {
191 case 'f':
192
193 AslCompilerdebug = 1; /* same as yydebug */
194 DtParserdebug = 1;
195 PrParserdebug = 1;
196 Gbl_DebugFlag = TRUE;
197 Gbl_KeepPreprocessorTempFile = TRUE;
198 break;
199
200 case 'p': /* Prune ASL parse tree */
201
202 /* Get the required argument */
203
204 if (AcpiGetoptArgument (argc, argv))
205 {
206 return (-1);
207 }
208
209 Gbl_PruneParseTree = TRUE;
210 Gbl_PruneDepth = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
211 break;
212
213 case 's':
214
215 Gbl_DebugFlag = TRUE;
216 break;
217
218 case 't':
219
220 /* Get the required argument */
221
222 if (AcpiGetoptArgument (argc, argv))
223 {
224 return (-1);
225 }
226
227 Gbl_PruneType = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
228 break;
229
230 default:
231
232 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
233 return (-1);
234 }
235
236 break;
237
238 case 'c':
239
240 switch (AcpiGbl_Optarg[0])
241 {
242 case 'r':
243
244 Gbl_NoResourceChecking = TRUE;
245 break;
246
247 default:
248
249 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
250 return (-1);
251 }
252 break;
253
254 case 'd': /* Disassembler */
255
256 switch (AcpiGbl_Optarg[0])
257 {
258 case '^':
259
260 Gbl_DoCompile = FALSE;
261 break;
262
263 case 'a':
264
265 Gbl_DoCompile = FALSE;
266 Gbl_DisassembleAll = TRUE;
267 break;
268
269 case 'b': /* Do not convert buffers to resource descriptors */
270
271 AcpiGbl_NoResourceDisassembly = TRUE;
272 break;
273
274 case 'c':
275
276 break;
277
278 case 'f':
279
280 AcpiGbl_ForceAmlDisassembly = TRUE;
281 break;
282
283 case 'l': /* Use legacy ASL code (not ASL+) for disassembly */
284
285 Gbl_DoCompile = FALSE;
286 AcpiGbl_CstyleDisassembly = FALSE;
287 break;
288
289 case 'v':
290
291 AcpiGbl_DbOpt_Verbose = TRUE;
292 break;
293
294 default:
295
296 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
297 return (-1);
298 }
299
300 Gbl_DisasmFlag = TRUE;
301 break;
302
303 case 'D': /* Define a symbol */
304
305 PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
306 break;
307
308 case 'e': /* External files for disassembler */
309
310 /* Get entire list of external files */
311
312 AcpiGbl_Optind--;
313 argv[AcpiGbl_Optind] = AcpiGbl_Optarg;
314
315 while (argv[AcpiGbl_Optind] &&
316 (argv[AcpiGbl_Optind][0] != '-'))
317 {
318 Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
319 if (ACPI_FAILURE (Status))
320 {
321 printf ("Could not add %s to external list\n", argv[AcpiGbl_Optind]);
322 return (-1);
323 }
324
325 AcpiGbl_Optind++;
326 }
327 break;
328
329 case 'f':
330
331 switch (AcpiGbl_Optarg[0])
332 {
333 case '^': /* Ignore errors and force creation of aml file */
334
335 Gbl_IgnoreErrors = TRUE;
336 break;
337
338 case 'e': /* Disassembler: Get external declaration file */
339
340 if (AcpiGetoptArgument (argc, argv))
341 {
342 return (-1);
343 }
344
345 Gbl_ExternalRefFilename = AcpiGbl_Optarg;
346 break;
347
348 default:
349
350 printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
351 return (-1);
352 }
353 break;
354
355 case 'G':
356
357 Gbl_CompileGeneric = TRUE;
358 break;
359
360 case 'g': /* Get all ACPI tables */
361
362 printf ("-g option is deprecated, use acpidump utility instead\n");
363 exit (1);
364
365 case 'h':
366
367 switch (AcpiGbl_Optarg[0])
368 {
369 case '^':
370
371 Usage ();
372 exit (0);
373
374 case 'c':
375
376 UtDisplayConstantOpcodes ();
377 exit (0);
378
379 case 'f':
380
381 AslFilenameHelp ();
382 exit (0);
383
384 case 'r':
385
386 /* reserved names */
387
388 ApDisplayReservedNames ();
389 exit (0);
390
391 case 't':
392
393 UtDisplaySupportedTables ();
394 exit (0);
395
396 default:
397
398 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
399 return (-1);
400 }
401
402 case 'I': /* Add an include file search directory */
403
404 FlAddIncludeDirectory (AcpiGbl_Optarg);
405 break;
406
407 case 'i': /* Output AML as an include file */
408
409 switch (AcpiGbl_Optarg[0])
410 {
411 case 'a':
412
413 /* Produce assembly code include file */
414
415 Gbl_AsmIncludeOutputFlag = TRUE;
416 break;
417
418 case 'c':
419
420 /* Produce C include file */
421
422 Gbl_C_IncludeOutputFlag = TRUE;
423 break;
424
425 case 'n':
426
427 /* Compiler/Disassembler: Ignore the NOOP operator */
428
429 AcpiGbl_IgnoreNoopOperator = TRUE;
430 break;
431
432 default:
433
434 printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
435 return (-1);
436 }
437 break;
438
439 case 'l': /* Listing files */
440
441 switch (AcpiGbl_Optarg[0])
442 {
443 case '^':
444
445 /* Produce listing file (Mixed source/aml) */
446
447 Gbl_ListingFlag = TRUE;
448 break;
449
450 case 'i':
451
452 /* Produce preprocessor output file */
453
454 Gbl_PreprocessorOutputFlag = TRUE;
455 break;
456
457 case 'm':
458
459 /* Produce hardware map summary file */
460
461 Gbl_MapfileFlag = TRUE;
462 break;
463
464 case 'n':
465
466 /* Produce namespace file */
467
468 Gbl_NsOutputFlag = TRUE;
469 break;
470
471 case 's':
472
473 /* Produce combined source file */
474
475 Gbl_SourceOutputFlag = TRUE;
476 break;
477
478 default:
479
480 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
481 return (-1);
482 }
483 break;
484
485 case 'm': /* Set line buffer size */
486
487 Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
488 if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
489 {
490 Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
491 }
492 printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
493 break;
494
495 case 'n': /* Parse only */
496
497 Gbl_ParseOnlyFlag = TRUE;
498 break;
499
500 case 'o': /* Control compiler AML optimizations */
501
502 switch (AcpiGbl_Optarg[0])
503 {
504 case 'a':
505
506 /* Disable all optimizations */
507
508 Gbl_FoldConstants = FALSE;
509 Gbl_IntegerOptimizationFlag = FALSE;
510 Gbl_ReferenceOptimizationFlag = FALSE;
511 break;
512
513 case 'f':
514
515 /* Disable folding on "normal" expressions */
516
517 Gbl_FoldConstants = FALSE;
518 break;
519
520 case 'i':
521
522 /* Disable integer optimization to constants */
523
524 Gbl_IntegerOptimizationFlag = FALSE;
525 break;
526
527 case 'n':
528
529 /* Disable named reference optimization */
530
531 Gbl_ReferenceOptimizationFlag = FALSE;
532 break;
533
534 case 't':
535
536 /* Display compile time(s) */
537
538 Gbl_CompileTimesFlag = TRUE;
539 break;
540
541 default:
542
543 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
544 return (-1);
545 }
546 break;
547
548 case 'P': /* Preprocessor options */
549
550 switch (AcpiGbl_Optarg[0])
551 {
552 case '^': /* Proprocess only, emit (.i) file */
553
554 Gbl_PreprocessOnly = TRUE;
555 Gbl_PreprocessorOutputFlag = TRUE;
556 break;
557
558 case 'n': /* Disable preprocessor */
559
560 Gbl_PreprocessFlag = FALSE;
561 break;
562
563 default:
564
565 printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
566 return (-1);
567 }
568 break;
569
570 case 'p': /* Override default AML output filename */
571
572 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
573 UtConvertBackslashes (Gbl_OutputFilenamePrefix);
574 Gbl_UseDefaultAmlFilename = FALSE;
575 break;
576
577 case 'r': /* Override revision found in table header */
578
579 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
580 break;
581
582 case 's': /* Create AML in a source code file */
583
584 switch (AcpiGbl_Optarg[0])
585 {
586 case 'a':
587
588 /* Produce assembly code output file */
589
590 Gbl_AsmOutputFlag = TRUE;
591 break;
592
593 case 'c':
594
595 /* Produce C hex output file */
596
597 Gbl_C_OutputFlag = TRUE;
598 break;
599
600 case 'o':
601
602 /* Produce AML offset table in C */
603
604 Gbl_C_OffsetTableFlag = TRUE;
605 break;
606
607 default:
608
609 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
610 return (-1);
611 }
612 break;
613
614 case 't': /* Produce hex table output file */
615
616 switch (AcpiGbl_Optarg[0])
617 {
618 case 'a':
619
620 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
621 break;
622
623 case 'c':
624
625 Gbl_HexOutputFlag = HEX_OUTPUT_C;
626 break;
627
628 case 's':
629
630 Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
631 break;
632
633 default:
634
635 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
636 return (-1);
637 }
638 break;
639
640 case 'T': /* Create a ACPI table template file */
641
642 Gbl_DoTemplates = TRUE;
643 Gbl_TemplateSignature = AcpiGbl_Optarg;
644 break;
645
646 case 'v': /* Version and verbosity settings */
647
648 switch (AcpiGbl_Optarg[0])
649 {
650 case '^':
651
652 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
653 exit (0);
654
655 case 'a':
656
657 /* Disable all error/warning/remark messages */
658
659 Gbl_NoErrors = TRUE;
660 break;
661
662 case 'e':
663
664 /* Disable all warning/remark messages (errors only) */
665
666 Gbl_DisplayRemarks = FALSE;
667 Gbl_DisplayWarnings = FALSE;
668 break;
669
670 case 'i':
671 /*
672 * Support for integrated development environment(s).
673 *
674 * 1) No compiler signon
675 * 2) Send stderr messages to stdout
676 * 3) Less verbose error messages (single line only for each)
677 * 4) Error/warning messages are formatted appropriately to
678 * be recognized by MS Visual Studio
679 */
680 Gbl_VerboseErrors = FALSE;
681 Gbl_DoSignon = FALSE;
682 Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
683 break;
684
685 case 'o':
686
687 Gbl_DisplayOptimizations = TRUE;
688 break;
689
690 case 'r':
691
692 Gbl_DisplayRemarks = FALSE;
693 break;
694
695 case 's':
696
697 Gbl_DoSignon = FALSE;
698 break;
699
700 case 't':
701
702 Gbl_VerboseTemplates = TRUE;
703 break;
704
705 case 'w':
706
707 /* Get the required argument */
708
709 if (AcpiGetoptArgument (argc, argv))
710 {
711 return (-1);
712 }
713
714 Status = AslDisableException (AcpiGbl_Optarg);
715 if (ACPI_FAILURE (Status))
716 {
717 return (-1);
718 }
719 break;
720
721 default:
722
723 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
724 return (-1);
725 }
726 break;
727
728 case 'w': /* Set warning levels */
729
730 switch (AcpiGbl_Optarg[0])
731 {
732 case '1':
733
734 Gbl_WarningLevel = ASL_WARNING;
735 break;
736
737 case '2':
738
739 Gbl_WarningLevel = ASL_WARNING2;
740 break;
741
742 case '3':
743
744 Gbl_WarningLevel = ASL_WARNING3;
745 break;
746
747 case 'e':
748
749 Gbl_WarningsAsErrors = TRUE;
750 break;
751
752 default:
753
754 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
755 return (-1);
756 }
757 break;
758
759 case 'x': /* Set debug print output level */
760
761 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
762 break;
763
764 case 'z':
765
766 Gbl_UseOriginalCompilerId = TRUE;
767 break;
768
769 default:
770
771 return (-1);
772 }
773
774 return (0);
775 }
776
777
778 /*******************************************************************************
779 *
780 * FUNCTION: AslMergeOptionTokens
781 *
782 * PARAMETERS: InBuffer - Input containing an option string
783 * OutBuffer - Merged output buffer
784 *
785 * RETURN: None
786 *
787 * DESCRIPTION: Remove all whitespace from an option string.
788 *
789 ******************************************************************************/
790
791 static void
792 AslMergeOptionTokens (
793 char *InBuffer,
794 char *OutBuffer)
795 {
796 char *Token;
797
798
799 *OutBuffer = 0;
800
801 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
802 while (Token)
803 {
804 strcat (OutBuffer, Token);
805 Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
806 }
807 }
808
809
810 /*******************************************************************************
811 *
812 * FUNCTION: AslDoResponseFile
813 *
814 * PARAMETERS: Filename - Name of the response file
815 *
816 * RETURN: Status
817 *
818 * DESCRIPTION: Open a response file and process all options within.
819 *
820 ******************************************************************************/
821
822 static int
823 AslDoResponseFile (
824 char *Filename)
825 {
826 char *argv = StringBuffer2;
827 FILE *ResponseFile;
828 int OptStatus = 0;
829 int Opterr;
830 int Optind;
831
832
833 ResponseFile = fopen (Filename, "r");
834 if (!ResponseFile)
835 {
836 printf ("Could not open command file %s, %s\n",
837 Filename, strerror (errno));
838 return (-1);
839 }
840
841 /* Must save the current GetOpt globals */
842
843 Opterr = AcpiGbl_Opterr;
844 Optind = AcpiGbl_Optind;
845
846 /*
847 * Process all lines in the response file. There must be one complete
848 * option per line
849 */
850 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
851 {
852 /* Compress all tokens, allowing us to use a single argv entry */
853
854 AslMergeOptionTokens (StringBuffer, StringBuffer2);
855
856 /* Process the option */
857
858 AcpiGbl_Opterr = 0;
859 AcpiGbl_Optind = 0;
860
861 OptStatus = AslDoOptions (1, &argv, TRUE);
862 if (OptStatus)
863 {
864 printf ("Invalid option in command file %s: %s\n",
865 Filename, StringBuffer);
866 break;
867 }
868 }
869
870 /* Restore the GetOpt globals */
871
872 AcpiGbl_Opterr = Opterr;
873 AcpiGbl_Optind = Optind;
874
875 fclose (ResponseFile);
876 return (OptStatus);
877 }
878