1 /******************************************************************************
3 * Module Name: asloptions - compiler command line processing
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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] &&
124 printf ("Missing input filename\n");
125 BadCommandLine = TRUE;
130 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
131 if (Gbl_IgnoreErrors)
133 printf ("Ignoring all errors, forcing AML file generation\n\n");
139 printf ("Use -h option for help information\n");
143 return (AcpiGbl_Optind);
147 /*******************************************************************************
149 * FUNCTION: AslDoOptions
151 * PARAMETERS: argc/argv - Standard argc/argv
152 * IsResponseFile - TRUE if executing a response file.
156 * DESCRIPTION: Command line option processing
158 ******************************************************************************/
164 BOOLEAN IsResponseFile)
170 /* Get the command line options */
172 while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
174 case '@': /* Begin a response file */
178 printf ("Nested command files are not supported\n");
182 if (AslDoResponseFile (AcpiGbl_Optarg))
188 case 'b': /* Debug output options */
190 switch (AcpiGbl_Optarg[0])
194 AslCompilerdebug = 1; /* same as yydebug */
205 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
209 /* Produce debug output file */
211 Gbl_DebugFlag = TRUE;
216 switch (AcpiGbl_Optarg[0])
220 Gbl_NoResourceChecking = TRUE;
225 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
230 case 'd': /* Disassembler */
232 switch (AcpiGbl_Optarg[0])
236 Gbl_DoCompile = FALSE;
241 Gbl_DoCompile = FALSE;
242 Gbl_DisassembleAll = TRUE;
245 case 'b': /* Do not convert buffers to resource descriptors */
247 AcpiGbl_NoResourceDisassembly = TRUE;
256 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
260 Gbl_DisasmFlag = TRUE;
263 case 'D': /* Define a symbol */
265 PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
268 case 'e': /* External files for disassembler */
270 Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg);
271 if (ACPI_FAILURE (Status))
273 printf ("Could not add %s to external list\n", AcpiGbl_Optarg);
280 switch (AcpiGbl_Optarg[0])
282 case '^': /* Ignore errors and force creation of aml file */
284 Gbl_IgnoreErrors = TRUE;
287 case 'e': /* Disassembler: Get external declaration file */
289 if (AcpiGetoptArgument (argc, argv))
294 Gbl_ExternalRefFilename = AcpiGbl_Optarg;
299 printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
306 Gbl_CompileGeneric = TRUE;
309 case 'g': /* Get all ACPI tables */
311 Gbl_GetAllTables = TRUE;
312 Gbl_DoCompile = FALSE;
317 switch (AcpiGbl_Optarg[0])
326 UtDisplayConstantOpcodes ();
338 ApDisplayReservedNames ();
343 UtDisplaySupportedTables ();
348 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
352 case 'I': /* Add an include file search directory */
354 FlAddIncludeDirectory (AcpiGbl_Optarg);
357 case 'i': /* Output AML as an include file */
359 switch (AcpiGbl_Optarg[0])
363 /* Produce assembly code include file */
365 Gbl_AsmIncludeOutputFlag = TRUE;
370 /* Produce C include file */
372 Gbl_C_IncludeOutputFlag = TRUE;
377 /* Compiler/Disassembler: Ignore the NOOP operator */
379 AcpiGbl_IgnoreNoopOperator = TRUE;
384 printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
389 case 'l': /* Listing files */
391 switch (AcpiGbl_Optarg[0])
395 /* Produce listing file (Mixed source/aml) */
397 Gbl_ListingFlag = TRUE;
402 /* Produce preprocessor output file */
404 Gbl_PreprocessorOutputFlag = TRUE;
409 /* Produce namespace file */
411 Gbl_NsOutputFlag = TRUE;
416 /* Produce combined source file */
418 Gbl_SourceOutputFlag = TRUE;
423 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
428 case 'm': /* Set line buffer size */
430 Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
431 if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
433 Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
435 printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
438 case 'n': /* Parse only */
440 Gbl_ParseOnlyFlag = TRUE;
443 case 'o': /* Control compiler AML optimizations */
445 switch (AcpiGbl_Optarg[0])
449 /* Disable all optimizations */
451 Gbl_FoldConstants = FALSE;
452 Gbl_IntegerOptimizationFlag = FALSE;
453 Gbl_ReferenceOptimizationFlag = FALSE;
458 /* Disable folding on "normal" expressions */
460 Gbl_FoldConstants = FALSE;
465 /* Disable integer optimization to constants */
467 Gbl_IntegerOptimizationFlag = FALSE;
472 /* Disable named reference optimization */
474 Gbl_ReferenceOptimizationFlag = FALSE;
479 /* Display compile time(s) */
481 Gbl_CompileTimesFlag = TRUE;
486 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
491 case 'P': /* Preprocessor options */
493 switch (AcpiGbl_Optarg[0])
495 case '^': /* Proprocess only, emit (.i) file */
497 Gbl_PreprocessOnly = TRUE;
498 Gbl_PreprocessorOutputFlag = TRUE;
501 case 'n': /* Disable preprocessor */
503 Gbl_PreprocessFlag = FALSE;
508 printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
513 case 'p': /* Override default AML output filename */
515 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
516 Gbl_UseDefaultAmlFilename = FALSE;
519 case 'r': /* Override revision found in table header */
521 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
524 case 's': /* Create AML in a source code file */
526 switch (AcpiGbl_Optarg[0])
530 /* Produce assembly code output file */
532 Gbl_AsmOutputFlag = TRUE;
537 /* Produce C hex output file */
539 Gbl_C_OutputFlag = TRUE;
544 /* Produce AML offset table in C */
546 Gbl_C_OffsetTableFlag = TRUE;
551 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
556 case 't': /* Produce hex table output file */
558 switch (AcpiGbl_Optarg[0])
562 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
567 Gbl_HexOutputFlag = HEX_OUTPUT_C;
572 Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
577 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
582 case 'T': /* Create a ACPI table template file */
584 Gbl_DoTemplates = TRUE;
585 Gbl_TemplateSignature = AcpiGbl_Optarg;
588 case 'v': /* Version and verbosity settings */
590 switch (AcpiGbl_Optarg[0])
594 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
599 /* Disable All error/warning messages */
606 * Support for integrated development environment(s).
608 * 1) No compiler signon
609 * 2) Send stderr messages to stdout
610 * 3) Less verbose error messages (single line only for each)
611 * 4) Error/warning messages are formatted appropriately to
612 * be recognized by MS Visual Studio
614 Gbl_VerboseErrors = FALSE;
615 Gbl_DoSignon = FALSE;
616 Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
621 Gbl_DisplayOptimizations = TRUE;
626 Gbl_DisplayRemarks = FALSE;
631 Gbl_DoSignon = FALSE;
636 Gbl_VerboseTemplates = TRUE;
641 /* Get the required argument */
643 if (AcpiGetoptArgument (argc, argv))
648 Status = AslDisableException (AcpiGbl_Optarg);
649 if (ACPI_FAILURE (Status))
657 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
662 case 'w': /* Set warning levels */
664 switch (AcpiGbl_Optarg[0])
668 Gbl_WarningLevel = ASL_WARNING;
673 Gbl_WarningLevel = ASL_WARNING2;
678 Gbl_WarningLevel = ASL_WARNING3;
683 Gbl_WarningsAsErrors = TRUE;
688 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
693 case 'x': /* Set debug print output level */
695 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
700 Gbl_UseOriginalCompilerId = TRUE;
712 /*******************************************************************************
714 * FUNCTION: AslMergeOptionTokens
716 * PARAMETERS: InBuffer - Input containing an option string
717 * OutBuffer - Merged output buffer
721 * DESCRIPTION: Remove all whitespace from an option string.
723 ******************************************************************************/
726 AslMergeOptionTokens (
735 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
738 strcat (OutBuffer, Token);
739 Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
744 /*******************************************************************************
746 * FUNCTION: AslDoResponseFile
748 * PARAMETERS: Filename - Name of the response file
752 * DESCRIPTION: Open a response file and process all options within.
754 ******************************************************************************/
760 char *argv = StringBuffer2;
767 ResponseFile = fopen (Filename, "r");
770 printf ("Could not open command file %s, %s\n",
771 Filename, strerror (errno));
775 /* Must save the current GetOpt globals */
777 Opterr = AcpiGbl_Opterr;
778 Optind = AcpiGbl_Optind;
781 * Process all lines in the response file. There must be one complete
784 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
786 /* Compress all tokens, allowing us to use a single argv entry */
788 AslMergeOptionTokens (StringBuffer, StringBuffer2);
790 /* Process the option */
795 OptStatus = AslDoOptions (1, &argv, TRUE);
798 printf ("Invalid option in command file %s: %s\n",
799 Filename, StringBuffer);
804 /* Restore the GetOpt globals */
806 AcpiGbl_Opterr = Opterr;
807 AcpiGbl_Optind = Optind;
809 fclose (ResponseFile);