aslmain.c revision 167802
1319974Shselasky 2319974Shselasky/****************************************************************************** 3319974Shselasky * 4331772Shselasky * Module Name: aslmain - compiler main and utilities 5331772Shselasky * $Revision: 1.96 $ 6331772Shselasky * 7319974Shselasky *****************************************************************************/ 8319974Shselasky 9319974Shselasky/****************************************************************************** 10319974Shselasky * 11319974Shselasky * 1. Copyright Notice 12319974Shselasky * 13319974Shselasky * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp. 14319974Shselasky * All rights reserved. 15319974Shselasky * 16319974Shselasky * 2. License 17319974Shselasky * 18319974Shselasky * 2.1. This is your license from Intel Corp. under its intellectual property 19319974Shselasky * rights. You may have additional license terms from the party that provided 20319974Shselasky * you this software, covering your right to use that party's intellectual 21319974Shselasky * property rights. 22319974Shselasky * 23319974Shselasky * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 24319974Shselasky * copy of the source code appearing in this file ("Covered Code") an 25319974Shselasky * irrevocable, perpetual, worldwide license under Intel's copyrights in the 26319974Shselasky * base code distributed originally by Intel ("Original Intel Code") to copy, 27319974Shselasky * make derivatives, distribute, use and display any portion of the Covered 28319974Shselasky * Code in any form, with the right to sublicense such rights; and 29319974Shselasky * 30319974Shselasky * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 31319974Shselasky * license (with the right to sublicense), under only those claims of Intel 32319974Shselasky * patents that are infringed by the Original Intel Code, to make, use, sell, 33319974Shselasky * offer to sell, and import the Covered Code and derivative works thereof 34319974Shselasky * solely to the minimum extent necessary to exercise the above copyright 35319974Shselasky * license, and in no event shall the patent license extend to any additions 36319974Shselasky * to or modifications of the Original Intel Code. No other license or right 37319974Shselasky * is granted directly or by implication, estoppel or otherwise; 38319974Shselasky * 39319974Shselasky * The above copyright and patent license is granted only if the following 40319974Shselasky * conditions are met: 41319974Shselasky * 42319974Shselasky * 3. Conditions 43319974Shselasky * 44319974Shselasky * 3.1. Redistribution of Source with Rights to Further Distribute Source. 45319974Shselasky * Redistribution of source code of any substantial portion of the Covered 46319974Shselasky * Code or modification with rights to further distribute source must include 47319974Shselasky * the above Copyright Notice, the above License, this list of Conditions, 48319974Shselasky * and the following Disclaimer and Export Compliance provision. In addition, 49319974Shselasky * Licensee must cause all Covered Code to which Licensee contributes to 50319974Shselasky * contain a file documenting the changes Licensee made to create that Covered 51331772Shselasky * Code and the date of any change. Licensee must include in that file the 52319974Shselasky * documentation of any changes made by any predecessor Licensee. Licensee 53319974Shselasky * must include a prominent statement that the modification is derived, 54319974Shselasky * directly or indirectly, from Original Intel Code. 55319974Shselasky * 56319974Shselasky * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 57319974Shselasky * Redistribution of source code of any substantial portion of the Covered 58319974Shselasky * Code or modification without rights to further distribute source must 59319974Shselasky * include the following Disclaimer and Export Compliance provision in the 60319974Shselasky * documentation and/or other materials provided with distribution. In 61319974Shselasky * addition, Licensee may not authorize further sublicense of source of any 62319974Shselasky * portion of the Covered Code, and must include terms to the effect that the 63319974Shselasky * license from Licensee to its licensee is limited to the intellectual 64319974Shselasky * property embodied in the software Licensee provides to its licensee, and 65319974Shselasky * not to intellectual property embodied in modifications its licensee may 66319974Shselasky * make. 67319974Shselasky * 68319974Shselasky * 3.3. Redistribution of Executable. Redistribution in executable form of any 69319974Shselasky * substantial portion of the Covered Code or modification must reproduce the 70319974Shselasky * above Copyright Notice, and the following Disclaimer and Export Compliance 71319974Shselasky * provision in the documentation and/or other materials provided with the 72319974Shselasky * distribution. 73319974Shselasky * 74319974Shselasky * 3.4. Intel retains all right, title, and interest in and to the Original 75319974Shselasky * Intel Code. 76319974Shselasky * 77319974Shselasky * 3.5. Neither the name Intel nor any other trademark owned or controlled by 78319974Shselasky * Intel shall be used in advertising or otherwise to promote the sale, use or 79319974Shselasky * other dealings in products derived from or relating to the Covered Code 80319974Shselasky * without prior written authorization from Intel. 81319974Shselasky * 82319974Shselasky * 4. Disclaimer and Export Compliance 83319974Shselasky * 84319974Shselasky * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 85319974Shselasky * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 86319974Shselasky * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 87319974Shselasky * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 88319974Shselasky * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 89319974Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 90319974Shselasky * PARTICULAR PURPOSE. 91319974Shselasky * 92319974Shselasky * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 93319974Shselasky * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 94319974Shselasky * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 95319974Shselasky * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 96319974Shselasky * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 97319974Shselasky * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 98319974Shselasky * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 99319974Shselasky * LIMITED REMEDY. 100319974Shselasky * 101319974Shselasky * 4.3. Licensee shall not export, either directly or indirectly, any of this 102319974Shselasky * software or system incorporating such software without first obtaining any 103319974Shselasky * required license or other approval from the U. S. Department of Commerce or 104319974Shselasky * any other agency or department of the United States Government. In the 105319974Shselasky * event Licensee exports any such software from the United States or 106319974Shselasky * re-exports any such software from a foreign destination, Licensee shall 107319974Shselasky * ensure that the distribution and export/re-export of the software is in 108319974Shselasky * compliance with all laws, regulations, orders, or other restrictions of the 109319974Shselasky * U.S. Export Administration Regulations. Licensee agrees that neither it nor 110319974Shselasky * any of its subsidiaries will export/re-export any technical data, process, 111319974Shselasky * software, or service, directly or indirectly, to any country for which the 112319974Shselasky * United States government or any agency thereof requires an export license, 113319974Shselasky * other governmental approval, or letter of assurance, without first obtaining 114319974Shselasky * such license, approval or letter. 115319974Shselasky * 116319974Shselasky *****************************************************************************/ 117319974Shselasky 118319974Shselasky 119319974Shselasky#define _DECLARE_GLOBALS 120319974Shselasky 121319974Shselasky#include <contrib/dev/acpica/compiler/aslcompiler.h> 122319974Shselasky#include <contrib/dev/acpica/acnamesp.h> 123319974Shselasky#include <contrib/dev/acpica/actables.h> 124319974Shselasky#include <contrib/dev/acpica/acapps.h> 125319974Shselasky 126319974Shselasky#ifdef _DEBUG 127319974Shselasky#include <crtdbg.h> 128319974Shselasky#endif 129319974Shselasky 130319974Shselasky#define _COMPONENT ACPI_COMPILER 131319974Shselasky ACPI_MODULE_NAME ("aslmain") 132319974Shselasky 133319974ShselaskyBOOLEAN AslToFile = TRUE; 134319974ShselaskyBOOLEAN DoCompile = TRUE; 135319974ShselaskyBOOLEAN DoSignon = TRUE; 136319974Shselasky 137319974Shselaskychar hex[] = 138319974Shselasky{ 139319974Shselasky '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' 140319974Shselasky}; 141319974Shselasky 142319974Shselasky/* Local prototypes */ 143319974Shselasky 144319974Shselaskystatic void 145319974ShselaskyOptions ( 146319974Shselasky void); 147319974Shselasky 148319974Shselaskystatic void 149319974ShselaskyHelpMessage ( 150319974Shselasky void); 151319974Shselasky 152319974Shselaskystatic void 153319974ShselaskyUsage ( 154319974Shselasky void); 155319974Shselasky 156319974Shselaskystatic void 157319974ShselaskyAslInitialize ( 158319974Shselasky void); 159319974Shselasky 160319974Shselaskystatic void 161319974ShselaskyAslCommandLine ( 162319974Shselasky int argc, 163319974Shselasky char **argv); 164319974Shselasky 165319974Shselasky#ifdef _DEBUG 166319974Shselasky#include <crtdbg.h> 167319974Shselasky#endif 168319974Shselasky 169319974Shselasky/******************************************************************************* 170319974Shselasky * 171319974Shselasky * FUNCTION: Options 172319974Shselasky * 173319974Shselasky * PARAMETERS: None 174319974Shselasky * 175319974Shselasky * RETURN: None 176319974Shselasky * 177319974Shselasky * DESCRIPTION: Display option help message 178319974Shselasky * 179319974Shselasky ******************************************************************************/ 180319974Shselasky 181319974Shselaskystatic void 182319974ShselaskyOptions ( 183319974Shselasky void) 184319974Shselasky{ 185319974Shselasky 186319974Shselasky printf ("General Output:\n"); 187319974Shselasky printf (" -p <prefix> Specify filename prefix for all output files (including .aml)\n"); 188319974Shselasky printf (" -vi Less verbose errors and warnings for use with IDEs\n"); 189319974Shselasky printf (" -vo Enable optimization comments\n"); 190319974Shselasky printf (" -vr Disable remarks\n"); 191319974Shselasky printf (" -vs Disable signon\n"); 192319974Shselasky printf (" -w<1|2|3> Set warning reporting level\n"); 193319974Shselasky 194319974Shselasky printf ("\nAML Output Files:\n"); 195319974Shselasky printf (" -s<a|c> Create AML in assembler or C source file (*.asm or *.c)\n"); 196319974Shselasky printf (" -i<a|c> Create assembler or C include file (*.inc or *.h)\n"); 197319974Shselasky printf (" -t<a|c> Create AML in assembler or C hex table (*.hex)\n"); 198319974Shselasky 199319974Shselasky printf ("\nAML Code Generation:\n"); 200319974Shselasky printf (" -oa Disable all optimizations (compatibility mode)\n"); 201319974Shselasky printf (" -of Disable constant folding\n"); 202319974Shselasky printf (" -oi Disable integer optimization to Zero/One/Ones\n"); 203319974Shselasky printf (" -on Disable named reference string optimization\n"); 204319974Shselasky printf (" -r<Revision> Override table header Revision (1-255)\n"); 205319974Shselasky 206319974Shselasky printf ("\nListings:\n"); 207319974Shselasky printf (" -l Create mixed listing file (ASL source and AML) (*.lst)\n"); 208319974Shselasky printf (" -ln Create namespace file (*.nsp)\n"); 209319974Shselasky printf (" -ls Create combined source file (expanded includes) (*.src)\n"); 210319974Shselasky 211319974Shselasky printf ("\nAML Disassembler:\n"); 212319974Shselasky printf (" -d [file] Disassemble or decode binary ACPI table to file (*.dsl)\n"); 213319974Shselasky printf (" -dc [file] Disassemble AML and immediately compile it\n"); 214319974Shselasky printf (" (Obtain DSDT from current system if no input file)\n"); 215319974Shselasky printf (" -e [file] Include ACPI table for external symbol resolution\n"); 216319974Shselasky printf (" -2 Emit ACPI 2.0 compatible ASL code\n"); 217319974Shselasky printf (" -g Get ACPI tables and write to files (*.dat)\n"); 218319974Shselasky 219319974Shselasky printf ("\nHelp:\n"); 220319974Shselasky printf (" -h Additional help and compiler debug options\n"); 221319974Shselasky printf (" -hc Display operators allowed in constant expressions\n"); 222319974Shselasky printf (" -hr Display ACPI reserved method names\n"); 223319974Shselasky} 224319974Shselasky 225319974Shselasky 226319974Shselasky/******************************************************************************* 227319974Shselasky * 228319974Shselasky * FUNCTION: HelpMessage 229319974Shselasky * 230319974Shselasky * PARAMETERS: None 231319974Shselasky * 232319974Shselasky * RETURN: None 233319974Shselasky * 234319974Shselasky * DESCRIPTION: Display help message 235319974Shselasky * 236319974Shselasky ******************************************************************************/ 237319974Shselasky 238319974Shselaskystatic void 239319974ShselaskyHelpMessage ( 240319974Shselasky void) 241319974Shselasky{ 242319974Shselasky 243319974Shselasky printf ("AML output filename generation:\n"); 244319974Shselasky printf (" Output filenames are generated by appending an extension to a common\n"); 245319974Shselasky printf (" filename prefix. The filename prefix is obtained via one of the\n"); 246319974Shselasky printf (" following methods (in priority order):\n"); 247319974Shselasky printf (" 1) The -p option specifies the prefix\n"); 248319974Shselasky printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n"); 249319974Shselasky printf (" 3) The prefix of the input filename\n"); 250319974Shselasky printf ("\n"); 251319974Shselasky 252319974Shselasky Options (); 253319974Shselasky 254319974Shselasky printf ("\nCompiler/Disassembler Debug Options:\n"); 255319974Shselasky printf (" -b<p|t|b> Create compiler debug/trace file (*.txt)\n"); 256319974Shselasky printf (" Types: Parse/Tree/Both\n"); 257319974Shselasky printf (" -f Ignore errors, force creation of AML output file(s)\n"); 258319974Shselasky printf (" -c Parse only, no output generation\n"); 259319974Shselasky printf (" -ot Display compile times\n"); 260319974Shselasky printf (" -x<level> Set debug level for trace output\n"); 261319974Shselasky} 262319974Shselasky 263319974Shselasky 264319974Shselasky/******************************************************************************* 265319974Shselasky * 266319974Shselasky * FUNCTION: Usage 267319974Shselasky * 268319974Shselasky * PARAMETERS: None 269319974Shselasky * 270319974Shselasky * RETURN: None 271319974Shselasky * 272319974Shselasky * DESCRIPTION: Display usage and option message 273319974Shselasky * 274319974Shselasky ******************************************************************************/ 275319974Shselasky 276319974Shselaskystatic void 277319974ShselaskyUsage ( 278319974Shselasky void) 279319974Shselasky{ 280319974Shselasky 281319974Shselasky printf ("Usage: %s [Options] [InputFile]\n\n", CompilerName); 282319974Shselasky Options (); 283319974Shselasky} 284319974Shselasky 285319974Shselasky 286319974Shselasky/******************************************************************************* 287319974Shselasky * 288319974Shselasky * FUNCTION: AslInitialize 289319974Shselasky * 290319974Shselasky * PARAMETERS: None 291319974Shselasky * 292319974Shselasky * RETURN: None 293319974Shselasky * 294319974Shselasky * DESCRIPTION: Initialize compiler globals 295319974Shselasky * 296319974Shselasky ******************************************************************************/ 297319974Shselasky 298319974Shselaskystatic void 299319974ShselaskyAslInitialize ( 300319974Shselasky void) 301319974Shselasky{ 302319974Shselasky UINT32 i; 303319974Shselasky 304319974Shselasky 305319974Shselasky#ifdef _DEBUG 306319974Shselasky _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0)); 307319974Shselasky#endif 308319974Shselasky 309319974Shselasky AcpiDbgLevel = 0; 310319974Shselasky 311319974Shselasky for (i = 0; i < ASL_NUM_FILES; i++) 312319974Shselasky { 313319974Shselasky Gbl_Files[i].Handle = NULL; 314319974Shselasky Gbl_Files[i].Filename = NULL; 315319974Shselasky } 316319974Shselasky 317319974Shselasky Gbl_Files[ASL_FILE_STDOUT].Handle = stdout; 318319974Shselasky Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT"; 319319974Shselasky 320319974Shselasky Gbl_Files[ASL_FILE_STDERR].Handle = stderr; 321319974Shselasky Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR"; 322319974Shselasky} 323319974Shselasky 324319974Shselasky 325319974Shselasky/******************************************************************************* 326319974Shselasky * 327319974Shselasky * FUNCTION: AslCommandLine 328319974Shselasky * 329319974Shselasky * PARAMETERS: argc/argv 330319974Shselasky * 331319974Shselasky * RETURN: None 332319974Shselasky * 333319974Shselasky * DESCRIPTION: Command line processing 334319974Shselasky * 335319974Shselasky ******************************************************************************/ 336319974Shselasky 337319974Shselaskystatic void 338319974ShselaskyAslCommandLine ( 339319974Shselasky int argc, 340319974Shselasky char **argv) 341319974Shselasky{ 342319974Shselasky BOOLEAN BadCommandLine = FALSE; 343319974Shselasky ACPI_NATIVE_INT j; 344319974Shselasky 345319974Shselasky 346319974Shselasky /* Minimum command line contains at least one option or an input file */ 347319974Shselasky 348319974Shselasky if (argc < 2) 349319974Shselasky { 350319974Shselasky AslCompilerSignon (ASL_FILE_STDOUT); 351319974Shselasky Usage (); 352319974Shselasky exit (1); 353319974Shselasky } 354319974Shselasky 355319974Shselasky /* Get the command line options */ 356319974Shselasky 357319974Shselasky while ((j = AcpiGetopt (argc, argv, "2b:cd^e:fgh^i^l^o:p:r:s:t:v:w:x:")) != EOF) switch (j) 358319974Shselasky { 359319974Shselasky case '2': 360319974Shselasky Gbl_Acpi2 = TRUE; 361319974Shselasky break; 362319974Shselasky 363319974Shselasky 364319974Shselasky case 'b': 365319974Shselasky 366319974Shselasky switch (AcpiGbl_Optarg[0]) 367319974Shselasky { 368319974Shselasky case 'b': 369319974Shselasky AslCompilerdebug = 1; /* same as yydebug */ 370319974Shselasky break; 371319974Shselasky 372319974Shselasky case 'p': 373319974Shselasky AslCompilerdebug = 1; /* same as yydebug */ 374319974Shselasky break; 375319974Shselasky 376319974Shselasky case 't': 377319974Shselasky break; 378319974Shselasky 379319974Shselasky default: 380319974Shselasky printf ("Unknown option: -b%s\n", AcpiGbl_Optarg); 381319974Shselasky BadCommandLine = TRUE; 382319974Shselasky break; 383319974Shselasky } 384319974Shselasky 385319974Shselasky /* Produce debug output file */ 386319974Shselasky 387319974Shselasky Gbl_DebugFlag = TRUE; 388319974Shselasky break; 389319974Shselasky 390319974Shselasky 391319974Shselasky case 'c': 392319974Shselasky 393319974Shselasky /* Parse only */ 394319974Shselasky 395319974Shselasky Gbl_ParseOnlyFlag = TRUE; 396319974Shselasky break; 397319974Shselasky 398319974Shselasky 399319974Shselasky case 'd': 400319974Shselasky switch (AcpiGbl_Optarg[0]) 401319974Shselasky { 402319974Shselasky case '^': 403319974Shselasky DoCompile = FALSE; 404319974Shselasky break; 405319974Shselasky 406319974Shselasky case 'c': 407319974Shselasky break; 408319974Shselasky 409319974Shselasky default: 410319974Shselasky printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); 411319974Shselasky BadCommandLine = TRUE; 412319974Shselasky break; 413319974Shselasky } 414319974Shselasky 415319974Shselasky Gbl_DisasmFlag = TRUE; 416319974Shselasky break; 417319974Shselasky 418319974Shselasky 419319974Shselasky case 'e': 420319974Shselasky Gbl_ExternalFilename = AcpiGbl_Optarg; 421319974Shselasky break; 422319974Shselasky 423319974Shselasky 424319974Shselasky case 'f': 425319974Shselasky 426319974Shselasky /* Ignore errors and force creation of aml file */ 427319974Shselasky 428319974Shselasky Gbl_IgnoreErrors = TRUE; 429319974Shselasky break; 430319974Shselasky 431319974Shselasky 432319974Shselasky case 'g': 433319974Shselasky 434319974Shselasky /* Get all ACPI tables */ 435319974Shselasky 436319974Shselasky Gbl_GetAllTables = TRUE; 437319974Shselasky DoCompile = FALSE; 438319974Shselasky break; 439319974Shselasky 440319974Shselasky 441319974Shselasky case 'h': 442319974Shselasky 443319974Shselasky switch (AcpiGbl_Optarg[0]) 444319974Shselasky { 445319974Shselasky case '^': 446319974Shselasky HelpMessage (); 447319974Shselasky exit (0); 448319974Shselasky 449319974Shselasky case 'c': 450319974Shselasky UtDisplayConstantOpcodes (); 451319974Shselasky exit (0); 452319974Shselasky 453319974Shselasky case 'r': 454319974Shselasky /* reserved names */ 455319974Shselasky 456319974Shselasky MpDisplayReservedNames (); 457319974Shselasky exit (0); 458319974Shselasky 459319974Shselasky default: 460319974Shselasky printf ("Unknown option: -h%s\n", AcpiGbl_Optarg); 461319974Shselasky BadCommandLine = TRUE; 462319974Shselasky break; 463319974Shselasky } 464319974Shselasky break; 465319974Shselasky 466319974Shselasky 467319974Shselasky case 'i': 468319974Shselasky 469319974Shselasky switch (AcpiGbl_Optarg[0]) 470319974Shselasky { 471319974Shselasky case 'a': 472319974Shselasky 473319974Shselasky /* Produce assembly code include file */ 474319974Shselasky 475319974Shselasky Gbl_AsmIncludeOutputFlag = TRUE; 476319974Shselasky break; 477319974Shselasky 478319974Shselasky case 'c': 479319974Shselasky 480319974Shselasky /* Produce C include file */ 481319974Shselasky 482319974Shselasky Gbl_C_IncludeOutputFlag = TRUE; 483319974Shselasky break; 484319974Shselasky 485319974Shselasky default: 486319974Shselasky printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 487319974Shselasky BadCommandLine = TRUE; 488319974Shselasky break; 489319974Shselasky } 490319974Shselasky break; 491319974Shselasky 492319974Shselasky 493319974Shselasky case 'l': 494319974Shselasky 495319974Shselasky switch (AcpiGbl_Optarg[0]) 496319974Shselasky { 497319974Shselasky case '^': 498319974Shselasky /* Produce listing file (Mixed source/aml) */ 499319974Shselasky 500319974Shselasky Gbl_ListingFlag = TRUE; 501319974Shselasky break; 502319974Shselasky 503319974Shselasky case 'n': 504 /* Produce namespace file */ 505 506 Gbl_NsOutputFlag = TRUE; 507 break; 508 509 case 's': 510 /* Produce combined source file */ 511 512 Gbl_SourceOutputFlag = TRUE; 513 break; 514 515 default: 516 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg); 517 BadCommandLine = TRUE; 518 break; 519 } 520 break; 521 522 523 case 'o': 524 525 switch (AcpiGbl_Optarg[0]) 526 { 527 case 'a': 528 529 /* Disable all optimizations */ 530 531 Gbl_FoldConstants = FALSE; 532 Gbl_IntegerOptimizationFlag = FALSE; 533 Gbl_ReferenceOptimizationFlag = FALSE; 534 break; 535 536 case 'f': 537 538 /* Disable folding on "normal" expressions */ 539 540 Gbl_FoldConstants = FALSE; 541 break; 542 543 case 'i': 544 545 /* Disable integer optimization to constants */ 546 547 Gbl_IntegerOptimizationFlag = FALSE; 548 break; 549 550 case 'n': 551 552 /* Disable named reference optimization */ 553 554 Gbl_ReferenceOptimizationFlag = FALSE; 555 break; 556 557 case 't': 558 559 /* Display compile time(s) */ 560 561 Gbl_CompileTimesFlag = TRUE; 562 break; 563 564 default: 565 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 566 BadCommandLine = TRUE; 567 break; 568 } 569 break; 570 571 572 case 'p': 573 574 /* Override default AML output filename */ 575 576 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg; 577 Gbl_UseDefaultAmlFilename = FALSE; 578 break; 579 580 581 case 'r': 582 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); 583 break; 584 585 586 case 's': 587 588 switch (AcpiGbl_Optarg[0]) 589 { 590 case 'a': 591 592 /* Produce assembly code output file */ 593 594 Gbl_AsmOutputFlag = TRUE; 595 break; 596 597 case 'c': 598 599 /* Produce C hex output file */ 600 601 Gbl_C_OutputFlag = TRUE; 602 break; 603 604 default: 605 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 606 BadCommandLine = TRUE; 607 break; 608 } 609 break; 610 611 612 case 't': 613 614 /* Produce hex table output file */ 615 616 switch (AcpiGbl_Optarg[0]) 617 { 618 case 'a': 619 Gbl_HexOutputFlag = HEX_OUTPUT_ASM; 620 break; 621 622 case 'c': 623 Gbl_HexOutputFlag = HEX_OUTPUT_C; 624 break; 625 626 default: 627 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg); 628 BadCommandLine = TRUE; 629 break; 630 } 631 break; 632 633 634 case 'v': 635 636 switch (AcpiGbl_Optarg[0]) 637 { 638 case 'i': 639 /* Less verbose error messages */ 640 641 Gbl_VerboseErrors = FALSE; 642 break; 643 644 case 'o': 645 Gbl_DisplayOptimizations = TRUE; 646 break; 647 648 case 'r': 649 Gbl_DisplayRemarks = FALSE; 650 break; 651 652 case 's': 653 DoSignon = FALSE; 654 break; 655 656 default: 657 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); 658 BadCommandLine = TRUE; 659 break; 660 } 661 break; 662 663 664 case 'w': /* Set warning levels */ 665 666 switch (AcpiGbl_Optarg[0]) 667 { 668 case '1': 669 Gbl_WarningLevel = ASL_WARNING; 670 break; 671 672 case '2': 673 Gbl_WarningLevel = ASL_WARNING2; 674 break; 675 676 case '3': 677 Gbl_WarningLevel = ASL_WARNING3; 678 break; 679 680 default: 681 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg); 682 BadCommandLine = TRUE; 683 break; 684 } 685 break; 686 687 688 case 'x': 689 690 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16); 691 break; 692 693 694 default: 695 696 BadCommandLine = TRUE; 697 break; 698 } 699 700 /* Next parameter must be the input filename */ 701 702 Gbl_Files[ASL_FILE_INPUT].Filename = argv[AcpiGbl_Optind]; 703 704 if (!Gbl_Files[ASL_FILE_INPUT].Filename && 705 !Gbl_DisasmFlag && 706 !Gbl_GetAllTables) 707 { 708 printf ("Missing input filename\n"); 709 BadCommandLine = TRUE; 710 } 711 712 if (DoSignon) 713 { 714 AslCompilerSignon (ASL_FILE_STDOUT); 715 } 716 717 /* Abort if anything went wrong on the command line */ 718 719 if (BadCommandLine) 720 { 721 printf ("\n"); 722 Usage (); 723 exit (1); 724 } 725 726 if ((AcpiGbl_Optind + 1) < argc) 727 { 728 printf ("Warning: extra arguments (%d) after input filename are ignored\n\n", 729 argc - AcpiGbl_Optind - 1); 730 } 731} 732 733 734/******************************************************************************* 735 * 736 * FUNCTION: main 737 * 738 * PARAMETERS: Standard argc/argv 739 * 740 * RETURN: Program termination code 741 * 742 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line 743 * options and begin the compile. 744 * 745 ******************************************************************************/ 746 747int ACPI_SYSTEM_XFACE 748main ( 749 int argc, 750 char **argv) 751{ 752 ACPI_STATUS Status; 753 char *Prefix; 754 755 756#ifdef _DEBUG 757 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | 758 _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); 759#endif 760 761 /* Init and command line */ 762 763 AslInitialize (); 764 AslCommandLine (argc, argv); 765 766 /* 767 * If -p not specified, we will use the input filename as the 768 * output filename prefix 769 */ 770 Status = FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename, 771 &Gbl_DirectoryPath, &Prefix); 772 if (ACPI_FAILURE (Status)) 773 { 774 return -1; 775 } 776 777 if (Gbl_UseDefaultAmlFilename) 778 { 779 Gbl_OutputFilenamePrefix = Prefix; 780 } 781 782 /* AML Disassembly (Optional) */ 783 784 if (Gbl_DisasmFlag || Gbl_GetAllTables) 785 { 786 /* ACPI CA subsystem initialization */ 787 788 Status = AdInitialize (); 789 if (ACPI_FAILURE (Status)) 790 { 791 return -1; 792 } 793 794 Status = AcpiAllocateRootTable (4); 795 if (ACPI_FAILURE (Status)) 796 { 797 AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n", 798 AcpiFormatException (Status)); 799 return -1; 800 } 801 802 /* This is where the disassembly happens */ 803 804 AcpiGbl_DbOpt_disasm = TRUE; 805 Status = AdAmlDisassemble (AslToFile, 806 Gbl_Files[ASL_FILE_INPUT].Filename, 807 Gbl_OutputFilenamePrefix, 808 &Gbl_Files[ASL_FILE_INPUT].Filename, 809 Gbl_GetAllTables); 810 if (ACPI_FAILURE (Status)) 811 { 812 return -1; 813 } 814 815 /* 816 * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the 817 * .DSL disassembly file, which can now be compiled if requested 818 */ 819 if (DoCompile) 820 { 821 AcpiOsPrintf ("\nCompiling \"%s\"\n", 822 Gbl_Files[ASL_FILE_INPUT].Filename); 823 } 824 } 825 826 /* 827 * ASL Compilation (Optional) 828 */ 829 if (DoCompile) 830 { 831 /* 832 * If -p not specified, we will use the input filename as the 833 * output filename prefix 834 */ 835 Status = FlSplitInputPathname (Gbl_Files[ASL_FILE_INPUT].Filename, 836 &Gbl_DirectoryPath, &Prefix); 837 if (ACPI_FAILURE (Status)) 838 { 839 return -1; 840 } 841 842 if (Gbl_UseDefaultAmlFilename) 843 { 844 Gbl_OutputFilenamePrefix = Prefix; 845 } 846 847 /* ACPI CA subsystem initialization (Must be re-initialized) */ 848 849 Status = AcpiOsInitialize (); 850 AcpiUtInitGlobals (); 851 Status = AcpiUtMutexInitialize (); 852 if (ACPI_FAILURE (Status)) 853 { 854 return -1; 855 } 856 857 Status = AcpiNsRootInitialize (); 858 if (ACPI_FAILURE (Status)) 859 { 860 return -1; 861 } 862 Status = CmDoCompile (); 863 } 864 865 return (0); 866} 867 868 869