asltransform.c (a009b7dcabdc27aa3fdde1f2c6dd08d4fe5a3170) asltransform.c (f9a6772ec354ef7acdcc3de0167e31461ab78a38)
1/******************************************************************************
2 *
3 * Module Name: asltransform - Parse tree transforms
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *

--- 137 unchanged lines hidden (view full) ---

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"
1/******************************************************************************
2 *
3 * Module Name: asltransform - Parse tree transforms
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *

--- 137 unchanged lines hidden (view full) ---

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/acnamesp.h>
154
155#define _COMPONENT ACPI_COMPILER
156 ACPI_MODULE_NAME ("asltransform")
157
158/* Local prototypes */
159
160static void
161TrTransformSubtree (

--- 27 unchanged lines hidden (view full) ---

189static void
190TrDoDefinitionBlock (
191 ACPI_PARSE_OBJECT *Op);
192
193static void
194TrDoSwitch (
195 ACPI_PARSE_OBJECT *StartNode);
196
155
156#define _COMPONENT ACPI_COMPILER
157 ACPI_MODULE_NAME ("asltransform")
158
159/* Local prototypes */
160
161static void
162TrTransformSubtree (

--- 27 unchanged lines hidden (view full) ---

190static void
191TrDoDefinitionBlock (
192 ACPI_PARSE_OBJECT *Op);
193
194static void
195TrDoSwitch (
196 ACPI_PARSE_OBJECT *StartNode);
197
198static void
199TrCheckForDuplicateCase (
200 ACPI_PARSE_OBJECT *CaseOp,
201 ACPI_PARSE_OBJECT *Predicate1);
197
202
203static BOOLEAN
204TrCheckForBufferMatch (
205 ACPI_PARSE_OBJECT *Next1,
206 ACPI_PARSE_OBJECT *Next2);
207
208
198/*******************************************************************************
199 *
200 * FUNCTION: TrAmlGetNextTempName
201 *
202 * PARAMETERS: Op - Current parse op
203 * TempCount - Current temporary counter. Was originally
204 * per-module; Currently per method, could be
205 * expanded to per-scope.

--- 220 unchanged lines hidden (view full) ---

426 *
427 ******************************************************************************/
428
429static void
430TrTransformSubtree (
431 ACPI_PARSE_OBJECT *Op)
432{
433 ACPI_PARSE_OBJECT *MethodOp;
209/*******************************************************************************
210 *
211 * FUNCTION: TrAmlGetNextTempName
212 *
213 * PARAMETERS: Op - Current parse op
214 * TempCount - Current temporary counter. Was originally
215 * per-module; Currently per method, could be
216 * expanded to per-scope.

--- 220 unchanged lines hidden (view full) ---

437 *
438 ******************************************************************************/
439
440static void
441TrTransformSubtree (
442 ACPI_PARSE_OBJECT *Op)
443{
444 ACPI_PARSE_OBJECT *MethodOp;
445 ACPI_NAMESTRING_INFO Info;
434
435
436 if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
437 {
438 return;
439 }
440
441 switch (Op->Asl.ParseOpcode)

--- 45 unchanged lines hidden (view full) ---

487 MethodOp = MethodOp->Asl.Parent;
488 }
489
490 /* At the root, invocation not within a control method */
491
492 Op->Asl.Value.String = "\\";
493 break;
494
446
447
448 if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
449 {
450 return;
451 }
452
453 switch (Op->Asl.ParseOpcode)

--- 45 unchanged lines hidden (view full) ---

499 MethodOp = MethodOp->Asl.Parent;
500 }
501
502 /* At the root, invocation not within a control method */
503
504 Op->Asl.Value.String = "\\";
505 break;
506
507 case PARSEOP_NAMESTRING:
508 /*
509 * A NameString can be up to 255 (0xFF) individual NameSegs maximum
510 * (with 254 dot separators) - as per the ACPI specification. Note:
511 * Cannot check for NumSegments == 0 because things like
512 * Scope(\) are legal and OK.
513 */
514 Info.ExternalName = Op->Asl.Value.String;
515 AcpiNsGetInternalNameLength (&Info);
516
517 if (Info.NumSegments > 255)
518 {
519 AslError (ASL_ERROR, ASL_MSG_NAMESTRING_LENGTH, Op, NULL);
520 }
521 break;
522
495 case PARSEOP_UNLOAD:
496
497 AslError (ASL_WARNING, ASL_MSG_UNLOAD, Op, NULL);
498 break;
499
500 case PARSEOP_SLEEP:
501
502 /* Remark for very long sleep values */
503
504 if (Op->Asl.Child->Asl.Value.Integer > 1000)
505 {
506 AslError (ASL_REMARK, ASL_MSG_LONG_SLEEP, Op, NULL);
507 }
508 break;
509
510 case PARSEOP_PROCESSOR:
511
512 AslError (ASL_WARNING, ASL_MSG_LEGACY_PROCESSOR_OP, Op, Op->Asl.ExternalName);
523 case PARSEOP_UNLOAD:
524
525 AslError (ASL_WARNING, ASL_MSG_UNLOAD, Op, NULL);
526 break;
527
528 case PARSEOP_SLEEP:
529
530 /* Remark for very long sleep values */
531
532 if (Op->Asl.Child->Asl.Value.Integer > 1000)
533 {
534 AslError (ASL_REMARK, ASL_MSG_LONG_SLEEP, Op, NULL);
535 }
536 break;
537
538 case PARSEOP_PROCESSOR:
539
540 AslError (ASL_WARNING, ASL_MSG_LEGACY_PROCESSOR_OP, Op, Op->Asl.ExternalName);
513
514 break;
515
516 default:
517
518 /* Nothing to do here for other opcodes */
519
520 break;
521 }

--- 119 unchanged lines hidden (view full) ---

641 Peer = Next->Asl.Next;
642 while (Peer)
643 {
644 Next = Peer;
645 Peer = Next->Asl.Next;
646
647 if (Next->Asl.ParseOpcode == PARSEOP_CASE)
648 {
541 break;
542
543 default:
544
545 /* Nothing to do here for other opcodes */
546
547 break;
548 }

--- 119 unchanged lines hidden (view full) ---

668 Peer = Next->Asl.Next;
669 while (Peer)
670 {
671 Next = Peer;
672 Peer = Next->Asl.Next;
673
674 if (Next->Asl.ParseOpcode == PARSEOP_CASE)
675 {
676 TrCheckForDuplicateCase (Next, Next->Asl.Child);
677
649 if (CaseOp)
650 {
651 /* Add an ELSE to complete the previous CASE */
652
653 NewOp = TrCreateLeafOp (PARSEOP_ELSE);
654 NewOp->Asl.Parent = Conditional->Asl.Parent;
655 TrAmlInitLineNumbers (NewOp, NewOp->Asl.Parent);
656

--- 315 unchanged lines hidden (view full) ---

972 Conditional = Conditional->Asl.Next;
973 }
974
975 BreakOp = TrCreateLeafOp (PARSEOP_BREAK);
976 TrAmlInitLineNumbers (BreakOp, NewOp);
977 BreakOp->Asl.Parent = StartNode;
978 TrAmlInsertPeer (Conditional, BreakOp);
979}
678 if (CaseOp)
679 {
680 /* Add an ELSE to complete the previous CASE */
681
682 NewOp = TrCreateLeafOp (PARSEOP_ELSE);
683 NewOp->Asl.Parent = Conditional->Asl.Parent;
684 TrAmlInitLineNumbers (NewOp, NewOp->Asl.Parent);
685

--- 315 unchanged lines hidden (view full) ---

1001 Conditional = Conditional->Asl.Next;
1002 }
1003
1004 BreakOp = TrCreateLeafOp (PARSEOP_BREAK);
1005 TrAmlInitLineNumbers (BreakOp, NewOp);
1006 BreakOp->Asl.Parent = StartNode;
1007 TrAmlInsertPeer (Conditional, BreakOp);
1008}
1009
1010
1011/*******************************************************************************
1012 *
1013 * FUNCTION: TrCheckForDuplicateCase
1014 *
1015 * PARAMETERS: CaseOp - Parse node for first Case statement in list
1016 * Predicate1 - Case value for the input CaseOp
1017 *
1018 * RETURN: None
1019 *
1020 * DESCRIPTION: Check for duplicate case values. Currently, only handles
1021 * Integers, Strings and Buffers. No support for Package objects.
1022 *
1023 ******************************************************************************/
1024
1025static void
1026TrCheckForDuplicateCase (
1027 ACPI_PARSE_OBJECT *CaseOp,
1028 ACPI_PARSE_OBJECT *Predicate1)
1029{
1030 ACPI_PARSE_OBJECT *Next;
1031 ACPI_PARSE_OBJECT *Predicate2;
1032
1033
1034 /* Walk the list of CASE opcodes */
1035
1036 Next = CaseOp->Asl.Next;
1037 while (Next)
1038 {
1039 if (Next->Asl.ParseOpcode == PARSEOP_CASE)
1040 {
1041 /* Emit error only once */
1042
1043 if (Next->Asl.CompileFlags & OP_IS_DUPLICATE)
1044 {
1045 goto NextCase;
1046 }
1047
1048 /* Check for a duplicate plain integer */
1049
1050 Predicate2 = Next->Asl.Child;
1051 if ((Predicate1->Asl.ParseOpcode == PARSEOP_INTEGER) &&
1052 (Predicate2->Asl.ParseOpcode == PARSEOP_INTEGER))
1053 {
1054 if (Predicate1->Asl.Value.Integer == Predicate2->Asl.Value.Integer)
1055 {
1056 goto FoundDuplicate;
1057 }
1058 }
1059
1060 /* Check for pairs of the constants ZERO, ONE, ONES */
1061
1062 else if (((Predicate1->Asl.ParseOpcode == PARSEOP_ZERO) &&
1063 (Predicate2->Asl.ParseOpcode == PARSEOP_ZERO)) ||
1064 ((Predicate1->Asl.ParseOpcode == PARSEOP_ONE) &&
1065 (Predicate2->Asl.ParseOpcode == PARSEOP_ONE)) ||
1066 ((Predicate1->Asl.ParseOpcode == PARSEOP_ONES) &&
1067 (Predicate2->Asl.ParseOpcode == PARSEOP_ONES)))
1068 {
1069 goto FoundDuplicate;
1070 }
1071
1072 /* Check for a duplicate string constant (literal) */
1073
1074 else if ((Predicate1->Asl.ParseOpcode == PARSEOP_STRING_LITERAL) &&
1075 (Predicate2->Asl.ParseOpcode == PARSEOP_STRING_LITERAL))
1076 {
1077 if (!strcmp (Predicate1->Asl.Value.String,
1078 Predicate2->Asl.Value.String))
1079 {
1080 goto FoundDuplicate;
1081 }
1082 }
1083
1084 /* Check for a duplicate buffer constant */
1085
1086 else if ((Predicate1->Asl.ParseOpcode == PARSEOP_BUFFER) &&
1087 (Predicate2->Asl.ParseOpcode == PARSEOP_BUFFER))
1088 {
1089 if (TrCheckForBufferMatch (Predicate1->Asl.Child,
1090 Predicate2->Asl.Child))
1091 {
1092 goto FoundDuplicate;
1093 }
1094 }
1095 }
1096 goto NextCase;
1097
1098FoundDuplicate:
1099 /* Emit error message only once */
1100
1101 Next->Asl.CompileFlags |= OP_IS_DUPLICATE;
1102
1103 AslDualParseOpError (ASL_ERROR, ASL_MSG_DUPLICATE_CASE, Next,
1104 Next->Asl.Value.String, ASL_MSG_CASE_FOUND_HERE, CaseOp,
1105 CaseOp->Asl.ExternalName);
1106
1107NextCase:
1108 Next = Next->Asl.Next;
1109 }
1110}
1111
1112
1113/*******************************************************************************
1114 *
1115 * FUNCTION: TrCheckForBufferMatch
1116 *
1117 * PARAMETERS: Next1 - Parse node for first opcode in first buffer list
1118 * (The DEFAULT_ARG or INTEGER node)
1119 * Next2 - Parse node for first opcode in second buffer list
1120 * (The DEFAULT_ARG or INTEGER node)
1121 *
1122 * RETURN: TRUE if buffers match, FALSE otherwise
1123 *
1124 * DESCRIPTION: Check for duplicate Buffer case values.
1125 *
1126 ******************************************************************************/
1127
1128static BOOLEAN
1129TrCheckForBufferMatch (
1130 ACPI_PARSE_OBJECT *NextOp1,
1131 ACPI_PARSE_OBJECT *NextOp2)
1132{
1133
1134 if (NextOp1->Asl.Value.Integer != NextOp2->Asl.Value.Integer)
1135 {
1136 return (FALSE);
1137 }
1138
1139 /* Start at the BYTECONST initializer node list */
1140
1141 NextOp1 = NextOp1->Asl.Next;
1142 NextOp2 = NextOp2->Asl.Next;
1143
1144 /*
1145 * Walk both lists until either a mismatch is found, or one or more
1146 * end-of-lists are found
1147 */
1148 while (NextOp1 && NextOp2)
1149 {
1150 if ((NextOp1->Asl.ParseOpcode == PARSEOP_STRING_LITERAL) &&
1151 (NextOp2->Asl.ParseOpcode == PARSEOP_STRING_LITERAL))
1152 {
1153 if (!strcmp (NextOp1->Asl.Value.String, NextOp2->Asl.Value.String))
1154 {
1155 return (TRUE);
1156 }
1157 else
1158 {
1159 return (FALSE);
1160 }
1161 }
1162 if ((UINT8) NextOp1->Asl.Value.Integer != (UINT8) NextOp2->Asl.Value.Integer)
1163 {
1164 return (FALSE);
1165 }
1166
1167 NextOp1 = NextOp1->Asl.Next;
1168 NextOp2 = NextOp2->Asl.Next;
1169 }
1170
1171 /* Not a match if one of the lists is not at end-of-list */
1172
1173 if (NextOp1 || NextOp2)
1174 {
1175 return (FALSE);
1176 }
1177
1178 /* Otherwise, the buffers match */
1179
1180 return (TRUE);
1181}