| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if V8_TARGET_ARCH_IA32 | 5 #if V8_TARGET_ARCH_IA32 |
| 6 | 6 |
| 7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| 11 #include "src/debug/debug.h" | 11 #include "src/debug/debug.h" |
| 12 #include "src/full-codegen/full-codegen.h" | 12 #include "src/full-codegen/full-codegen.h" |
| 13 #include "src/ia32/frames-ia32.h" | 13 #include "src/ia32/frames-ia32.h" |
| 14 #include "src/ic/ic.h" | 14 #include "src/ic/ic.h" |
| 15 #include "src/parsing/parser.h" | 15 #include "src/parsing/parser.h" |
| 16 | 16 |
| 17 namespace v8 { | 17 namespace v8 { |
| 18 namespace internal { | 18 namespace internal { |
| 19 | 19 |
| 20 #define __ ACCESS_MASM(masm_) | 20 #define __ ACCESS_MASM(masm()) |
| 21 | |
| 22 | 21 |
| 23 class JumpPatchSite BASE_EMBEDDED { | 22 class JumpPatchSite BASE_EMBEDDED { |
| 24 public: | 23 public: |
| 25 explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) { | 24 explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) { |
| 26 #ifdef DEBUG | 25 #ifdef DEBUG |
| 27 info_emitted_ = false; | 26 info_emitted_ = false; |
| 28 #endif | 27 #endif |
| 29 } | 28 } |
| 30 | 29 |
| 31 ~JumpPatchSite() { | 30 ~JumpPatchSite() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 61 | 60 |
| 62 private: | 61 private: |
| 63 // jc will be patched with jz, jnc will become jnz. | 62 // jc will be patched with jz, jnc will become jnz. |
| 64 void EmitJump(Condition cc, Label* target, Label::Distance distance) { | 63 void EmitJump(Condition cc, Label* target, Label::Distance distance) { |
| 65 DCHECK(!patch_site_.is_bound() && !info_emitted_); | 64 DCHECK(!patch_site_.is_bound() && !info_emitted_); |
| 66 DCHECK(cc == carry || cc == not_carry); | 65 DCHECK(cc == carry || cc == not_carry); |
| 67 __ bind(&patch_site_); | 66 __ bind(&patch_site_); |
| 68 __ j(cc, target, distance); | 67 __ j(cc, target, distance); |
| 69 } | 68 } |
| 70 | 69 |
| 70 MacroAssembler* masm() { return masm_; } |
| 71 MacroAssembler* masm_; | 71 MacroAssembler* masm_; |
| 72 Label patch_site_; | 72 Label patch_site_; |
| 73 #ifdef DEBUG | 73 #ifdef DEBUG |
| 74 bool info_emitted_; | 74 bool info_emitted_; |
| 75 #endif | 75 #endif |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 | 78 |
| 79 // Generate code for a JS function. On entry to the function the receiver | 79 // Generate code for a JS function. On entry to the function the receiver |
| 80 // and arguments have been pushed on the stack left to right, with the | 80 // and arguments have been pushed on the stack left to right, with the |
| (...skipping 1768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 __ bind(&continuation); | 1849 __ bind(&continuation); |
| 1850 // When we arrive here, the stack top is the resume mode and | 1850 // When we arrive here, the stack top is the resume mode and |
| 1851 // result_register() holds the input value (the argument given to the | 1851 // result_register() holds the input value (the argument given to the |
| 1852 // respective resume operation). | 1852 // respective resume operation). |
| 1853 __ RecordGeneratorContinuation(); | 1853 __ RecordGeneratorContinuation(); |
| 1854 __ pop(ebx); | 1854 __ pop(ebx); |
| 1855 __ cmp(ebx, Immediate(Smi::FromInt(JSGeneratorObject::RETURN))); | 1855 __ cmp(ebx, Immediate(Smi::FromInt(JSGeneratorObject::RETURN))); |
| 1856 __ j(not_equal, &resume); | 1856 __ j(not_equal, &resume); |
| 1857 __ push(result_register()); | 1857 __ push(result_register()); |
| 1858 EmitCreateIteratorResult(true); | 1858 EmitCreateIteratorResult(true); |
| 1859 EmitUnwindBeforeReturn(); | 1859 EmitUnwindAndReturn(); |
| 1860 EmitReturnSequence(); | |
| 1861 | 1860 |
| 1862 __ bind(&suspend); | 1861 __ bind(&suspend); |
| 1863 VisitForAccumulatorValue(expr->generator_object()); | 1862 VisitForAccumulatorValue(expr->generator_object()); |
| 1864 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); | 1863 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); |
| 1865 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), | 1864 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
| 1866 Immediate(Smi::FromInt(continuation.pos()))); | 1865 Immediate(Smi::FromInt(continuation.pos()))); |
| 1867 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); | 1866 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
| 1868 __ mov(ecx, esi); | 1867 __ mov(ecx, esi); |
| 1869 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, | 1868 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
| 1870 kDontSaveFPRegs); | 1869 kDontSaveFPRegs); |
| 1871 __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); | 1870 __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); |
| 1872 __ cmp(esp, ebx); | 1871 __ cmp(esp, ebx); |
| 1873 __ j(equal, &post_runtime); | 1872 __ j(equal, &post_runtime); |
| 1874 __ push(eax); // generator object | 1873 __ push(eax); // generator object |
| 1875 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 1874 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 1876 __ mov(context_register(), | 1875 __ mov(context_register(), |
| 1877 Operand(ebp, StandardFrameConstants::kContextOffset)); | 1876 Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 1878 __ bind(&post_runtime); | 1877 __ bind(&post_runtime); |
| 1879 __ pop(result_register()); | 1878 __ pop(result_register()); |
| 1880 EmitReturnSequence(); | 1879 EmitReturnSequence(); |
| 1881 | 1880 |
| 1882 __ bind(&resume); | 1881 __ bind(&resume); |
| 1883 context()->Plug(result_register()); | 1882 context()->Plug(result_register()); |
| 1884 break; | 1883 break; |
| 1885 } | 1884 } |
| 1886 | 1885 |
| 1887 case Yield::kFinal: { | 1886 case Yield::kFinal: { |
| 1888 // Pop value from top-of-stack slot, box result into result register. | 1887 // Pop value from top-of-stack slot, box result into result register. |
| 1889 EmitCreateIteratorResult(true); | 1888 EmitCreateIteratorResult(true); |
| 1890 EmitUnwindBeforeReturn(); | 1889 EmitUnwindAndReturn(); |
| 1891 EmitReturnSequence(); | |
| 1892 break; | 1890 break; |
| 1893 } | 1891 } |
| 1894 | 1892 |
| 1895 case Yield::kDelegating: { | 1893 case Yield::kDelegating: { |
| 1896 VisitForStackValue(expr->generator_object()); | 1894 VisitForStackValue(expr->generator_object()); |
| 1897 | 1895 |
| 1898 // Initial stack layout is as follows: | 1896 // Initial stack layout is as follows: |
| 1899 // [sp + 1 * kPointerSize] iter | 1897 // [sp + 1 * kPointerSize] iter |
| 1900 // [sp + 0 * kPointerSize] g | 1898 // [sp + 0 * kPointerSize] g |
| 1901 | 1899 |
| (...skipping 2678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4580 DCHECK(closure_scope->is_function_scope()); | 4578 DCHECK(closure_scope->is_function_scope()); |
| 4581 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 4579 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 4582 } | 4580 } |
| 4583 } | 4581 } |
| 4584 | 4582 |
| 4585 | 4583 |
| 4586 // ---------------------------------------------------------------------------- | 4584 // ---------------------------------------------------------------------------- |
| 4587 // Non-local control flow support. | 4585 // Non-local control flow support. |
| 4588 | 4586 |
| 4589 void FullCodeGenerator::EnterFinallyBlock() { | 4587 void FullCodeGenerator::EnterFinallyBlock() { |
| 4590 // Cook return address on top of stack (smi encoded Code* delta) | |
| 4591 DCHECK(!result_register().is(edx)); | |
| 4592 __ pop(edx); | |
| 4593 __ sub(edx, Immediate(masm_->CodeObject())); | |
| 4594 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); | |
| 4595 STATIC_ASSERT(kSmiTag == 0); | |
| 4596 __ SmiTag(edx); | |
| 4597 __ push(edx); | |
| 4598 | |
| 4599 // Store result register while executing finally block. | |
| 4600 __ push(result_register()); | |
| 4601 | |
| 4602 // Store pending message while executing finally block. | 4588 // Store pending message while executing finally block. |
| 4603 ExternalReference pending_message_obj = | 4589 ExternalReference pending_message_obj = |
| 4604 ExternalReference::address_of_pending_message_obj(isolate()); | 4590 ExternalReference::address_of_pending_message_obj(isolate()); |
| 4605 __ mov(edx, Operand::StaticVariable(pending_message_obj)); | 4591 __ mov(edx, Operand::StaticVariable(pending_message_obj)); |
| 4606 __ push(edx); | 4592 __ push(edx); |
| 4607 | 4593 |
| 4608 ClearPendingMessage(); | 4594 ClearPendingMessage(); |
| 4609 } | 4595 } |
| 4610 | 4596 |
| 4611 | 4597 |
| 4612 void FullCodeGenerator::ExitFinallyBlock() { | 4598 void FullCodeGenerator::ExitFinallyBlock() { |
| 4613 DCHECK(!result_register().is(edx)); | 4599 DCHECK(!result_register().is(edx)); |
| 4614 // Restore pending message from stack. | 4600 // Restore pending message from stack. |
| 4615 __ pop(edx); | 4601 __ pop(edx); |
| 4616 ExternalReference pending_message_obj = | 4602 ExternalReference pending_message_obj = |
| 4617 ExternalReference::address_of_pending_message_obj(isolate()); | 4603 ExternalReference::address_of_pending_message_obj(isolate()); |
| 4618 __ mov(Operand::StaticVariable(pending_message_obj), edx); | 4604 __ mov(Operand::StaticVariable(pending_message_obj), edx); |
| 4619 | |
| 4620 // Restore result register from stack. | |
| 4621 __ pop(result_register()); | |
| 4622 | |
| 4623 // Uncook return address. | |
| 4624 __ pop(edx); | |
| 4625 __ SmiUntag(edx); | |
| 4626 __ add(edx, Immediate(masm_->CodeObject())); | |
| 4627 __ jmp(edx); | |
| 4628 } | 4605 } |
| 4629 | 4606 |
| 4630 | 4607 |
| 4631 void FullCodeGenerator::ClearPendingMessage() { | 4608 void FullCodeGenerator::ClearPendingMessage() { |
| 4632 DCHECK(!result_register().is(edx)); | 4609 DCHECK(!result_register().is(edx)); |
| 4633 ExternalReference pending_message_obj = | 4610 ExternalReference pending_message_obj = |
| 4634 ExternalReference::address_of_pending_message_obj(isolate()); | 4611 ExternalReference::address_of_pending_message_obj(isolate()); |
| 4635 __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); | 4612 __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); |
| 4636 __ mov(Operand::StaticVariable(pending_message_obj), edx); | 4613 __ mov(Operand::StaticVariable(pending_message_obj), edx); |
| 4637 } | 4614 } |
| 4638 | 4615 |
| 4639 | 4616 |
| 4640 void FullCodeGenerator::EmitLoadStoreICSlot(FeedbackVectorSlot slot) { | 4617 void FullCodeGenerator::EmitLoadStoreICSlot(FeedbackVectorSlot slot) { |
| 4641 DCHECK(!slot.IsInvalid()); | 4618 DCHECK(!slot.IsInvalid()); |
| 4642 __ mov(VectorStoreICTrampolineDescriptor::SlotRegister(), | 4619 __ mov(VectorStoreICTrampolineDescriptor::SlotRegister(), |
| 4643 Immediate(SmiFromSlot(slot))); | 4620 Immediate(SmiFromSlot(slot))); |
| 4644 } | 4621 } |
| 4645 | 4622 |
| 4623 void FullCodeGenerator::DeferredCommands::EmitCommands() { |
| 4624 DCHECK(!result_register().is(edx)); |
| 4625 __ Pop(result_register()); // Restore the accumulator. |
| 4626 __ Pop(edx); // Get the token. |
| 4627 for (DeferredCommand cmd : commands_) { |
| 4628 Label skip; |
| 4629 __ cmp(edx, Immediate(Smi::FromInt(cmd.token))); |
| 4630 __ j(not_equal, &skip); |
| 4631 switch (cmd.command) { |
| 4632 case kReturn: |
| 4633 codegen_->EmitUnwindAndReturn(); |
| 4634 break; |
| 4635 case kThrow: |
| 4636 __ Push(result_register()); |
| 4637 __ CallRuntime(Runtime::kReThrow); |
| 4638 break; |
| 4639 case kContinue: |
| 4640 codegen_->EmitContinue(cmd.target); |
| 4641 break; |
| 4642 case kBreak: |
| 4643 codegen_->EmitBreak(cmd.target); |
| 4644 break; |
| 4645 } |
| 4646 __ bind(&skip); |
| 4647 } |
| 4648 } |
| 4646 | 4649 |
| 4647 #undef __ | 4650 #undef __ |
| 4648 | 4651 |
| 4649 | 4652 |
| 4650 static const byte kJnsInstruction = 0x79; | 4653 static const byte kJnsInstruction = 0x79; |
| 4651 static const byte kJnsOffset = 0x11; | 4654 static const byte kJnsOffset = 0x11; |
| 4652 static const byte kNopByteOne = 0x66; | 4655 static const byte kNopByteOne = 0x66; |
| 4653 static const byte kNopByteTwo = 0x90; | 4656 static const byte kNopByteTwo = 0x90; |
| 4654 #ifdef DEBUG | 4657 #ifdef DEBUG |
| 4655 static const byte kCallInstruction = 0xe8; | 4658 static const byte kCallInstruction = 0xe8; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4721 Assembler::target_address_at(call_target_address, | 4724 Assembler::target_address_at(call_target_address, |
| 4722 unoptimized_code)); | 4725 unoptimized_code)); |
| 4723 return OSR_AFTER_STACK_CHECK; | 4726 return OSR_AFTER_STACK_CHECK; |
| 4724 } | 4727 } |
| 4725 | 4728 |
| 4726 | 4729 |
| 4727 } // namespace internal | 4730 } // namespace internal |
| 4728 } // namespace v8 | 4731 } // namespace v8 |
| 4729 | 4732 |
| 4730 #endif // V8_TARGET_ARCH_IA32 | 4733 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |