From fab26d37f7e107596bd733d70d2330410eae24cf Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 21 Dec 2015 13:02:35 -0800 Subject: parse imports early, as they may be at the end --- src/wasm-s-parser.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 6061dacc5..1a4b96be4 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -222,6 +222,7 @@ public: functionCounter = 0; for (unsigned i = 1; i < module.size(); i++) { preParseFunctionType(*module[i]); + preParseImports(*module[i]); } functionCounter = 0; for (unsigned i = 1; i < module.size(); i++) { @@ -263,12 +264,17 @@ private: functionTypes[name] = none; } + void preParseImports(Element& curr) { + IString id = curr[0]->str(); + if (id == IMPORT) parseImport(curr); + } + void parseModuleElement(Element& curr) { IString id = curr[0]->str(); if (id == FUNC) return parseFunction(curr); if (id == MEMORY) return parseMemory(curr); if (id == EXPORT) return parseExport(curr); - if (id == IMPORT) return parseImport(curr); + if (id == IMPORT) return; // already done if (id == TABLE) return parseTable(curr); if (id == TYPE) return; // already done std::cerr << "bad module element " << id.str << '\n'; -- cgit v1.2.3