/src/WasmEdge/include/ast/section.h
Line | Count | Source (jump to first uncovered line) |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: 2019-2024 Second State INC |
3 | | |
4 | | //===-- wasmedge/ast/section.h - Section class definitions ----------------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the declaration of the Section node classes. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | #pragma once |
15 | | |
16 | | #include "ast/description.h" |
17 | | #include "ast/segment.h" |
18 | | |
19 | | #include <optional> |
20 | | #include <vector> |
21 | | |
22 | | namespace WasmEdge { |
23 | | namespace AST { |
24 | | |
25 | | /// Section's base class. |
26 | | class Section { |
27 | | public: |
28 | | /// Getter and setter of content size. |
29 | 150k | uint64_t getContentSize() const noexcept { return ContentSize; } |
30 | 65.6k | void setContentSize(uint64_t Size) noexcept { ContentSize = Size; } |
31 | | |
32 | | /// Getter and setter of start offset in source. |
33 | 0 | uint64_t getStartOffset() const noexcept { return StartOffset; } |
34 | 65.9k | void setStartOffset(uint64_t Off) noexcept { StartOffset = Off; } |
35 | | |
36 | | protected: |
37 | | /// Content size of this section. |
38 | | uint64_t ContentSize = 0; |
39 | | |
40 | | /// Start offset in source of this section. |
41 | | uint64_t StartOffset = 0; |
42 | | }; |
43 | | |
44 | | /// AST CustomSection node. |
45 | | class CustomSection : public Section { |
46 | | public: |
47 | | /// Getter and setter of name. |
48 | 0 | std::string_view getName() const noexcept { return Name; } |
49 | 44.8k | void setName(std::string_view N) { Name = N; } |
50 | | |
51 | | /// Getter of content vector. |
52 | 0 | Span<const Byte> getContent() const noexcept { return Content; } |
53 | 89.7k | std::vector<Byte> &getContent() noexcept { return Content; } |
54 | | |
55 | | private: |
56 | | /// \name Data of CustomSection. |
57 | | /// @{ |
58 | | std::string Name; |
59 | | std::vector<Byte> Content; |
60 | | /// @} |
61 | | }; |
62 | | |
63 | | /// AST TypeSection node. |
64 | | class TypeSection : public Section { |
65 | | public: |
66 | | /// Getter of content vector. |
67 | 5.94k | Span<const SubType> getContent() const noexcept { return Content; } |
68 | 33.7k | std::vector<SubType> &getContent() noexcept { return Content; } |
69 | | |
70 | | private: |
71 | | /// \name Data of TypeSection. |
72 | | /// @{ |
73 | | std::vector<SubType> Content; |
74 | | /// @} |
75 | | }; |
76 | | |
77 | | /// AST ImportSection node. |
78 | | class ImportSection : public Section { |
79 | | public: |
80 | | /// Getter of content vector. |
81 | 5.94k | Span<const ImportDesc> getContent() const noexcept { return Content; } |
82 | 4.08k | std::vector<ImportDesc> &getContent() noexcept { return Content; } |
83 | | |
84 | | private: |
85 | | /// \name Data of ImportSection. |
86 | | /// @{ |
87 | | std::vector<ImportDesc> Content; |
88 | | /// @} |
89 | | }; |
90 | | |
91 | | /// AST FunctionSection node. |
92 | | class FunctionSection : public Section { |
93 | | public: |
94 | | /// Getter of content vector. |
95 | 5.93k | Span<const uint32_t> getContent() const noexcept { return Content; } |
96 | 8.17k | std::vector<uint32_t> &getContent() noexcept { return Content; } |
97 | | |
98 | | private: |
99 | | /// \name Data of FunctionSection. |
100 | | /// @{ |
101 | | std::vector<uint32_t> Content; |
102 | | /// @} |
103 | | }; |
104 | | |
105 | | /// AST TableSection node. |
106 | | class TableSection : public Section { |
107 | | public: |
108 | | /// Getter of content vector. |
109 | 3.78k | Span<const TableSegment> getContent() const noexcept { return Content; } |
110 | 427 | std::vector<TableSegment> &getContent() noexcept { return Content; } |
111 | | |
112 | | private: |
113 | | /// \name Data of TableSection. |
114 | | /// @{ |
115 | | std::vector<TableSegment> Content; |
116 | | /// @} |
117 | | }; |
118 | | |
119 | | /// AST MemorySection node. |
120 | | class MemorySection : public Section { |
121 | | public: |
122 | | /// Getter of content vector. |
123 | 3.78k | Span<const MemoryType> getContent() const noexcept { return Content; } |
124 | 1.51k | std::vector<MemoryType> &getContent() noexcept { return Content; } |
125 | | |
126 | | private: |
127 | | /// \name Data of MemorySection. |
128 | | /// @{ |
129 | | std::vector<MemoryType> Content; |
130 | | /// @} |
131 | | }; |
132 | | |
133 | | /// AST GlobalSection node. |
134 | | class GlobalSection : public Section { |
135 | | public: |
136 | | /// Getter of content vector. |
137 | 5.89k | Span<const GlobalSegment> getContent() const noexcept { return Content; } |
138 | 666 | std::vector<GlobalSegment> &getContent() noexcept { return Content; } |
139 | | |
140 | | private: |
141 | | /// \name Data of GlobalSection. |
142 | | /// @{ |
143 | | std::vector<GlobalSegment> Content; |
144 | | /// @} |
145 | | }; |
146 | | |
147 | | /// AST ExportSection node. |
148 | | class ExportSection : public Section { |
149 | | public: |
150 | | /// Getter of content vector. |
151 | 3.69k | Span<const ExportDesc> getContent() const noexcept { return Content; } |
152 | 1.23k | std::vector<ExportDesc> &getContent() noexcept { return Content; } |
153 | | |
154 | | private: |
155 | | /// \name Data of ExportSection. |
156 | | /// @{ |
157 | | std::vector<ExportDesc> Content; |
158 | | /// @} |
159 | | }; |
160 | | |
161 | | /// AST StartSection node. |
162 | | class StartSection : public Section { |
163 | | public: |
164 | | /// Getter and setter of content. |
165 | 3.64k | std::optional<uint32_t> getContent() const { return Content; } |
166 | 25 | void setContent(uint32_t Val) noexcept { Content = Val; } |
167 | | |
168 | | private: |
169 | | /// \name Data of StartSection. |
170 | | /// @{ |
171 | | std::optional<uint32_t> Content = std::nullopt; |
172 | | /// @} |
173 | | }; |
174 | | |
175 | | /// AST ElementSection node. |
176 | | class ElementSection : public Section { |
177 | | public: |
178 | | /// Getter of content vector. |
179 | 3.61k | Span<const ElementSegment> getContent() const noexcept { return Content; } |
180 | 1.41k | std::vector<ElementSegment> &getContent() noexcept { return Content; } |
181 | | |
182 | | private: |
183 | | /// \name Data of ElementSection. |
184 | | /// @{ |
185 | | std::vector<ElementSegment> Content; |
186 | | /// @} |
187 | | }; |
188 | | |
189 | | /// AST CodeSection node. |
190 | | class CodeSection : public Section { |
191 | | public: |
192 | | /// Getter of content vector. |
193 | 5.68k | Span<const CodeSegment> getContent() const noexcept { return Content; } |
194 | 8.40k | std::vector<CodeSegment> &getContent() noexcept { return Content; } |
195 | | |
196 | | private: |
197 | | /// \name Data of CodeSection. |
198 | | /// @{ |
199 | | std::vector<CodeSegment> Content; |
200 | | /// @} |
201 | | }; |
202 | | |
203 | | /// AST DataSection node. |
204 | | class DataSection : public Section { |
205 | | public: |
206 | | /// Getter of content vector. |
207 | 3.57k | Span<const DataSegment> getContent() const noexcept { return Content; } |
208 | 1.61k | std::vector<DataSegment> &getContent() noexcept { return Content; } |
209 | | |
210 | | private: |
211 | | /// \name Data of DataSection. |
212 | | /// @{ |
213 | | std::vector<DataSegment> Content; |
214 | | /// @} |
215 | | }; |
216 | | |
217 | | /// AST DataCountSection node. |
218 | | class DataCountSection : public Section { |
219 | | public: |
220 | | /// Getter and setter of content. |
221 | 3.86k | std::optional<uint32_t> getContent() const noexcept { return Content; } |
222 | 83 | void setContent(uint32_t Val) noexcept { Content = Val; } |
223 | | |
224 | | private: |
225 | | /// \name Data of DataCountSection. |
226 | | /// @{ |
227 | | std::optional<uint32_t> Content = std::nullopt; |
228 | | /// @} |
229 | | }; |
230 | | |
231 | | /// AST TagSection node. |
232 | | class TagSection : public Section { |
233 | | public: |
234 | | /// Getter of content vector. |
235 | 3.69k | Span<const TagType> getContent() const noexcept { return Content; } |
236 | 3.82k | std::vector<TagType> &getContent() noexcept { return Content; } |
237 | | |
238 | | private: |
239 | | /// \name Data of TagSection. |
240 | | /// @{ |
241 | | std::vector<TagType> Content; |
242 | | /// @} |
243 | | }; |
244 | | |
245 | | /// AST AOTSection node. For AOT/JIT using. |
246 | | class AOTSection { |
247 | | public: |
248 | | /// Getter and setter of version. |
249 | 0 | uint32_t getVersion() const noexcept { return Version; } |
250 | 0 | void setVersion(uint32_t Ver) noexcept { Version = Ver; } |
251 | | |
252 | | /// Getter and setter of OS type. |
253 | 0 | uint8_t getOSType() const noexcept { return OSType; } |
254 | 0 | void setOSType(uint8_t Type) noexcept { OSType = Type; } |
255 | | |
256 | | /// Getter and setter of arch type. |
257 | 0 | uint8_t getArchType() const noexcept { return ArchType; } |
258 | 0 | void setArchType(uint8_t Type) noexcept { ArchType = Type; } |
259 | | |
260 | | /// Getter and setter of version address. |
261 | 0 | uint64_t getVersionAddress() const noexcept { return VersionAddress; } |
262 | 0 | void setVersionAddress(uint64_t Addr) noexcept { VersionAddress = Addr; } |
263 | | |
264 | | /// Getter and setter of intrinsics address. |
265 | 0 | uint64_t getIntrinsicsAddress() const noexcept { return IntrinsicsAddress; } |
266 | 0 | void setIntrinsicsAddress(uint64_t Addr) noexcept { |
267 | 0 | IntrinsicsAddress = Addr; |
268 | 0 | } |
269 | | |
270 | | /// Getter of type addresses. |
271 | 0 | constexpr const auto &getTypesAddress() const noexcept { |
272 | 0 | return TypesAddress; |
273 | 0 | } |
274 | 0 | constexpr auto &getTypesAddress() noexcept { return TypesAddress; } |
275 | | |
276 | | /// Getter of code addresses. |
277 | 0 | constexpr const auto &getCodesAddress() const noexcept { |
278 | 0 | return CodesAddress; |
279 | 0 | } |
280 | 0 | constexpr auto &getCodesAddress() noexcept { return CodesAddress; } |
281 | | |
282 | | /// Getter of sections. |
283 | 0 | constexpr const auto &getSections() const noexcept { return Sections; } |
284 | 0 | constexpr auto &getSections() noexcept { return Sections; } |
285 | | |
286 | | private: |
287 | | /// \name Data of AOTSection. |
288 | | /// @{ |
289 | | uint32_t Version; |
290 | | uint8_t OSType; |
291 | | uint8_t ArchType; |
292 | | uint64_t VersionAddress; |
293 | | uint64_t IntrinsicsAddress; |
294 | | std::vector<uintptr_t> TypesAddress; |
295 | | std::vector<uintptr_t> CodesAddress; |
296 | | std::vector<std::tuple<uint8_t, uint64_t, uint64_t, std::vector<Byte>>> |
297 | | Sections; |
298 | | std::vector<uint8_t> Bytecodes; |
299 | | /// @} |
300 | | }; |
301 | | |
302 | | } // namespace AST |
303 | | } // namespace WasmEdge |