aslfold.c revision 1.1.1.2.4.2 1 1.1.1.2.4.2 rmind
2 1.1.1.2.4.2 rmind /******************************************************************************
3 1.1.1.2.4.2 rmind *
4 1.1.1.2.4.2 rmind * Module Name: aslfold - Constant folding
5 1.1.1.2.4.2 rmind *
6 1.1.1.2.4.2 rmind *****************************************************************************/
7 1.1.1.2.4.2 rmind
8 1.1.1.2.4.2 rmind /*
9 1.1.1.2.4.2 rmind * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1.1.2.4.2 rmind * All rights reserved.
11 1.1.1.2.4.2 rmind *
12 1.1.1.2.4.2 rmind * Redistribution and use in source and binary forms, with or without
13 1.1.1.2.4.2 rmind * modification, are permitted provided that the following conditions
14 1.1.1.2.4.2 rmind * are met:
15 1.1.1.2.4.2 rmind * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2.4.2 rmind * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2.4.2 rmind * without modification.
18 1.1.1.2.4.2 rmind * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2.4.2 rmind * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2.4.2 rmind * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2.4.2 rmind * including a substantially similar Disclaimer requirement for further
22 1.1.1.2.4.2 rmind * binary redistribution.
23 1.1.1.2.4.2 rmind * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2.4.2 rmind * of any contributors may be used to endorse or promote products derived
25 1.1.1.2.4.2 rmind * from this software without specific prior written permission.
26 1.1.1.2.4.2 rmind *
27 1.1.1.2.4.2 rmind * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2.4.2 rmind * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2.4.2 rmind * Software Foundation.
30 1.1.1.2.4.2 rmind *
31 1.1.1.2.4.2 rmind * NO WARRANTY
32 1.1.1.2.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2.4.2 rmind * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2.4.2 rmind * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2.4.2 rmind * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2.4.2 rmind * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2.4.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2.4.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2.4.2 rmind * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.2.4.2 rmind */
44 1.1.1.2.4.2 rmind
45 1.1.1.2.4.2 rmind
46 1.1.1.2.4.2 rmind #include "aslcompiler.h"
47 1.1.1.2.4.2 rmind #include "aslcompiler.y.h"
48 1.1.1.2.4.2 rmind #include "amlcode.h"
49 1.1.1.2.4.2 rmind
50 1.1.1.2.4.2 rmind #include "acdispat.h"
51 1.1.1.2.4.2 rmind #include "acparser.h"
52 1.1.1.2.4.2 rmind
53 1.1.1.2.4.2 rmind #define _COMPONENT ACPI_COMPILER
54 1.1.1.2.4.2 rmind ACPI_MODULE_NAME ("aslfold")
55 1.1.1.2.4.2 rmind
56 1.1.1.2.4.2 rmind /* Local prototypes */
57 1.1.1.2.4.2 rmind
58 1.1.1.2.4.2 rmind static ACPI_STATUS
59 1.1.1.2.4.2 rmind OpcAmlEvaluationWalk1 (
60 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op,
61 1.1.1.2.4.2 rmind UINT32 Level,
62 1.1.1.2.4.2 rmind void *Context);
63 1.1.1.2.4.2 rmind
64 1.1.1.2.4.2 rmind static ACPI_STATUS
65 1.1.1.2.4.2 rmind OpcAmlEvaluationWalk2 (
66 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op,
67 1.1.1.2.4.2 rmind UINT32 Level,
68 1.1.1.2.4.2 rmind void *Context);
69 1.1.1.2.4.2 rmind
70 1.1.1.2.4.2 rmind static ACPI_STATUS
71 1.1.1.2.4.2 rmind OpcAmlCheckForConstant (
72 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op,
73 1.1.1.2.4.2 rmind UINT32 Level,
74 1.1.1.2.4.2 rmind void *Context);
75 1.1.1.2.4.2 rmind
76 1.1.1.2.4.2 rmind
77 1.1.1.2.4.2 rmind /*******************************************************************************
78 1.1.1.2.4.2 rmind *
79 1.1.1.2.4.2 rmind * FUNCTION: OpcAmlEvaluationWalk1
80 1.1.1.2.4.2 rmind *
81 1.1.1.2.4.2 rmind * PARAMETERS: ASL_WALK_CALLBACK
82 1.1.1.2.4.2 rmind *
83 1.1.1.2.4.2 rmind * RETURN: Status
84 1.1.1.2.4.2 rmind *
85 1.1.1.2.4.2 rmind * DESCRIPTION: Descending callback for AML execution of constant subtrees
86 1.1.1.2.4.2 rmind *
87 1.1.1.2.4.2 rmind ******************************************************************************/
88 1.1.1.2.4.2 rmind
89 1.1.1.2.4.2 rmind static ACPI_STATUS
90 1.1.1.2.4.2 rmind OpcAmlEvaluationWalk1 (
91 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op,
92 1.1.1.2.4.2 rmind UINT32 Level,
93 1.1.1.2.4.2 rmind void *Context)
94 1.1.1.2.4.2 rmind {
95 1.1.1.2.4.2 rmind ACPI_WALK_STATE *WalkState = Context;
96 1.1.1.2.4.2 rmind ACPI_STATUS Status;
97 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *OutOp;
98 1.1.1.2.4.2 rmind
99 1.1.1.2.4.2 rmind
100 1.1.1.2.4.2 rmind WalkState->Op = Op;
101 1.1.1.2.4.2 rmind WalkState->Opcode = Op->Common.AmlOpcode;
102 1.1.1.2.4.2 rmind WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
103 1.1.1.2.4.2 rmind
104 1.1.1.2.4.2 rmind /* Copy child pointer to Arg for compatibility with Interpreter */
105 1.1.1.2.4.2 rmind
106 1.1.1.2.4.2 rmind if (Op->Asl.Child)
107 1.1.1.2.4.2 rmind {
108 1.1.1.2.4.2 rmind Op->Common.Value.Arg = Op->Asl.Child;
109 1.1.1.2.4.2 rmind }
110 1.1.1.2.4.2 rmind
111 1.1.1.2.4.2 rmind /* Call AML dispatcher */
112 1.1.1.2.4.2 rmind
113 1.1.1.2.4.2 rmind Status = AcpiDsExecBeginOp (WalkState, &OutOp);
114 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
115 1.1.1.2.4.2 rmind {
116 1.1.1.2.4.2 rmind AcpiOsPrintf ("Constant interpretation failed - %s\n",
117 1.1.1.2.4.2 rmind AcpiFormatException (Status));
118 1.1.1.2.4.2 rmind }
119 1.1.1.2.4.2 rmind
120 1.1.1.2.4.2 rmind return (Status);
121 1.1.1.2.4.2 rmind }
122 1.1.1.2.4.2 rmind
123 1.1.1.2.4.2 rmind
124 1.1.1.2.4.2 rmind /*******************************************************************************
125 1.1.1.2.4.2 rmind *
126 1.1.1.2.4.2 rmind * FUNCTION: OpcAmlEvaluationWalk2
127 1.1.1.2.4.2 rmind *
128 1.1.1.2.4.2 rmind * PARAMETERS: ASL_WALK_CALLBACK
129 1.1.1.2.4.2 rmind *
130 1.1.1.2.4.2 rmind * RETURN: Status
131 1.1.1.2.4.2 rmind *
132 1.1.1.2.4.2 rmind * DESCRIPTION: Ascending callback for AML execution of constant subtrees
133 1.1.1.2.4.2 rmind *
134 1.1.1.2.4.2 rmind ******************************************************************************/
135 1.1.1.2.4.2 rmind
136 1.1.1.2.4.2 rmind static ACPI_STATUS
137 1.1.1.2.4.2 rmind OpcAmlEvaluationWalk2 (
138 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op,
139 1.1.1.2.4.2 rmind UINT32 Level,
140 1.1.1.2.4.2 rmind void *Context)
141 1.1.1.2.4.2 rmind {
142 1.1.1.2.4.2 rmind ACPI_WALK_STATE *WalkState = Context;
143 1.1.1.2.4.2 rmind ACPI_STATUS Status;
144 1.1.1.2.4.2 rmind
145 1.1.1.2.4.2 rmind
146 1.1.1.2.4.2 rmind WalkState->Op = Op;
147 1.1.1.2.4.2 rmind WalkState->Opcode = Op->Common.AmlOpcode;
148 1.1.1.2.4.2 rmind WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
149 1.1.1.2.4.2 rmind
150 1.1.1.2.4.2 rmind /* Copy child pointer to Arg for compatibility with Interpreter */
151 1.1.1.2.4.2 rmind
152 1.1.1.2.4.2 rmind if (Op->Asl.Child)
153 1.1.1.2.4.2 rmind {
154 1.1.1.2.4.2 rmind Op->Common.Value.Arg = Op->Asl.Child;
155 1.1.1.2.4.2 rmind }
156 1.1.1.2.4.2 rmind
157 1.1.1.2.4.2 rmind /* Call AML dispatcher */
158 1.1.1.2.4.2 rmind
159 1.1.1.2.4.2 rmind Status = AcpiDsExecEndOp (WalkState);
160 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
161 1.1.1.2.4.2 rmind {
162 1.1.1.2.4.2 rmind AcpiOsPrintf ("Constant interpretation failed - %s\n",
163 1.1.1.2.4.2 rmind AcpiFormatException (Status));
164 1.1.1.2.4.2 rmind }
165 1.1.1.2.4.2 rmind
166 1.1.1.2.4.2 rmind return (Status);
167 1.1.1.2.4.2 rmind }
168 1.1.1.2.4.2 rmind
169 1.1.1.2.4.2 rmind
170 1.1.1.2.4.2 rmind /*******************************************************************************
171 1.1.1.2.4.2 rmind *
172 1.1.1.2.4.2 rmind * FUNCTION: OpcAmlCheckForConstant
173 1.1.1.2.4.2 rmind *
174 1.1.1.2.4.2 rmind * PARAMETERS: ASL_WALK_CALLBACK
175 1.1.1.2.4.2 rmind *
176 1.1.1.2.4.2 rmind * RETURN: Status
177 1.1.1.2.4.2 rmind *
178 1.1.1.2.4.2 rmind * DESCRIPTION: Check one Op for a type 3/4/5 AML opcode
179 1.1.1.2.4.2 rmind *
180 1.1.1.2.4.2 rmind ******************************************************************************/
181 1.1.1.2.4.2 rmind
182 1.1.1.2.4.2 rmind static ACPI_STATUS
183 1.1.1.2.4.2 rmind OpcAmlCheckForConstant (
184 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op,
185 1.1.1.2.4.2 rmind UINT32 Level,
186 1.1.1.2.4.2 rmind void *Context)
187 1.1.1.2.4.2 rmind {
188 1.1.1.2.4.2 rmind ACPI_WALK_STATE *WalkState = Context;
189 1.1.1.2.4.2 rmind
190 1.1.1.2.4.2 rmind
191 1.1.1.2.4.2 rmind WalkState->Op = Op;
192 1.1.1.2.4.2 rmind WalkState->Opcode = Op->Common.AmlOpcode;
193 1.1.1.2.4.2 rmind WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
194 1.1.1.2.4.2 rmind
195 1.1.1.2.4.2 rmind DbgPrint (ASL_PARSE_OUTPUT, "[%.4d] Opcode: %12.12s ",
196 1.1.1.2.4.2 rmind Op->Asl.LogicalLineNumber, Op->Asl.ParseOpName);
197 1.1.1.2.4.2 rmind
198 1.1.1.2.4.2 rmind if (!(WalkState->OpInfo->Flags & AML_CONSTANT))
199 1.1.1.2.4.2 rmind {
200 1.1.1.2.4.2 rmind /* The opcode is not a Type 3/4/5 opcode */
201 1.1.1.2.4.2 rmind
202 1.1.1.2.4.2 rmind if (Op->Asl.CompileFlags & NODE_IS_TARGET)
203 1.1.1.2.4.2 rmind {
204 1.1.1.2.4.2 rmind DbgPrint (ASL_PARSE_OUTPUT,
205 1.1.1.2.4.2 rmind "**** Valid Target, cannot reduce ****\n");
206 1.1.1.2.4.2 rmind }
207 1.1.1.2.4.2 rmind else
208 1.1.1.2.4.2 rmind {
209 1.1.1.2.4.2 rmind DbgPrint (ASL_PARSE_OUTPUT,
210 1.1.1.2.4.2 rmind "**** Not a Type 3/4/5 opcode ****\n");
211 1.1.1.2.4.2 rmind }
212 1.1.1.2.4.2 rmind
213 1.1.1.2.4.2 rmind if (WalkState->WalkType == ACPI_WALK_CONST_OPTIONAL)
214 1.1.1.2.4.2 rmind {
215 1.1.1.2.4.2 rmind /*
216 1.1.1.2.4.2 rmind * We are looking at at normal expression to see if it can be
217 1.1.1.2.4.2 rmind * reduced. It can't. No error
218 1.1.1.2.4.2 rmind */
219 1.1.1.2.4.2 rmind return (AE_TYPE);
220 1.1.1.2.4.2 rmind }
221 1.1.1.2.4.2 rmind
222 1.1.1.2.4.2 rmind /*
223 1.1.1.2.4.2 rmind * This is an expression that MUST reduce to a constant, and it
224 1.1.1.2.4.2 rmind * can't be reduced. This is an error
225 1.1.1.2.4.2 rmind */
226 1.1.1.2.4.2 rmind if (Op->Asl.CompileFlags & NODE_IS_TARGET)
227 1.1.1.2.4.2 rmind {
228 1.1.1.2.4.2 rmind AslError (ASL_ERROR, ASL_MSG_INVALID_TARGET, Op,
229 1.1.1.2.4.2 rmind Op->Asl.ParseOpName);
230 1.1.1.2.4.2 rmind }
231 1.1.1.2.4.2 rmind else
232 1.1.1.2.4.2 rmind {
233 1.1.1.2.4.2 rmind AslError (ASL_ERROR, ASL_MSG_INVALID_CONSTANT_OP, Op,
234 1.1.1.2.4.2 rmind Op->Asl.ParseOpName);
235 1.1.1.2.4.2 rmind }
236 1.1.1.2.4.2 rmind
237 1.1.1.2.4.2 rmind return (AE_TYPE);
238 1.1.1.2.4.2 rmind }
239 1.1.1.2.4.2 rmind
240 1.1.1.2.4.2 rmind /* Debug output */
241 1.1.1.2.4.2 rmind
242 1.1.1.2.4.2 rmind DbgPrint (ASL_PARSE_OUTPUT, "TYPE_345");
243 1.1.1.2.4.2 rmind
244 1.1.1.2.4.2 rmind if (Op->Asl.CompileFlags & NODE_IS_TARGET)
245 1.1.1.2.4.2 rmind {
246 1.1.1.2.4.2 rmind DbgPrint (ASL_PARSE_OUTPUT, " TARGET");
247 1.1.1.2.4.2 rmind }
248 1.1.1.2.4.2 rmind if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG)
249 1.1.1.2.4.2 rmind {
250 1.1.1.2.4.2 rmind DbgPrint (ASL_PARSE_OUTPUT, " TERMARG");
251 1.1.1.2.4.2 rmind }
252 1.1.1.2.4.2 rmind DbgPrint (ASL_PARSE_OUTPUT, "\n");
253 1.1.1.2.4.2 rmind
254 1.1.1.2.4.2 rmind return (AE_OK);
255 1.1.1.2.4.2 rmind }
256 1.1.1.2.4.2 rmind
257 1.1.1.2.4.2 rmind
258 1.1.1.2.4.2 rmind /*******************************************************************************
259 1.1.1.2.4.2 rmind *
260 1.1.1.2.4.2 rmind * FUNCTION: OpcAmlConstantWalk
261 1.1.1.2.4.2 rmind *
262 1.1.1.2.4.2 rmind * PARAMETERS: ASL_WALK_CALLBACK
263 1.1.1.2.4.2 rmind *
264 1.1.1.2.4.2 rmind * RETURN: Status
265 1.1.1.2.4.2 rmind *
266 1.1.1.2.4.2 rmind * DESCRIPTION: Reduce an Op and its subtree to a constant if possible
267 1.1.1.2.4.2 rmind *
268 1.1.1.2.4.2 rmind ******************************************************************************/
269 1.1.1.2.4.2 rmind
270 1.1.1.2.4.2 rmind ACPI_STATUS
271 1.1.1.2.4.2 rmind OpcAmlConstantWalk (
272 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *Op,
273 1.1.1.2.4.2 rmind UINT32 Level,
274 1.1.1.2.4.2 rmind void *Context)
275 1.1.1.2.4.2 rmind {
276 1.1.1.2.4.2 rmind ACPI_WALK_STATE *WalkState;
277 1.1.1.2.4.2 rmind ACPI_STATUS Status = AE_OK;
278 1.1.1.2.4.2 rmind ACPI_OPERAND_OBJECT *ObjDesc;
279 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *RootOp;
280 1.1.1.2.4.2 rmind ACPI_PARSE_OBJECT *OriginalParentOp;
281 1.1.1.2.4.2 rmind UINT8 WalkType;
282 1.1.1.2.4.2 rmind
283 1.1.1.2.4.2 rmind
284 1.1.1.2.4.2 rmind /*
285 1.1.1.2.4.2 rmind * Only interested in subtrees that could possibly contain
286 1.1.1.2.4.2 rmind * expressions that can be evaluated at this time
287 1.1.1.2.4.2 rmind */
288 1.1.1.2.4.2 rmind if ((!(Op->Asl.CompileFlags & NODE_COMPILE_TIME_CONST)) ||
289 1.1.1.2.4.2 rmind (Op->Asl.CompileFlags & NODE_IS_TARGET))
290 1.1.1.2.4.2 rmind {
291 1.1.1.2.4.2 rmind return (AE_OK);
292 1.1.1.2.4.2 rmind }
293 1.1.1.2.4.2 rmind
294 1.1.1.2.4.2 rmind /* Set the walk type based on the reduction used for this op */
295 1.1.1.2.4.2 rmind
296 1.1.1.2.4.2 rmind if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG)
297 1.1.1.2.4.2 rmind {
298 1.1.1.2.4.2 rmind /* Op is a TermArg, constant folding is merely optional */
299 1.1.1.2.4.2 rmind
300 1.1.1.2.4.2 rmind if (!Gbl_FoldConstants)
301 1.1.1.2.4.2 rmind {
302 1.1.1.2.4.2 rmind return (AE_CTRL_DEPTH);
303 1.1.1.2.4.2 rmind }
304 1.1.1.2.4.2 rmind
305 1.1.1.2.4.2 rmind WalkType = ACPI_WALK_CONST_OPTIONAL;
306 1.1.1.2.4.2 rmind }
307 1.1.1.2.4.2 rmind else
308 1.1.1.2.4.2 rmind {
309 1.1.1.2.4.2 rmind /* Op is a DataObject, the expression MUST reduced to a constant */
310 1.1.1.2.4.2 rmind
311 1.1.1.2.4.2 rmind WalkType = ACPI_WALK_CONST_REQUIRED;
312 1.1.1.2.4.2 rmind }
313 1.1.1.2.4.2 rmind
314 1.1.1.2.4.2 rmind /* Create a new walk state */
315 1.1.1.2.4.2 rmind
316 1.1.1.2.4.2 rmind WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
317 1.1.1.2.4.2 rmind if (!WalkState)
318 1.1.1.2.4.2 rmind {
319 1.1.1.2.4.2 rmind return AE_NO_MEMORY;
320 1.1.1.2.4.2 rmind }
321 1.1.1.2.4.2 rmind
322 1.1.1.2.4.2 rmind WalkState->NextOp = NULL;
323 1.1.1.2.4.2 rmind WalkState->Params = NULL;
324 1.1.1.2.4.2 rmind WalkState->CallerReturnDesc = &ObjDesc;
325 1.1.1.2.4.2 rmind WalkState->WalkType = WalkType;
326 1.1.1.2.4.2 rmind
327 1.1.1.2.4.2 rmind /*
328 1.1.1.2.4.2 rmind * Examine the entire subtree -- all nodes must be constants
329 1.1.1.2.4.2 rmind * or type 3/4/5 opcodes
330 1.1.1.2.4.2 rmind */
331 1.1.1.2.4.2 rmind Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD,
332 1.1.1.2.4.2 rmind OpcAmlCheckForConstant, NULL, WalkState);
333 1.1.1.2.4.2 rmind
334 1.1.1.2.4.2 rmind /*
335 1.1.1.2.4.2 rmind * Did we find an entire subtree that contains all constants and type 3/4/5
336 1.1.1.2.4.2 rmind * opcodes? (Only AE_OK or AE_TYPE returned from above)
337 1.1.1.2.4.2 rmind */
338 1.1.1.2.4.2 rmind if (Status == AE_TYPE)
339 1.1.1.2.4.2 rmind {
340 1.1.1.2.4.2 rmind /* Subtree cannot be reduced to a constant */
341 1.1.1.2.4.2 rmind
342 1.1.1.2.4.2 rmind if (WalkState->WalkType == ACPI_WALK_CONST_OPTIONAL)
343 1.1.1.2.4.2 rmind {
344 1.1.1.2.4.2 rmind AcpiDsDeleteWalkState (WalkState);
345 1.1.1.2.4.2 rmind return (AE_OK);
346 1.1.1.2.4.2 rmind }
347 1.1.1.2.4.2 rmind
348 1.1.1.2.4.2 rmind /* Don't descend any further, and use a default "constant" value */
349 1.1.1.2.4.2 rmind
350 1.1.1.2.4.2 rmind Status = AE_CTRL_DEPTH;
351 1.1.1.2.4.2 rmind }
352 1.1.1.2.4.2 rmind else
353 1.1.1.2.4.2 rmind {
354 1.1.1.2.4.2 rmind /* Subtree can be reduced */
355 1.1.1.2.4.2 rmind
356 1.1.1.2.4.2 rmind /* Allocate a new temporary root for this subtree */
357 1.1.1.2.4.2 rmind
358 1.1.1.2.4.2 rmind RootOp = TrAllocateNode (PARSEOP_INTEGER);
359 1.1.1.2.4.2 rmind if (!RootOp)
360 1.1.1.2.4.2 rmind {
361 1.1.1.2.4.2 rmind return (AE_NO_MEMORY);
362 1.1.1.2.4.2 rmind }
363 1.1.1.2.4.2 rmind
364 1.1.1.2.4.2 rmind RootOp->Common.AmlOpcode = AML_INT_EVAL_SUBTREE_OP;
365 1.1.1.2.4.2 rmind
366 1.1.1.2.4.2 rmind OriginalParentOp = Op->Common.Parent;
367 1.1.1.2.4.2 rmind Op->Common.Parent = RootOp;
368 1.1.1.2.4.2 rmind
369 1.1.1.2.4.2 rmind /* Hand off the subtree to the AML interpreter */
370 1.1.1.2.4.2 rmind
371 1.1.1.2.4.2 rmind Status = TrWalkParseTree (Op, ASL_WALK_VISIT_TWICE,
372 1.1.1.2.4.2 rmind OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState);
373 1.1.1.2.4.2 rmind Op->Common.Parent = OriginalParentOp;
374 1.1.1.2.4.2 rmind
375 1.1.1.2.4.2 rmind /* TBD: we really *should* release the RootOp node */
376 1.1.1.2.4.2 rmind
377 1.1.1.2.4.2 rmind if (ACPI_SUCCESS (Status))
378 1.1.1.2.4.2 rmind {
379 1.1.1.2.4.2 rmind TotalFolds++;
380 1.1.1.2.4.2 rmind
381 1.1.1.2.4.2 rmind /* Get the final result */
382 1.1.1.2.4.2 rmind
383 1.1.1.2.4.2 rmind Status = AcpiDsResultPop (&ObjDesc, WalkState);
384 1.1.1.2.4.2 rmind }
385 1.1.1.2.4.2 rmind }
386 1.1.1.2.4.2 rmind
387 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
388 1.1.1.2.4.2 rmind {
389 1.1.1.2.4.2 rmind /* We could not resolve the subtree for some reason */
390 1.1.1.2.4.2 rmind
391 1.1.1.2.4.2 rmind AslCoreSubsystemError (Op, Status,
392 1.1.1.2.4.2 rmind "Failure during constant evaluation", FALSE);
393 1.1.1.2.4.2 rmind AslError (ASL_ERROR, ASL_MSG_CONSTANT_EVALUATION, Op,
394 1.1.1.2.4.2 rmind Op->Asl.ParseOpName);
395 1.1.1.2.4.2 rmind
396 1.1.1.2.4.2 rmind /* Set the subtree value to ZERO anyway. Eliminates further errors */
397 1.1.1.2.4.2 rmind
398 1.1.1.2.4.2 rmind Op->Asl.ParseOpcode = PARSEOP_INTEGER;
399 1.1.1.2.4.2 rmind Op->Common.Value.Integer = 0;
400 1.1.1.2.4.2 rmind OpcSetOptimalIntegerSize (Op);
401 1.1.1.2.4.2 rmind }
402 1.1.1.2.4.2 rmind else
403 1.1.1.2.4.2 rmind {
404 1.1.1.2.4.2 rmind AslError (ASL_OPTIMIZATION, ASL_MSG_CONSTANT_FOLDED, Op,
405 1.1.1.2.4.2 rmind Op->Asl.ParseOpName);
406 1.1.1.2.4.2 rmind
407 1.1.1.2.4.2 rmind /*
408 1.1.1.2.4.2 rmind * Because we know we executed type 3/4/5 opcodes above, we know that
409 1.1.1.2.4.2 rmind * the result must be either an Integer, String, or Buffer.
410 1.1.1.2.4.2 rmind */
411 1.1.1.2.4.2 rmind switch (ObjDesc->Common.Type)
412 1.1.1.2.4.2 rmind {
413 1.1.1.2.4.2 rmind case ACPI_TYPE_INTEGER:
414 1.1.1.2.4.2 rmind
415 1.1.1.2.4.2 rmind Op->Asl.ParseOpcode = PARSEOP_INTEGER;
416 1.1.1.2.4.2 rmind Op->Common.Value.Integer = ObjDesc->Integer.Value;
417 1.1.1.2.4.2 rmind OpcSetOptimalIntegerSize (Op);
418 1.1.1.2.4.2 rmind
419 1.1.1.2.4.2 rmind DbgPrint (ASL_PARSE_OUTPUT,
420 1.1.1.2.4.2 rmind "Constant expression reduced to (INTEGER) %8.8X%8.8X\n",
421 1.1.1.2.4.2 rmind ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
422 1.1.1.2.4.2 rmind break;
423 1.1.1.2.4.2 rmind
424 1.1.1.2.4.2 rmind
425 1.1.1.2.4.2 rmind case ACPI_TYPE_STRING:
426 1.1.1.2.4.2 rmind
427 1.1.1.2.4.2 rmind Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
428 1.1.1.2.4.2 rmind Op->Common.AmlOpcode = AML_STRING_OP;
429 1.1.1.2.4.2 rmind Op->Asl.AmlLength = ACPI_STRLEN (ObjDesc->String.Pointer) + 1;
430 1.1.1.2.4.2 rmind Op->Common.Value.String = ObjDesc->String.Pointer;
431 1.1.1.2.4.2 rmind
432 1.1.1.2.4.2 rmind DbgPrint (ASL_PARSE_OUTPUT,
433 1.1.1.2.4.2 rmind "Constant expression reduced to (STRING) %s\n",
434 1.1.1.2.4.2 rmind Op->Common.Value.String);
435 1.1.1.2.4.2 rmind
436 1.1.1.2.4.2 rmind break;
437 1.1.1.2.4.2 rmind
438 1.1.1.2.4.2 rmind
439 1.1.1.2.4.2 rmind case ACPI_TYPE_BUFFER:
440 1.1.1.2.4.2 rmind
441 1.1.1.2.4.2 rmind Op->Asl.ParseOpcode = PARSEOP_BUFFER;
442 1.1.1.2.4.2 rmind Op->Common.AmlOpcode = AML_BUFFER_OP;
443 1.1.1.2.4.2 rmind Op->Asl.CompileFlags = NODE_AML_PACKAGE;
444 1.1.1.2.4.2 rmind UtSetParseOpName (Op);
445 1.1.1.2.4.2 rmind
446 1.1.1.2.4.2 rmind /* Child node is the buffer length */
447 1.1.1.2.4.2 rmind
448 1.1.1.2.4.2 rmind RootOp = TrAllocateNode (PARSEOP_INTEGER);
449 1.1.1.2.4.2 rmind
450 1.1.1.2.4.2 rmind RootOp->Asl.AmlOpcode = AML_DWORD_OP;
451 1.1.1.2.4.2 rmind RootOp->Asl.Value.Integer = ObjDesc->Buffer.Length;
452 1.1.1.2.4.2 rmind RootOp->Asl.Parent = Op;
453 1.1.1.2.4.2 rmind
454 1.1.1.2.4.2 rmind (void) OpcSetOptimalIntegerSize (RootOp);
455 1.1.1.2.4.2 rmind
456 1.1.1.2.4.2 rmind Op->Asl.Child = RootOp;
457 1.1.1.2.4.2 rmind Op = RootOp;
458 1.1.1.2.4.2 rmind UtSetParseOpName (Op);
459 1.1.1.2.4.2 rmind
460 1.1.1.2.4.2 rmind /* Peer to the child is the raw buffer data */
461 1.1.1.2.4.2 rmind
462 1.1.1.2.4.2 rmind RootOp = TrAllocateNode (PARSEOP_RAW_DATA);
463 1.1.1.2.4.2 rmind RootOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
464 1.1.1.2.4.2 rmind RootOp->Asl.AmlLength = ObjDesc->Buffer.Length;
465 1.1.1.2.4.2 rmind RootOp->Asl.Value.String = (char *) ObjDesc->Buffer.Pointer;
466 1.1.1.2.4.2 rmind RootOp->Asl.Parent = Op->Asl.Parent;
467 1.1.1.2.4.2 rmind
468 1.1.1.2.4.2 rmind Op->Asl.Next = RootOp;
469 1.1.1.2.4.2 rmind Op = RootOp;
470 1.1.1.2.4.2 rmind
471 1.1.1.2.4.2 rmind DbgPrint (ASL_PARSE_OUTPUT,
472 1.1.1.2.4.2 rmind "Constant expression reduced to (BUFFER) length %X\n",
473 1.1.1.2.4.2 rmind ObjDesc->Buffer.Length);
474 1.1.1.2.4.2 rmind break;
475 1.1.1.2.4.2 rmind
476 1.1.1.2.4.2 rmind
477 1.1.1.2.4.2 rmind default:
478 1.1.1.2.4.2 rmind printf ("Unsupported return type: %s\n",
479 1.1.1.2.4.2 rmind AcpiUtGetObjectTypeName (ObjDesc));
480 1.1.1.2.4.2 rmind break;
481 1.1.1.2.4.2 rmind }
482 1.1.1.2.4.2 rmind }
483 1.1.1.2.4.2 rmind
484 1.1.1.2.4.2 rmind UtSetParseOpName (Op);
485 1.1.1.2.4.2 rmind Op->Asl.Child = NULL;
486 1.1.1.2.4.2 rmind
487 1.1.1.2.4.2 rmind AcpiDsDeleteWalkState (WalkState);
488 1.1.1.2.4.2 rmind
489 1.1.1.2.4.2 rmind return (AE_CTRL_DEPTH);
490 1.1.1.2.4.2 rmind }
491 1.1.1.2.4.2 rmind
492