• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 RAWHEAP_TRANSLATE_COMMON_H
17 #define RAWHEAP_TRANSLATE_COMMON_H
18 
19 #include <cstdint>
20 #include <vector>
21 #include <string>
22 
23 namespace rawheap_translate {
24 using JSType = uint8_t;
25 using NodeType = uint8_t;
26 using StringKey = size_t;
27 using StringId = uint32_t;
28 
29 static constexpr NodeType DEFAULT_NODETYPE = 8;  // 8: means default node type
30 static constexpr NodeType FRAMEWORK_NODETYPE = 14;
31 enum class EdgeType { CONTEXT, ELEMENT, PROPERTY, INTERNAL, HIDDEN, SHORTCUT, WEAK, DEFAULT = PROPERTY };
32 
33 struct Field {
34     std::string name = "";
35     uint32_t offset = 0;
36     uint32_t size = 0;
37 };
38 
39 struct MetaData {
40     std::string name = "";
41     std::string visitType = "";
42     std::vector<Field> fields {};
43     MetaData *parent {nullptr};
44     uint32_t endOffset = 0;
45     JSType type = 0;
46     NodeType nodeType = DEFAULT_NODETYPE;
47 
IsArrayMetaData48     bool IsArray()
49     {
50         return visitType == "Array";
51     }
52 };
53 
54 struct BitField {
55     Field objectTypeField;
56     Field nativePointerBindingSizeField;
57     Field taggedArrayLengthField;
58     Field taggedArrayDataField;
59     Field dictionaryLengthField;
60     Field dictionaryDataField;
61 };
62 
63 struct DictionaryLayout {
64     uint32_t keyIndex = 0;
65     uint32_t valueIndex = 0;
66     uint32_t detailIndex = 0;
67     uint32_t entrySize = 0;
68     uint32_t headerSize = 0;
69 };
70 
71 struct TypeRange {
72     JSType stringFirst = 0;
73     JSType stringLast = 0;
74     JSType objectFirst = 0;
75     JSType objectLast = 0;
76 };
77 
78 struct Node {
79     uint64_t nodeId = 0;
80     StringId strId = 1;   // 1: for empty string
81     uint32_t edgeCount = 0;
82     uint32_t index = 0;
83     uint32_t size = 0;
84     uint32_t nativeSize = 0;
85     char *data {nullptr};
86     NodeType type = DEFAULT_NODETYPE;
87     JSType jsType = 0;
88 
NodeNode89     Node(uint32_t nodeIndex) : index(nodeIndex) {}
90 };
91 
92 struct Edge {
93     Node *to {nullptr};
94     uint32_t nameOrIndex = 0;
95     EdgeType type = EdgeType::DEFAULT;
96 
EdgeEdge97     Edge(Node *node, uint32_t index, EdgeType edgeType) : to(node), nameOrIndex(index), type(edgeType) {}
98 };
99 
100 static constexpr uint8_t ZERO_VALUE = 0x02U;       // 0000 0010
101 static constexpr uint8_t HOLE_VALUE = 0x12U;       // 0001 0010
102 static constexpr uint8_t NULL_VALUE = 0x22U;       // 0010 0010
103 static constexpr uint8_t EXCP_VALUE = 0x32U;       // 0011 0010
104 static constexpr uint8_t UNDF_VALUE = 0x42U;       // 0100 0010
105 static constexpr uint8_t TRUE_VALUE = 0x52U;       // 0101 0010
106 static constexpr uint8_t FALS_VALUE = 0x62U;       // 0110 0010
107 static constexpr uint8_t INTL_VALUE = 0x04U;       // 0000 0100
108 static constexpr uint8_t DOUB_VALUE = 0x06U;       // 0000 0110
109 }  // namespace rawheap_translate
110 #endif  // RAWHEAP_TRANSLATE_COMMON_H