Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / compiler / asloptions.c
blob00e30004e9219be54f15303c4a6bffe7293d9541
1 /******************************************************************************
3 * Module Name: asloptions - compiler command line processing
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include "aslcompiler.h"
45 #include "acapps.h"
46 #include "acdisasm.h"
48 #define _COMPONENT ACPI_COMPILER
49 ACPI_MODULE_NAME ("asloption")
52 /* Local prototypes */
54 static int
55 AslDoOptions (
56 int argc,
57 char **argv,
58 BOOLEAN IsResponseFile);
60 static void
61 AslMergeOptionTokens (
62 char *InBuffer,
63 char *OutBuffer);
65 static int
66 AslDoResponseFile (
67 char *Filename);
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"
74 /*******************************************************************************
76 * FUNCTION: AslCommandLine
78 * PARAMETERS: argc/argv
80 * RETURN: Last argv index
82 * DESCRIPTION: Command line processing
84 ******************************************************************************/
86 int
87 AslCommandLine (
88 int argc,
89 char **argv)
91 int BadCommandLine = 0;
92 ACPI_STATUS Status;
95 /* Minimum command line contains at least the command and an input file */
97 if (argc < 2)
99 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
100 Usage ();
101 exit (1);
104 /* Process all command line options */
106 BadCommandLine = AslDoOptions (argc, argv, FALSE);
108 if (Gbl_DoTemplates)
110 Status = DtCreateTemplates (Gbl_TemplateSignature);
111 if (ACPI_FAILURE (Status))
113 exit (-1);
115 exit (1);
118 /* Next parameter must be the input filename */
120 if (!argv[AcpiGbl_Optind] &&
121 !Gbl_DisasmFlag &&
122 !Gbl_GetAllTables)
124 printf ("Missing input filename\n");
125 BadCommandLine = TRUE;
128 if (Gbl_DoSignon)
130 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
131 if (Gbl_IgnoreErrors)
133 printf ("Ignoring all errors, forcing AML file generation\n\n");
137 if (BadCommandLine)
139 printf ("Use -h option for help information\n");
140 exit (1);
143 return (AcpiGbl_Optind);
147 /*******************************************************************************
149 * FUNCTION: AslDoOptions
151 * PARAMETERS: argc/argv - Standard argc/argv
152 * IsResponseFile - TRUE if executing a response file.
154 * RETURN: Status
156 * DESCRIPTION: Command line option processing
158 ******************************************************************************/
160 static int
161 AslDoOptions (
162 int argc,
163 char **argv,
164 BOOLEAN IsResponseFile)
166 ACPI_STATUS Status;
167 UINT32 j;
170 /* Get the command line options */
172 while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
174 case '@': /* Begin a response file */
176 if (IsResponseFile)
178 printf ("Nested command files are not supported\n");
179 return (-1);
182 if (AslDoResponseFile (AcpiGbl_Optarg))
184 return (-1);
186 break;
188 case 'b': /* Debug output options */
190 switch (AcpiGbl_Optarg[0])
192 case 'f':
194 AslCompilerdebug = 1; /* same as yydebug */
195 DtParserdebug = 1;
196 PrParserdebug = 1;
197 break;
199 case 't':
201 break;
203 default:
205 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
206 return (-1);
209 /* Produce debug output file */
211 Gbl_DebugFlag = TRUE;
212 break;
214 case 'c':
216 switch (AcpiGbl_Optarg[0])
218 case 'r':
220 Gbl_NoResourceChecking = TRUE;
221 break;
223 default:
225 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
226 return (-1);
228 break;
230 case 'd': /* Disassembler */
232 switch (AcpiGbl_Optarg[0])
234 case '^':
236 Gbl_DoCompile = FALSE;
237 break;
239 case 'a':
241 Gbl_DoCompile = FALSE;
242 Gbl_DisassembleAll = TRUE;
243 break;
245 case 'b': /* Do not convert buffers to resource descriptors */
247 AcpiGbl_NoResourceDisassembly = TRUE;
248 break;
250 case 'c':
252 break;
254 default:
256 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
257 return (-1);
260 Gbl_DisasmFlag = TRUE;
261 break;
263 case 'D': /* Define a symbol */
265 PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
266 break;
268 case 'e': /* External files for disassembler */
270 /* Get entire list of external files */
272 AcpiGbl_Optind--;
274 while (argv[AcpiGbl_Optind] &&
275 (argv[AcpiGbl_Optind][0] != '-'))
277 Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
278 if (ACPI_FAILURE (Status))
280 printf ("Could not add %s to external list\n", argv[AcpiGbl_Optind]);
281 return (-1);
284 AcpiGbl_Optind++;
286 break;
288 case 'f':
290 switch (AcpiGbl_Optarg[0])
292 case '^': /* Ignore errors and force creation of aml file */
294 Gbl_IgnoreErrors = TRUE;
295 break;
297 case 'e': /* Disassembler: Get external declaration file */
299 if (AcpiGetoptArgument (argc, argv))
301 return (-1);
304 Gbl_ExternalRefFilename = AcpiGbl_Optarg;
305 break;
307 default:
309 printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
310 return (-1);
312 break;
314 case 'G':
316 Gbl_CompileGeneric = TRUE;
317 break;
319 case 'g': /* Get all ACPI tables */
321 Gbl_GetAllTables = TRUE;
322 Gbl_DoCompile = FALSE;
323 break;
325 case 'h':
327 switch (AcpiGbl_Optarg[0])
329 case '^':
331 Usage ();
332 exit (0);
334 case 'c':
336 UtDisplayConstantOpcodes ();
337 exit (0);
339 case 'f':
341 AslFilenameHelp ();
342 exit (0);
344 case 'r':
346 /* reserved names */
348 ApDisplayReservedNames ();
349 exit (0);
351 case 't':
353 UtDisplaySupportedTables ();
354 exit (0);
356 default:
358 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
359 return (-1);
362 case 'I': /* Add an include file search directory */
364 FlAddIncludeDirectory (AcpiGbl_Optarg);
365 break;
367 case 'i': /* Output AML as an include file */
369 switch (AcpiGbl_Optarg[0])
371 case 'a':
373 /* Produce assembly code include file */
375 Gbl_AsmIncludeOutputFlag = TRUE;
376 break;
378 case 'c':
380 /* Produce C include file */
382 Gbl_C_IncludeOutputFlag = TRUE;
383 break;
385 case 'n':
387 /* Compiler/Disassembler: Ignore the NOOP operator */
389 AcpiGbl_IgnoreNoopOperator = TRUE;
390 break;
392 default:
394 printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
395 return (-1);
397 break;
399 case 'l': /* Listing files */
401 switch (AcpiGbl_Optarg[0])
403 case '^':
405 /* Produce listing file (Mixed source/aml) */
407 Gbl_ListingFlag = TRUE;
408 break;
410 case 'i':
412 /* Produce preprocessor output file */
414 Gbl_PreprocessorOutputFlag = TRUE;
415 break;
417 case 'n':
419 /* Produce namespace file */
421 Gbl_NsOutputFlag = TRUE;
422 break;
424 case 's':
426 /* Produce combined source file */
428 Gbl_SourceOutputFlag = TRUE;
429 break;
431 default:
433 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
434 return (-1);
436 break;
438 case 'm': /* Set line buffer size */
440 Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
441 if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
443 Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
445 printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
446 break;
448 case 'n': /* Parse only */
450 Gbl_ParseOnlyFlag = TRUE;
451 break;
453 case 'o': /* Control compiler AML optimizations */
455 switch (AcpiGbl_Optarg[0])
457 case 'a':
459 /* Disable all optimizations */
461 Gbl_FoldConstants = FALSE;
462 Gbl_IntegerOptimizationFlag = FALSE;
463 Gbl_ReferenceOptimizationFlag = FALSE;
464 break;
466 case 'f':
468 /* Disable folding on "normal" expressions */
470 Gbl_FoldConstants = FALSE;
471 break;
473 case 'i':
475 /* Disable integer optimization to constants */
477 Gbl_IntegerOptimizationFlag = FALSE;
478 break;
480 case 'n':
482 /* Disable named reference optimization */
484 Gbl_ReferenceOptimizationFlag = FALSE;
485 break;
487 case 't':
489 /* Display compile time(s) */
491 Gbl_CompileTimesFlag = TRUE;
492 break;
494 default:
496 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
497 return (-1);
499 break;
501 case 'P': /* Preprocessor options */
503 switch (AcpiGbl_Optarg[0])
505 case '^': /* Proprocess only, emit (.i) file */
507 Gbl_PreprocessOnly = TRUE;
508 Gbl_PreprocessorOutputFlag = TRUE;
509 break;
511 case 'n': /* Disable preprocessor */
513 Gbl_PreprocessFlag = FALSE;
514 break;
516 default:
518 printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
519 return (-1);
521 break;
523 case 'p': /* Override default AML output filename */
525 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
526 Gbl_UseDefaultAmlFilename = FALSE;
527 break;
529 case 'r': /* Override revision found in table header */
531 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
532 break;
534 case 's': /* Create AML in a source code file */
536 switch (AcpiGbl_Optarg[0])
538 case 'a':
540 /* Produce assembly code output file */
542 Gbl_AsmOutputFlag = TRUE;
543 break;
545 case 'c':
547 /* Produce C hex output file */
549 Gbl_C_OutputFlag = TRUE;
550 break;
552 case 'o':
554 /* Produce AML offset table in C */
556 Gbl_C_OffsetTableFlag = TRUE;
557 break;
559 default:
561 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
562 return (-1);
564 break;
566 case 't': /* Produce hex table output file */
568 switch (AcpiGbl_Optarg[0])
570 case 'a':
572 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
573 break;
575 case 'c':
577 Gbl_HexOutputFlag = HEX_OUTPUT_C;
578 break;
580 case 's':
582 Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
583 break;
585 default:
587 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
588 return (-1);
590 break;
592 case 'T': /* Create a ACPI table template file */
594 Gbl_DoTemplates = TRUE;
595 Gbl_TemplateSignature = AcpiGbl_Optarg;
596 break;
598 case 'v': /* Version and verbosity settings */
600 switch (AcpiGbl_Optarg[0])
602 case '^':
604 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
605 exit (0);
607 case 'a':
609 /* Disable All error/warning messages */
611 Gbl_NoErrors = TRUE;
612 break;
614 case 'i':
616 * Support for integrated development environment(s).
618 * 1) No compiler signon
619 * 2) Send stderr messages to stdout
620 * 3) Less verbose error messages (single line only for each)
621 * 4) Error/warning messages are formatted appropriately to
622 * be recognized by MS Visual Studio
624 Gbl_VerboseErrors = FALSE;
625 Gbl_DoSignon = FALSE;
626 Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
627 break;
629 case 'o':
631 Gbl_DisplayOptimizations = TRUE;
632 break;
634 case 'r':
636 Gbl_DisplayRemarks = FALSE;
637 break;
639 case 's':
641 Gbl_DoSignon = FALSE;
642 break;
644 case 't':
646 Gbl_VerboseTemplates = TRUE;
647 break;
649 case 'w':
651 /* Get the required argument */
653 if (AcpiGetoptArgument (argc, argv))
655 return (-1);
658 Status = AslDisableException (AcpiGbl_Optarg);
659 if (ACPI_FAILURE (Status))
661 return (-1);
663 break;
665 default:
667 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
668 return (-1);
670 break;
672 case 'w': /* Set warning levels */
674 switch (AcpiGbl_Optarg[0])
676 case '1':
678 Gbl_WarningLevel = ASL_WARNING;
679 break;
681 case '2':
683 Gbl_WarningLevel = ASL_WARNING2;
684 break;
686 case '3':
688 Gbl_WarningLevel = ASL_WARNING3;
689 break;
691 case 'e':
693 Gbl_WarningsAsErrors = TRUE;
694 break;
696 default:
698 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
699 return (-1);
701 break;
703 case 'x': /* Set debug print output level */
705 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
706 break;
708 case 'z':
710 Gbl_UseOriginalCompilerId = TRUE;
711 break;
713 default:
715 return (-1);
718 return (0);
722 /*******************************************************************************
724 * FUNCTION: AslMergeOptionTokens
726 * PARAMETERS: InBuffer - Input containing an option string
727 * OutBuffer - Merged output buffer
729 * RETURN: None
731 * DESCRIPTION: Remove all whitespace from an option string.
733 ******************************************************************************/
735 static void
736 AslMergeOptionTokens (
737 char *InBuffer,
738 char *OutBuffer)
740 char *Token;
743 *OutBuffer = 0;
745 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
746 while (Token)
748 strcat (OutBuffer, Token);
749 Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
754 /*******************************************************************************
756 * FUNCTION: AslDoResponseFile
758 * PARAMETERS: Filename - Name of the response file
760 * RETURN: Status
762 * DESCRIPTION: Open a response file and process all options within.
764 ******************************************************************************/
766 static int
767 AslDoResponseFile (
768 char *Filename)
770 char *argv = StringBuffer2;
771 FILE *ResponseFile;
772 int OptStatus = 0;
773 int Opterr;
774 int Optind;
777 ResponseFile = fopen (Filename, "r");
778 if (!ResponseFile)
780 printf ("Could not open command file %s, %s\n",
781 Filename, strerror (errno));
782 return (-1);
785 /* Must save the current GetOpt globals */
787 Opterr = AcpiGbl_Opterr;
788 Optind = AcpiGbl_Optind;
791 * Process all lines in the response file. There must be one complete
792 * option per line
794 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
796 /* Compress all tokens, allowing us to use a single argv entry */
798 AslMergeOptionTokens (StringBuffer, StringBuffer2);
800 /* Process the option */
802 AcpiGbl_Opterr = 0;
803 AcpiGbl_Optind = 0;
805 OptStatus = AslDoOptions (1, &argv, TRUE);
806 if (OptStatus)
808 printf ("Invalid option in command file %s: %s\n",
809 Filename, StringBuffer);
810 break;
814 /* Restore the GetOpt globals */
816 AcpiGbl_Opterr = Opterr;
817 AcpiGbl_Optind = Optind;
819 fclose (ResponseFile);
820 return (OptStatus);