OLD | NEW |
---|---|
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 | 466 |
467 __ CallRuntime(function, arg_count); | 467 __ CallRuntime(function, arg_count); |
468 if (expr->location().is_temporary()) { | 468 if (expr->location().is_temporary()) { |
469 __ push(rax); | 469 __ push(rax); |
470 } else { | 470 } else { |
471 ASSERT(expr->location().is_nowhere()); | 471 ASSERT(expr->location().is_nowhere()); |
472 } | 472 } |
473 } | 473 } |
474 | 474 |
475 | 475 |
476 void FastCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { | |
477 // Compile a short-circuited boolean or operation in a non-test | |
478 // context. | |
479 ASSERT(expr->op() == Token::OR); | |
480 // Compile (e0 || e1) as if it were | |
481 // (let (temp = e0) temp ? temp : e1). | |
482 | |
483 Label eval_right, done; | |
484 Location destination = expr->location(); | |
485 ASSERT(!destination.is_constant()); | |
486 | |
487 Expression* left = expr->left(); | |
488 Location left_source = left->location(); | |
489 ASSERT(!left_source.is_nowhere()); | |
490 | |
491 Expression* right = expr->right(); | |
492 Location right_source = right->location(); | |
493 ASSERT(!right_source.is_nowhere()); | |
494 | |
495 Visit(left); | |
496 // Use the shared ToBoolean stub to find the boolean value of the | |
497 // left-hand subexpression. Load the value into rax to perform some | |
498 // inlined checks assumed by the stub. | |
499 if (left_source.is_temporary()) { | |
500 if (destination.is_temporary()) { | |
501 // Copy the left-hand value into rax because we may need it as the | |
502 // final result. | |
503 __ movq(rax, Operand(rsp, 0)); | |
504 } else { | |
505 // Pop the left-hand value into rax because we will not need it as the | |
506 // final result. | |
507 __ pop(rax); | |
508 } | |
509 } else { | |
510 // Load the left-hand value into rax. Put it on the stack if we may | |
511 // need it. | |
512 ASSERT(left->AsLiteral() != NULL); | |
513 __ Move(rax, left->AsLiteral()->handle()); | |
514 if (destination.is_temporary()) __ push(rax); | |
515 } | |
William Hesse
2009/10/23 07:20:05
Should "Load a Location into rax and optionally th
| |
516 // The left-hand value is in rax. It is also on the stack iff the | |
517 // destination location is temporary. | |
518 | |
519 // Perform fast checks assumed by the stub. | |
520 // The undefined value is false. | |
521 __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); | |
522 __ j(equal, &eval_right); | |
523 __ CompareRoot(rax, Heap::kTrueValueRootIndex); // True is true. | |
524 __ j(equal, &done); | |
525 __ CompareRoot(rax, Heap::kFalseValueRootIndex); // False is false. | |
526 __ j(equal, &eval_right); | |
527 ASSERT(kSmiTag == 0); | |
528 __ SmiCompare(rax, Smi::FromInt(0)); // The smi zero is false. | |
529 __ j(equal, &eval_right); | |
530 Condition is_smi = masm_->CheckSmi(rax); // All other smis are true. | |
531 __ j(is_smi, &done); | |
532 | |
533 // Call the stub for all other cases. | |
534 __ push(rax); | |
535 ToBooleanStub stub; | |
536 __ CallStub(&stub); | |
537 __ testq(rax, rax); // The stub returns nonzero for true. | |
538 __ j(not_zero, &done); | |
539 | |
540 __ bind(&eval_right); | |
541 // Discard the left-hand value if present on the stack. | |
542 if (destination.is_temporary()) { | |
543 __ addq(rsp, Immediate(kPointerSize)); | |
544 } | |
545 Visit(right); | |
546 | |
547 // Save or discard the right-hand value as needed. | |
548 if (destination.is_temporary() && right_source.is_constant()) { | |
549 ASSERT(right->AsLiteral() != NULL); | |
550 __ Push(right->AsLiteral()->handle()); | |
551 } else if (destination.is_nowhere() && right_source.is_temporary()) { | |
552 __ addq(rsp, Immediate(kPointerSize)); | |
553 } | |
554 | |
555 __ bind(&done); | |
556 } | |
557 | |
558 | |
476 } } // namespace v8::internal | 559 } } // namespace v8::internal |
OLD | NEW |