MCPcopy Create free account
hub / github.com/WasmVM/WasmVM / module_decode

Method module_decode

src/lib/decode/decode.cpp:13–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11using namespace Decode;
12
13WasmModule WasmVM::module_decode(std::istream& istream){
14 // Check magic & version
15 {
16 u32_t data;
17 istream.read((char*) &data, sizeof(u32_t));
18 if(data != Decode::magic){
19 throw Exception::incorrect_magic();
20 }
21 istream.read((char*) &data, sizeof(u32_t));
22 if(data != Decode::version){
23 throw Exception::incorrect_magic();
24 }
25 }
26
27 WasmModule module;
28 Decode::Stream stream(istream, module);
29 // Types
30 stream >> Decode::Type(module.types);
31 // Imports
32 stream >> Decode::Import(module.imports);
33 // Funcs
34 stream >> Decode::Func(module.funcs);
35 // Tables
36 stream >> Decode::Table(module.tables);
37 // Mems
38 stream >> Decode::Memory(module.mems);
39 // Tags
40 stream >> Decode::Tag(module.tags);
41 // Globals
42 stream >> Decode::Global(module.globals);
43 // Exports
44 stream >> Decode::Export(module.exports);
45 // Start
46 stream >> Decode::Start(module.start);
47 // Elems
48 stream >> Decode::Elem(module.elems);
49 // Data count
50 stream >> Decode::DataCount(module.datas);
51 // Code
52 stream >> Decode::Code(module.funcs);
53 // Datas
54 stream >> Decode::Data(module.datas);
55 return module;
56}
57
58byte_t Decode::Stream::peek(){
59 return (byte_t)istream.peek();

Callers

nothing calls this directly

Calls 14

incorrect_magicClass · 0.85
TagClass · 0.85
TypeClass · 0.50
ImportClass · 0.50
FuncClass · 0.50
TableClass · 0.50
MemoryClass · 0.50
GlobalClass · 0.50
ExportClass · 0.50
StartClass · 0.50
ElemClass · 0.50
DataCountClass · 0.50

Tested by

no test coverage detected