Home | History | Annotate | Line # | Download | only in compiler
asloptions.c revision 1.3.4.1
      1      1.1  christos /******************************************************************************
      2      1.1  christos  *
      3      1.1  christos  * Module Name: asloptions - compiler command line processing
      4      1.1  christos  *
      5      1.1  christos  *****************************************************************************/
      6      1.1  christos 
      7      1.1  christos /*
      8      1.3  christos  * Copyright (C) 2000 - 2017, Intel Corp.
      9      1.1  christos  * All rights reserved.
     10      1.1  christos  *
     11      1.1  christos  * Redistribution and use in source and binary forms, with or without
     12      1.1  christos  * modification, are permitted provided that the following conditions
     13      1.1  christos  * are met:
     14      1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15      1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16      1.1  christos  *    without modification.
     17      1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21      1.1  christos  *    binary redistribution.
     22      1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24      1.1  christos  *    from this software without specific prior written permission.
     25      1.1  christos  *
     26      1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27      1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1  christos  * Software Foundation.
     29      1.1  christos  *
     30      1.1  christos  * NO WARRANTY
     31      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1  christos  */
     43      1.1  christos 
     44      1.1  christos #include "aslcompiler.h"
     45      1.1  christos #include "acapps.h"
     46      1.1  christos #include "acdisasm.h"
     47      1.1  christos 
     48      1.1  christos #define _COMPONENT          ACPI_COMPILER
     49      1.1  christos         ACPI_MODULE_NAME    ("asloption")
     50      1.1  christos 
     51      1.1  christos 
     52      1.1  christos /* Local prototypes */
     53      1.1  christos 
     54      1.1  christos static int
     55      1.1  christos AslDoOptions (
     56      1.1  christos     int                     argc,
     57      1.1  christos     char                    **argv,
     58      1.1  christos     BOOLEAN                 IsResponseFile);
     59      1.1  christos 
     60      1.1  christos static void
     61      1.1  christos AslMergeOptionTokens (
     62      1.1  christos     char                    *InBuffer,
     63      1.1  christos     char                    *OutBuffer);
     64      1.1  christos 
     65      1.1  christos static int
     66      1.1  christos AslDoResponseFile (
     67      1.1  christos     char                    *Filename);
     68      1.1  christos 
     69      1.1  christos 
     70      1.1  christos #define ASL_TOKEN_SEPARATORS    " \t\n"
     71  1.3.4.1  pgoyette #define ASL_SUPPORTED_OPTIONS   "@:a:b|c|d^D:e:f^gh^i|I:l^m:no|p:P^q^r:s|t|T+G^v^w|x:z"
     72      1.2  christos 
     73      1.2  christos #ifdef ACPI_REPRO
     74      1.2  christos static char ASL_BUILD_DATE[] = "Jan 1, 1970";
     75      1.2  christos static char ASL_BUILD_TIME[] = "00:00:00";
     76      1.2  christos #else
     77      1.2  christos static char ASL_BUILD_DATE[] = __DATE__;
     78      1.2  christos static char ASL_BUILD_TIME[] = __TIME__;
     79      1.2  christos #endif
     80      1.1  christos 
     81      1.1  christos 
     82      1.1  christos /*******************************************************************************
     83      1.1  christos  *
     84      1.1  christos  * FUNCTION:    AslCommandLine
     85      1.1  christos  *
     86      1.1  christos  * PARAMETERS:  argc/argv
     87      1.1  christos  *
     88      1.1  christos  * RETURN:      Last argv index
     89      1.1  christos  *
     90      1.1  christos  * DESCRIPTION: Command line processing
     91      1.1  christos  *
     92      1.1  christos  ******************************************************************************/
     93      1.1  christos 
     94      1.1  christos int
     95      1.1  christos AslCommandLine (
     96      1.1  christos     int                     argc,
     97      1.1  christos     char                    **argv)
     98      1.1  christos {
     99      1.1  christos     int                     BadCommandLine = 0;
    100      1.1  christos     ACPI_STATUS             Status;
    101      1.1  christos 
    102      1.1  christos 
    103      1.1  christos     /* Minimum command line contains at least the command and an input file */
    104      1.1  christos 
    105      1.1  christos     if (argc < 2)
    106      1.1  christos     {
    107      1.1  christos         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
    108      1.1  christos         Usage ();
    109      1.1  christos         exit (1);
    110      1.1  christos     }
    111      1.1  christos 
    112      1.1  christos     /* Process all command line options */
    113      1.1  christos 
    114      1.1  christos     BadCommandLine = AslDoOptions (argc, argv, FALSE);
    115      1.1  christos 
    116      1.1  christos     if (Gbl_DoTemplates)
    117      1.1  christos     {
    118      1.2  christos         Status = DtCreateTemplates (argv);
    119      1.1  christos         if (ACPI_FAILURE (Status))
    120      1.1  christos         {
    121      1.1  christos             exit (-1);
    122      1.1  christos         }
    123      1.1  christos         exit (1);
    124      1.1  christos     }
    125      1.1  christos 
    126      1.1  christos     /* Next parameter must be the input filename */
    127      1.1  christos 
    128      1.1  christos     if (!argv[AcpiGbl_Optind] &&
    129      1.2  christos         !Gbl_DisasmFlag)
    130      1.1  christos     {
    131      1.1  christos         printf ("Missing input filename\n");
    132      1.1  christos         BadCommandLine = TRUE;
    133      1.1  christos     }
    134      1.1  christos 
    135      1.1  christos     if (Gbl_DoSignon)
    136      1.1  christos     {
    137      1.1  christos         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
    138      1.1  christos         if (Gbl_IgnoreErrors)
    139      1.1  christos         {
    140      1.1  christos             printf ("Ignoring all errors, forcing AML file generation\n\n");
    141      1.1  christos         }
    142      1.1  christos     }
    143      1.1  christos 
    144      1.1  christos     if (BadCommandLine)
    145      1.1  christos     {
    146      1.1  christos         printf ("Use -h option for help information\n");
    147      1.1  christos         exit (1);
    148      1.1  christos     }
    149      1.1  christos 
    150      1.1  christos     return (AcpiGbl_Optind);
    151      1.1  christos }
    152      1.1  christos 
    153      1.1  christos 
    154      1.1  christos /*******************************************************************************
    155      1.1  christos  *
    156      1.1  christos  * FUNCTION:    AslDoOptions
    157      1.1  christos  *
    158      1.1  christos  * PARAMETERS:  argc/argv           - Standard argc/argv
    159      1.1  christos  *              IsResponseFile      - TRUE if executing a response file.
    160      1.1  christos  *
    161      1.1  christos  * RETURN:      Status
    162      1.1  christos  *
    163      1.1  christos  * DESCRIPTION: Command line option processing
    164      1.1  christos  *
    165      1.1  christos  ******************************************************************************/
    166      1.1  christos 
    167      1.1  christos static int
    168      1.1  christos AslDoOptions (
    169      1.1  christos     int                     argc,
    170      1.1  christos     char                    **argv,
    171      1.1  christos     BOOLEAN                 IsResponseFile)
    172      1.1  christos {
    173      1.1  christos     ACPI_STATUS             Status;
    174      1.1  christos     UINT32                  j;
    175      1.1  christos 
    176      1.1  christos 
    177      1.1  christos     /* Get the command line options */
    178      1.1  christos 
    179      1.2  christos     while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
    180      1.1  christos     {
    181      1.1  christos     case '@':   /* Begin a response file */
    182      1.1  christos 
    183      1.1  christos         if (IsResponseFile)
    184      1.1  christos         {
    185      1.1  christos             printf ("Nested command files are not supported\n");
    186      1.1  christos             return (-1);
    187      1.1  christos         }
    188      1.1  christos 
    189      1.1  christos         if (AslDoResponseFile (AcpiGbl_Optarg))
    190      1.1  christos         {
    191      1.1  christos             return (-1);
    192      1.1  christos         }
    193      1.1  christos         break;
    194      1.1  christos 
    195      1.2  christos     case 'a':   /* Debug options */
    196      1.2  christos 
    197      1.2  christos         switch (AcpiGbl_Optarg[0])
    198      1.2  christos         {
    199      1.2  christos         case 'r':
    200      1.2  christos 
    201      1.2  christos             Gbl_EnableReferenceTypechecking = TRUE;
    202      1.2  christos             break;
    203      1.2  christos 
    204      1.2  christos         default:
    205      1.2  christos 
    206      1.2  christos             printf ("Unknown option: -a%s\n", AcpiGbl_Optarg);
    207      1.2  christos             return (-1);
    208      1.2  christos         }
    209      1.2  christos 
    210      1.2  christos         break;
    211      1.2  christos 
    212      1.2  christos 
    213      1.2  christos     case 'b':   /* Debug options */
    214      1.1  christos 
    215      1.1  christos         switch (AcpiGbl_Optarg[0])
    216      1.1  christos         {
    217  1.3.4.1  pgoyette 
    218  1.3.4.1  pgoyette         case 'c':
    219  1.3.4.1  pgoyette 
    220  1.3.4.1  pgoyette             printf ("Debug ASL to ASL+ conversion\n");
    221  1.3.4.1  pgoyette 
    222  1.3.4.1  pgoyette             Gbl_DoAslConversion = TRUE;
    223  1.3.4.1  pgoyette             Gbl_FoldConstants = FALSE;
    224  1.3.4.1  pgoyette             Gbl_IntegerOptimizationFlag = FALSE;
    225  1.3.4.1  pgoyette             Gbl_ReferenceOptimizationFlag = FALSE;
    226  1.3.4.1  pgoyette             Gbl_OptimizeTrivialParseNodes = FALSE;
    227  1.3.4.1  pgoyette             Gbl_CaptureComments = TRUE;
    228  1.3.4.1  pgoyette             AcpiGbl_DoDisassemblerOptimizations = FALSE;
    229  1.3.4.1  pgoyette             AcpiGbl_DebugAslConversion = TRUE;
    230  1.3.4.1  pgoyette             AcpiGbl_DmEmitExternalOpcodes = TRUE;
    231  1.3.4.1  pgoyette             Gbl_DoExternalsInPlace = TRUE;
    232  1.3.4.1  pgoyette 
    233  1.3.4.1  pgoyette             return (0);
    234  1.3.4.1  pgoyette 
    235      1.1  christos         case 'f':
    236      1.1  christos 
    237      1.1  christos             AslCompilerdebug = 1; /* same as yydebug */
    238      1.1  christos             DtParserdebug = 1;
    239      1.1  christos             PrParserdebug = 1;
    240      1.2  christos             Gbl_DebugFlag = TRUE;
    241      1.2  christos             Gbl_KeepPreprocessorTempFile = TRUE;
    242      1.2  christos             break;
    243      1.2  christos 
    244      1.2  christos         case 'p':   /* Prune ASL parse tree */
    245      1.2  christos 
    246      1.2  christos             /* Get the required argument */
    247      1.2  christos 
    248      1.2  christos             if (AcpiGetoptArgument (argc, argv))
    249      1.2  christos             {
    250      1.2  christos                 return (-1);
    251      1.2  christos             }
    252      1.2  christos 
    253      1.2  christos             Gbl_PruneParseTree = TRUE;
    254      1.2  christos             Gbl_PruneDepth = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
    255      1.2  christos             break;
    256      1.2  christos 
    257      1.2  christos         case 's':
    258      1.2  christos 
    259      1.2  christos             Gbl_DebugFlag = TRUE;
    260      1.1  christos             break;
    261      1.1  christos 
    262      1.1  christos         case 't':
    263      1.1  christos 
    264      1.2  christos             /* Get the required argument */
    265      1.2  christos 
    266      1.2  christos             if (AcpiGetoptArgument (argc, argv))
    267      1.2  christos             {
    268      1.2  christos                 return (-1);
    269      1.2  christos             }
    270      1.2  christos 
    271      1.2  christos             Gbl_PruneType = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
    272      1.1  christos             break;
    273      1.1  christos 
    274      1.1  christos         default:
    275      1.1  christos 
    276      1.1  christos             printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
    277      1.1  christos             return (-1);
    278      1.1  christos         }
    279      1.1  christos 
    280      1.1  christos         break;
    281      1.1  christos 
    282      1.1  christos     case 'c':
    283      1.1  christos 
    284      1.1  christos         switch (AcpiGbl_Optarg[0])
    285      1.1  christos         {
    286  1.3.4.1  pgoyette 
    287  1.3.4.1  pgoyette         case 'a':
    288  1.3.4.1  pgoyette 
    289  1.3.4.1  pgoyette             printf ("Convert ASL to ASL+ with comments\n");
    290  1.3.4.1  pgoyette             Gbl_DoAslConversion = TRUE;
    291  1.3.4.1  pgoyette             Gbl_FoldConstants = FALSE;
    292  1.3.4.1  pgoyette             Gbl_IntegerOptimizationFlag = FALSE;
    293  1.3.4.1  pgoyette             Gbl_ReferenceOptimizationFlag = FALSE;
    294  1.3.4.1  pgoyette             Gbl_OptimizeTrivialParseNodes = FALSE;
    295  1.3.4.1  pgoyette             Gbl_CaptureComments = TRUE;
    296  1.3.4.1  pgoyette             AcpiGbl_DoDisassemblerOptimizations = FALSE;
    297  1.3.4.1  pgoyette             AcpiGbl_DmEmitExternalOpcodes = TRUE;
    298  1.3.4.1  pgoyette             Gbl_DoExternalsInPlace = TRUE;
    299  1.3.4.1  pgoyette 
    300  1.3.4.1  pgoyette             return (0);
    301  1.3.4.1  pgoyette 
    302      1.1  christos         case 'r':
    303      1.1  christos 
    304      1.1  christos             Gbl_NoResourceChecking = TRUE;
    305      1.1  christos             break;
    306      1.1  christos 
    307      1.1  christos         default:
    308      1.1  christos 
    309      1.1  christos             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
    310      1.1  christos             return (-1);
    311      1.1  christos         }
    312      1.1  christos         break;
    313      1.1  christos 
    314      1.1  christos     case 'd':   /* Disassembler */
    315      1.1  christos 
    316      1.1  christos         switch (AcpiGbl_Optarg[0])
    317      1.1  christos         {
    318      1.1  christos         case '^':
    319      1.1  christos 
    320      1.2  christos             /* Get the required argument */
    321      1.2  christos 
    322      1.2  christos             if (AcpiGetoptArgument (argc, argv))
    323      1.2  christos             {
    324      1.2  christos                 return (-1);
    325      1.2  christos             }
    326      1.2  christos 
    327      1.1  christos             Gbl_DoCompile = FALSE;
    328      1.1  christos             break;
    329      1.1  christos 
    330      1.1  christos         case 'a':
    331      1.1  christos 
    332      1.2  christos             /* Get the required argument */
    333      1.2  christos 
    334      1.2  christos             if (AcpiGetoptArgument (argc, argv))
    335      1.2  christos             {
    336      1.2  christos                 return (-1);
    337      1.2  christos             }
    338      1.2  christos 
    339      1.1  christos             Gbl_DoCompile = FALSE;
    340      1.1  christos             Gbl_DisassembleAll = TRUE;
    341      1.1  christos             break;
    342      1.1  christos 
    343      1.1  christos         case 'b':   /* Do not convert buffers to resource descriptors */
    344      1.1  christos 
    345      1.1  christos             AcpiGbl_NoResourceDisassembly = TRUE;
    346      1.1  christos             break;
    347      1.1  christos 
    348      1.1  christos         case 'c':
    349      1.1  christos 
    350      1.1  christos             break;
    351      1.1  christos 
    352      1.2  christos         case 'f':
    353      1.2  christos 
    354      1.2  christos             AcpiGbl_ForceAmlDisassembly = TRUE;
    355      1.2  christos             break;
    356      1.2  christos 
    357      1.2  christos         case 'l':   /* Use legacy ASL code (not ASL+) for disassembly */
    358      1.2  christos 
    359      1.2  christos             Gbl_DoCompile = FALSE;
    360      1.2  christos             AcpiGbl_CstyleDisassembly = FALSE;
    361      1.2  christos             break;
    362      1.2  christos 
    363      1.1  christos         default:
    364      1.1  christos 
    365      1.1  christos             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
    366      1.1  christos             return (-1);
    367      1.1  christos         }
    368      1.1  christos 
    369      1.1  christos         Gbl_DisasmFlag = TRUE;
    370      1.1  christos         break;
    371      1.1  christos 
    372      1.1  christos     case 'D':   /* Define a symbol */
    373      1.1  christos 
    374      1.1  christos         PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
    375      1.1  christos         break;
    376      1.1  christos 
    377      1.1  christos     case 'e':   /* External files for disassembler */
    378      1.1  christos 
    379      1.1  christos         /* Get entire list of external files */
    380      1.1  christos 
    381      1.1  christos         AcpiGbl_Optind--;
    382      1.2  christos         argv[AcpiGbl_Optind] = AcpiGbl_Optarg;
    383      1.1  christos 
    384      1.1  christos         while (argv[AcpiGbl_Optind] &&
    385      1.1  christos               (argv[AcpiGbl_Optind][0] != '-'))
    386      1.1  christos         {
    387      1.1  christos             Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
    388      1.1  christos             if (ACPI_FAILURE (Status))
    389      1.1  christos             {
    390      1.2  christos                 printf ("Could not add %s to external list\n",
    391      1.2  christos                     argv[AcpiGbl_Optind]);
    392      1.1  christos                 return (-1);
    393      1.1  christos             }
    394      1.1  christos 
    395      1.1  christos             AcpiGbl_Optind++;
    396      1.1  christos         }
    397      1.1  christos         break;
    398      1.1  christos 
    399      1.1  christos     case 'f':
    400      1.1  christos 
    401      1.1  christos         switch (AcpiGbl_Optarg[0])
    402      1.1  christos         {
    403      1.1  christos         case '^':   /* Ignore errors and force creation of aml file */
    404      1.1  christos 
    405      1.1  christos             Gbl_IgnoreErrors = TRUE;
    406      1.1  christos             break;
    407      1.1  christos 
    408      1.1  christos         case 'e':   /* Disassembler: Get external declaration file */
    409      1.1  christos 
    410      1.1  christos             if (AcpiGetoptArgument (argc, argv))
    411      1.1  christos             {
    412      1.1  christos                 return (-1);
    413      1.1  christos             }
    414      1.1  christos 
    415      1.1  christos             Gbl_ExternalRefFilename = AcpiGbl_Optarg;
    416      1.1  christos             break;
    417      1.1  christos 
    418      1.1  christos         default:
    419      1.1  christos 
    420      1.1  christos             printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
    421      1.1  christos             return (-1);
    422      1.1  christos         }
    423      1.1  christos         break;
    424      1.1  christos 
    425      1.1  christos     case 'G':
    426      1.1  christos 
    427      1.1  christos         Gbl_CompileGeneric = TRUE;
    428      1.1  christos         break;
    429      1.1  christos 
    430      1.1  christos     case 'g':   /* Get all ACPI tables */
    431      1.1  christos 
    432      1.2  christos         printf ("-g option is deprecated, use acpidump utility instead\n");
    433      1.2  christos         exit (1);
    434      1.1  christos 
    435      1.1  christos     case 'h':
    436      1.1  christos 
    437      1.1  christos         switch (AcpiGbl_Optarg[0])
    438      1.1  christos         {
    439      1.1  christos         case '^':
    440      1.1  christos 
    441      1.1  christos             Usage ();
    442      1.1  christos             exit (0);
    443      1.1  christos 
    444      1.1  christos         case 'c':
    445      1.1  christos 
    446      1.1  christos             UtDisplayConstantOpcodes ();
    447      1.1  christos             exit (0);
    448      1.1  christos 
    449      1.2  christos         case 'd':
    450      1.2  christos 
    451      1.2  christos             AslDisassemblyHelp ();
    452      1.2  christos             exit (0);
    453      1.2  christos 
    454      1.1  christos         case 'f':
    455      1.1  christos 
    456      1.1  christos             AslFilenameHelp ();
    457      1.1  christos             exit (0);
    458      1.1  christos 
    459      1.1  christos         case 'r':
    460      1.1  christos 
    461      1.1  christos             /* reserved names */
    462      1.1  christos 
    463      1.1  christos             ApDisplayReservedNames ();
    464      1.1  christos             exit (0);
    465      1.1  christos 
    466      1.1  christos         case 't':
    467      1.1  christos 
    468      1.1  christos             UtDisplaySupportedTables ();
    469      1.1  christos             exit (0);
    470      1.1  christos 
    471      1.1  christos         default:
    472      1.1  christos 
    473      1.1  christos             printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
    474      1.1  christos             return (-1);
    475      1.1  christos         }
    476      1.1  christos 
    477      1.1  christos     case 'I':   /* Add an include file search directory */
    478      1.1  christos 
    479      1.1  christos         FlAddIncludeDirectory (AcpiGbl_Optarg);
    480      1.1  christos         break;
    481      1.1  christos 
    482      1.1  christos     case 'i':   /* Output AML as an include file */
    483      1.1  christos 
    484      1.1  christos         switch (AcpiGbl_Optarg[0])
    485      1.1  christos         {
    486      1.1  christos         case 'a':
    487      1.1  christos 
    488      1.1  christos             /* Produce assembly code include file */
    489      1.1  christos 
    490      1.1  christos             Gbl_AsmIncludeOutputFlag = TRUE;
    491      1.1  christos             break;
    492      1.1  christos 
    493      1.1  christos         case 'c':
    494      1.1  christos 
    495      1.1  christos             /* Produce C include file */
    496      1.1  christos 
    497      1.1  christos             Gbl_C_IncludeOutputFlag = TRUE;
    498      1.1  christos             break;
    499      1.1  christos 
    500      1.1  christos         case 'n':
    501      1.1  christos 
    502      1.1  christos             /* Compiler/Disassembler: Ignore the NOOP operator */
    503      1.1  christos 
    504      1.1  christos             AcpiGbl_IgnoreNoopOperator = TRUE;
    505      1.1  christos             break;
    506      1.1  christos 
    507      1.1  christos         default:
    508      1.1  christos 
    509      1.1  christos             printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
    510      1.1  christos             return (-1);
    511      1.1  christos         }
    512      1.1  christos         break;
    513      1.1  christos 
    514      1.1  christos     case 'l':   /* Listing files */
    515      1.1  christos 
    516      1.1  christos         switch (AcpiGbl_Optarg[0])
    517      1.1  christos         {
    518      1.1  christos         case '^':
    519      1.1  christos 
    520      1.1  christos             /* Produce listing file (Mixed source/aml) */
    521      1.1  christos 
    522      1.1  christos             Gbl_ListingFlag = TRUE;
    523      1.2  christos             AcpiGbl_DmOpt_Listing = TRUE;
    524      1.1  christos             break;
    525      1.1  christos 
    526      1.1  christos         case 'i':
    527      1.1  christos 
    528      1.1  christos             /* Produce preprocessor output file */
    529      1.1  christos 
    530      1.1  christos             Gbl_PreprocessorOutputFlag = TRUE;
    531      1.1  christos             break;
    532      1.1  christos 
    533      1.2  christos         case 'm':
    534      1.2  christos 
    535      1.2  christos             /* Produce hardware map summary file */
    536      1.2  christos 
    537      1.2  christos             Gbl_MapfileFlag = TRUE;
    538      1.2  christos             break;
    539      1.2  christos 
    540      1.1  christos         case 'n':
    541      1.1  christos 
    542      1.1  christos             /* Produce namespace file */
    543      1.1  christos 
    544      1.1  christos             Gbl_NsOutputFlag = TRUE;
    545      1.1  christos             break;
    546      1.1  christos 
    547      1.1  christos         case 's':
    548      1.1  christos 
    549      1.1  christos             /* Produce combined source file */
    550      1.1  christos 
    551      1.1  christos             Gbl_SourceOutputFlag = TRUE;
    552      1.1  christos             break;
    553      1.1  christos 
    554      1.2  christos         case 'x':
    555      1.2  christos 
    556      1.2  christos             /* Produce cross-reference file */
    557      1.2  christos 
    558      1.2  christos             Gbl_CrossReferenceOutput = TRUE;
    559      1.2  christos             break;
    560      1.2  christos 
    561      1.1  christos         default:
    562      1.1  christos 
    563      1.1  christos             printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
    564      1.1  christos             return (-1);
    565      1.1  christos         }
    566      1.1  christos         break;
    567      1.1  christos 
    568      1.1  christos     case 'm':   /* Set line buffer size */
    569      1.1  christos 
    570      1.1  christos         Gbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
    571      1.1  christos         if (Gbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
    572      1.1  christos         {
    573      1.1  christos             Gbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
    574      1.1  christos         }
    575      1.1  christos         printf ("Line Buffer Size: %u\n", Gbl_LineBufferSize);
    576      1.1  christos         break;
    577      1.1  christos 
    578      1.1  christos     case 'n':   /* Parse only */
    579      1.1  christos 
    580      1.1  christos         Gbl_ParseOnlyFlag = TRUE;
    581      1.1  christos         break;
    582      1.1  christos 
    583      1.1  christos     case 'o':   /* Control compiler AML optimizations */
    584      1.1  christos 
    585      1.1  christos         switch (AcpiGbl_Optarg[0])
    586      1.1  christos         {
    587      1.1  christos         case 'a':
    588      1.1  christos 
    589      1.1  christos             /* Disable all optimizations */
    590      1.1  christos 
    591      1.1  christos             Gbl_FoldConstants = FALSE;
    592      1.1  christos             Gbl_IntegerOptimizationFlag = FALSE;
    593      1.1  christos             Gbl_ReferenceOptimizationFlag = FALSE;
    594  1.3.4.1  pgoyette             Gbl_OptimizeTrivialParseNodes = FALSE;
    595  1.3.4.1  pgoyette 
    596      1.1  christos             break;
    597      1.1  christos 
    598      1.2  christos         case 'c':
    599      1.2  christos 
    600      1.2  christos             /* Display compile time(s) */
    601      1.2  christos 
    602      1.2  christos             Gbl_CompileTimesFlag = TRUE;
    603      1.2  christos             break;
    604      1.2  christos 
    605      1.2  christos         case 'd':
    606      1.2  christos 
    607      1.2  christos             /* Disable disassembler code optimizations */
    608      1.2  christos 
    609      1.2  christos             AcpiGbl_DoDisassemblerOptimizations = FALSE;
    610      1.2  christos             break;
    611      1.2  christos 
    612      1.2  christos         case 'e':
    613      1.2  christos 
    614      1.2  christos             /* Disassembler: Emit embedded external operators */
    615      1.2  christos 
    616      1.2  christos             AcpiGbl_DmEmitExternalOpcodes = TRUE;
    617      1.2  christos             break;
    618      1.2  christos 
    619  1.3.4.1  pgoyette         case 'E':
    620  1.3.4.1  pgoyette 
    621  1.3.4.1  pgoyette             /*
    622  1.3.4.1  pgoyette              * iASL: keep External opcodes in place.
    623  1.3.4.1  pgoyette              * No affect if Gbl_DoExternals is false.
    624  1.3.4.1  pgoyette              */
    625  1.3.4.1  pgoyette 
    626  1.3.4.1  pgoyette             Gbl_DoExternalsInPlace = TRUE;
    627  1.3.4.1  pgoyette             break;
    628  1.3.4.1  pgoyette 
    629      1.1  christos         case 'f':
    630      1.1  christos 
    631      1.1  christos             /* Disable folding on "normal" expressions */
    632      1.1  christos 
    633      1.1  christos             Gbl_FoldConstants = FALSE;
    634      1.1  christos             break;
    635      1.1  christos 
    636      1.1  christos         case 'i':
    637      1.1  christos 
    638      1.1  christos             /* Disable integer optimization to constants */
    639      1.1  christos 
    640      1.1  christos             Gbl_IntegerOptimizationFlag = FALSE;
    641      1.1  christos             break;
    642      1.1  christos 
    643      1.1  christos         case 'n':
    644      1.1  christos 
    645      1.1  christos             /* Disable named reference optimization */
    646      1.1  christos 
    647      1.1  christos             Gbl_ReferenceOptimizationFlag = FALSE;
    648      1.1  christos             break;
    649      1.1  christos 
    650      1.1  christos         case 't':
    651      1.1  christos 
    652      1.2  christos             /* Disable heavy typechecking */
    653      1.1  christos 
    654      1.2  christos             Gbl_DoTypechecking = FALSE;
    655      1.1  christos             break;
    656      1.1  christos 
    657      1.1  christos         default:
    658      1.1  christos 
    659      1.1  christos             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
    660      1.1  christos             return (-1);
    661      1.1  christos         }
    662      1.1  christos         break;
    663      1.1  christos 
    664      1.1  christos     case 'P':   /* Preprocessor options */
    665      1.1  christos 
    666      1.1  christos         switch (AcpiGbl_Optarg[0])
    667      1.1  christos         {
    668      1.1  christos         case '^':   /* Proprocess only, emit (.i) file */
    669      1.1  christos 
    670      1.1  christos             Gbl_PreprocessOnly = TRUE;
    671      1.1  christos             Gbl_PreprocessorOutputFlag = TRUE;
    672      1.1  christos             break;
    673      1.1  christos 
    674      1.1  christos         case 'n':   /* Disable preprocessor */
    675      1.1  christos 
    676      1.1  christos             Gbl_PreprocessFlag = FALSE;
    677      1.1  christos             break;
    678      1.1  christos 
    679      1.1  christos         default:
    680      1.1  christos 
    681      1.1  christos             printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
    682      1.1  christos             return (-1);
    683      1.1  christos         }
    684      1.1  christos         break;
    685      1.1  christos 
    686      1.1  christos     case 'p':   /* Override default AML output filename */
    687      1.1  christos 
    688      1.1  christos         Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
    689      1.1  christos         UtConvertBackslashes (Gbl_OutputFilenamePrefix);
    690      1.1  christos         Gbl_UseDefaultAmlFilename = FALSE;
    691      1.1  christos         break;
    692      1.1  christos 
    693  1.3.4.1  pgoyette     case 'q':   /* ASL/ASl+ converter: compile only and leave badaml. */
    694  1.3.4.1  pgoyette 
    695  1.3.4.1  pgoyette         printf ("Convert ASL to ASL+ with comments\n");
    696  1.3.4.1  pgoyette         Gbl_FoldConstants = FALSE;
    697  1.3.4.1  pgoyette         Gbl_IntegerOptimizationFlag = FALSE;
    698  1.3.4.1  pgoyette         Gbl_ReferenceOptimizationFlag = FALSE;
    699  1.3.4.1  pgoyette         Gbl_OptimizeTrivialParseNodes = FALSE;
    700  1.3.4.1  pgoyette         Gbl_CaptureComments = TRUE;
    701  1.3.4.1  pgoyette         Gbl_DoExternalsInPlace = TRUE;
    702  1.3.4.1  pgoyette         return (0);
    703  1.3.4.1  pgoyette 
    704      1.1  christos     case 'r':   /* Override revision found in table header */
    705      1.1  christos 
    706      1.1  christos         Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
    707      1.1  christos         break;
    708      1.1  christos 
    709      1.1  christos     case 's':   /* Create AML in a source code file */
    710      1.1  christos 
    711      1.1  christos         switch (AcpiGbl_Optarg[0])
    712      1.1  christos         {
    713      1.1  christos         case 'a':
    714      1.1  christos 
    715      1.1  christos             /* Produce assembly code output file */
    716      1.1  christos 
    717      1.1  christos             Gbl_AsmOutputFlag = TRUE;
    718      1.1  christos             break;
    719      1.1  christos 
    720      1.1  christos         case 'c':
    721      1.1  christos 
    722      1.1  christos             /* Produce C hex output file */
    723      1.1  christos 
    724      1.1  christos             Gbl_C_OutputFlag = TRUE;
    725      1.1  christos             break;
    726      1.1  christos 
    727      1.1  christos         case 'o':
    728      1.1  christos 
    729      1.1  christos             /* Produce AML offset table in C */
    730      1.1  christos 
    731      1.1  christos             Gbl_C_OffsetTableFlag = TRUE;
    732      1.1  christos             break;
    733      1.1  christos 
    734      1.1  christos         default:
    735      1.1  christos 
    736      1.1  christos             printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
    737      1.1  christos             return (-1);
    738      1.1  christos         }
    739      1.1  christos         break;
    740      1.1  christos 
    741      1.1  christos     case 't':   /* Produce hex table output file */
    742      1.1  christos 
    743      1.1  christos         switch (AcpiGbl_Optarg[0])
    744      1.1  christos         {
    745      1.1  christos         case 'a':
    746      1.1  christos 
    747      1.1  christos             Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
    748      1.1  christos             break;
    749      1.1  christos 
    750      1.1  christos         case 'c':
    751      1.1  christos 
    752      1.1  christos             Gbl_HexOutputFlag = HEX_OUTPUT_C;
    753      1.1  christos             break;
    754      1.1  christos 
    755      1.1  christos         case 's':
    756      1.1  christos 
    757      1.1  christos             Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
    758      1.1  christos             break;
    759      1.1  christos 
    760      1.1  christos         default:
    761      1.1  christos 
    762      1.1  christos             printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
    763      1.1  christos             return (-1);
    764      1.1  christos         }
    765      1.1  christos         break;
    766      1.1  christos 
    767      1.1  christos     case 'T':   /* Create a ACPI table template file */
    768      1.1  christos 
    769      1.1  christos         Gbl_DoTemplates = TRUE;
    770      1.1  christos         break;
    771      1.1  christos 
    772      1.1  christos     case 'v':   /* Version and verbosity settings */
    773      1.1  christos 
    774      1.1  christos         switch (AcpiGbl_Optarg[0])
    775      1.1  christos         {
    776      1.1  christos         case '^':
    777      1.1  christos 
    778      1.1  christos             printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
    779      1.1  christos             exit (0);
    780      1.1  christos 
    781      1.1  christos         case 'a':
    782      1.1  christos 
    783      1.1  christos             /* Disable all error/warning/remark messages */
    784      1.1  christos 
    785      1.1  christos             Gbl_NoErrors = TRUE;
    786      1.1  christos             break;
    787      1.1  christos 
    788      1.2  christos         case 'd':
    789      1.2  christos 
    790      1.2  christos             printf ("%s Build date/time: %s %s\n",
    791      1.2  christos                 ASL_COMPILER_NAME, ASL_BUILD_DATE, ASL_BUILD_TIME);
    792      1.2  christos             exit (0);
    793      1.2  christos 
    794      1.1  christos         case 'e':
    795      1.1  christos 
    796      1.1  christos             /* Disable all warning/remark messages (errors only) */
    797      1.1  christos 
    798      1.1  christos             Gbl_DisplayRemarks = FALSE;
    799      1.1  christos             Gbl_DisplayWarnings = FALSE;
    800      1.1  christos             break;
    801      1.1  christos 
    802      1.1  christos         case 'i':
    803      1.1  christos             /*
    804      1.1  christos              * Support for integrated development environment(s).
    805      1.1  christos              *
    806      1.1  christos              * 1) No compiler signon
    807      1.1  christos              * 2) Send stderr messages to stdout
    808      1.1  christos              * 3) Less verbose error messages (single line only for each)
    809      1.1  christos              * 4) Error/warning messages are formatted appropriately to
    810      1.1  christos              *    be recognized by MS Visual Studio
    811      1.1  christos              */
    812      1.1  christos             Gbl_VerboseErrors = FALSE;
    813      1.1  christos             Gbl_DoSignon = FALSE;
    814      1.1  christos             Gbl_Files[ASL_FILE_STDERR].Handle = stdout;
    815      1.1  christos             break;
    816      1.1  christos 
    817      1.1  christos         case 'o':
    818      1.1  christos 
    819      1.1  christos             Gbl_DisplayOptimizations = TRUE;
    820      1.1  christos             break;
    821      1.1  christos 
    822      1.1  christos         case 'r':
    823      1.1  christos 
    824      1.1  christos             Gbl_DisplayRemarks = FALSE;
    825      1.1  christos             break;
    826      1.1  christos 
    827      1.1  christos         case 's':
    828      1.1  christos 
    829      1.1  christos             Gbl_DoSignon = FALSE;
    830      1.1  christos             break;
    831      1.1  christos 
    832      1.1  christos         case 't':
    833      1.1  christos 
    834      1.1  christos             Gbl_VerboseTemplates = TRUE;
    835      1.1  christos             break;
    836      1.1  christos 
    837      1.1  christos         case 'w':
    838      1.1  christos 
    839      1.1  christos             /* Get the required argument */
    840      1.1  christos 
    841      1.1  christos             if (AcpiGetoptArgument (argc, argv))
    842      1.1  christos             {
    843      1.1  christos                 return (-1);
    844      1.1  christos             }
    845      1.1  christos 
    846      1.1  christos             Status = AslDisableException (AcpiGbl_Optarg);
    847      1.1  christos             if (ACPI_FAILURE (Status))
    848      1.1  christos             {
    849      1.1  christos                 return (-1);
    850      1.1  christos             }
    851      1.1  christos             break;
    852      1.1  christos 
    853      1.1  christos         default:
    854      1.1  christos 
    855      1.1  christos             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
    856      1.1  christos             return (-1);
    857      1.1  christos         }
    858      1.1  christos         break;
    859      1.1  christos 
    860      1.1  christos     case 'w': /* Set warning levels */
    861      1.1  christos 
    862      1.1  christos         switch (AcpiGbl_Optarg[0])
    863      1.1  christos         {
    864      1.1  christos         case '1':
    865      1.1  christos 
    866      1.1  christos             Gbl_WarningLevel = ASL_WARNING;
    867      1.1  christos             break;
    868      1.1  christos 
    869      1.1  christos         case '2':
    870      1.1  christos 
    871      1.1  christos             Gbl_WarningLevel = ASL_WARNING2;
    872      1.1  christos             break;
    873      1.1  christos 
    874      1.1  christos         case '3':
    875      1.1  christos 
    876      1.1  christos             Gbl_WarningLevel = ASL_WARNING3;
    877      1.1  christos             break;
    878      1.1  christos 
    879      1.1  christos         case 'e':
    880      1.1  christos 
    881      1.1  christos             Gbl_WarningsAsErrors = TRUE;
    882      1.1  christos             break;
    883      1.1  christos 
    884      1.1  christos         default:
    885      1.1  christos 
    886      1.1  christos             printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
    887      1.1  christos             return (-1);
    888      1.1  christos         }
    889      1.1  christos         break;
    890      1.1  christos 
    891      1.1  christos     case 'x':   /* Set debug print output level */
    892      1.1  christos 
    893      1.1  christos         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
    894      1.1  christos         break;
    895      1.1  christos 
    896      1.1  christos     case 'z':
    897      1.1  christos 
    898      1.1  christos         Gbl_UseOriginalCompilerId = TRUE;
    899      1.1  christos         break;
    900      1.1  christos 
    901      1.1  christos     default:
    902      1.1  christos 
    903      1.1  christos         return (-1);
    904      1.1  christos     }
    905      1.1  christos 
    906      1.1  christos     return (0);
    907      1.1  christos }
    908      1.1  christos 
    909      1.1  christos 
    910      1.1  christos /*******************************************************************************
    911      1.1  christos  *
    912      1.1  christos  * FUNCTION:    AslMergeOptionTokens
    913      1.1  christos  *
    914      1.1  christos  * PARAMETERS:  InBuffer            - Input containing an option string
    915      1.1  christos  *              OutBuffer           - Merged output buffer
    916      1.1  christos  *
    917      1.1  christos  * RETURN:      None
    918      1.1  christos  *
    919      1.1  christos  * DESCRIPTION: Remove all whitespace from an option string.
    920      1.1  christos  *
    921      1.1  christos  ******************************************************************************/
    922      1.1  christos 
    923      1.1  christos static void
    924      1.1  christos AslMergeOptionTokens (
    925      1.1  christos     char                    *InBuffer,
    926      1.1  christos     char                    *OutBuffer)
    927      1.1  christos {
    928      1.1  christos     char                    *Token;
    929      1.1  christos 
    930      1.1  christos 
    931      1.1  christos     *OutBuffer = 0;
    932      1.1  christos 
    933      1.1  christos     Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
    934      1.1  christos     while (Token)
    935      1.1  christos     {
    936      1.1  christos         strcat (OutBuffer, Token);
    937      1.1  christos         Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
    938      1.1  christos     }
    939      1.1  christos }
    940      1.1  christos 
    941      1.1  christos 
    942      1.1  christos /*******************************************************************************
    943      1.1  christos  *
    944      1.1  christos  * FUNCTION:    AslDoResponseFile
    945      1.1  christos  *
    946      1.1  christos  * PARAMETERS:  Filename        - Name of the response file
    947      1.1  christos  *
    948      1.1  christos  * RETURN:      Status
    949      1.1  christos  *
    950      1.1  christos  * DESCRIPTION: Open a response file and process all options within.
    951      1.1  christos  *
    952      1.1  christos  ******************************************************************************/
    953      1.1  christos 
    954      1.1  christos static int
    955      1.1  christos AslDoResponseFile (
    956      1.1  christos     char                    *Filename)
    957      1.1  christos {
    958      1.1  christos     char                    *argv = StringBuffer2;
    959      1.1  christos     FILE                    *ResponseFile;
    960      1.1  christos     int                     OptStatus = 0;
    961      1.1  christos     int                     Opterr;
    962      1.1  christos     int                     Optind;
    963      1.1  christos 
    964      1.1  christos 
    965      1.1  christos     ResponseFile = fopen (Filename, "r");
    966      1.1  christos     if (!ResponseFile)
    967      1.1  christos     {
    968      1.1  christos         printf ("Could not open command file %s, %s\n",
    969      1.1  christos             Filename, strerror (errno));
    970      1.1  christos         return (-1);
    971      1.1  christos     }
    972      1.1  christos 
    973      1.1  christos     /* Must save the current GetOpt globals */
    974      1.1  christos 
    975      1.1  christos     Opterr = AcpiGbl_Opterr;
    976      1.1  christos     Optind = AcpiGbl_Optind;
    977      1.1  christos 
    978      1.1  christos     /*
    979      1.1  christos      * Process all lines in the response file. There must be one complete
    980      1.1  christos      * option per line
    981      1.1  christos      */
    982      1.1  christos     while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
    983      1.1  christos     {
    984      1.1  christos         /* Compress all tokens, allowing us to use a single argv entry */
    985      1.1  christos 
    986      1.1  christos         AslMergeOptionTokens (StringBuffer, StringBuffer2);
    987      1.1  christos 
    988      1.1  christos         /* Process the option */
    989      1.1  christos 
    990      1.1  christos         AcpiGbl_Opterr = 0;
    991      1.1  christos         AcpiGbl_Optind = 0;
    992      1.1  christos 
    993      1.1  christos         OptStatus = AslDoOptions (1, &argv, TRUE);
    994      1.1  christos         if (OptStatus)
    995      1.1  christos         {
    996      1.1  christos             printf ("Invalid option in command file %s: %s\n",
    997      1.1  christos                 Filename, StringBuffer);
    998      1.1  christos             break;
    999      1.1  christos         }
   1000      1.1  christos     }
   1001      1.1  christos 
   1002      1.1  christos     /* Restore the GetOpt globals */
   1003      1.1  christos 
   1004      1.1  christos     AcpiGbl_Opterr = Opterr;
   1005      1.1  christos     AcpiGbl_Optind = Optind;
   1006      1.1  christos 
   1007      1.1  christos     fclose (ResponseFile);
   1008      1.1  christos     return (OptStatus);
   1009      1.1  christos }
   1010