• 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 "ecmascript/compiler/mcr_gate_meta_data.h"
17 #include "ecmascript/compiler/gate_meta_data_builder.h"
18 
19 namespace panda::ecmascript::kungfu {
IsTypedOperator() const20 bool GateMetaData::IsTypedOperator() const
21 {
22     return (opcode_ == OpCode::TYPED_BINARY_OP) || (opcode_ == OpCode::TYPE_CONVERT) ||
23         (opcode_ == OpCode::TYPED_UNARY_OP);
24 }
25 
IsCheckWithTwoIns() const26 bool GateMetaData::IsCheckWithTwoIns() const
27 {
28     return (opcode_ == OpCode::OBJECT_TYPE_CHECK) ||
29            (opcode_ == OpCode::INDEX_CHECK) ||
30            (opcode_ == OpCode::TYPED_CALL_CHECK);
31 }
32 
IsCheckWithOneIn() const33 bool GateMetaData::IsCheckWithOneIn() const
34 {
35     return (opcode_ == OpCode::PRIMITIVE_TYPE_CHECK) ||
36            (opcode_ == OpCode::HEAP_OBJECT_CHECK) ||
37            (opcode_ == OpCode::STABLE_ARRAY_CHECK) ||
38            (opcode_ == OpCode::TYPED_ARRAY_CHECK);
39 }
40 
Str(TypedBinOp op)41 std::string GateMetaData::Str(TypedBinOp op)
42 {
43     const std::map<TypedBinOp, const char *> strMap = {
44 #define TYPED_BIN_OP_NAME_MAP(OP) { TypedBinOp::OP, #OP },
45     TYPED_BIN_OP_LIST(TYPED_BIN_OP_NAME_MAP)
46 #undef TYPED_BIN_OP_NAME_MAP
47     };
48     if (strMap.count(op) > 0) {
49         return strMap.at(op);
50     }
51     return "UNKNOW";
52 }
53 
Str(TypedUnOp op)54 std::string GateMetaData::Str(TypedUnOp op)
55 {
56     const std::map<TypedUnOp, const char *> strMap = {
57 #define TYPED_UN_OP_NAME_MAP(OP) { TypedUnOp::OP, #OP },
58     TYPED_UN_OP_LIST(TYPED_UN_OP_NAME_MAP)
59 #undef TYPED_UN_OP_NAME_MAP
60     };
61     if (strMap.count(op) > 0) {
62         return strMap.at(op);
63     }
64     return "UNKNOW";
65 }
66 
Str(TypedJumpOp op)67 std::string GateMetaData::Str(TypedJumpOp op)
68 {
69     const std::map<TypedJumpOp, const char *> strMap = {
70 #define TYPED_JUMP_OP_NAME_MAP(OP) { TypedJumpOp::OP, #OP },
71     TYPED_JUMP_OP_LIST(TYPED_JUMP_OP_NAME_MAP)
72 #undef TYPED_JUMP_OP_NAME_MAP
73     };
74     if (strMap.count(op) > 0) {
75         return strMap.at(op);
76     }
77     return "UNKNOW";
78 }
79 
Str(TypedLoadOp op)80 std::string GateMetaData::Str(TypedLoadOp op)
81 {
82     const std::map<TypedLoadOp, const char *> strMap = {
83 #define TYPED_LOAD_OP_NAME_MAP(OP) { TypedLoadOp::OP, #OP },
84     TYPED_LOAD_OP_LIST(TYPED_LOAD_OP_NAME_MAP)
85 #undef TYPED_LOAD_OP_NAME_MAP
86     };
87     if (strMap.count(op) > 0) {
88         return strMap.at(op);
89     }
90     return "UNKNOW";
91 }
92 
Str(TypedStoreOp op)93 std::string GateMetaData::Str(TypedStoreOp op)
94 {
95     const std::map<TypedStoreOp, const char *> strMap = {
96 #define TYPED_STORE_OP_NAME_MAP(OP) { TypedStoreOp::OP, #OP },
97     TYPED_STORE_OP_LIST(TYPED_STORE_OP_NAME_MAP)
98 #undef TYPED_STORE_OP_NAME_MAP
99     };
100     if (strMap.count(op) > 0) {
101         return strMap.at(op);
102     }
103     return "UNKNOW";
104 }
105 
Str(TypedCallTargetCheckOp op)106 std::string GateMetaData::Str(TypedCallTargetCheckOp op)
107 {
108     const std::map<TypedCallTargetCheckOp, const char *> strMap = {
109 #define TYPED_CALL_TARGET_CHECK_OP_NAME_MAP(OP) { TypedCallTargetCheckOp::OP, #OP },
110     TYPED_CALL_TARGET_CHECK_OP_LIST(TYPED_CALL_TARGET_CHECK_OP_NAME_MAP)
111 #undef TYPED_CALL_TARGET_CHECK_OP_NAME_MAP
112     };
113     if (strMap.count(op) > 0) {
114         return strMap.at(op);
115     }
116     return "UNKNOW";
117 }
118 
Str(ValueType type)119 std::string GateMetaData::Str(ValueType type)
120 {
121     const std::map<ValueType, const char *> strMap = {
122 #define VALUE_TYPE_NAME_MAP(TYPE) { ValueType::TYPE, #TYPE },
123     VALUE_TYPE_LIST(VALUE_TYPE_NAME_MAP)
124 #undef VALUE_TYPE_NAME_MAP
125     };
126     if (strMap.count(type) > 0) {
127         return strMap.at(type);
128     }
129     return "UNKNOW";
130 }
131 }
132