diff options
author | Thomas Lively <tlively@google.com> | 2024-02-08 16:19:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-08 16:19:40 -0800 |
commit | 90087f0972aa34ee37860b70072cb8fc33c89ce3 (patch) | |
tree | 7a56e60f9798299135563e4c8e725ceb1dd3a773 /src/parser/wat-parser.cpp | |
parent | f5d8d30171e53c225fc640e6db8aa42973c8804c (diff) | |
download | binaryen-90087f0972aa34ee37860b70072cb8fc33c89ce3.tar.gz binaryen-90087f0972aa34ee37860b70072cb8fc33c89ce3.tar.bz2 binaryen-90087f0972aa34ee37860b70072cb8fc33c89ce3.zip |
[Parser] Support references to struct fields by name (#6293)
Construct a mapping from heap type and field name to field index, then use it
while parsing instructions.
Diffstat (limited to 'src/parser/wat-parser.cpp')
-rw-r--r-- | src/parser/wat-parser.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/parser/wat-parser.cpp b/src/parser/wat-parser.cpp index 50a47d7b6..33066ea71 100644 --- a/src/parser/wat-parser.cpp +++ b/src/parser/wat-parser.cpp @@ -110,6 +110,7 @@ Result<> parseModule(Module& wasm, std::string_view input) { // Parse type definitions. std::vector<HeapType> types; + std::unordered_map<HeapType, std::unordered_map<Name, Index>> typeNames; { TypeBuilder builder(decls.subtypeDefs.size()); ParseTypeDefsCtx ctx(input, builder, *typeIndices); @@ -124,11 +125,16 @@ Result<> parseModule(Module& wasm, std::string_view input) { return ctx.in.err(decls.typeDefs[err->index].pos, msg.str()); } types = *built; - // Record type names on the module. + // Record type names on the module and in typeNames. for (size_t i = 0; i < types.size(); ++i) { auto& names = ctx.names[i]; - if (names.name.is() || names.fieldNames.size()) { + auto& fieldNames = names.fieldNames; + if (names.name.is() || fieldNames.size()) { wasm.typeNames.insert({types[i], names}); + auto& fieldIdxMap = typeNames[types[i]]; + for (auto [idx, name] : fieldNames) { + fieldIdxMap.insert({name, idx}); + } } } } @@ -167,6 +173,7 @@ Result<> parseModule(Module& wasm, std::string_view input) { wasm, types, implicitTypes, + typeNames, decls.implicitElemIndices, *typeIndices); CHECK_ERR(parseDefs(ctx, decls.tableDefs, table)); |