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 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 namespace interpreter { | 9 namespace interpreter { |
10 | 10 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 output->set_handler_table(*handler_table); | 131 output->set_handler_table(*handler_table); |
132 output->set_source_position_table(*source_position_table); | 132 output->set_source_position_table(*source_position_table); |
133 bytecode_generated_ = true; | 133 bytecode_generated_ = true; |
134 return output; | 134 return output; |
135 } | 135 } |
136 | 136 |
137 | 137 |
138 template <size_t N> | 138 template <size_t N> |
139 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t(&operands)[N]) { | 139 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t(&operands)[N]) { |
140 // Don't output dead code. | 140 // Don't output dead code. |
141 if (exit_seen_in_block_) return; | 141 if (exit_seen_in_block_) { |
| 142 source_position_table_builder_.RevertPosition(bytecodes()->size()); |
| 143 return; |
| 144 } |
142 | 145 |
143 int operand_count = static_cast<int>(N); | 146 int operand_count = static_cast<int>(N); |
144 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count); | 147 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count); |
145 | 148 |
146 int register_operand_count = Bytecodes::NumberOfRegisterOperands(bytecode); | 149 int register_operand_count = Bytecodes::NumberOfRegisterOperands(bytecode); |
147 if (register_operand_count > 0) { | 150 if (register_operand_count > 0) { |
148 register_translator()->TranslateInputRegisters(bytecode, operands, | 151 register_translator()->TranslateInputRegisters(bytecode, operands, |
149 operand_count); | 152 operand_count); |
150 } | 153 } |
151 | 154 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 202 |
200 | 203 |
201 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t operand0) { | 204 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t operand0) { |
202 uint32_t operands[] = {operand0}; | 205 uint32_t operands[] = {operand0}; |
203 Output(bytecode, operands); | 206 Output(bytecode, operands); |
204 } | 207 } |
205 | 208 |
206 | 209 |
207 void BytecodeArrayBuilder::Output(Bytecode bytecode) { | 210 void BytecodeArrayBuilder::Output(Bytecode bytecode) { |
208 // Don't output dead code. | 211 // Don't output dead code. |
209 if (exit_seen_in_block_) return; | 212 if (exit_seen_in_block_) { |
| 213 source_position_table_builder_.RevertPosition(bytecodes()->size()); |
| 214 return; |
| 215 } |
210 | 216 |
211 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); | 217 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); |
212 last_bytecode_start_ = bytecodes()->size(); | 218 last_bytecode_start_ = bytecodes()->size(); |
213 bytecodes()->push_back(Bytecodes::ToByte(bytecode)); | 219 bytecodes()->push_back(Bytecodes::ToByte(bytecode)); |
214 } | 220 } |
215 | 221 |
216 | 222 |
217 BytecodeArrayBuilder& BytecodeArrayBuilder::BinaryOperation(Token::Value op, | 223 BytecodeArrayBuilder& BytecodeArrayBuilder::BinaryOperation(Token::Value op, |
218 Register reg, | 224 Register reg, |
219 Strength strength) { | 225 Strength strength) { |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 case OperandSize::kNone: | 885 case OperandSize::kNone: |
880 UNREACHABLE(); | 886 UNREACHABLE(); |
881 } | 887 } |
882 unbound_jumps_--; | 888 unbound_jumps_--; |
883 } | 889 } |
884 | 890 |
885 | 891 |
886 BytecodeArrayBuilder& BytecodeArrayBuilder::OutputJump(Bytecode jump_bytecode, | 892 BytecodeArrayBuilder& BytecodeArrayBuilder::OutputJump(Bytecode jump_bytecode, |
887 BytecodeLabel* label) { | 893 BytecodeLabel* label) { |
888 // Don't emit dead code. | 894 // Don't emit dead code. |
889 if (exit_seen_in_block_) return *this; | 895 if (exit_seen_in_block_) { |
| 896 source_position_table_builder_.RevertPosition(bytecodes()->size()); |
| 897 return *this; |
| 898 } |
890 | 899 |
891 // Check if the value in accumulator is boolean, if not choose an | 900 // Check if the value in accumulator is boolean, if not choose an |
892 // appropriate JumpIfToBoolean bytecode. | 901 // appropriate JumpIfToBoolean bytecode. |
893 if (NeedToBooleanCast()) { | 902 if (NeedToBooleanCast()) { |
894 jump_bytecode = GetJumpWithToBoolean(jump_bytecode); | 903 jump_bytecode = GetJumpWithToBoolean(jump_bytecode); |
895 } | 904 } |
896 | 905 |
897 if (label->is_bound()) { | 906 if (label->is_bound()) { |
898 // Label has been bound already so this is a backwards jump. | 907 // Label has been bound already so this is a backwards jump. |
899 CHECK_GE(bytecodes()->size(), label->offset()); | 908 CHECK_GE(bytecodes()->size(), label->offset()); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 return *this; | 1212 return *this; |
1204 } | 1213 } |
1205 | 1214 |
1206 | 1215 |
1207 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { | 1216 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { |
1208 return constant_array_builder()->Insert(object); | 1217 return constant_array_builder()->Insert(object); |
1209 } | 1218 } |
1210 | 1219 |
1211 void BytecodeArrayBuilder::SetStatementPosition(Statement* stmt) { | 1220 void BytecodeArrayBuilder::SetStatementPosition(Statement* stmt) { |
1212 if (stmt->position() == RelocInfo::kNoPosition) return; | 1221 if (stmt->position() == RelocInfo::kNoPosition) return; |
1213 source_position_table_builder_.AddStatementPosition( | 1222 source_position_table_builder_.AddStatementPosition(bytecodes_.size(), |
1214 static_cast<int>(bytecodes_.size()), stmt->position()); | 1223 stmt->position()); |
1215 } | 1224 } |
1216 | 1225 |
1217 void BytecodeArrayBuilder::SetExpressionPosition(Expression* expr) { | 1226 void BytecodeArrayBuilder::SetExpressionPosition(Expression* expr) { |
1218 if (expr->position() == RelocInfo::kNoPosition) return; | 1227 if (expr->position() == RelocInfo::kNoPosition) return; |
1219 source_position_table_builder_.AddExpressionPosition( | 1228 source_position_table_builder_.AddExpressionPosition(bytecodes_.size(), |
1220 static_cast<int>(bytecodes_.size()), expr->position()); | 1229 expr->position()); |
1221 } | 1230 } |
1222 | 1231 |
1223 bool BytecodeArrayBuilder::TemporaryRegisterIsLive(Register reg) const { | 1232 bool BytecodeArrayBuilder::TemporaryRegisterIsLive(Register reg) const { |
1224 return temporary_register_allocator()->RegisterIsLive(reg); | 1233 return temporary_register_allocator()->RegisterIsLive(reg); |
1225 } | 1234 } |
1226 | 1235 |
1227 bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index, | 1236 bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index, |
1228 uint32_t operand_value) const { | 1237 uint32_t operand_value) const { |
1229 OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index); | 1238 OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index); |
1230 switch (operand_type) { | 1239 switch (operand_type) { |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 } | 1696 } |
1688 | 1697 |
1689 // static | 1698 // static |
1690 bool BytecodeArrayBuilder::FitsInReg16OperandUntranslated(Register value) { | 1699 bool BytecodeArrayBuilder::FitsInReg16OperandUntranslated(Register value) { |
1691 return value.is_short_operand(); | 1700 return value.is_short_operand(); |
1692 } | 1701 } |
1693 | 1702 |
1694 } // namespace interpreter | 1703 } // namespace interpreter |
1695 } // namespace internal | 1704 } // namespace internal |
1696 } // namespace v8 | 1705 } // namespace v8 |
OLD | NEW |