Home | History | Annotate | Line # | Download | only in compiler
aslmain.c revision 1.1.1.3
      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>|ALL|* Create table template file(s) for <Sig>\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             DtParserdebug = 1;
    429             break;
    430 
    431         case 'p':
    432             AslCompilerdebug = 1; /* same as yydebug */
    433             DtParserdebug = 1;
    434             break;
    435 
    436         case 't':
    437             break;
    438 
    439         default:
    440             printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
    441             return (-1);
    442         }
    443 
    444         /* Produce debug output file */
    445 
    446         Gbl_DebugFlag = TRUE;
    447         break;
    448 
    449 
    450     case 'c':
    451         switch (AcpiGbl_Optarg[0])
    452         {
    453         case 'r':
    454             Gbl_NoResourceChecking = TRUE;
    455             break;
    456 
    457         default:
    458             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
    459             return (-1);
    460         }
    461         break;
    462 
    463 
    464     case 'd':
    465         switch (AcpiGbl_Optarg[0])
    466         {
    467         case '^':
    468             Gbl_DoCompile = FALSE;
    469             break;
    470 
    471         case 'a':
    472             Gbl_DoCompile = FALSE;
    473             Gbl_DisassembleAll = TRUE;
    474             break;
    475 
    476         case 'c':
    477             break;
    478 
    479         default:
    480             printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
    481             return (-1);
    482         }
    483 
    484         Gbl_DisasmFlag = TRUE;
    485         break;
    486 
    487 
    488     case 'e':
    489         Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg);
    490         if (ACPI_FAILURE (Status))
    491         {
    492             printf ("Could not add %s to external list\n", AcpiGbl_Optarg);
    493             return (-1);
    494         }
    495         break;
    496 
    497 
    498     case 'f':
    499 
    500         /* Ignore errors and force creation of aml file */
    501 
    502         Gbl_IgnoreErrors = TRUE;
    503         break;
    504 
    505 
    506     case 'g':
    507 
    508         /* Get all ACPI tables */
    509 
    510         Gbl_GetAllTables = TRUE;
    511         Gbl_DoCompile = FALSE;
    512         break;
    513 
    514 
    515     case 'h':
    516 
    517         switch (AcpiGbl_Optarg[0])
    518         {
    519         case '^':
    520             HelpMessage ();
    521             exit (0);
    522 
    523         case 'c':
    524             UtDisplayConstantOpcodes ();
    525             exit (0);
    526 
    527         case 'r':
    528             /* reserved names */
    529 
    530             ApDisplayReservedNames ();
    531             exit (0);
    532 
    533         case 't':
    534             UtDisplaySupportedTables ();
    535             exit (0);
    536 
    537         default:
    538             printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
    539             return (-1);
    540         }
    541 
    542 
    543     case 'I': /* Add an include file search directory */
    544 
    545         FlAddIncludeDirectory (AcpiGbl_Optarg);
    546         break;
    547 
    548 
    549     case 'i':
    550 
    551         switch (AcpiGbl_Optarg[0])
    552         {
    553         case 'a':
    554 
    555             /* Produce assembly code include file */
    556 
    557             Gbl_AsmIncludeOutputFlag = TRUE;
    558             break;
    559 
    560         case 'c':
    561 
    562             /* Produce C include file */
    563 
    564             Gbl_C_IncludeOutputFlag = TRUE;
    565             break;
    566 
    567         default:
    568             printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
    569             return (-1);
    570         }
    571         break;
    572 
    573 
    574     case 'l':
    575 
    576         switch (AcpiGbl_Optarg[0])
    577         {
    578         case '^':
    579             /* Produce listing file (Mixed source/aml) */
    580 
    581             Gbl_ListingFlag = TRUE;
    582             break;
    583 
    584         case 'n':
    585             /* Produce namespace file */
    586 
    587             Gbl_NsOutputFlag = TRUE;
    588             break;
    589 
    590         case 's':
    591             /* Produce combined source file */
    592 
    593             Gbl_SourceOutputFlag = TRUE;
    594             break;
    595 
    596         default:
    597             printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
    598             return (-1);
    599         }
    600         break;
    601 
    602 
    603     case 'o':
    604 
    605         switch (AcpiGbl_Optarg[0])
    606         {
    607         case 'a':
    608 
    609             /* Disable all optimizations */
    610 
    611             Gbl_FoldConstants = FALSE;
    612             Gbl_IntegerOptimizationFlag = FALSE;
    613             Gbl_ReferenceOptimizationFlag = FALSE;
    614             break;
    615 
    616         case 'f':
    617 
    618             /* Disable folding on "normal" expressions */
    619 
    620             Gbl_FoldConstants = FALSE;
    621             break;
    622 
    623         case 'i':
    624 
    625             /* Disable integer optimization to constants */
    626 
    627             Gbl_IntegerOptimizationFlag = FALSE;
    628             break;
    629 
    630         case 'n':
    631 
    632             /* Disable named reference optimization */
    633 
    634             Gbl_ReferenceOptimizationFlag = FALSE;
    635             break;
    636 
    637         case 't':
    638 
    639             /* Display compile time(s) */
    640 
    641             Gbl_CompileTimesFlag = TRUE;
    642             break;
    643 
    644         default:
    645             printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
    646             return (-1);
    647         }
    648         break;
    649 
    650 
    651     case 'n':
    652 
    653         /* Parse only */
    654 
    655         Gbl_ParseOnlyFlag = TRUE;
    656         break;
    657 
    658 
    659     case 'p':
    660 
    661         /* Override default AML output filename */
    662 
    663         Gbl_OutputFilenamePrefix = AcpiGbl_Optarg;
    664         Gbl_UseDefaultAmlFilename = FALSE;
    665         break;
    666 
    667 
    668     case 'r':
    669         Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
    670         break;
    671 
    672 
    673     case 's':
    674 
    675         switch (AcpiGbl_Optarg[0])
    676         {
    677         case 'a':
    678 
    679             /* Produce assembly code output file */
    680 
    681             Gbl_AsmOutputFlag = TRUE;
    682             break;
    683 
    684         case 'c':
    685 
    686             /* Produce C hex output file */
    687 
    688             Gbl_C_OutputFlag = TRUE;
    689             break;
    690 
    691         default:
    692             printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
    693             return (-1);
    694         }
    695         break;
    696 
    697 
    698     case 't':
    699 
    700         /* Produce hex table output file */
    701 
    702         switch (AcpiGbl_Optarg[0])
    703         {
    704         case 'a':
    705             Gbl_HexOutputFlag = HEX_OUTPUT_ASM;
    706             break;
    707 
    708         case 'c':
    709             Gbl_HexOutputFlag = HEX_OUTPUT_C;
    710             break;
    711 
    712         case 's':
    713             Gbl_HexOutputFlag = HEX_OUTPUT_ASL;
    714             break;
    715 
    716         default:
    717             printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
    718             return (-1);
    719         }
    720         break;
    721 
    722 
    723     case 'T':
    724         Gbl_DoTemplates = TRUE;
    725         Gbl_TemplateSignature = AcpiGbl_Optarg;
    726         break;
    727 
    728 
    729     case 'v':
    730 
    731         switch (AcpiGbl_Optarg[0])
    732         {
    733         case 'a':
    734             /* Disable All error/warning messages */
    735 
    736             Gbl_NoErrors = TRUE;
    737             break;
    738 
    739         case 'i':
    740             /* Less verbose error messages */
    741 
    742             Gbl_VerboseErrors = FALSE;
    743             break;
    744 
    745         case 'o':
    746             Gbl_DisplayOptimizations = TRUE;
    747             break;
    748 
    749         case 'r':
    750             Gbl_DisplayRemarks = FALSE;
    751             break;
    752 
    753         case 's':
    754             Gbl_DoSignon = FALSE;
    755             break;
    756 
    757         case 't':
    758             Gbl_VerboseTemplates = TRUE;
    759             break;
    760 
    761         default:
    762             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
    763             return (-1);
    764         }
    765         break;
    766 
    767 
    768     case 'w': /* Set warning levels */
    769 
    770         switch (AcpiGbl_Optarg[0])
    771         {
    772         case '1':
    773             Gbl_WarningLevel = ASL_WARNING;
    774             break;
    775 
    776         case '2':
    777             Gbl_WarningLevel = ASL_WARNING2;
    778             break;
    779 
    780         case '3':
    781             Gbl_WarningLevel = ASL_WARNING3;
    782             break;
    783 
    784         default:
    785             printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
    786             return (-1);
    787         }
    788         break;
    789 
    790 
    791     case 'x':
    792 
    793         AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
    794         break;
    795 
    796 
    797     case 'z':
    798 
    799         Gbl_UseOriginalCompilerId = TRUE;
    800         break;
    801 
    802 
    803     default:
    804 
    805         return (-1);
    806     }
    807 
    808     return (0);
    809 }
    810 
    811 
    812 /*******************************************************************************
    813  *
    814  * FUNCTION:    AslCommandLine
    815  *
    816  * PARAMETERS:  argc/argv
    817  *
    818  * RETURN:      Last argv index
    819  *
    820  * DESCRIPTION: Command line processing
    821  *
    822  ******************************************************************************/
    823 
    824 static int
    825 AslCommandLine (
    826     int                     argc,
    827     char                    **argv)
    828 {
    829     int                     BadCommandLine = 0;
    830     ACPI_STATUS             Status;
    831 
    832 
    833     /* Minimum command line contains at least the command and an input file */
    834 
    835     if (argc < 2)
    836     {
    837         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
    838         Usage ();
    839         exit (1);
    840     }
    841 
    842     /* Process all command line options */
    843 
    844     BadCommandLine = AslDoOptions (argc, argv, FALSE);
    845 
    846     if (Gbl_DoTemplates)
    847     {
    848         Status = DtCreateTemplates (Gbl_TemplateSignature);
    849         if (ACPI_FAILURE (Status))
    850         {
    851             exit (-1);
    852         }
    853         exit (1);
    854     }
    855 
    856     /* Next parameter must be the input filename */
    857 
    858     if (!argv[AcpiGbl_Optind] &&
    859         !Gbl_DisasmFlag &&
    860         !Gbl_GetAllTables)
    861     {
    862         printf ("Missing input filename\n");
    863         BadCommandLine = TRUE;
    864     }
    865 
    866     if (Gbl_DoSignon)
    867     {
    868         printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME));
    869     }
    870 
    871     /* Abort if anything went wrong on the command line */
    872 
    873     if (BadCommandLine)
    874     {
    875         printf ("\n");
    876         Usage ();
    877         exit (1);
    878     }
    879 
    880     return (AcpiGbl_Optind);
    881 }
    882 
    883 
    884 /*******************************************************************************
    885  *
    886  * FUNCTION:    main
    887  *
    888  * PARAMETERS:  Standard argc/argv
    889  *
    890  * RETURN:      Program termination code
    891  *
    892  * DESCRIPTION: C main routine for the Asl Compiler. Handle command line
    893  *              options and begin the compile for each file on the command line
    894  *
    895  ******************************************************************************/
    896 
    897 int ACPI_SYSTEM_XFACE
    898 main (
    899     int                     argc,
    900     char                    **argv)
    901 {
    902     ACPI_STATUS             Status;
    903     int                     Index1;
    904     int                     Index2;
    905 
    906 
    907     AcpiGbl_ExternalFileList = NULL;
    908 
    909 #ifdef _DEBUG
    910     _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
    911                     _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
    912 #endif
    913 
    914     /* Init and command line */
    915 
    916     AslInitialize ();
    917     Index1 = Index2 = AslCommandLine (argc, argv);
    918 
    919     /* Options that have no additional parameters or pathnames */
    920 
    921     if (Gbl_GetAllTables)
    922     {
    923         Status = AslDoOneFile (NULL);
    924         if (ACPI_FAILURE (Status))
    925         {
    926             return (-1);
    927         }
    928         return (0);
    929     }
    930 
    931     if (Gbl_DisassembleAll)
    932     {
    933         while (argv[Index1])
    934         {
    935             Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList);
    936             if (ACPI_FAILURE (Status))
    937             {
    938                 return (-1);
    939             }
    940 
    941             Index1++;
    942         }
    943     }
    944 
    945     /* Process each pathname/filename in the list, with possible wildcards */
    946 
    947     while (argv[Index2])
    948     {
    949         Status = AslDoOnePathname (argv[Index2], AslDoOneFile);
    950         if (ACPI_FAILURE (Status))
    951         {
    952             return (-1);
    953         }
    954 
    955         Index2++;
    956     }
    957 
    958     if (AcpiGbl_ExternalFileList)
    959     {
    960         AcpiDmClearExternalFileList();
    961     }
    962 
    963     return (0);
    964 }
    965 
    966 
    967