diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2022-02-09 13:33:42 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-09 21:33:42 +0000 |
commit | 89ef773d78f0b2e7818deb9d7b3c24943c512fd2 (patch) | |
tree | 6e7554e7c41ade7b4fb4e1531a9a266a1475550d /src | |
parent | 2651ffb1cbf6c8b874f4c2bc611d1a9e875724d7 (diff) | |
download | binaryen-89ef773d78f0b2e7818deb9d7b3c24943c512fd2.tar.gz binaryen-89ef773d78f0b2e7818deb9d7b3c24943c512fd2.tar.bz2 binaryen-89ef773d78f0b2e7818deb9d7b3c24943c512fd2.zip |
Make IndexedTypeNameGenerator more powerful (#4511)
Allow IndexedTypeNameGenerator to be configured with a custom prefix and also
allow it to be parameterized with an explicit fallback generator. This allows
multiple IndexedTypeNameGenerators to be composed together, for example.
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/wasm-fuzz-types.cpp | 4 | ||||
-rw-r--r-- | src/wasm-type-printing.h | 16 |
2 files changed, 15 insertions, 5 deletions
diff --git a/src/tools/wasm-fuzz-types.cpp b/src/tools/wasm-fuzz-types.cpp index 4fba27753..d2540636f 100644 --- a/src/tools/wasm-fuzz-types.cpp +++ b/src/tools/wasm-fuzz-types.cpp @@ -95,8 +95,8 @@ void Fuzzer::printTypes() { TypeNames getNames(HeapType type) { Fatal() << "trying to print unknown heap type"; } - }; - IndexedTypeNameGenerator<FatalTypeNameGenerator> print(types); + } fatalGenerator; + IndexedTypeNameGenerator<FatalTypeNameGenerator> print(types, fatalGenerator); std::unordered_map<HeapType, size_t> seen; std::optional<RecGroup> currRecGroup; auto inRecGroup = [&]() { return currRecGroup && currRecGroup->size() > 1; }; diff --git a/src/wasm-type-printing.h b/src/wasm-type-printing.h index fcf05db17..685d488fd 100644 --- a/src/wasm-type-printing.h +++ b/src/wasm-type-printing.h @@ -67,13 +67,23 @@ struct DefaultTypeNameGenerator template<typename FallbackGenerator = DefaultTypeNameGenerator> struct IndexedTypeNameGenerator : TypeNameGeneratorBase<IndexedTypeNameGenerator<FallbackGenerator>> { - FallbackGenerator fallback; + DefaultTypeNameGenerator defaultGenerator; + FallbackGenerator& fallback; std::unordered_map<HeapType, TypeNames> names; - template<typename T> IndexedTypeNameGenerator(T& types) { + + template<typename T> + IndexedTypeNameGenerator(T& types, + FallbackGenerator& fallback, + const std::string& prefix = "") + : fallback(fallback) { for (size_t i = 0; i < types.size(); ++i) { - names.insert({types[i], {std::to_string(i), {}}}); + names.insert({types[i], {prefix + std::to_string(i), {}}}); } } + template<typename T> + IndexedTypeNameGenerator(T& types, const std::string& prefix = "") + : IndexedTypeNameGenerator(types, defaultGenerator, prefix) {} + TypeNames getNames(HeapType type) { if (auto it = names.find(type); it != names.end()) { return it->second; |