From fa4c884f4ebfde185c9d8a3ee4e54f96c57cebed Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Tue, 29 Sep 2020 17:55:28 +0200 Subject: Prototype extended-name-section proposal (#3162) Implements the parts of the Extended Name Section Proposal that are trivially applicable to Binaryen, in particular table, memory and global names. Does not yet implement label, type, elem and data names. --- src/wasm-binary.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/wasm-binary.h') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 9ac5664d3..c869adf06 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -393,6 +393,14 @@ enum Subsection { NameModule = 0, NameFunction = 1, NameLocal = 2, + // see: https://github.com/WebAssembly/extended-name-section + NameLabel = 3, + NameType = 4, + NameTable = 5, + NameMemory = 6, + NameGlobal = 7, + NameElem = 8, + NameData = 9 }; } // namespace UserSections @@ -1299,8 +1307,8 @@ public: Name getNextLabel(); - // We read functions before we know their names, so we need to backpatch the - // names later + // We read functions and globals before we know their names, so we need to + // backpatch the names later // we store functions here before wasm.addFunction after we know their names std::vector functions; @@ -1314,6 +1322,14 @@ public: // function to check Index endOfFunction = -1; + // we store globals here before wasm.addGlobal after we know their names + std::vector globals; + // we store global imports here before wasm.addGlobalImport after we know + // their names + std::vector globalImports; + // at index i we have all refs to the global i + std::map> globalRefs; + // Throws a parsing error if we are not in a function context void requireFunctionContext(const char* error); @@ -1382,7 +1398,7 @@ public: Expression* popTypedExpression(Type type); void validateBinary(); // validations that cannot be performed on the Module - void processFunctions(); + void processNames(); size_t dataCount = 0; bool hasDataCount = false; -- cgit v1.2.3