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 "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 "@:a:b|c|d^D:e:f^gh^i|I:l^m:no|p:P^r:s|t|T+G^v^w|x:z"
73 static char ASL_BUILD_DATE
[] = __DATE__
;
74 static char ASL_BUILD_TIME
[] = __TIME__
;
77 /*******************************************************************************
79 * FUNCTION: AslCommandLine
81 * PARAMETERS: argc/argv
83 * RETURN: Last argv index
85 * DESCRIPTION: Command line processing
87 ******************************************************************************/
94 int BadCommandLine
= 0;
98 /* Minimum command line contains at least the command and an input file */
102 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME
));
107 /* Process all command line options */
109 BadCommandLine
= AslDoOptions (argc
, argv
, FALSE
);
113 Status
= DtCreateTemplates (argv
);
114 if (ACPI_FAILURE (Status
))
121 /* Next parameter must be the input filename */
123 if (!argv
[AcpiGbl_Optind
] &&
126 printf ("Missing input filename\n");
127 BadCommandLine
= TRUE
;
132 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME
));
133 if (Gbl_IgnoreErrors
)
135 printf ("Ignoring all errors, forcing AML file generation\n\n");
141 printf ("Use -h option for help information\n");
145 return (AcpiGbl_Optind
);
149 /*******************************************************************************
151 * FUNCTION: AslDoOptions
153 * PARAMETERS: argc/argv - Standard argc/argv
154 * IsResponseFile - TRUE if executing a response file.
158 * DESCRIPTION: Command line option processing
160 ******************************************************************************/
166 BOOLEAN IsResponseFile
)
172 /* Get the command line options */
174 while ((j
= AcpiGetopt (argc
, argv
, ASL_SUPPORTED_OPTIONS
)) != ACPI_OPT_END
) switch (j
)
176 case '@': /* Begin a response file */
180 printf ("Nested command files are not supported\n");
184 if (AslDoResponseFile (AcpiGbl_Optarg
))
190 case 'a': /* Debug options */
192 switch (AcpiGbl_Optarg
[0])
196 Gbl_EnableReferenceTypechecking
= TRUE
;
201 printf ("Unknown option: -a%s\n", AcpiGbl_Optarg
);
208 case 'b': /* Debug options */
210 switch (AcpiGbl_Optarg
[0])
214 AslCompilerdebug
= 1; /* same as yydebug */
217 Gbl_DebugFlag
= TRUE
;
218 Gbl_KeepPreprocessorTempFile
= TRUE
;
221 case 'p': /* Prune ASL parse tree */
223 /* Get the required argument */
225 if (AcpiGetoptArgument (argc
, argv
))
230 Gbl_PruneParseTree
= TRUE
;
231 Gbl_PruneDepth
= (UINT8
) strtoul (AcpiGbl_Optarg
, NULL
, 0);
236 Gbl_DebugFlag
= TRUE
;
241 /* Get the required argument */
243 if (AcpiGetoptArgument (argc
, argv
))
248 Gbl_PruneType
= (UINT8
) strtoul (AcpiGbl_Optarg
, NULL
, 0);
253 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg
);
261 switch (AcpiGbl_Optarg
[0])
265 Gbl_NoResourceChecking
= TRUE
;
270 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg
);
275 case 'd': /* Disassembler */
277 switch (AcpiGbl_Optarg
[0])
281 /* Get the required argument */
283 if (AcpiGetoptArgument (argc
, argv
))
288 Gbl_DoCompile
= FALSE
;
293 /* Get the required argument */
295 if (AcpiGetoptArgument (argc
, argv
))
300 Gbl_DoCompile
= FALSE
;
301 Gbl_DisassembleAll
= TRUE
;
304 case 'b': /* Do not convert buffers to resource descriptors */
306 AcpiGbl_NoResourceDisassembly
= TRUE
;
315 AcpiGbl_ForceAmlDisassembly
= TRUE
;
318 case 'l': /* Use legacy ASL code (not ASL+) for disassembly */
320 Gbl_DoCompile
= FALSE
;
321 AcpiGbl_CstyleDisassembly
= FALSE
;
326 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg
);
330 Gbl_DisasmFlag
= TRUE
;
333 case 'D': /* Define a symbol */
335 PrAddDefine (AcpiGbl_Optarg
, NULL
, TRUE
);
338 case 'e': /* External files for disassembler */
340 /* Get entire list of external files */
343 argv
[AcpiGbl_Optind
] = AcpiGbl_Optarg
;
345 while (argv
[AcpiGbl_Optind
] &&
346 (argv
[AcpiGbl_Optind
][0] != '-'))
348 Status
= AcpiDmAddToExternalFileList (argv
[AcpiGbl_Optind
]);
349 if (ACPI_FAILURE (Status
))
351 printf ("Could not add %s to external list\n",
352 argv
[AcpiGbl_Optind
]);
362 switch (AcpiGbl_Optarg
[0])
364 case '^': /* Ignore errors and force creation of aml file */
366 Gbl_IgnoreErrors
= TRUE
;
369 case 'e': /* Disassembler: Get external declaration file */
371 if (AcpiGetoptArgument (argc
, argv
))
376 Gbl_ExternalRefFilename
= AcpiGbl_Optarg
;
381 printf ("Unknown option: -f%s\n", AcpiGbl_Optarg
);
388 Gbl_CompileGeneric
= TRUE
;
391 case 'g': /* Get all ACPI tables */
393 printf ("-g option is deprecated, use acpidump utility instead\n");
398 switch (AcpiGbl_Optarg
[0])
407 UtDisplayConstantOpcodes ();
412 AslDisassemblyHelp ();
424 ApDisplayReservedNames ();
429 UtDisplaySupportedTables ();
434 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg
);
438 case 'I': /* Add an include file search directory */
440 FlAddIncludeDirectory (AcpiGbl_Optarg
);
443 case 'i': /* Output AML as an include file */
445 switch (AcpiGbl_Optarg
[0])
449 /* Produce assembly code include file */
451 Gbl_AsmIncludeOutputFlag
= TRUE
;
456 /* Produce C include file */
458 Gbl_C_IncludeOutputFlag
= TRUE
;
463 /* Compiler/Disassembler: Ignore the NOOP operator */
465 AcpiGbl_IgnoreNoopOperator
= TRUE
;
470 printf ("Unknown option: -i%s\n", AcpiGbl_Optarg
);
475 case 'l': /* Listing files */
477 switch (AcpiGbl_Optarg
[0])
481 /* Produce listing file (Mixed source/aml) */
483 Gbl_ListingFlag
= TRUE
;
484 AcpiGbl_DmOpt_Listing
= TRUE
;
489 /* Produce preprocessor output file */
491 Gbl_PreprocessorOutputFlag
= TRUE
;
496 /* Produce hardware map summary file */
498 Gbl_MapfileFlag
= TRUE
;
503 /* Produce namespace file */
505 Gbl_NsOutputFlag
= TRUE
;
510 /* Produce combined source file */
512 Gbl_SourceOutputFlag
= TRUE
;
517 /* Produce cross-reference file */
519 Gbl_CrossReferenceOutput
= TRUE
;
524 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg
);
529 case 'm': /* Set line buffer size */
531 Gbl_LineBufferSize
= (UINT32
) strtoul (AcpiGbl_Optarg
, NULL
, 0) * 1024;
532 if (Gbl_LineBufferSize
< ASL_DEFAULT_LINE_BUFFER_SIZE
)
534 Gbl_LineBufferSize
= ASL_DEFAULT_LINE_BUFFER_SIZE
;
536 printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize
);
539 case 'n': /* Parse only */
541 Gbl_ParseOnlyFlag
= TRUE
;
544 case 'o': /* Control compiler AML optimizations */
546 switch (AcpiGbl_Optarg
[0])
550 /* Disable all optimizations */
552 Gbl_FoldConstants
= FALSE
;
553 Gbl_IntegerOptimizationFlag
= FALSE
;
554 Gbl_ReferenceOptimizationFlag
= FALSE
;
559 /* Display compile time(s) */
561 Gbl_CompileTimesFlag
= TRUE
;
566 /* iASL: Disable External opcode generation */
568 Gbl_DoExternals
= FALSE
;
570 /* Disassembler: Emit embedded external operators */
572 AcpiGbl_DmEmitExternalOpcodes
= TRUE
;
577 /* Disable folding on "normal" expressions */
579 Gbl_FoldConstants
= FALSE
;
584 /* Disable integer optimization to constants */
586 Gbl_IntegerOptimizationFlag
= FALSE
;
591 /* Disable named reference optimization */
593 Gbl_ReferenceOptimizationFlag
= FALSE
;
598 /* Disable heavy typechecking */
600 Gbl_DoTypechecking
= FALSE
;
605 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg
);
610 case 'P': /* Preprocessor options */
612 switch (AcpiGbl_Optarg
[0])
614 case '^': /* Proprocess only, emit (.i) file */
616 Gbl_PreprocessOnly
= TRUE
;
617 Gbl_PreprocessorOutputFlag
= TRUE
;
620 case 'n': /* Disable preprocessor */
622 Gbl_PreprocessFlag
= FALSE
;
627 printf ("Unknown option: -P%s\n", AcpiGbl_Optarg
);
632 case 'p': /* Override default AML output filename */
634 Gbl_OutputFilenamePrefix
= AcpiGbl_Optarg
;
635 UtConvertBackslashes (Gbl_OutputFilenamePrefix
);
636 Gbl_UseDefaultAmlFilename
= FALSE
;
639 case 'r': /* Override revision found in table header */
641 Gbl_RevisionOverride
= (UINT8
) strtoul (AcpiGbl_Optarg
, NULL
, 0);
644 case 's': /* Create AML in a source code file */
646 switch (AcpiGbl_Optarg
[0])
650 /* Produce assembly code output file */
652 Gbl_AsmOutputFlag
= TRUE
;
657 /* Produce C hex output file */
659 Gbl_C_OutputFlag
= TRUE
;
664 /* Produce AML offset table in C */
666 Gbl_C_OffsetTableFlag
= TRUE
;
671 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg
);
676 case 't': /* Produce hex table output file */
678 switch (AcpiGbl_Optarg
[0])
682 Gbl_HexOutputFlag
= HEX_OUTPUT_ASM
;
687 Gbl_HexOutputFlag
= HEX_OUTPUT_C
;
692 Gbl_HexOutputFlag
= HEX_OUTPUT_ASL
;
697 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg
);
702 case 'T': /* Create a ACPI table template file */
704 Gbl_DoTemplates
= TRUE
;
707 case 'v': /* Version and verbosity settings */
709 switch (AcpiGbl_Optarg
[0])
713 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME
));
718 /* Disable all error/warning/remark messages */
725 printf ("%s Build date/time: %s %s\n",
726 ASL_COMPILER_NAME
, ASL_BUILD_DATE
, ASL_BUILD_TIME
);
731 /* Disable all warning/remark messages (errors only) */
733 Gbl_DisplayRemarks
= FALSE
;
734 Gbl_DisplayWarnings
= FALSE
;
739 * Support for integrated development environment(s).
741 * 1) No compiler signon
742 * 2) Send stderr messages to stdout
743 * 3) Less verbose error messages (single line only for each)
744 * 4) Error/warning messages are formatted appropriately to
745 * be recognized by MS Visual Studio
747 Gbl_VerboseErrors
= FALSE
;
748 Gbl_DoSignon
= FALSE
;
749 Gbl_Files
[ASL_FILE_STDERR
].Handle
= stdout
;
754 Gbl_DisplayOptimizations
= TRUE
;
759 Gbl_DisplayRemarks
= FALSE
;
764 Gbl_DoSignon
= FALSE
;
769 Gbl_VerboseTemplates
= TRUE
;
774 /* Get the required argument */
776 if (AcpiGetoptArgument (argc
, argv
))
781 Status
= AslDisableException (AcpiGbl_Optarg
);
782 if (ACPI_FAILURE (Status
))
790 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg
);
795 case 'w': /* Set warning levels */
797 switch (AcpiGbl_Optarg
[0])
801 Gbl_WarningLevel
= ASL_WARNING
;
806 Gbl_WarningLevel
= ASL_WARNING2
;
811 Gbl_WarningLevel
= ASL_WARNING3
;
816 Gbl_WarningsAsErrors
= TRUE
;
821 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg
);
826 case 'x': /* Set debug print output level */
828 AcpiDbgLevel
= strtoul (AcpiGbl_Optarg
, NULL
, 16);
833 Gbl_UseOriginalCompilerId
= TRUE
;
845 /*******************************************************************************
847 * FUNCTION: AslMergeOptionTokens
849 * PARAMETERS: InBuffer - Input containing an option string
850 * OutBuffer - Merged output buffer
854 * DESCRIPTION: Remove all whitespace from an option string.
856 ******************************************************************************/
859 AslMergeOptionTokens (
868 Token
= strtok (InBuffer
, ASL_TOKEN_SEPARATORS
);
871 strcat (OutBuffer
, Token
);
872 Token
= strtok (NULL
, ASL_TOKEN_SEPARATORS
);
877 /*******************************************************************************
879 * FUNCTION: AslDoResponseFile
881 * PARAMETERS: Filename - Name of the response file
885 * DESCRIPTION: Open a response file and process all options within.
887 ******************************************************************************/
893 char *argv
= StringBuffer2
;
900 ResponseFile
= fopen (Filename
, "r");
903 printf ("Could not open command file %s, %s\n",
904 Filename
, strerror (errno
));
908 /* Must save the current GetOpt globals */
910 Opterr
= AcpiGbl_Opterr
;
911 Optind
= AcpiGbl_Optind
;
914 * Process all lines in the response file. There must be one complete
917 while (fgets (StringBuffer
, ASL_MSG_BUFFER_SIZE
, ResponseFile
))
919 /* Compress all tokens, allowing us to use a single argv entry */
921 AslMergeOptionTokens (StringBuffer
, StringBuffer2
);
923 /* Process the option */
928 OptStatus
= AslDoOptions (1, &argv
, TRUE
);
931 printf ("Invalid option in command file %s: %s\n",
932 Filename
, StringBuffer
);
937 /* Restore the GetOpt globals */
939 AcpiGbl_Opterr
= Opterr
;
940 AcpiGbl_Optind
= Optind
;
942 fclose (ResponseFile
);