Fixup IntLiteral names.

This CL fixes the IntLiteral name to contain the type of the literal.
This keeps i32 and u32 from fighting over a given name. Now, the name
ends up being __int__i32_0 instead of __int_0.

Change-Id: Ifb9f0516139d25f34312c75c77318eccbe076ef8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20941
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-05-04 18:58:19 +00:00 committed by David Neto
parent 6164da26b7
commit 253ee1b3ef
3 changed files with 21 additions and 7 deletions

View File

@ -31,7 +31,7 @@ std::string IntLiteral::to_str() const {
}
std::string IntLiteral::name() const {
return "__int" + std::to_string(value_);
return "__int" + type()->type_name() + "_" + std::to_string(value_);
}
} // namespace ast

View File

@ -16,6 +16,7 @@
#include "gtest/gtest.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/u32_type.h"
namespace tint {
namespace ast {
@ -46,6 +47,17 @@ TEST_F(IntLiteralTest, ToStr) {
EXPECT_EQ(i.to_str(), "-42");
}
TEST_F(IntLiteralTest, Name_I32) {
ast::type::I32Type i32;
IntLiteral i{&i32, 2};
EXPECT_EQ("__int__i32_2", i.name());
}
TEST_F(IntLiteralTest, Name_U32) {
ast::type::U32Type u32;
IntLiteral i{&u32, 2};
EXPECT_EQ("__int__u32_2", i.name());
}
} // namespace
} // namespace ast
} // namespace tint

View File

@ -897,7 +897,7 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
b.push_function(Function{});
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
EXPECT_EQ(b.GenerateAccessorExpression(&expr), 19u);
EXPECT_EQ(b.GenerateAccessorExpression(&expr), 21u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%9 = OpTypeFloat 32
%8 = OpTypeVector %9 3
@ -912,16 +912,18 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
%2 = OpTypePointer Function %3
%13 = OpTypeInt 32 1
%14 = OpConstant %13 0
%15 = OpTypePointer Function %8
%17 = OpTypeVector %9 2
%15 = OpConstant %10 0
%16 = OpConstant %13 2
%17 = OpTypePointer Function %8
%19 = OpTypeVector %9 2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
R"(%1 = OpVariable %2 Function
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
R"(%16 = OpAccessChain %15 %1 %14 %14 %12 %14 %14
%18 = OpLoad %8 %16
%19 = OpVectorShuffle %17 %18 %18 1 0
R"(%18 = OpAccessChain %17 %1 %14 %15 %16 %15 %15
%20 = OpLoad %8 %18
%21 = OpVectorShuffle %19 %20 %20 1 0
)");
}