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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 DISALLOW_COPY_AND_ASSIGN(PreviousBytecodeHelper); | 63 DISALLOW_COPY_AND_ASSIGN(PreviousBytecodeHelper); |
64 }; | 64 }; |
65 | 65 |
66 | 66 |
67 BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate, Zone* zone) | 67 BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate, Zone* zone) |
68 : isolate_(isolate), | 68 : isolate_(isolate), |
69 zone_(zone), | 69 zone_(zone), |
70 bytecodes_(zone), | 70 bytecodes_(zone), |
71 bytecode_generated_(false), | 71 bytecode_generated_(false), |
72 constant_array_builder_(isolate, zone), | 72 constant_array_builder_(isolate, zone), |
| 73 handler_table_builder_(isolate, zone), |
73 last_block_end_(0), | 74 last_block_end_(0), |
74 last_bytecode_start_(~0), | 75 last_bytecode_start_(~0), |
75 exit_seen_in_block_(false), | 76 exit_seen_in_block_(false), |
76 unbound_jumps_(0), | 77 unbound_jumps_(0), |
77 parameter_count_(-1), | 78 parameter_count_(-1), |
78 local_register_count_(-1), | 79 local_register_count_(-1), |
79 context_register_count_(-1), | 80 context_register_count_(-1), |
80 temporary_register_count_(0), | 81 temporary_register_count_(0), |
81 free_temporaries_(zone) {} | 82 free_temporaries_(zone) {} |
82 | 83 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { | 146 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() { |
146 DCHECK_EQ(bytecode_generated_, false); | 147 DCHECK_EQ(bytecode_generated_, false); |
147 EnsureReturn(); | 148 EnsureReturn(); |
148 | 149 |
149 int bytecode_size = static_cast<int>(bytecodes_.size()); | 150 int bytecode_size = static_cast<int>(bytecodes_.size()); |
150 int register_count = fixed_register_count() + temporary_register_count_; | 151 int register_count = fixed_register_count() + temporary_register_count_; |
151 int frame_size = register_count * kPointerSize; | 152 int frame_size = register_count * kPointerSize; |
152 Factory* factory = isolate_->factory(); | 153 Factory* factory = isolate_->factory(); |
153 Handle<FixedArray> constant_pool = | 154 Handle<FixedArray> constant_pool = |
154 constant_array_builder()->ToFixedArray(factory); | 155 constant_array_builder()->ToFixedArray(factory); |
| 156 Handle<FixedArray> handler_table = handler_table_builder()->ToHandlerTable(); |
155 Handle<BytecodeArray> output = | 157 Handle<BytecodeArray> output = |
156 factory->NewBytecodeArray(bytecode_size, &bytecodes_.front(), frame_size, | 158 factory->NewBytecodeArray(bytecode_size, &bytecodes_.front(), frame_size, |
157 parameter_count(), constant_pool); | 159 parameter_count(), constant_pool); |
| 160 output->set_handler_table(*handler_table); |
158 bytecode_generated_ = true; | 161 bytecode_generated_ = true; |
159 return output; | 162 return output; |
160 } | 163 } |
161 | 164 |
162 | 165 |
163 template <size_t N> | 166 template <size_t N> |
164 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t(&operands)[N]) { | 167 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t(&operands)[N]) { |
165 // Don't output dead code. | 168 // Don't output dead code. |
166 if (exit_seen_in_block_) return; | 169 if (exit_seen_in_block_) return; |
167 | 170 |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 return *this; | 1006 return *this; |
1004 } | 1007 } |
1005 | 1008 |
1006 | 1009 |
1007 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInStep(Register index) { | 1010 BytecodeArrayBuilder& BytecodeArrayBuilder::ForInStep(Register index) { |
1008 Output(Bytecode::kForInStep, index.ToRawOperand()); | 1011 Output(Bytecode::kForInStep, index.ToRawOperand()); |
1009 return *this; | 1012 return *this; |
1010 } | 1013 } |
1011 | 1014 |
1012 | 1015 |
| 1016 BytecodeArrayBuilder& BytecodeArrayBuilder::MarkHandler(int handler_id, |
| 1017 bool will_catch) { |
| 1018 handler_table_builder()->SetHandlerTarget(handler_id, bytecodes()->size()); |
| 1019 handler_table_builder()->SetPrediction(handler_id, will_catch); |
| 1020 return *this; |
| 1021 } |
| 1022 |
| 1023 |
| 1024 BytecodeArrayBuilder& BytecodeArrayBuilder::MarkTryBegin(int handler_id, |
| 1025 Register context) { |
| 1026 handler_table_builder()->SetTryRegionStart(handler_id, bytecodes()->size()); |
| 1027 handler_table_builder()->SetContextRegister(handler_id, context); |
| 1028 return *this; |
| 1029 } |
| 1030 |
| 1031 |
| 1032 BytecodeArrayBuilder& BytecodeArrayBuilder::MarkTryEnd(int handler_id) { |
| 1033 handler_table_builder()->SetTryRegionEnd(handler_id, bytecodes()->size()); |
| 1034 return *this; |
| 1035 } |
| 1036 |
| 1037 |
1013 void BytecodeArrayBuilder::LeaveBasicBlock() { | 1038 void BytecodeArrayBuilder::LeaveBasicBlock() { |
1014 last_block_end_ = bytecodes()->size(); | 1039 last_block_end_ = bytecodes()->size(); |
1015 exit_seen_in_block_ = false; | 1040 exit_seen_in_block_ = false; |
1016 } | 1041 } |
1017 | 1042 |
1018 | 1043 |
1019 void BytecodeArrayBuilder::EnsureReturn() { | 1044 void BytecodeArrayBuilder::EnsureReturn() { |
1020 if (!exit_seen_in_block_) { | 1045 if (!exit_seen_in_block_) { |
1021 LoadUndefined(); | 1046 LoadUndefined(); |
1022 Return(); | 1047 Return(); |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 | 1680 |
1656 | 1681 |
1657 // static | 1682 // static |
1658 bool BytecodeArrayBuilder::FitsInReg16Operand(Register value) { | 1683 bool BytecodeArrayBuilder::FitsInReg16Operand(Register value) { |
1659 return kMinInt16 <= value.index() && value.index() <= kMaxInt16; | 1684 return kMinInt16 <= value.index() && value.index() <= kMaxInt16; |
1660 } | 1685 } |
1661 | 1686 |
1662 } // namespace interpreter | 1687 } // namespace interpreter |
1663 } // namespace internal | 1688 } // namespace internal |
1664 } // namespace v8 | 1689 } // namespace v8 |
OLD | NEW |