[spirv-reader] Store to module-scope variables

Bug: tint:3
Change-Id: Ib4dbb976268999529c2a1c55531aa8293e565b9c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19222
Reviewed-by: dan sinclair <dsinclair@google.com>
This commit is contained in:
David Neto 2020-04-14 14:23:59 +00:00 committed by dan sinclair
parent b39dabd0cd
commit 2a3e79cf8c
2 changed files with 26 additions and 0 deletions

View File

@ -209,6 +209,10 @@ std::unique_ptr<ast::Expression> FunctionEmitter::MakeExpression(uint32_t id) {
return nullptr;
}
switch (inst->opcode()) {
case SpvOpVariable:
// This occurs for module-scope variables.
return std::make_unique<ast::IdentifierExpression>(
namer_.Name(inst->result_id()));
default:
break;
}

View File

@ -257,6 +257,28 @@ Assignment{
)"));
}
TEST_F(SpvParserTest, EmitStatement_StoreToModuleScopeVar) {
auto p = parser(test::Assemble(R"(
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%ty = OpTypeInt 32 0
%val = OpConstant %ty 42
%ptr_ty = OpTypePointer Workgroup %ty
%1 = OpVariable %ptr_ty Workgroup
%100 = OpFunction %void None %voidfn
%entry = OpLabel
OpStore %1 %val
OpReturn
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p, *spirv_function(100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{
Identifier{x_1}
ScalarConstructor{42}
})"));
}
} // namespace
} // namespace spirv
} // namespace reader