1 /******************************************************************************
3 * Module Name: asloptions - compiler command line processing
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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 <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include <contrib/dev/acpica/include/acapps.h>
46 #include <contrib/dev/acpica/include/acdisasm.h>
48 #define _COMPONENT ACPI_COMPILER
49 ACPI_MODULE_NAME ("asloption")
52 /* Local prototypes */
58 BOOLEAN IsResponseFile);
61 AslMergeOptionTokens (
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 ******************************************************************************/
91 int BadCommandLine = 0;
95 /* Minimum command line contains at least the command and an input file */
99 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
104 /* Process all command line options */
106 BadCommandLine = AslDoOptions (argc, argv, FALSE);
110 Status = DtCreateTemplates (Gbl_TemplateSignature);
111 if (ACPI_FAILURE (Status))
118 /* Next parameter must be the input filename */
120 if (!argv[AcpiGbl_Optind] &&
123 printf ("Missing input filename\n");
124 BadCommandLine = TRUE;
129 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
130 if (Gbl_IgnoreErrors)
132 printf ("Ignoring all errors, forcing AML file generation\n\n");
138 printf ("Use -h option for help information\n");
142 return (AcpiGbl_Optind);
146 /*******************************************************************************
148 * FUNCTION: AslDoOptions
150 * PARAMETERS: argc/argv - Standard argc/argv
151 * IsResponseFile - TRUE if executing a response file.
155 * DESCRIPTION: Command line option processing
157 ******************************************************************************/
163 BOOLEAN IsResponseFile)
169 /* Get the command line options */
171 while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
173 case '@': /* Begin a response file */
177 printf ("Nested command files are not supported\n");
181 if (AslDoResponseFile (AcpiGbl_Optarg))
187 case 'b': /* Debug options */
189 switch (AcpiGbl_Optarg[0])
193 AslCompilerdebug = 1; /* same as yydebug */
196 Gbl_DebugFlag = TRUE;
199 case 'p': /* Prune ASL parse tree */
201 /* Get the required argument */
203 if (AcpiGetoptArgument (argc, argv))
208 Gbl_PruneParseTree = TRUE;
209 Gbl_PruneDepth = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
214 Gbl_DebugFlag = TRUE;
219 /* Get the required argument */
221 if (AcpiGetoptArgument (argc, argv))
226 Gbl_PruneType = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
231 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
239 switch (AcpiGbl_Optarg[0])
243 Gbl_NoResourceChecking = TRUE;
248 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
253 case 'd': /* Disassembler */
255 switch (AcpiGbl_Optarg[0])
259 Gbl_DoCompile = FALSE;
264 Gbl_DoCompile = FALSE;
265 Gbl_DisassembleAll = TRUE;
268 case 'b': /* Do not convert buffers to resource descriptors */
270 AcpiGbl_NoResourceDisassembly = TRUE;
279 AcpiGbl_ForceAmlDisassembly = TRUE;
282 case 'l': /* Use legacy ASL code (not ASL+) for disassembly */
284 Gbl_DoCompile = FALSE;
285 AcpiGbl_CstyleDisassembly = FALSE;
290 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
294 Gbl_DisasmFlag = TRUE;
297 case 'D': /* Define a symbol */
299 PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
302 case 'e': /* External files for disassembler */
304 /* Get entire list of external files */
307 argv[AcpiGbl_Optind] = AcpiGbl_Optarg;
309 while (argv[AcpiGbl_Optind] &&
310 (argv[AcpiGbl_Optind][0] != '-'))
312 Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
313 if (ACPI_FAILURE (Status))
315 printf ("Could not add %s to external list\n", argv[AcpiGbl_Optind]);
325 switch (AcpiGbl_Optarg[0])
327 case '^': /* Ignore errors and force creation of aml file */
329 Gbl_IgnoreErrors = TRUE;
332 case 'e': /* Disassembler: Get external declaration file */
334 if (AcpiGetoptArgument (argc, argv))
339 Gbl_ExternalRefFilename = AcpiGbl_Optarg;
344 printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
351 Gbl_CompileGeneric = TRUE;
354 case 'g': /* Get all ACPI tables */
356 printf ("-g option is deprecated, use acpidump utility instead\n");
361 switch (AcpiGbl_Optarg[0])
370 UtDisplayConstantOpcodes ();
382 ApDisplayReservedNames ();
387 UtDisplaySupportedTables ();
392 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
396 case 'I': /* Add an include file search directory */
398 FlAddIncludeDirectory (AcpiGbl_Optarg);
401 case 'i': /* Output AML as an include file */
403 switch (AcpiGbl_Optarg[0])
407 /* Produce assembly code include file */
409 Gbl_AsmIncludeOutputFlag = TRUE;
414 /* Produce C include file */
416 Gbl_C_IncludeOutputFlag = TRUE;
421 /* Compiler/Disassembler: Ignore the NOOP operator */
423 AcpiGbl_IgnoreNoopOperator = TRUE;
428 printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
433 case 'l': /* Listing files */
435 switch (AcpiGbl_Optarg[0])
439 /* Produce listing file (Mixed source/aml) */
441 Gbl_ListingFlag = TRUE;
446 /* Produce preprocessor output file */
448 Gbl_PreprocessorOutputFlag = TRUE;
453 /* Produce hardware map summary file */
455 Gbl_MapfileFlag = TRUE;
460 /* Produce namespace file */
462 Gbl_NsOutputFlag = TRUE;
467 /* Produce combined source file */
469 Gbl_SourceOutputFlag = TRUE;
474 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
479 case 'm': /* Set line buffer size */
481 Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
482 if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
484 Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
486 printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
489 case 'n': /* Parse only */
491 Gbl_ParseOnlyFlag = TRUE;
494 case 'o': /* Control compiler AML optimizations */
496 switch (AcpiGbl_Optarg[0])
500 /* Disable all optimizations */
502 Gbl_FoldConstants = FALSE;
503 Gbl_IntegerOptimizationFlag = FALSE;
504 Gbl_ReferenceOptimizationFlag = FALSE;
509 /* Disable folding on "normal" expressions */
511 Gbl_FoldConstants = FALSE;
516 /* Disable integer optimization to constants */
518 Gbl_IntegerOptimizationFlag = FALSE;
523 /* Disable named reference optimization */
525 Gbl_ReferenceOptimizationFlag = FALSE;
530 /* Display compile time(s) */
532 Gbl_CompileTimesFlag = TRUE;
537 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
542 case 'P': /* Preprocessor options */
544 switch (AcpiGbl_Optarg[0])
546 case '^': /* Proprocess only, emit (.i) file */
548 Gbl_PreprocessOnly = TRUE;
549 Gbl_PreprocessorOutputFlag = TRUE;
552 case 'n': /* Disable preprocessor */
554 Gbl_PreprocessFlag = FALSE;
559 printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
564 case 'p': /* Override default AML output filename */
566 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
567 UtConvertBackslashes (Gbl_OutputFilenamePrefix);
568 Gbl_UseDefaultAmlFilename = FALSE;
571 case 'r': /* Override revision found in table header */
573 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
576 case 's': /* Create AML in a source code file */
578 switch (AcpiGbl_Optarg[0])
582 /* Produce assembly code output file */
584 Gbl_AsmOutputFlag = TRUE;
589 /* Produce C hex output file */
591 Gbl_C_OutputFlag = TRUE;
596 /* Produce AML offset table in C */
598 Gbl_C_OffsetTableFlag = TRUE;
603 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
608 case 't': /* Produce hex table output file */
610 switch (AcpiGbl_Optarg[0])
614 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
619 Gbl_HexOutputFlag = HEX_OUTPUT_C;
624 Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
629 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
634 case 'T': /* Create a ACPI table template file */
636 Gbl_DoTemplates = TRUE;
637 Gbl_TemplateSignature = AcpiGbl_Optarg;
640 case 'v': /* Version and verbosity settings */
642 switch (AcpiGbl_Optarg[0])
646 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
651 /* Disable all error/warning/remark messages */
658 /* Disable all warning/remark messages (errors only) */
660 Gbl_DisplayRemarks = FALSE;
661 Gbl_DisplayWarnings = FALSE;
666 * Support for integrated development environment(s).
668 * 1) No compiler signon
669 * 2) Send stderr messages to stdout
670 * 3) Less verbose error messages (single line only for each)
671 * 4) Error/warning messages are formatted appropriately to
672 * be recognized by MS Visual Studio
674 Gbl_VerboseErrors = FALSE;
675 Gbl_DoSignon = FALSE;
676 Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
681 Gbl_DisplayOptimizations = TRUE;
686 Gbl_DisplayRemarks = FALSE;
691 Gbl_DoSignon = FALSE;
696 Gbl_VerboseTemplates = TRUE;
701 /* Get the required argument */
703 if (AcpiGetoptArgument (argc, argv))
708 Status = AslDisableException (AcpiGbl_Optarg);
709 if (ACPI_FAILURE (Status))
717 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
722 case 'w': /* Set warning levels */
724 switch (AcpiGbl_Optarg[0])
728 Gbl_WarningLevel = ASL_WARNING;
733 Gbl_WarningLevel = ASL_WARNING2;
738 Gbl_WarningLevel = ASL_WARNING3;
743 Gbl_WarningsAsErrors = TRUE;
748 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
753 case 'x': /* Set debug print output level */
755 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
760 Gbl_UseOriginalCompilerId = TRUE;
772 /*******************************************************************************
774 * FUNCTION: AslMergeOptionTokens
776 * PARAMETERS: InBuffer - Input containing an option string
777 * OutBuffer - Merged output buffer
781 * DESCRIPTION: Remove all whitespace from an option string.
783 ******************************************************************************/
786 AslMergeOptionTokens (
795 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
798 strcat (OutBuffer, Token);
799 Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
804 /*******************************************************************************
806 * FUNCTION: AslDoResponseFile
808 * PARAMETERS: Filename - Name of the response file
812 * DESCRIPTION: Open a response file and process all options within.
814 ******************************************************************************/
820 char *argv = StringBuffer2;
827 ResponseFile = fopen (Filename, "r");
830 printf ("Could not open command file %s, %s\n",
831 Filename, strerror (errno));
835 /* Must save the current GetOpt globals */
837 Opterr = AcpiGbl_Opterr;
838 Optind = AcpiGbl_Optind;
841 * Process all lines in the response file. There must be one complete
844 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
846 /* Compress all tokens, allowing us to use a single argv entry */
848 AslMergeOptionTokens (StringBuffer, StringBuffer2);
850 /* Process the option */
855 OptStatus = AslDoOptions (1, &argv, TRUE);
858 printf ("Invalid option in command file %s: %s\n",
859 Filename, StringBuffer);
864 /* Restore the GetOpt globals */
866 AcpiGbl_Opterr = Opterr;
867 AcpiGbl_Optind = Optind;
869 fclose (ResponseFile);