diff options
author | Thomas Lively <tlively@google.com> | 2024-04-16 16:27:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-16 16:27:50 -0700 |
commit | d8dc55ceafff2c3b92d7d3e6434d56d346f8913b (patch) | |
tree | 0ccde7ed745a2d3fc54358cfadb2b38d933a5b36 /src | |
parent | 359d5aa30ca8349fd38e6968350e7ab4280c1cbb (diff) | |
download | binaryen-d8dc55ceafff2c3b92d7d3e6434d56d346f8913b.tar.gz binaryen-d8dc55ceafff2c3b92d7d3e6434d56d346f8913b.tar.bz2 binaryen-d8dc55ceafff2c3b92d7d3e6434d56d346f8913b.zip |
[Parser] Match legacy parser block naming (#6504)
To reduce the size of the test output diff when switching to the new text
parser, update it to generate the same block names as the legacy parser.
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/names.h | 8 | ||||
-rw-r--r-- | src/wasm-ir-builder.h | 10 | ||||
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 6 |
3 files changed, 17 insertions, 7 deletions
diff --git a/src/ir/names.h b/src/ir/names.h index e2a168940..c10b70b52 100644 --- a/src/ir/names.h +++ b/src/ir/names.h @@ -49,12 +49,14 @@ inline void ensureNames(Function* func) { // name will begin there. This can be used to avoid trying the same 0,1,2,.. // etc. names each time (which could lead to quadratic behavior in certain // cases). -inline Name -getValidName(Name root, std::function<bool(Name)> check, Index hint = 0) { +inline Name getValidName(Name root, + std::function<bool(Name)> check, + Index hint = 0, + std::string separator = "_") { if (check(root)) { return root; } - auto prefixed = std::string(root.str) + '_'; + auto prefixed = std::string(root.str) + separator; Index num = hint; while (1) { auto name = prefixed + std::to_string(num); diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h index 3b6588e86..5803f0c61 100644 --- a/src/wasm-ir-builder.h +++ b/src/wasm-ir-builder.h @@ -461,9 +461,13 @@ private: std::unordered_map<Name, std::vector<Index>> labelDepths; Name makeFresh(Name label) { - return Names::getValidName(label, [&](Name candidate) { - return labelDepths.insert({candidate, {}}).second; - }); + return Names::getValidName( + label, + [&](Name candidate) { + return labelDepths.insert({candidate, {}}).second; + }, + 0, + ""); } void pushScope(ScopeCtx scope) { diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index bee858435..78ce07f8d 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -1035,7 +1035,11 @@ Result<Name> IRBuilder::getLabelName(Index label) { auto& scopeLabel = (*scope)->label; if (!scopeLabel) { // The scope does not already have a name, so we need to create one. - scopeLabel = makeFresh("label"); + if ((*scope)->getBlock()) { + scopeLabel = makeFresh("block"); + } else { + scopeLabel = makeFresh("label"); + } } (*scope)->labelUsed = true; return scopeLabel; |