MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / loadModuleAOT

Method loadModuleAOT

lib/loader/ast/module.cpp:239–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237}
238
239Expect<void> Loader::loadModuleAOT(AST::AOTSection &AOTSection) {
240 // Find and read the AOT custom section first. Jump over the others.
241 // This loop checks whether the input is a universal WASM.
242 // Therefore, if the configuration is set to force interpreter mode, skip
243 // this.
244 while (WASMType != InputType::SharedLibrary) {
245 // This loop only scans custom sections and reads the AOT section.
246 // For other general errors, break and handle them in the sequential
247 // parsing below.
248 uint8_t NewSectionId = 0x00;
249 if (auto Res = FMgr.readByte()) {
250 NewSectionId = *Res;
251 } else {
252 break;
253 }
254
255 if (NewSectionId == 0x00U) {
256 // Load the section size.
257 uint32_t ContentSize = 0;
258 if (auto Res = FMgr.readU32()) {
259 ContentSize = *Res;
260 } else {
261 break;
262 }
263 if (ContentSize > FMgr.getRemainSize()) {
264 break;
265 }
266
267 // Load the section name.
268 auto StartOffset = FMgr.getOffset();
269 std::string Name;
270 if (auto Res = FMgr.readName()) {
271 // The UTF-8 failure case will be ignored here.
272 Name = std::move(*Res);
273 }
274
275 auto ReadSize = FMgr.getOffset() - StartOffset;
276 if (ContentSize < ReadSize) {
277 // Syntax error caused by overread. Jump to the next section.
278 FMgr.seek(StartOffset + ContentSize);
279 continue;
280 }
281
282 if (Name == "wasmedge") {
283 // Found the AOT section in universal WASM. Load the AOT code.
284 // Read the content.
285 std::vector<uint8_t> Content;
286 if (auto Res = FMgr.readBytes(ContentSize - ReadSize)) {
287 Content = std::move(*Res);
288 } else {
289 break;
290 }
291
292 // Load the AOT section.
293 FileMgr VecMgr;
294 AST::AOTSection NewAOTSection;
295 VecMgr.setCode(Content);
296 if (auto Res = loadSection(VecMgr, NewAOTSection)) {

Callers

nothing calls this directly

Calls 10

unlikelyFunction · 0.85
readByteMethod · 0.80
readU32Method · 0.80
getRemainSizeMethod · 0.80
readNameMethod · 0.80
readBytesMethod · 0.80
jumpContentMethod · 0.80
getOffsetMethod · 0.45
seekMethod · 0.45
setCodeMethod · 0.45

Tested by

no test coverage detected