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 "intrinsics.h"
17 #include "mir_builder.h"
18
19 namespace maple {
20 MIRType *IntrinDesc::jsValueType = nullptr;
21 MIRModule *IntrinDesc::mirModule = nullptr;
22 IntrinDesc IntrinDesc::intrinTable[INTRN_LAST + 1] = {
23 #define DEF_MIR_INTRINSIC(X, NAME, RETURN_TYPE, ...) \
24 {(NAME), {(RETURN_TYPE), ##__VA_ARGS__}},
25 #include "intrinsics.def"
26 #undef DEF_MIR_INTRINSIC
27 };
28
InitMIRModule(MIRModule * mod)29 void IntrinDesc::InitMIRModule(MIRModule *mod)
30 {
31 mirModule = mod;
32 }
33
GetTypeFromArgTy(IntrinArgType argType) const34 MIRType *IntrinDesc::GetTypeFromArgTy(IntrinArgType argType) const
35 {
36 switch (argType) {
37 case kArgTyVoid:
38 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_void));
39 case kArgTyI8:
40 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_i8));
41 case kArgTyI16:
42 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_i16));
43 case kArgTyI32:
44 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_i32));
45 case kArgTyI64:
46 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_i64));
47 case kArgTyU8:
48 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_u8));
49 case kArgTyU16:
50 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_u16));
51 case kArgTyU32:
52 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_u32));
53 case kArgTyU64:
54 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_u64));
55 case kArgTyU1:
56 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_u1));
57 case kArgTyPtr:
58 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_ptr));
59 case kArgTyRef:
60 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_ref));
61 case kArgTyA64:
62 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_a64));
63 case kArgTyF32:
64 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_f32));
65 case kArgTyF64:
66 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_f64));
67 case kArgTyDynany:
68 return GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast<TyIdx>(PTY_dynany));
69 default:
70 return nullptr;
71 }
72 }
73
GetArgType(uint32 index) const74 MIRType *IntrinDesc::GetArgType(uint32 index) const
75 {
76 // 0 is the arg of return type
77 CHECK_FATAL(index < kMaxArgsNum, "index out of range");
78 return GetTypeFromArgTy(argTypes[index + 1]);
79 }
80
GetReturnType() const81 MIRType *IntrinDesc::GetReturnType() const
82 {
83 return GetTypeFromArgTy(argTypes[0]);
84 }
85 } // namespace maple
86