5 #include "src/interpreter/handler-table-builder.h" 7 #include "src/heap/factory.h" 8 #include "src/interpreter/bytecode-register.h" 9 #include "src/isolate.h" 10 #include "src/objects-inl.h" 14 namespace interpreter {
16 HandlerTableBuilder::HandlerTableBuilder(Zone* zone) : entries_(zone) {}
18 Handle<ByteArray> HandlerTableBuilder::ToHandlerTable(Isolate* isolate) {
19 int handler_table_size =
static_cast<int>(entries_.size());
20 Handle<ByteArray> table_byte_array = isolate->factory()->NewByteArray(
21 HandlerTable::LengthForRange(handler_table_size), TENURED);
22 HandlerTable table(*table_byte_array);
23 for (
int i = 0;
i < handler_table_size; ++
i) {
24 Entry& entry = entries_[
i];
25 HandlerTable::CatchPrediction pred = entry.catch_prediction_;
26 table.SetRangeStart(
i, static_cast<int>(entry.offset_start));
27 table.SetRangeEnd(
i, static_cast<int>(entry.offset_end));
28 table.SetRangeHandler(
i, static_cast<int>(entry.offset_target), pred);
29 table.SetRangeData(
i, entry.context.index());
31 return table_byte_array;
35 int HandlerTableBuilder::NewHandlerEntry() {
36 int handler_id =
static_cast<int>(entries_.size());
37 Entry entry = {0, 0, 0, Register::invalid_value(), HandlerTable::UNCAUGHT};
38 entries_.push_back(entry);
43 void HandlerTableBuilder::SetTryRegionStart(
int handler_id,
size_t offset) {
44 DCHECK(Smi::IsValid(offset));
45 entries_[handler_id].offset_start = offset;
49 void HandlerTableBuilder::SetTryRegionEnd(
int handler_id,
size_t offset) {
50 DCHECK(Smi::IsValid(offset));
51 entries_[handler_id].offset_end = offset;
55 void HandlerTableBuilder::SetHandlerTarget(
int handler_id,
size_t offset) {
56 DCHECK(Smi::IsValid(offset));
57 entries_[handler_id].offset_target = offset;
60 void HandlerTableBuilder::SetPrediction(
61 int handler_id, HandlerTable::CatchPrediction prediction) {
62 entries_[handler_id].catch_prediction_ = prediction;
66 void HandlerTableBuilder::SetContextRegister(
int handler_id, Register reg) {
67 entries_[handler_id].context = reg;