1 : // Copyright 2013 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/assm/register.h"
16 :
17 : #include "gtest/gtest.h"
18 :
19 : namespace assm {
20 :
21 E : TEST(RegisterTest, AllViewsOccupySameMemory) {
22 : // We expect the by-type arrays to be slices of the full register array.
23 E : EXPECT_EQ(reinterpret_cast<const Register*>(&kRegisters8[0]),
24 E : &kRegisters[kRegister8Min]);
25 E : EXPECT_EQ(reinterpret_cast<const Register*>(&kRegisters16[0]),
26 E : &kRegisters[kRegister16Min]);
27 E : EXPECT_EQ(reinterpret_cast<const Register*>(&kRegisters32[0]),
28 E : &kRegisters[kRegister32Min]);
29 :
30 : // We expect the individual registers to be members of the full register
31 : // array.
32 E : EXPECT_EQ(reinterpret_cast<const Register*>(&al), &kRegisters[kRegisterAl]);
33 E : EXPECT_EQ(reinterpret_cast<const Register*>(&ch), &kRegisters[kRegisterCh]);
34 :
35 E : EXPECT_EQ(reinterpret_cast<const Register*>(&dx), &kRegisters[kRegisterDx]);
36 E : EXPECT_EQ(reinterpret_cast<const Register*>(&sp), &kRegisters[kRegisterSp]);
37 :
38 E : EXPECT_EQ(reinterpret_cast<const Register*>(&ebx), &kRegisters[kRegisterEbx]);
39 E : EXPECT_EQ(reinterpret_cast<const Register*>(&ebp), &kRegisters[kRegisterEbp]);
40 E : }
41 :
42 E : TEST(RegisterTest, Accessors) {
43 E : EXPECT_EQ(kRegisterEax, eax.id());
44 E : EXPECT_EQ(kSize32Bit, eax.size());
45 E : EXPECT_EQ(0, eax.code());
46 E : }
47 :
48 E : TEST(RegisterTest, Get) {
49 E : EXPECT_EQ(reinterpret_cast<const Register*>(&ch),
50 E : &Register::Get(kRegisterCh));
51 E : EXPECT_EQ(reinterpret_cast<const Register*>(&bx),
52 E : &Register::Get(kRegisterBx));
53 E : EXPECT_EQ(reinterpret_cast<const Register*>(&eax),
54 E : &Register::Get(kRegisterEax));
55 E : }
56 :
57 E : TEST(RegisterTest, Comparison) {
58 E : EXPECT_TRUE(dh == dh);
59 E : EXPECT_TRUE(sp == sp);
60 E : EXPECT_TRUE(eax == eax);
61 :
62 E : EXPECT_FALSE(al == ax);
63 E : EXPECT_FALSE(al == eax);
64 E : EXPECT_FALSE(ax == eax);
65 :
66 E : EXPECT_TRUE(al != ax);
67 E : EXPECT_TRUE(al != eax);
68 E : EXPECT_TRUE(ax != eax);
69 :
70 E : EXPECT_FALSE(dh != dh);
71 E : EXPECT_FALSE(sp != sp);
72 E : EXPECT_FALSE(eax != eax);
73 E : }
74 :
75 : } // namespace assm
|