Add Symbol to alias.

This CL adds a Symbol alongside the name in the Alias type. The name
will be removed in a future CL.

Change-Id: I23fa77566cc7a2aead783b64c34c0cc3195df24b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35461
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair
2020-12-11 19:35:03 +00:00
committed by Commit Bot service account
parent 6b59bf45aa
commit 4226b6a1d8
27 changed files with 102 additions and 85 deletions

View File

@@ -16,6 +16,7 @@
#include <vector>
#include "gmock/gmock.h"
#include "src/demangler.h"
#include "src/reader/spirv/function.h"
#include "src/reader/spirv/parser_impl.h"
#include "src/reader/spirv/parser_impl_test_helper.h"
@@ -799,7 +800,8 @@ TEST_F(SpvParserTest, RemapStorageBuffer_TypesAndVarDeclarations) {
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions())
<< assembly << p->error();
const auto module_str = p->module().to_str();
const auto module_str =
Demangler().Demangle(p->get_module(), p->get_module().to_str());
EXPECT_THAT(module_str, HasSubstr(R"(
RTArr -> __array__u32_stride_4
S Struct{

View File

@@ -1111,8 +1111,8 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id,
return;
}
const auto name = namer_.GetName(type_id);
auto* ast_alias_type =
ast_module_.create<ast::type::Alias>(name, ast_underlying_type);
auto* ast_alias_type = ast_module_.create<ast::type::Alias>(
ast_module_.RegisterSymbol(name), name, ast_underlying_type);
// Record this new alias as the AST type for this SPIR-V ID.
id_to_type_[type_id] = ast_alias_type;
ast_module_.AddConstructedType(ast_alias_type);

View File

@@ -80,7 +80,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArrayWithDecoration) {
%arr = OpTypeRuntimeArray %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(p->module().to_str(),
EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()),
HasSubstr("RTArr -> __array__u32_stride_8\n"));
}
@@ -93,7 +93,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArray_Dup_EmitBoth) {
%arr2 = OpTypeRuntimeArray %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(p->module().to_str(),
EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()),
HasSubstr("RTArr -> __array__u32_stride_8\n RTArr_1 -> "
"__array__u32_stride_8\n"));
}
@@ -106,7 +106,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedRTArray) {
%arr = OpTypeRuntimeArray %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(p->module().to_str(),
EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()),
HasSubstr("myrtarr -> __array__u32_stride_8\n"));
}
@@ -120,7 +120,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedArray) {
%arr2 = OpTypeArray %uint %uint_5
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(p->module().to_str(),
EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()),
HasSubstr("myarr -> __array__u32_5_stride_8"));
}
@@ -134,7 +134,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonArray_Dup_EmitBoth) {
%arr2 = OpTypeArray %uint %uint_5
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(p->module().to_str(),
EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()),
HasSubstr("Arr -> __array__u32_5_stride_8\n Arr_1 -> "
"__array__u32_5_stride_8"));
}

View File

@@ -937,7 +937,8 @@ Maybe<ast::type::Type*> ParserImpl::type_alias() {
if (!type.matched)
return add_error(peek(), "invalid type alias");
auto* alias = module_.create<ast::type::Alias>(name.value, type.value);
auto* alias = module_.create<ast::type::Alias>(
module_.RegisterSymbol(name.value), name.value, type.value);
register_constructed(name.value, alias);
return alias;

View File

@@ -89,7 +89,9 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) {
auto& m = p->get_module();
ASSERT_EQ(m.constructed_types().size(), 1u);
ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::Alias>());
EXPECT_EQ(m.constructed_types()[0]->As<ast::type::Alias>()->name(), "A");
EXPECT_EQ(m.SymbolToName(
m.constructed_types()[0]->As<ast::type::Alias>()->symbol()),
"A");
}
TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) {
@@ -109,7 +111,7 @@ type B = A;)");
ASSERT_TRUE(m.constructed_types()[1]->Is<ast::type::Alias>());
auto* alias = m.constructed_types()[1]->As<ast::type::Alias>();
EXPECT_EQ(alias->name(), "B");
EXPECT_EQ(m.SymbolToName(alias->symbol()), "B");
EXPECT_EQ(alias->type(), str);
}
@@ -134,7 +136,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function) {
auto& m = p->get_module();
ASSERT_EQ(m.functions().size(), 1u);
EXPECT_EQ(m.functions()[0]->name(), "main");
EXPECT_EQ(m.SymbolToName(m.functions()[0]->symbol()), "main");
}
TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) {
@@ -144,7 +146,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) {
auto& m = p->get_module();
ASSERT_EQ(m.functions().size(), 1u);
EXPECT_EQ(m.functions()[0]->name(), "main");
EXPECT_EQ(m.SymbolToName(m.functions()[0]->symbol()), "main");
}
TEST_F(ParserImplTest, GlobalDecl_Function_Invalid) {

View File

@@ -55,7 +55,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::Alias>());
auto* alias = t->As<ast::type::Alias>();
EXPECT_EQ(alias->name(), "a");
EXPECT_EQ(p->get_module().SymbolToName(alias->symbol()), "a");
ASSERT_TRUE(alias->type()->Is<ast::type::Struct>());
auto* s = alias->type()->As<ast::type::Struct>();

View File

@@ -49,7 +49,8 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
auto& mod = p->get_module();
auto* int_type = mod.create<ast::type::I32>();
auto* alias_type = mod.create<ast::type::Alias>("A", int_type);
auto* alias_type =
mod.create<ast::type::Alias>(mod.RegisterSymbol("A"), "A", int_type);
p->register_constructed("A", alias_type);
@@ -61,7 +62,7 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
ASSERT_TRUE(t->Is<ast::type::Alias>());
auto* alias = t->As<ast::type::Alias>();
EXPECT_EQ(alias->name(), "A");
EXPECT_EQ(p->get_module().SymbolToName(alias->symbol()), "A");
EXPECT_EQ(alias->type(), int_type);
}