mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-04 19:25:47 +00:00
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:
parent
6b59bf45aa
commit
4226b6a1d8
@ -44,8 +44,8 @@ TEST_F(ExpressionTest, set_result_type) {
|
||||
|
||||
TEST_F(ExpressionTest, set_result_type_alias) {
|
||||
type::I32 i32;
|
||||
type::Alias a("a", &i32);
|
||||
type::Alias b("b", &a);
|
||||
type::Alias a(mod.RegisterSymbol("a"), "a", &i32);
|
||||
type::Alias b(mod.RegisterSymbol("b"), "b", &a);
|
||||
|
||||
Expr e;
|
||||
e.set_result_type(&b);
|
||||
|
@ -138,7 +138,8 @@ std::string Module::to_str() const {
|
||||
out << " ";
|
||||
}
|
||||
if (auto* alias = ty->As<type::Alias>()) {
|
||||
out << alias->name() << " -> " << alias->type()->type_name() << std::endl;
|
||||
out << alias->symbol().to_str() << " -> " << alias->type()->type_name()
|
||||
<< std::endl;
|
||||
if (auto* str = alias->type()->As<type::Struct>()) {
|
||||
str->impl()->to_str(out, indent);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) {
|
||||
|
||||
TEST_F(ModuleTest, IsValid_Alias) {
|
||||
type::F32 f32;
|
||||
type::Alias alias("alias", &f32);
|
||||
type::Alias alias(mod.RegisterSymbol("alias"), "alias", &f32);
|
||||
|
||||
Module m;
|
||||
m.AddConstructedType(&alias);
|
||||
@ -109,7 +109,7 @@ TEST_F(ModuleTest, IsValid_Null_Alias) {
|
||||
TEST_F(ModuleTest, IsValid_Struct) {
|
||||
type::F32 f32;
|
||||
type::Struct st("name", {});
|
||||
type::Alias alias("name", &st);
|
||||
type::Alias alias(mod.RegisterSymbol("name"), "name", &st);
|
||||
|
||||
Module m;
|
||||
m.AddConstructedType(&alias);
|
||||
@ -119,7 +119,7 @@ TEST_F(ModuleTest, IsValid_Struct) {
|
||||
TEST_F(ModuleTest, IsValid_Struct_EmptyName) {
|
||||
type::F32 f32;
|
||||
type::Struct st("", {});
|
||||
type::Alias alias("name", &st);
|
||||
type::Alias alias(mod.RegisterSymbol("name"), "name", &st);
|
||||
|
||||
Module m;
|
||||
m.AddConstructedType(&alias);
|
||||
|
@ -25,8 +25,8 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
Alias::Alias(const std::string& name, Type* subtype)
|
||||
: name_(name), subtype_(subtype) {
|
||||
Alias::Alias(const Symbol& sym, const std::string& name, Type* subtype)
|
||||
: symbol_(sym), name_(name), subtype_(subtype) {
|
||||
assert(subtype_);
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ Alias::Alias(Alias&&) = default;
|
||||
Alias::~Alias() = default;
|
||||
|
||||
std::string Alias::type_name() const {
|
||||
return "__alias_" + name_ + subtype_->type_name();
|
||||
return "__alias_" + symbol_.to_str() + subtype_->type_name();
|
||||
}
|
||||
|
||||
uint64_t Alias::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
@ -47,7 +47,7 @@ uint64_t Alias::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
}
|
||||
|
||||
Alias* Alias::Clone(CloneContext* ctx) const {
|
||||
return ctx->mod->create<Alias>(name_, ctx->Clone(subtype_));
|
||||
return ctx->mod->create<Alias>(symbol_, name_, ctx->Clone(subtype_));
|
||||
}
|
||||
|
||||
} // namespace type
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "src/ast/type/type.h"
|
||||
#include "src/symbol.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
@ -27,13 +28,17 @@ namespace type {
|
||||
class Alias : public Castable<Alias, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param sym the symbol for the alias
|
||||
/// @param name the alias name
|
||||
/// @param subtype the alias'd type
|
||||
Alias(const std::string& name, Type* subtype);
|
||||
Alias(const Symbol& sym, const std::string& name, Type* subtype);
|
||||
/// Move constructor
|
||||
Alias(Alias&&);
|
||||
/// Destructor
|
||||
~Alias() override;
|
||||
|
||||
/// @returns the alias symbol
|
||||
Symbol symbol() const { return symbol_; }
|
||||
/// @returns the alias name
|
||||
const std::string& name() const { return name_; }
|
||||
/// @returns the alias type
|
||||
@ -58,6 +63,7 @@ class Alias : public Castable<Alias, Type> {
|
||||
Alias* Clone(CloneContext* ctx) const override;
|
||||
|
||||
private:
|
||||
Symbol symbol_;
|
||||
std::string name_;
|
||||
Type* subtype_ = nullptr;
|
||||
};
|
||||
|
@ -44,15 +44,16 @@ using AliasTest = TestHelper;
|
||||
|
||||
TEST_F(AliasTest, Create) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
EXPECT_EQ(a.name(), "a_type");
|
||||
Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32};
|
||||
EXPECT_EQ(a.symbol(), Symbol(1));
|
||||
// EXPECT_EQ(a.name(), "a_type");
|
||||
EXPECT_EQ(a.type(), &u32);
|
||||
}
|
||||
|
||||
TEST_F(AliasTest, Is) {
|
||||
I32 i32;
|
||||
|
||||
Alias at{"a", &i32};
|
||||
Alias at{mod.RegisterSymbol("a"), "a", &i32};
|
||||
Type* ty = &at;
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_TRUE(ty->Is<Alias>());
|
||||
@ -71,14 +72,15 @@ TEST_F(AliasTest, Is) {
|
||||
|
||||
TEST_F(AliasTest, TypeName) {
|
||||
I32 i32;
|
||||
Alias at{"Particle", &i32};
|
||||
EXPECT_EQ(at.type_name(), "__alias_Particle__i32");
|
||||
Alias at{mod.RegisterSymbol("Particle"), "Particle", &i32};
|
||||
EXPECT_EQ(at.type_name(), "__alias_tint_symbol_1__i32");
|
||||
}
|
||||
|
||||
TEST_F(AliasTest, UnwrapIfNeeded_Alias) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
EXPECT_EQ(a.name(), "a_type");
|
||||
Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32};
|
||||
EXPECT_EQ(a.symbol(), Symbol(1));
|
||||
// EXPECT_EQ(a.name(), "a_type");
|
||||
EXPECT_EQ(a.type(), &u32);
|
||||
EXPECT_EQ(a.UnwrapIfNeeded(), &u32);
|
||||
EXPECT_EQ(u32.UnwrapIfNeeded(), &u32);
|
||||
@ -93,16 +95,17 @@ TEST_F(AliasTest, UnwrapIfNeeded_AccessControl) {
|
||||
|
||||
TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
Alias aa{"aa_type", &a};
|
||||
EXPECT_EQ(aa.name(), "aa_type");
|
||||
Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32};
|
||||
Alias aa{mod.RegisterSymbol("aa_type"), "aa_type", &a};
|
||||
EXPECT_EQ(aa.symbol(), Symbol(2));
|
||||
// EXPECT_EQ(aa.name(), "aa_type");
|
||||
EXPECT_EQ(aa.type(), &a);
|
||||
EXPECT_EQ(aa.UnwrapIfNeeded(), &u32);
|
||||
}
|
||||
|
||||
TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel_AliasAccessControl) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32};
|
||||
AccessControl aa{ast::AccessControl::kReadWrite, &a};
|
||||
EXPECT_EQ(aa.type(), &a);
|
||||
EXPECT_EQ(aa.UnwrapIfNeeded(), &u32);
|
||||
@ -110,12 +113,13 @@ TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel_AliasAccessControl) {
|
||||
|
||||
TEST_F(AliasTest, UnwrapAll_TwiceAliasPointerTwiceAlias) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
Alias aa{"aa_type", &a};
|
||||
Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32};
|
||||
Alias aa{mod.RegisterSymbol("aa_type"), "aa_type", &a};
|
||||
Pointer paa{&aa, StorageClass::kUniform};
|
||||
Alias apaa{"paa_type", &paa};
|
||||
Alias aapaa{"aapaa_type", &apaa};
|
||||
EXPECT_EQ(aapaa.name(), "aapaa_type");
|
||||
Alias apaa{mod.RegisterSymbol("paa_type"), "paa_type", &paa};
|
||||
Alias aapaa{mod.RegisterSymbol("aapaa_type"), "aapaa_type", &apaa};
|
||||
EXPECT_EQ(aapaa.symbol(), Symbol(4));
|
||||
// EXPECT_EQ(aapaa.name(), "aapaa_type");
|
||||
EXPECT_EQ(aapaa.type(), &apaa);
|
||||
EXPECT_EQ(aapaa.UnwrapAll(), &u32);
|
||||
EXPECT_EQ(u32.UnwrapAll(), &u32);
|
||||
@ -123,23 +127,23 @@ TEST_F(AliasTest, UnwrapAll_TwiceAliasPointerTwiceAlias) {
|
||||
|
||||
TEST_F(AliasTest, UnwrapAll_SecondConsecutivePointerBlocksUnrapping) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
Alias aa{"aa_type", &a};
|
||||
Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32};
|
||||
Alias aa{mod.RegisterSymbol("aa_type"), "aa_type", &a};
|
||||
Pointer paa{&aa, StorageClass::kUniform};
|
||||
Pointer ppaa{&paa, StorageClass::kUniform};
|
||||
Alias appaa{"appaa_type", &ppaa};
|
||||
Alias appaa{mod.RegisterSymbol("appaa_type"), "appaa_type", &ppaa};
|
||||
EXPECT_EQ(appaa.UnwrapAll(), &paa);
|
||||
}
|
||||
|
||||
TEST_F(AliasTest, UnwrapAll_SecondNonConsecutivePointerBlocksUnrapping) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
Alias aa{"aa_type", &a};
|
||||
Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32};
|
||||
Alias aa{mod.RegisterSymbol("aa_type"), "aa_type", &a};
|
||||
Pointer paa{&aa, StorageClass::kUniform};
|
||||
Alias apaa{"apaa_type", &paa};
|
||||
Alias aapaa{"aapaa_type", &apaa};
|
||||
Alias apaa{mod.RegisterSymbol("apaa_type"), "apaa_type", &paa};
|
||||
Alias aapaa{mod.RegisterSymbol("aapaa_type"), "aapaa_type", &apaa};
|
||||
Pointer paapaa{&aapaa, StorageClass::kUniform};
|
||||
Alias apaapaa{"apaapaa_type", &paapaa};
|
||||
Alias apaapaa{mod.RegisterSymbol("apaapaa_type"), "apaapaa_type", &paapaa};
|
||||
EXPECT_EQ(apaapaa.UnwrapAll(), &paa);
|
||||
}
|
||||
|
||||
@ -163,7 +167,7 @@ TEST_F(AliasTest, UnwrapAll_PointerAccessControl) {
|
||||
|
||||
TEST_F(AliasTest, MinBufferBindingSizeU32) {
|
||||
U32 u32;
|
||||
Alias alias{"alias", &u32};
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &u32};
|
||||
EXPECT_EQ(4u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
@ -173,7 +177,7 @@ TEST_F(AliasTest, MinBufferBindingSizeArray) {
|
||||
ArrayDecorationList{
|
||||
create<StrideDecoration>(4, Source{}),
|
||||
});
|
||||
Alias alias{"alias", &array};
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &array};
|
||||
EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
@ -183,7 +187,7 @@ TEST_F(AliasTest, MinBufferBindingSizeRuntimeArray) {
|
||||
ArrayDecorationList{
|
||||
create<StrideDecoration>(4, Source{}),
|
||||
});
|
||||
Alias alias{"alias", &array};
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &array};
|
||||
EXPECT_EQ(4u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
@ -205,14 +209,14 @@ TEST_F(AliasTest, MinBufferBindingSizeStruct) {
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
Alias alias{"alias", &struct_type};
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &struct_type};
|
||||
EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, alias.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AliasTest, BaseAlignmentU32) {
|
||||
U32 u32;
|
||||
Alias alias{"alias", &u32};
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &u32};
|
||||
EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
@ -222,7 +226,7 @@ TEST_F(AliasTest, BaseAlignmentArray) {
|
||||
ArrayDecorationList{
|
||||
create<StrideDecoration>(4, Source{}),
|
||||
});
|
||||
Alias alias{"alias", &array};
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &array};
|
||||
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
@ -232,7 +236,7 @@ TEST_F(AliasTest, BaseAlignmentRuntimeArray) {
|
||||
ArrayDecorationList{
|
||||
create<StrideDecoration>(4, Source{}),
|
||||
});
|
||||
Alias alias{"alias", &array};
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &array};
|
||||
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
@ -254,7 +258,7 @@ TEST_F(AliasTest, BaseAlignmentStruct) {
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
Alias alias{"alias", &struct_type};
|
||||
Alias alias{mod.RegisterSymbol("alias"), "alias", &struct_type};
|
||||
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
@ -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{
|
||||
|
@ -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);
|
||||
|
@ -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"));
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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>();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -474,7 +474,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Alias_Array) {
|
||||
ast::type::I32 i32;
|
||||
ast::type::F32 f32;
|
||||
ast::type::Array ary(&f32, 3, ast::ArrayDecorationList{});
|
||||
ast::type::Alias aary("myarrty", &ary);
|
||||
ast::type::Alias aary(mod->RegisterSymbol("myarrty"), "myarrty", &ary);
|
||||
|
||||
auto* idx = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2));
|
||||
@ -1208,7 +1208,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct_Alias) {
|
||||
auto* strct = create<ast::Struct>(members);
|
||||
|
||||
auto st = std::make_unique<ast::type::Struct>("alias", strct);
|
||||
ast::type::Alias alias("alias", st.get());
|
||||
ast::type::Alias alias(mod->RegisterSymbol("alias"), "alias", st.get());
|
||||
|
||||
auto* var =
|
||||
create<ast::Variable>(Source{}, // source
|
||||
|
@ -421,7 +421,7 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
|
||||
// }
|
||||
|
||||
ast::type::U32 u32;
|
||||
ast::type::Alias my_int{"MyInt", &u32};
|
||||
ast::type::Alias my_int{mod()->RegisterSymbol("MyInt"), "MyInt", &u32};
|
||||
|
||||
auto* var = create<ast::Variable>(
|
||||
Source{}, // source
|
||||
|
@ -133,7 +133,7 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsNotLast_Fail) {
|
||||
|
||||
ast::type::F32 u32;
|
||||
ast::type::Array array(&u32, 0, ast::ArrayDecorationList{});
|
||||
ast::type::Alias alias{"RTArr", &array};
|
||||
ast::type::Alias alias{mod()->RegisterSymbol("RTArr"), "RTArr", &array};
|
||||
|
||||
ast::StructMemberList members;
|
||||
{
|
||||
@ -167,7 +167,7 @@ TEST_F(ValidatorTypeTest, AliasRuntimeArrayIsLast_Pass) {
|
||||
|
||||
ast::type::F32 u32;
|
||||
ast::type::Array array(&u32, 0, ast::ArrayDecorationList{});
|
||||
ast::type::Alias alias{"RTArr", &array};
|
||||
ast::type::Alias alias{mod()->RegisterSymbol("RTArr"), "RTArr", &array};
|
||||
|
||||
ast::StructMemberList members;
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ using HlslGeneratorImplTest_Alias = TestHelper;
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_F32) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias("a", &f32);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("a"), "a", &f32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(typedef float a;
|
||||
@ -39,7 +39,7 @@ TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_F32) {
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_NameCollision) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias("float", &f32);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("float"), "float", &f32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(typedef float float_tint_0;
|
||||
@ -59,7 +59,7 @@ TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_Struct) {
|
||||
});
|
||||
|
||||
ast::type::Struct s("A", str);
|
||||
ast::type::Alias alias("B", &s);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("B"), "B", &s);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct B {
|
||||
|
@ -45,7 +45,7 @@ using HlslGeneratorImplTest_Type = TestHelper;
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias("alias", &f32);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("alias"), "alias", &f32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(out, &alias, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "alias");
|
||||
@ -53,7 +53,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias) {
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias_NameCollision) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias("bool", &f32);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("bool"), "bool", &f32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(out, &alias, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "bool_tint_0");
|
||||
|
@ -33,7 +33,7 @@ using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructedType_F32) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias("a", &f32);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("a"), "a", &f32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructedType(&alias)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(typedef float a;
|
||||
@ -42,7 +42,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_F32) {
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructedType_NameCollision) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias("float", &f32);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("float"), "float", &f32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructedType(&alias)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(typedef float float_tint_0;
|
||||
@ -88,7 +88,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_AliasStructIdent) {
|
||||
auto* str = create<ast::Struct>(members);
|
||||
|
||||
ast::type::Struct s("b", str);
|
||||
ast::type::Alias alias("a", &s);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("a"), "a", &s);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructedType(&alias)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(typedef b a;
|
||||
|
@ -118,7 +118,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_alias) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias("a", &f32);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("a"), "a", &f32);
|
||||
EXPECT_EQ(4u, gen.calculate_alignment_size(&alias));
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Alias) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias("alias", &f32);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("alias"), "alias", &f32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&alias, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "alias");
|
||||
@ -56,7 +56,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Alias) {
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Alias_NameCollision) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias("bool", &f32);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("bool"), "bool", &f32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&alias, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool_tint_0");
|
||||
|
@ -411,7 +411,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
|
||||
|
||||
ast::type::Struct inner_struct("Inner", create<ast::Struct>(inner_members));
|
||||
|
||||
ast::type::Alias alias("Inner", &inner_struct);
|
||||
ast::type::Alias alias(mod->RegisterSymbol("Inner"), "Inner", &inner_struct);
|
||||
|
||||
ast::StructMemberList outer_members;
|
||||
outer_members.push_back(create<ast::StructMember>("inner", &alias, decos));
|
||||
|
@ -102,7 +102,7 @@ TEST_F(SpvBuilderConstructorTest, Type_WithAlias) {
|
||||
// type Int = i32
|
||||
// cast<Int>(2.3f)
|
||||
|
||||
ast::type::Alias alias("Int", ty.i32);
|
||||
ast::type::Alias alias(mod->RegisterSymbol("Int"), "Int", ty.i32);
|
||||
|
||||
ast::TypeConstructorExpression cast(&alias, ExprList(2.3f));
|
||||
|
||||
|
@ -566,7 +566,7 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) {
|
||||
members.push_back(create<ast::StructMember>("a", &i32, decos));
|
||||
|
||||
ast::type::Struct A("A", create<ast::Struct>(members));
|
||||
ast::type::Alias B("B", &A);
|
||||
ast::type::Alias B(mod->RegisterSymbol("B"), "B", &A);
|
||||
ast::type::AccessControl ac{ast::AccessControl::kReadOnly, &B};
|
||||
|
||||
ast::Variable var(Source{}, "b", ast::StorageClass::kStorageBuffer, &ac,
|
||||
@ -602,7 +602,7 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) {
|
||||
|
||||
ast::type::Struct A("A", create<ast::Struct>(members));
|
||||
ast::type::AccessControl ac{ast::AccessControl::kReadOnly, &A};
|
||||
ast::type::Alias B("B", &ac);
|
||||
ast::type::Alias B(mod->RegisterSymbol("B"), "B", &ac);
|
||||
|
||||
ast::Variable var(Source{}, "b", ast::StorageClass::kStorageBuffer, &B, false,
|
||||
nullptr, ast::VariableDecorationList{});
|
||||
|
@ -53,7 +53,7 @@ using BuilderTest_Type = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest_Type, GenerateAlias) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias_type("my_type", &f32);
|
||||
ast::type::Alias alias_type(mod->RegisterSymbol("my_type"), "my_type", &f32);
|
||||
|
||||
auto id = b.GenerateTypeIfNeeded(&alias_type);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
@ -67,7 +67,7 @@ TEST_F(BuilderTest_Type, GenerateAlias) {
|
||||
TEST_F(BuilderTest_Type, ReturnsGeneratedAlias) {
|
||||
ast::type::I32 i32;
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias_type("my_type", &f32);
|
||||
ast::type::Alias alias_type(mod->RegisterSymbol("my_type"), "my_type", &f32);
|
||||
|
||||
EXPECT_EQ(b.GenerateTypeIfNeeded(&alias_type), 1u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -32,7 +32,7 @@ using WgslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, EmitAlias_F32) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias("a", &f32);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("a"), "a", &f32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructedType(&alias)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(type a = f32;
|
||||
@ -54,7 +54,7 @@ TEST_F(WgslGeneratorImplTest, EmitConstructedType_Struct) {
|
||||
auto* str = create<ast::Struct>(members);
|
||||
|
||||
ast::type::Struct s("A", str);
|
||||
ast::type::Alias alias("B", &s);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("B"), "B", &s);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructedType(&s)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitConstructedType(&alias)) << gen.error();
|
||||
@ -82,7 +82,7 @@ TEST_F(WgslGeneratorImplTest, EmitAlias_ToStruct) {
|
||||
auto* str = create<ast::Struct>(members);
|
||||
|
||||
ast::type::Struct s("A", str);
|
||||
ast::type::Alias alias("B", &s);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("B"), "B", &s);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructedType(&alias)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(type B = A;
|
||||
|
@ -49,7 +49,7 @@ using WgslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Alias) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Alias alias("alias", &f32);
|
||||
ast::type::Alias alias(mod.RegisterSymbol("alias"), "alias", &f32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&alias)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "alias");
|
||||
|
Loading…
x
Reference in New Issue
Block a user