OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "src/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/interpreter/bytecode-register-allocator.h" | 10 #include "src/interpreter/bytecode-register-allocator.h" |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 ZoneVector<BytecodeLabel>& targets) { | 650 ZoneVector<BytecodeLabel>& targets) { |
651 // TODO(neis): Optimize this by using a proper jump table. | 651 // TODO(neis): Optimize this by using a proper jump table. |
652 for (size_t i = start_index; i < start_index + size; i++) { | 652 for (size_t i = start_index; i < start_index + size; i++) { |
653 DCHECK(0 <= i && i < targets.size()); | 653 DCHECK(0 <= i && i < targets.size()); |
654 builder() | 654 builder() |
655 ->LoadLiteral(Smi::FromInt(static_cast<int>(i))) | 655 ->LoadLiteral(Smi::FromInt(static_cast<int>(i))) |
656 .CompareOperation(Token::Value::EQ_STRICT, index) | 656 .CompareOperation(Token::Value::EQ_STRICT, index) |
657 .JumpIfTrue(&(targets[i])); | 657 .JumpIfTrue(&(targets[i])); |
658 } | 658 } |
659 | 659 |
660 RegisterAllocationScope register_scope(this); | 660 BuildAbort(BailoutReason::kInvalidJumpTableIndex); |
661 Register reason = register_allocator()->NewRegister(); | |
662 BailoutReason bailout_reason = BailoutReason::kInvalidJumpTableIndex; | |
663 builder() | |
664 ->LoadLiteral(Smi::FromInt(static_cast<int>(bailout_reason))) | |
665 .StoreAccumulatorInRegister(reason) | |
666 .CallRuntime(Runtime::kAbort, reason, 1); | |
667 } | 661 } |
668 | 662 |
669 void BytecodeGenerator::VisitIterationHeader(IterationStatement* stmt, | 663 void BytecodeGenerator::VisitIterationHeader(IterationStatement* stmt, |
670 LoopBuilder* loop_builder) { | 664 LoopBuilder* loop_builder) { |
671 // Recall that stmt->yield_count() is always zero inside ordinary | 665 // Recall that stmt->yield_count() is always zero inside ordinary |
672 // (i.e. non-generator) functions. | 666 // (i.e. non-generator) functions. |
673 | 667 |
674 // Collect all labels for generator resume points within the loop (if any) so | 668 // Collect all labels for generator resume points within the loop (if any) so |
675 // that they can be bound to the loop header below. Also create fresh labels | 669 // that they can be bound to the loop header below. Also create fresh labels |
676 // for these resume points, to be used inside the loop. | 670 // for these resume points, to be used inside the loop. |
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 Register home_object, | 1946 Register home_object, |
1953 Register key, | 1947 Register key, |
1954 Register value) { | 1948 Register value) { |
1955 DCHECK(Register::AreContiguous(receiver, home_object, key, value)); | 1949 DCHECK(Register::AreContiguous(receiver, home_object, key, value)); |
1956 Runtime::FunctionId function_id = is_strict(language_mode()) | 1950 Runtime::FunctionId function_id = is_strict(language_mode()) |
1957 ? Runtime::kStoreKeyedToSuper_Strict | 1951 ? Runtime::kStoreKeyedToSuper_Strict |
1958 : Runtime::kStoreKeyedToSuper_Sloppy; | 1952 : Runtime::kStoreKeyedToSuper_Sloppy; |
1959 builder()->CallRuntime(function_id, receiver, 4); | 1953 builder()->CallRuntime(function_id, receiver, 4); |
1960 } | 1954 } |
1961 | 1955 |
| 1956 void BytecodeGenerator::BuildAbort(BailoutReason bailout_reason) { |
| 1957 RegisterAllocationScope register_scope(this); |
| 1958 Register reason = register_allocator()->NewRegister(); |
| 1959 builder() |
| 1960 ->LoadLiteral(Smi::FromInt(static_cast<int>(bailout_reason))) |
| 1961 .StoreAccumulatorInRegister(reason) |
| 1962 .CallRuntime(Runtime::kAbort, reason, 1); |
| 1963 } |
| 1964 |
1962 void BytecodeGenerator::BuildThrowReferenceError(Handle<String> name) { | 1965 void BytecodeGenerator::BuildThrowReferenceError(Handle<String> name) { |
1963 RegisterAllocationScope register_scope(this); | 1966 RegisterAllocationScope register_scope(this); |
1964 Register name_reg = register_allocator()->NewRegister(); | 1967 Register name_reg = register_allocator()->NewRegister(); |
1965 builder()->LoadLiteral(name).StoreAccumulatorInRegister(name_reg).CallRuntime( | 1968 builder()->LoadLiteral(name).StoreAccumulatorInRegister(name_reg).CallRuntime( |
1966 Runtime::kThrowReferenceError, name_reg, 1); | 1969 Runtime::kThrowReferenceError, name_reg, 1); |
1967 } | 1970 } |
1968 | 1971 |
1969 void BytecodeGenerator::BuildThrowIfHole(Handle<String> name) { | 1972 void BytecodeGenerator::BuildThrowIfHole(Handle<String> name) { |
1970 // TODO(interpreter): Can the parser reduce the number of checks | 1973 // TODO(interpreter): Can the parser reduce the number of checks |
1971 // performed? Or should there be a ThrowIfHole bytecode. | 1974 // performed? Or should there be a ThrowIfHole bytecode. |
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3275 } | 3278 } |
3276 | 3279 |
3277 | 3280 |
3278 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3281 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
3279 return info()->shared_info()->feedback_vector()->GetIndex(slot); | 3282 return info()->shared_info()->feedback_vector()->GetIndex(slot); |
3280 } | 3283 } |
3281 | 3284 |
3282 } // namespace interpreter | 3285 } // namespace interpreter |
3283 } // namespace internal | 3286 } // namespace internal |
3284 } // namespace v8 | 3287 } // namespace v8 |
OLD | NEW |