| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
| 6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 7 | 7 |
| 8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
| 9 | 9 |
| 10 #include "lib/error.h" | 10 #include "lib/error.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 ASSERT(type.IsInstantiated()); | 204 ASSERT(type.IsInstantiated()); |
| 205 const Class& type_class = Class::Handle(type.type_class()); | 205 const Class& type_class = Class::Handle(type.type_class()); |
| 206 ASSERT(!type_class.HasTypeArguments()); | 206 ASSERT(!type_class.HasTypeArguments()); |
| 207 | 207 |
| 208 const Register kInstanceReg = EAX; | 208 const Register kInstanceReg = EAX; |
| 209 Label compare_classes; | 209 Label compare_classes; |
| 210 __ testl(kInstanceReg, Immediate(kSmiTagMask)); | 210 __ testl(kInstanceReg, Immediate(kSmiTagMask)); |
| 211 __ j(NOT_ZERO, &compare_classes, Assembler::kNearJump); | 211 __ j(NOT_ZERO, &compare_classes, Assembler::kNearJump); |
| 212 // Instance is Smi, check directly. | 212 // Instance is Smi, check directly. |
| 213 const Class& smi_class = Class::Handle(Smi::Class()); | 213 const Class& smi_class = Class::Handle(Smi::Class()); |
| 214 // TODO(regis): We should introduce a SmiType. | |
| 215 Error& malformed_error = Error::Handle(); | 214 Error& malformed_error = Error::Handle(); |
| 216 if (smi_class.IsSubtypeOf(TypeArguments::Handle(), | 215 if (smi_class.IsSubtypeOf(TypeArguments::Handle(), |
| 217 type_class, | 216 type_class, |
| 218 TypeArguments::Handle(), | 217 TypeArguments::Handle(), |
| 219 &malformed_error)) { | 218 &malformed_error)) { |
| 220 __ jmp(is_instance_lbl); | 219 __ jmp(is_instance_lbl); |
| 221 } else { | 220 } else { |
| 222 __ jmp(is_not_instance_lbl); | 221 __ jmp(is_not_instance_lbl); |
| 223 } | 222 } |
| 224 // Compare if the classes are equal. | 223 // Compare if the classes are equal. |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 | 473 |
| 475 // Generate inline instanceof test. | 474 // Generate inline instanceof test. |
| 476 SubtypeTestCache& test_cache = SubtypeTestCache::ZoneHandle(); | 475 SubtypeTestCache& test_cache = SubtypeTestCache::ZoneHandle(); |
| 477 test_cache = GenerateInlineInstanceof(cid, token_pos, type, | 476 test_cache = GenerateInlineInstanceof(cid, token_pos, type, |
| 478 &is_instance, &is_not_instance); | 477 &is_instance, &is_not_instance); |
| 479 | 478 |
| 480 // Generate runtime call. | 479 // Generate runtime call. |
| 481 __ movl(EDX, Address(ESP, 0)); // Get instantiator type arguments. | 480 __ movl(EDX, Address(ESP, 0)); // Get instantiator type arguments. |
| 482 __ movl(ECX, Address(ESP, kWordSize)); // Get instantiator. | 481 __ movl(ECX, Address(ESP, kWordSize)); // Get instantiator. |
| 483 __ PushObject(Object::ZoneHandle()); // Make room for the result. | 482 __ PushObject(Object::ZoneHandle()); // Make room for the result. |
| 484 __ pushl(Immediate(Smi::RawValue(token_pos))); // Source location. | |
| 485 __ pushl(Immediate(Smi::RawValue(cid))); // Computation id. | 483 __ pushl(Immediate(Smi::RawValue(cid))); // Computation id. |
| 486 __ pushl(EAX); // Push the instance. | 484 __ pushl(EAX); // Push the instance. |
| 487 __ PushObject(type); // Push the type. | 485 __ PushObject(type); // Push the type. |
| 488 __ pushl(ECX); // TODO(srdjan): Pass instantiator instead of null. | 486 __ pushl(ECX); // TODO(srdjan): Pass instantiator instead of null. |
| 489 __ pushl(EDX); // Instantiator type arguments. | 487 __ pushl(EDX); // Instantiator type arguments. |
| 490 __ LoadObject(EAX, test_cache); | 488 __ LoadObject(EAX, test_cache); |
| 491 __ pushl(EAX); | 489 __ pushl(EAX); |
| 492 GenerateCallRuntime(cid, token_pos, try_index, kInstanceofRuntimeEntry); | 490 GenerateCallRuntime(cid, token_pos, try_index, kInstanceofRuntimeEntry); |
| 493 // Pop the two parameters supplied to the runtime entry. The result of the | 491 // Pop the parameters supplied to the runtime entry. The result of the |
| 494 // instanceof runtime call will be left as the result of the operation. | 492 // instanceof runtime call will be left as the result of the operation. |
| 495 __ Drop(7); | 493 __ Drop(6); |
| 496 Label done; | 494 Label done; |
| 497 if (negate_result) { | 495 if (negate_result) { |
| 498 __ popl(EDX); | 496 __ popl(EDX); |
| 499 __ LoadObject(EAX, bool_true()); | 497 __ LoadObject(EAX, bool_true()); |
| 500 __ cmpl(EDX, EAX); | 498 __ cmpl(EDX, EAX); |
| 501 __ j(NOT_EQUAL, &done, Assembler::kNearJump); | 499 __ j(NOT_EQUAL, &done, Assembler::kNearJump); |
| 502 __ LoadObject(EAX, bool_false()); | 500 __ LoadObject(EAX, bool_false()); |
| 503 } else { | 501 } else { |
| 504 __ popl(EAX); | 502 __ popl(EAX); |
| 505 } | 503 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 Label is_assignable, runtime_call; | 547 Label is_assignable, runtime_call; |
| 550 __ cmpl(EAX, raw_null); | 548 __ cmpl(EAX, raw_null); |
| 551 __ j(EQUAL, &is_assignable); | 549 __ j(EQUAL, &is_assignable); |
| 552 | 550 |
| 553 // Generate throw new TypeError() if the type is malformed. | 551 // Generate throw new TypeError() if the type is malformed. |
| 554 if (dst_type.IsMalformed()) { | 552 if (dst_type.IsMalformed()) { |
| 555 const Error& error = Error::Handle(dst_type.malformed_error()); | 553 const Error& error = Error::Handle(dst_type.malformed_error()); |
| 556 const String& error_message = String::ZoneHandle( | 554 const String& error_message = String::ZoneHandle( |
| 557 String::NewSymbol(error.ToErrorCString())); | 555 String::NewSymbol(error.ToErrorCString())); |
| 558 __ PushObject(Object::ZoneHandle()); // Make room for the result. | 556 __ PushObject(Object::ZoneHandle()); // Make room for the result. |
| 559 __ pushl(Immediate(Smi::RawValue(token_pos))); // Source location. | |
| 560 __ pushl(EAX); // Push the source object. | 557 __ pushl(EAX); // Push the source object. |
| 561 __ PushObject(dst_name); // Push the name of the destination. | 558 __ PushObject(dst_name); // Push the name of the destination. |
| 562 __ PushObject(error_message); | 559 __ PushObject(error_message); |
| 563 GenerateCallRuntime(cid, | 560 GenerateCallRuntime(cid, |
| 564 token_pos, | 561 token_pos, |
| 565 try_index, | 562 try_index, |
| 566 kMalformedTypeErrorRuntimeEntry); | 563 kMalformedTypeErrorRuntimeEntry); |
| 567 // We should never return here. | 564 // We should never return here. |
| 568 __ int3(); | 565 __ int3(); |
| 569 | 566 |
| 570 __ Bind(&is_assignable); // For a null object. | 567 __ Bind(&is_assignable); // For a null object. |
| 571 return; | 568 return; |
| 572 } | 569 } |
| 573 | 570 |
| 574 // Generate inline type check, linking to runtime call if not assignable. | 571 // Generate inline type check, linking to runtime call if not assignable. |
| 575 SubtypeTestCache& test_cache = SubtypeTestCache::ZoneHandle(); | 572 SubtypeTestCache& test_cache = SubtypeTestCache::ZoneHandle(); |
| 576 test_cache = GenerateInlineInstanceof(cid, token_pos, dst_type, | 573 test_cache = GenerateInlineInstanceof(cid, token_pos, dst_type, |
| 577 &is_assignable, &runtime_call); | 574 &is_assignable, &runtime_call); |
| 578 | 575 |
| 579 __ Bind(&runtime_call); | 576 __ Bind(&runtime_call); |
| 580 __ movl(EDX, Address(ESP, 0)); // Get instantiator type arguments. | 577 __ movl(EDX, Address(ESP, 0)); // Get instantiator type arguments. |
| 581 __ movl(ECX, Address(ESP, kWordSize)); // Get instantiator. | 578 __ movl(ECX, Address(ESP, kWordSize)); // Get instantiator. |
| 582 __ PushObject(Object::ZoneHandle()); // Make room for the result. | 579 __ PushObject(Object::ZoneHandle()); // Make room for the result. |
| 583 __ pushl(Immediate(Smi::RawValue(token_pos))); // Source location. | |
| 584 __ pushl(Immediate(Smi::RawValue(cid))); // Computation id. | 580 __ pushl(Immediate(Smi::RawValue(cid))); // Computation id. |
| 585 __ pushl(EAX); // Push the source object. | 581 __ pushl(EAX); // Push the source object. |
| 586 __ PushObject(dst_type); // Push the type of the destination. | 582 __ PushObject(dst_type); // Push the type of the destination. |
| 587 __ pushl(ECX); // Instantiator. | 583 __ pushl(ECX); // Instantiator. |
| 588 __ pushl(EDX); // Instantiator type arguments. | 584 __ pushl(EDX); // Instantiator type arguments. |
| 589 __ PushObject(dst_name); // Push the name of the destination. | 585 __ PushObject(dst_name); // Push the name of the destination. |
| 590 __ LoadObject(EAX, test_cache); | 586 __ LoadObject(EAX, test_cache); |
| 591 __ pushl(EAX); | 587 __ pushl(EAX); |
| 592 GenerateCallRuntime(cid, | 588 GenerateCallRuntime(cid, |
| 593 token_pos, | 589 token_pos, |
| 594 try_index, | 590 try_index, |
| 595 kTypeCheckRuntimeEntry); | 591 kTypeCheckRuntimeEntry); |
| 596 // Pop the parameters supplied to the runtime entry. The result of the | 592 // Pop the parameters supplied to the runtime entry. The result of the |
| 597 // type check runtime call is the checked value. | 593 // type check runtime call is the checked value. |
| 598 __ Drop(8); | 594 __ Drop(7); |
| 599 __ popl(EAX); | 595 __ popl(EAX); |
| 600 | 596 |
| 601 __ Bind(&is_assignable); | 597 __ Bind(&is_assignable); |
| 602 __ popl(EDX); // Remove pushed instantiator type arguments.. | 598 __ popl(EDX); // Remove pushed instantiator type arguments.. |
| 603 __ popl(ECX); // Remove pushed instantiator. | 599 __ popl(ECX); // Remove pushed instantiator. |
| 604 } | 600 } |
| 605 | 601 |
| 606 | 602 |
| 607 void FlowGraphCompiler::EmitInstructionPrologue(Instruction* instr) { | 603 void FlowGraphCompiler::EmitInstructionPrologue(Instruction* instr) { |
| 608 LocationSummary* locs = instr->locs(); | 604 LocationSummary* locs = instr->locs(); |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 __ cvtsi2sd(result, temp); | 1070 __ cvtsi2sd(result, temp); |
| 1075 __ Bind(&done); | 1071 __ Bind(&done); |
| 1076 } | 1072 } |
| 1077 | 1073 |
| 1078 | 1074 |
| 1079 #undef __ | 1075 #undef __ |
| 1080 | 1076 |
| 1081 } // namespace dart | 1077 } // namespace dart |
| 1082 | 1078 |
| 1083 #endif // defined TARGET_ARCH_IA32 | 1079 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |