mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-05 04:36:02 +00:00
Register the name of 'var' and 'let' variables when building the IR. Use the names of these variables when printing the disassembly. Change-Id: I56ee24a29333f1bc8f97459bc1cfca5c3a59e79d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/131741 Auto-Submit: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
// Copyright 2022 The Tint Authors.
|
|
//
|
|
// 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 "src/tint/ir/module.h"
|
|
|
|
#include <limits>
|
|
|
|
namespace tint::ir {
|
|
|
|
Module::Module() = default;
|
|
|
|
Module::Module(Module&&) = default;
|
|
|
|
Module::~Module() = default;
|
|
|
|
Module& Module::operator=(Module&&) = default;
|
|
|
|
Symbol Module::NameOf(const Value* value) const {
|
|
return value_to_id_.Get(value).value_or(Symbol{});
|
|
}
|
|
|
|
Symbol Module::SetName(const Value* value, std::string_view name) {
|
|
TINT_ASSERT(IR, !name.empty());
|
|
|
|
if (auto old = value_to_id_.Get(value)) {
|
|
value_to_id_.Remove(value);
|
|
id_to_value_.Remove(old.value());
|
|
}
|
|
|
|
auto sym = symbols.Register(name);
|
|
if (id_to_value_.Add(sym, value)) {
|
|
value_to_id_.Add(value, sym);
|
|
return sym;
|
|
}
|
|
auto prefix = std::string(name) + "_";
|
|
for (uint64_t suffix = 1; suffix != std::numeric_limits<uint64_t>::max(); suffix++) {
|
|
sym = symbols.Register(prefix + std::to_string(suffix));
|
|
if (id_to_value_.Add(sym, value)) {
|
|
value_to_id_.Add(value, sym);
|
|
return sym;
|
|
}
|
|
}
|
|
TINT_ASSERT(IR, false); // !
|
|
return Symbol{};
|
|
}
|
|
|
|
} // namespace tint::ir
|