• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 #ifndef PANDA_PLUGINS_ETS_RUNTIME_ETS_CLASS_ROOT_H
16 #define PANDA_PLUGINS_ETS_RUNTIME_ETS_CLASS_ROOT_H
17 
18 #include "libpandabase/utils/logger.h"
19 #include "libpandabase/utils/type_helpers.h"
20 #include "runtime/include/class_root.h"
21 
22 namespace panda::ets {
23 
24 enum class EtsClassRoot {
25     VOID = helpers::ToUnderlying(ClassRoot::V),
26     BOOLEAN = helpers::ToUnderlying(ClassRoot::U1),
27     BYTE = helpers::ToUnderlying(ClassRoot::I8),
28     CHAR = helpers::ToUnderlying(ClassRoot::U16),
29     SHORT = helpers::ToUnderlying(ClassRoot::I16),
30     INT = helpers::ToUnderlying(ClassRoot::I32),
31     LONG = helpers::ToUnderlying(ClassRoot::I64),
32     FLOAT = helpers::ToUnderlying(ClassRoot::F32),
33     DOUBLE = helpers::ToUnderlying(ClassRoot::F64),
34 
35     BOOLEAN_ARRAY = helpers::ToUnderlying(ClassRoot::ARRAY_U1),
36     BYTE_ARRAY = helpers::ToUnderlying(ClassRoot::ARRAY_I8),
37     CHAR_ARRAY = helpers::ToUnderlying(ClassRoot::ARRAY_U16),
38     SHORT_ARRAY = helpers::ToUnderlying(ClassRoot::ARRAY_I16),
39     INT_ARRAY = helpers::ToUnderlying(ClassRoot::ARRAY_I32),
40     LONG_ARRAY = helpers::ToUnderlying(ClassRoot::ARRAY_I64),
41     FLOAT_ARRAY = helpers::ToUnderlying(ClassRoot::ARRAY_F32),
42     DOUBLE_ARRAY = helpers::ToUnderlying(ClassRoot::ARRAY_F64),
43 
44     CLASS = helpers::ToUnderlying(ClassRoot::CLASS),
45     OBJECT = helpers::ToUnderlying(ClassRoot::OBJECT),
46     STRING = helpers::ToUnderlying(ClassRoot::STRING),
47     STRING_ARRAY = helpers::ToUnderlying(ClassRoot::ARRAY_STRING),
48 };
49 
ToCoreClassRoot(EtsClassRoot etsClassRoot)50 inline ClassRoot ToCoreClassRoot(EtsClassRoot etsClassRoot)
51 {
52     return static_cast<ClassRoot>(etsClassRoot);
53 }
54 
ToEtsClassRoot(ClassRoot classRoot)55 inline EtsClassRoot ToEtsClassRoot(ClassRoot classRoot)
56 {
57     switch (classRoot) {
58         // Primitives types
59         case ClassRoot::V:
60             return EtsClassRoot::VOID;
61         case ClassRoot::U1:
62             return EtsClassRoot::BOOLEAN;
63         case ClassRoot::I8:
64             return EtsClassRoot::BYTE;
65         case ClassRoot::U16:
66             return EtsClassRoot::CHAR;
67         case ClassRoot::I16:
68             return EtsClassRoot::SHORT;
69         case ClassRoot::I32:
70             return EtsClassRoot::INT;
71         case ClassRoot::I64:
72             return EtsClassRoot::LONG;
73         case ClassRoot::F32:
74             return EtsClassRoot::FLOAT;
75         case ClassRoot::F64:
76             return EtsClassRoot::DOUBLE;
77 
78         // Primitive arrays types
79         case ClassRoot::ARRAY_U1:
80             return EtsClassRoot::BOOLEAN_ARRAY;
81         case ClassRoot::ARRAY_U8:
82             return EtsClassRoot::BYTE_ARRAY;
83         case ClassRoot::ARRAY_U16:
84             return EtsClassRoot::CHAR_ARRAY;
85         case ClassRoot::ARRAY_I16:
86             return EtsClassRoot::SHORT_ARRAY;
87         case ClassRoot::ARRAY_I32:
88             return EtsClassRoot::INT_ARRAY;
89         case ClassRoot::ARRAY_I64:
90             return EtsClassRoot::LONG_ARRAY;
91         case ClassRoot::ARRAY_F32:
92             return EtsClassRoot::FLOAT_ARRAY;
93         case ClassRoot::ARRAY_F64:
94             return EtsClassRoot::DOUBLE_ARRAY;
95 
96         // Object types
97         case ClassRoot::CLASS:
98             return EtsClassRoot::CLASS;
99         case ClassRoot::OBJECT:
100             return EtsClassRoot::OBJECT;
101 
102         // Other types
103         case ClassRoot::STRING:
104             return EtsClassRoot::STRING;
105         case ClassRoot::ARRAY_CLASS:
106             return EtsClassRoot::STRING_ARRAY;
107         default:
108             LOG(FATAL, ETS) << "Unsupporeted class_root: " << helpers::ToUnderlying(classRoot);
109     }
110 
111     UNREACHABLE();
112 }
113 
114 }  // namespace panda::ets
115 
116 #endif  // PANDA_PLUGINS_ETS_RUNTIME_ETS_CLASS_ROOT_H
117