OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/handler-table-builder.h" | 5 #include "src/interpreter/handler-table-builder.h" |
6 | 6 |
7 #include "src/factory.h" | 7 #include "src/factory.h" |
8 #include "src/interpreter/bytecode-register.h" | 8 #include "src/interpreter/bytecode-register.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 namespace interpreter { | 14 namespace interpreter { |
15 | 15 |
16 HandlerTableBuilder::HandlerTableBuilder(Isolate* isolate, Zone* zone) | 16 HandlerTableBuilder::HandlerTableBuilder(Isolate* isolate, Zone* zone) |
17 : isolate_(isolate), entries_(zone) {} | 17 : isolate_(isolate), entries_(zone) {} |
18 | 18 |
19 Handle<HandlerTable> HandlerTableBuilder::ToHandlerTable() { | 19 Handle<HandlerTable> HandlerTableBuilder::ToHandlerTable() { |
20 int handler_table_size = static_cast<int>(entries_.size()); | 20 int handler_table_size = static_cast<int>(entries_.size()); |
21 Handle<HandlerTable> table = | 21 Handle<HandlerTable> table = |
22 Handle<HandlerTable>::cast(isolate_->factory()->NewFixedArray( | 22 Handle<HandlerTable>::cast(isolate_->factory()->NewFixedArray( |
23 HandlerTable::LengthForRange(handler_table_size), TENURED)); | 23 HandlerTable::LengthForRange(handler_table_size), TENURED)); |
24 for (int i = 0; i < handler_table_size; ++i) { | 24 for (int i = 0; i < handler_table_size; ++i) { |
25 Entry& entry = entries_[i]; | 25 Entry& entry = entries_[i]; |
26 HandlerTable::CatchPrediction pred = | 26 HandlerTable::CatchPrediction pred = entry.catch_prediction_; |
27 entry.will_catch ? HandlerTable::CAUGHT : HandlerTable::UNCAUGHT; | |
28 table->SetRangeStart(i, static_cast<int>(entry.offset_start)); | 27 table->SetRangeStart(i, static_cast<int>(entry.offset_start)); |
29 table->SetRangeEnd(i, static_cast<int>(entry.offset_end)); | 28 table->SetRangeEnd(i, static_cast<int>(entry.offset_end)); |
30 table->SetRangeHandler(i, static_cast<int>(entry.offset_target), pred); | 29 table->SetRangeHandler(i, static_cast<int>(entry.offset_target), pred); |
31 table->SetRangeData(i, entry.context.index()); | 30 table->SetRangeData(i, entry.context.index()); |
32 } | 31 } |
33 return table; | 32 return table; |
34 } | 33 } |
35 | 34 |
36 | 35 |
37 int HandlerTableBuilder::NewHandlerEntry() { | 36 int HandlerTableBuilder::NewHandlerEntry() { |
38 int handler_id = static_cast<int>(entries_.size()); | 37 int handler_id = static_cast<int>(entries_.size()); |
39 Entry entry = {0, 0, 0, Register(), false}; | 38 Entry entry = {0, 0, 0, Register(), HandlerTable::UNCAUGHT}; |
40 entries_.push_back(entry); | 39 entries_.push_back(entry); |
41 return handler_id; | 40 return handler_id; |
42 } | 41 } |
43 | 42 |
44 | 43 |
45 void HandlerTableBuilder::SetTryRegionStart(int handler_id, size_t offset) { | 44 void HandlerTableBuilder::SetTryRegionStart(int handler_id, size_t offset) { |
46 DCHECK(Smi::IsValid(offset)); // Encoding of handler table requires this. | 45 DCHECK(Smi::IsValid(offset)); // Encoding of handler table requires this. |
47 entries_[handler_id].offset_start = offset; | 46 entries_[handler_id].offset_start = offset; |
48 } | 47 } |
49 | 48 |
50 | 49 |
51 void HandlerTableBuilder::SetTryRegionEnd(int handler_id, size_t offset) { | 50 void HandlerTableBuilder::SetTryRegionEnd(int handler_id, size_t offset) { |
52 DCHECK(Smi::IsValid(offset)); // Encoding of handler table requires this. | 51 DCHECK(Smi::IsValid(offset)); // Encoding of handler table requires this. |
53 entries_[handler_id].offset_end = offset; | 52 entries_[handler_id].offset_end = offset; |
54 } | 53 } |
55 | 54 |
56 | 55 |
57 void HandlerTableBuilder::SetHandlerTarget(int handler_id, size_t offset) { | 56 void HandlerTableBuilder::SetHandlerTarget(int handler_id, size_t offset) { |
58 DCHECK(Smi::IsValid(offset)); // Encoding of handler table requires this. | 57 DCHECK(Smi::IsValid(offset)); // Encoding of handler table requires this. |
59 entries_[handler_id].offset_target = offset; | 58 entries_[handler_id].offset_target = offset; |
60 } | 59 } |
61 | 60 |
62 | 61 void HandlerTableBuilder::SetPrediction( |
63 void HandlerTableBuilder::SetPrediction(int handler_id, bool will_catch) { | 62 int handler_id, HandlerTable::CatchPrediction prediction) { |
64 entries_[handler_id].will_catch = will_catch; | 63 entries_[handler_id].catch_prediction_ = prediction; |
65 } | 64 } |
66 | 65 |
67 | 66 |
68 void HandlerTableBuilder::SetContextRegister(int handler_id, Register reg) { | 67 void HandlerTableBuilder::SetContextRegister(int handler_id, Register reg) { |
69 entries_[handler_id].context = reg; | 68 entries_[handler_id].context = reg; |
70 } | 69 } |
71 | 70 |
72 } // namespace interpreter | 71 } // namespace interpreter |
73 } // namespace internal | 72 } // namespace internal |
74 } // namespace v8 | 73 } // namespace v8 |
OLD | NEW |