Flutter Engine
The Flutter Engine
native_location_test.cc
Go to the documentation of this file.
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
6
8
9namespace dart {
10namespace compiler {
11namespace ffi {
12
14 const auto& native_type = *new (Z) NativePrimitiveType(kInt8);
15
16 const int kUnalignedStackLocation = 17;
17
18 const auto& native_location = *new (Z) NativeStackLocation(
19 native_type, native_type, SPREG, kUnalignedStackLocation);
20
21 EXPECT_EQ(kUnalignedStackLocation + native_type.SizeInBytes(),
22 native_location.StackTopInBytes());
23}
24
25UNIT_TEST_CASE_WITH_ZONE(NativeStackLocation_Split) {
26 const auto& native_type = *new (Z) NativePrimitiveType(kInt64);
27
28 const auto& native_location =
29 *new (Z) NativeStackLocation(native_type, native_type, SPREG, 0);
30
31 const auto& half_0 = native_location.Split(Z, 2, 0);
32 const auto& half_1 = native_location.Split(Z, 2, 1);
33
34 EXPECT_EQ(0, half_0.offset_in_bytes());
35 EXPECT_EQ(4, half_1.offset_in_bytes());
36}
37
38// Regression test for NativeFpuRegistersLocation::Equals not considering kind
39// when comparing.
40UNIT_TEST_CASE_WITH_ZONE(NativeStackLocation_Equals) {
41 const auto& native_type = *new (Z) NativePrimitiveType(kInt8);
42
43 // Two FPU registers of the same kind and number are equal.
44 {
45 const auto& native_location1 = *new (Z) NativeFpuRegistersLocation(
46 native_type, native_type, kQuadFpuReg,
47 /*fpu_register=*/0);
48
49 const auto& native_location2 = *new (Z) NativeFpuRegistersLocation(
50 native_type, native_type, kQuadFpuReg,
51 /*fpu_register=*/0);
52
53 EXPECT(native_location1.Equals(native_location2));
54 }
55
56 // Two FPU registers with different numbers are NOT equal.
57 {
58 const auto& native_location1 = *new (Z) NativeFpuRegistersLocation(
59 native_type, native_type, kQuadFpuReg,
60 /*fpu_register=*/2);
61
62 const auto& native_location2 = *new (Z) NativeFpuRegistersLocation(
63 native_type, native_type, kQuadFpuReg,
64 /*fpu_register=*/4);
65
66 EXPECT(!native_location1.Equals(native_location2));
67 }
68
69 // Two FPU registers with different kinds are NOT equal.
70 {
71 const auto& native_location1 = *new (Z) NativeFpuRegistersLocation(
72 native_type, native_type, kQuadFpuReg,
73 /*fpu_register=*/3);
74
75 const auto& native_location2 = *new (Z) NativeFpuRegistersLocation(
76 native_type, native_type, kDoubleFpuReg,
77 /*fpu_register=*/3);
78
79 EXPECT(!native_location1.Equals(native_location2));
80 }
81}
82
83} // namespace ffi
84} // namespace compiler
85} // namespace dart
#define EXPECT(type, expectedAlignment, expectedSize)
#define Z
virtual NativeStackLocation & Split(Zone *zone, intptr_t num_parts, intptr_t index) const
UNIT_TEST_CASE_WITH_ZONE(NativeCallingConvention_int8x10)
Definition: dart_vm.cc:33
const Register SPREG