OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 2638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2649 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { | 2649 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
2650 class DeferredStringCharCodeAt: public LDeferredCode { | 2650 class DeferredStringCharCodeAt: public LDeferredCode { |
2651 public: | 2651 public: |
2652 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) | 2652 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
2653 : LDeferredCode(codegen), instr_(instr) { } | 2653 : LDeferredCode(codegen), instr_(instr) { } |
2654 virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } | 2654 virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } |
2655 private: | 2655 private: |
2656 LStringCharCodeAt* instr_; | 2656 LStringCharCodeAt* instr_; |
2657 }; | 2657 }; |
2658 | 2658 |
2659 DeferredStringCharCodeAt* deferred | |
2660 = new DeferredStringCharCodeAt(this, instr); | |
2661 | |
2662 Register string = ToRegister(instr->string()); | 2659 Register string = ToRegister(instr->string()); |
2663 Register index = no_reg; | 2660 Register index = no_reg; |
2664 int const_index = -1; | 2661 int const_index = -1; |
2665 if (instr->index()->IsConstantOperand()) { | 2662 if (instr->index()->IsConstantOperand()) { |
2666 const_index = ToInteger32(LConstantOperand::cast(instr->index())); | 2663 const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 2664 STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); |
| 2665 if (!Smi::IsValid(const_index)) { |
| 2666 // Guaranteed to be out of bounds because of the assert above. |
| 2667 // So the bounds check that must dominate this instruction must |
| 2668 // have deoptimized already. |
| 2669 if (FLAG_debug_code) { |
| 2670 __ Abort("StringCharCodeAt: out of bounds index."); |
| 2671 } |
| 2672 // No code needs to be generated. |
| 2673 return; |
| 2674 } |
2667 } else { | 2675 } else { |
2668 index = ToRegister(instr->index()); | 2676 index = ToRegister(instr->index()); |
2669 } | 2677 } |
2670 Register result = ToRegister(instr->result()); | 2678 Register result = ToRegister(instr->result()); |
2671 | 2679 |
| 2680 DeferredStringCharCodeAt* deferred = |
| 2681 new DeferredStringCharCodeAt(this, instr); |
| 2682 |
2672 NearLabel flat_string, ascii_string, done; | 2683 NearLabel flat_string, ascii_string, done; |
2673 | 2684 |
2674 // Fetch the instance type of the receiver into result register. | 2685 // Fetch the instance type of the receiver into result register. |
2675 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); | 2686 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); |
2676 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); | 2687 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); |
2677 | 2688 |
2678 // We need special handling for non-flat strings. | 2689 // We need special handling for non-flat strings. |
2679 STATIC_ASSERT(kSeqStringTag == 0); | 2690 STATIC_ASSERT(kSeqStringTag == 0); |
2680 __ test(result, Immediate(kStringRepresentationMask)); | 2691 __ test(result, Immediate(kStringRepresentationMask)); |
2681 __ j(zero, &flat_string); | 2692 __ j(zero, &flat_string); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2743 Register string = ToRegister(instr->string()); | 2754 Register string = ToRegister(instr->string()); |
2744 Register result = ToRegister(instr->result()); | 2755 Register result = ToRegister(instr->result()); |
2745 | 2756 |
2746 // TODO(3095996): Get rid of this. For now, we need to make the | 2757 // TODO(3095996): Get rid of this. For now, we need to make the |
2747 // result register contain a valid pointer because it is already | 2758 // result register contain a valid pointer because it is already |
2748 // contained in the register pointer map. | 2759 // contained in the register pointer map. |
2749 __ Set(result, Immediate(0)); | 2760 __ Set(result, Immediate(0)); |
2750 | 2761 |
2751 __ PushSafepointRegisters(); | 2762 __ PushSafepointRegisters(); |
2752 __ push(string); | 2763 __ push(string); |
2753 // Push the index as a smi. | 2764 // Push the index as a smi. This is safe because of the checks in |
| 2765 // DoStringCharCodeAt above. |
| 2766 STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); |
2754 if (instr->index()->IsConstantOperand()) { | 2767 if (instr->index()->IsConstantOperand()) { |
2755 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); | 2768 int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
2756 __ push(Immediate(Smi::FromInt(const_index))); | 2769 __ push(Immediate(Smi::FromInt(const_index))); |
2757 } else { | 2770 } else { |
2758 Register index = ToRegister(instr->index()); | 2771 Register index = ToRegister(instr->index()); |
2759 __ SmiTag(index); | 2772 __ SmiTag(index); |
2760 __ push(index); | 2773 __ push(index); |
2761 } | 2774 } |
2762 __ CallRuntimeSaveDoubles(Runtime::kStringCharCodeAt); | 2775 __ CallRuntimeSaveDoubles(Runtime::kStringCharCodeAt); |
2763 RecordSafepointWithRegisters( | 2776 RecordSafepointWithRegisters( |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3583 ASSERT(osr_pc_offset_ == -1); | 3596 ASSERT(osr_pc_offset_ == -1); |
3584 osr_pc_offset_ = masm()->pc_offset(); | 3597 osr_pc_offset_ = masm()->pc_offset(); |
3585 } | 3598 } |
3586 | 3599 |
3587 | 3600 |
3588 #undef __ | 3601 #undef __ |
3589 | 3602 |
3590 } } // namespace v8::internal | 3603 } } // namespace v8::internal |
3591 | 3604 |
3592 #endif // V8_TARGET_ARCH_IA32 | 3605 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |