1 /****************************************************************************** 2 * 3 * Module Name: aslparseop - Parse op create/allocate/cache interfaces 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include <contrib/dev/acpica/compiler/aslcompiler.h> 153 #include "aslcompiler.y.h" 154 #include <contrib/dev/acpica/include/acapps.h> 155 #include <contrib/dev/acpica/include/acconvert.h> 156 157 #define _COMPONENT ACPI_COMPILER 158 ACPI_MODULE_NAME ("aslparseop") 159 160 161 /* Local prototypes */ 162 163 static ACPI_PARSE_OBJECT * 164 TrGetOpFromCache ( 165 void); 166 167 168 /******************************************************************************* 169 * 170 * FUNCTION: TrCreateOp 171 * 172 * PARAMETERS: ParseOpcode - Opcode to be assigned to the op 173 * NumChildren - Number of children to follow 174 * ... - A list of child ops to link to the new 175 * op. NumChildren long. 176 * 177 * RETURN: Pointer to the new op. Aborts on allocation failure 178 * 179 * DESCRIPTION: Create a new parse op and link together a list of child 180 * ops underneath the new op. 181 * 182 ******************************************************************************/ 183 184 ACPI_PARSE_OBJECT * 185 TrCreateOp ( 186 UINT32 ParseOpcode, 187 UINT32 NumChildren, 188 ...) 189 { 190 ACPI_PARSE_OBJECT *Op; 191 ACPI_PARSE_OBJECT *Child; 192 ACPI_PARSE_OBJECT *PrevChild; 193 va_list ap; 194 UINT32 i; 195 BOOLEAN FirstChild; 196 197 198 va_start (ap, NumChildren); 199 200 /* Allocate one new op */ 201 202 Op = TrAllocateOp (ParseOpcode); 203 204 DbgPrint (ASL_PARSE_OUTPUT, 205 "\nCreateOp Ln/Col %u/%u NewParent %p Child %u Op %s ", 206 Op->Asl.LineNumber, Op->Asl.Column, Op, 207 NumChildren, UtGetOpName(ParseOpcode)); 208 209 /* Some extra debug output based on the parse opcode */ 210 211 switch (ParseOpcode) 212 { 213 case PARSEOP_ASL_CODE: 214 215 Gbl_ParseTreeRoot = Op; 216 Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; 217 DbgPrint (ASL_PARSE_OUTPUT, "ASLCODE (Tree Completed)->"); 218 break; 219 220 case PARSEOP_DEFINITION_BLOCK: 221 222 DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->"); 223 break; 224 225 case PARSEOP_OPERATIONREGION: 226 227 DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->"); 228 break; 229 230 case PARSEOP_OR: 231 232 DbgPrint (ASL_PARSE_OUTPUT, "OR->"); 233 break; 234 235 default: 236 237 /* Nothing to do for other opcodes */ 238 239 break; 240 } 241 242 /* Link the new op to its children */ 243 244 PrevChild = NULL; 245 FirstChild = TRUE; 246 for (i = 0; i < NumChildren; i++) 247 { 248 /* Get the next child */ 249 250 Child = va_arg (ap, ACPI_PARSE_OBJECT *); 251 DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child); 252 253 /* 254 * If child is NULL, this means that an optional argument 255 * was omitted. We must create a placeholder with a special 256 * opcode (DEFAULT_ARG) so that the code generator will know 257 * that it must emit the correct default for this argument 258 */ 259 if (!Child) 260 { 261 Child = TrAllocateOp (PARSEOP_DEFAULT_ARG); 262 } 263 264 /* Link first child to parent */ 265 266 if (FirstChild) 267 { 268 FirstChild = FALSE; 269 Op->Asl.Child = Child; 270 271 /* 272 * For the ASL-/ASL+ converter: if the ParseOp is a Connection, 273 * External, Offset or AccessAs, it means that the comments in the 274 * FirstChild belongs to their parent due to the parsing order in 275 * the .y files. To correct this, take the comments in the 276 * FirstChild place it in the parent. This also means that 277 * legitimate comments for the child gets put to the parent. 278 */ 279 if (Gbl_CaptureComments && 280 ((ParseOpcode == PARSEOP_CONNECTION) || 281 (ParseOpcode == PARSEOP_EXTERNAL) || 282 (ParseOpcode == PARSEOP_OFFSET) || 283 (ParseOpcode == PARSEOP_ACCESSAS))) 284 { 285 Op->Asl.CommentList = Child->Asl.CommentList; 286 Op->Asl.EndBlkComment = Child->Asl.EndBlkComment; 287 Op->Asl.InlineComment = Child->Asl.InlineComment; 288 Op->Asl.FileChanged = Child->Asl.FileChanged; 289 290 Child->Asl.CommentList = NULL; 291 Child->Asl.EndBlkComment = NULL; 292 Child->Asl.InlineComment = NULL; 293 Child->Asl.FileChanged = FALSE; 294 295 /* 296 * These do not need to be "passed off". They can be copied 297 * because the code for these opcodes should be printed in the 298 * same file. 299 */ 300 Op->Asl.Filename = Child->Asl.Filename; 301 Op->Asl.ParentFilename = Child->Asl.ParentFilename; 302 } 303 } 304 305 /* Point all children to parent */ 306 307 Child->Asl.Parent = Op; 308 309 /* Link children in a peer list */ 310 311 if (PrevChild) 312 { 313 PrevChild->Asl.Next = Child; 314 }; 315 316 /* Get the comment from last child in the resource template call */ 317 318 if (Gbl_CaptureComments && 319 (Op->Asl.ParseOpcode == PARSEOP_RESOURCETEMPLATE)) 320 { 321 CvDbgPrint ("Transferred current comment list to this op.\n"); 322 Op->Asl.CommentList = Child->Asl.CommentList; 323 Child->Asl.CommentList = NULL; 324 325 Op->Asl.InlineComment = Child->Asl.InlineComment; 326 Child->Asl.InlineComment = NULL; 327 } 328 329 /* 330 * This child might be a list, point all ops in the list 331 * to the same parent 332 */ 333 while (Child->Asl.Next) 334 { 335 Child = Child->Asl.Next; 336 Child->Asl.Parent = Op; 337 } 338 339 PrevChild = Child; 340 } 341 342 va_end(ap); 343 DbgPrint (ASL_PARSE_OUTPUT, "\n"); 344 return (Op); 345 } 346 347 348 /******************************************************************************* 349 * 350 * FUNCTION: TrCreateLeafOp 351 * 352 * PARAMETERS: ParseOpcode - New opcode to be assigned to the op 353 * 354 * RETURN: Pointer to the new op. Aborts on allocation failure 355 * 356 * DESCRIPTION: Create a simple leaf op (no children or peers, and no value 357 * assigned to the op) 358 * 359 ******************************************************************************/ 360 361 ACPI_PARSE_OBJECT * 362 TrCreateLeafOp ( 363 UINT32 ParseOpcode) 364 { 365 ACPI_PARSE_OBJECT *Op; 366 367 368 Op = TrAllocateOp (ParseOpcode); 369 370 DbgPrint (ASL_PARSE_OUTPUT, 371 "\nCreateLeafOp Ln/Col %u/%u NewOp %p Op %s\n\n", 372 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode)); 373 374 return (Op); 375 } 376 377 378 /******************************************************************************* 379 * 380 * FUNCTION: TrCreateValuedLeafOp 381 * 382 * PARAMETERS: ParseOpcode - New opcode to be assigned to the op 383 * Value - Value to be assigned to the op 384 * 385 * RETURN: Pointer to the new op. Aborts on allocation failure 386 * 387 * DESCRIPTION: Create a leaf op (no children or peers) with a value 388 * assigned to it 389 * 390 ******************************************************************************/ 391 392 ACPI_PARSE_OBJECT * 393 TrCreateValuedLeafOp ( 394 UINT32 ParseOpcode, 395 UINT64 Value) 396 { 397 ACPI_PARSE_OBJECT *Op; 398 399 400 Op = TrAllocateOp (ParseOpcode); 401 Op->Asl.Value.Integer = Value; 402 403 DbgPrint (ASL_PARSE_OUTPUT, 404 "\nCreateValuedLeafOp Ln/Col %u/%u NewOp %p " 405 "Op %s Value %8.8X%8.8X ", 406 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode), 407 ACPI_FORMAT_UINT64 (Value)); 408 409 switch (ParseOpcode) 410 { 411 case PARSEOP_STRING_LITERAL: 412 413 DbgPrint (ASL_PARSE_OUTPUT, "STRING->%s", Value); 414 break; 415 416 case PARSEOP_NAMESEG: 417 418 DbgPrint (ASL_PARSE_OUTPUT, "NAMESEG->%s", Value); 419 break; 420 421 case PARSEOP_NAMESTRING: 422 423 DbgPrint (ASL_PARSE_OUTPUT, "NAMESTRING->%s", Value); 424 break; 425 426 case PARSEOP_EISAID: 427 428 DbgPrint (ASL_PARSE_OUTPUT, "EISAID->%s", Value); 429 break; 430 431 case PARSEOP_METHOD: 432 433 DbgPrint (ASL_PARSE_OUTPUT, "METHOD"); 434 break; 435 436 case PARSEOP_INTEGER: 437 438 DbgPrint (ASL_PARSE_OUTPUT, "INTEGER->%8.8X%8.8X", 439 ACPI_FORMAT_UINT64 (Value)); 440 break; 441 442 default: 443 break; 444 } 445 446 DbgPrint (ASL_PARSE_OUTPUT, "\n\n"); 447 return (Op); 448 } 449 450 451 /******************************************************************************* 452 * 453 * FUNCTION: TrCreateTargetOp 454 * 455 * PARAMETERS: OriginalOp - Op to be copied 456 * 457 * RETURN: Pointer to the new op. Aborts on allocation failure 458 * 459 * DESCRIPTION: Copy an existing op (and subtree). Used in ASL+ (C-style) 460 * expressions where the target is the same as one of the 461 * operands. A new op and subtree must be created from the 462 * original so that the parse tree can be linked properly. 463 * 464 * NOTE: This code is specific to target operands that are the last 465 * operand in an ASL/AML operator. Meaning that the top-level 466 * parse Op in a possible subtree has a NULL Next pointer. 467 * This simplifies the recursion. 468 * 469 * Subtree example: 470 * DeRefOf (Local1) += 32 471 * 472 * This gets converted to: 473 * Add (DeRefOf (Local1), 32, DeRefOf (Local1)) 474 * 475 * Each DeRefOf has a single child, Local1. Even more complex 476 * subtrees can be created via the Index and DeRefOf operators. 477 * 478 ******************************************************************************/ 479 480 ACPI_PARSE_OBJECT * 481 TrCreateTargetOp ( 482 ACPI_PARSE_OBJECT *OriginalOp, 483 ACPI_PARSE_OBJECT *ParentOp) 484 { 485 ACPI_PARSE_OBJECT *Op; 486 487 488 if (!OriginalOp) 489 { 490 return (NULL); 491 } 492 493 Op = TrGetOpFromCache (); 494 495 /* Copy the pertinent values (omit link pointer fields) */ 496 497 Op->Asl.Value = OriginalOp->Asl.Value; 498 Op->Asl.Filename = OriginalOp->Asl.Filename; 499 Op->Asl.LineNumber = OriginalOp->Asl.LineNumber; 500 Op->Asl.LogicalLineNumber = OriginalOp->Asl.LogicalLineNumber; 501 Op->Asl.LogicalByteOffset = OriginalOp->Asl.LogicalByteOffset; 502 Op->Asl.Column = OriginalOp->Asl.Column; 503 Op->Asl.Flags = OriginalOp->Asl.Flags; 504 Op->Asl.CompileFlags = OriginalOp->Asl.CompileFlags; 505 Op->Asl.AmlOpcode = OriginalOp->Asl.AmlOpcode; 506 Op->Asl.ParseOpcode = OriginalOp->Asl.ParseOpcode; 507 Op->Asl.Parent = ParentOp; 508 509 UtSetParseOpName (Op); 510 511 /* Copy a possible subtree below this op */ 512 513 if (OriginalOp->Asl.Child) 514 { 515 Op->Asl.Child = TrCreateTargetOp (OriginalOp->Asl.Child, Op); 516 } 517 518 if (OriginalOp->Asl.Next) /* Null for top-level op */ 519 { 520 Op->Asl.Next = TrCreateTargetOp (OriginalOp->Asl.Next, ParentOp); 521 } 522 523 return (Op); 524 } 525 526 527 /******************************************************************************* 528 * 529 * FUNCTION: TrCreateAssignmentOp 530 * 531 * PARAMETERS: Target - Assignment target 532 * Source - Assignment source 533 * 534 * RETURN: Pointer to the new op. Aborts on allocation failure 535 * 536 * DESCRIPTION: Implements the C-style '=' operator. It changes the parse 537 * tree if possible to utilize the last argument of the math 538 * operators which is a target operand -- thus saving invocation 539 * of and additional Store() operator. An optimization. 540 * 541 ******************************************************************************/ 542 543 ACPI_PARSE_OBJECT * 544 TrCreateAssignmentOp ( 545 ACPI_PARSE_OBJECT *Target, 546 ACPI_PARSE_OBJECT *Source) 547 { 548 ACPI_PARSE_OBJECT *TargetOp; 549 ACPI_PARSE_OBJECT *SourceOp1; 550 ACPI_PARSE_OBJECT *SourceOp2; 551 ACPI_PARSE_OBJECT *Operator; 552 553 554 DbgPrint (ASL_PARSE_OUTPUT, 555 "\nTrCreateAssignmentOp Line [%u to %u] Source %s Target %s\n", 556 Source->Asl.LineNumber, Source->Asl.EndLine, 557 UtGetOpName (Source->Asl.ParseOpcode), 558 UtGetOpName (Target->Asl.ParseOpcode)); 559 560 TrSetOpFlags (Target, OP_IS_TARGET); 561 562 switch (Source->Asl.ParseOpcode) 563 { 564 /* 565 * Only these operators can be optimized because they have 566 * a target operand 567 */ 568 case PARSEOP_ADD: 569 case PARSEOP_AND: 570 case PARSEOP_DIVIDE: 571 case PARSEOP_INDEX: 572 case PARSEOP_MOD: 573 case PARSEOP_MULTIPLY: 574 case PARSEOP_NOT: 575 case PARSEOP_OR: 576 case PARSEOP_SHIFTLEFT: 577 case PARSEOP_SHIFTRIGHT: 578 case PARSEOP_SUBTRACT: 579 case PARSEOP_XOR: 580 581 break; 582 583 /* Otherwise, just create a normal Store operator */ 584 585 default: 586 goto CannotOptimize; 587 } 588 589 /* 590 * Transform the parse tree such that the target is moved to the 591 * last operand of the operator 592 */ 593 SourceOp1 = Source->Asl.Child; 594 SourceOp2 = SourceOp1->Asl.Next; 595 596 /* NOT only has one operand, but has a target */ 597 598 if (Source->Asl.ParseOpcode == PARSEOP_NOT) 599 { 600 SourceOp2 = SourceOp1; 601 } 602 603 /* DIVIDE has an extra target operand (remainder) */ 604 605 if (Source->Asl.ParseOpcode == PARSEOP_DIVIDE) 606 { 607 SourceOp2 = SourceOp2->Asl.Next; 608 } 609 610 TargetOp = SourceOp2->Asl.Next; 611 612 /* 613 * Can't perform this optimization if there already is a target 614 * for the operator (ZERO is a "no target" placeholder). 615 */ 616 if (TargetOp->Asl.ParseOpcode != PARSEOP_ZERO) 617 { 618 goto CannotOptimize; 619 } 620 621 /* Link in the target as the final operand */ 622 623 SourceOp2->Asl.Next = Target; 624 Target->Asl.Parent = Source; 625 return (Source); 626 627 628 CannotOptimize: 629 630 Operator = TrAllocateOp (PARSEOP_STORE); 631 TrLinkOpChildren (Operator, 2, Source, Target); 632 633 /* Set the appropriate line numbers for the new op */ 634 635 Operator->Asl.LineNumber = Target->Asl.LineNumber; 636 Operator->Asl.LogicalLineNumber = Target->Asl.LogicalLineNumber; 637 Operator->Asl.LogicalByteOffset = Target->Asl.LogicalByteOffset; 638 Operator->Asl.Column = Target->Asl.Column; 639 640 return (Operator); 641 } 642 643 644 /******************************************************************************* 645 * 646 * FUNCTION: TrCreateNullTargetOp 647 * 648 * PARAMETERS: None 649 * 650 * RETURN: Pointer to the new op. Aborts on allocation failure 651 * 652 * DESCRIPTION: Create a "null" target op. This is defined by the ACPI 653 * specification to be a zero AML opcode, and indicates that 654 * no target has been specified for the parent operation 655 * 656 ******************************************************************************/ 657 658 ACPI_PARSE_OBJECT * 659 TrCreateNullTargetOp ( 660 void) 661 { 662 ACPI_PARSE_OBJECT *Op; 663 664 665 Op = TrAllocateOp (PARSEOP_ZERO); 666 Op->Asl.CompileFlags |= (OP_IS_TARGET | OP_COMPILE_TIME_CONST); 667 668 DbgPrint (ASL_PARSE_OUTPUT, 669 "\nCreateNullTargetOp Ln/Col %u/%u NewOp %p Op %s\n", 670 Op->Asl.LineNumber, Op->Asl.Column, Op, 671 UtGetOpName (Op->Asl.ParseOpcode)); 672 673 return (Op); 674 } 675 676 677 /******************************************************************************* 678 * 679 * FUNCTION: TrCreateConstantLeafOp 680 * 681 * PARAMETERS: ParseOpcode - The constant opcode 682 * 683 * RETURN: Pointer to the new op. Aborts on allocation failure 684 * 685 * DESCRIPTION: Create a leaf op (no children or peers) for one of the 686 * special constants - __LINE__, __FILE__, and __DATE__. 687 * 688 * Note: The fullimplemenation of __METHOD__ cannot happen here because we 689 * don't have a full parse tree at this time and cannot find the parent 690 * control method. __METHOD__ must be implemented later, after the parse 691 * tree has been fully constructed. 692 * 693 ******************************************************************************/ 694 695 ACPI_PARSE_OBJECT * 696 TrCreateConstantLeafOp ( 697 UINT32 ParseOpcode) 698 { 699 ACPI_PARSE_OBJECT *Op = NULL; 700 time_t CurrentTime; 701 char *StaticTimeString; 702 char *TimeString; 703 char *Filename; 704 705 706 switch (ParseOpcode) 707 { 708 case PARSEOP___LINE__: 709 710 Op = TrAllocateOp (PARSEOP_INTEGER); 711 Op->Asl.Value.Integer = Op->Asl.LineNumber; 712 break; 713 714 case PARSEOP___METHOD__: 715 716 /* Will become a string literal later */ 717 718 Op = TrAllocateOp (PARSEOP___METHOD__); 719 Op->Asl.Value.String = NULL; 720 break; 721 722 case PARSEOP___PATH__: 723 724 Op = TrAllocateOp (PARSEOP_STRING_LITERAL); 725 726 /* Op.Asl.Filename contains the full pathname to the file */ 727 728 Op->Asl.Value.String = Op->Asl.Filename; 729 break; 730 731 case PARSEOP___FILE__: 732 733 Op = TrAllocateOp (PARSEOP_STRING_LITERAL); 734 735 /* Get the simple filename from the full path */ 736 737 FlSplitInputPathname (Op->Asl.Filename, NULL, &Filename); 738 Op->Asl.Value.String = Filename; 739 break; 740 741 case PARSEOP___DATE__: 742 743 Op = TrAllocateOp (PARSEOP_STRING_LITERAL); 744 745 /* Get a copy of the current time */ 746 747 CurrentTime = time (NULL); 748 StaticTimeString = ctime (&CurrentTime); 749 TimeString = UtLocalCalloc (strlen (StaticTimeString) + 1); 750 strcpy (TimeString, StaticTimeString); 751 752 TimeString[strlen(TimeString) -1] = 0; /* Remove trailing newline */ 753 Op->Asl.Value.String = TimeString; 754 break; 755 756 default: /* This would be an internal error */ 757 758 return (NULL); 759 } 760 761 DbgPrint (ASL_PARSE_OUTPUT, 762 "\nCreateConstantLeafOp Ln/Col %u/%u NewOp %p " 763 "Op %s Value %8.8X%8.8X \n", 764 Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode), 765 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer)); 766 767 return (Op); 768 } 769 770 771 /******************************************************************************* 772 * 773 * FUNCTION: TrAllocateOp 774 * 775 * PARAMETERS: ParseOpcode - Opcode to be assigned to the op 776 * 777 * RETURN: New parse op. Aborts on allocation failure 778 * 779 * DESCRIPTION: Allocate and initialize a new parse op for the parse tree 780 * 781 ******************************************************************************/ 782 783 ACPI_PARSE_OBJECT * 784 TrAllocateOp ( 785 UINT32 ParseOpcode) 786 { 787 ACPI_PARSE_OBJECT *Op; 788 ACPI_PARSE_OBJECT *LatestOp; 789 790 791 Op = TrGetOpFromCache (); 792 793 Op->Asl.ParseOpcode = (UINT16) ParseOpcode; 794 Op->Asl.Filename = Gbl_Files[ASL_FILE_INPUT].Filename; 795 Op->Asl.LineNumber = Gbl_CurrentLineNumber; 796 Op->Asl.LogicalLineNumber = Gbl_LogicalLineNumber; 797 Op->Asl.LogicalByteOffset = Gbl_CurrentLineOffset; 798 Op->Asl.Column = Gbl_CurrentColumn; 799 800 UtSetParseOpName (Op); 801 802 /* The following is for capturing comments */ 803 804 if(Gbl_CaptureComments) 805 { 806 LatestOp = Gbl_CommentState.LatestParseOp; 807 Op->Asl.InlineComment = NULL; 808 Op->Asl.EndNodeComment = NULL; 809 Op->Asl.CommentList = NULL; 810 Op->Asl.FileChanged = FALSE; 811 812 /* 813 * Check to see if the file name has changed before resetting the 814 * latest parse op. 815 */ 816 if (LatestOp && 817 (ParseOpcode != PARSEOP_INCLUDE) && 818 (ParseOpcode != PARSEOP_INCLUDE_END) && 819 strcmp (LatestOp->Asl.Filename, Op->Asl.Filename)) 820 { 821 CvDbgPrint ("latest op: %s\n", LatestOp->Asl.ParseOpName); 822 Op->Asl.FileChanged = TRUE; 823 if (Gbl_IncludeFileStack) 824 { 825 Op->Asl.ParentFilename = Gbl_IncludeFileStack->Filename; 826 } 827 else 828 { 829 Op->Asl.ParentFilename = NULL; 830 } 831 } 832 833 Gbl_CommentState.LatestParseOp = Op; 834 CvDbgPrint ("TrAllocateOp=Set latest parse op to this op.\n"); 835 CvDbgPrint (" Op->Asl.ParseOpName = %s\n", 836 Gbl_CommentState.LatestParseOp->Asl.ParseOpName); 837 CvDbgPrint (" Op->Asl.ParseOpcode = 0x%x\n", ParseOpcode); 838 839 if (Op->Asl.FileChanged) 840 { 841 CvDbgPrint(" file has been changed!\n"); 842 } 843 844 /* 845 * if this parse op's syntax uses () and {} (i.e. Package(1){0x00}) then 846 * set a flag in the comment state. This facilitates paring comments for 847 * these types of opcodes. 848 */ 849 if ((CvParseOpBlockType(Op) == (BLOCK_PAREN | BLOCK_BRACE)) && 850 (ParseOpcode != PARSEOP_DEFINITION_BLOCK)) 851 { 852 CvDbgPrint ("Parsing paren/Brace op now!\n"); 853 Gbl_CommentState.ParsingParenBraceNode = Op; 854 } 855 856 if (Gbl_CommentListHead) 857 { 858 CvDbgPrint ("Transferring...\n"); 859 Op->Asl.CommentList = Gbl_CommentListHead; 860 Gbl_CommentListHead = NULL; 861 Gbl_CommentListTail = NULL; 862 CvDbgPrint (" Transferred current comment list to this op.\n"); 863 CvDbgPrint (" %s\n", Op->Asl.CommentList->Comment); 864 } 865 866 if (Gbl_InlineCommentBuffer) 867 { 868 Op->Asl.InlineComment = Gbl_InlineCommentBuffer; 869 Gbl_InlineCommentBuffer = NULL; 870 CvDbgPrint ("Transferred current inline comment list to this op.\n"); 871 } 872 } 873 874 return (Op); 875 } 876 877 878 /******************************************************************************* 879 * 880 * FUNCTION: TrGetOpFromCache 881 * 882 * PARAMETERS: None 883 * 884 * RETURN: New parse op. Aborts on allocation failure 885 * 886 * DESCRIPTION: Allocate a new parse op for the parse tree. Bypass the local 887 * dynamic memory manager for performance reasons (This has a 888 * major impact on the speed of the compiler.) 889 * 890 ******************************************************************************/ 891 892 static ACPI_PARSE_OBJECT * 893 TrGetOpFromCache ( 894 void) 895 { 896 ASL_CACHE_INFO *Cache; 897 898 899 if (Gbl_ParseOpCacheNext >= Gbl_ParseOpCacheLast) 900 { 901 /* Allocate a new buffer */ 902 903 Cache = UtLocalCalloc (sizeof (Cache->Next) + 904 (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE)); 905 906 /* Link new cache buffer to head of list */ 907 908 Cache->Next = Gbl_ParseOpCacheList; 909 Gbl_ParseOpCacheList = Cache; 910 911 /* Setup cache management pointers */ 912 913 Gbl_ParseOpCacheNext = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, Cache->Buffer); 914 Gbl_ParseOpCacheLast = Gbl_ParseOpCacheNext + ASL_PARSEOP_CACHE_SIZE; 915 } 916 917 Gbl_ParseOpCount++; 918 return (Gbl_ParseOpCacheNext++); 919 } 920 921 922 /******************************************************************************* 923 * 924 * FUNCTION: TrPrintOpFlags 925 * 926 * PARAMETERS: Flags - Flags word to be decoded 927 * OutputLevel - Debug output level: ASL_TREE_OUTPUT etc. 928 * 929 * RETURN: None 930 * 931 * DESCRIPTION: Decode a flags word to text. Displays all flags that are set. 932 * 933 ******************************************************************************/ 934 935 void 936 TrPrintOpFlags ( 937 UINT32 Flags, 938 UINT32 OutputLevel) 939 { 940 UINT32 FlagBit = 1; 941 UINT32 i; 942 943 944 for (i = 0; i < ACPI_NUM_OP_FLAGS; i++) 945 { 946 if (Flags & FlagBit) 947 { 948 DbgPrint (OutputLevel, " %s", Gbl_OpFlagNames[i]); 949 } 950 951 FlagBit <<= 1; 952 } 953 } 954