Deleted Added
full compact
aslfold.c (229989) aslfold.c (239340)
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
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);
76
80
81
77/*******************************************************************************
78 *
79 * FUNCTION: OpcAmlEvaluationWalk1
80 *
81 * PARAMETERS: ASL_WALK_CALLBACK
82 *
83 * RETURN: Status
84 *

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

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

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

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

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

364 RootOp->Common.AmlOpcode = AML_INT_EVAL_SUBTREE_OP;
365
366 OriginalParentOp = Op->Common.Parent;
367 Op->Common.Parent = RootOp;
368
369 /* Hand off the subtree to the AML interpreter */
370
371 Status = TrWalkParseTree (Op, ASL_WALK_VISIT_TWICE,
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,
372 OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState);
377 OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState);
373 Op->Common.Parent = OriginalParentOp;
374
375 /* TBD: we really *should* release the RootOp node */
376
377 if (ACPI_SUCCESS (Status))
378 {
379 TotalFolds++;
380
381 /* Get the final result */
382
383 Status = AcpiDsResultPop (&ObjDesc, WalkState);
384 }
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 }
385 }
386
387 if (ACPI_FAILURE (Status))
388 {
389 /* We could not resolve the subtree for some reason */
390
398 }
399
400 if (ACPI_FAILURE (Status))
401 {
402 /* We could not resolve the subtree for some reason */
403
391 AslCoreSubsystemError (Op, Status,
392 "Failure during constant evaluation", FALSE);
393 AslError (ASL_ERROR, ASL_MSG_CONSTANT_EVALUATION, Op,
394 Op->Asl.ParseOpName);
395
404 AslError (ASL_ERROR, ASL_MSG_CONSTANT_EVALUATION, Op,
405 Op->Asl.ParseOpName);
406
396 /* Set the subtree value to ZERO anyway. Eliminates further errors */
407 /* Set the subtree value to ZERO anyway. Eliminates further errors */
397
408
398 Op->Asl.ParseOpcode = PARSEOP_INTEGER;
399 Op->Common.Value.Integer = 0;
400 OpcSetOptimalIntegerSize (Op);
409 OpcUpdateIntegerNode (Op, 0);
401 }
402 else
403 {
404 AslError (ASL_OPTIMIZATION, ASL_MSG_CONSTANT_FOLDED, Op,
405 Op->Asl.ParseOpName);
406
407 /*
408 * Because we know we executed type 3/4/5 opcodes above, we know that
409 * the result must be either an Integer, String, or Buffer.
410 */
411 switch (ObjDesc->Common.Type)
412 {
413 case ACPI_TYPE_INTEGER:
414
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
415 Op->Asl.ParseOpcode = PARSEOP_INTEGER;
416 Op->Common.Value.Integer = ObjDesc->Integer.Value;
417 OpcSetOptimalIntegerSize (Op);
424 OpcUpdateIntegerNode (Op, ObjDesc->Integer.Value);
418
419 DbgPrint (ASL_PARSE_OUTPUT,
425
426 DbgPrint (ASL_PARSE_OUTPUT,
420 "Constant expression reduced to (INTEGER) %8.8X%8.8X\n",
421 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
427 "Constant expression reduced to (%s) %8.8X%8.8X\n",
428 Op->Asl.ParseOpName,
429 ACPI_FORMAT_UINT64 (Op->Common.Value.Integer));
422 break;
423
424
425 case ACPI_TYPE_STRING:
426
430 break;
431
432
433 case ACPI_TYPE_STRING:
434
427 Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
428 Op->Common.AmlOpcode = AML_STRING_OP;
429 Op->Asl.AmlLength = ACPI_STRLEN (ObjDesc->String.Pointer) + 1;
435 Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL;
436 Op->Common.AmlOpcode = AML_STRING_OP;
437 Op->Asl.AmlLength = ACPI_STRLEN (ObjDesc->String.Pointer) + 1;
430 Op->Common.Value.String = ObjDesc->String.Pointer;
431
432 DbgPrint (ASL_PARSE_OUTPUT,
433 "Constant expression reduced to (STRING) %s\n",
434 Op->Common.Value.String);
435
436 break;
437
438
439 case ACPI_TYPE_BUFFER:
440
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
441 Op->Asl.ParseOpcode = PARSEOP_BUFFER;
442 Op->Common.AmlOpcode = AML_BUFFER_OP;
443 Op->Asl.CompileFlags = NODE_AML_PACKAGE;
449 Op->Asl.ParseOpcode = PARSEOP_BUFFER;
450 Op->Common.AmlOpcode = AML_BUFFER_OP;
451 Op->Asl.CompileFlags = NODE_AML_PACKAGE;
444 UtSetParseOpName (Op);
445
446 /* Child node is the buffer length */
447
448 RootOp = TrAllocateNode (PARSEOP_INTEGER);
449
452 UtSetParseOpName (Op);
453
454 /* Child node is the buffer length */
455
456 RootOp = TrAllocateNode (PARSEOP_INTEGER);
457
450 RootOp->Asl.AmlOpcode = AML_DWORD_OP;
458 RootOp->Asl.AmlOpcode = AML_DWORD_OP;
451 RootOp->Asl.Value.Integer = ObjDesc->Buffer.Length;
459 RootOp->Asl.Value.Integer = ObjDesc->Buffer.Length;
452 RootOp->Asl.Parent = Op;
460 RootOp->Asl.Parent = Op;
453
454 (void) OpcSetOptimalIntegerSize (RootOp);
455
456 Op->Asl.Child = RootOp;
457 Op = RootOp;
458 UtSetParseOpName (Op);
459
460 /* Peer to the child is the raw buffer data */
461
462 RootOp = TrAllocateNode (PARSEOP_RAW_DATA);
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);
463 RootOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER;
464 RootOp->Asl.AmlLength = ObjDesc->Buffer.Length;
465 RootOp->Asl.Value.String = (char *) ObjDesc->Buffer.Pointer;
466 RootOp->Asl.Parent = Op->Asl.Parent;
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;
467
468 Op->Asl.Next = RootOp;
469 Op = RootOp;
470
471 DbgPrint (ASL_PARSE_OUTPUT,
472 "Constant expression reduced to (BUFFER) length %X\n",
473 ObjDesc->Buffer.Length);
474 break;
475
476
477 default:
478 printf ("Unsupported return type: %s\n",
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",
479 AcpiUtGetObjectTypeName (ObjDesc));
487 AcpiUtGetObjectTypeName (ObjDesc));
480 break;
481 }
482 }
483
484 UtSetParseOpName (Op);
485 Op->Asl.Child = NULL;
486
487 AcpiDsDeleteWalkState (WalkState);
488 break;
489 }
490 }
491
492 UtSetParseOpName (Op);
493 Op->Asl.Child = NULL;
494
495 AcpiDsDeleteWalkState (WalkState);
488
489 return (AE_CTRL_DEPTH);
490}
491
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}