1 /*******************************************************************************
3 * Module Name: dmcstyle - Support for C-style operator disassembly
5 ******************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2020, Intel Corp.
12 * All rights reserved.
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
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
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;
37 * The above copyright and patent license is granted only if the following
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.
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
80 * 4. Disclaimer and Export Compliance
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
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
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.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
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.
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.
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.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acparser.h>
155 #include <contrib/dev/acpica/include/amlcode.h>
156 #include <contrib/dev/acpica/include/acdebug.h>
157 #include <contrib/dev/acpica/include/acconvert.h>
160 #define _COMPONENT ACPI_CA_DEBUGGER
161 ACPI_MODULE_NAME ("dmcstyle")
164 /* Local prototypes */
167 AcpiDmGetCompoundSymbol (
171 AcpiDmPromoteTarget (
172 ACPI_PARSE_OBJECT *Op,
173 ACPI_PARSE_OBJECT *Target);
176 AcpiDmIsValidTarget (
177 ACPI_PARSE_OBJECT *Op);
180 AcpiDmIsTargetAnOperand (
181 ACPI_PARSE_OBJECT *Target,
182 ACPI_PARSE_OBJECT *Operand,
186 AcpiDmIsOptimizationIgnored (
187 ACPI_PARSE_OBJECT *StoreOp,
188 ACPI_PARSE_OBJECT *StoreArgument);
191 /*******************************************************************************
193 * FUNCTION: AcpiDmCheckForSymbolicOpcode
195 * PARAMETERS: Op - Current parse object
196 * Walk - Current parse tree walk info
198 * RETURN: TRUE if opcode can be converted to symbolic, FALSE otherwise
200 * DESCRIPTION: This is the main code that implements disassembly of AML code
201 * to C-style operators. Called during descending phase of the
204 ******************************************************************************/
207 AcpiDmCheckForSymbolicOpcode (
208 ACPI_PARSE_OBJECT *Op,
209 ACPI_OP_WALK_INFO *Info)
211 char *OperatorSymbol = NULL;
212 ACPI_PARSE_OBJECT *Argument1;
213 ACPI_PARSE_OBJECT *Argument2;
214 ACPI_PARSE_OBJECT *Target;
215 ACPI_PARSE_OBJECT *Target2;
218 /* Exit immediately if ASL+ not enabled */
220 if (!AcpiGbl_CstyleDisassembly)
225 /* Get the first operand */
227 Argument1 = AcpiPsGetArg (Op, 0);
233 /* Get the second operand */
235 Argument2 = Argument1->Common.Next;
237 /* Setup the operator string for this opcode */
239 switch (Op->Common.AmlOpcode)
242 OperatorSymbol = " + ";
245 case AML_SUBTRACT_OP:
246 OperatorSymbol = " - ";
249 case AML_MULTIPLY_OP:
250 OperatorSymbol = " * ";
254 OperatorSymbol = " / ";
258 OperatorSymbol = " % ";
261 case AML_SHIFT_LEFT_OP:
262 OperatorSymbol = " << ";
265 case AML_SHIFT_RIGHT_OP:
266 OperatorSymbol = " >> ";
270 OperatorSymbol = " & ";
274 OperatorSymbol = " | ";
278 OperatorSymbol = " ^ ";
281 /* Logical operators, no target */
283 case AML_LOGICAL_AND_OP:
284 OperatorSymbol = " && ";
287 case AML_LOGICAL_EQUAL_OP:
288 OperatorSymbol = " == ";
291 case AML_LOGICAL_GREATER_OP:
292 OperatorSymbol = " > ";
295 case AML_LOGICAL_LESS_OP:
296 OperatorSymbol = " < ";
299 case AML_LOGICAL_OR_OP:
300 OperatorSymbol = " || ";
303 case AML_LOGICAL_NOT_OP:
305 * Check for the LNOT sub-opcodes. These correspond to
306 * LNotEqual, LLessEqual, and LGreaterEqual. There are
307 * no actual AML opcodes for these operators.
309 switch (Argument1->Common.AmlOpcode)
311 case AML_LOGICAL_EQUAL_OP:
312 OperatorSymbol = " != ";
315 case AML_LOGICAL_GREATER_OP:
316 OperatorSymbol = " <= ";
319 case AML_LOGICAL_LESS_OP:
320 OperatorSymbol = " >= ";
325 /* Unary LNOT case, emit "!" immediately */
331 Argument1->Common.DisasmOpcode = ACPI_DASM_LNOT_SUFFIX;
332 Op->Common.DisasmOpcode = ACPI_DASM_LNOT_PREFIX;
334 /* Save symbol string in the next child (not peer) */
336 Argument2 = AcpiPsGetArg (Argument1, 0);
342 Argument2->Common.OperatorSymbol = OperatorSymbol;
347 * Check for constant source operand. Note: although technically
348 * legal syntax, the iASL compiler does not support this with
349 * the symbolic operators for Index(). It doesn't make sense to
350 * use Index() with a constant anyway.
352 if ((Argument1->Common.AmlOpcode == AML_STRING_OP) ||
353 (Argument1->Common.AmlOpcode == AML_BUFFER_OP) ||
354 (Argument1->Common.AmlOpcode == AML_PACKAGE_OP) ||
355 (Argument1->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
357 Op->Common.DisasmFlags |= ACPI_PARSEOP_CLOSING_PAREN;
361 /* Index operator is [] */
363 Argument1->Common.OperatorSymbol = " [";
364 Argument2->Common.OperatorSymbol = "]";
367 /* Unary operators */
369 case AML_DECREMENT_OP:
370 OperatorSymbol = "--";
373 case AML_INCREMENT_OP:
374 OperatorSymbol = "++";
379 OperatorSymbol = NULL;
386 if (Argument1->Common.DisasmOpcode == ACPI_DASM_LNOT_SUFFIX)
392 * This is the key to how the disassembly of the C-style operators
393 * works. We save the operator symbol in the first child, thus
394 * deferring symbol output until after the first operand has been
397 if (!Argument1->Common.OperatorSymbol)
399 Argument1->Common.OperatorSymbol = OperatorSymbol;
403 * Check for a valid target as the 3rd (or sometimes 2nd) operand
405 * Compound assignment operator support:
406 * Attempt to optimize constructs of the form:
407 * Add (Local1, 0xFF, Local1)
411 * Only the math operators and Store() have a target.
412 * Logicals have no target.
414 switch (Op->Common.AmlOpcode)
417 case AML_SUBTRACT_OP:
418 case AML_MULTIPLY_OP:
421 case AML_SHIFT_LEFT_OP:
422 case AML_SHIFT_RIGHT_OP:
427 /* Target is 3rd operand */
429 Target = Argument2->Common.Next;
430 if (Op->Common.AmlOpcode == AML_DIVIDE_OP)
432 Target2 = Target->Common.Next;
435 * Divide has an extra target operand (Remainder).
436 * Default behavior is to simply ignore ASL+ conversion
437 * if the remainder target (modulo) is specified.
439 if (!AcpiGbl_DoDisassemblerOptimizations)
441 if (AcpiDmIsValidTarget (Target))
443 Argument1->Common.OperatorSymbol = NULL;
444 Op->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
448 Target->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
454 * Divide has an extra target operand (Remainder).
455 * If both targets are specified, it cannot be converted
456 * to a C-style operator.
458 if (AcpiDmIsValidTarget (Target) &&
459 AcpiDmIsValidTarget (Target2))
461 Argument1->Common.OperatorSymbol = NULL;
462 Op->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
466 if (AcpiDmIsValidTarget (Target)) /* Only first Target is valid (remainder) */
468 /* Convert the Divide to Modulo */
470 Op->Common.AmlOpcode = AML_MOD_OP;
472 Argument1->Common.OperatorSymbol = " % ";
473 Target2->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
475 else /* Only second Target (quotient) is valid */
477 Target->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
483 /* Parser should ensure there is at least a placeholder target */
490 if (!AcpiDmIsValidTarget (Target))
492 /* Not a valid target (placeholder only, from parser) */
497 * Promote the target up to the first child in the parse
498 * tree. This is done because the target will be output
499 * first, in the form:
500 * <Target> = Operands...
502 AcpiDmPromoteTarget (Op, Target);
504 /* Check operands for conversion to a "Compound Assignment" */
506 switch (Op->Common.AmlOpcode)
508 /* Commutative operators */
511 case AML_MULTIPLY_OP:
516 * For the commutative operators, we can convert to a
517 * compound statement only if at least one (either) operand
518 * is the same as the target.
520 * Add (A, B, A) --> A += B
521 * Add (B, A, A) --> A += B
522 * Add (B, C, A) --> A = (B + C)
524 if ((AcpiDmIsTargetAnOperand (Target, Argument1, TRUE)) ||
525 (AcpiDmIsTargetAnOperand (Target, Argument2, TRUE)))
527 Target->Common.OperatorSymbol =
528 AcpiDmGetCompoundSymbol (Op->Common.AmlOpcode);
530 /* Convert operator to compound assignment */
532 Op->Common.DisasmFlags |= ACPI_PARSEOP_COMPOUND_ASSIGNMENT;
533 Argument1->Common.OperatorSymbol = NULL;
538 /* Non-commutative operators */
540 case AML_SUBTRACT_OP:
543 case AML_SHIFT_LEFT_OP:
544 case AML_SHIFT_RIGHT_OP:
546 * For the non-commutative operators, we can convert to a
547 * compound statement only if the target is the same as the
550 * Subtract (A, B, A) --> A -= B
551 * Subtract (B, A, A) --> A = (B - A)
553 if ((AcpiDmIsTargetAnOperand (Target, Argument1, TRUE)))
555 Target->Common.OperatorSymbol =
556 AcpiDmGetCompoundSymbol (Op->Common.AmlOpcode);
558 /* Convert operator to compound assignment */
560 Op->Common.DisasmFlags |= ACPI_PARSEOP_COMPOUND_ASSIGNMENT;
561 Argument1->Common.OperatorSymbol = NULL;
571 * If we are within a C-style expression, emit an extra open
572 * paren. Implemented by examining the parent op.
574 switch (Op->Common.Parent->Common.AmlOpcode)
577 case AML_SUBTRACT_OP:
578 case AML_MULTIPLY_OP:
581 case AML_SHIFT_LEFT_OP:
582 case AML_SHIFT_RIGHT_OP:
586 case AML_LOGICAL_AND_OP:
587 case AML_LOGICAL_EQUAL_OP:
588 case AML_LOGICAL_GREATER_OP:
589 case AML_LOGICAL_LESS_OP:
590 case AML_LOGICAL_OR_OP:
592 Op->Common.DisasmFlags |= ACPI_PARSEOP_ASSIGNMENT;
600 /* Normal output for ASL/AML operators with a target operand */
602 Target->Common.OperatorSymbol = " = (";
605 /* Binary operators, no parens */
607 case AML_DECREMENT_OP:
608 case AML_INCREMENT_OP:
613 /* Target is optional, 3rd operand */
615 Target = Argument2->Common.Next;
616 if (AcpiDmIsValidTarget (Target))
618 AcpiDmPromoteTarget (Op, Target);
620 if (!Target->Common.OperatorSymbol)
622 Target->Common.OperatorSymbol = " = ";
629 * For Store, the Target is the 2nd operand. We know the target
630 * is valid, because it is not optional.
632 * Ignore any optimizations/folding if flag is set.
633 * Used for iASL/disassembler test suite only.
635 if (AcpiDmIsOptimizationIgnored (Op, Argument1))
641 * Perform conversion.
642 * In the parse tree, simply swap the target with the
643 * source so that the target is processed first.
645 Target = Argument1->Common.Next;
651 AcpiDmPromoteTarget (Op, Target);
652 if (!Target->Common.OperatorSymbol)
654 Target->Common.OperatorSymbol = " = ";
660 /* Target is optional, 2nd operand */
662 Target = Argument1->Common.Next;
668 if (AcpiDmIsValidTarget (Target))
670 /* Valid target, not a placeholder */
672 AcpiDmPromoteTarget (Op, Target);
673 Target->Common.OperatorSymbol = " = ~";
677 /* No target. Emit this prefix operator immediately */
687 /* All other operators, emit an open paren */
694 /*******************************************************************************
696 * FUNCTION: AcpiDmIsOptimizationIgnored
698 * PARAMETERS: StoreOp - Store operator parse object
699 * StoreArgument - Target associate with the Op
701 * RETURN: TRUE if this Store operator should not be converted/removed.
703 * DESCRIPTION: The following function implements "Do not optimize if a
704 * store is immediately followed by a math/bit operator that
707 * Function is ignored if DoDisassemblerOptimizations is TRUE.
708 * This is the default, ignore this function.
710 * Disables these types of optimizations, and simply emits
712 * Store (Add (INT1, 4), INT2) --> Add (INT1, 4, INT2)
713 * --> INT2 = INT1 + 4
715 * Store (Not (INT1), INT2) --> Not (INT1, INT2)
718 * Used only for the ASL test suite. For the test suite, we
719 * don't want to perform some optimizations to ensure binary
720 * compatibility with the generation of the legacy ASL->AML.
721 * In other words, for all test modules we want exactly:
722 * (ASL+ -> AML) == (ASL- -> AML)
724 ******************************************************************************/
727 AcpiDmIsOptimizationIgnored (
728 ACPI_PARSE_OBJECT *StoreOp,
729 ACPI_PARSE_OBJECT *StoreArgument)
731 ACPI_PARSE_OBJECT *Argument1;
732 ACPI_PARSE_OBJECT *Argument2;
733 ACPI_PARSE_OBJECT *Target;
736 /* No optimizations/folding for the typical case */
738 if (AcpiGbl_DoDisassemblerOptimizations)
744 * Only a small subset of ASL/AML operators can be optimized.
745 * Can only optimize/fold if there is no target (or targets)
746 * specified for the operator. And of course, the operator
747 * is surrounded by a Store() operator.
749 switch (StoreArgument->Common.AmlOpcode)
752 case AML_SUBTRACT_OP:
753 case AML_MULTIPLY_OP:
755 case AML_SHIFT_LEFT_OP:
756 case AML_SHIFT_RIGHT_OP:
762 /* These operators have two arguments and one target */
764 Argument1 = StoreArgument->Common.Value.Arg;
765 Argument2 = Argument1->Common.Next;
766 Target = Argument2->Common.Next;
768 if (!AcpiDmIsValidTarget (Target))
770 StoreOp->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
777 /* This operator has two arguments and two targets */
779 Argument1 = StoreArgument->Common.Value.Arg;
780 Argument2 = Argument1->Common.Next;
781 Target = Argument2->Common.Next;
783 if (!AcpiDmIsValidTarget (Target) ||
784 !AcpiDmIsValidTarget (Target->Common.Next))
786 StoreOp->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
793 /* This operator has one operand and one target */
795 Argument1 = StoreArgument->Common.Value.Arg;
796 Target = Argument1->Common.Next;
798 if (!AcpiDmIsValidTarget (Target))
800 StoreOp->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
813 /*******************************************************************************
815 * FUNCTION: AcpiDmCloseOperator
817 * PARAMETERS: Op - Current parse object
821 * DESCRIPTION: Closes an operator by adding a closing parentheses if and
822 * when necessary. Called during ascending phase of the
825 ******************************************************************************/
828 AcpiDmCloseOperator (
829 ACPI_PARSE_OBJECT *Op)
832 /* Always emit paren if ASL+ disassembly disabled */
834 if (!AcpiGbl_CstyleDisassembly)
837 ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
841 if (Op->Common.DisasmFlags & ACPI_PARSEOP_LEGACY_ASL_ONLY)
844 ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
848 /* Check if we need to add an additional closing paren */
850 switch (Op->Common.AmlOpcode)
853 case AML_SUBTRACT_OP:
854 case AML_MULTIPLY_OP:
857 case AML_SHIFT_LEFT_OP:
858 case AML_SHIFT_RIGHT_OP:
862 case AML_LOGICAL_AND_OP:
863 case AML_LOGICAL_EQUAL_OP:
864 case AML_LOGICAL_GREATER_OP:
865 case AML_LOGICAL_LESS_OP:
866 case AML_LOGICAL_OR_OP:
868 /* Emit paren only if this is not a compound assignment */
870 if (Op->Common.DisasmFlags & ACPI_PARSEOP_COMPOUND_ASSIGNMENT)
872 ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
876 /* Emit extra close paren for assignment within an expression */
878 if (Op->Common.DisasmFlags & ACPI_PARSEOP_ASSIGNMENT)
886 /* This is case for unsupported Index() source constants */
888 if (Op->Common.DisasmFlags & ACPI_PARSEOP_CLOSING_PAREN)
892 ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
895 /* No need for parens for these */
897 case AML_DECREMENT_OP:
898 case AML_INCREMENT_OP:
899 case AML_LOGICAL_NOT_OP:
902 ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
907 /* Always emit paren for non-ASL+ operators */
912 ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
918 /*******************************************************************************
920 * FUNCTION: AcpiDmGetCompoundSymbol
922 * PARAMETERS: AslOpcode
924 * RETURN: String containing the compound assignment symbol
926 * DESCRIPTION: Detect opcodes that can be converted to compound assignment,
927 * return the appropriate operator string.
929 ******************************************************************************/
932 AcpiDmGetCompoundSymbol (
944 case AML_SUBTRACT_OP:
948 case AML_MULTIPLY_OP:
960 case AML_SHIFT_LEFT_OP:
964 case AML_SHIFT_RIGHT_OP:
982 /* No operator string for all other opcodes */
991 /*******************************************************************************
993 * FUNCTION: AcpiDmPromoteTarget
995 * PARAMETERS: Op - Operator parse object
996 * Target - Target associate with the Op
1000 * DESCRIPTION: Transform the parse tree by moving the target up to the first
1003 ******************************************************************************/
1006 AcpiDmPromoteTarget (
1007 ACPI_PARSE_OBJECT *Op,
1008 ACPI_PARSE_OBJECT *Target)
1010 ACPI_PARSE_OBJECT *Child;
1013 /* Link target directly to the Op as first child */
1015 Child = Op->Common.Value.Arg;
1016 Op->Common.Value.Arg = Target;
1017 Target->Common.Next = Child;
1019 /* Find the last peer, it is linked to the target. Unlink it. */
1021 while (Child->Common.Next != Target)
1023 Child = Child->Common.Next;
1026 Child->Common.Next = NULL;
1030 /*******************************************************************************
1032 * FUNCTION: AcpiDmIsValidTarget
1034 * PARAMETERS: Target - Target Op from the parse tree
1036 * RETURN: TRUE if the Target is real. FALSE if it is just a placeholder
1037 * Op that was inserted by the parser.
1039 * DESCRIPTION: Determine if a Target Op is a placeholder Op or a real Target.
1040 * In other words, determine if the optional target is used or
1041 * not. Note: If Target is NULL, something is seriously wrong,
1042 * probably with the parse tree.
1044 ******************************************************************************/
1047 AcpiDmIsValidTarget (
1048 ACPI_PARSE_OBJECT *Target)
1056 if ((Target->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
1057 (Target->Common.Value.Arg == NULL))
1066 /*******************************************************************************
1068 * FUNCTION: AcpiDmIsTargetAnOperand
1070 * PARAMETERS: Target - Target associated with the expression
1071 * Operand - An operand associated with expression
1073 * RETURN: TRUE if expression can be converted to a compound assignment.
1076 * DESCRIPTION: Determine if the Target duplicates the operand, in order to
1077 * detect if the expression can be converted to a compound
1078 * assignment. (+=, *=, etc.)
1080 ******************************************************************************/
1083 AcpiDmIsTargetAnOperand (
1084 ACPI_PARSE_OBJECT *Target,
1085 ACPI_PARSE_OBJECT *Operand,
1088 const ACPI_OPCODE_INFO *OpInfo;
1093 * Opcodes must match. Note: ignoring the difference between nameseg
1094 * and namepath for now. May be needed later.
1096 if (Target->Common.AmlOpcode != Operand->Common.AmlOpcode)
1101 /* Nodes should match, even if they are NULL */
1103 if (Target->Common.Node != Operand->Common.Node)
1108 /* Determine if a child exists */
1110 OpInfo = AcpiPsGetOpcodeInfo (Operand->Common.AmlOpcode);
1111 if (OpInfo->Flags & AML_HAS_ARGS)
1113 Same = AcpiDmIsTargetAnOperand (Target->Common.Value.Arg,
1114 Operand->Common.Value.Arg, FALSE);
1121 /* Check the next peer, as long as we are not at the top level */
1124 Target->Common.Next)
1126 Same = AcpiDmIsTargetAnOperand (Target->Common.Next,
1127 Operand->Common.Next, FALSE);
1134 /* Suppress the duplicate operand at the top-level */
1138 Operand->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;