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#include "vm/compiler/ffi/frame_rebase.h"
6
7namespace dart {
8
9namespace compiler {
10
11namespace ffi {
12
13const NativeLocation& FrameRebase::Rebase(const NativeLocation& loc) const {
14 if (!loc.IsStack() || loc.AsStack().base_register() != old_base_) {
15 return loc;
16 }
17
18 return *new (zone_) NativeStackLocation(
19 loc.payload_type(), loc.container_type(), new_base_,
20 loc.AsStack().offset_in_bytes() + stack_delta_in_bytes_);
21}
22
23Location FrameRebase::Rebase(const Location loc) const {
24 if (loc.IsPairLocation()) {
25 return Location::Pair(Rebase(loc.Component(0)), Rebase(loc.Component(1)));
26 }
27 if (!loc.HasStackIndex() || loc.base_reg() != old_base_) {
28 return loc;
29 }
30
31 const intptr_t new_stack_index =
32 loc.stack_index() + stack_delta_in_bytes_ / compiler::target::kWordSize;
33 if (loc.IsStackSlot()) {
34 return Location::StackSlot(new_stack_index, new_base_);
35 }
36 if (loc.IsDoubleStackSlot()) {
37 return Location::DoubleStackSlot(new_stack_index, new_base_);
38 }
39 ASSERT(loc.IsQuadStackSlot());
40 return Location::QuadStackSlot(new_stack_index, new_base_);
41}
42
43} // namespace ffi
44
45} // namespace compiler
46
47} // namespace dart
48