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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate, Zone* zone, | 67 BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate, Zone* zone, |
68 int parameter_count, | 68 int parameter_count, |
69 int context_count, int locals_count) | 69 int context_count, int locals_count) |
70 : isolate_(isolate), | 70 : isolate_(isolate), |
71 zone_(zone), | 71 zone_(zone), |
72 bytecodes_(zone), | 72 bytecodes_(zone), |
73 bytecode_generated_(false), | 73 bytecode_generated_(false), |
74 constant_array_builder_(isolate, zone), | 74 constant_array_builder_(isolate, zone), |
75 handler_table_builder_(isolate, zone), | 75 handler_table_builder_(isolate, zone), |
| 76 source_position_table_builder_(isolate, zone), |
76 last_block_end_(0), | 77 last_block_end_(0), |
77 last_bytecode_start_(~0), | 78 last_bytecode_start_(~0), |
78 exit_seen_in_block_(false), | 79 exit_seen_in_block_(false), |
79 unbound_jumps_(0), | 80 unbound_jumps_(0), |
80 parameter_count_(parameter_count), | 81 parameter_count_(parameter_count), |
81 local_register_count_(locals_count), | 82 local_register_count_(locals_count), |
82 context_register_count_(context_count), | 83 context_register_count_(context_count), |
83 temporary_allocator_(zone, fixed_register_count()), | 84 temporary_allocator_(zone, fixed_register_count()), |
84 register_translator_(this) { | 85 register_translator_(this) { |
85 DCHECK_GE(parameter_count_, 0); | 86 DCHECK_GE(parameter_count_, 0); |
(...skipping 29 matching lines...) Expand all Loading... |
115 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { | 116 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { |
116 DCHECK_EQ(bytecode_generated_, false); | 117 DCHECK_EQ(bytecode_generated_, false); |
117 EnsureReturn(); | 118 EnsureReturn(); |
118 | 119 |
119 int bytecode_size = static_cast<int>(bytecodes_.size()); | 120 int bytecode_size = static_cast<int>(bytecodes_.size()); |
120 int register_count = | 121 int register_count = |
121 fixed_and_temporary_register_count() + translation_register_count(); | 122 fixed_and_temporary_register_count() + translation_register_count(); |
122 int frame_size = register_count * kPointerSize; | 123 int frame_size = register_count * kPointerSize; |
123 Handle<FixedArray> constant_pool = constant_array_builder()->ToFixedArray(); | 124 Handle<FixedArray> constant_pool = constant_array_builder()->ToFixedArray(); |
124 Handle<FixedArray> handler_table = handler_table_builder()->ToHandlerTable(); | 125 Handle<FixedArray> handler_table = handler_table_builder()->ToHandlerTable(); |
| 126 Handle<FixedArray> source_position_table = |
| 127 source_position_table_builder()->ToFixedArray(); |
125 Handle<BytecodeArray> output = isolate_->factory()->NewBytecodeArray( | 128 Handle<BytecodeArray> output = isolate_->factory()->NewBytecodeArray( |
126 bytecode_size, &bytecodes_.front(), frame_size, parameter_count(), | 129 bytecode_size, &bytecodes_.front(), frame_size, parameter_count(), |
127 constant_pool); | 130 constant_pool); |
128 output->set_handler_table(*handler_table); | 131 output->set_handler_table(*handler_table); |
| 132 output->set_source_position_table(*source_position_table); |
129 bytecode_generated_ = true; | 133 bytecode_generated_ = true; |
130 return output; | 134 return output; |
131 } | 135 } |
132 | 136 |
133 | 137 |
134 template <size_t N> | 138 template <size_t N> |
135 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t(&operands)[N]) { | 139 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t(&operands)[N]) { |
136 // Don't output dead code. | 140 // Don't output dead code. |
137 if (exit_seen_in_block_) return; | 141 if (exit_seen_in_block_) return; |
138 | 142 |
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 BytecodeArrayBuilder& BytecodeArrayBuilder::DeleteLookupSlot() { | 1179 BytecodeArrayBuilder& BytecodeArrayBuilder::DeleteLookupSlot() { |
1176 Output(Bytecode::kDeleteLookupSlot); | 1180 Output(Bytecode::kDeleteLookupSlot); |
1177 return *this; | 1181 return *this; |
1178 } | 1182 } |
1179 | 1183 |
1180 | 1184 |
1181 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { | 1185 size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) { |
1182 return constant_array_builder()->Insert(object); | 1186 return constant_array_builder()->Insert(object); |
1183 } | 1187 } |
1184 | 1188 |
| 1189 void BytecodeArrayBuilder::SetStatementPosition(Statement* stmt) { |
| 1190 if (stmt->position() == RelocInfo::kNoPosition) return; |
| 1191 source_position_table_builder_.AddStatementPosition( |
| 1192 static_cast<int>(bytecodes_.size()), stmt->position()); |
| 1193 } |
| 1194 |
| 1195 void BytecodeArrayBuilder::SetExpressionPosition(Expression* expr) { |
| 1196 if (expr->position() == RelocInfo::kNoPosition) return; |
| 1197 source_position_table_builder_.AddExpressionPosition( |
| 1198 static_cast<int>(bytecodes_.size()), expr->position()); |
| 1199 } |
| 1200 |
1185 bool BytecodeArrayBuilder::TemporaryRegisterIsLive(Register reg) const { | 1201 bool BytecodeArrayBuilder::TemporaryRegisterIsLive(Register reg) const { |
1186 return temporary_register_allocator()->RegisterIsLive(reg); | 1202 return temporary_register_allocator()->RegisterIsLive(reg); |
1187 } | 1203 } |
1188 | 1204 |
1189 bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index, | 1205 bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index, |
1190 uint32_t operand_value) const { | 1206 uint32_t operand_value) const { |
1191 OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index); | 1207 OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index); |
1192 switch (operand_type) { | 1208 switch (operand_type) { |
1193 case OperandType::kNone: | 1209 case OperandType::kNone: |
1194 return false; | 1210 return false; |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 } | 1665 } |
1650 | 1666 |
1651 // static | 1667 // static |
1652 bool BytecodeArrayBuilder::FitsInReg16OperandUntranslated(Register value) { | 1668 bool BytecodeArrayBuilder::FitsInReg16OperandUntranslated(Register value) { |
1653 return value.is_short_operand(); | 1669 return value.is_short_operand(); |
1654 } | 1670 } |
1655 | 1671 |
1656 } // namespace interpreter | 1672 } // namespace interpreter |
1657 } // namespace internal | 1673 } // namespace internal |
1658 } // namespace v8 | 1674 } // namespace v8 |
OLD | NEW |