Use the top level namer in the SPIR-V backend.
This CL updates the SPIR-V backend to use the top level namer.
Change-Id: I67566d7674d5366c82c99d6fbb985805a2a9a5b4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36720
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index 5423d60..78f6158 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -278,7 +278,8 @@
Builder::AccessorInfo::~AccessorInfo() {}
-Builder::Builder(ast::Module* mod) : mod_(mod), scope_stack_({}) {}
+Builder::Builder(ast::Module* mod)
+ : mod_(mod), namer_(std::make_unique<UnsafeNamer>(mod)), scope_stack_({}) {}
Builder::~Builder() = default;
@@ -539,7 +540,8 @@
auto func_id = func_op.to_i();
push_debug(spv::Op::OpName,
- {Operand::Int(func_id), Operand::String(func->name())});
+ {Operand::Int(func_id),
+ Operand::String(namer_->NameFor(func->symbol()))});
auto ret_id = GenerateTypeIfNeeded(func->return_type());
if (ret_id == 0) {
@@ -564,7 +566,8 @@
}
push_debug(spv::Op::OpName,
- {Operand::Int(param_id), Operand::String(param->name())});
+ {Operand::Int(param_id),
+ Operand::String(namer_->NameFor(param->symbol()))});
params.push_back(Instruction{spv::Op::OpFunctionParameter,
{Operand::Int(param_type_id), param_op}});
@@ -654,8 +657,9 @@
return false;
}
- push_debug(spv::Op::OpName,
- {Operand::Int(var_id), Operand::String(var->name())});
+ push_debug(
+ spv::Op::OpName,
+ {Operand::Int(var_id), Operand::String(namer_->NameFor(var->symbol()))});
// TODO(dsinclair) We could detect if the constructor is fully const and emit
// an initializer value for the variable instead of doing the OpLoad.
@@ -706,7 +710,8 @@
return false;
}
push_debug(spv::Op::OpName,
- {Operand::Int(init_id), Operand::String(var->name())});
+ {Operand::Int(init_id),
+ Operand::String(namer_->NameFor(var->symbol()))});
scope_stack_.set_global(var->symbol(), init_id);
spirv_id_to_variable_[init_id] = var;
@@ -726,8 +731,9 @@
return false;
}
- push_debug(spv::Op::OpName,
- {Operand::Int(var_id), Operand::String(var->name())});
+ push_debug(
+ spv::Op::OpName,
+ {Operand::Int(var_id), Operand::String(namer_->NameFor(var->symbol()))});
auto* type = var->type()->UnwrapAll();
@@ -2784,7 +2790,8 @@
if (!struct_type->name().empty()) {
push_debug(spv::Op::OpName,
- {Operand::Int(struct_id), Operand::String(struct_type->name())});
+ {Operand::Int(struct_id),
+ Operand::String(namer_->NameFor(struct_type->symbol()))});
}
OperandList ops;
diff --git a/src/writer/spirv/builder.h b/src/writer/spirv/builder.h
index aad13ba..451c961 100644
--- a/src/writer/spirv/builder.h
+++ b/src/writer/spirv/builder.h
@@ -16,6 +16,7 @@
#define SRC_WRITER_SPIRV_BUILDER_H_
#include <functional>
+#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
@@ -51,6 +52,7 @@
#include "src/ast/type_constructor_expression.h"
#include "src/ast/unary_op_expression.h"
#include "src/ast/variable_decl_statement.h"
+#include "src/namer.h"
#include "src/scope_stack.h"
#include "src/writer/spirv/function.h"
#include "src/writer/spirv/instruction.h"
@@ -499,6 +501,7 @@
}
ast::Module* mod_;
+ std::unique_ptr<Namer> namer_;
std::string error_;
uint32_t next_id_ = 1;
uint32_t current_label_id_ = 0;