Chromium Code Reviews| 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-array-builder.h" | 5 #include "src/interpreter/bytecode-array-builder.h" | 
| 6 #include "src/compiler.h" | 6 #include "src/compiler.h" | 
| 7 | 7 | 
| 8 namespace v8 { | 8 namespace v8 { | 
| 9 namespace internal { | 9 namespace internal { | 
| 10 namespace interpreter { | 10 namespace interpreter { | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 constant_array_builder_(isolate, zone), | 75 constant_array_builder_(isolate, zone), | 
| 76 handler_table_builder_(isolate, zone), | 76 handler_table_builder_(isolate, zone), | 
| 77 source_position_table_builder_(isolate, zone), | 77 source_position_table_builder_(isolate, zone), | 
| 78 last_block_end_(0), | 78 last_block_end_(0), | 
| 79 last_bytecode_start_(~0), | 79 last_bytecode_start_(~0), | 
| 80 exit_seen_in_block_(false), | 80 exit_seen_in_block_(false), | 
| 81 unbound_jumps_(0), | 81 unbound_jumps_(0), | 
| 82 parameter_count_(parameter_count), | 82 parameter_count_(parameter_count), | 
| 83 local_register_count_(locals_count), | 83 local_register_count_(locals_count), | 
| 84 context_register_count_(context_count), | 84 context_register_count_(context_count), | 
| 85 return_position_(RelocInfo::kNoPosition), | |
| 85 temporary_allocator_(zone, fixed_register_count()), | 86 temporary_allocator_(zone, fixed_register_count()), | 
| 86 register_translator_(this) { | 87 register_translator_(this) { | 
| 87 DCHECK_GE(parameter_count_, 0); | 88 DCHECK_GE(parameter_count_, 0); | 
| 88 DCHECK_GE(context_register_count_, 0); | 89 DCHECK_GE(context_register_count_, 0); | 
| 89 DCHECK_GE(local_register_count_, 0); | 90 DCHECK_GE(local_register_count_, 0); | 
| 90 } | 91 } | 
| 91 | 92 | 
| 92 BytecodeArrayBuilder::~BytecodeArrayBuilder() { DCHECK_EQ(0, unbound_jumps_); } | 93 BytecodeArrayBuilder::~BytecodeArrayBuilder() { DCHECK_EQ(0, unbound_jumps_); } | 
| 93 | 94 | 
| 94 Register BytecodeArrayBuilder::first_context_register() const { | 95 Register BytecodeArrayBuilder::first_context_register() const { | 
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 954 | 955 | 
| 955 | 956 | 
| 956 BytecodeArrayBuilder& BytecodeArrayBuilder::ReThrow() { | 957 BytecodeArrayBuilder& BytecodeArrayBuilder::ReThrow() { | 
| 957 Output(Bytecode::kReThrow); | 958 Output(Bytecode::kReThrow); | 
| 958 exit_seen_in_block_ = true; | 959 exit_seen_in_block_ = true; | 
| 959 return *this; | 960 return *this; | 
| 960 } | 961 } | 
| 961 | 962 | 
| 962 | 963 | 
| 963 BytecodeArrayBuilder& BytecodeArrayBuilder::Return() { | 964 BytecodeArrayBuilder& BytecodeArrayBuilder::Return() { | 
| 965 SetReturnPosition(); | |
| 964 Output(Bytecode::kReturn); | 966 Output(Bytecode::kReturn); | 
| 965 exit_seen_in_block_ = true; | 967 exit_seen_in_block_ = true; | 
| 966 return *this; | 968 return *this; | 
| 967 } | 969 } | 
| 968 | 970 | 
| 969 BytecodeArrayBuilder& BytecodeArrayBuilder::Debugger() { | 971 BytecodeArrayBuilder& BytecodeArrayBuilder::Debugger() { | 
| 970 Output(Bytecode::kDebugger); | 972 Output(Bytecode::kDebugger); | 
| 971 return *this; | 973 return *this; | 
| 972 } | 974 } | 
| 973 | 975 | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1035 handler_table_builder()->SetTryRegionEnd(handler_id, bytecodes()->size()); | 1037 handler_table_builder()->SetTryRegionEnd(handler_id, bytecodes()->size()); | 
| 1036 return *this; | 1038 return *this; | 
| 1037 } | 1039 } | 
| 1038 | 1040 | 
| 1039 | 1041 | 
| 1040 void BytecodeArrayBuilder::LeaveBasicBlock() { | 1042 void BytecodeArrayBuilder::LeaveBasicBlock() { | 
| 1041 last_block_end_ = bytecodes()->size(); | 1043 last_block_end_ = bytecodes()->size(); | 
| 1042 exit_seen_in_block_ = false; | 1044 exit_seen_in_block_ = false; | 
| 1043 } | 1045 } | 
| 1044 | 1046 | 
| 1045 void BytecodeArrayBuilder::EnsureReturn(FunctionLiteral* literal) { | 1047 void BytecodeArrayBuilder::EnsureReturn(FunctionLiteral* literal) { | 
| 
 
vogelheim
2016/02/29 14:52:32
Remove literal parameter?
 
Yang
2016/03/01 08:09:18
Done.
 
 | |
| 1046 if (!exit_seen_in_block_) { | 1048 if (!exit_seen_in_block_) { | 
| 1047 LoadUndefined(); | 1049 LoadUndefined(); | 
| 1048 SetReturnPosition(literal); | |
| 1049 Return(); | 1050 Return(); | 
| 1050 } | 1051 } | 
| 1051 DCHECK(exit_seen_in_block_); | 1052 DCHECK(exit_seen_in_block_); | 
| 1052 } | 1053 } | 
| 1053 | 1054 | 
| 1054 BytecodeArrayBuilder& BytecodeArrayBuilder::Call(Register callable, | 1055 BytecodeArrayBuilder& BytecodeArrayBuilder::Call(Register callable, | 
| 1055 Register receiver_args, | 1056 Register receiver_args, | 
| 1056 size_t receiver_args_count, | 1057 size_t receiver_args_count, | 
| 1057 int feedback_slot, | 1058 int feedback_slot, | 
| 1058 TailCallMode tail_call_mode) { | 1059 TailCallMode tail_call_mode) { | 
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1169 LanguageMode language_mode) { | 1170 LanguageMode language_mode) { | 
| 1170 Output(BytecodeForDelete(language_mode), object.ToRawOperand()); | 1171 Output(BytecodeForDelete(language_mode), object.ToRawOperand()); | 
| 1171 return *this; | 1172 return *this; | 
| 1172 } | 1173 } | 
| 1173 | 1174 | 
| 1174 | 1175 | 
| 1175 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { | 1176 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { | 
| 1176 return constant_array_builder()->Insert(object); | 1177 return constant_array_builder()->Insert(object); | 
| 1177 } | 1178 } | 
| 1178 | 1179 | 
| 1179 void BytecodeArrayBuilder::SetReturnPosition(FunctionLiteral* fun) { | 1180 void BytecodeArrayBuilder::InitializeReturnPosition(FunctionLiteral* literal) { | 
| 1180 // Don't emit dead code. | 1181 DCHECK_EQ(RelocInfo::kNoPosition, return_position_); | 
| 1182 return_position_ = | |
| 1183 std::max(literal->start_position(), literal->end_position() - 1); | |
| 1184 } | |
| 1185 | |
| 1186 void BytecodeArrayBuilder::SetReturnPosition() { | |
| 1187 if (return_position_ == RelocInfo::kNoPosition) return; | |
| 
 
vogelheim
2016/02/29 14:52:32
Is this ever supposed to happen?
 
 | |
| 1181 if (exit_seen_in_block_) return; | 1188 if (exit_seen_in_block_) return; | 
| 1182 | 1189 source_position_table_builder_.AddStatementPosition(bytecodes_.size(), | 
| 1183 int pos = std::max(fun->start_position(), fun->end_position() - 1); | 1190 return_position_); | 
| 
 
vogelheim
2016/02/29 14:52:32
I'm confused at this logic. (Not specifically this
 
 | |
| 1184 source_position_table_builder_.AddStatementPosition(bytecodes_.size(), pos); | |
| 1185 } | 1191 } | 
| 1186 | 1192 | 
| 1187 void BytecodeArrayBuilder::SetStatementPosition(Statement* stmt) { | 1193 void BytecodeArrayBuilder::SetStatementPosition(Statement* stmt) { | 
| 1188 if (stmt->position() == RelocInfo::kNoPosition) return; | 1194 if (stmt->position() == RelocInfo::kNoPosition) return; | 
| 1189 if (exit_seen_in_block_) return; | 1195 if (exit_seen_in_block_) return; | 
| 1190 source_position_table_builder_.AddStatementPosition(bytecodes_.size(), | 1196 source_position_table_builder_.AddStatementPosition(bytecodes_.size(), | 
| 1191 stmt->position()); | 1197 stmt->position()); | 
| 1192 } | 1198 } | 
| 1193 | 1199 | 
| 1194 void BytecodeArrayBuilder::SetExpressionPosition(Expression* expr) { | 1200 void BytecodeArrayBuilder::SetExpressionPosition(Expression* expr) { | 
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1624 } | 1630 } | 
| 1625 | 1631 | 
| 1626 // static | 1632 // static | 
| 1627 bool BytecodeArrayBuilder::FitsInReg16OperandUntranslated(Register value) { | 1633 bool BytecodeArrayBuilder::FitsInReg16OperandUntranslated(Register value) { | 
| 1628 return value.is_short_operand(); | 1634 return value.is_short_operand(); | 
| 1629 } | 1635 } | 
| 1630 | 1636 | 
| 1631 } // namespace interpreter | 1637 } // namespace interpreter | 
| 1632 } // namespace internal | 1638 } // namespace internal | 
| 1633 } // namespace v8 | 1639 } // namespace v8 | 
| OLD | NEW |