diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Print.cpp | 5 | ||||
-rw-r--r-- | src/wasm-binary.h | 2 | ||||
-rw-r--r-- | src/wasm.h | 10 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 16 |
4 files changed, 29 insertions, 4 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 9ead2aee7..c46a0621d 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -735,6 +735,11 @@ struct PrintSExpression : public Visitor<PrintSExpression> { visitFunction(child.get()); o << maybeNewLine; } + for (auto& section : curr->userSections) { + doIndent(o, indent); + o << ";; custom section \"" << section.name << "\", size " << section.data.size(); + o << maybeNewLine; + } decIndent(); o << maybeNewLine; currModule = nullptr; diff --git a/src/wasm-binary.h b/src/wasm-binary.h index ecdde571e..f57d351c3 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -638,7 +638,7 @@ public: WasmBinaryBuilder(Module& wasm, std::vector<char>& input, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), debug(debug) {} void read(); - void readUserSection(); + void readUserSection(size_t payloadLen); bool more() { return pos < input.size();} uint8_t getInt8(); diff --git a/src/wasm.h b/src/wasm.h index 9807ee63c..4ad0870cc 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1528,6 +1528,14 @@ public: bool mutable_; }; +// "Opaque" data, not part of the core wasm spec, that is held in binaries. +// May be parsed/handled by utility code elsewhere, but not in wasm.h +class UserSection { +public: + std::string name; + std::vector<char> data; +}; + class Module { public: // wasm contents (generally you shouldn't access these from outside, except maybe for iterating; use add*() and the get() functions) @@ -1541,6 +1549,8 @@ public: Memory memory; Name start; + std::vector<UserSection> userSections; + MixedArena allocator; private: diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index f7fa821ea..095a0942f 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -951,7 +951,8 @@ void WasmBinaryBuilder::read() { case BinaryConsts::Section::Data: readDataSegments(); break; case BinaryConsts::Section::Table: readFunctionTableDeclaration(); break; default: { - readUserSection(); + readUserSection(payloadLen); + assert(pos <= oldPos + payloadLen); pos = oldPos + payloadLen; } } @@ -963,12 +964,21 @@ void WasmBinaryBuilder::read() { processFunctions(); } -void WasmBinaryBuilder::readUserSection() { +void WasmBinaryBuilder::readUserSection(size_t payloadLen) { + auto oldPos = pos; Name sectionName = getInlineString(); if (sectionName.equals(BinaryConsts::UserSections::Name)) { readNames(); } else { - std::cerr << "unfamiliar section: " << sectionName << std::endl; + // an unfamiliar custom section + wasm.userSections.resize(wasm.userSections.size() + 1); + auto& section = wasm.userSections.back(); + section.name = sectionName.str; + auto sectionSize = payloadLen - (pos - oldPos); + section.data.resize(sectionSize); + for (size_t i = 0; i < sectionSize; i++) { + section.data[i] = getInt8(); + } } } |