• 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 <safe_cast.h>
17#include "opcode_info.h"
18
19namespace maple {
20#ifdef LOAD_SAFE_CAST_FOR_MIR_CONST
21#undef LOAD_SAFE_CAST_FOR_MIR_CONST
22REGISTER_SAFE_CAST(MIRIntConst, from.GetKind() == kConstInt);
23REGISTER_SAFE_CAST(MIRAddrofConst, from.GetKind() == kConstAddrof);
24REGISTER_SAFE_CAST(MIRAddroffuncConst, from.GetKind() == kConstAddrofFunc);
25REGISTER_SAFE_CAST(MIRLblConst, from.GetKind() == kConstLblConst);
26REGISTER_SAFE_CAST(MIRStrConst, from.GetKind() == kConstStrConst);
27REGISTER_SAFE_CAST(MIRStr16Const, from.GetKind() == kConstStr16Const);
28REGISTER_SAFE_CAST(MIRFloatConst, from.GetKind() == kConstFloatConst);
29REGISTER_SAFE_CAST(MIRDoubleConst, from.GetKind() == kConstDoubleConst);
30REGISTER_SAFE_CAST(MIRAggConst, from.GetKind() == kConstAggConst);
31REGISTER_SAFE_CAST(MIRStConst, from.GetKind() == kConstStConst);
32#endif
33
34#ifdef LOAD_SAFE_CAST_FOR_MIR_TYPE
35#undef LOAD_SAFE_CAST_FOR_MIR_TYPE
36REGISTER_SAFE_CAST(MIRPtrType, from.GetKind() == kTypePointer);
37REGISTER_SAFE_CAST(MIRArrayType, from.GetKind() == kTypeArray);
38REGISTER_SAFE_CAST(MIRFuncType, from.GetKind() == kTypeFunction);
39REGISTER_SAFE_CAST(MIRTypeByName, from.GetKind() == kTypeByName);
40#endif
41
42#ifdef LOAD_SAFE_CAST_FOR_MIR_NODE
43#undef LOAD_SAFE_CAST_FOR_MIR_NODE
44REGISTER_SAFE_CAST(UnaryNode, from.GetOpCode() == OP_abs ||
45                              from.GetOpCode() == OP_bnot ||
46                              from.GetOpCode() == OP_lnot ||
47                              from.GetOpCode() == OP_neg ||
48                              from.GetOpCode() == OP_sqrt ||
49                              instance_of<TypeCvtNode>(from) ||
50                              instance_of<ExtractbitsNode>(from) ||
51                              instance_of<IreadNode>(from));
52REGISTER_SAFE_CAST(TypeCvtNode, from.GetOpCode() == OP_ceil ||
53                                from.GetOpCode() == OP_cvt ||
54                                from.GetOpCode() == OP_floor ||
55                                from.GetOpCode() == OP_trunc ||
56                                instance_of<RetypeNode>(from));
57REGISTER_SAFE_CAST(RetypeNode, from.GetOpCode() == OP_retype);
58REGISTER_SAFE_CAST(ExtractbitsNode, from.GetOpCode() == OP_extractbits ||
59                                    from.GetOpCode() == OP_sext ||
60                                    from.GetOpCode() == OP_zext);
61REGISTER_SAFE_CAST(IreadNode, from.GetOpCode() == OP_iread);
62REGISTER_SAFE_CAST(BinaryNode, from.GetOpCode() == OP_add ||
63                               from.GetOpCode() == OP_sub ||
64                               from.GetOpCode() == OP_mul ||
65                               from.GetOpCode() == OP_div ||
66                               from.GetOpCode() == OP_rem ||
67                               from.GetOpCode() == OP_ashr ||
68                               from.GetOpCode() == OP_lshr ||
69                               from.GetOpCode() == OP_shl ||
70                               from.GetOpCode() == OP_max ||
71                               from.GetOpCode() == OP_min ||
72                               from.GetOpCode() == OP_band ||
73                               from.GetOpCode() == OP_bior ||
74                               from.GetOpCode() == OP_bxor ||
75                               instance_of<CompareNode>(from));
76REGISTER_SAFE_CAST(CompareNode, from.GetOpCode() == OP_eq ||
77                                from.GetOpCode() = OP_ge ||
78                                from.GetOpCode() = OP_gt ||
79                                from.GetOpCode() = OP_le ||
80                                from.GetOpCode() = OP_lt ||
81                                from.GetOpCode() = OP_ne ||
82                                from.GetOpCode() = OP_cmp);
83REGISTER_SAFE_CAST(NaryNode, instance_of<IntrinsicopNode>(from));
84REGISTER_SAFE_CAST(IntrinsicopNode, from.GetOpCode() == OP_intrinsicop);
85REGISTER_SAFE_CAST(ConstvalNode, from.GetOpCode() == OP_constval);
86REGISTER_SAFE_CAST(AddrofNode, from.GetOpCode() == OP_dread ||
87                               from.GetOpCode() == OP_addrof);
88REGISTER_SAFE_CAST(RegreadNode, from.GetOpCode() == OP_regread);
89REGISTER_SAFE_CAST(StmtNode, instance_of<IassignNode>(from) ||
90                             instance_of<GotoNode>(from) ||
91                             instance_of<SwitchNode>(from) ||
92                             instance_of<UnaryStmtNode>(from) ||
93                             instance_of<BlockNode>(from) ||
94                             instance_of<NaryStmtNode>(from) ||
95                             instance_of<LabelNode>(from) ||
96                             instance_of<CommentNode>(from));
97REGISTER_SAFE_CAST(IassignNode, from.GetOpCode() == OP_iassign);
98REGISTER_SAFE_CAST(GotoNode, from.GetOpCode() == OP_goto);
99REGISTER_SAFE_CAST(SwitchNode, from.GetOpCode() == OP_switch);
100REGISTER_SAFE_CAST(UnaryStmtNode, from.GetOpCode() == OP_eval ||
101                                  instance_of<DassignNode>(from) ||
102                                  instance_of<RegassignNode>(from) ||
103                                  instance_of<CondGotoNode>(from) ||
104                                  instance_of<RangeGotoNode>(from) ||
105                                  instance_of<IfStmtNode>(from));
106REGISTER_SAFE_CAST(DassignNode, from.GetOpCode() == OP_dassign);
107REGISTER_SAFE_CAST(RegassignNode, from.GetOpCode() == OP_regassign);
108REGISTER_SAFE_CAST(CondGotoNode, from.GetOpCode() == OP_brtrue ||
109                                 from.GetOpCode() == OP_brfalse);
110REGISTER_SAFE_CAST(RangeGotoNode, from.GetOpCode() == OP_rangegoto);
111REGISTER_SAFE_CAST(BlockNode, from.GetOpCode() == OP_block);
112REGISTER_SAFE_CAST(IfStmtNode, from.GetOpCode() == OP_if);
113REGISTER_SAFE_CAST(NaryStmtNode, from.GetOpCode() == OP_return ||
114                                 instance_of<CallNode>(from) ||
115                                 instance_of<IcallNode>(from) ||
116                                 instance_of<IntrinsiccallNode>(from));
117REGISTER_SAFE_CAST(CallNode, from.GetOpCode() == OP_call ||
118                             from.GetOpCode() == OP_callassigned);
119REGISTER_SAFE_CAST(IcallNode, from.GetOpCode() == OP_icall ||
120                              from.GetOpCode() == OP_icallassigned ||
121                              from.GetOpCode() == OP_icallproto ||
122                              from.GetOpCode() == OP_icallprotoassigned);
123REGISTER_SAFE_CAST(IntrinsiccallNode, from.GetOpCode() == OP_intrinsiccall ||
124                                      from.GetOpCode() == OP_intrinsiccallwithtype ||
125                                      from.GetOpCode() == OP_intrinsiccallassigned);
126REGISTER_SAFE_CAST(LabelNode, from.GetOpCode() == OP_label);
127REGISTER_SAFE_CAST(CommentNode, from.GetOpCode() == OP_comment);
128#endif
129}
130