1 /******************************************************************************
3 * Module Name: asloptions - compiler command line processing
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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 "@:a: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 (argv);
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 'a': /* Debug options */
189 switch (AcpiGbl_Optarg[0])
193 Gbl_EnableReferenceTypechecking = TRUE;
198 printf ("Unknown option: -a%s\n", AcpiGbl_Optarg);
205 case 'b': /* Debug options */
207 switch (AcpiGbl_Optarg[0])
211 AslCompilerdebug = 1; /* same as yydebug */
214 Gbl_DebugFlag = TRUE;
215 Gbl_KeepPreprocessorTempFile = TRUE;
218 case 'p': /* Prune ASL parse tree */
220 /* Get the required argument */
222 if (AcpiGetoptArgument (argc, argv))
227 Gbl_PruneParseTree = TRUE;
228 Gbl_PruneDepth = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
233 Gbl_DebugFlag = TRUE;
238 /* Get the required argument */
240 if (AcpiGetoptArgument (argc, argv))
245 Gbl_PruneType = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
250 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
258 switch (AcpiGbl_Optarg[0])
262 Gbl_NoResourceChecking = TRUE;
267 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
272 case 'd': /* Disassembler */
274 switch (AcpiGbl_Optarg[0])
278 /* Get the required argument */
280 if (AcpiGetoptArgument (argc, argv))
285 Gbl_DoCompile = FALSE;
290 /* Get the required argument */
292 if (AcpiGetoptArgument (argc, argv))
297 Gbl_DoCompile = FALSE;
298 Gbl_DisassembleAll = TRUE;
301 case 'b': /* Do not convert buffers to resource descriptors */
303 AcpiGbl_NoResourceDisassembly = TRUE;
312 AcpiGbl_ForceAmlDisassembly = TRUE;
315 case 'l': /* Use legacy ASL code (not ASL+) for disassembly */
317 Gbl_DoCompile = FALSE;
318 AcpiGbl_CstyleDisassembly = FALSE;
323 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
327 Gbl_DisasmFlag = TRUE;
330 case 'D': /* Define a symbol */
332 PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
335 case 'e': /* External files for disassembler */
337 /* Get entire list of external files */
340 argv[AcpiGbl_Optind] = AcpiGbl_Optarg;
342 while (argv[AcpiGbl_Optind] &&
343 (argv[AcpiGbl_Optind][0] != '-'))
345 Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
346 if (ACPI_FAILURE (Status))
348 printf ("Could not add %s to external list\n",
349 argv[AcpiGbl_Optind]);
359 switch (AcpiGbl_Optarg[0])
361 case '^': /* Ignore errors and force creation of aml file */
363 Gbl_IgnoreErrors = TRUE;
366 case 'e': /* Disassembler: Get external declaration file */
368 if (AcpiGetoptArgument (argc, argv))
373 Gbl_ExternalRefFilename = AcpiGbl_Optarg;
378 printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
385 Gbl_CompileGeneric = TRUE;
388 case 'g': /* Get all ACPI tables */
390 printf ("-g option is deprecated, use acpidump utility instead\n");
395 switch (AcpiGbl_Optarg[0])
404 UtDisplayConstantOpcodes ();
409 AslDisassemblyHelp ();
421 ApDisplayReservedNames ();
426 UtDisplaySupportedTables ();
431 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
435 case 'I': /* Add an include file search directory */
437 FlAddIncludeDirectory (AcpiGbl_Optarg);
440 case 'i': /* Output AML as an include file */
442 switch (AcpiGbl_Optarg[0])
446 /* Produce assembly code include file */
448 Gbl_AsmIncludeOutputFlag = TRUE;
453 /* Produce C include file */
455 Gbl_C_IncludeOutputFlag = TRUE;
460 /* Compiler/Disassembler: Ignore the NOOP operator */
462 AcpiGbl_IgnoreNoopOperator = TRUE;
467 printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
472 case 'l': /* Listing files */
474 switch (AcpiGbl_Optarg[0])
478 /* Produce listing file (Mixed source/aml) */
480 Gbl_ListingFlag = TRUE;
481 AcpiGbl_DmOpt_Listing = TRUE;
486 /* Produce preprocessor output file */
488 Gbl_PreprocessorOutputFlag = TRUE;
493 /* Produce hardware map summary file */
495 Gbl_MapfileFlag = TRUE;
500 /* Produce namespace file */
502 Gbl_NsOutputFlag = TRUE;
507 /* Produce combined source file */
509 Gbl_SourceOutputFlag = TRUE;
514 /* Produce cross-reference file */
516 Gbl_CrossReferenceOutput = TRUE;
521 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
526 case 'm': /* Set line buffer size */
528 Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
529 if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
531 Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
533 printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
536 case 'n': /* Parse only */
538 Gbl_ParseOnlyFlag = TRUE;
541 case 'o': /* Control compiler AML optimizations */
543 switch (AcpiGbl_Optarg[0])
547 /* Disable all optimizations */
549 Gbl_FoldConstants = FALSE;
550 Gbl_IntegerOptimizationFlag = FALSE;
551 Gbl_ReferenceOptimizationFlag = FALSE;
556 /* Display compile time(s) */
558 Gbl_CompileTimesFlag = TRUE;
563 /* Disable disassembler code optimizations */
565 AcpiGbl_DoDisassemblerOptimizations = FALSE;
570 /* iASL: Disable External opcode generation */
572 Gbl_DoExternals = FALSE;
574 /* Disassembler: Emit embedded external operators */
576 AcpiGbl_DmEmitExternalOpcodes = TRUE;
581 /* Disable folding on "normal" expressions */
583 Gbl_FoldConstants = FALSE;
588 /* Disable integer optimization to constants */
590 Gbl_IntegerOptimizationFlag = FALSE;
595 /* Disable named reference optimization */
597 Gbl_ReferenceOptimizationFlag = FALSE;
602 /* Disable heavy typechecking */
604 Gbl_DoTypechecking = FALSE;
609 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
614 case 'P': /* Preprocessor options */
616 switch (AcpiGbl_Optarg[0])
618 case '^': /* Proprocess only, emit (.i) file */
620 Gbl_PreprocessOnly = TRUE;
621 Gbl_PreprocessorOutputFlag = TRUE;
624 case 'n': /* Disable preprocessor */
626 Gbl_PreprocessFlag = FALSE;
631 printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
636 case 'p': /* Override default AML output filename */
638 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
639 UtConvertBackslashes (Gbl_OutputFilenamePrefix);
640 Gbl_UseDefaultAmlFilename = FALSE;
643 case 'r': /* Override revision found in table header */
645 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
648 case 's': /* Create AML in a source code file */
650 switch (AcpiGbl_Optarg[0])
654 /* Produce assembly code output file */
656 Gbl_AsmOutputFlag = TRUE;
661 /* Produce C hex output file */
663 Gbl_C_OutputFlag = TRUE;
668 /* Produce AML offset table in C */
670 Gbl_C_OffsetTableFlag = TRUE;
675 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
680 case 't': /* Produce hex table output file */
682 switch (AcpiGbl_Optarg[0])
686 Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
691 Gbl_HexOutputFlag = HEX_OUTPUT_C;
696 Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
701 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
706 case 'T': /* Create a ACPI table template file */
708 Gbl_DoTemplates = TRUE;
711 case 'v': /* Version and verbosity settings */
713 switch (AcpiGbl_Optarg[0])
717 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
722 /* Disable all error/warning/remark messages */
729 /* Disable all warning/remark messages (errors only) */
731 Gbl_DisplayRemarks = FALSE;
732 Gbl_DisplayWarnings = FALSE;
737 * Support for integrated development environment(s).
739 * 1) No compiler signon
740 * 2) Send stderr messages to stdout
741 * 3) Less verbose error messages (single line only for each)
742 * 4) Error/warning messages are formatted appropriately to
743 * be recognized by MS Visual Studio
745 Gbl_VerboseErrors = FALSE;
746 Gbl_DoSignon = FALSE;
747 Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
752 Gbl_DisplayOptimizations = TRUE;
757 Gbl_DisplayRemarks = FALSE;
762 Gbl_DoSignon = FALSE;
767 Gbl_VerboseTemplates = TRUE;
772 /* Get the required argument */
774 if (AcpiGetoptArgument (argc, argv))
779 Status = AslDisableException (AcpiGbl_Optarg);
780 if (ACPI_FAILURE (Status))
788 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
793 case 'w': /* Set warning levels */
795 switch (AcpiGbl_Optarg[0])
799 Gbl_WarningLevel = ASL_WARNING;
804 Gbl_WarningLevel = ASL_WARNING2;
809 Gbl_WarningLevel = ASL_WARNING3;
814 Gbl_WarningsAsErrors = TRUE;
819 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
824 case 'x': /* Set debug print output level */
826 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
831 Gbl_UseOriginalCompilerId = TRUE;
843 /*******************************************************************************
845 * FUNCTION: AslMergeOptionTokens
847 * PARAMETERS: InBuffer - Input containing an option string
848 * OutBuffer - Merged output buffer
852 * DESCRIPTION: Remove all whitespace from an option string.
854 ******************************************************************************/
857 AslMergeOptionTokens (
866 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
869 strcat (OutBuffer, Token);
870 Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
875 /*******************************************************************************
877 * FUNCTION: AslDoResponseFile
879 * PARAMETERS: Filename - Name of the response file
883 * DESCRIPTION: Open a response file and process all options within.
885 ******************************************************************************/
891 char *argv = StringBuffer2;
898 ResponseFile = fopen (Filename, "r");
901 printf ("Could not open command file %s, %s\n",
902 Filename, strerror (errno));
906 /* Must save the current GetOpt globals */
908 Opterr = AcpiGbl_Opterr;
909 Optind = AcpiGbl_Optind;
912 * Process all lines in the response file. There must be one complete
915 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
917 /* Compress all tokens, allowing us to use a single argv entry */
919 AslMergeOptionTokens (StringBuffer, StringBuffer2);
921 /* Process the option */
926 OptStatus = AslDoOptions (1, &argv, TRUE);
929 printf ("Invalid option in command file %s: %s\n",
930 Filename, StringBuffer);
935 /* Restore the GetOpt globals */
937 AcpiGbl_Opterr = Opterr;
938 AcpiGbl_Optind = Optind;
940 fclose (ResponseFile);