diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/passes/NameTypes.cpp | 49 | ||||
-rw-r--r-- | src/passes/pass.cpp | 1 | ||||
-rw-r--r-- | src/passes/passes.h | 1 |
4 files changed, 52 insertions, 0 deletions
diff --git a/src/passes/CMakeLists.txt b/src/passes/CMakeLists.txt index e49afcde3..906871b91 100644 --- a/src/passes/CMakeLists.txt +++ b/src/passes/CMakeLists.txt @@ -45,6 +45,7 @@ set(passes_SOURCES Metrics.cpp MinifyImportsAndExports.cpp NameList.cpp + NameTypes.cpp NoExitRuntime.cpp OptimizeAddedConstants.cpp OptimizeInstructions.cpp diff --git a/src/passes/NameTypes.cpp b/src/passes/NameTypes.cpp new file mode 100644 index 000000000..2939f9ad5 --- /dev/null +++ b/src/passes/NameTypes.cpp @@ -0,0 +1,49 @@ +/* + * Copyright 2021 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ir/module-utils.h" +#include "pass.h" +#include "wasm.h" + +// +// Ensures each type has a name. This can be useful for debugging. +// +// TODO: keep existing useful (short-enough) names, and just replace ones that +// are bothersome +// + +using namespace std; + +namespace wasm { + +struct NameTypes : public Pass { + void run(PassRunner* runner, Module* module) override { + // Find all the types. + std::vector<HeapType> types; + std::unordered_map<HeapType, Index> typeIndices; + ModuleUtils::collectHeapTypes(*module, types, typeIndices); + + // Ensure simple names. + size_t i = 0; + for (auto& type : types) { + module->typeNames[type].name = "type$" + std::to_string(i++); + } + } +}; + +Pass* createNameTypesPass() { return new NameTypes(); } + +} // namespace wasm diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 6dd9926f6..72c415ed8 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -217,6 +217,7 @@ void PassRegistry::registerPasses() { "apply the assumption that asyncify never unwinds", createModAsyncifyNeverUnwindPass); registerPass("nm", "name list", createNameListPass); + registerPass("name-types", "(re)name all heap types", createNameTypesPass); registerPass("no-exit-runtime", "removes calls to atexit(), which is valid if the C runtime " "will never be exited", diff --git a/src/passes/passes.h b/src/passes/passes.h index c844ec485..93f986773 100644 --- a/src/passes/passes.h +++ b/src/passes/passes.h @@ -71,6 +71,7 @@ Pass* createMinifyImportsAndExportsPass(); Pass* createMinifyImportsAndExportsAndModulesPass(); Pass* createMetricsPass(); Pass* createNameListPass(); +Pass* createNameTypesPass(); Pass* createNoExitRuntimePass(); Pass* createOptimizeAddedConstantsPass(); Pass* createOptimizeAddedConstantsPropagatePass(); |