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