| 1 | // Copyright (c) 2019, the Dart project authors.  Please see the AUTHORS file | 
|---|
| 2 | // for details. All rights reserved. Use of this source code is governed by a | 
|---|
| 3 | // BSD-style license that can be found in the LICENSE file. | 
|---|
| 4 |  | 
|---|
| 5 | #ifndef RUNTIME_VM_FRAME_LAYOUT_H_ | 
|---|
| 6 | #define RUNTIME_VM_FRAME_LAYOUT_H_ | 
|---|
| 7 |  | 
|---|
| 8 | #include "platform/assert.h" | 
|---|
| 9 | #include "platform/globals.h" | 
|---|
| 10 |  | 
|---|
| 11 | // FrameLayout structure captures configuration specific properties of the | 
|---|
| 12 | // frame layout used by the runtime system and compiler. | 
|---|
| 13 | // | 
|---|
| 14 | // Runtime system uses runtime_frame_layout defined in stack_frame.h. | 
|---|
| 15 | // Compiler uses compiler::target::frame_layout defined in runtime_api.h | 
|---|
| 16 |  | 
|---|
| 17 | namespace dart { | 
|---|
| 18 |  | 
|---|
| 19 | // Forward declarations. | 
|---|
| 20 | class LocalVariable; | 
|---|
| 21 |  | 
|---|
| 22 | struct FrameLayout { | 
|---|
| 23 | // The offset (in words) from FP to the first object. | 
|---|
| 24 | int first_object_from_fp; | 
|---|
| 25 |  | 
|---|
| 26 | // The offset (in words) from FP to the last fixed object. | 
|---|
| 27 | int last_fixed_object_from_fp; | 
|---|
| 28 |  | 
|---|
| 29 | // The offset (in words) from FP to the slot past the last parameter. | 
|---|
| 30 | int param_end_from_fp; | 
|---|
| 31 |  | 
|---|
| 32 | // The offset (in words) from SP on entry (before frame is setup) to | 
|---|
| 33 | // the last parameter. | 
|---|
| 34 | int last_param_from_entry_sp; | 
|---|
| 35 |  | 
|---|
| 36 | // The offset (in words) from FP to the first local. | 
|---|
| 37 | int first_local_from_fp; | 
|---|
| 38 |  | 
|---|
| 39 | // The fixed size of the frame. | 
|---|
| 40 | int dart_fixed_frame_size; | 
|---|
| 41 |  | 
|---|
| 42 | // The offset (in words) from FP to the saved pool (if applicable). | 
|---|
| 43 | int saved_caller_pp_from_fp; | 
|---|
| 44 |  | 
|---|
| 45 | // The offset (in words) from FP to the code object (if applicable). | 
|---|
| 46 | int code_from_fp; | 
|---|
| 47 |  | 
|---|
| 48 | // Entry and exit frame layout. | 
|---|
| 49 | int exit_link_slot_from_entry_fp; | 
|---|
| 50 |  | 
|---|
| 51 | // The number of fixed slots below the saved PC. | 
|---|
| 52 | int saved_below_pc() const { return -first_local_from_fp; } | 
|---|
| 53 |  | 
|---|
| 54 | // Returns the FP-relative index where [variable] can be found (assumes | 
|---|
| 55 | // [variable] is not captured), in words. | 
|---|
| 56 | int FrameSlotForVariable(const LocalVariable* variable) const; | 
|---|
| 57 |  | 
|---|
| 58 | // Returns the FP-relative index where [variable_index] can be found (assumes | 
|---|
| 59 | // [variable_index] comes from a [LocalVariable::index()], which is not | 
|---|
| 60 | // captured). | 
|---|
| 61 | int FrameSlotForVariableIndex(int index) const; | 
|---|
| 62 |  | 
|---|
| 63 | // Returns the variable index from a FP-relative index. | 
|---|
| 64 | intptr_t VariableIndexForFrameSlot(intptr_t frame_slot) const { | 
|---|
| 65 | if (frame_slot <= first_local_from_fp) { | 
|---|
| 66 | return frame_slot - first_local_from_fp; | 
|---|
| 67 | } else { | 
|---|
| 68 | ASSERT(frame_slot > param_end_from_fp); | 
|---|
| 69 | return frame_slot - param_end_from_fp; | 
|---|
| 70 | } | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | // Called to initialize the stack frame layout during startup. | 
|---|
| 74 | static void Init(); | 
|---|
| 75 | }; | 
|---|
| 76 |  | 
|---|
| 77 | }  // namespace dart | 
|---|
| 78 |  | 
|---|
| 79 | #endif  // RUNTIME_VM_FRAME_LAYOUT_H_ | 
|---|
| 80 |  | 
|---|