diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/names.h | 53 | ||||
-rw-r--r-- | src/passes/I64ToI32Lowering.cpp | 2 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/ir/names.h b/src/ir/names.h new file mode 100644 index 000000000..a589571bf --- /dev/null +++ b/src/ir/names.h @@ -0,0 +1,53 @@ +/* + * Copyright 2017 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. + */ + +#ifndef wasm_ir_names_h +#define wasm_ir_names_h + +#include "wasm.h" + +namespace wasm { + +namespace Names { + +// Add explicit names for function locals not yet named, and do not +// modify existing names +inline void ensureNames(Function* func) { + std::unordered_set<Name> seen; + for (auto& pair : func->localNames) { + seen.insert(pair.second); + } + Index nameIndex = seen.size(); + for (Index i = 0; i < func->getNumLocals(); i++) { + if (!func->hasLocalName(i)) { + while (1) { + auto name = Name::fromInt(nameIndex++); + if (seen.count(name) == 0) { + func->localNames[i] = name; + func->localIndices[name] = i; + seen.insert(name); + break; + } + } + } + } +} + +} // namespace Names + +} // namespace wasm + +#endif // wasm_ir_names_h diff --git a/src/passes/I64ToI32Lowering.cpp b/src/passes/I64ToI32Lowering.cpp index 0b476bb15..a9ac2da82 100644 --- a/src/passes/I64ToI32Lowering.cpp +++ b/src/passes/I64ToI32Lowering.cpp @@ -27,6 +27,7 @@ #include "emscripten-optimizer/istring.h" #include "support/name.h" #include "wasm-builder.h" +#include "ir/names.h" namespace wasm { @@ -140,6 +141,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { func->localNames.clear(); func->localIndices.clear(); Index newIdx = 0; + Names::ensureNames(&oldFunc); for (Index i = 0; i < oldFunc.getNumLocals(); ++i) { assert(oldFunc.hasLocalName(i)); Name lowName = oldFunc.getLocalName(i); |