| 1 | // Copyright (c) 2020, 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_COMPILER_FFI_FRAME_REBASE_H_ |
| 6 | #define RUNTIME_VM_COMPILER_FFI_FRAME_REBASE_H_ |
| 7 | |
| 8 | #if defined(DART_PRECOMPILED_RUNTIME) |
| 9 | #error "AOT runtime should not use compiler sources (including header files)" |
| 10 | #endif // defined(DART_PRECOMPILED_RUNTIME) |
| 11 | |
| 12 | #include "vm/compiler/backend/locations.h" |
| 13 | #include "vm/compiler/ffi/native_location.h" |
| 14 | #include "vm/compiler/ffi/native_type.h" |
| 15 | #include "vm/compiler/runtime_api.h" |
| 16 | #include "vm/thread.h" |
| 17 | |
| 18 | namespace dart { |
| 19 | |
| 20 | namespace compiler { |
| 21 | |
| 22 | namespace ffi { |
| 23 | |
| 24 | // Describes a change of stack frame where the stack or base register or stack |
| 25 | // offset may change. This class allows easily rebasing stack locations across |
| 26 | // frame manipulations. |
| 27 | // |
| 28 | // If the stack offset register matches 'old_base', it is changed to 'new_base' |
| 29 | // and 'stack_delta_in_bytes' (# of bytes) is applied. |
| 30 | // |
| 31 | // This class can be used to rebase both Locations and NativeLocations. |
| 32 | class FrameRebase : public ValueObject { |
| 33 | public: |
| 34 | FrameRebase(const Register old_base, |
| 35 | const Register new_base, |
| 36 | intptr_t stack_delta_in_bytes, |
| 37 | Zone* zone) |
| 38 | : old_base_(old_base), |
| 39 | new_base_(new_base), |
| 40 | stack_delta_in_bytes_(stack_delta_in_bytes), |
| 41 | zone_(zone) {} |
| 42 | |
| 43 | const NativeLocation& Rebase(const NativeLocation& loc) const; |
| 44 | |
| 45 | Location Rebase(const Location loc) const; |
| 46 | |
| 47 | private: |
| 48 | const Register old_base_; |
| 49 | const Register new_base_; |
| 50 | const intptr_t stack_delta_in_bytes_; |
| 51 | Zone* zone_; |
| 52 | }; |
| 53 | |
| 54 | } // namespace ffi |
| 55 | |
| 56 | } // namespace compiler |
| 57 | |
| 58 | } // namespace dart |
| 59 | |
| 60 | #endif // RUNTIME_VM_COMPILER_FFI_FRAME_REBASE_H_ |
| 61 | |