• 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_ME_EXPR
21#undef LOAD_SAFE_CAST_FOR_ME_EXPR
22REGISTER_SAFE_CAST(VarMeExpr, from.GetMeOp() == kMeOpVar);
23REGISTER_SAFE_CAST(RegMeExpr, from.GetMeOp() == kMeOpReg);
24REGISTER_SAFE_CAST(ConstMeExpr, from.GetMeOp() == kMeOpConst);
25REGISTER_SAFE_CAST(ConststrMeExpr, from.GetMeOp() == kMeOpConststr);
26REGISTER_SAFE_CAST(Conststr16MeExpr, from.GetMeOp() == kMeOpConststr16);
27REGISTER_SAFE_CAST(SizeoftypeMeExpr, from.GetMeOp() == kMeOpSizeoftype);
28REGISTER_SAFE_CAST(FieldsDistMeExpr, from.GetMeOp() == kMeOpFieldsDist);
29REGISTER_SAFE_CAST(AddrofMeExpr, from.GetMeOp() == kMeOpAddrof);
30REGISTER_SAFE_CAST(AddroffuncMeExpr, from.GetMeOp() == kMeOpAddroffunc);
31REGISTER_SAFE_CAST(GcmallocMeExpr, from.GetMeOp() == kMeOpGcmalloc);
32REGISTER_SAFE_CAST(OpMeExpr, from.GetMeOp() == kMeOpOp);
33REGISTER_SAFE_CAST(IvarMeExpr, from.GetMeOp() == kMeOpIvar);
34#endif
35
36#ifdef LOAD_SAFE_CAST_FOR_ME_STMT
37#undef LOAD_SAFE_CAST_FOR_ME_STMT
38REGISTER_SAFE_CAST(PiassignMeStmt, from.GetOp() == OP_piassign);
39REGISTER_SAFE_CAST(DassignMeStmt, from.GetOp() == OP_dassign);
40REGISTER_SAFE_CAST(AssignMeStmt, from.GetOp() == OP_regassign);
41REGISTER_SAFE_CAST(MaydassignMeStmt, from.GetOp() == OP_maydassign);
42REGISTER_SAFE_CAST(IassignMeStmt, from.GetOp() == OP_iassign);
43REGISTER_SAFE_CAST(NaryMeStmt, instance_of<CallMeStmt>(from) ||
44                               instance_of<IcallMeStmt>(from) ||
45                               instance_of<IntrinsiccallMeStmt>(from) ||
46                               instance_of<RetMeStmt>(from) ||
47                               instance_of<SyncMeStmt>(from));
48REGISTER_SAFE_CAST(CallMeStmt, from.GetOp() == OP_call ||
49                               from.GetOp() == OP_virtualcall ||
50                               from.GetOp() == OP_superclasscall ||
51                               from.GetOp() == OP_interfacecall ||
52                               from.GetOp() == OP_customcall ||
53                               from.GetOp() == OP_polymorphiccall ||
54                               from.GetOp() == OP_interfaceicall ||
55                               from.GetOp() == OP_virtualicall ||
56                               from.GetOp() == OP_callassigned ||
57                               from.GetOp() == OP_virtualcallassigned ||
58                               from.GetOp() == OP_superclasscallassigned ||
59                               from.GetOp() == OP_interfacecallassigned ||
60                               from.GetOp() == OP_customcallassigned ||
61                               from.GetOp() == OP_polymorphiccallassigned ||
62                               from.GetOp() == OP_interfaceicallassigned ||
63                               from.GetOp() == OP_virtualicallassigned);
64REGISTER_SAFE_CAST(IcallMeStmt, from.GetOp() == OP_icall ||
65                                from.GetOp() == OP_icallassigned);
66REGISTER_SAFE_CAST(IntrinsiccallMeStmt, from.GetOp() == OP_intrinsiccall ||
67                                        from.GetOp() == OP_intrinsiccallwithtype ||
68                                        from.GetOp() == OP_xintrinsiccall ||
69                                        from.GetOp() == OP_intrinsiccallassigned ||
70                                        from.GetOp() == OP_intrinsiccallwithtypeassigned ||
71                                        from.GetOp() == OP_xintrinsiccallassigned);
72REGISTER_SAFE_CAST(RetMeStmt, from.GetOp() == OP_return);
73REGISTER_SAFE_CAST(UnaryMeStmt, instance_of<CondGotoMeStmt>(from) ||
74                                instance_of<SwitchMeStmt>(from) ||
75                                instance_of<CondGotoMeStmt>(from) ||
76                                from.GetOp() == OP_eval ||
77                                from.GetOp() == OP_free ||
78                                (kOpcodeInfo.IsAssertNonnull(from.GetOpCode()) &&
79                                 !kOpcodeInfo.IsCallAssertNonnull(from.GetOpCode())) ||
80                                from.GetOp() == OP_incref ||
81                                from.GetOp() == OP_decref ||
82                                from.GetOp() == OP_decrefreset);
83REGISTER_SAFE_CAST(SafetyCallCheckMeStmt, from.GetOpCode() == OP_callassertnonnull);
84REGISTER_SAFE_CAST(GotoMeStmt, from.GetOp() == OP_goto);
85REGISTER_SAFE_CAST(CondGotoMeStmt, from.GetOp() == OP_brtrue ||
86                                   from.GetOp() == OP_brfalse);
87REGISTER_SAFE_CAST(JsTryMeStmt, from.GetOp() == OP_jstry);
88REGISTER_SAFE_CAST(TryMeStmt, from.GetOp() == OP_try);
89REGISTER_SAFE_CAST(CatchMeStmt, from.GetOp() == OP_catch);
90REGISTER_SAFE_CAST(SwitchMeStmt, from.GetOp() == OP_switch);
91REGISTER_SAFE_CAST(CommentMeStmt, from.GetOp() == OP_comment);
92REGISTER_SAFE_CAST(WithMuMeStmt, instance_of<GosubMeStmt>(from) ||
93                                 instance_of<ThrowMeStmt>(from) ||
94                                 from.GetOp() == OP_retsub);
95REGISTER_SAFE_CAST(GosubMeStmt, from.GetOp() == OP_gosub);
96REGISTER_SAFE_CAST(ThrowMeStmt, from.GetOp() == OP_throw);
97REGISTER_SAFE_CAST(SyncMeStmt, from.GetOp() == OP_syncenter ||
98                               from.GetOp() == OP_syncexit);
99#endif
100}
101