Subversion Repositories Kolibri OS

Rev

Rev 1498 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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