• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef ECMASCRIPT_JS_THREAD_ELEMENTS_HCLASS_ENTRIES_H
17 #define ECMASCRIPT_JS_THREAD_ELEMENTS_HCLASS_ENTRIES_H
18 
19 #include "ecmascript/elements.h"
20 
21 namespace panda::ecmascript {
22 struct ElementsHClassEntries {
23     static constexpr size_t N_ENTRIES = static_cast<size_t>(Elements::KIND_COUNT);
24     struct Entry {
25         GlobalEnvField hclassIdx = GlobalEnvField::INVALID;
26         GlobalEnvField hclassWithProtoIdx = GlobalEnvField::INVALID;
27     };
28     Entry entries[N_ENTRIES];
29 
30     static constexpr size_t SizeArch32 = sizeof(entries);
31     static constexpr size_t SizeArch64 = sizeof(entries);
32 
ElementsHClassEntriesElementsHClassEntries33     ElementsHClassEntries()
34     {
35         for (uint32_t i = 0; i < Elements::KIND_COUNT; ++i) {
36             if ((i & 1) != 0) {
37                 entries[i].hclassIdx = GlobalEnvField::ELEMENT_HOLE_TAGGED_HCLASS_INDEX;
38                 entries[i].hclassWithProtoIdx = GlobalEnvField::ELEMENT_HOLE_TAGGED_PROTO_HCLASS_INDEX;
39             } else {
40                 entries[i].hclassIdx = GlobalEnvField::ELEMENT_TAGGED_HCLASS_INDEX;
41                 entries[i].hclassWithProtoIdx = GlobalEnvField::ELEMENT_TAGGED_PROTO_HCLASS_INDEX;
42             }
43         }
44 #define INIT_ARRAY_HCLASS_INDEX_ARRAYS(name)                                                                       \
45         entries[Elements::ToUint(ElementsKind::name)] =                                                            \
46             {GlobalEnvField::ELEMENT_##name##_HCLASS_INDEX, GlobalEnvField::ELEMENT_##name##_PROTO_HCLASS_INDEX};
47         ELEMENTS_KIND_INIT_HCLASS_LIST(INIT_ARRAY_HCLASS_INDEX_ARRAYS)
48 #undef INIT_ARRAY_HCLASS_INDEX_ARRAYS
49     }
50 
GetArrayInstanceHClassIndexElementsHClassEntries51     GlobalEnvField GetArrayInstanceHClassIndex(ElementsKind kind, bool isPrototype) const
52     {
53         ASSERT(Elements::ToUint(kind) <= Elements::ToUint(ElementsKind::GENERIC));
54         auto entry = entries[Elements::ToUint(kind)];
55         return isPrototype ? entry.hclassWithProtoIdx : entry.hclassIdx;
56     }
57 };
58 
59 STATIC_ASSERT_EQ_ARCH(sizeof(ElementsHClassEntries), ElementsHClassEntries::SizeArch32,
60                       ElementsHClassEntries::SizeArch64);
61 }
62 // namespace panda::ecmascript
63 
64 #endif // ECMASCRIPT_JS_THREAD_ELEMENTS_HCLASS_ENTRIES_H
65