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