sem: Rename Vector::size() to Vector::Width()

`Size()` will be added which is the size of the type in bytes.

Change-Id: If997820d7859cd9d1bb0631d1b72150378e6a24b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59300
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton
2021-07-22 18:31:34 +00:00
committed by Tint LUCI CQ
parent 4261466a84
commit f5ed2ba906
23 changed files with 147 additions and 146 deletions

View File

@@ -36,7 +36,7 @@ const Type* ElemType(const Type* ty, size_t num_elements) {
return ty;
}
if (auto* vec = ty->As<Vector>()) {
if (num_elements != vec->size()) {
if (num_elements != vec->Width()) {
TINT_ICE(Semantic, diag)
<< "sem::Constant() type <-> num_element mismatch. type: '"
<< ty->type_name() << "' num_elements: " << num_elements;

View File

@@ -25,7 +25,7 @@ namespace sem {
Matrix::Matrix(Vector* column_type, uint32_t columns)
: subtype_(column_type->type()),
column_type_(column_type),
rows_(column_type->size()),
rows_(column_type->Width()),
columns_(columns) {
TINT_ASSERT(AST, rows_ > 1);
TINT_ASSERT(AST, rows_ < 5);

View File

@@ -82,9 +82,9 @@ void Type::GetDefaultAlignAndSize(uint32_t& align, uint32_t& size) const {
return;
}
if (auto* vec = As<Vector>()) {
TINT_ASSERT(Semantic, vec->size() >= 2 && vec->size() <= 4);
align = vector_align[vec->size()];
size = vector_size[vec->size()];
TINT_ASSERT(Semantic, vec->Width() >= 2 && vec->Width() <= 4);
align = vector_align[vec->Width()];
size = vector_size[vec->Width()];
return;
}
if (auto* mat = As<Matrix>()) {

View File

@@ -21,10 +21,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::Vector);
namespace tint {
namespace sem {
Vector::Vector(Type const* subtype, uint32_t size)
: subtype_(subtype), size_(size) {
TINT_ASSERT(Semantic, size_ > 1);
TINT_ASSERT(Semantic, size_ < 5);
Vector::Vector(Type const* subtype, uint32_t width)
: subtype_(subtype), width_(width) {
TINT_ASSERT(Semantic, width_ > 1);
TINT_ASSERT(Semantic, width_ < 5);
}
Vector::Vector(Vector&&) = default;
@@ -32,12 +32,12 @@ Vector::Vector(Vector&&) = default;
Vector::~Vector() = default;
std::string Vector::type_name() const {
return "__vec_" + std::to_string(size_) + subtype_->type_name();
return "__vec_" + std::to_string(width_) + subtype_->type_name();
}
std::string Vector::FriendlyName(const SymbolTable& symbols) const {
std::ostringstream out;
out << "vec" << size_ << "<" << subtype_->FriendlyName(symbols) << ">";
out << "vec" << width_ << "<" << subtype_->FriendlyName(symbols) << ">";
return out.str();
}

View File

@@ -35,12 +35,13 @@ class Vector : public Castable<Vector, Type> {
/// @returns the type of the vector elements
Type* type() const { return const_cast<Type*>(subtype_); }
/// @returns the size of the vector
uint32_t size() const { return size_; }
/// @returns the name for th type
std::string type_name() const override;
/// @returns the width of the vector
uint32_t Width() const { return width_; }
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
/// declared in WGSL.
@@ -52,7 +53,7 @@ class Vector : public Castable<Vector, Type> {
private:
Type const* const subtype_;
uint32_t const size_;
uint32_t const width_;
};
} // namespace sem

View File

@@ -25,7 +25,7 @@ TEST_F(VectorTest, Creation) {
I32 i32;
Vector v{&i32, 2};
EXPECT_EQ(v.type(), &i32);
EXPECT_EQ(v.size(), 2u);
EXPECT_EQ(v.Width(), 2u);
}
TEST_F(VectorTest, TypeName) {