• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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 #include "src/sem/array.h"
16 
17 #include <string>
18 
19 #include "src/debug.h"
20 
21 TINT_INSTANTIATE_TYPEINFO(tint::sem::Array);
22 
23 namespace tint {
24 namespace sem {
25 
Array(const Type * element,uint32_t count,uint32_t align,uint32_t size,uint32_t stride,uint32_t implicit_stride)26 Array::Array(const Type* element,
27              uint32_t count,
28              uint32_t align,
29              uint32_t size,
30              uint32_t stride,
31              uint32_t implicit_stride)
32     : element_(element),
33       count_(count),
34       align_(align),
35       size_(size),
36       stride_(stride),
37       implicit_stride_(implicit_stride),
38       constructible_(count > 0  // Runtime-sized arrays are not constructible
39                      && element->IsConstructible()) {
40   TINT_ASSERT(Semantic, element_);
41 }
42 
IsConstructible() const43 bool Array::IsConstructible() const {
44   return constructible_;
45 }
46 
type_name() const47 std::string Array::type_name() const {
48   std::string type_name = "__array" + element_->type_name();
49   type_name += "_count_" + std::to_string(count_);
50   type_name += "_align_" + std::to_string(align_);
51   type_name += "_size_" + std::to_string(size_);
52   type_name += "_stride_" + std::to_string(stride_);
53   // Note: implicit_stride is not part of the type_name string as this is
54   // derived from the element type
55   return type_name;
56 }
57 
FriendlyName(const SymbolTable & symbols) const58 std::string Array::FriendlyName(const SymbolTable& symbols) const {
59   std::ostringstream out;
60   if (!IsStrideImplicit()) {
61     out << "[[stride(" << stride_ << ")]] ";
62   }
63   out << "array<" << element_->FriendlyName(symbols);
64   if (!IsRuntimeSized()) {
65     out << ", " << count_;
66   }
67   out << ">";
68   return out.str();
69 }
70 
Align() const71 uint32_t Array::Align() const {
72   return align_;
73 }
74 
Size() const75 uint32_t Array::Size() const {
76   return size_;
77 }
78 
79 }  // namespace sem
80 }  // namespace tint
81