OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 } | 746 } |
747 | 747 |
748 | 748 |
749 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { | 749 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
750 // The variable in the declaration always resides in the current context. | 750 // The variable in the declaration always resides in the current context. |
751 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); | 751 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
752 if (generate_debug_code_) { | 752 if (generate_debug_code_) { |
753 // Check that we're not inside a with or catch context. | 753 // Check that we're not inside a with or catch context. |
754 __ movq(rbx, FieldOperand(rsi, HeapObject::kMapOffset)); | 754 __ movq(rbx, FieldOperand(rsi, HeapObject::kMapOffset)); |
755 __ CompareRoot(rbx, Heap::kWithContextMapRootIndex); | 755 __ CompareRoot(rbx, Heap::kWithContextMapRootIndex); |
756 __ Check(not_equal, kDeclarationInWithContext); | 756 __ Check(not_equal, "Declaration in with context."); |
757 __ CompareRoot(rbx, Heap::kCatchContextMapRootIndex); | 757 __ CompareRoot(rbx, Heap::kCatchContextMapRootIndex); |
758 __ Check(not_equal, kDeclarationInCatchContext); | 758 __ Check(not_equal, "Declaration in catch context."); |
759 } | 759 } |
760 } | 760 } |
761 | 761 |
762 | 762 |
763 void FullCodeGenerator::VisitVariableDeclaration( | 763 void FullCodeGenerator::VisitVariableDeclaration( |
764 VariableDeclaration* declaration) { | 764 VariableDeclaration* declaration) { |
765 // If it was not possible to allocate the variable at compile time, we | 765 // If it was not possible to allocate the variable at compile time, we |
766 // need to "declare" it at runtime to make sure it actually exists in the | 766 // need to "declare" it at runtime to make sure it actually exists in the |
767 // local context. | 767 // local context. |
768 VariableProxy* proxy = declaration->proxy(); | 768 VariableProxy* proxy = declaration->proxy(); |
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2185 __ subq(rdx, Immediate(1)); | 2185 __ subq(rdx, Immediate(1)); |
2186 __ j(carry, &call_resume); | 2186 __ j(carry, &call_resume); |
2187 __ push(rcx); | 2187 __ push(rcx); |
2188 __ jmp(&push_operand_holes); | 2188 __ jmp(&push_operand_holes); |
2189 __ bind(&call_resume); | 2189 __ bind(&call_resume); |
2190 __ push(rbx); | 2190 __ push(rbx); |
2191 __ push(result_register()); | 2191 __ push(result_register()); |
2192 __ Push(Smi::FromInt(resume_mode)); | 2192 __ Push(Smi::FromInt(resume_mode)); |
2193 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); | 2193 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
2194 // Not reached: the runtime call returns elsewhere. | 2194 // Not reached: the runtime call returns elsewhere. |
2195 __ Abort(kGeneratorFailedToResume); | 2195 __ Abort("Generator failed to resume."); |
2196 | 2196 |
2197 // Throw error if we attempt to operate on a running generator. | 2197 // Throw error if we attempt to operate on a running generator. |
2198 __ bind(&wrong_state); | 2198 __ bind(&wrong_state); |
2199 __ push(rbx); | 2199 __ push(rbx); |
2200 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); | 2200 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); |
2201 | 2201 |
2202 __ bind(&done); | 2202 __ bind(&done); |
2203 context()->Plug(result_register()); | 2203 context()->Plug(result_register()); |
2204 } | 2204 } |
2205 | 2205 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2449 | 2449 |
2450 } else if (!var->is_const_mode() || op == Token::INIT_CONST_HARMONY) { | 2450 } else if (!var->is_const_mode() || op == Token::INIT_CONST_HARMONY) { |
2451 // Assignment to var or initializing assignment to let/const | 2451 // Assignment to var or initializing assignment to let/const |
2452 // in harmony mode. | 2452 // in harmony mode. |
2453 if (var->IsStackAllocated() || var->IsContextSlot()) { | 2453 if (var->IsStackAllocated() || var->IsContextSlot()) { |
2454 MemOperand location = VarOperand(var, rcx); | 2454 MemOperand location = VarOperand(var, rcx); |
2455 if (generate_debug_code_ && op == Token::INIT_LET) { | 2455 if (generate_debug_code_ && op == Token::INIT_LET) { |
2456 // Check for an uninitialized let binding. | 2456 // Check for an uninitialized let binding. |
2457 __ movq(rdx, location); | 2457 __ movq(rdx, location); |
2458 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); | 2458 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); |
2459 __ Check(equal, kLetBindingReInitialization); | 2459 __ Check(equal, "Let binding re-initialization."); |
2460 } | 2460 } |
2461 // Perform the assignment. | 2461 // Perform the assignment. |
2462 __ movq(location, rax); | 2462 __ movq(location, rax); |
2463 if (var->IsContextSlot()) { | 2463 if (var->IsContextSlot()) { |
2464 __ movq(rdx, rax); | 2464 __ movq(rdx, rax); |
2465 __ RecordWriteContextSlot( | 2465 __ RecordWriteContextSlot( |
2466 rcx, Context::SlotOffset(var->index()), rdx, rbx, kDontSaveFPRegs); | 2466 rcx, Context::SlotOffset(var->index()), rdx, rbx, kDontSaveFPRegs); |
2467 } | 2467 } |
2468 } else { | 2468 } else { |
2469 ASSERT(var->IsLookupSlot()); | 2469 ASSERT(var->IsLookupSlot()); |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3391 __ CallRuntime(Runtime::kThrowNotDateError, 0); | 3391 __ CallRuntime(Runtime::kThrowNotDateError, 0); |
3392 __ bind(&done); | 3392 __ bind(&done); |
3393 context()->Plug(rax); | 3393 context()->Plug(rax); |
3394 } | 3394 } |
3395 | 3395 |
3396 | 3396 |
3397 void FullCodeGenerator::EmitSeqStringSetCharCheck(Register string, | 3397 void FullCodeGenerator::EmitSeqStringSetCharCheck(Register string, |
3398 Register index, | 3398 Register index, |
3399 Register value, | 3399 Register value, |
3400 uint32_t encoding_mask) { | 3400 uint32_t encoding_mask) { |
3401 __ Check(masm()->CheckSmi(index), kNonSmiIndex); | 3401 __ Check(masm()->CheckSmi(index), "Non-smi index"); |
3402 __ Check(masm()->CheckSmi(value), kNonSmiValue); | 3402 __ Check(masm()->CheckSmi(value), "Non-smi value"); |
3403 | 3403 |
3404 __ SmiCompare(index, FieldOperand(string, String::kLengthOffset)); | 3404 __ SmiCompare(index, FieldOperand(string, String::kLengthOffset)); |
3405 __ Check(less, kIndexIsTooLarge); | 3405 __ Check(less, "Index is too large"); |
3406 | 3406 |
3407 __ SmiCompare(index, Smi::FromInt(0)); | 3407 __ SmiCompare(index, Smi::FromInt(0)); |
3408 __ Check(greater_equal, kIndexIsNegative); | 3408 __ Check(greater_equal, "Index is negative"); |
3409 | 3409 |
3410 __ push(value); | 3410 __ push(value); |
3411 __ movq(value, FieldOperand(string, HeapObject::kMapOffset)); | 3411 __ movq(value, FieldOperand(string, HeapObject::kMapOffset)); |
3412 __ movzxbq(value, FieldOperand(value, Map::kInstanceTypeOffset)); | 3412 __ movzxbq(value, FieldOperand(value, Map::kInstanceTypeOffset)); |
3413 | 3413 |
3414 __ andb(value, Immediate(kStringRepresentationMask | kStringEncodingMask)); | 3414 __ andb(value, Immediate(kStringRepresentationMask | kStringEncodingMask)); |
3415 __ cmpq(value, Immediate(encoding_mask)); | 3415 __ cmpq(value, Immediate(encoding_mask)); |
3416 __ Check(equal, kUnexpectedStringType); | 3416 __ Check(equal, "Unexpected string type"); |
3417 __ pop(value); | 3417 __ pop(value); |
3418 } | 3418 } |
3419 | 3419 |
3420 | 3420 |
3421 void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { | 3421 void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { |
3422 ZoneList<Expression*>* args = expr->arguments(); | 3422 ZoneList<Expression*>* args = expr->arguments(); |
3423 ASSERT_EQ(3, args->length()); | 3423 ASSERT_EQ(3, args->length()); |
3424 | 3424 |
3425 Register string = rax; | 3425 Register string = rax; |
3426 Register index = rbx; | 3426 Register index = rbx; |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3770 void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { | 3770 void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { |
3771 ZoneList<Expression*>* args = expr->arguments(); | 3771 ZoneList<Expression*>* args = expr->arguments(); |
3772 ASSERT_EQ(2, args->length()); | 3772 ASSERT_EQ(2, args->length()); |
3773 | 3773 |
3774 ASSERT_NE(NULL, args->at(0)->AsLiteral()); | 3774 ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
3775 int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value(); | 3775 int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value(); |
3776 | 3776 |
3777 Handle<FixedArray> jsfunction_result_caches( | 3777 Handle<FixedArray> jsfunction_result_caches( |
3778 isolate()->native_context()->jsfunction_result_caches()); | 3778 isolate()->native_context()->jsfunction_result_caches()); |
3779 if (jsfunction_result_caches->length() <= cache_id) { | 3779 if (jsfunction_result_caches->length() <= cache_id) { |
3780 __ Abort(kAttemptToUseUndefinedCache); | 3780 __ Abort("Attempt to use undefined cache."); |
3781 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | 3781 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
3782 context()->Plug(rax); | 3782 context()->Plug(rax); |
3783 return; | 3783 return; |
3784 } | 3784 } |
3785 | 3785 |
3786 VisitForAccumulatorValue(args->at(1)); | 3786 VisitForAccumulatorValue(args->at(1)); |
3787 | 3787 |
3788 Register key = rax; | 3788 Register key = rax; |
3789 Register cache = rbx; | 3789 Register cache = rbx; |
3790 Register tmp = rcx; | 3790 Register tmp = rcx; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3964 | 3964 |
3965 // Check that all array elements are sequential ASCII strings, and | 3965 // Check that all array elements are sequential ASCII strings, and |
3966 // accumulate the sum of their lengths, as a smi-encoded value. | 3966 // accumulate the sum of their lengths, as a smi-encoded value. |
3967 __ Set(index, 0); | 3967 __ Set(index, 0); |
3968 __ Set(string_length, 0); | 3968 __ Set(string_length, 0); |
3969 // Loop condition: while (index < array_length). | 3969 // Loop condition: while (index < array_length). |
3970 // Live loop registers: index(int32), array_length(int32), string(String*), | 3970 // Live loop registers: index(int32), array_length(int32), string(String*), |
3971 // scratch, string_length(int32), elements(FixedArray*). | 3971 // scratch, string_length(int32), elements(FixedArray*). |
3972 if (generate_debug_code_) { | 3972 if (generate_debug_code_) { |
3973 __ cmpq(index, array_length); | 3973 __ cmpq(index, array_length); |
3974 __ Assert(below, kNoEmptyArraysHereInEmitFastAsciiArrayJoin); | 3974 __ Assert(below, "No empty arrays here in EmitFastAsciiArrayJoin"); |
3975 } | 3975 } |
3976 __ bind(&loop); | 3976 __ bind(&loop); |
3977 __ movq(string, FieldOperand(elements, | 3977 __ movq(string, FieldOperand(elements, |
3978 index, | 3978 index, |
3979 times_pointer_size, | 3979 times_pointer_size, |
3980 FixedArray::kHeaderSize)); | 3980 FixedArray::kHeaderSize)); |
3981 __ JumpIfSmi(string, &bailout); | 3981 __ JumpIfSmi(string, &bailout); |
3982 __ movq(scratch, FieldOperand(string, HeapObject::kMapOffset)); | 3982 __ movq(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
3983 __ movzxbl(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); | 3983 __ movzxbl(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
3984 __ andb(scratch, Immediate( | 3984 __ andb(scratch, Immediate( |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4328 case Token::TYPEOF: { | 4328 case Token::TYPEOF: { |
4329 Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); | 4329 Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
4330 { StackValueContext context(this); | 4330 { StackValueContext context(this); |
4331 VisitForTypeofValue(expr->expression()); | 4331 VisitForTypeofValue(expr->expression()); |
4332 } | 4332 } |
4333 __ CallRuntime(Runtime::kTypeof, 1); | 4333 __ CallRuntime(Runtime::kTypeof, 1); |
4334 context()->Plug(rax); | 4334 context()->Plug(rax); |
4335 break; | 4335 break; |
4336 } | 4336 } |
4337 | 4337 |
| 4338 case Token::SUB: |
| 4339 EmitUnaryOperation(expr, "[ UnaryOperation (SUB)"); |
| 4340 break; |
| 4341 |
| 4342 case Token::BIT_NOT: |
| 4343 EmitUnaryOperation(expr, "[ UnaryOperation (BIT_NOT)"); |
| 4344 break; |
| 4345 |
4338 default: | 4346 default: |
4339 UNREACHABLE(); | 4347 UNREACHABLE(); |
4340 } | 4348 } |
4341 } | 4349 } |
4342 | 4350 |
4343 | 4351 |
| 4352 void FullCodeGenerator::EmitUnaryOperation(UnaryOperation* expr, |
| 4353 const char* comment) { |
| 4354 // TODO(svenpanne): Allowing format strings in Comment would be nice here... |
| 4355 Comment cmt(masm_, comment); |
| 4356 UnaryOpStub stub(expr->op()); |
| 4357 // UnaryOpStub expects the argument to be in the |
| 4358 // accumulator register rax. |
| 4359 VisitForAccumulatorValue(expr->expression()); |
| 4360 SetSourcePosition(expr->position()); |
| 4361 CallIC(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, |
| 4362 expr->UnaryOperationFeedbackId()); |
| 4363 context()->Plug(rax); |
| 4364 } |
| 4365 |
| 4366 |
4344 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { | 4367 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
4345 Comment cmnt(masm_, "[ CountOperation"); | 4368 Comment cmnt(masm_, "[ CountOperation"); |
4346 SetSourcePosition(expr->position()); | 4369 SetSourcePosition(expr->position()); |
4347 | 4370 |
4348 // Invalid left-hand-sides are rewritten to have a 'throw | 4371 // Invalid left-hand-sides are rewritten to have a 'throw |
4349 // ReferenceError' as the left-hand side. | 4372 // ReferenceError' as the left-hand side. |
4350 if (!expr->expression()->IsValidLeftHandSide()) { | 4373 if (!expr->expression()->IsValidLeftHandSide()) { |
4351 VisitForEffect(expr->expression()); | 4374 VisitForEffect(expr->expression()); |
4352 return; | 4375 return; |
4353 } | 4376 } |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4789 | 4812 |
4790 | 4813 |
4791 // ---------------------------------------------------------------------------- | 4814 // ---------------------------------------------------------------------------- |
4792 // Non-local control flow support. | 4815 // Non-local control flow support. |
4793 | 4816 |
4794 | 4817 |
4795 void FullCodeGenerator::EnterFinallyBlock() { | 4818 void FullCodeGenerator::EnterFinallyBlock() { |
4796 ASSERT(!result_register().is(rdx)); | 4819 ASSERT(!result_register().is(rdx)); |
4797 ASSERT(!result_register().is(rcx)); | 4820 ASSERT(!result_register().is(rcx)); |
4798 // Cook return address on top of stack (smi encoded Code* delta) | 4821 // Cook return address on top of stack (smi encoded Code* delta) |
4799 __ PopReturnAddressTo(rdx); | 4822 __ pop(rdx); |
4800 __ Move(rcx, masm_->CodeObject()); | 4823 __ Move(rcx, masm_->CodeObject()); |
4801 __ subq(rdx, rcx); | 4824 __ subq(rdx, rcx); |
4802 __ Integer32ToSmi(rdx, rdx); | 4825 __ Integer32ToSmi(rdx, rdx); |
4803 __ push(rdx); | 4826 __ push(rdx); |
4804 | 4827 |
4805 // Store result register while executing finally block. | 4828 // Store result register while executing finally block. |
4806 __ push(result_register()); | 4829 __ push(result_register()); |
4807 | 4830 |
4808 // Store pending message while executing finally block. | 4831 // Store pending message while executing finally block. |
4809 ExternalReference pending_message_obj = | 4832 ExternalReference pending_message_obj = |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4882 *context_length = 0; | 4905 *context_length = 0; |
4883 return previous_; | 4906 return previous_; |
4884 } | 4907 } |
4885 | 4908 |
4886 | 4909 |
4887 #undef __ | 4910 #undef __ |
4888 | 4911 |
4889 } } // namespace v8::internal | 4912 } } // namespace v8::internal |
4890 | 4913 |
4891 #endif // V8_TARGET_ARCH_X64 | 4914 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |