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