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