spirv-reader: treat function parameters as const declarations
Change-Id: I5e5f35be15737c6dc46bb2e9dc1319f7c403eab8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30921
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc
index 963a33d..9c62f9b 100644
--- a/src/reader/spirv/function.cc
+++ b/src/reader/spirv/function.cc
@@ -614,8 +614,11 @@
[this, &ast_params](const spvtools::opt::Instruction* param) {
auto* ast_type = parser_impl_.ConvertType(param->type_id());
if (ast_type != nullptr) {
- ast_params.emplace_back(parser_impl_.MakeVariable(
- param->result_id(), ast::StorageClass::kNone, ast_type));
+ auto ast_param = parser_impl_.MakeVariable(
+ param->result_id(), ast::StorageClass::kNone, ast_type);
+ // Parameters are treated as const declarations.
+ ast_param->set_is_const(true);
+ ast_params.emplace_back(std::move(ast_param));
// The value is accessible by name.
identifier_values_.insert(param->result_id());
} else {
diff --git a/src/reader/spirv/function_call_test.cc b/src/reader/spirv/function_call_test.cc
index 4eb8288..934bb5c 100644
--- a/src/reader/spirv/function_call_test.cc
+++ b/src/reader/spirv/function_call_test.cc
@@ -219,12 +219,12 @@
EXPECT_THAT(module_ast_str, HasSubstr(R"(Module{
Function x_50 -> __u32
(
- Variable{
+ VariableConst{
x_51
none
__u32
}
- Variable{
+ VariableConst{
x_52
none
__u32
diff --git a/src/reader/spirv/function_decl_test.cc b/src/reader/spirv/function_decl_test.cc
index 20e5b1b..6142726 100644
--- a/src/reader/spirv/function_decl_test.cc
+++ b/src/reader/spirv/function_decl_test.cc
@@ -104,17 +104,17 @@
EXPECT_THAT(p->module().to_str(), HasSubstr(R"(
Function x_100 -> __void
(
- Variable{
+ VariableConst{
a
none
__u32
}
- Variable{
+ VariableConst{
b
none
__f32
}
- Variable{
+ VariableConst{
c
none
__i32
@@ -143,17 +143,17 @@
EXPECT_THAT(p->module().to_str(), HasSubstr(R"(
Function x_100 -> __void
(
- Variable{
+ VariableConst{
x_14
none
__u32
}
- Variable{
+ VariableConst{
x_15
none
__f32
}
- Variable{
+ VariableConst{
x_16
none
__i32
diff --git a/src/reader/spirv/parser_impl_function_decl_test.cc b/src/reader/spirv/parser_impl_function_decl_test.cc
index 37af744..0d0c826 100644
--- a/src/reader/spirv/parser_impl_function_decl_test.cc
+++ b/src/reader/spirv/parser_impl_function_decl_test.cc
@@ -293,17 +293,17 @@
EXPECT_THAT(module_ast, HasSubstr(R"(
Function mixed_params -> __void
(
- Variable{
+ VariableConst{
a
none
__u32
}
- Variable{
+ VariableConst{
b
none
__f32
}
- Variable{
+ VariableConst{
c
none
__i32
@@ -332,17 +332,17 @@
EXPECT_THAT(module_ast, HasSubstr(R"(
Function mixed_params -> __void
(
- Variable{
+ VariableConst{
x_14
none
__u32
}
- Variable{
+ VariableConst{
x_15
none
__f32
}
- Variable{
+ VariableConst{
x_16
none
__i32