mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
Add optional access to ptr<>
This also completes the work to resolve the access controls for each storage type. Fixed: tint:846 Change-Id: Iab24057ec14620a2978ec63c4a91ba12d1bc6e9b Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53381 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
3db1820f0b
commit
1858854f7e
@@ -15,18 +15,24 @@
|
||||
#include "src/sem/pointer_type.h"
|
||||
|
||||
#include "src/program_builder.h"
|
||||
#include "src/sem/reference_type.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::sem::Pointer);
|
||||
|
||||
namespace tint {
|
||||
namespace sem {
|
||||
|
||||
Pointer::Pointer(const Type* subtype, ast::StorageClass storage_class)
|
||||
: subtype_(subtype), storage_class_(storage_class) {}
|
||||
Pointer::Pointer(const Type* subtype,
|
||||
ast::StorageClass storage_class,
|
||||
ast::Access access)
|
||||
: subtype_(subtype), storage_class_(storage_class), access_(access) {
|
||||
TINT_ASSERT(!subtype->Is<Reference>());
|
||||
TINT_ASSERT(access != ast::Access::kUndefined);
|
||||
}
|
||||
|
||||
std::string Pointer::type_name() const {
|
||||
std::ostringstream out;
|
||||
out << "__ptr_" << storage_class_ << subtype_->type_name();
|
||||
out << "__ptr_" << storage_class_ << subtype_->type_name() << "__" << access_;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
@@ -36,7 +42,8 @@ std::string Pointer::FriendlyName(const SymbolTable& symbols) const {
|
||||
if (storage_class_ != ast::StorageClass::kNone) {
|
||||
out << storage_class_ << ", ";
|
||||
}
|
||||
out << subtype_->FriendlyName(symbols) << ">";
|
||||
out << subtype_->FriendlyName(symbols) << ", " << access_;
|
||||
out << ">";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/ast/access.h"
|
||||
#include "src/ast/storage_class.h"
|
||||
#include "src/sem/type.h"
|
||||
|
||||
@@ -29,16 +30,24 @@ class Pointer : public Castable<Pointer, Type> {
|
||||
/// Constructor
|
||||
/// @param subtype the pointee type
|
||||
/// @param storage_class the storage class of the pointer
|
||||
Pointer(const Type* subtype, ast::StorageClass storage_class);
|
||||
/// @param access the resolved access control of the reference
|
||||
Pointer(const Type* subtype,
|
||||
ast::StorageClass storage_class,
|
||||
ast::Access access);
|
||||
|
||||
/// Move constructor
|
||||
Pointer(Pointer&&);
|
||||
~Pointer() override;
|
||||
|
||||
/// @returns the pointee type
|
||||
const Type* StoreType() const { return subtype_; }
|
||||
|
||||
/// @returns the storage class of the pointer
|
||||
ast::StorageClass StorageClass() const { return storage_class_; }
|
||||
|
||||
/// @returns the access control of the reference
|
||||
ast::Access Access() const { return access_; }
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
|
||||
@@ -50,6 +59,7 @@ class Pointer : public Castable<Pointer, Type> {
|
||||
private:
|
||||
Type const* const subtype_;
|
||||
ast::StorageClass const storage_class_;
|
||||
ast::AccessControl const access_;
|
||||
};
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -22,24 +22,29 @@ namespace {
|
||||
using PointerTest = TestHelper;
|
||||
|
||||
TEST_F(PointerTest, Creation) {
|
||||
auto* r = create<Pointer>(create<I32>(), ast::StorageClass::kStorage);
|
||||
auto* r = create<Pointer>(create<I32>(), ast::StorageClass::kStorage,
|
||||
ast::Access::kReadWrite);
|
||||
EXPECT_TRUE(r->StoreType()->Is<sem::I32>());
|
||||
EXPECT_EQ(r->StorageClass(), ast::StorageClass::kStorage);
|
||||
EXPECT_EQ(r->Access(), ast::Access::kReadWrite);
|
||||
}
|
||||
|
||||
TEST_F(PointerTest, TypeName) {
|
||||
auto* r = create<Pointer>(create<I32>(), ast::StorageClass::kWorkgroup);
|
||||
EXPECT_EQ(r->type_name(), "__ptr_workgroup__i32");
|
||||
auto* r = create<Pointer>(create<I32>(), ast::StorageClass::kWorkgroup,
|
||||
ast::Access::kReadWrite);
|
||||
EXPECT_EQ(r->type_name(), "__ptr_workgroup__i32__read_write");
|
||||
}
|
||||
|
||||
TEST_F(PointerTest, FriendlyName) {
|
||||
auto* r = create<Pointer>(create<I32>(), ast::StorageClass::kNone,
|
||||
ast::Access::kRead);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ptr<i32, read>");
|
||||
}
|
||||
|
||||
TEST_F(PointerTest, FriendlyNameWithStorageClass) {
|
||||
auto* r = create<Pointer>(create<I32>(), ast::StorageClass::kWorkgroup);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ptr<workgroup, i32>");
|
||||
}
|
||||
|
||||
TEST_F(PointerTest, FriendlyNameWithoutStorageClass) {
|
||||
auto* r = create<Pointer>(create<I32>(), ast::StorageClass::kNone);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ptr<i32>");
|
||||
auto* r = create<Pointer>(create<I32>(), ast::StorageClass::kWorkgroup,
|
||||
ast::Access::kRead);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ptr<workgroup, i32, read>");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -21,14 +21,17 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::Reference);
|
||||
namespace tint {
|
||||
namespace sem {
|
||||
|
||||
Reference::Reference(const Type* subtype, ast::StorageClass storage_class)
|
||||
: subtype_(subtype), storage_class_(storage_class) {
|
||||
Reference::Reference(const Type* subtype,
|
||||
ast::StorageClass storage_class,
|
||||
ast::Access access)
|
||||
: subtype_(subtype), storage_class_(storage_class), access_(access) {
|
||||
TINT_ASSERT(!subtype->Is<Reference>());
|
||||
TINT_ASSERT(access != ast::Access::kUndefined);
|
||||
}
|
||||
|
||||
std::string Reference::type_name() const {
|
||||
std::ostringstream out;
|
||||
out << "__ref_" << storage_class_ << subtype_->type_name();
|
||||
out << "__ref_" << storage_class_ << subtype_->type_name() << "__" << access_;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
@@ -38,7 +41,8 @@ std::string Reference::FriendlyName(const SymbolTable& symbols) const {
|
||||
if (storage_class_ != ast::StorageClass::kNone) {
|
||||
out << storage_class_ << ", ";
|
||||
}
|
||||
out << subtype_->FriendlyName(symbols) << ">";
|
||||
out << subtype_->FriendlyName(symbols) << ", " << access_;
|
||||
out << ">";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/ast/access.h"
|
||||
#include "src/ast/storage_class.h"
|
||||
#include "src/sem/type.h"
|
||||
|
||||
@@ -29,16 +30,24 @@ class Reference : public Castable<Reference, Type> {
|
||||
/// Constructor
|
||||
/// @param subtype the pointee type
|
||||
/// @param storage_class the storage class of the reference
|
||||
Reference(const Type* subtype, ast::StorageClass storage_class);
|
||||
/// @param access the resolved access control of the reference
|
||||
Reference(const Type* subtype,
|
||||
ast::StorageClass storage_class,
|
||||
ast::Access access);
|
||||
|
||||
/// Move constructor
|
||||
Reference(Reference&&);
|
||||
~Reference() override;
|
||||
|
||||
/// @returns the pointee type
|
||||
const Type* StoreType() const { return subtype_; }
|
||||
|
||||
/// @returns the storage class of the reference
|
||||
ast::StorageClass StorageClass() const { return storage_class_; }
|
||||
|
||||
/// @returns the resolved access control of the reference.
|
||||
ast::Access Access() const { return access_; }
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
|
||||
@@ -50,6 +59,7 @@ class Reference : public Castable<Reference, Type> {
|
||||
private:
|
||||
Type const* const subtype_;
|
||||
ast::StorageClass const storage_class_;
|
||||
ast::AccessControl const access_;
|
||||
};
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -22,24 +22,29 @@ namespace {
|
||||
using ReferenceTest = TestHelper;
|
||||
|
||||
TEST_F(ReferenceTest, Creation) {
|
||||
auto* r = create<Reference>(create<I32>(), ast::StorageClass::kStorage);
|
||||
auto* r = create<Reference>(create<I32>(), ast::StorageClass::kStorage,
|
||||
ast::Access::kReadWrite);
|
||||
EXPECT_TRUE(r->StoreType()->Is<sem::I32>());
|
||||
EXPECT_EQ(r->StorageClass(), ast::StorageClass::kStorage);
|
||||
EXPECT_EQ(r->Access(), ast::Access::kReadWrite);
|
||||
}
|
||||
|
||||
TEST_F(ReferenceTest, TypeName) {
|
||||
auto* r = create<Reference>(create<I32>(), ast::StorageClass::kWorkgroup);
|
||||
EXPECT_EQ(r->type_name(), "__ref_workgroup__i32");
|
||||
auto* r = create<Reference>(create<I32>(), ast::StorageClass::kWorkgroup,
|
||||
ast::Access::kReadWrite);
|
||||
EXPECT_EQ(r->type_name(), "__ref_workgroup__i32__read_write");
|
||||
}
|
||||
|
||||
TEST_F(ReferenceTest, FriendlyName) {
|
||||
auto* r = create<Reference>(create<I32>(), ast::StorageClass::kNone,
|
||||
ast::Access::kRead);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ref<i32, read>");
|
||||
}
|
||||
|
||||
TEST_F(ReferenceTest, FriendlyNameWithStorageClass) {
|
||||
auto* r = create<Reference>(create<I32>(), ast::StorageClass::kWorkgroup);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ref<workgroup, i32>");
|
||||
}
|
||||
|
||||
TEST_F(ReferenceTest, FriendlyNameWithoutStorageClass) {
|
||||
auto* r = create<Reference>(create<I32>(), ast::StorageClass::kNone);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ref<i32>");
|
||||
auto* r = create<Reference>(create<I32>(), ast::StorageClass::kWorkgroup,
|
||||
ast::Access::kRead);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ref<workgroup, i32, read>");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user