Home | History | Annotate | Line # | Download | only in compiler
asloptions.c revision 1.6.2.3
      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.6.2.1  pgoyette  * Copyright (C) 2000 - 2018, 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.4  christos #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.1  christos 
     74      1.1  christos /*******************************************************************************
     75      1.1  christos  *
     76      1.1  christos  * FUNCTION:    AslCommandLine
     77      1.1  christos  *
     78      1.1  christos  * PARAMETERS:  argc/argv
     79      1.1  christos  *
     80      1.1  christos  * RETURN:      Last argv index
     81      1.1  christos  *
     82      1.1  christos  * DESCRIPTION: Command line processing
     83      1.1  christos  *
     84      1.1  christos  ******************************************************************************/
     85      1.1  christos 
     86      1.1  christos int
     87      1.1  christos AslCommandLine (
     88      1.1  christos     int                     argc,
     89      1.1  christos     char                    **argv)
     90      1.1  christos {
     91      1.1  christos     int                     BadCommandLine = 0;
     92      1.1  christos     ACPI_STATUS             Status;
     93      1.1  christos 
     94      1.1  christos 
     95      1.1  christos     /* Minimum command line contains at least the command and an input file */
     96      1.1  christos 
     97      1.1  christos     if (argc < 2)
     98      1.1  christos     {
     99      1.1  christos         Usage ();
    100      1.1  christos         exit (1);
    101      1.1  christos     }
    102      1.1  christos 
    103      1.1  christos     /* Process all command line options */
    104      1.1  christos 
    105      1.1  christos     BadCommandLine = AslDoOptions (argc, argv, FALSE);
    106      1.1  christos 
    107  1.6.2.3  pgoyette     if (AslGbl_DoTemplates)
    108      1.1  christos     {
    109      1.2  christos         Status = DtCreateTemplates (argv);
    110      1.1  christos         if (ACPI_FAILURE (Status))
    111      1.1  christos         {
    112      1.1  christos             exit (-1);
    113      1.1  christos         }
    114      1.1  christos         exit (1);
    115      1.1  christos     }
    116      1.1  christos 
    117      1.1  christos     /* Next parameter must be the input filename */
    118      1.1  christos 
    119      1.1  christos     if (!argv[AcpiGbl_Optind] &&
    120      1.5  christos         !AcpiGbl_DisasmFlag)
    121      1.1  christos     {
    122      1.1  christos         printf ("Missing input filename\n");
    123      1.1  christos         BadCommandLine = TRUE;
    124      1.1  christos     }
    125      1.1  christos 
    126  1.6.2.3  pgoyette     if (AslGbl_DoSignon)
    127      1.1  christos     {
    128      1.1  christos         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
    129  1.6.2.3  pgoyette         if (AslGbl_IgnoreErrors)
    130      1.1  christos         {
    131      1.1  christos             printf ("Ignoring all errors, forcing AML file generation\n\n");
    132      1.1  christos         }
    133      1.1  christos     }
    134      1.1  christos 
    135      1.1  christos     if (BadCommandLine)
    136      1.1  christos     {
    137      1.1  christos         printf ("Use -h option for help information\n");
    138      1.1  christos         exit (1);
    139      1.1  christos     }
    140      1.1  christos 
    141      1.1  christos     return (AcpiGbl_Optind);
    142      1.1  christos }
    143      1.1  christos 
    144      1.1  christos 
    145      1.1  christos /*******************************************************************************
    146      1.1  christos  *
    147      1.1  christos  * FUNCTION:    AslDoOptions
    148      1.1  christos  *
    149      1.1  christos  * PARAMETERS:  argc/argv           - Standard argc/argv
    150      1.1  christos  *              IsResponseFile      - TRUE if executing a response file.
    151      1.1  christos  *
    152      1.1  christos  * RETURN:      Status
    153      1.1  christos  *
    154      1.1  christos  * DESCRIPTION: Command line option processing
    155      1.1  christos  *
    156      1.1  christos  ******************************************************************************/
    157      1.1  christos 
    158      1.1  christos static int
    159      1.1  christos AslDoOptions (
    160      1.1  christos     int                     argc,
    161      1.1  christos     char                    **argv,
    162      1.1  christos     BOOLEAN                 IsResponseFile)
    163      1.1  christos {
    164      1.1  christos     ACPI_STATUS             Status;
    165      1.1  christos     UINT32                  j;
    166      1.1  christos 
    167      1.1  christos 
    168      1.1  christos     /* Get the command line options */
    169      1.1  christos 
    170      1.2  christos     while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
    171      1.1  christos     {
    172      1.1  christos     case '@':   /* Begin a response file */
    173      1.1  christos 
    174      1.1  christos         if (IsResponseFile)
    175      1.1  christos         {
    176      1.1  christos             printf ("Nested command files are not supported\n");
    177      1.1  christos             return (-1);
    178      1.1  christos         }
    179      1.1  christos 
    180      1.1  christos         if (AslDoResponseFile (AcpiGbl_Optarg))
    181      1.1  christos         {
    182      1.1  christos             return (-1);
    183      1.1  christos         }
    184      1.1  christos         break;
    185      1.1  christos 
    186      1.2  christos     case 'a':   /* Debug options */
    187      1.2  christos 
    188      1.2  christos         switch (AcpiGbl_Optarg[0])
    189      1.2  christos         {
    190      1.2  christos         case 'r':
    191      1.2  christos 
    192  1.6.2.3  pgoyette             AslGbl_EnableReferenceTypechecking = TRUE;
    193      1.2  christos             break;
    194      1.2  christos 
    195      1.2  christos         default:
    196      1.2  christos 
    197      1.2  christos             printf ("Unknown option: -a%s\n", AcpiGbl_Optarg);
    198      1.2  christos             return (-1);
    199      1.2  christos         }
    200      1.2  christos 
    201      1.2  christos         break;
    202      1.2  christos 
    203      1.2  christos 
    204      1.2  christos     case 'b':   /* Debug options */
    205      1.1  christos 
    206      1.1  christos         switch (AcpiGbl_Optarg[0])
    207      1.1  christos         {
    208      1.4  christos 
    209      1.4  christos         case 'c':
    210      1.4  christos 
    211      1.4  christos             printf ("Debug ASL to ASL+ conversion\n");
    212      1.4  christos 
    213  1.6.2.3  pgoyette             AslGbl_DoAslConversion = TRUE;
    214  1.6.2.3  pgoyette             AslGbl_FoldConstants = FALSE;
    215  1.6.2.3  pgoyette             AslGbl_IntegerOptimizationFlag = FALSE;
    216  1.6.2.3  pgoyette             AslGbl_ReferenceOptimizationFlag = FALSE;
    217  1.6.2.3  pgoyette             AslGbl_OptimizeTrivialParseNodes = FALSE;
    218  1.6.2.1  pgoyette             AcpiGbl_CaptureComments = TRUE;
    219      1.4  christos             AcpiGbl_DoDisassemblerOptimizations = FALSE;
    220      1.4  christos             AcpiGbl_DebugAslConversion = TRUE;
    221      1.4  christos             AcpiGbl_DmEmitExternalOpcodes = TRUE;
    222  1.6.2.3  pgoyette             AslGbl_DoExternalsInPlace = TRUE;
    223      1.4  christos 
    224      1.4  christos             return (0);
    225      1.4  christos 
    226      1.1  christos         case 'f':
    227      1.1  christos 
    228      1.1  christos             AslCompilerdebug = 1; /* same as yydebug */
    229      1.1  christos             DtParserdebug = 1;
    230      1.1  christos             PrParserdebug = 1;
    231  1.6.2.3  pgoyette             AslGbl_DebugFlag = TRUE;
    232  1.6.2.3  pgoyette             AslGbl_KeepPreprocessorTempFile = TRUE;
    233      1.2  christos             break;
    234      1.2  christos 
    235      1.2  christos         case 'p':   /* Prune ASL parse tree */
    236      1.2  christos 
    237      1.2  christos             /* Get the required argument */
    238      1.2  christos 
    239      1.2  christos             if (AcpiGetoptArgument (argc, argv))
    240      1.2  christos             {
    241      1.2  christos                 return (-1);
    242      1.2  christos             }
    243      1.2  christos 
    244  1.6.2.3  pgoyette             AslGbl_PruneParseTree = TRUE;
    245  1.6.2.3  pgoyette             AslGbl_PruneDepth = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
    246      1.2  christos             break;
    247      1.2  christos 
    248      1.2  christos         case 's':
    249      1.2  christos 
    250  1.6.2.3  pgoyette             AslGbl_DebugFlag = TRUE;
    251      1.1  christos             break;
    252      1.1  christos 
    253      1.1  christos         case 't':
    254      1.1  christos 
    255      1.2  christos             /* Get the required argument */
    256      1.2  christos 
    257      1.2  christos             if (AcpiGetoptArgument (argc, argv))
    258      1.2  christos             {
    259      1.2  christos                 return (-1);
    260      1.2  christos             }
    261      1.2  christos 
    262  1.6.2.3  pgoyette             AslGbl_PruneType = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
    263      1.1  christos             break;
    264      1.1  christos 
    265      1.1  christos         default:
    266      1.1  christos 
    267      1.1  christos             printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
    268      1.1  christos             return (-1);
    269      1.1  christos         }
    270      1.1  christos 
    271      1.1  christos         break;
    272      1.1  christos 
    273      1.1  christos     case 'c':
    274      1.1  christos 
    275      1.1  christos         switch (AcpiGbl_Optarg[0])
    276      1.1  christos         {
    277      1.4  christos 
    278      1.4  christos         case 'a':
    279      1.4  christos 
    280      1.4  christos             printf ("Convert ASL to ASL+ with comments\n");
    281  1.6.2.3  pgoyette             AslGbl_DoAslConversion = TRUE;
    282  1.6.2.3  pgoyette             AslGbl_FoldConstants = FALSE;
    283  1.6.2.3  pgoyette             AslGbl_IntegerOptimizationFlag = FALSE;
    284  1.6.2.3  pgoyette             AslGbl_ReferenceOptimizationFlag = FALSE;
    285  1.6.2.3  pgoyette             AslGbl_OptimizeTrivialParseNodes = FALSE;
    286  1.6.2.1  pgoyette             AcpiGbl_CaptureComments = TRUE;
    287      1.4  christos             AcpiGbl_DoDisassemblerOptimizations = FALSE;
    288      1.4  christos             AcpiGbl_DmEmitExternalOpcodes = TRUE;
    289  1.6.2.3  pgoyette             AslGbl_DoExternalsInPlace = TRUE;
    290      1.4  christos 
    291      1.4  christos             return (0);
    292      1.4  christos 
    293      1.1  christos         case 'r':
    294      1.1  christos 
    295  1.6.2.3  pgoyette             AslGbl_NoResourceChecking = TRUE;
    296      1.1  christos             break;
    297      1.1  christos 
    298      1.1  christos         default:
    299      1.1  christos 
    300      1.1  christos             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
    301      1.1  christos             return (-1);
    302      1.1  christos         }
    303      1.1  christos         break;
    304      1.1  christos 
    305      1.1  christos     case 'd':   /* Disassembler */
    306      1.1  christos 
    307      1.1  christos         switch (AcpiGbl_Optarg[0])
    308      1.1  christos         {
    309      1.1  christos         case '^':
    310      1.1  christos 
    311  1.6.2.3  pgoyette             AslGbl_DoCompile = FALSE;
    312      1.1  christos             break;
    313      1.1  christos 
    314      1.1  christos         case 'a':
    315      1.1  christos 
    316  1.6.2.3  pgoyette             AslGbl_DoCompile = FALSE;
    317  1.6.2.3  pgoyette             AslGbl_DisassembleAll = TRUE;
    318      1.1  christos             break;
    319      1.1  christos 
    320      1.1  christos         case 'b':   /* Do not convert buffers to resource descriptors */
    321      1.1  christos 
    322      1.1  christos             AcpiGbl_NoResourceDisassembly = TRUE;
    323      1.1  christos             break;
    324      1.1  christos 
    325      1.1  christos         case 'c':
    326      1.1  christos 
    327      1.1  christos             break;
    328      1.1  christos 
    329      1.2  christos         case 'f':
    330      1.2  christos 
    331      1.2  christos             AcpiGbl_ForceAmlDisassembly = TRUE;
    332      1.2  christos             break;
    333      1.2  christos 
    334      1.2  christos         case 'l':   /* Use legacy ASL code (not ASL+) for disassembly */
    335      1.2  christos 
    336  1.6.2.3  pgoyette             AslGbl_DoCompile = FALSE;
    337      1.2  christos             AcpiGbl_CstyleDisassembly = FALSE;
    338      1.2  christos             break;
    339      1.2  christos 
    340      1.1  christos         default:
    341      1.1  christos 
    342      1.1  christos             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
    343      1.1  christos             return (-1);
    344      1.1  christos         }
    345      1.1  christos 
    346      1.5  christos         AcpiGbl_DisasmFlag = TRUE;
    347      1.1  christos         break;
    348      1.1  christos 
    349      1.1  christos     case 'D':   /* Define a symbol */
    350      1.1  christos 
    351      1.1  christos         PrAddDefine (AcpiGbl_Optarg, NULL, TRUE);
    352      1.1  christos         break;
    353      1.1  christos 
    354      1.1  christos     case 'e':   /* External files for disassembler */
    355      1.1  christos 
    356      1.1  christos         /* Get entire list of external files */
    357      1.1  christos 
    358      1.1  christos         AcpiGbl_Optind--;
    359      1.2  christos         argv[AcpiGbl_Optind] = AcpiGbl_Optarg;
    360      1.1  christos 
    361      1.1  christos         while (argv[AcpiGbl_Optind] &&
    362      1.1  christos               (argv[AcpiGbl_Optind][0] != '-'))
    363      1.1  christos         {
    364      1.1  christos             Status = AcpiDmAddToExternalFileList (argv[AcpiGbl_Optind]);
    365      1.1  christos             if (ACPI_FAILURE (Status))
    366      1.1  christos             {
    367      1.2  christos                 printf ("Could not add %s to external list\n",
    368      1.2  christos                     argv[AcpiGbl_Optind]);
    369      1.1  christos                 return (-1);
    370      1.1  christos             }
    371      1.1  christos 
    372      1.1  christos             AcpiGbl_Optind++;
    373      1.1  christos         }
    374      1.1  christos         break;
    375      1.1  christos 
    376      1.1  christos     case 'f':
    377      1.1  christos 
    378      1.1  christos         switch (AcpiGbl_Optarg[0])
    379      1.1  christos         {
    380      1.1  christos         case '^':   /* Ignore errors and force creation of aml file */
    381      1.1  christos 
    382  1.6.2.3  pgoyette             AslGbl_IgnoreErrors = TRUE;
    383      1.1  christos             break;
    384      1.1  christos 
    385      1.1  christos         case 'e':   /* Disassembler: Get external declaration file */
    386      1.1  christos 
    387      1.1  christos             if (AcpiGetoptArgument (argc, argv))
    388      1.1  christos             {
    389      1.1  christos                 return (-1);
    390      1.1  christos             }
    391      1.1  christos 
    392  1.6.2.3  pgoyette             AslGbl_ExternalRefFilename = AcpiGbl_Optarg;
    393      1.1  christos             break;
    394      1.1  christos 
    395      1.1  christos         default:
    396      1.1  christos 
    397      1.1  christos             printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
    398      1.1  christos             return (-1);
    399      1.1  christos         }
    400      1.1  christos         break;
    401      1.1  christos 
    402      1.1  christos     case 'G':
    403      1.1  christos 
    404  1.6.2.3  pgoyette         AslGbl_CompileGeneric = TRUE;
    405      1.1  christos         break;
    406      1.1  christos 
    407      1.1  christos     case 'g':   /* Get all ACPI tables */
    408      1.1  christos 
    409      1.2  christos         printf ("-g option is deprecated, use acpidump utility instead\n");
    410      1.2  christos         exit (1);
    411      1.1  christos 
    412      1.1  christos     case 'h':
    413      1.1  christos 
    414      1.1  christos         switch (AcpiGbl_Optarg[0])
    415      1.1  christos         {
    416      1.1  christos         case '^':
    417      1.1  christos 
    418      1.1  christos             Usage ();
    419      1.1  christos             exit (0);
    420      1.1  christos 
    421      1.1  christos         case 'c':
    422      1.1  christos 
    423      1.1  christos             UtDisplayConstantOpcodes ();
    424      1.1  christos             exit (0);
    425      1.1  christos 
    426      1.2  christos         case 'd':
    427      1.2  christos 
    428      1.2  christos             AslDisassemblyHelp ();
    429      1.2  christos             exit (0);
    430      1.2  christos 
    431      1.1  christos         case 'f':
    432      1.1  christos 
    433      1.1  christos             AslFilenameHelp ();
    434      1.1  christos             exit (0);
    435      1.1  christos 
    436      1.1  christos         case 'r':
    437      1.1  christos 
    438      1.1  christos             /* reserved names */
    439      1.1  christos 
    440      1.1  christos             ApDisplayReservedNames ();
    441      1.1  christos             exit (0);
    442      1.1  christos 
    443      1.1  christos         case 't':
    444      1.1  christos 
    445      1.1  christos             UtDisplaySupportedTables ();
    446      1.1  christos             exit (0);
    447      1.1  christos 
    448      1.1  christos         default:
    449      1.1  christos 
    450      1.1  christos             printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
    451      1.1  christos             return (-1);
    452      1.1  christos         }
    453      1.1  christos 
    454      1.1  christos     case 'I':   /* Add an include file search directory */
    455      1.1  christos 
    456      1.1  christos         FlAddIncludeDirectory (AcpiGbl_Optarg);
    457      1.1  christos         break;
    458      1.1  christos 
    459      1.1  christos     case 'i':   /* Output AML as an include file */
    460      1.1  christos 
    461      1.1  christos         switch (AcpiGbl_Optarg[0])
    462      1.1  christos         {
    463      1.1  christos         case 'a':
    464      1.1  christos 
    465      1.1  christos             /* Produce assembly code include file */
    466      1.1  christos 
    467  1.6.2.3  pgoyette             AslGbl_AsmIncludeOutputFlag = TRUE;
    468      1.1  christos             break;
    469      1.1  christos 
    470      1.1  christos         case 'c':
    471      1.1  christos 
    472      1.1  christos             /* Produce C include file */
    473      1.1  christos 
    474  1.6.2.3  pgoyette             AslGbl_C_IncludeOutputFlag = TRUE;
    475      1.1  christos             break;
    476      1.1  christos 
    477      1.1  christos         case 'n':
    478      1.1  christos 
    479      1.1  christos             /* Compiler/Disassembler: Ignore the NOOP operator */
    480      1.1  christos 
    481      1.1  christos             AcpiGbl_IgnoreNoopOperator = TRUE;
    482      1.1  christos             break;
    483      1.1  christos 
    484      1.1  christos         default:
    485      1.1  christos 
    486      1.1  christos             printf ("Unknown option: -i%s\n", AcpiGbl_Optarg);
    487      1.1  christos             return (-1);
    488      1.1  christos         }
    489      1.1  christos         break;
    490      1.1  christos 
    491      1.1  christos     case 'l':   /* Listing files */
    492      1.1  christos 
    493      1.1  christos         switch (AcpiGbl_Optarg[0])
    494      1.1  christos         {
    495      1.1  christos         case '^':
    496      1.1  christos 
    497      1.1  christos             /* Produce listing file (Mixed source/aml) */
    498      1.1  christos 
    499  1.6.2.3  pgoyette             AslGbl_ListingFlag = TRUE;
    500      1.2  christos             AcpiGbl_DmOpt_Listing = TRUE;
    501      1.1  christos             break;
    502      1.1  christos 
    503      1.1  christos         case 'i':
    504      1.1  christos 
    505      1.1  christos             /* Produce preprocessor output file */
    506      1.1  christos 
    507  1.6.2.3  pgoyette             AslGbl_PreprocessorOutputFlag = TRUE;
    508      1.1  christos             break;
    509      1.1  christos 
    510      1.2  christos         case 'm':
    511      1.2  christos 
    512      1.2  christos             /* Produce hardware map summary file */
    513      1.2  christos 
    514  1.6.2.3  pgoyette             AslGbl_MapfileFlag = TRUE;
    515      1.2  christos             break;
    516      1.2  christos 
    517      1.1  christos         case 'n':
    518      1.1  christos 
    519      1.1  christos             /* Produce namespace file */
    520      1.1  christos 
    521  1.6.2.3  pgoyette             AslGbl_NsOutputFlag = TRUE;
    522      1.1  christos             break;
    523      1.1  christos 
    524      1.1  christos         case 's':
    525      1.1  christos 
    526      1.1  christos             /* Produce combined source file */
    527      1.1  christos 
    528  1.6.2.3  pgoyette             AslGbl_SourceOutputFlag = TRUE;
    529      1.1  christos             break;
    530      1.1  christos 
    531      1.2  christos         case 'x':
    532      1.2  christos 
    533      1.2  christos             /* Produce cross-reference file */
    534      1.2  christos 
    535  1.6.2.3  pgoyette             AslGbl_CrossReferenceOutput = TRUE;
    536      1.2  christos             break;
    537      1.2  christos 
    538      1.1  christos         default:
    539      1.1  christos 
    540      1.1  christos             printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
    541      1.1  christos             return (-1);
    542      1.1  christos         }
    543      1.1  christos         break;
    544      1.1  christos 
    545      1.1  christos     case 'm':   /* Set line buffer size */
    546      1.1  christos 
    547  1.6.2.3  pgoyette         AslGbl_LineBufferSize = (UINT32) strtoul (AcpiGbl_Optarg, NULL, 0) * 1024;
    548  1.6.2.3  pgoyette         if (AslGbl_LineBufferSize < ASL_DEFAULT_LINE_BUFFER_SIZE)
    549      1.1  christos         {
    550  1.6.2.3  pgoyette             AslGbl_LineBufferSize = ASL_DEFAULT_LINE_BUFFER_SIZE;
    551      1.1  christos         }
    552  1.6.2.3  pgoyette         printf ("Line Buffer Size: %u\n", AslGbl_LineBufferSize);
    553      1.1  christos         break;
    554      1.1  christos 
    555      1.1  christos     case 'n':   /* Parse only */
    556      1.1  christos 
    557  1.6.2.3  pgoyette         AslGbl_ParseOnlyFlag = TRUE;
    558      1.1  christos         break;
    559      1.1  christos 
    560      1.1  christos     case 'o':   /* Control compiler AML optimizations */
    561      1.1  christos 
    562      1.1  christos         switch (AcpiGbl_Optarg[0])
    563      1.1  christos         {
    564      1.1  christos         case 'a':
    565      1.1  christos 
    566      1.1  christos             /* Disable all optimizations */
    567      1.1  christos 
    568  1.6.2.3  pgoyette             AslGbl_FoldConstants = FALSE;
    569  1.6.2.3  pgoyette             AslGbl_IntegerOptimizationFlag = FALSE;
    570  1.6.2.3  pgoyette             AslGbl_ReferenceOptimizationFlag = FALSE;
    571  1.6.2.3  pgoyette             AslGbl_OptimizeTrivialParseNodes = FALSE;
    572      1.4  christos 
    573      1.1  christos             break;
    574      1.1  christos 
    575      1.2  christos         case 'c':
    576      1.2  christos 
    577      1.2  christos             /* Display compile time(s) */
    578      1.2  christos 
    579  1.6.2.3  pgoyette             AslGbl_CompileTimesFlag = TRUE;
    580      1.2  christos             break;
    581      1.2  christos 
    582      1.2  christos         case 'd':
    583      1.2  christos 
    584      1.2  christos             /* Disable disassembler code optimizations */
    585      1.2  christos 
    586      1.2  christos             AcpiGbl_DoDisassemblerOptimizations = FALSE;
    587      1.2  christos             break;
    588      1.2  christos 
    589      1.2  christos         case 'e':
    590      1.2  christos 
    591      1.4  christos             /* Disassembler: Emit embedded external operators */
    592      1.4  christos 
    593      1.4  christos             AcpiGbl_DmEmitExternalOpcodes = TRUE;
    594      1.4  christos             break;
    595      1.2  christos 
    596      1.4  christos         case 'E':
    597      1.2  christos 
    598      1.4  christos             /*
    599      1.4  christos              * iASL: keep External opcodes in place.
    600      1.4  christos              * No affect if Gbl_DoExternals is false.
    601      1.4  christos              */
    602      1.2  christos 
    603  1.6.2.3  pgoyette             AslGbl_DoExternalsInPlace = TRUE;
    604      1.2  christos             break;
    605      1.2  christos 
    606      1.1  christos         case 'f':
    607      1.1  christos 
    608      1.1  christos             /* Disable folding on "normal" expressions */
    609      1.1  christos 
    610  1.6.2.3  pgoyette             AslGbl_FoldConstants = FALSE;
    611      1.1  christos             break;
    612      1.1  christos 
    613      1.1  christos         case 'i':
    614      1.1  christos 
    615      1.1  christos             /* Disable integer optimization to constants */
    616      1.1  christos 
    617  1.6.2.3  pgoyette             AslGbl_IntegerOptimizationFlag = FALSE;
    618      1.1  christos             break;
    619      1.1  christos 
    620      1.1  christos         case 'n':
    621      1.1  christos 
    622      1.1  christos             /* Disable named reference optimization */
    623      1.1  christos 
    624  1.6.2.3  pgoyette             AslGbl_ReferenceOptimizationFlag = FALSE;
    625      1.1  christos             break;
    626      1.1  christos 
    627      1.1  christos         case 't':
    628      1.1  christos 
    629      1.2  christos             /* Disable heavy typechecking */
    630      1.1  christos 
    631  1.6.2.3  pgoyette             AslGbl_DoTypechecking = FALSE;
    632      1.1  christos             break;
    633      1.1  christos 
    634      1.1  christos         default:
    635      1.1  christos 
    636      1.1  christos             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
    637      1.1  christos             return (-1);
    638      1.1  christos         }
    639      1.1  christos         break;
    640      1.1  christos 
    641      1.1  christos     case 'P':   /* Preprocessor options */
    642      1.1  christos 
    643      1.1  christos         switch (AcpiGbl_Optarg[0])
    644      1.1  christos         {
    645      1.1  christos         case '^':   /* Proprocess only, emit (.i) file */
    646      1.1  christos 
    647  1.6.2.3  pgoyette             AslGbl_PreprocessOnly = TRUE;
    648  1.6.2.3  pgoyette             AslGbl_PreprocessorOutputFlag = TRUE;
    649      1.1  christos             break;
    650      1.1  christos 
    651      1.1  christos         case 'n':   /* Disable preprocessor */
    652      1.1  christos 
    653  1.6.2.3  pgoyette             AslGbl_PreprocessFlag = FALSE;
    654      1.1  christos             break;
    655      1.1  christos 
    656      1.1  christos         default:
    657      1.1  christos 
    658      1.1  christos             printf ("Unknown option: -P%s\n", AcpiGbl_Optarg);
    659      1.1  christos             return (-1);
    660      1.1  christos         }
    661      1.1  christos         break;
    662      1.1  christos 
    663      1.1  christos     case 'p':   /* Override default AML output filename */
    664      1.1  christos 
    665  1.6.2.3  pgoyette         AslGbl_OutputFilenamePrefix = AcpiGbl_Optarg;
    666  1.6.2.3  pgoyette         UtConvertBackslashes (AslGbl_OutputFilenamePrefix);
    667  1.6.2.3  pgoyette         AslGbl_UseDefaultAmlFilename = FALSE;
    668      1.1  christos         break;
    669      1.1  christos 
    670      1.4  christos     case 'q':   /* ASL/ASl+ converter: compile only and leave badaml. */
    671      1.4  christos 
    672      1.4  christos         printf ("Convert ASL to ASL+ with comments\n");
    673  1.6.2.3  pgoyette         AslGbl_FoldConstants = FALSE;
    674  1.6.2.3  pgoyette         AslGbl_IntegerOptimizationFlag = FALSE;
    675  1.6.2.3  pgoyette         AslGbl_ReferenceOptimizationFlag = FALSE;
    676  1.6.2.3  pgoyette         AslGbl_OptimizeTrivialParseNodes = FALSE;
    677  1.6.2.3  pgoyette         AslGbl_DoExternalsInPlace = TRUE;
    678  1.6.2.1  pgoyette         AcpiGbl_CaptureComments = TRUE;
    679      1.4  christos         return (0);
    680      1.4  christos 
    681      1.1  christos     case 'r':   /* Override revision found in table header */
    682      1.1  christos 
    683  1.6.2.3  pgoyette         AslGbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
    684      1.1  christos         break;
    685      1.1  christos 
    686      1.1  christos     case 's':   /* Create AML in a source code file */
    687      1.1  christos 
    688      1.1  christos         switch (AcpiGbl_Optarg[0])
    689      1.1  christos         {
    690      1.1  christos         case 'a':
    691      1.1  christos 
    692      1.1  christos             /* Produce assembly code output file */
    693      1.1  christos 
    694  1.6.2.3  pgoyette             AslGbl_AsmOutputFlag = TRUE;
    695      1.1  christos             break;
    696      1.1  christos 
    697      1.1  christos         case 'c':
    698      1.1  christos 
    699      1.1  christos             /* Produce C hex output file */
    700      1.1  christos 
    701  1.6.2.3  pgoyette             AslGbl_C_OutputFlag = TRUE;
    702      1.1  christos             break;
    703      1.1  christos 
    704      1.1  christos         case 'o':
    705      1.1  christos 
    706      1.1  christos             /* Produce AML offset table in C */
    707      1.1  christos 
    708  1.6.2.3  pgoyette             AslGbl_C_OffsetTableFlag = TRUE;
    709      1.1  christos             break;
    710      1.1  christos 
    711      1.1  christos         default:
    712      1.1  christos 
    713      1.1  christos             printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
    714      1.1  christos             return (-1);
    715      1.1  christos         }
    716      1.1  christos         break;
    717      1.1  christos 
    718      1.1  christos     case 't':   /* Produce hex table output file */
    719      1.1  christos 
    720      1.1  christos         switch (AcpiGbl_Optarg[0])
    721      1.1  christos         {
    722      1.1  christos         case 'a':
    723      1.1  christos 
    724  1.6.2.3  pgoyette             AslGbl_HexOutputFlag = HEX_OUTPUT_ASM;
    725      1.1  christos             break;
    726      1.1  christos 
    727      1.1  christos         case 'c':
    728      1.1  christos 
    729  1.6.2.3  pgoyette             AslGbl_HexOutputFlag = HEX_OUTPUT_C;
    730      1.1  christos             break;
    731      1.1  christos 
    732      1.1  christos         case 's':
    733      1.1  christos 
    734  1.6.2.3  pgoyette             AslGbl_HexOutputFlag = HEX_OUTPUT_ASL;
    735      1.1  christos             break;
    736      1.1  christos 
    737      1.1  christos         default:
    738      1.1  christos 
    739      1.1  christos             printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
    740      1.1  christos             return (-1);
    741      1.1  christos         }
    742      1.1  christos         break;
    743      1.1  christos 
    744      1.1  christos     case 'T':   /* Create a ACPI table template file */
    745      1.1  christos 
    746  1.6.2.3  pgoyette         AslGbl_DoTemplates = TRUE;
    747      1.1  christos         break;
    748      1.1  christos 
    749      1.1  christos     case 'v':   /* Version and verbosity settings */
    750      1.1  christos 
    751      1.1  christos         switch (AcpiGbl_Optarg[0])
    752      1.1  christos         {
    753      1.1  christos         case '^':
    754      1.1  christos 
    755      1.1  christos             printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
    756      1.1  christos             exit (0);
    757      1.1  christos 
    758      1.1  christos         case 'a':
    759      1.1  christos 
    760      1.1  christos             /* Disable all error/warning/remark messages */
    761      1.1  christos 
    762  1.6.2.3  pgoyette             AslGbl_NoErrors = TRUE;
    763      1.1  christos             break;
    764      1.1  christos 
    765      1.2  christos         case 'd':
    766      1.2  christos 
    767      1.6  christos             printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
    768      1.6  christos             printf (ACPI_COMMON_BUILD_TIME);
    769      1.2  christos             exit (0);
    770      1.2  christos 
    771      1.1  christos         case 'e':
    772      1.1  christos 
    773      1.1  christos             /* Disable all warning/remark messages (errors only) */
    774      1.1  christos 
    775  1.6.2.3  pgoyette             AslGbl_DisplayRemarks = FALSE;
    776  1.6.2.3  pgoyette             AslGbl_DisplayWarnings = FALSE;
    777      1.1  christos             break;
    778      1.1  christos 
    779      1.1  christos         case 'i':
    780      1.1  christos             /*
    781      1.1  christos              * Support for integrated development environment(s).
    782      1.1  christos              *
    783      1.1  christos              * 1) No compiler signon
    784      1.1  christos              * 2) Send stderr messages to stdout
    785      1.1  christos              * 3) Less verbose error messages (single line only for each)
    786      1.1  christos              * 4) Error/warning messages are formatted appropriately to
    787      1.1  christos              *    be recognized by MS Visual Studio
    788      1.1  christos              */
    789  1.6.2.3  pgoyette             AslGbl_VerboseErrors = FALSE;
    790  1.6.2.3  pgoyette             AslGbl_DoSignon = FALSE;
    791  1.6.2.3  pgoyette             AslGbl_Files[ASL_FILE_STDERR].Handle = stdout;
    792      1.1  christos             break;
    793      1.1  christos 
    794      1.1  christos         case 'o':
    795      1.1  christos 
    796  1.6.2.3  pgoyette             AslGbl_DisplayOptimizations = TRUE;
    797      1.1  christos             break;
    798      1.1  christos 
    799      1.1  christos         case 'r':
    800      1.1  christos 
    801  1.6.2.3  pgoyette             AslGbl_DisplayRemarks = FALSE;
    802      1.1  christos             break;
    803      1.1  christos 
    804      1.1  christos         case 's':
    805      1.1  christos 
    806  1.6.2.3  pgoyette             AslGbl_DoSignon = FALSE;
    807      1.1  christos             break;
    808      1.1  christos 
    809      1.1  christos         case 't':
    810      1.1  christos 
    811  1.6.2.3  pgoyette             AslGbl_VerboseTemplates = TRUE;
    812      1.1  christos             break;
    813      1.1  christos 
    814      1.1  christos         case 'w':
    815      1.1  christos 
    816      1.1  christos             /* Get the required argument */
    817      1.1  christos 
    818      1.1  christos             if (AcpiGetoptArgument (argc, argv))
    819      1.1  christos             {
    820      1.1  christos                 return (-1);
    821      1.1  christos             }
    822      1.1  christos 
    823      1.1  christos             Status = AslDisableException (AcpiGbl_Optarg);
    824      1.1  christos             if (ACPI_FAILURE (Status))
    825      1.1  christos             {
    826      1.1  christos                 return (-1);
    827      1.1  christos             }
    828      1.1  christos             break;
    829      1.1  christos 
    830      1.5  christos         case 'x':
    831      1.5  christos 
    832      1.5  christos             /* Get the required argument */
    833      1.5  christos 
    834      1.5  christos             if (AcpiGetoptArgument (argc, argv))
    835      1.5  christos             {
    836      1.5  christos                 return (-1);
    837      1.5  christos             }
    838      1.5  christos 
    839      1.5  christos             Status = AslExpectException (AcpiGbl_Optarg);
    840      1.5  christos             if (ACPI_FAILURE (Status))
    841      1.5  christos             {
    842      1.5  christos                 return (-1);
    843      1.5  christos             }
    844      1.5  christos             break;
    845      1.5  christos 
    846      1.1  christos         default:
    847      1.1  christos 
    848      1.1  christos             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
    849      1.1  christos             return (-1);
    850      1.1  christos         }
    851      1.1  christos         break;
    852      1.1  christos 
    853      1.1  christos     case 'w': /* Set warning levels */
    854      1.1  christos 
    855      1.1  christos         switch (AcpiGbl_Optarg[0])
    856      1.1  christos         {
    857      1.1  christos         case '1':
    858      1.1  christos 
    859  1.6.2.3  pgoyette             AslGbl_WarningLevel = ASL_WARNING;
    860      1.1  christos             break;
    861      1.1  christos 
    862      1.1  christos         case '2':
    863      1.1  christos 
    864  1.6.2.3  pgoyette             AslGbl_WarningLevel = ASL_WARNING2;
    865      1.1  christos             break;
    866      1.1  christos 
    867      1.1  christos         case '3':
    868      1.1  christos 
    869  1.6.2.3  pgoyette             AslGbl_WarningLevel = ASL_WARNING3;
    870      1.1  christos             break;
    871      1.1  christos 
    872      1.1  christos         case 'e':
    873      1.1  christos 
    874  1.6.2.3  pgoyette             AslGbl_WarningsAsErrors = TRUE;
    875      1.1  christos             break;
    876      1.1  christos 
    877  1.6.2.3  pgoyette         case 'w':
    878  1.6.2.3  pgoyette 
    879  1.6.2.3  pgoyette             /* Get the required argument */
    880  1.6.2.3  pgoyette 
    881  1.6.2.3  pgoyette             if (AcpiGetoptArgument (argc, argv))
    882  1.6.2.3  pgoyette             {
    883  1.6.2.3  pgoyette                 return (-1);
    884  1.6.2.3  pgoyette             }
    885  1.6.2.3  pgoyette 
    886  1.6.2.3  pgoyette             Status = AslElevateException (AcpiGbl_Optarg);
    887  1.6.2.3  pgoyette             if (ACPI_FAILURE (Status))
    888  1.6.2.3  pgoyette             {
    889  1.6.2.3  pgoyette                 return (-1);
    890  1.6.2.3  pgoyette             }
    891  1.6.2.3  pgoyette             break;
    892  1.6.2.3  pgoyette 
    893  1.6.2.3  pgoyette 
    894      1.1  christos         default:
    895      1.1  christos 
    896      1.1  christos             printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
    897      1.1  christos             return (-1);
    898      1.1  christos         }
    899      1.1  christos         break;
    900      1.1  christos 
    901      1.1  christos     case 'x':   /* Set debug print output level */
    902      1.1  christos 
    903      1.1  christos         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
    904      1.1  christos         break;
    905      1.1  christos 
    906      1.1  christos     case 'z':
    907      1.1  christos 
    908  1.6.2.3  pgoyette         AslGbl_UseOriginalCompilerId = TRUE;
    909      1.1  christos         break;
    910      1.1  christos 
    911      1.1  christos     default:
    912      1.1  christos 
    913      1.1  christos         return (-1);
    914      1.1  christos     }
    915      1.1  christos 
    916      1.1  christos     return (0);
    917      1.1  christos }
    918      1.1  christos 
    919      1.1  christos 
    920      1.1  christos /*******************************************************************************
    921      1.1  christos  *
    922      1.1  christos  * FUNCTION:    AslMergeOptionTokens
    923      1.1  christos  *
    924      1.1  christos  * PARAMETERS:  InBuffer            - Input containing an option string
    925      1.1  christos  *              OutBuffer           - Merged output buffer
    926      1.1  christos  *
    927      1.1  christos  * RETURN:      None
    928      1.1  christos  *
    929      1.1  christos  * DESCRIPTION: Remove all whitespace from an option string.
    930      1.1  christos  *
    931      1.1  christos  ******************************************************************************/
    932      1.1  christos 
    933      1.1  christos static void
    934      1.1  christos AslMergeOptionTokens (
    935      1.1  christos     char                    *InBuffer,
    936      1.1  christos     char                    *OutBuffer)
    937      1.1  christos {
    938      1.1  christos     char                    *Token;
    939      1.1  christos 
    940      1.1  christos 
    941      1.1  christos     *OutBuffer = 0;
    942      1.1  christos 
    943      1.1  christos     Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
    944      1.1  christos     while (Token)
    945      1.1  christos     {
    946      1.1  christos         strcat (OutBuffer, Token);
    947      1.1  christos         Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
    948      1.1  christos     }
    949      1.1  christos }
    950      1.1  christos 
    951      1.1  christos 
    952      1.1  christos /*******************************************************************************
    953      1.1  christos  *
    954      1.1  christos  * FUNCTION:    AslDoResponseFile
    955      1.1  christos  *
    956      1.1  christos  * PARAMETERS:  Filename        - Name of the response file
    957      1.1  christos  *
    958      1.1  christos  * RETURN:      Status
    959      1.1  christos  *
    960      1.1  christos  * DESCRIPTION: Open a response file and process all options within.
    961      1.1  christos  *
    962      1.1  christos  ******************************************************************************/
    963      1.1  christos 
    964      1.1  christos static int
    965      1.1  christos AslDoResponseFile (
    966      1.1  christos     char                    *Filename)
    967      1.1  christos {
    968  1.6.2.3  pgoyette     char                    *argv = AslGbl_StringBuffer2;
    969      1.1  christos     FILE                    *ResponseFile;
    970      1.1  christos     int                     OptStatus = 0;
    971      1.1  christos     int                     Opterr;
    972      1.1  christos     int                     Optind;
    973      1.1  christos 
    974      1.1  christos 
    975      1.1  christos     ResponseFile = fopen (Filename, "r");
    976      1.1  christos     if (!ResponseFile)
    977      1.1  christos     {
    978      1.1  christos         printf ("Could not open command file %s, %s\n",
    979      1.1  christos             Filename, strerror (errno));
    980      1.1  christos         return (-1);
    981      1.1  christos     }
    982      1.1  christos 
    983      1.1  christos     /* Must save the current GetOpt globals */
    984      1.1  christos 
    985      1.1  christos     Opterr = AcpiGbl_Opterr;
    986      1.1  christos     Optind = AcpiGbl_Optind;
    987      1.1  christos 
    988      1.1  christos     /*
    989      1.1  christos      * Process all lines in the response file. There must be one complete
    990      1.1  christos      * option per line
    991      1.1  christos      */
    992  1.6.2.3  pgoyette     while (fgets (AslGbl_StringBuffer, ASL_STRING_BUFFER_SIZE, ResponseFile))
    993      1.1  christos     {
    994      1.1  christos         /* Compress all tokens, allowing us to use a single argv entry */
    995      1.1  christos 
    996  1.6.2.3  pgoyette         AslMergeOptionTokens (AslGbl_StringBuffer, AslGbl_StringBuffer2);
    997      1.1  christos 
    998      1.1  christos         /* Process the option */
    999      1.1  christos 
   1000      1.1  christos         AcpiGbl_Opterr = 0;
   1001      1.1  christos         AcpiGbl_Optind = 0;
   1002      1.1  christos 
   1003      1.1  christos         OptStatus = AslDoOptions (1, &argv, TRUE);
   1004      1.1  christos         if (OptStatus)
   1005      1.1  christos         {
   1006      1.1  christos             printf ("Invalid option in command file %s: %s\n",
   1007  1.6.2.3  pgoyette                 Filename, AslGbl_StringBuffer);
   1008      1.1  christos             break;
   1009      1.1  christos         }
   1010      1.1  christos     }
   1011      1.1  christos 
   1012      1.1  christos     /* Restore the GetOpt globals */
   1013      1.1  christos 
   1014      1.1  christos     AcpiGbl_Opterr = Opterr;
   1015      1.1  christos     AcpiGbl_Optind = Optind;
   1016      1.1  christos 
   1017      1.1  christos     fclose (ResponseFile);
   1018      1.1  christos     return (OptStatus);
   1019      1.1  christos }
   1020