1 // Copyright 2020 The Tint Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef SRC_SEM_VECTOR_TYPE_H_ 16 #define SRC_SEM_VECTOR_TYPE_H_ 17 18 #include <string> 19 20 #include "src/sem/type.h" 21 22 namespace tint { 23 namespace sem { 24 25 /// A vector type. 26 class Vector : public Castable<Vector, Type> { 27 public: 28 /// Constructor 29 /// @param subtype the vector element type 30 /// @param size the number of elements in the vector 31 Vector(Type const* subtype, uint32_t size); 32 /// Move constructor 33 Vector(Vector&&); 34 ~Vector() override; 35 36 /// @returns the type of the vector elements type()37 const Type* type() const { return subtype_; } 38 39 /// @returns the name for th type 40 std::string type_name() const override; 41 42 /// @param symbols the program's symbol table 43 /// @returns the name for this type that closely resembles how it would be 44 /// declared in WGSL. 45 std::string FriendlyName(const SymbolTable& symbols) const override; 46 47 /// @returns true if constructible as per 48 /// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types 49 bool IsConstructible() const override; 50 51 /// @returns the number of elements in the vector Width()52 uint32_t Width() const { return width_; } 53 54 /// @returns the size in bytes of the type. This may include tail padding. 55 uint32_t Size() const override; 56 57 /// @returns the alignment in bytes of the type. This may include tail 58 /// padding. 59 uint32_t Align() const override; 60 61 /// @param width the width of the vector 62 /// @returns the size in bytes of a vector of the given width. 63 static uint32_t SizeOf(uint32_t width); 64 65 /// @param width the width of the vector 66 /// @returns the alignment in bytes of a vector of the given width. 67 static uint32_t AlignOf(uint32_t width); 68 69 private: 70 Type const* const subtype_; 71 const uint32_t width_; 72 }; 73 74 } // namespace sem 75 } // namespace tint 76 77 #endif // SRC_SEM_VECTOR_TYPE_H_ 78