Deleted Added
sdiff udiff text old ( 229989 ) new ( 239340 )
full compact
1
2/******************************************************************************
3 *
4 * Module Name: aslfold - Constant folding
5 *
6 *****************************************************************************/
7
8/*

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

68 void *Context);
69
70static ACPI_STATUS
71OpcAmlCheckForConstant (
72 ACPI_PARSE_OBJECT *Op,
73 UINT32 Level,
74 void *Context);
75
76static void
77OpcUpdateIntegerNode (
78 ACPI_PARSE_OBJECT *Op,
79 UINT64 Value);
80
81
82/*******************************************************************************
83 *
84 * FUNCTION: OpcAmlEvaluationWalk1
85 *
86 * PARAMETERS: ASL_WALK_CALLBACK
87 *
88 * RETURN: Status
89 *

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

214 DbgPrint (ASL_PARSE_OUTPUT,
215 "**** Not a Type 3/4/5 opcode ****\n");
216 }
217
218 if (WalkState->WalkType == ACPI_WALK_CONST_OPTIONAL)
219 {
220 /*
221 * We are looking at at normal expression to see if it can be
222 * reduced. It can't. No error
223 */
224 return (AE_TYPE);
225 }
226
227 /*
228 * This is an expression that MUST reduce to a constant, and it
229 * can't be reduced. This is an error
230 */
231 if (Op->Asl.CompileFlags & NODE_IS_TARGET)
232 {
233 AslError (ASL_ERROR, ASL_MSG_INVALID_TARGET, Op,
234 Op->Asl.ParseOpName);
235 }
236 else
237 {

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

319 /* Create a new walk state */
320
321 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
322 if (!WalkState)
323 {
324 return AE_NO_MEMORY;
325 }
326
327 WalkState->NextOp = NULL;
328 WalkState->Params = NULL;
329 WalkState->WalkType = WalkType;
330 WalkState->CallerReturnDesc = &ObjDesc;
331
332 /*
333 * Examine the entire subtree -- all nodes must be constants
334 * or type 3/4/5 opcodes
335 */
336 Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD,
337 OpcAmlCheckForConstant, NULL, WalkState);
338
339 /*
340 * Did we find an entire subtree that contains all constants and type 3/4/5
341 * opcodes? (Only AE_OK or AE_TYPE returned from above)
342 */
343 if (Status == AE_TYPE)
344 {
345 /* Subtree cannot be reduced to a constant */

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

369 RootOp->Common.AmlOpcode = AML_INT_EVAL_SUBTREE_OP;
370
371 OriginalParentOp = Op->Common.Parent;
372 Op->Common.Parent = RootOp;
373
374 /* Hand off the subtree to the AML interpreter */
375
376 Status = TrWalkParseTree (Op, ASL_WALK_VISIT_TWICE,
377 OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState);
378 Op->Common.Parent = OriginalParentOp;
379
380 /* TBD: we really *should* release the RootOp node */
381
382 if (ACPI_SUCCESS (Status))
383 {
384 TotalFolds++;
385
386 /* Get the final result */
387
388 Status = AcpiDsResultPop (&ObjDesc, WalkState);
389 }
390
391 /* Check for error from the ACPICA core */
392
393 if (ACPI_FAILURE (Status))
394 {
395 AslCoreSubsystemError (Op, Status,
396 "Failure during constant evaluation", FALSE);
397 }
398 }
399
400 if (ACPI_FAILURE (Status))
401 {
402 /* We could not resolve the subtree for some reason */
403
404 AslError (ASL_ERROR, ASL_MSG_CONSTANT_EVALUATION, Op,
405 Op->Asl.ParseOpName);
406
407 /* Set the subtree value to ZERO anyway. Eliminates further errors */
408
409 OpcUpdateIntegerNode (Op, 0);
410 }
411 else
412 {
413 AslError (ASL_OPTIMIZATION, ASL_MSG_CONSTANT_FOLDED, Op,
414 Op->Asl.ParseOpName);
415
416 /*
417 * Because we know we executed type 3/4/5 opcodes above, we know that
418 * the result must be either an Integer, String, or Buffer.
419 */
420 switch (ObjDesc->Common.Type)
421 {
422 case ACPI_TYPE_INTEGER:
423
424 OpcUpdateIntegerNode (Op, ObjDesc->Integer.Value);
425
426 DbgPrint (ASL_PARSE_OUTPUT,
427 "Constant expression reduced to (%s) %8.8X%8.8X\n",
428 Op->Asl.ParseOpName,
429 ACPI_FORMAT_UINT64 (Op->Common.Value.Integer));
430 break;
431
432
433 case ACPI_TYPE_STRING:
434
435 Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
436 Op->Common.AmlOpcode = AML_STRING_OP;
437 Op->Asl.AmlLength = ACPI_STRLEN (ObjDesc->String.Pointer) + 1;
438 Op->Common.Value.String = ObjDesc->String.Pointer;
439
440 DbgPrint (ASL_PARSE_OUTPUT,
441 "Constant expression reduced to (STRING) %s\n",
442 Op->Common.Value.String);
443
444 break;
445
446
447 case ACPI_TYPE_BUFFER:
448
449 Op->Asl.ParseOpcode = PARSEOP_BUFFER;
450 Op->Common.AmlOpcode = AML_BUFFER_OP;
451 Op->Asl.CompileFlags = NODE_AML_PACKAGE;
452 UtSetParseOpName (Op);
453
454 /* Child node is the buffer length */
455
456 RootOp = TrAllocateNode (PARSEOP_INTEGER);
457
458 RootOp->Asl.AmlOpcode = AML_DWORD_OP;
459 RootOp->Asl.Value.Integer = ObjDesc->Buffer.Length;
460 RootOp->Asl.Parent = Op;
461
462 (void) OpcSetOptimalIntegerSize (RootOp);
463
464 Op->Asl.Child = RootOp;
465 Op = RootOp;
466 UtSetParseOpName (Op);
467
468 /* Peer to the child is the raw buffer data */
469
470 RootOp = TrAllocateNode (PARSEOP_RAW_DATA);
471 RootOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
472 RootOp->Asl.AmlLength = ObjDesc->Buffer.Length;
473 RootOp->Asl.Value.String = (char *) ObjDesc->Buffer.Pointer;
474 RootOp->Asl.Parent = Op->Asl.Parent;
475
476 Op->Asl.Next = RootOp;
477 Op = RootOp;
478
479 DbgPrint (ASL_PARSE_OUTPUT,
480 "Constant expression reduced to (BUFFER) length %X\n",
481 ObjDesc->Buffer.Length);
482 break;
483
484
485 default:
486 printf ("Unsupported return type: %s\n",
487 AcpiUtGetObjectTypeName (ObjDesc));
488 break;
489 }
490 }
491
492 UtSetParseOpName (Op);
493 Op->Asl.Child = NULL;
494
495 AcpiDsDeleteWalkState (WalkState);
496 return (AE_CTRL_DEPTH);
497}
498
499
500/*******************************************************************************
501 *
502 * FUNCTION: OpcUpdateIntegerNode
503 *
504 * PARAMETERS: Op - Current parse object
505 *
506 * RETURN: None
507 *
508 * DESCRIPTION: Update node to the correct integer type.
509 *
510 ******************************************************************************/
511
512static void
513OpcUpdateIntegerNode (
514 ACPI_PARSE_OBJECT *Op,
515 UINT64 Value)
516{
517
518 Op->Common.Value.Integer = Value;
519
520 /*
521 * The AmlLength is used by the parser to indicate a constant,
522 * (if non-zero). Length is either (1/2/4/8)
523 */
524 switch (Op->Asl.AmlLength)
525 {
526 case 1:
527 TrUpdateNode (PARSEOP_BYTECONST, Op);
528 Op->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
529 break;
530
531 case 2:
532 TrUpdateNode (PARSEOP_WORDCONST, Op);
533 Op->Asl.AmlOpcode = AML_RAW_DATA_WORD;
534 break;
535
536 case 4:
537 TrUpdateNode (PARSEOP_DWORDCONST, Op);
538 Op->Asl.AmlOpcode = AML_RAW_DATA_DWORD;
539 break;
540
541 case 8:
542 TrUpdateNode (PARSEOP_QWORDCONST, Op);
543 Op->Asl.AmlOpcode = AML_RAW_DATA_QWORD;
544 break;
545
546 case 0:
547 default:
548 OpcSetOptimalIntegerSize (Op);
549 TrUpdateNode (PARSEOP_INTEGER, Op);
550 break;
551 }
552
553 Op->Asl.AmlLength = 0;
554}