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