• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
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 
16 #include "mir_const.h"
17 #include "mir_function.h"
18 #include "global_tables.h"
19 #include "printing.h"
20 #include <iomanip>
21 
22 #include "gtest/gtest.h"
23 #include <iostream>
24 #include "mir_builder.h"
25 
26 using namespace maple;
27 namespace {
TEST(operator_EE_FUNC,t01)28 TEST(operator_EE_FUNC, t01)
29 { // MIRIntConst::operator==
30     MIRIntConst *mirConst_int_ptr1 = GlobalTables::GetIntConstTable().GetOrCreateIntConst(
31         1, *GlobalTables::GetTypeTable().GetInt64());
32     MIRIntConst *mirConst_int_ptr2 = GlobalTables::GetIntConstTable().GetOrCreateIntConst(
33         1, *GlobalTables::GetTypeTable().GetInt64());
34     MIRIntConst *mirConst_int_ptr3 = GlobalTables::GetIntConstTable().GetOrCreateIntConst(
35         2, *GlobalTables::GetTypeTable().GetInt64());
36     MIRDoubleConst *mirConst_double_ptr1 = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(1);
37     // GetKind() =  kConstDoubleConst (8)
38 
39     bool ans1, ans2, ans3, ans4;
40     ans1 = (*mirConst_int_ptr1 == *mirConst_int_ptr2);
41     ans2 = (*mirConst_int_ptr1 == *mirConst_int_ptr3);
42     ans3 = (*mirConst_int_ptr1 == *mirConst_int_ptr1);
43     ans4 = (*mirConst_int_ptr1 == *mirConst_double_ptr1);
44 
45     EXPECT_EQ(ans1, true);
46     EXPECT_EQ(ans2, false);
47     EXPECT_EQ(ans3, true);
48     EXPECT_EQ(ans4, false);
49 }
50 
TEST(operator_EE_FUNC,t03)51 TEST(operator_EE_FUNC, t03)
52 { // MIRAddrofConst::operator==  Incomplete!
53     MIRIntConst *mirConst_int_ptr1 = GlobalTables::GetIntConstTable().GetOrCreateIntConst(
54         0, *GlobalTables::GetTypeTable().GetInt64());
55     MIRDoubleConst *mirConst_double_ptr1 = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(1);
56     MIRAddrofConst *addrSymbol_1 = static_cast<MIRAddrofConst *>((MIRConst *)mirConst_int_ptr1);
57     MIRAddrofConst *addrSymbol_2 = static_cast<MIRAddrofConst *>((MIRConst *)mirConst_double_ptr1);
58     bool ans1 = (*addrSymbol_1 == *addrSymbol_1), ans2 = (*addrSymbol_1 == *addrSymbol_2);
59     EXPECT_EQ(ans1, true);
60     EXPECT_EQ(ans2, false);
61 }
62 
TEST(operator_EE_FUNC,t04)63 TEST(operator_EE_FUNC, t04)
64 { // MIRFloatConst::operator==
65     MIRFloatConst *mirConst_float_ptr1 = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(0.0);
66     MIRFloatConst *mirConst_float_ptr2 = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(0.0);
67     MIRFloatConst *mirConst_float_ptr3 = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(
68         std::numeric_limits<float>::quiet_NaN());
69     MIRFloatConst *mirConst_float_ptr4 = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(0.1);
70     MIRIntConst *mirConst_int_ptr1 = GlobalTables::GetIntConstTable().GetOrCreateIntConst(
71         1, *GlobalTables::GetTypeTable().GetInt64());
72 
73     bool ans1, ans2, ans3, ans4, ans5, ans6;
74     ans1 = (*mirConst_float_ptr1 == *mirConst_float_ptr1);
75     ans2 = (*mirConst_int_ptr1 == *mirConst_float_ptr1);
76     ans3 = (*mirConst_float_ptr1 == *mirConst_float_ptr3);
77     ans4 = (*mirConst_float_ptr3 == *mirConst_float_ptr1);
78     ans5 = (*mirConst_float_ptr1 == *mirConst_float_ptr2);
79     ans6 = (*mirConst_float_ptr1 == *mirConst_float_ptr4);
80 
81     EXPECT_EQ(ans1, true);
82     EXPECT_EQ(ans2, false);
83     EXPECT_EQ(ans3, false);
84     EXPECT_EQ(ans4, false);
85     EXPECT_EQ(ans5, true);
86     EXPECT_EQ(ans6, false);
87 }
88 
TEST(operator_EE_FUNC,t05)89 TEST(operator_EE_FUNC, t05)
90 { // MIRDoubleConst::operator==
91     MIRDoubleConst *mirConst_double_ptr1 = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(0.0);
92     MIRDoubleConst *mirConst_double_ptr2 = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(0.0);
93     MIRDoubleConst *mirConst_double_ptr3 = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(
94         std::numeric_limits<float>::quiet_NaN());
95     MIRDoubleConst *mirConst_double_ptr4 = GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(0.1);
96 
97     MIRFloatConst *mirConst_float_ptr1 = GlobalTables::GetFpConstTable().GetOrCreateFloatConst(0.0);
98 
99     bool ans1, ans2, ans3, ans4, ans5, ans6;
100     ans1 = (*mirConst_double_ptr1 == *mirConst_double_ptr1);
101     ans2 = (*mirConst_double_ptr1 == *mirConst_float_ptr1);
102     ans3 = (*mirConst_double_ptr1 == *mirConst_double_ptr3);
103     ans4 = (*mirConst_double_ptr3 == *mirConst_double_ptr1);
104     ans5 = (*mirConst_double_ptr1 == *mirConst_double_ptr2);
105     ans6 = (*mirConst_double_ptr1 == *mirConst_double_ptr4);
106     EXPECT_EQ(ans1, true);
107     EXPECT_EQ(ans2, false);
108     EXPECT_EQ(ans3, false);
109     EXPECT_EQ(ans4, false);
110     EXPECT_EQ(ans5, true);
111     EXPECT_EQ(ans6, false);
112 }
113 }  // namespace