1 2 /****************************************************************************** 3 * 4 * Module Name: aslmain - compiler main and utilities 5 * 6 *****************************************************************************/ 7 8 /* 9 * Copyright (C) 2000 - 2012, 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 <contrib/dev/acpica/compiler/aslcompiler.h> 49 #include <contrib/dev/acpica/include/acapps.h> 50 #include <contrib/dev/acpica/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 FilenameHelp ( 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^D:e:fgh^i|I:l^mno|p:P^r:s|t|T:G^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 ("\nGlobal:\n"); 120 ACPI_OPTION ("-@ <file>", "Specify command file"); 121 ACPI_OPTION ("-I <dir>", "Specify additional include directory"); 122 ACPI_OPTION ("-v", "Display compiler version"); 123 124 printf ("\nPreprocessor:\n"); 125 ACPI_OPTION ("-D <symbol>", "Define symbol for preprocessor use"); 126 ACPI_OPTION ("-li", "Create preprocessed output file (*.i)"); 127 ACPI_OPTION ("-P", "Preprocess only and create preprocessor output file (*.i)"); 128 ACPI_OPTION ("-Pn", "Disable preprocessor"); 129 130 printf ("\nGeneral Output:\n"); 131 ACPI_OPTION ("-p <prefix>", "Specify path/filename prefix for all output files"); 132 ACPI_OPTION ("-va", "Disable all errors and warnings (summary only)"); 133 ACPI_OPTION ("-vi", "Less verbose errors and warnings for use with IDEs"); 134 ACPI_OPTION ("-vo", "Enable optimization comments"); 135 ACPI_OPTION ("-vr", "Disable remarks"); 136 ACPI_OPTION ("-vs", "Disable signon"); 137 ACPI_OPTION ("-w1 -w2 -w3", "Set warning reporting level"); 138 ACPI_OPTION ("-we", "Report warnings as errors"); 139 140 printf ("\nAML Output Files:\n"); 141 ACPI_OPTION ("-sa -sc", "Create AML in assembler or C source file (*.asm or *.c)"); 142 ACPI_OPTION ("-ia -ic", "Create assembler or C include file (*.inc or *.h)"); 143 ACPI_OPTION ("-ta -tc -ts", "Create AML in assembler, C, or ASL hex table (*.hex)"); 144 145 printf ("\nAML Code Generation:\n"); 146 ACPI_OPTION ("-oa", "Disable all optimizations (compatibility mode)"); 147 ACPI_OPTION ("-of", "Disable constant folding"); 148 ACPI_OPTION ("-oi", "Disable integer optimization to Zero/One/Ones"); 149 ACPI_OPTION ("-on", "Disable named reference string optimization"); 150 ACPI_OPTION ("-cr", "Disable Resource Descriptor error checking"); 151 ACPI_OPTION ("-r <revision>", "Override table header Revision (1-255)"); 152 153 printf ("\nASL Listing Files:\n"); 154 ACPI_OPTION ("-l", "Create mixed listing file (ASL source and AML) (*.lst)"); 155 ACPI_OPTION ("-ln", "Create namespace file (*.nsp)"); 156 ACPI_OPTION ("-ls", "Create combined source file (expanded includes) (*.src)"); 157 158 printf ("\nACPI Data Tables:\n"); 159 ACPI_OPTION ("-G", "Compile custom table containing generic operators"); 160 ACPI_OPTION ("-T <sig>|ALL|*", "Create table template file(s) for <Sig>"); 161 ACPI_OPTION ("-vt", "Create verbose templates (full disassembly)"); 162 163 printf ("\nAML Disassembler:\n"); 164 ACPI_OPTION ("-d [file]", "Disassemble or decode binary ACPI table to file (*.dsl)"); 165 ACPI_OPTION ("-da [f1,f2]", "Disassemble multiple tables from single namespace"); 166 ACPI_OPTION ("-dc [file]", "Disassemble AML and immediately compile it"); 167 ACPI_OPTION ("", "(Obtain DSDT from current system if no input file)"); 168 ACPI_OPTION ("-e [f1,f2]", "Include ACPI table(s) for external symbol resolution"); 169 ACPI_OPTION ("-m", "Do not translate Buffers to Resource Templates"); 170 ACPI_OPTION ("-2", "Emit ACPI 2.0 compatible ASL code"); 171 ACPI_OPTION ("-g", "Get ACPI tables and write to files (*.dat)"); 172 173 printf ("\nHelp:\n"); 174 ACPI_OPTION ("-h", "This message"); 175 ACPI_OPTION ("-hc", "Display operators allowed in constant expressions"); 176 ACPI_OPTION ("-hf", "Display help for output filename generation"); 177 ACPI_OPTION ("-hr", "Display ACPI reserved method names"); 178 ACPI_OPTION ("-ht", "Display currently supported ACPI table names"); 179 180 printf ("\nDebug Options:\n"); 181 ACPI_OPTION ("-bf -bt", "Create debug file (full or parse tree only) (*.txt)"); 182 ACPI_OPTION ("-f", "Ignore errors, force creation of AML output file(s)"); 183 ACPI_OPTION ("-n", "Parse only, no output generation"); 184 ACPI_OPTION ("-ot", "Display compile times and statistics"); 185 ACPI_OPTION ("-x <level>", "Set debug level for trace output"); 186 ACPI_OPTION ("-z", "Do not insert new compiler ID for DataTables"); 187 } 188 189 190 /******************************************************************************* 191 * 192 * FUNCTION: FilenameHelp 193 * 194 * PARAMETERS: None 195 * 196 * RETURN: None 197 * 198 * DESCRIPTION: Display help message for output filename generation 199 * 200 ******************************************************************************/ 201 202 static void 203 FilenameHelp ( 204 void) 205 { 206 207 printf ("\nAML output filename generation:\n"); 208 printf (" Output filenames are generated by appending an extension to a common\n"); 209 printf (" filename prefix. The filename prefix is obtained via one of the\n"); 210 printf (" following methods (in priority order):\n"); 211 printf (" 1) The -p option specifies the prefix\n"); 212 printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n"); 213 printf (" 3) The prefix of the input filename\n"); 214 printf ("\n"); 215 } 216 217 218 /******************************************************************************* 219 * 220 * FUNCTION: Usage 221 * 222 * PARAMETERS: None 223 * 224 * RETURN: None 225 * 226 * DESCRIPTION: Display usage and option message 227 * 228 ******************************************************************************/ 229 230 static void 231 Usage ( 232 void) 233 { 234 235 printf ("%s\n\n", ASL_COMPLIANCE); 236 ACPI_USAGE_HEADER ("iasl [Options] [Files]"); 237 Options (); 238 } 239 240 241 /******************************************************************************* 242 * 243 * FUNCTION: AslInitialize 244 * 245 * PARAMETERS: None 246 * 247 * RETURN: None 248 * 249 * DESCRIPTION: Initialize compiler globals 250 * 251 ******************************************************************************/ 252 253 static void 254 AslInitialize ( 255 void) 256 { 257 UINT32 i; 258 259 260 #ifdef _DEBUG 261 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0)); 262 #endif 263 264 AcpiDbgLevel = 0; 265 266 for (i = 0; i < ASL_NUM_FILES; i++) 267 { 268 Gbl_Files[i].Handle = NULL; 269 Gbl_Files[i].Filename = NULL; 270 } 271 272 Gbl_Files[ASL_FILE_STDOUT].Handle = stdout; 273 Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT"; 274 275 Gbl_Files[ASL_FILE_STDERR].Handle = stderr; 276 Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR"; 277 } 278 279 280 /******************************************************************************* 281 * 282 * FUNCTION: AslMergeOptionTokens 283 * 284 * PARAMETERS: InBuffer - Input containing an option string 285 * OutBuffer - Merged output buffer 286 * 287 * RETURN: None 288 * 289 * DESCRIPTION: Remove all whitespace from an option string. 290 * 291 ******************************************************************************/ 292 293 static void 294 AslMergeOptionTokens ( 295 char *InBuffer, 296 char *OutBuffer) 297 { 298 char *Token; 299 300 301 *OutBuffer = 0; 302 303 Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS); 304 while (Token) 305 { 306 strcat (OutBuffer, Token); 307 Token = strtok (NULL, ASL_TOKEN_SEPARATORS); 308 } 309 } 310 311 312 /******************************************************************************* 313 * 314 * FUNCTION: AslDoResponseFile 315 * 316 * PARAMETERS: Filename - Name of the response file 317 * 318 * RETURN: Status 319 * 320 * DESCRIPTION: Open a response file and process all options within. 321 * 322 ******************************************************************************/ 323 324 static int 325 AslDoResponseFile ( 326 char *Filename) 327 { 328 char *argv = StringBuffer2; 329 FILE *ResponseFile; 330 int OptStatus = 0; 331 int Opterr; 332 int Optind; 333 334 335 ResponseFile = fopen (Filename, "r"); 336 if (!ResponseFile) 337 { 338 printf ("Could not open command file %s, %s\n", 339 Filename, strerror (errno)); 340 return -1; 341 } 342 343 /* Must save the current GetOpt globals */ 344 345 Opterr = AcpiGbl_Opterr; 346 Optind = AcpiGbl_Optind; 347 348 /* 349 * Process all lines in the response file. There must be one complete 350 * option per line 351 */ 352 while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile)) 353 { 354 /* Compress all tokens, allowing us to use a single argv entry */ 355 356 AslMergeOptionTokens (StringBuffer, StringBuffer2); 357 358 /* Process the option */ 359 360 AcpiGbl_Opterr = 0; 361 AcpiGbl_Optind = 0; 362 363 OptStatus = AslDoOptions (1, &argv, TRUE); 364 if (OptStatus) 365 { 366 printf ("Invalid option in command file %s: %s\n", 367 Filename, StringBuffer); 368 break; 369 } 370 } 371 372 /* Restore the GetOpt globals */ 373 374 AcpiGbl_Opterr = Opterr; 375 AcpiGbl_Optind = Optind; 376 377 fclose (ResponseFile); 378 return (OptStatus); 379 } 380 381 382 /******************************************************************************* 383 * 384 * FUNCTION: AslDoOptions 385 * 386 * PARAMETERS: argc/argv - Standard argc/argv 387 * IsResponseFile - TRUE if executing a response file. 388 * 389 * RETURN: Status 390 * 391 * DESCRIPTION: Command line option processing 392 * 393 ******************************************************************************/ 394 395 static int 396 AslDoOptions ( 397 int argc, 398 char **argv, 399 BOOLEAN IsResponseFile) 400 { 401 int j; 402 ACPI_STATUS Status; 403 404 405 /* Get the command line options */ 406 407 while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j) 408 { 409 case '@': /* Begin a response file */ 410 411 if (IsResponseFile) 412 { 413 printf ("Nested command files are not supported\n"); 414 return (-1); 415 } 416 417 if (AslDoResponseFile (AcpiGbl_Optarg)) 418 { 419 return (-1); 420 } 421 break; 422 423 424 case '2': /* ACPI 2.0 compatibility mode */ 425 Gbl_Acpi2 = TRUE; 426 break; 427 428 429 case 'b': /* Debug output options */ 430 switch (AcpiGbl_Optarg[0]) 431 { 432 case 'f': 433 AslCompilerdebug = 1; /* same as yydebug */ 434 DtParserdebug = 1; 435 PrParserdebug = 1; 436 break; 437 438 case 't': 439 break; 440 441 default: 442 printf ("Unknown option: -b%s\n", AcpiGbl_Optarg); 443 return (-1); 444 } 445 446 /* Produce debug output file */ 447 448 Gbl_DebugFlag = TRUE; 449 break; 450 451 452 case 'c': 453 switch (AcpiGbl_Optarg[0]) 454 { 455 case 'r': 456 Gbl_NoResourceChecking = TRUE; 457 break; 458 459 default: 460 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 461 return (-1); 462 } 463 break; 464 465 466 case 'd': /* Disassembler */ 467 switch (AcpiGbl_Optarg[0]) 468 { 469 case '^': 470 Gbl_DoCompile = FALSE; 471 break; 472 473 case 'a': 474 Gbl_DoCompile = FALSE; 475 Gbl_DisassembleAll = TRUE; 476 break; 477 478 case 'c': 479 break; 480 481 default: 482 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); 483 return (-1); 484 } 485 486 Gbl_DisasmFlag = TRUE; 487 break; 488 489 490 case 'D': /* Define a symbol */ 491 PrAddDefine (AcpiGbl_Optarg, NULL, TRUE); 492 break; 493 494 495 case 'e': /* External files for disassembler */ 496 Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg); 497 if (ACPI_FAILURE (Status)) 498 { 499 printf ("Could not add %s to external list\n", AcpiGbl_Optarg); 500 return (-1); 501 } 502 break; 503 504 505 case 'f': /* Ignore errors and force creation of aml file */ 506 Gbl_IgnoreErrors = TRUE; 507 break; 508 509 510 case 'G': 511 Gbl_CompileGeneric = TRUE; 512 break; 513 514 515 case 'g': /* Get all ACPI tables */ 516 517 Gbl_GetAllTables = TRUE; 518 Gbl_DoCompile = FALSE; 519 break; 520 521 522 case 'h': 523 switch (AcpiGbl_Optarg[0]) 524 { 525 case '^': 526 Usage (); 527 exit (0); 528 529 case 'c': 530 UtDisplayConstantOpcodes (); 531 exit (0); 532 533 case 'f': 534 FilenameHelp (); 535 exit (0); 536 537 case 'r': 538 /* reserved names */ 539 540 ApDisplayReservedNames (); 541 exit (0); 542 543 case 't': 544 UtDisplaySupportedTables (); 545 exit (0); 546 547 default: 548 printf ("Unknown option: -h%s\n", AcpiGbl_Optarg); 549 return (-1); 550 } 551 552 553 case 'I': /* Add an include file search directory */ 554 FlAddIncludeDirectory (AcpiGbl_Optarg); 555 break; 556 557 558 case 'i': /* Output AML as an include file */ 559 switch (AcpiGbl_Optarg[0]) 560 { 561 case 'a': 562 563 /* Produce assembly code include file */ 564 565 Gbl_AsmIncludeOutputFlag = TRUE; 566 break; 567 568 case 'c': 569 570 /* Produce C include file */ 571 572 Gbl_C_IncludeOutputFlag = TRUE; 573 break; 574 575 default: 576 printf ("Unknown option: -i%s\n", AcpiGbl_Optarg); 577 return (-1); 578 } 579 break; 580 581 582 case 'l': /* Listing files */ 583 switch (AcpiGbl_Optarg[0]) 584 { 585 case '^': 586 /* Produce listing file (Mixed source/aml) */ 587 588 Gbl_ListingFlag = TRUE; 589 break; 590 591 case 'i': 592 /* Produce preprocessor output file */ 593 594 Gbl_PreprocessorOutputFlag = TRUE; 595 break; 596 597 case 'n': 598 /* Produce namespace file */ 599 600 Gbl_NsOutputFlag = TRUE; 601 break; 602 603 case 's': 604 /* Produce combined source file */ 605 606 Gbl_SourceOutputFlag = TRUE; 607 break; 608 609 default: 610 printf ("Unknown option: -l%s\n", AcpiGbl_Optarg); 611 return (-1); 612 } 613 break; 614 615 616 case 'm': /* Do not convert buffers to resource descriptors */ 617 AcpiGbl_NoResourceDisassembly = TRUE; 618 break; 619 620 621 case 'n': /* Parse only */ 622 Gbl_ParseOnlyFlag = TRUE; 623 break; 624 625 626 case 'o': /* Control compiler AML optimizations */ 627 switch (AcpiGbl_Optarg[0]) 628 { 629 case 'a': 630 631 /* Disable all optimizations */ 632 633 Gbl_FoldConstants = FALSE; 634 Gbl_IntegerOptimizationFlag = FALSE; 635 Gbl_ReferenceOptimizationFlag = FALSE; 636 break; 637 638 case 'f': 639 640 /* Disable folding on "normal" expressions */ 641 642 Gbl_FoldConstants = FALSE; 643 break; 644 645 case 'i': 646 647 /* Disable integer optimization to constants */ 648 649 Gbl_IntegerOptimizationFlag = FALSE; 650 break; 651 652 case 'n': 653 654 /* Disable named reference optimization */ 655 656 Gbl_ReferenceOptimizationFlag = FALSE; 657 break; 658 659 case 't': 660 661 /* Display compile time(s) */ 662 663 Gbl_CompileTimesFlag = TRUE; 664 break; 665 666 default: 667 printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); 668 return (-1); 669 } 670 break; 671 672 673 case 'P': /* Preprocessor options */ 674 switch (AcpiGbl_Optarg[0]) 675 { 676 case '^': /* Proprocess only, emit (.i) file */ 677 Gbl_PreprocessOnly = TRUE; 678 Gbl_PreprocessorOutputFlag = TRUE; 679 break; 680 681 case 'n': /* Disable preprocessor */ 682 Gbl_PreprocessFlag = FALSE; 683 break; 684 685 default: 686 printf ("Unknown option: -P%s\n", AcpiGbl_Optarg); 687 return (-1); 688 } 689 break; 690 691 692 case 'p': /* Override default AML output filename */ 693 Gbl_OutputFilenamePrefix = AcpiGbl_Optarg; 694 Gbl_UseDefaultAmlFilename = FALSE; 695 break; 696 697 698 case 'r': /* Override revision found in table header */ 699 Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); 700 break; 701 702 703 case 's': /* Create AML in a source code file */ 704 switch (AcpiGbl_Optarg[0]) 705 { 706 case 'a': 707 708 /* Produce assembly code output file */ 709 710 Gbl_AsmOutputFlag = TRUE; 711 break; 712 713 case 'c': 714 715 /* Produce C hex output file */ 716 717 Gbl_C_OutputFlag = TRUE; 718 break; 719 720 default: 721 printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); 722 return (-1); 723 } 724 break; 725 726 727 case 't': /* Produce hex table output file */ 728 switch (AcpiGbl_Optarg[0]) 729 { 730 case 'a': 731 Gbl_HexOutputFlag = HEX_OUTPUT_ASM; 732 break; 733 734 case 'c': 735 Gbl_HexOutputFlag = HEX_OUTPUT_C; 736 break; 737 738 case 's': 739 Gbl_HexOutputFlag = HEX_OUTPUT_ASL; 740 break; 741 742 default: 743 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg); 744 return (-1); 745 } 746 break; 747 748 749 case 'T': /* Create a ACPI table template file */ 750 Gbl_DoTemplates = TRUE; 751 Gbl_TemplateSignature = AcpiGbl_Optarg; 752 break; 753 754 755 case 'v': /* Version and verbosity settings */ 756 switch (AcpiGbl_Optarg[0]) 757 { 758 case '^': 759 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); 760 exit (0); 761 762 case 'a': 763 /* Disable All error/warning messages */ 764 765 Gbl_NoErrors = TRUE; 766 break; 767 768 case 'i': 769 /* 770 * Support for integrated development environment(s). 771 * 772 * 1) No compiler signon 773 * 2) Send stderr messages to stdout 774 * 3) Less verbose error messages (single line only for each) 775 * 4) Error/warning messages are formatted appropriately to 776 * be recognized by MS Visual Studio 777 */ 778 Gbl_VerboseErrors = FALSE; 779 Gbl_DoSignon = FALSE; 780 Gbl_Files[ASL_FILE_STDERR].Handle = stdout; 781 break; 782 783 case 'o': 784 Gbl_DisplayOptimizations = TRUE; 785 break; 786 787 case 'r': 788 Gbl_DisplayRemarks = FALSE; 789 break; 790 791 case 's': 792 Gbl_DoSignon = FALSE; 793 break; 794 795 case 't': 796 Gbl_VerboseTemplates = TRUE; 797 break; 798 799 default: 800 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); 801 return (-1); 802 } 803 break; 804 805 806 case 'w': /* Set warning levels */ 807 switch (AcpiGbl_Optarg[0]) 808 { 809 case '1': 810 Gbl_WarningLevel = ASL_WARNING; 811 break; 812 813 case '2': 814 Gbl_WarningLevel = ASL_WARNING2; 815 break; 816 817 case '3': 818 Gbl_WarningLevel = ASL_WARNING3; 819 break; 820 821 case 'e': 822 Gbl_WarningsAsErrors = TRUE; 823 break; 824 825 default: 826 printf ("Unknown option: -w%s\n", AcpiGbl_Optarg); 827 return (-1); 828 } 829 break; 830 831 832 case 'x': /* Set debug print output level */ 833 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16); 834 break; 835 836 837 case 'z': 838 Gbl_UseOriginalCompilerId = TRUE; 839 break; 840 841 842 default: 843 return (-1); 844 } 845 846 return (0); 847 } 848 849 850 /******************************************************************************* 851 * 852 * FUNCTION: AslCommandLine 853 * 854 * PARAMETERS: argc/argv 855 * 856 * RETURN: Last argv index 857 * 858 * DESCRIPTION: Command line processing 859 * 860 ******************************************************************************/ 861 862 static int 863 AslCommandLine ( 864 int argc, 865 char **argv) 866 { 867 int BadCommandLine = 0; 868 ACPI_STATUS Status; 869 870 871 /* Minimum command line contains at least the command and an input file */ 872 873 if (argc < 2) 874 { 875 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); 876 Usage (); 877 exit (1); 878 } 879 880 /* Process all command line options */ 881 882 BadCommandLine = AslDoOptions (argc, argv, FALSE); 883 884 if (Gbl_DoTemplates) 885 { 886 Status = DtCreateTemplates (Gbl_TemplateSignature); 887 if (ACPI_FAILURE (Status)) 888 { 889 exit (-1); 890 } 891 exit (1); 892 } 893 894 /* Next parameter must be the input filename */ 895 896 if (!argv[AcpiGbl_Optind] && 897 !Gbl_DisasmFlag && 898 !Gbl_GetAllTables) 899 { 900 printf ("Missing input filename\n"); 901 BadCommandLine = TRUE; 902 } 903 904 if (Gbl_DoSignon) 905 { 906 printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); 907 if (Gbl_IgnoreErrors) 908 { 909 printf ("Ignoring all errors, forcing AML file generation\n\n"); 910 } 911 } 912 913 /* Abort if anything went wrong on the command line */ 914 915 if (BadCommandLine) 916 { 917 printf ("\n"); 918 Usage (); 919 exit (1); 920 } 921 922 return (AcpiGbl_Optind); 923 } 924 925 926 /******************************************************************************* 927 * 928 * FUNCTION: main 929 * 930 * PARAMETERS: Standard argc/argv 931 * 932 * RETURN: Program termination code 933 * 934 * DESCRIPTION: C main routine for the Asl Compiler. Handle command line 935 * options and begin the compile for each file on the command line 936 * 937 ******************************************************************************/ 938 939 int ACPI_SYSTEM_XFACE 940 main ( 941 int argc, 942 char **argv) 943 { 944 ACPI_STATUS Status; 945 int Index1; 946 int Index2; 947 948 949 AcpiGbl_ExternalFileList = NULL; 950 951 #ifdef _DEBUG 952 _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | 953 _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); 954 #endif 955 956 /* Init and command line */ 957 958 AslInitialize (); 959 PrInitializePreprocessor (); 960 Index1 = Index2 = AslCommandLine (argc, argv); 961 962 /* Options that have no additional parameters or pathnames */ 963 964 if (Gbl_GetAllTables) 965 { 966 Status = AslDoOneFile (NULL); 967 if (ACPI_FAILURE (Status)) 968 { 969 return (-1); 970 } 971 return (0); 972 } 973 974 if (Gbl_DisassembleAll) 975 { 976 while (argv[Index1]) 977 { 978 Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList); 979 if (ACPI_FAILURE (Status)) 980 { 981 return (-1); 982 } 983 984 Index1++; 985 } 986 } 987 988 /* Process each pathname/filename in the list, with possible wildcards */ 989 990 while (argv[Index2]) 991 { 992 Status = AslDoOnePathname (argv[Index2], AslDoOneFile); 993 if (ACPI_FAILURE (Status)) 994 { 995 return (-1); 996 } 997 998 Index2++; 999 } 1000 1001 if (AcpiGbl_ExternalFileList) 1002 { 1003 AcpiDmClearExternalFileList(); 1004 } 1005 1006 return (0); 1007 } 1008 1009 1010