handler-table-builder.h 2.22 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_INTERPRETER_HANDLER_TABLE_BUILDER_H_
#define V8_INTERPRETER_HANDLER_TABLE_BUILDER_H_

8
#include "src/frames.h"
9
#include "src/interpreter/bytecode-register.h"
10
#include "src/interpreter/bytecodes.h"
11
#include "src/zone/zone-containers.h"
12 13 14 15

namespace v8 {
namespace internal {

marja's avatar
marja committed
16 17
template <typename T>
class Handle;
18 19 20 21 22 23
class HandlerTable;
class Isolate;

namespace interpreter {

// A helper class for constructing exception handler tables for the interpreter.
24
class V8_EXPORT_PRIVATE HandlerTableBuilder final {
25
 public:
26
  explicit HandlerTableBuilder(Zone* zone);
27 28 29

  // Builds the actual handler table by copying the current values into a heap
  // object. Any further mutations to the builder won't be reflected.
30
  Handle<ByteArray> ToHandlerTable(Isolate* isolate);
31 32 33 34 35 36 37 38 39 40 41

  // Creates a new handler table entry and returns a {hander_id} identifying the
  // entry, so that it can be referenced by below setter functions.
  int NewHandlerEntry();

  // Setter functions that modify certain values within the handler table entry
  // being referenced by the given {handler_id}. All values will be encoded by
  // the resulting {HandlerTable} class when copied into the heap.
  void SetTryRegionStart(int handler_id, size_t offset);
  void SetTryRegionEnd(int handler_id, size_t offset);
  void SetHandlerTarget(int handler_id, size_t offset);
42
  void SetPrediction(int handler_id, HandlerTable::CatchPrediction prediction);
43 44 45 46 47 48 49 50
  void SetContextRegister(int handler_id, Register reg);

 private:
  struct Entry {
    size_t offset_start;   // Bytecode offset starting try-region.
    size_t offset_end;     // Bytecode offset ending try-region.
    size_t offset_target;  // Bytecode offset of handler target.
    Register context;      // Register holding context for handler.
51 52
                           // Optimistic prediction for handler.
    HandlerTable::CatchPrediction catch_prediction_;
53 54 55 56 57 58 59 60 61 62 63 64
  };

  ZoneVector<Entry> entries_;

  DISALLOW_COPY_AND_ASSIGN(HandlerTableBuilder);
};

}  // namespace interpreter
}  // namespace internal
}  // namespace v8

#endif  // V8_INTERPRETER_HANDLER_TABLE_BUILDER_H_