1 /**
2 * Copyright (c) 2021-2022 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 "unit_test.h"
17
18 namespace panda::compiler {
19 class CallInputTypesTest : public AsmTest {
20 public:
GetCallInstruction(Graph * graph) const21 const auto *GetCallInstruction(Graph *graph) const
22 {
23 for (const auto *bb : graph->GetBlocksRPO()) {
24 for (const auto *inst : bb->Insts()) {
25 if (inst->IsCall()) {
26 return inst;
27 }
28 }
29 }
30 UNREACHABLE();
31 }
32 };
33
34 // Checks the build of the static call instruction
TEST_F(CallInputTypesTest,CallStatic)35 TEST_F(CallInputTypesTest, CallStatic)
36 {
37 auto source = R"(
38 .function i64 main() {
39 movi.64 v0, 1
40 movi.64 v1, 2
41 call foo, v0, v1
42 return
43 }
44 .function i64 foo(i32 a0, f64 a1) {
45 ldai 0
46 return
47 }
48 )";
49 ASSERT_TRUE(ParseToGraph(source, "main"));
50 auto call_inst = GetCallInstruction(GetGraph());
51 ASSERT_EQ(call_inst->GetInputType(0), DataType::INT32);
52 ASSERT_EQ(call_inst->GetInputType(1), DataType::FLOAT64);
53 ASSERT_EQ(call_inst->GetInputType(2), DataType::NO_TYPE); // SaveState instruction
54 }
55
56 // Checks the build of a call of a function without arguments
TEST_F(CallInputTypesTest,NoArgs)57 TEST_F(CallInputTypesTest, NoArgs)
58 {
59 auto source = R"(
60 .function i64 main() {
61 movi.64 v0, 1
62 movi.64 v1, 2
63 call foo
64 return
65 }
66 .function i64 foo() {
67 ldai 0
68 return
69 }
70 )";
71 ASSERT_TRUE(ParseToGraph(source, "main"));
72 auto call_inst = GetCallInstruction(GetGraph());
73 ASSERT_EQ(call_inst->GetInputType(0), DataType::NO_TYPE); // SaveState instruction
74 }
75 } // namespace panda::compiler
76