diff options
-rw-r--r-- | src/wasm-binary.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 081924ba0..2ce460c6f 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -386,6 +386,7 @@ public: } void write() { + writeHeader(); writeStart(); writeMemory(); writeSignatures(); @@ -396,6 +397,12 @@ public: finishUp(); } + void writeHeader() { + if (debug) std::cerr << "== writeStart" << std::endl; + o << int32_t(0x6d736100); // magic number \0asm + o << int32_t(10); // version number + } + void writeStart() { if (!wasm->start.is()) return; if (debug) std::cerr << "== writeStart" << std::endl; @@ -966,6 +973,8 @@ public: WasmBinaryBuilder(AllocatingModule& wasm, std::vector<char>& input, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), debug(debug), pos(0) {} void read() { + readHeader(); + // read sections until the end while (1) { int8_t section = getInt8(); @@ -1085,6 +1094,11 @@ public: pos--; } + void readHeader() { + verifyInt32(0x6d736100); + verifyInt32(10); + } + void readStart() { if (debug) std::cerr << "== readStart" << std::endl; wasm.start = getString(); |