1 /******************************************************************************
3 * Module Name: asloptions - compiler command line processing
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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 "aslcompiler.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)) != EOF) 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 output options */
189 switch (AcpiGbl_Optarg[0])
193 AslCompilerdebug = 1; /* same as yydebug */
204 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
208 /* Produce debug output file */
210 Gbl_DebugFlag = TRUE;
215 switch (AcpiGbl_Optarg[0])
219 Gbl_NoResourceChecking = TRUE;
224 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
229 case 'd': /* Disassembler */
231 switch (AcpiGbl_Optarg[0])
235 Gbl_DoCompile = FALSE;
240 Gbl_DoCompile = FALSE;
241 Gbl_DisassembleAll = TRUE;
244 case 'b': /* Do not convert buffers to resource descriptors */
246 AcpiGbl_NoResourceDisassembly = TRUE;
255 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
259 Gbl_DisasmFlag = TRUE;
262 case 'D': /* Define a symbol */
264 PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
267 case 'e': /* External files for disassembler */
269 /* Get entire list of external files */
273 while (argv[AcpiGbl_Optind] &&
274 (argv[AcpiGbl_Optind][0] != '-'))
276 Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
277 if (ACPI_FAILURE (Status))
279 printf ("Could not add %s to external list\n", argv[AcpiGbl_Optind]);
289 switch (AcpiGbl_Optarg[0])
291 case '^': /* Ignore errors and force creation of aml file */
293 Gbl_IgnoreErrors = TRUE;
296 case 'e': /* Disassembler: Get external declaration file */
298 if (AcpiGetoptArgument (argc, argv))
303 Gbl_ExternalRefFilename = AcpiGbl_Optarg;
308 printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
315 Gbl_CompileGeneric = TRUE;
318 case 'g': /* Get all ACPI tables */
320 printf ("-g option is deprecated, use acpidump utility instead\n");
325 switch (AcpiGbl_Optarg[0])
334 UtDisplayConstantOpcodes ();
346 ApDisplayReservedNames ();
351 UtDisplaySupportedTables ();
356 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
360 case 'I': /* Add an include file search directory */
362 FlAddIncludeDirectory (AcpiGbl_Optarg);
365 case 'i': /* Output AML as an include file */
367 switch (AcpiGbl_Optarg[0])
371 /* Produce assembly code include file */
373 Gbl_AsmIncludeOutputFlag = TRUE;
378 /* Produce C include file */
380 Gbl_C_IncludeOutputFlag = TRUE;
385 /* Compiler/Disassembler: Ignore the NOOP operator */
387 AcpiGbl_IgnoreNoopOperator = TRUE;
392 printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
397 case 'l': /* Listing files */
399 switch (AcpiGbl_Optarg[0])
403 /* Produce listing file (Mixed source/aml) */
405 Gbl_ListingFlag = TRUE;
410 /* Produce preprocessor output file */
412 Gbl_PreprocessorOutputFlag = TRUE;
417 /* Produce namespace file */
419 Gbl_NsOutputFlag = TRUE;
424 /* Produce combined source file */
426 Gbl_SourceOutputFlag = TRUE;
431 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
436 case 'm': /* Set line buffer size */
438 Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
439 if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
441 Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
443 printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
446 case 'n': /* Parse only */
448 Gbl_ParseOnlyFlag = TRUE;
451 case 'o': /* Control compiler AML optimizations */
453 switch (AcpiGbl_Optarg[0])
457 /* Disable all optimizations */
459 Gbl_FoldConstants = FALSE;
460 Gbl_IntegerOptimizationFlag = FALSE;
461 Gbl_ReferenceOptimizationFlag = FALSE;
466 /* Disable folding on "normal" expressions */
468 Gbl_FoldConstants = FALSE;
473 /* Disable integer optimization to constants */
475 Gbl_IntegerOptimizationFlag = FALSE;
480 /* Disable named reference optimization */
482 Gbl_ReferenceOptimizationFlag = FALSE;
487 /* Display compile time(s) */
489 Gbl_CompileTimesFlag = TRUE;
494 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
499 case 'P': /* Preprocessor options */
501 switch (AcpiGbl_Optarg[0])
503 case '^': /* Proprocess only, emit (.i) file */
505 Gbl_PreprocessOnly = TRUE;
506 Gbl_PreprocessorOutputFlag = TRUE;
509 case 'n': /* Disable preprocessor */
511 Gbl_PreprocessFlag = FALSE;
516 printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
521 case 'p': /* Override default AML output filename */
523 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
524 UtConvertBackslashes (Gbl_OutputFilenamePrefix);
526 Gbl_UseDefaultAmlFilename = FALSE;
529 case 'r': /* Override revision found in table header */
531 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
534 case 's': /* Create AML in a source code file */
536 switch (AcpiGbl_Optarg[0])
540 /* Produce assembly code output file */
542 Gbl_AsmOutputFlag = TRUE;
547 /* Produce C hex output file */
549 Gbl_C_OutputFlag = TRUE;
554 /* Produce AML offset table in C */
556 Gbl_C_OffsetTableFlag = TRUE;
561 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
566 case 't': /* Produce hex table output file */
568 switch (AcpiGbl_Optarg[0])
572 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
577 Gbl_HexOutputFlag = HEX_OUTPUT_C;
582 Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
587 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
592 case 'T': /* Create a ACPI table template file */
594 Gbl_DoTemplates = TRUE;
595 Gbl_TemplateSignature = AcpiGbl_Optarg;
598 case 'v': /* Version and verbosity settings */
600 switch (AcpiGbl_Optarg[0])
604 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
609 /* Disable all error/warning/remark messages */
616 /* Disable all warning/remark messages (errors only) */
618 Gbl_DisplayRemarks = FALSE;
619 Gbl_DisplayWarnings = FALSE;
624 * Support for integrated development environment(s).
626 * 1) No compiler signon
627 * 2) Send stderr messages to stdout
628 * 3) Less verbose error messages (single line only for each)
629 * 4) Error/warning messages are formatted appropriately to
630 * be recognized by MS Visual Studio
632 Gbl_VerboseErrors = FALSE;
633 Gbl_DoSignon = FALSE;
634 Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
639 Gbl_DisplayOptimizations = TRUE;
644 Gbl_DisplayRemarks = FALSE;
649 Gbl_DoSignon = FALSE;
654 Gbl_VerboseTemplates = TRUE;
659 /* Get the required argument */
661 if (AcpiGetoptArgument (argc, argv))
666 Status = AslDisableException (AcpiGbl_Optarg);
667 if (ACPI_FAILURE (Status))
675 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
680 case 'w': /* Set warning levels */
682 switch (AcpiGbl_Optarg[0])
686 Gbl_WarningLevel = ASL_WARNING;
691 Gbl_WarningLevel = ASL_WARNING2;
696 Gbl_WarningLevel = ASL_WARNING3;
701 Gbl_WarningsAsErrors = TRUE;
706 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
711 case 'x': /* Set debug print output level */
713 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
718 Gbl_UseOriginalCompilerId = TRUE;
730 /*******************************************************************************
732 * FUNCTION: AslMergeOptionTokens
734 * PARAMETERS: InBuffer - Input containing an option string
735 * OutBuffer - Merged output buffer
739 * DESCRIPTION: Remove all whitespace from an option string.
741 ******************************************************************************/
744 AslMergeOptionTokens (
753 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
756 strcat (OutBuffer, Token);
757 Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
762 /*******************************************************************************
764 * FUNCTION: AslDoResponseFile
766 * PARAMETERS: Filename - Name of the response file
770 * DESCRIPTION: Open a response file and process all options within.
772 ******************************************************************************/
778 char *argv = StringBuffer2;
785 ResponseFile = fopen (Filename, "r");
788 printf ("Could not open command file %s, %s\n",
789 Filename, strerror (errno));
793 /* Must save the current GetOpt globals */
795 Opterr = AcpiGbl_Opterr;
796 Optind = AcpiGbl_Optind;
799 * Process all lines in the response file. There must be one complete
802 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
804 /* Compress all tokens, allowing us to use a single argv entry */
806 AslMergeOptionTokens (StringBuffer, StringBuffer2);
808 /* Process the option */
813 OptStatus = AslDoOptions (1, &argv, TRUE);
816 printf ("Invalid option in command file %s: %s\n",
817 Filename, StringBuffer);
822 /* Restore the GetOpt globals */
824 AcpiGbl_Opterr = Opterr;
825 AcpiGbl_Optind = Optind;
827 fclose (ResponseFile);