Use TestNamer in the SPIR-V backend.

This CL updates the SPIR-V generation tests to use the TestNamer.

Change-Id: I6a1d9a4c41f080ba3518509864bb06f1629ab0a9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36941
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair 2021-01-11 16:24:32 +00:00 committed by dan sinclair
parent f4bc0e7337
commit 7d152e0936
15 changed files with 164 additions and 152 deletions

View File

@ -278,8 +278,8 @@ Builder::AccessorInfo::AccessorInfo() : source_id(0), source_type(nullptr) {}
Builder::AccessorInfo::~AccessorInfo() {} Builder::AccessorInfo::~AccessorInfo() {}
Builder::Builder(ast::Module* mod) Builder::Builder(ast::Module* mod, Namer* namer)
: mod_(mod), namer_(std::make_unique<UnsafeNamer>(mod)), scope_stack_({}) {} : mod_(mod), namer_(namer), scope_stack_({}) {}
Builder::~Builder() = default; Builder::~Builder() = default;

View File

@ -85,7 +85,8 @@ class Builder {
/// Constructor /// Constructor
/// @param mod the module to generate from /// @param mod the module to generate from
explicit Builder(ast::Module* mod); /// @param namer the namer to use
Builder(ast::Module* mod, Namer* namer);
~Builder(); ~Builder();
/// Generates the SPIR-V instructions for the given module /// Generates the SPIR-V instructions for the given module
@ -491,7 +492,7 @@ class Builder {
Operand result_op(); Operand result_op();
ast::Module* mod_; ast::Module* mod_;
std::unique_ptr<Namer> namer_; Namer* namer_ = nullptr;
std::string error_; std::string error_;
uint32_t next_id_ = 1; uint32_t next_id_ = 1;
uint32_t current_label_id_ = 0; uint32_t current_label_id_ = 0;

View File

@ -61,10 +61,10 @@ TEST_F(BuilderTest, Expression_Call) {
ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(b.GenerateCallExpression(expr), 14u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 14u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "test_a_func"
OpName %4 "a" OpName %4 "test_a"
OpName %5 "b" OpName %5 "test_b"
OpName %12 "main" OpName %12 "test_main"
%2 = OpTypeFloat 32 %2 = OpTypeFloat 32
%1 = OpTypeFunction %2 %2 %2 %1 = OpTypeFunction %2 %2 %2
%11 = OpTypeVoid %11 = OpTypeVoid
@ -110,10 +110,10 @@ TEST_F(BuilderTest, Statement_Call) {
ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_TRUE(b.GenerateStatement(expr)) << b.error(); EXPECT_TRUE(b.GenerateStatement(expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func" EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "test_a_func"
OpName %5 "a" OpName %5 "test_a"
OpName %6 "b" OpName %6 "test_b"
OpName %12 "main" OpName %12 "test_main"
%2 = OpTypeVoid %2 = OpTypeVoid
%3 = OpTypeFloat 32 %3 = OpTypeFloat 32
%1 = OpTypeFunction %2 %3 %3 %1 = OpTypeFunction %2 %3 %3

View File

@ -45,7 +45,7 @@ TEST_F(BuilderTest, FunctionDecoration_Stage) {
ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.entry_points()), EXPECT_EQ(DumpInstructions(b.entry_points()),
R"(OpEntryPoint Vertex %3 "main" R"(OpEntryPoint Vertex %3 "test_main"
)"); )");
} }
@ -105,10 +105,10 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
mod->AddGlobalVariable(v_wg); mod->AddGlobalVariable(v_wg);
ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_in" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_my_in"
OpName %4 "my_out" OpName %4 "test_my_out"
OpName %7 "my_wg" OpName %7 "test_my_wg"
OpName %11 "main" OpName %11 "test_main"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Input %3 %2 = OpTypePointer Input %3
@ -122,7 +122,7 @@ OpName %11 "main"
%9 = OpTypeFunction %10 %9 = OpTypeFunction %10
)"); )");
EXPECT_EQ(DumpInstructions(b.entry_points()), EXPECT_EQ(DumpInstructions(b.entry_points()),
R"(OpEntryPoint Vertex %11 "main" R"(OpEntryPoint Vertex %11 "test_main"
)"); )");
} }
@ -158,10 +158,10 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
mod->AddGlobalVariable(v_wg); mod->AddGlobalVariable(v_wg);
ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_in" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_my_in"
OpName %4 "my_out" OpName %4 "test_my_out"
OpName %7 "my_wg" OpName %7 "test_my_wg"
OpName %11 "main" OpName %11 "test_main"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Input %3 %2 = OpTypePointer Input %3
@ -175,7 +175,7 @@ OpName %11 "main"
%9 = OpTypeFunction %10 %9 = OpTypeFunction %10
)"); )");
EXPECT_EQ(DumpInstructions(b.entry_points()), EXPECT_EQ(DumpInstructions(b.entry_points()),
R"(OpEntryPoint Vertex %11 "main" %4 %1 R"(OpEntryPoint Vertex %11 "test_main" %4 %1
)"); )");
} }
@ -235,12 +235,12 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) {
ASSERT_TRUE(b.GenerateFunction(func1)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func1)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func2)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func2)) << b.error();
EXPECT_EQ(DumpBuilder(b), EXPECT_EQ(DumpBuilder(b),
R"(OpEntryPoint Fragment %3 "main1" R"(OpEntryPoint Fragment %3 "test_main1"
OpEntryPoint Fragment %5 "main2" OpEntryPoint Fragment %5 "test_main2"
OpExecutionMode %3 OriginUpperLeft OpExecutionMode %3 OriginUpperLeft
OpExecutionMode %5 OriginUpperLeft OpExecutionMode %5 OriginUpperLeft
OpName %3 "main1" OpName %3 "test_main1"
OpName %5 "main2" OpName %5 "test_main2"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%3 = OpFunction %2 None %1 %3 = OpFunction %2 None %1

View File

@ -50,7 +50,7 @@ TEST_F(BuilderTest, Function_Empty) {
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(func)); ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%3 = OpFunction %2 None %1 %3 = OpFunction %2 None %1
@ -68,7 +68,7 @@ TEST_F(BuilderTest, Function_Terminator_Return) {
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(func)); ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%3 = OpFunction %2 None %1 %3 = OpFunction %2 None %1
@ -89,8 +89,8 @@ TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
ASSERT_TRUE(td.DetermineFunction(func)) << td.error(); ASSERT_TRUE(td.DetermineFunction(func)) << td.error();
ASSERT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "a" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_a"
OpName %7 "a_func" OpName %7 "test_a_func"
%3 = OpTypeFloat 32 %3 = OpTypeFloat 32
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3
@ -113,7 +113,7 @@ TEST_F(BuilderTest, Function_Terminator_Discard) {
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(func)); ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%3 = OpFunction %2 None %1 %3 = OpFunction %2 None %1
@ -136,9 +136,9 @@ TEST_F(BuilderTest, Function_WithParams) {
EXPECT_TRUE(td.DetermineFunction(func)); EXPECT_TRUE(td.DetermineFunction(func));
ASSERT_TRUE(b.GenerateFunction(func)); ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func" EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "test_a_func"
OpName %5 "a" OpName %5 "test_a"
OpName %6 "b" OpName %6 "test_b"
%2 = OpTypeFloat 32 %2 = OpTypeFloat 32
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%1 = OpTypeFunction %2 %2 %3 %1 = OpTypeFunction %2 %2 %3
@ -160,7 +160,7 @@ TEST_F(BuilderTest, Function_WithBody) {
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
ASSERT_TRUE(b.GenerateFunction(func)); ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%3 = OpFunction %2 None %1 %3 = OpFunction %2 None %1
@ -269,17 +269,17 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
ASSERT_TRUE(b.Build()); ASSERT_TRUE(b.Build());
EXPECT_EQ(DumpBuilder(b), R"(OpCapability Shader EXPECT_EQ(DumpBuilder(b), R"(OpCapability Shader
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %7 "a" OpEntryPoint GLCompute %7 "test_a"
OpEntryPoint GLCompute %17 "b" OpEntryPoint GLCompute %17 "test_b"
OpExecutionMode %7 LocalSize 1 1 1 OpExecutionMode %7 LocalSize 1 1 1
OpExecutionMode %17 LocalSize 1 1 1 OpExecutionMode %17 LocalSize 1 1 1
OpName %3 "Data" OpName %3 "test_Data"
OpMemberName %3 0 "d" OpMemberName %3 0 "test_d"
OpName %1 "data" OpName %1 "test_data"
OpName %7 "a" OpName %7 "test_a"
OpName %14 "v" OpName %14 "test_v"
OpName %17 "b" OpName %17 "test_b"
OpName %21 "v" OpName %21 "test_v"
OpDecorate %3 Block OpDecorate %3 Block
OpMemberDecorate %3 0 Offset 0 OpMemberDecorate %3 0 Offset 0
OpDecorate %1 Binding 0 OpDecorate %1 Binding 0

View File

@ -49,7 +49,7 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
b.push_function(Function{}); b.push_function(Function{});
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Function %3 %2 = OpTypePointer Function %3
@ -74,7 +74,7 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3 %1 = OpTypeVector %2 3
@ -103,7 +103,7 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %7 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %7 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 2 %1 = OpTypeVector %2 2
@ -142,8 +142,8 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructorLoadedFromVar) {
EXPECT_TRUE(b.GenerateFunctionVariable(v2)) << b.error(); EXPECT_TRUE(b.GenerateFunctionVariable(v2)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "v" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_v"
OpName %7 "v2" OpName %7 "test_v2"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 1 %2 = OpConstant %1 1
@ -181,8 +181,8 @@ TEST_F(BuilderTest, FunctionVar_ConstWithVarInitializer) {
EXPECT_TRUE(b.GenerateFunctionVariable(v2)) << b.error(); EXPECT_TRUE(b.GenerateFunctionVariable(v2)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "v" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_v"
OpName %7 "v2" OpName %7 "test_v2"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 1 %2 = OpConstant %1 1

View File

@ -52,7 +52,7 @@ using BuilderTest = TestHelper;
TEST_F(BuilderTest, GlobalVar_NoStorageClass) { TEST_F(BuilderTest, GlobalVar_NoStorageClass) {
auto* v = Var("var", ast::StorageClass::kNone, ty.f32); auto* v = Var("var", ast::StorageClass::kNone, ty.f32);
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
@ -64,7 +64,7 @@ TEST_F(BuilderTest, GlobalVar_NoStorageClass) {
TEST_F(BuilderTest, GlobalVar_WithStorageClass) { TEST_F(BuilderTest, GlobalVar_WithStorageClass) {
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32); auto* v = Var("var", ast::StorageClass::kOutput, ty.f32);
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Output %3 %2 = OpTypePointer Output %3
@ -76,7 +76,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass) {
TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) { TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) {
auto* v = Var("var", ast::StorageClass::kInput, ty.f32); auto* v = Var("var", ast::StorageClass::kInput, ty.f32);
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Input %3 %2 = OpTypePointer Input %3
@ -95,7 +95,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3 %1 = OpTypeVector %2 3
@ -118,7 +118,7 @@ TEST_F(BuilderTest, GlobalVar_Const) {
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %5 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %5 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3 %1 = OpTypeVector %2 3
@ -183,7 +183,7 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) {
}); });
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Location 5 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Location 5
)"); )");
@ -202,7 +202,7 @@ TEST_F(BuilderTest, GlobalVar_WithBindingAndSet) {
}); });
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Binding 2 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Binding 2
OpDecorate %1 DescriptorSet 3 OpDecorate %1 DescriptorSet 3
@ -221,7 +221,7 @@ TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
}); });
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 BuiltIn Position EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 BuiltIn Position
)"); )");
@ -239,7 +239,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
}); });
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %2 SpecId 1200 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %2 SpecId 1200
)"); )");
@ -257,7 +257,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
}); });
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 1200 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 1200
)"); )");
@ -275,7 +275,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
}); });
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %2 SpecId 0 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %2 SpecId 0
)"); )");
@ -293,7 +293,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
}); });
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0
)"); )");
@ -311,7 +311,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
}); });
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0
)"); )");
@ -329,7 +329,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_U32_NoConstructor) {
}); });
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0
)"); )");
@ -392,10 +392,10 @@ TEST_F(BuilderTest, GlobalVar_DeclReadOnly) {
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
OpMemberDecorate %3 1 NonWritable OpMemberDecorate %3 1 NonWritable
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_A"
OpMemberName %3 0 "a" OpMemberName %3 0 "test_a"
OpMemberName %3 1 "b" OpMemberName %3 1 "test_b"
OpName %1 "b" OpName %1 "test_b"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
%3 = OpTypeStruct %4 %4 %3 = OpTypeStruct %4 %4
@ -421,9 +421,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) {
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_A"
OpMemberName %3 0 "a" OpMemberName %3 0 "test_a"
OpName %1 "b" OpName %1 "test_b"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
%3 = OpTypeStruct %4 %3 = OpTypeStruct %4
@ -449,9 +449,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) {
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_A"
OpMemberName %3 0 "a" OpMemberName %3 0 "test_a"
OpName %1 "b" OpName %1 "test_b"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
%3 = OpTypeStruct %4 %3 = OpTypeStruct %4
@ -480,12 +480,12 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) {
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "test_A"
OpMemberName %3 0 "a" OpMemberName %3 0 "test_a"
OpName %1 "b" OpName %1 "test_b"
OpName %7 "A" OpName %7 "test_A"
OpMemberName %7 0 "a" OpMemberName %7 0 "test_a"
OpName %5 "c" OpName %5 "test_c"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
%3 = OpTypeStruct %4 %3 = OpTypeStruct %4

View File

@ -66,7 +66,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
b.push_function(Function{}); b.push_function(Function{});
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Output %3 %2 = OpTypePointer Output %3
@ -108,7 +108,7 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
b.push_function(Function{}); b.push_function(Function{});
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error(); EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_var"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Function %3 %2 = OpTypePointer Function %3

View File

@ -45,6 +45,7 @@
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "src/writer/spirv/builder.h" #include "src/writer/spirv/builder.h"
#include "src/writer/spirv/spv_dump.h" #include "src/writer/spirv/spv_dump.h"
#include "src/writer/test_namer.h"
namespace tint { namespace tint {
namespace writer { namespace writer {
@ -59,7 +60,8 @@ class IntrinsicBuilderTest : public ast::BuilderWithModule,
} }
TypeDeterminer td{mod}; TypeDeterminer td{mod};
spirv::Builder b{mod}; TestNamer namer{mod};
spirv::Builder b{mod, &namer};
}; };
template <typename T> template <typename T>
@ -479,8 +481,8 @@ TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) {
EXPECT_EQ(b.GenerateCallExpression(expr), 9u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 9u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%10 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%10 = OpExtInstImport "GLSL.std.450"
OpName %1 "ident" OpName %1 "test_ident"
OpName %7 "a_func" OpName %7 "test_a_func"
%3 = OpTypeFloat 32 %3 = OpTypeFloat 32
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3
@ -511,7 +513,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %6 = OpTypeFloat 32
@ -538,7 +540,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Vector) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeFloat 32 %7 = OpTypeFloat 32
@ -591,7 +593,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %6 = OpTypeFloat 32
@ -615,7 +617,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Vector) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %6 = OpTypeFloat 32
@ -641,7 +643,7 @@ TEST_F(IntrinsicBuilderTest, Call_Normalize) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeFloat 32 %7 = OpTypeFloat 32
@ -672,7 +674,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %6 = OpTypeFloat 32
@ -700,7 +702,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Vector) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeFloat 32 %7 = OpTypeFloat 32
@ -736,7 +738,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %6 = OpTypeFloat 32
@ -761,7 +763,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %6 = OpTypeFloat 32
@ -789,7 +791,7 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeFloat 32 %7 = OpTypeFloat 32
@ -819,7 +821,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %6 = OpTypeFloat 32
@ -848,7 +850,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Vector) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeFloat 32 %7 = OpTypeFloat 32
@ -888,7 +890,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 1 %6 = OpTypeInt 32 1
@ -915,7 +917,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Vector) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 1 %7 = OpTypeInt 32 1
@ -949,7 +951,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 0 %6 = OpTypeInt 32 0
@ -976,7 +978,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Vector) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 0 %7 = OpTypeInt 32 0
@ -1010,7 +1012,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 1 %6 = OpTypeInt 32 1
@ -1037,7 +1039,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Vector) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 1 %7 = OpTypeInt 32 1
@ -1072,7 +1074,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 0 %6 = OpTypeInt 32 0
@ -1099,7 +1101,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Vector) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 0 %7 = OpTypeInt 32 0
@ -1134,7 +1136,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 1 %6 = OpTypeInt 32 1
@ -1163,7 +1165,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Vector) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 1 %7 = OpTypeInt 32 1
@ -1197,7 +1199,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 0 %6 = OpTypeInt 32 0
@ -1226,7 +1228,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Vector) {
EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 0 %7 = OpTypeInt 32 0
@ -1260,8 +1262,8 @@ TEST_F(IntrinsicBuilderTest, Call_Determinant) {
EXPECT_EQ(b.GenerateCallExpression(expr), 11u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(expr), 11u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%12 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%12 = OpExtInstImport "GLSL.std.450"
OpName %3 "a_func" OpName %3 "test_a_func"
OpName %5 "var" OpName %5 "test_var"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%9 = OpTypeFloat 32 %9 = OpTypeFloat 32

View File

@ -24,6 +24,7 @@
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "src/writer/spirv/builder.h" #include "src/writer/spirv/builder.h"
#include "src/writer/spirv/spv_dump.h" #include "src/writer/spirv/spv_dump.h"
#include "src/writer/test_namer.h"
namespace tint { namespace tint {
namespace writer { namespace writer {
@ -2708,7 +2709,8 @@ class IntrinsicTextureTest
} }
TypeDeterminer td{mod}; TypeDeterminer td{mod};
spirv::Builder b{mod}; TestNamer namer{mod};
spirv::Builder b{mod, &namer};
}; };
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(

View File

@ -103,9 +103,9 @@ TEST_F(BuilderTest, Switch_WithCase) {
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error(); EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_v"
OpName %5 "a" OpName %5 "test_a"
OpName %7 "a_func" OpName %7 "test_a_func"
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3
@ -164,9 +164,9 @@ TEST_F(BuilderTest, Switch_WithDefault) {
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error(); EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_v"
OpName %5 "a" OpName %5 "test_a"
OpName %7 "a_func" OpName %7 "test_a_func"
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3
@ -238,9 +238,9 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error(); EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_v"
OpName %5 "a" OpName %5 "test_a"
OpName %7 "a_func" OpName %7 "test_a_func"
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3
@ -321,9 +321,9 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error(); EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_v"
OpName %5 "a" OpName %5 "test_a"
OpName %7 "a_func" OpName %7 "test_a_func"
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3
@ -431,9 +431,9 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error(); EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "test_v"
OpName %5 "a" OpName %5 "test_a"
OpName %7 "a_func" OpName %7 "test_a_func"
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3

View File

@ -251,7 +251,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
EXPECT_EQ(id, 1u); EXPECT_EQ(id, 1u);
EXPECT_EQ(b.types().size(), 1u); EXPECT_EQ(b.types().size(), 1u);
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_S"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeStruct EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeStruct
)"); )");
@ -269,8 +269,8 @@ TEST_F(BuilderTest_Type, GenerateStruct) {
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeStruct %2 %1 = OpTypeStruct %2
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_my_struct"
OpMemberName %1 0 "a" OpMemberName %1 0 "test_a"
)"); )");
} }
@ -289,8 +289,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_Decorated) {
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeStruct %2 %1 = OpTypeStruct %2
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_my_struct"
OpMemberName %1 0 "a" OpMemberName %1 0 "test_a"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Block EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Block
)"); )");
@ -310,9 +310,9 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) {
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeStruct %2 %2 %1 = OpTypeStruct %2 %2
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_S"
OpMemberName %1 0 "a" OpMemberName %1 0 "test_a"
OpMemberName %1 1 "b" OpMemberName %1 1 "test_b"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
OpMemberDecorate %1 1 Offset 8 OpMemberDecorate %1 1 Offset 8
@ -340,10 +340,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_NonLayout_Matrix) {
%7 = OpTypeMatrix %8 4 %7 = OpTypeMatrix %8 4
%1 = OpTypeStruct %2 %5 %7 %1 = OpTypeStruct %2 %5 %7
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_S"
OpMemberName %1 0 "a" OpMemberName %1 0 "test_a"
OpMemberName %1 1 "b" OpMemberName %1 1 "test_b"
OpMemberName %1 2 "c" OpMemberName %1 2 "test_c"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), ""); EXPECT_EQ(DumpInstructions(b.annots()), "");
} }
@ -370,10 +370,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutMatrix) {
%7 = OpTypeMatrix %8 4 %7 = OpTypeMatrix %8 4
%1 = OpTypeStruct %2 %5 %7 %1 = OpTypeStruct %2 %5 %7
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_S"
OpMemberName %1 0 "a" OpMemberName %1 0 "test_a"
OpMemberName %1 1 "b" OpMemberName %1 1 "test_b"
OpMemberName %1 2 "c" OpMemberName %1 2 "test_c"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
OpMemberDecorate %1 0 ColMajor OpMemberDecorate %1 0 ColMajor
@ -426,10 +426,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) {
%11 = OpTypeRuntimeArray %12 %11 = OpTypeRuntimeArray %12
%1 = OpTypeStruct %2 %8 %11 %1 = OpTypeStruct %2 %8 %11
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "test_S"
OpMemberName %1 0 "a" OpMemberName %1 0 "test_a"
OpMemberName %1 1 "b" OpMemberName %1 1 "test_b"
OpMemberName %1 2 "c" OpMemberName %1 2 "test_c"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
OpMemberDecorate %1 0 ColMajor OpMemberDecorate %1 0 ColMajor

View File

@ -22,13 +22,15 @@ namespace spirv {
Generator::Generator(ast::Module module) Generator::Generator(ast::Module module)
: writer::Writer(std::move(module)), : writer::Writer(std::move(module)),
builder_(std::make_unique<Builder>(&module_)), namer_(std::make_unique<UnsafeNamer>(&module_)),
builder_(std::make_unique<Builder>(&module_, namer_.get())),
writer_(std::make_unique<BinaryWriter>()) {} writer_(std::make_unique<BinaryWriter>()) {}
Generator::~Generator() = default; Generator::~Generator() = default;
void Generator::Reset() { void Generator::Reset() {
builder_ = std::make_unique<Builder>(&module_); namer_->Reset();
builder_ = std::make_unique<Builder>(&module_, namer_.get());
writer_ = std::make_unique<BinaryWriter>(); writer_ = std::make_unique<BinaryWriter>();
} }

View File

@ -20,6 +20,7 @@
#include <vector> #include <vector>
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/namer.h"
#include "src/writer/spirv/binary_writer.h" #include "src/writer/spirv/binary_writer.h"
#include "src/writer/spirv/builder.h" #include "src/writer/spirv/builder.h"
#include "src/writer/writer.h" #include "src/writer/writer.h"
@ -54,6 +55,7 @@ class Generator : public writer::Writer {
const std::vector<uint32_t>& result() const { return writer_->result(); } const std::vector<uint32_t>& result() const { return writer_->result(); }
private: private:
std::unique_ptr<Namer> namer_;
std::unique_ptr<Builder> builder_; std::unique_ptr<Builder> builder_;
std::unique_ptr<BinaryWriter> writer_; std::unique_ptr<BinaryWriter> writer_;
}; };

View File

@ -23,6 +23,7 @@
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "src/writer/spirv/builder.h" #include "src/writer/spirv/builder.h"
#include "src/writer/test_namer.h"
namespace tint { namespace tint {
namespace writer { namespace writer {
@ -32,11 +33,13 @@ namespace spirv {
template <typename BASE> template <typename BASE>
class TestHelperBase : public ast::BuilderWithModule, public BASE { class TestHelperBase : public ast::BuilderWithModule, public BASE {
public: public:
TestHelperBase() : td(mod), b(mod) {} TestHelperBase() : td(mod), namer(mod), b(mod, &namer) {}
~TestHelperBase() override = default; ~TestHelperBase() override = default;
/// The type determiner /// The type determiner
TypeDeterminer td; TypeDeterminer td;
/// The test namer
TestNamer namer;
/// The generator /// The generator
spirv::Builder b; spirv::Builder b;