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(MIRFloat128Const, from.GetKind() == kConstFloat128Const); 31REGISTER_SAFE_CAST(MIRAggConst, from.GetKind() == kConstAggConst); 32REGISTER_SAFE_CAST(MIRStConst, from.GetKind() == kConstStConst); 33#endif 34 35#ifdef LOAD_SAFE_CAST_FOR_MIR_TYPE 36#undef LOAD_SAFE_CAST_FOR_MIR_TYPE 37REGISTER_SAFE_CAST(MIRPtrType, from.GetKind() == kTypePointer); 38REGISTER_SAFE_CAST(MIRArrayType, from.GetKind() == kTypeArray); 39REGISTER_SAFE_CAST(MIRFarrayType, from.GetKind() == kTypeFArray || 40 instance_of<MIRJarrayType>(from)); 41REGISTER_SAFE_CAST(MIRStructType, from.GetKind() == kTypeStruct || 42 from.GetKind() == kTypeStructIncomplete || 43 from.GetKind() == kTypeUnion || 44 instance_of<MIRClassType>(from) || 45 instance_of<MIRInterfaceType>(from)); 46REGISTER_SAFE_CAST(MIRJarrayType, from.GetKind() == kTypeJArray); 47REGISTER_SAFE_CAST(MIRClassType, from.GetKind() == kTypeClass || 48 from.GetKind() == kTypeClassIncomplete); 49REGISTER_SAFE_CAST(MIRInterfaceType, from.GetKind() == kTypeInterface || 50 from.GetKind() == kTypeInterfaceIncomplete); 51REGISTER_SAFE_CAST(MIRBitFieldType, from.GetKind() == kTypeBitField); 52REGISTER_SAFE_CAST(MIRFuncType, from.GetKind() == kTypeFunction); 53REGISTER_SAFE_CAST(MIRTypeByName, from.GetKind() == kTypeByName); 54REGISTER_SAFE_CAST(MIRTypeParam, from.GetKind() == kTypeParam); 55REGISTER_SAFE_CAST(MIRInstantVectorType, from.GetKind() == kTypeInstantVector); 56REGISTER_SAFE_CAST(MIRGenericInstantType, from.GetKind() == kTypeGenericInstant); 57#endif 58 59#ifdef LOAD_SAFE_CAST_FOR_MIR_NODE 60#undef LOAD_SAFE_CAST_FOR_MIR_NODE 61REGISTER_SAFE_CAST(UnaryNode, from.GetOpCode() == OP_abs || 62 from.GetOpCode() == OP_bnot || 63 from.GetOpCode() == OP_lnot || 64 from.GetOpCode() == OP_neg || 65 from.GetOpCode() == OP_recip || 66 from.GetOpCode() == OP_sqrt || 67 from.GetOpCode() == OP_alloca || 68 from.GetOpCode() == OP_malloc || 69 instance_of<TypeCvtNode>(from) || 70 instance_of<ExtractbitsNode>(from) || 71 instance_of<JarrayMallocNode>(from) || 72 instance_of<IreadNode>(from) || 73 instance_of<IreadoffNode>(from)); 74REGISTER_SAFE_CAST(TypeCvtNode, from.GetOpCode() == OP_ceil || 75 from.GetOpCode() == OP_cvt || 76 from.GetOpCode() == OP_floor || 77 from.GetOpCode() == OP_round || 78 from.GetOpCode() == OP_trunc || 79 instance_of<RetypeNode>(from)); 80REGISTER_SAFE_CAST(RetypeNode, from.GetOpCode() == OP_retype); 81REGISTER_SAFE_CAST(ExtractbitsNode, from.GetOpCode() == OP_extractbits || 82 from.GetOpCode() == OP_sext || 83 from.GetOpCode() == OP_zext); 84REGISTER_SAFE_CAST(GCMallocNode, from.GetOpCode() == OP_gcmalloc || 85 from.GetOpCode() = OP_gcpermalloc); 86REGISTER_SAFE_CAST(JarrayMallocNode, from.GetOpCode() == OP_gcmallocjarray || 87 from.GetOpCode() = OP_gcpermallocjarray); 88REGISTER_SAFE_CAST(IreadNode, from.GetOpCode() == OP_iread || 89 from.GetOpCode() = OP_iaddrof); 90REGISTER_SAFE_CAST(IreadoffNode, from.GetOpCode() == OP_ireadoff); 91REGISTER_SAFE_CAST(IreadFPoffNode, from.GetOpCode() == OP_ireadfpoff); 92REGISTER_SAFE_CAST(BinaryNode, from.GetOpCode() == OP_add || 93 from.GetOpCode() == OP_sub || 94 from.GetOpCode() == OP_mul || 95 from.GetOpCode() == OP_div || 96 from.GetOpCode() == OP_rem || 97 from.GetOpCode() == OP_ashr || 98 from.GetOpCode() == OP_lshr || 99 from.GetOpCode() == OP_shl || 100 from.GetOpCode() == OP_max || 101 from.GetOpCode() == OP_min || 102 from.GetOpCode() == OP_band || 103 from.GetOpCode() == OP_bior || 104 from.GetOpCode() == OP_bxor || 105 from.GetOpCode() == OP_CG_array_elem_add || 106 from.GetOpCode() == OP_land || 107 from.GetOpCode() == OP_lior || 108 from.GetOpCode() == OP_cand || 109 from.GetOpCode() == OP_cior || 110 instance_of<CompareNode>(from) || 111 instance_of<DepositbitsNode>(from) || 112 instance_of<ResolveFuncNode>(from)); 113REGISTER_SAFE_CAST(CompareNode, from.GetOpCode() == OP_eq || 114 from.GetOpCode() = OP_ge || 115 from.GetOpCode() = OP_gt || 116 from.GetOpCode() = OP_le || 117 from.GetOpCode() = OP_lt || 118 from.GetOpCode() = OP_ne || 119 from.GetOpCode() = OP_cmp || 120 from.GetOpCode() = OP_cmpl || 121 from.GetOpCode() = OP_cmpg); 122REGISTER_SAFE_CAST(DepositbitsNode, from.GetOpCode() == OP_depositbits); 123REGISTER_SAFE_CAST(ResolveFuncNode, from.GetOpCode() == OP_resolveinterfacefunc || 124 from.GetOpCode() == OP_resolvevirtualfunc); 125REGISTER_SAFE_CAST(TernaryNode, from.GetOpCode() == OP_select); 126REGISTER_SAFE_CAST(NaryNode, instance_of<IntrinsicopNode>(from) || 127 instance_of<ArrayNode>(from)); 128REGISTER_SAFE_CAST(IntrinsicopNode, from.GetOpCode() == OP_intrinsicop || 129 from.GetOpCode() == OP_intrinsicopwithtype); 130REGISTER_SAFE_CAST(ConstvalNode, from.GetOpCode() == OP_constval); 131REGISTER_SAFE_CAST(ConststrNode, from.GetOpCode() == OP_conststr); 132REGISTER_SAFE_CAST(Conststr16Node, from.GetOpCode() == OP_conststr16); 133REGISTER_SAFE_CAST(SizeoftypeNode, from.GetOpCode() == OP_sizeoftype); 134REGISTER_SAFE_CAST(FieldsDistNode, from.GetOpCode() == OP_fieldsdist); 135REGISTER_SAFE_CAST(ArrayNode, from.GetOpCode() == OP_array); 136REGISTER_SAFE_CAST(AddrofNode, from.GetOpCode() == OP_dread || 137 from.GetOpCode() == OP_addrof); 138REGISTER_SAFE_CAST(RegreadNode, from.GetOpCode() == OP_regread); 139REGISTER_SAFE_CAST(AddroffuncNode, from.GetOpCode() == OP_addroffunc); 140REGISTER_SAFE_CAST(AddroflabelNode, from.GetOpCode() == OP_addroflabel); 141REGISTER_SAFE_CAST(StmtNode, from.GetOpCode() == OP_finally || 142 from.GetOpCode() == OP_cleanuptry || 143 from.GetOpCode() == OP_endtry || 144 from.GetOpCode() == OP_retsub || 145 from.GetOpCode() == OP_membaracquire || 146 from.GetOpCode() == OP_membarrelease || 147 from.GetOpCode() == OP_membarstoreload || 148 from.GetOpCode() == OP_membarstorestore || 149 instance_of<IassignNode>(from) || 150 instance_of<GotoNode>(from) || 151 instance_of<JsTryNode>(from) || 152 instance_of<TryNode>(from) || 153 instance_of<CatchNode>(from) || 154 instance_of<SwitchNode>(from) || 155 instance_of<MultiwayNode>(from) || 156 instance_of<UnaryStmtNode>(from) || 157 instance_of<BlockNode>(from) || 158 instance_of<DoloopNode>(from) || 159 instance_of<ForeachelemNode>(from) || 160 instance_of<NaryStmtNode>(from) || 161 instance_of<LabelNode>(from) || 162 instance_of<CommentNode>(from)); 163REGISTER_SAFE_CAST(IassignNode, from.GetOpCode() == OP_iassign); 164REGISTER_SAFE_CAST(GotoNode, from.GetOpCode() == OP_goto || 165 from.GetOpCode() == OP_gosub); 166REGISTER_SAFE_CAST(JsTryNode, from.GetOpCode() == OP_jstry); 167REGISTER_SAFE_CAST(TryNode, from.GetOpCode() == OP_try); 168REGISTER_SAFE_CAST(CatchNode, from.GetOpCode() == OP_catch); 169REGISTER_SAFE_CAST(SwitchNode, from.GetOpCode() == OP_switch); 170REGISTER_SAFE_CAST(MultiwayNode, from.GetOpCode() == OP_multiway); 171REGISTER_SAFE_CAST(UnaryStmtNode, from.GetOpCode() == OP_eval || 172 from.GetOpCode() == OP_throw || 173 from.GetOpCode() == OP_free || 174 from.GetOpCode() == OP_decref || 175 from.GetOpCode() == OP_incref || 176 from.GetOpCode() == OP_decrefreset || 177 (kOpcodeInfo.IsAssertNonnull(from.GetOpCode()) && 178 !kOpcodeInfo.IsCallAssertNonnull(from.GetOpCode())) || 179 instance_of<DassignNode>(from) || 180 instance_of<RegassignNode>(from) || 181 instance_of<CondGotoNode>(from) || 182 instance_of<RangeGotoNode>(from) || 183 instance_of<IfStmtNode>(from) || 184 instance_of<WhileStmtNode>(from) || 185 instance_of<IassignFPoffNode>(from)); 186REGISTER_SAFE_CAST(CallAssertNonnullStmtNode, from.GetOpCode() == OP_callassertnonnull); 187REGISTER_SAFE_CAST(DassignNode, from.GetOpCode() == OP_dassign || 188 from.GetOpCode() == OP_maydassign); 189REGISTER_SAFE_CAST(RegassignNode, from.GetOpCode() == OP_regassign); 190REGISTER_SAFE_CAST(CondGotoNode, from.GetOpCode() == OP_brtrue || 191 from.GetOpCode() == OP_brfalse); 192REGISTER_SAFE_CAST(RangeGotoNode, from.GetOpCode() == OP_rangegoto); 193REGISTER_SAFE_CAST(BlockNode, from.GetOpCode() == OP_block); 194REGISTER_SAFE_CAST(IfStmtNode, from.GetOpCode() == OP_if); 195REGISTER_SAFE_CAST(WhileStmtNode, from.GetOpCode() == OP_while || 196 from.GetOpCode() == OP_dowhile); 197REGISTER_SAFE_CAST(DoloopNode, from.GetOpCode() == OP_doloop); 198REGISTER_SAFE_CAST(ForeachelemNode, from.GetOpCode() == OP_foreachelem); 199REGISTER_SAFE_CAST(BinaryStmtNode, from.GetOpCode() == OP_assertge || 200 from.GetOpCode() == OP_assertlt || 201 instance_of<IassignoffNode>(from)); 202REGISTER_SAFE_CAST(IassignoffNode, from.GetOpCode() == OP_iassignoff); 203REGISTER_SAFE_CAST(IassignFPoffNode, from.GetOpCode() == OP_iassignfpoff); 204REGISTER_SAFE_CAST(NaryStmtNode, from.GetOpCode() == OP_return || 205 from.GetOpCode() == OP_syncenter || 206 from.GetOpCode() == OP_syncexit || 207 instance_of<CallNode>(from) || 208 instance_of<IcallNode>(from) || 209 instance_of<IntrinsiccallNode>(from)); 210REGISTER_SAFE_CAST(CallNode, from.GetOpCode() == OP_call || 211 from.GetOpCode() == OP_virtualcall || 212 from.GetOpCode() == OP_superclasscall || 213 from.GetOpCode() == OP_interfacecall || 214 from.GetOpCode() == OP_customcall || 215 from.GetOpCode() == OP_polymorphiccall || 216 from.GetOpCode() == OP_interfaceicall || 217 from.GetOpCode() == OP_virtualicall || 218 from.GetOpCode() == OP_callassigned || 219 from.GetOpCode() == OP_virtualcallassigned || 220 from.GetOpCode() == OP_superclasscallassigned || 221 from.GetOpCode() == OP_interfacecallassigned || 222 from.GetOpCode() == OP_customcallassigned || 223 from.GetOpCode() == OP_polymorphiccallassigned || 224 from.GetOpCode() == OP_interfaceicallassigned || 225 from.GetOpCode() == OP_virtualicallassigned || 226 instance_of<CallinstantNode>(from)); 227REGISTER_SAFE_CAST(IcallNode, from.GetOpCode() == OP_icall || 228 from.GetOpCode() == OP_icallassigned || 229 from.GetOpCode() == OP_icallproto || 230 from.GetOpCode() == OP_icallprotoassigned); 231REGISTER_SAFE_CAST(IntrinsiccallNode, from.GetOpCode() == OP_intrinsiccall || 232 from.GetOpCode() == OP_intrinsiccallwithtype || 233 from.GetOpCode() == OP_xintrinsiccall || 234 from.GetOpCode() == OP_intrinsiccallassigned || 235 from.GetOpCode() == OP_intrinsiccallwithtypeassigned || 236 from.GetOpCode() == OP_xintrinsiccallassigned); 237REGISTER_SAFE_CAST(CallinstantNode, from.GetOpCode() == OP_callinstant || 238 from.GetOpCode() == OP_virtualcallinstant || 239 from.GetOpCode() == OP_superclasscallinstant || 240 from.GetOpCode() == OP_interfacecallinstant || 241 from.GetOpCode() == OP_callinstantassigned || 242 from.GetOpCode() == OP_virtualcallinstantassigned || 243 from.GetOpCode() == OP_superclasscallinstantassigned || 244 from.GetOpCode() == OP_interfacecallinstantassigned); 245REGISTER_SAFE_CAST(LabelNode, from.GetOpCode() == OP_label); 246REGISTER_SAFE_CAST(CommentNode, from.GetOpCode() == OP_comment); 247#endif 248} 249