blob: 7356e37767d12c5682a3023c3b8040ecfd2df0fe [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001// 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#ifndef V8_INTERPRETER_HANDLER_TABLE_BUILDER_H_
6#define V8_INTERPRETER_HANDLER_TABLE_BUILDER_H_
7
8#include "src/handles.h"
9#include "src/interpreter/bytecodes.h"
10#include "src/zone-containers.h"
11
12namespace v8 {
13namespace internal {
14
15class HandlerTable;
16class Isolate;
17
18namespace interpreter {
19
20// A helper class for constructing exception handler tables for the interpreter.
21class HandlerTableBuilder final BASE_EMBEDDED {
22 public:
23 HandlerTableBuilder(Isolate* isolate, Zone* zone);
24
25 // Builds the actual handler table by copying the current values into a heap
26 // object. Any further mutations to the builder won't be reflected.
27 Handle<HandlerTable> ToHandlerTable();
28
29 // Creates a new handler table entry and returns a {hander_id} identifying the
30 // entry, so that it can be referenced by below setter functions.
31 int NewHandlerEntry();
32
33 // Setter functions that modify certain values within the handler table entry
34 // being referenced by the given {handler_id}. All values will be encoded by
35 // the resulting {HandlerTable} class when copied into the heap.
36 void SetTryRegionStart(int handler_id, size_t offset);
37 void SetTryRegionEnd(int handler_id, size_t offset);
38 void SetHandlerTarget(int handler_id, size_t offset);
39 void SetPrediction(int handler_id, bool will_catch);
40 void SetContextRegister(int handler_id, Register reg);
41
42 private:
43 struct Entry {
44 size_t offset_start; // Bytecode offset starting try-region.
45 size_t offset_end; // Bytecode offset ending try-region.
46 size_t offset_target; // Bytecode offset of handler target.
47 Register context; // Register holding context for handler.
48 bool will_catch; // Optimistic prediction for handler.
49 };
50
51 Isolate* isolate_;
52 ZoneVector<Entry> entries_;
53
54 DISALLOW_COPY_AND_ASSIGN(HandlerTableBuilder);
55};
56
57} // namespace interpreter
58} // namespace internal
59} // namespace v8
60
61#endif // V8_INTERPRETER_HANDLER_TABLE_BUILDER_H_