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>
This commit is contained in:
parent
e6fda61ef0
commit
9ab6e8b9eb
|
@ -614,8 +614,11 @@ bool FunctionEmitter::EmitFunctionDeclaration() {
|
||||||
[this, &ast_params](const spvtools::opt::Instruction* param) {
|
[this, &ast_params](const spvtools::opt::Instruction* param) {
|
||||||
auto* ast_type = parser_impl_.ConvertType(param->type_id());
|
auto* ast_type = parser_impl_.ConvertType(param->type_id());
|
||||||
if (ast_type != nullptr) {
|
if (ast_type != nullptr) {
|
||||||
ast_params.emplace_back(parser_impl_.MakeVariable(
|
auto ast_param = parser_impl_.MakeVariable(
|
||||||
param->result_id(), ast::StorageClass::kNone, ast_type));
|
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.
|
// The value is accessible by name.
|
||||||
identifier_values_.insert(param->result_id());
|
identifier_values_.insert(param->result_id());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -219,12 +219,12 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
|
||||||
EXPECT_THAT(module_ast_str, HasSubstr(R"(Module{
|
EXPECT_THAT(module_ast_str, HasSubstr(R"(Module{
|
||||||
Function x_50 -> __u32
|
Function x_50 -> __u32
|
||||||
(
|
(
|
||||||
Variable{
|
VariableConst{
|
||||||
x_51
|
x_51
|
||||||
none
|
none
|
||||||
__u32
|
__u32
|
||||||
}
|
}
|
||||||
Variable{
|
VariableConst{
|
||||||
x_52
|
x_52
|
||||||
none
|
none
|
||||||
__u32
|
__u32
|
||||||
|
|
|
@ -104,17 +104,17 @@ TEST_F(SpvParserTest, EmitFunctionDeclaration_MixedParamTypes) {
|
||||||
EXPECT_THAT(p->module().to_str(), HasSubstr(R"(
|
EXPECT_THAT(p->module().to_str(), HasSubstr(R"(
|
||||||
Function x_100 -> __void
|
Function x_100 -> __void
|
||||||
(
|
(
|
||||||
Variable{
|
VariableConst{
|
||||||
a
|
a
|
||||||
none
|
none
|
||||||
__u32
|
__u32
|
||||||
}
|
}
|
||||||
Variable{
|
VariableConst{
|
||||||
b
|
b
|
||||||
none
|
none
|
||||||
__f32
|
__f32
|
||||||
}
|
}
|
||||||
Variable{
|
VariableConst{
|
||||||
c
|
c
|
||||||
none
|
none
|
||||||
__i32
|
__i32
|
||||||
|
@ -143,17 +143,17 @@ TEST_F(SpvParserTest, EmitFunctionDeclaration_GenerateParamNames) {
|
||||||
EXPECT_THAT(p->module().to_str(), HasSubstr(R"(
|
EXPECT_THAT(p->module().to_str(), HasSubstr(R"(
|
||||||
Function x_100 -> __void
|
Function x_100 -> __void
|
||||||
(
|
(
|
||||||
Variable{
|
VariableConst{
|
||||||
x_14
|
x_14
|
||||||
none
|
none
|
||||||
__u32
|
__u32
|
||||||
}
|
}
|
||||||
Variable{
|
VariableConst{
|
||||||
x_15
|
x_15
|
||||||
none
|
none
|
||||||
__f32
|
__f32
|
||||||
}
|
}
|
||||||
Variable{
|
VariableConst{
|
||||||
x_16
|
x_16
|
||||||
none
|
none
|
||||||
__i32
|
__i32
|
||||||
|
|
|
@ -293,17 +293,17 @@ TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) {
|
||||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||||
Function mixed_params -> __void
|
Function mixed_params -> __void
|
||||||
(
|
(
|
||||||
Variable{
|
VariableConst{
|
||||||
a
|
a
|
||||||
none
|
none
|
||||||
__u32
|
__u32
|
||||||
}
|
}
|
||||||
Variable{
|
VariableConst{
|
||||||
b
|
b
|
||||||
none
|
none
|
||||||
__f32
|
__f32
|
||||||
}
|
}
|
||||||
Variable{
|
VariableConst{
|
||||||
c
|
c
|
||||||
none
|
none
|
||||||
__i32
|
__i32
|
||||||
|
@ -332,17 +332,17 @@ TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) {
|
||||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||||
Function mixed_params -> __void
|
Function mixed_params -> __void
|
||||||
(
|
(
|
||||||
Variable{
|
VariableConst{
|
||||||
x_14
|
x_14
|
||||||
none
|
none
|
||||||
__u32
|
__u32
|
||||||
}
|
}
|
||||||
Variable{
|
VariableConst{
|
||||||
x_15
|
x_15
|
||||||
none
|
none
|
||||||
__f32
|
__f32
|
||||||
}
|
}
|
||||||
Variable{
|
VariableConst{
|
||||||
x_16
|
x_16
|
||||||
none
|
none
|
||||||
__i32
|
__i32
|
||||||
|
|
Loading…
Reference in New Issue