• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
GetInfoForInteropCallArgsConversion(MethodPtr methodPtr,ArenaVector<std::pair<IntrinsicId,compiler::DataType::Type>> * intrinsics)16 void GetInfoForInteropCallArgsConversion(
17     MethodPtr methodPtr, ArenaVector<std::pair<IntrinsicId, compiler::DataType::Type>> *intrinsics) const override
18 {
19     auto method = MethodCast(methodPtr);
20     uint32_t numArgs = method->GetNumArgs() - 2U;
21     panda_file::ShortyIterator it(method->GetShorty());
22     it.IncrementWithoutCheck();
23     it.IncrementWithoutCheck();
24     it.IncrementWithoutCheck();
25     for (uint32_t argIdx = 0; argIdx < numArgs; ++argIdx, it.IncrementWithoutCheck()) {
26         auto type = *it;
27         std::pair<IntrinsicId, compiler::DataType::Type> pair = {};
28         switch (type.GetId()) {
29             case panda_file::Type::TypeId::VOID:
30                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_VOID_TO_LOCAL, compiler::DataType::NO_TYPE};
31                 break;
32             case panda_file::Type::TypeId::U1:
33                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_U1_TO_LOCAL, compiler::DataType::BOOL};
34                 break;
35             case panda_file::Type::TypeId::I8:
36                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_I8_TO_LOCAL, compiler::DataType::INT8};
37                 break;
38             case panda_file::Type::TypeId::U8:
39                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_U8_TO_LOCAL, compiler::DataType::UINT8};
40                 break;
41             case panda_file::Type::TypeId::I16:
42                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_I16_TO_LOCAL, compiler::DataType::INT16};
43                 break;
44             case panda_file::Type::TypeId::U16:
45                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_U16_TO_LOCAL, compiler::DataType::UINT16};
46                 break;
47             case panda_file::Type::TypeId::I32:
48                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_I32_TO_LOCAL, compiler::DataType::INT32};
49                 break;
50             case panda_file::Type::TypeId::U32:
51                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_U32_TO_LOCAL, compiler::DataType::UINT32};
52                 break;
53             case panda_file::Type::TypeId::I64:
54                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_I64_TO_LOCAL, compiler::DataType::INT64};
55                 break;
56             case panda_file::Type::TypeId::U64:
57                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_U64_TO_LOCAL, compiler::DataType::UINT64};
58                 break;
59             case panda_file::Type::TypeId::F32:
60                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_F32_TO_LOCAL, compiler::DataType::FLOAT32};
61                 break;
62             case panda_file::Type::TypeId::F64:
63                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_F64_TO_LOCAL, compiler::DataType::FLOAT64};
64                 break;
65             case panda_file::Type::TypeId::REFERENCE:
66                 pair = {IntrinsicId::INTRINSIC_COMPILER_CONVERT_REF_TYPE_TO_LOCAL, compiler::DataType::REFERENCE};
67                 break;
68             default: {
69                 UNREACHABLE();
70             }
71         }
72         intrinsics->push_back(pair);
73     }
74 }
75 
76 std::optional<std::pair<compiler::RuntimeInterface::IntrinsicId, compiler::DataType::Type>>
GetInfoForInteropCallRetValueConversion(MethodPtr methodPtr)77 GetInfoForInteropCallRetValueConversion(MethodPtr methodPtr) const override
78 {
79     auto method = MethodCast(methodPtr);
80     auto type = method->GetReturnType();
81     switch (type.GetId()) {
82         case panda_file::Type::TypeId::VOID:
83             return {};
84         case panda_file::Type::TypeId::U1:
85             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_U1, compiler::DataType::BOOL}};
86         case panda_file::Type::TypeId::I8:
87             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_I8, compiler::DataType::INT8}};
88         case panda_file::Type::TypeId::U8:
89             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_U8, compiler::DataType::UINT8}};
90         case panda_file::Type::TypeId::I16:
91             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_I16, compiler::DataType::INT16}};
92         case panda_file::Type::TypeId::U16:
93             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_U16, compiler::DataType::UINT16}};
94         case panda_file::Type::TypeId::I32:
95             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_I32, compiler::DataType::INT32}};
96         case panda_file::Type::TypeId::U32:
97             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_U32, compiler::DataType::UINT32}};
98         case panda_file::Type::TypeId::I64:
99             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_I64, compiler::DataType::INT64}};
100         case panda_file::Type::TypeId::U64:
101             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_U64, compiler::DataType::UINT64}};
102         case panda_file::Type::TypeId::F32:
103             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_F32, compiler::DataType::FLOAT32}};
104         case panda_file::Type::TypeId::F64:
105             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_F64, compiler::DataType::FLOAT64}};
106         case panda_file::Type::TypeId::REFERENCE: {
107             auto vm = reinterpret_cast<PandaEtsVM *>(Thread::GetCurrent()->GetVM());
108             auto classLinker = vm->GetClassLinker();
109             auto klass = GetClass(method, GetMethodReturnTypeId(method));
110             // start fastpath
111             if (klass ==
112                 classLinker->GetClass(panda_file_items::class_descriptors::JS_VALUE.data())->GetRuntimeClass()) {
113                 return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_JS_VALUE, compiler::DataType::REFERENCE}};
114             }
115             if (klass == classLinker->GetClass(panda_file_items::class_descriptors::STRING.data())->GetRuntimeClass()) {
116                 return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_STRING, compiler::DataType::REFERENCE}};
117             }
118             return {{IntrinsicId::INTRINSIC_COMPILER_CONVERT_LOCAL_TO_REF_TYPE, compiler::DataType::REFERENCE}};
119         }
120         default: {
121             UNREACHABLE();
122         }
123     }
124     return {};
125 }
126