asloptions.c revision 1.1.1.2 1 /******************************************************************************
2 *
3 * Module Name: asloptions - compiler command line processing
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2014, 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 output 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 break;
197
198 case 't':
199
200 break;
201
202 default:
203
204 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
205 return (-1);
206 }
207
208 /* Produce debug output file */
209
210 Gbl_DebugFlag = TRUE;
211 break;
212
213 case 'c':
214
215 switch (AcpiGbl_Optarg[0])
216 {
217 case 'r':
218
219 Gbl_NoResourceChecking = TRUE;
220 break;
221
222 default:
223
224 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
225 return (-1);
226 }
227 break;
228
229 case 'd': /* Disassembler */
230
231 switch (AcpiGbl_Optarg[0])
232 {
233 case '^':
234
235 Gbl_DoCompile = FALSE;
236 break;
237
238 case 'a':
239
240 Gbl_DoCompile = FALSE;
241 Gbl_DisassembleAll = TRUE;
242 break;
243
244 case 'b': /* Do not convert buffers to resource descriptors */
245
246 AcpiGbl_NoResourceDisassembly = TRUE;
247 break;
248
249 case 'c':
250
251 break;
252
253 default:
254
255 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
256 return (-1);
257 }
258
259 Gbl_DisasmFlag = TRUE;
260 break;
261
262 case 'D': /* Define a symbol */
263
264 PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
265 break;
266
267 case 'e': /* External files for disassembler */
268
269 /* Get entire list of external files */
270
271 AcpiGbl_Optind--;
272 argv[AcpiGbl_Optind] = AcpiGbl_Optarg;
273
274 while (argv[AcpiGbl_Optind] &&
275 (argv[AcpiGbl_Optind][0] != '-'))
276 {
277 Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
278 if (ACPI_FAILURE (Status))
279 {
280 printf ("Could not add %s to external list\n", argv[AcpiGbl_Optind]);
281 return (-1);
282 }
283
284 AcpiGbl_Optind++;
285 }
286 break;
287
288 case 'f':
289
290 switch (AcpiGbl_Optarg[0])
291 {
292 case '^': /* Ignore errors and force creation of aml file */
293
294 Gbl_IgnoreErrors = TRUE;
295 break;
296
297 case 'e': /* Disassembler: Get external declaration file */
298
299 if (AcpiGetoptArgument (argc, argv))
300 {
301 return (-1);
302 }
303
304 Gbl_ExternalRefFilename = AcpiGbl_Optarg;
305 break;
306
307 default:
308
309 printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
310 return (-1);
311 }
312 break;
313
314 case 'G':
315
316 Gbl_CompileGeneric = TRUE;
317 break;
318
319 case 'g': /* Get all ACPI tables */
320
321 printf ("-g option is deprecated, use acpidump utility instead\n");
322 exit (1);
323
324 case 'h':
325
326 switch (AcpiGbl_Optarg[0])
327 {
328 case '^':
329
330 Usage ();
331 exit (0);
332
333 case 'c':
334
335 UtDisplayConstantOpcodes ();
336 exit (0);
337
338 case 'f':
339
340 AslFilenameHelp ();
341 exit (0);
342
343 case 'r':
344
345 /* reserved names */
346
347 ApDisplayReservedNames ();
348 exit (0);
349
350 case 't':
351
352 UtDisplaySupportedTables ();
353 exit (0);
354
355 default:
356
357 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
358 return (-1);
359 }
360
361 case 'I': /* Add an include file search directory */
362
363 FlAddIncludeDirectory (AcpiGbl_Optarg);
364 break;
365
366 case 'i': /* Output AML as an include file */
367
368 switch (AcpiGbl_Optarg[0])
369 {
370 case 'a':
371
372 /* Produce assembly code include file */
373
374 Gbl_AsmIncludeOutputFlag = TRUE;
375 break;
376
377 case 'c':
378
379 /* Produce C include file */
380
381 Gbl_C_IncludeOutputFlag = TRUE;
382 break;
383
384 case 'n':
385
386 /* Compiler/Disassembler: Ignore the NOOP operator */
387
388 AcpiGbl_IgnoreNoopOperator = TRUE;
389 break;
390
391 default:
392
393 printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
394 return (-1);
395 }
396 break;
397
398 case 'l': /* Listing files */
399
400 switch (AcpiGbl_Optarg[0])
401 {
402 case '^':
403
404 /* Produce listing file (Mixed source/aml) */
405
406 Gbl_ListingFlag = TRUE;
407 break;
408
409 case 'i':
410
411 /* Produce preprocessor output file */
412
413 Gbl_PreprocessorOutputFlag = TRUE;
414 break;
415
416 case 'm':
417
418 /* Produce hardware map summary file */
419
420 Gbl_MapfileFlag = TRUE;
421 break;
422
423 case 'n':
424
425 /* Produce namespace file */
426
427 Gbl_NsOutputFlag = TRUE;
428 break;
429
430 case 's':
431
432 /* Produce combined source file */
433
434 Gbl_SourceOutputFlag = TRUE;
435 break;
436
437 default:
438
439 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
440 return (-1);
441 }
442 break;
443
444 case 'm': /* Set line buffer size */
445
446 Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
447 if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
448 {
449 Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
450 }
451 printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
452 break;
453
454 case 'n': /* Parse only */
455
456 Gbl_ParseOnlyFlag = TRUE;
457 break;
458
459 case 'o': /* Control compiler AML optimizations */
460
461 switch (AcpiGbl_Optarg[0])
462 {
463 case 'a':
464
465 /* Disable all optimizations */
466
467 Gbl_FoldConstants = FALSE;
468 Gbl_IntegerOptimizationFlag = FALSE;
469 Gbl_ReferenceOptimizationFlag = FALSE;
470 break;
471
472 case 'f':
473
474 /* Disable folding on "normal" expressions */
475
476 Gbl_FoldConstants = FALSE;
477 break;
478
479 case 'i':
480
481 /* Disable integer optimization to constants */
482
483 Gbl_IntegerOptimizationFlag = FALSE;
484 break;
485
486 case 'n':
487
488 /* Disable named reference optimization */
489
490 Gbl_ReferenceOptimizationFlag = FALSE;
491 break;
492
493 case 't':
494
495 /* Display compile time(s) */
496
497 Gbl_CompileTimesFlag = TRUE;
498 break;
499
500 default:
501
502 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
503 return (-1);
504 }
505 break;
506
507 case 'P': /* Preprocessor options */
508
509 switch (AcpiGbl_Optarg[0])
510 {
511 case '^': /* Proprocess only, emit (.i) file */
512
513 Gbl_PreprocessOnly = TRUE;
514 Gbl_PreprocessorOutputFlag = TRUE;
515 break;
516
517 case 'n': /* Disable preprocessor */
518
519 Gbl_PreprocessFlag = FALSE;
520 break;
521
522 default:
523
524 printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
525 return (-1);
526 }
527 break;
528
529 case 'p': /* Override default AML output filename */
530
531 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
532 UtConvertBackslashes (Gbl_OutputFilenamePrefix);
533
534 Gbl_UseDefaultAmlFilename = FALSE;
535 break;
536
537 case 'r': /* Override revision found in table header */
538
539 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
540 break;
541
542 case 's': /* Create AML in a source code file */
543
544 switch (AcpiGbl_Optarg[0])
545 {
546 case 'a':
547
548 /* Produce assembly code output file */
549
550 Gbl_AsmOutputFlag = TRUE;
551 break;
552
553 case 'c':
554
555 /* Produce C hex output file */
556
557 Gbl_C_OutputFlag = TRUE;
558 break;
559
560 case 'o':
561
562 /* Produce AML offset table in C */
563
564 Gbl_C_OffsetTableFlag = TRUE;
565 break;
566
567 default:
568
569 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
570 return (-1);
571 }
572 break;
573
574 case 't': /* Produce hex table output file */
575
576 switch (AcpiGbl_Optarg[0])
577 {
578 case 'a':
579
580 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
581 break;
582
583 case 'c':
584
585 Gbl_HexOutputFlag = HEX_OUTPUT_C;
586 break;
587
588 case 's':
589
590 Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
591 break;
592
593 default:
594
595 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
596 return (-1);
597 }
598 break;
599
600 case 'T': /* Create a ACPI table template file */
601
602 Gbl_DoTemplates = TRUE;
603 Gbl_TemplateSignature = AcpiGbl_Optarg;
604 break;
605
606 case 'v': /* Version and verbosity settings */
607
608 switch (AcpiGbl_Optarg[0])
609 {
610 case '^':
611
612 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
613 exit (0);
614
615 case 'a':
616
617 /* Disable all error/warning/remark messages */
618
619 Gbl_NoErrors = TRUE;
620 break;
621
622 case 'e':
623
624 /* Disable all warning/remark messages (errors only) */
625
626 Gbl_DisplayRemarks = FALSE;
627 Gbl_DisplayWarnings = FALSE;
628 break;
629
630 case 'i':
631 /*
632 * Support for integrated development environment(s).
633 *
634 * 1) No compiler signon
635 * 2) Send stderr messages to stdout
636 * 3) Less verbose error messages (single line only for each)
637 * 4) Error/warning messages are formatted appropriately to
638 * be recognized by MS Visual Studio
639 */
640 Gbl_VerboseErrors = FALSE;
641 Gbl_DoSignon = FALSE;
642 Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
643 break;
644
645 case 'o':
646
647 Gbl_DisplayOptimizations = TRUE;
648 break;
649
650 case 'r':
651
652 Gbl_DisplayRemarks = FALSE;
653 break;
654
655 case 's':
656
657 Gbl_DoSignon = FALSE;
658 break;
659
660 case 't':
661
662 Gbl_VerboseTemplates = TRUE;
663 break;
664
665 case 'w':
666
667 /* Get the required argument */
668
669 if (AcpiGetoptArgument (argc, argv))
670 {
671 return (-1);
672 }
673
674 Status = AslDisableException (AcpiGbl_Optarg);
675 if (ACPI_FAILURE (Status))
676 {
677 return (-1);
678 }
679 break;
680
681 default:
682
683 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
684 return (-1);
685 }
686 break;
687
688 case 'w': /* Set warning levels */
689
690 switch (AcpiGbl_Optarg[0])
691 {
692 case '1':
693
694 Gbl_WarningLevel = ASL_WARNING;
695 break;
696
697 case '2':
698
699 Gbl_WarningLevel = ASL_WARNING2;
700 break;
701
702 case '3':
703
704 Gbl_WarningLevel = ASL_WARNING3;
705 break;
706
707 case 'e':
708
709 Gbl_WarningsAsErrors = TRUE;
710 break;
711
712 default:
713
714 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
715 return (-1);
716 }
717 break;
718
719 case 'x': /* Set debug print output level */
720
721 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
722 break;
723
724 case 'z':
725
726 Gbl_UseOriginalCompilerId = TRUE;
727 break;
728
729 default:
730
731 return (-1);
732 }
733
734 return (0);
735 }
736
737
738 /*******************************************************************************
739 *
740 * FUNCTION: AslMergeOptionTokens
741 *
742 * PARAMETERS: InBuffer - Input containing an option string
743 * OutBuffer - Merged output buffer
744 *
745 * RETURN: None
746 *
747 * DESCRIPTION: Remove all whitespace from an option string.
748 *
749 ******************************************************************************/
750
751 static void
752 AslMergeOptionTokens (
753 char *InBuffer,
754 char *OutBuffer)
755 {
756 char *Token;
757
758
759 *OutBuffer = 0;
760
761 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
762 while (Token)
763 {
764 strcat (OutBuffer, Token);
765 Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
766 }
767 }
768
769
770 /*******************************************************************************
771 *
772 * FUNCTION: AslDoResponseFile
773 *
774 * PARAMETERS: Filename - Name of the response file
775 *
776 * RETURN: Status
777 *
778 * DESCRIPTION: Open a response file and process all options within.
779 *
780 ******************************************************************************/
781
782 static int
783 AslDoResponseFile (
784 char *Filename)
785 {
786 char *argv = StringBuffer2;
787 FILE *ResponseFile;
788 int OptStatus = 0;
789 int Opterr;
790 int Optind;
791
792
793 ResponseFile = fopen (Filename, "r");
794 if (!ResponseFile)
795 {
796 printf ("Could not open command file %s, %s\n",
797 Filename, strerror (errno));
798 return (-1);
799 }
800
801 /* Must save the current GetOpt globals */
802
803 Opterr = AcpiGbl_Opterr;
804 Optind = AcpiGbl_Optind;
805
806 /*
807 * Process all lines in the response file. There must be one complete
808 * option per line
809 */
810 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
811 {
812 /* Compress all tokens, allowing us to use a single argv entry */
813
814 AslMergeOptionTokens (StringBuffer, StringBuffer2);
815
816 /* Process the option */
817
818 AcpiGbl_Opterr = 0;
819 AcpiGbl_Optind = 0;
820
821 OptStatus = AslDoOptions (1, &argv, TRUE);
822 if (OptStatus)
823 {
824 printf ("Invalid option in command file %s: %s\n",
825 Filename, StringBuffer);
826 break;
827 }
828 }
829
830 /* Restore the GetOpt globals */
831
832 AcpiGbl_Opterr = Opterr;
833 AcpiGbl_Optind = Optind;
834
835 fclose (ResponseFile);
836 return (OptStatus);
837 }
838