Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 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 | #ifndef SRC_TINT_PROGRAM_BUILDER_H_ |
| 16 | #define SRC_TINT_PROGRAM_BUILDER_H_ |
| 17 | |
| 18 | #include <string> |
| 19 | #include <unordered_set> |
| 20 | #include <utility> |
| 21 | |
Ben Clayton | 9a6acc4 | 2022-07-27 20:50:40 +0000 | [diff] [blame] | 22 | #include "tint/override_id.h" |
| 23 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 24 | #include "src/tint/ast/alias.h" |
| 25 | #include "src/tint/ast/array.h" |
| 26 | #include "src/tint/ast/assignment_statement.h" |
| 27 | #include "src/tint/ast/atomic.h" |
| 28 | #include "src/tint/ast/binary_expression.h" |
| 29 | #include "src/tint/ast/binding_attribute.h" |
| 30 | #include "src/tint/ast/bitcast_expression.h" |
| 31 | #include "src/tint/ast/bool.h" |
| 32 | #include "src/tint/ast/bool_literal_expression.h" |
dan sinclair | b8b0c21 | 2022-10-20 22:45:50 +0000 | [diff] [blame] | 33 | #include "src/tint/ast/break_if_statement.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 34 | #include "src/tint/ast/break_statement.h" |
| 35 | #include "src/tint/ast/call_expression.h" |
| 36 | #include "src/tint/ast/call_statement.h" |
| 37 | #include "src/tint/ast/case_statement.h" |
James Price | c022ff5 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 38 | #include "src/tint/ast/compound_assignment_statement.h" |
Ben Clayton | e3834c4 | 2022-06-25 23:21:39 +0000 | [diff] [blame] | 39 | #include "src/tint/ast/const.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 40 | #include "src/tint/ast/continue_statement.h" |
| 41 | #include "src/tint/ast/depth_multisampled_texture.h" |
| 42 | #include "src/tint/ast/depth_texture.h" |
| 43 | #include "src/tint/ast/disable_validation_attribute.h" |
| 44 | #include "src/tint/ast/discard_statement.h" |
Zhaoming Jiang | 7098d3d | 2022-04-27 02:27:52 +0000 | [diff] [blame] | 45 | #include "src/tint/ast/enable.h" |
Ben Clayton | 7f2b8cd | 2022-05-18 22:41:48 +0000 | [diff] [blame] | 46 | #include "src/tint/ast/extension.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 47 | #include "src/tint/ast/external_texture.h" |
Zhaoming Jiang | 62bfd31 | 2022-05-13 12:01:11 +0000 | [diff] [blame] | 48 | #include "src/tint/ast/f16.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 49 | #include "src/tint/ast/f32.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 50 | #include "src/tint/ast/float_literal_expression.h" |
| 51 | #include "src/tint/ast/for_loop_statement.h" |
| 52 | #include "src/tint/ast/i32.h" |
| 53 | #include "src/tint/ast/id_attribute.h" |
| 54 | #include "src/tint/ast/if_statement.h" |
James Price | ebe9741 | 2022-04-07 13:42:45 +0000 | [diff] [blame] | 55 | #include "src/tint/ast/increment_decrement_statement.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 56 | #include "src/tint/ast/index_accessor_expression.h" |
dan sinclair | d32fbe0 | 2022-10-19 00:43:41 +0000 | [diff] [blame] | 57 | #include "src/tint/ast/int_literal_expression.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 58 | #include "src/tint/ast/interpolate_attribute.h" |
| 59 | #include "src/tint/ast/invariant_attribute.h" |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 60 | #include "src/tint/ast/let.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 61 | #include "src/tint/ast/loop_statement.h" |
| 62 | #include "src/tint/ast/matrix.h" |
| 63 | #include "src/tint/ast/member_accessor_expression.h" |
| 64 | #include "src/tint/ast/module.h" |
| 65 | #include "src/tint/ast/multisampled_texture.h" |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 66 | #include "src/tint/ast/override.h" |
| 67 | #include "src/tint/ast/parameter.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 68 | #include "src/tint/ast/phony_expression.h" |
| 69 | #include "src/tint/ast/pointer.h" |
| 70 | #include "src/tint/ast/return_statement.h" |
| 71 | #include "src/tint/ast/sampled_texture.h" |
| 72 | #include "src/tint/ast/sampler.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 73 | #include "src/tint/ast/stage_attribute.h" |
Ben Clayton | bfd1a81 | 2022-08-02 23:16:25 +0000 | [diff] [blame] | 74 | #include "src/tint/ast/static_assert.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 75 | #include "src/tint/ast/storage_texture.h" |
| 76 | #include "src/tint/ast/stride_attribute.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 77 | #include "src/tint/ast/struct_member_align_attribute.h" |
| 78 | #include "src/tint/ast/struct_member_offset_attribute.h" |
| 79 | #include "src/tint/ast/struct_member_size_attribute.h" |
| 80 | #include "src/tint/ast/switch_statement.h" |
| 81 | #include "src/tint/ast/type_name.h" |
| 82 | #include "src/tint/ast/u32.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 83 | #include "src/tint/ast/unary_op_expression.h" |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 84 | #include "src/tint/ast/var.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 85 | #include "src/tint/ast/variable_decl_statement.h" |
| 86 | #include "src/tint/ast/vector.h" |
| 87 | #include "src/tint/ast/void.h" |
dan sinclair | 49d1a2d | 2022-06-16 12:01:27 +0000 | [diff] [blame] | 88 | #include "src/tint/ast/while_statement.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 89 | #include "src/tint/ast/workgroup_attribute.h" |
dan sinclair | 02b466f | 2022-12-15 21:56:32 +0000 | [diff] [blame] | 90 | #include "src/tint/constant/composite.h" |
| 91 | #include "src/tint/constant/splat.h" |
dan sinclair | b53b8cf | 2022-12-15 16:25:31 +0000 | [diff] [blame] | 92 | #include "src/tint/constant/value.h" |
Ben Clayton | 0ce9ab0 | 2022-05-05 20:23:40 +0000 | [diff] [blame] | 93 | #include "src/tint/number.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 94 | #include "src/tint/program.h" |
| 95 | #include "src/tint/program_id.h" |
dan sinclair | 4b1d79e | 2022-12-01 23:45:18 +0000 | [diff] [blame] | 96 | #include "src/tint/sem/array_count.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 97 | #include "src/tint/sem/struct.h" |
dan sinclair | 946858a | 2022-12-08 22:21:24 +0000 | [diff] [blame] | 98 | #include "src/tint/type/array.h" |
dan sinclair | d37ecf9 | 2022-12-08 16:39:59 +0000 | [diff] [blame] | 99 | #include "src/tint/type/bool.h" |
dan sinclair | 4595fb7 | 2022-12-08 14:14:10 +0000 | [diff] [blame] | 100 | #include "src/tint/type/depth_texture.h" |
| 101 | #include "src/tint/type/external_texture.h" |
dan sinclair | d37ecf9 | 2022-12-08 16:39:59 +0000 | [diff] [blame] | 102 | #include "src/tint/type/f16.h" |
| 103 | #include "src/tint/type/f32.h" |
| 104 | #include "src/tint/type/i32.h" |
dan sinclair | 0e780da | 2022-12-08 22:21:24 +0000 | [diff] [blame] | 105 | #include "src/tint/type/matrix.h" |
dan sinclair | 4595fb7 | 2022-12-08 14:14:10 +0000 | [diff] [blame] | 106 | #include "src/tint/type/multisampled_texture.h" |
dan sinclair | 4d56b48 | 2022-12-08 17:50:50 +0000 | [diff] [blame] | 107 | #include "src/tint/type/pointer.h" |
dan sinclair | 4595fb7 | 2022-12-08 14:14:10 +0000 | [diff] [blame] | 108 | #include "src/tint/type/sampled_texture.h" |
| 109 | #include "src/tint/type/storage_texture.h" |
dan sinclair | d37ecf9 | 2022-12-08 16:39:59 +0000 | [diff] [blame] | 110 | #include "src/tint/type/u32.h" |
dan sinclair | 0e780da | 2022-12-08 22:21:24 +0000 | [diff] [blame] | 111 | #include "src/tint/type/vector.h" |
dan sinclair | d37ecf9 | 2022-12-08 16:39:59 +0000 | [diff] [blame] | 112 | #include "src/tint/type/void.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 113 | |
Ben Clayton | 8fa6c25 | 2022-11-03 19:16:26 +0000 | [diff] [blame] | 114 | #ifdef CURRENTLY_IN_TINT_PUBLIC_HEADER |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 115 | #error "internal tint header being #included from tint.h" |
| 116 | #endif |
| 117 | |
| 118 | // Forward declarations |
Ben Clayton | a7230f0 | 2022-04-11 14:37:21 +0000 | [diff] [blame] | 119 | namespace tint { |
| 120 | class CloneContext; |
| 121 | } // namespace tint |
dan sinclair | 8155b9d | 2022-04-07 19:10:25 +0000 | [diff] [blame] | 122 | namespace tint::ast { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 123 | class VariableDeclStatement; |
dan sinclair | 8155b9d | 2022-04-07 19:10:25 +0000 | [diff] [blame] | 124 | } // namespace tint::ast |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 125 | |
| 126 | namespace tint { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 127 | |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 128 | namespace detail { |
| 129 | |
| 130 | /// IsVectorLike<T>::value is true if T is a utils::Vector or utils::VectorRef. |
| 131 | template <typename T> |
| 132 | struct IsVectorLike { |
| 133 | /// Non-specialized form of IsVectorLike defaults to false |
| 134 | static constexpr bool value = false; |
| 135 | }; |
| 136 | |
| 137 | /// IsVectorLike specialization for utils::Vector |
| 138 | template <typename T, size_t N> |
| 139 | struct IsVectorLike<utils::Vector<T, N>> { |
| 140 | /// True for the IsVectorLike specialization of utils::Vector |
| 141 | static constexpr bool value = true; |
| 142 | }; |
| 143 | |
| 144 | /// IsVectorLike specialization for utils::VectorRef |
| 145 | template <typename T> |
| 146 | struct IsVectorLike<utils::VectorRef<T>> { |
| 147 | /// True for the IsVectorLike specialization of utils::VectorRef |
| 148 | static constexpr bool value = true; |
| 149 | }; |
| 150 | } // namespace detail |
| 151 | |
Antonio Maiorano | dfa92a9 | 2022-12-23 17:56:56 +0000 | [diff] [blame^] | 152 | // Forward declare metafunction that evaluates to true iff T can be wrapped in a statement. |
| 153 | template <typename T, typename = void> |
| 154 | struct CanWrapInStatement; |
| 155 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 156 | /// ProgramBuilder is a mutable builder for a Program. |
| 157 | /// To construct a Program, populate the builder and then `std::move` it to a |
| 158 | /// Program. |
| 159 | class ProgramBuilder { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 160 | /// A helper used to disable overloads if the first type in `TYPES` is a |
| 161 | /// Source. Used to avoid ambiguities in overloads that take a Source as the |
| 162 | /// first parameter and those that perfectly-forward the first argument. |
| 163 | template <typename... TYPES> |
| 164 | using DisableIfSource = |
| 165 | traits::EnableIfIsNotType<traits::Decay<traits::NthTypeOf<0, TYPES..., void>>, Source>; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 166 | |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 167 | /// A helper used to disable overloads if the first type in `TYPES` is a utils::Vector, |
| 168 | /// utils::VectorRef or utils::VectorRef. |
| 169 | template <typename... TYPES> |
| 170 | using DisableIfVectorLike = traits::EnableIf< |
| 171 | !detail::IsVectorLike<traits::Decay<traits::NthTypeOf<0, TYPES..., void>>>::value>; |
| 172 | |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 173 | /// VarOptions is a helper for accepting an arbitrary number of order independent options for |
| 174 | /// constructing an ast::Var. |
| 175 | struct VarOptions { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 176 | template <typename... ARGS> |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 177 | explicit VarOptions(ARGS&&... args) { |
| 178 | (Set(std::forward<ARGS>(args)), ...); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 179 | } |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 180 | ~VarOptions(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 181 | |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 182 | const ast::Type* type = nullptr; |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 183 | ast::AddressSpace address_space = ast::AddressSpace::kNone; |
Ben Clayton | d2e0db3 | 2022-10-12 18:49:15 +0000 | [diff] [blame] | 184 | ast::Access access = ast::Access::kUndefined; |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 185 | const ast::Expression* initializer = nullptr; |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 186 | utils::Vector<const ast::Attribute*, 4> attributes; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 187 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 188 | private: |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 189 | void Set(const ast::Type* t) { type = t; } |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 190 | void Set(ast::AddressSpace addr_space) { address_space = addr_space; } |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 191 | void Set(ast::Access ac) { access = ac; } |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 192 | void Set(const ast::Expression* c) { initializer = c; } |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 193 | void Set(utils::VectorRef<const ast::Attribute*> l) { attributes = std::move(l); } |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 194 | void Set(const ast::Attribute* a) { attributes.Push(a); } |
| 195 | }; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 196 | |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 197 | /// LetOptions is a helper for accepting an arbitrary number of order independent options for |
| 198 | /// constructing an ast::Let. |
| 199 | struct LetOptions { |
| 200 | template <typename... ARGS> |
| 201 | explicit LetOptions(ARGS&&... args) { |
| 202 | static constexpr bool has_init = |
| 203 | (traits::IsTypeOrDerived<std::remove_pointer_t<std::remove_reference_t<ARGS>>, |
| 204 | ast::Expression> || |
| 205 | ...); |
| 206 | static_assert(has_init, "Let() must be constructed with an initializer expression"); |
| 207 | (Set(std::forward<ARGS>(args)), ...); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 208 | } |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 209 | ~LetOptions(); |
| 210 | |
| 211 | const ast::Type* type = nullptr; |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 212 | const ast::Expression* initializer = nullptr; |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 213 | utils::Vector<const ast::Attribute*, 4> attributes; |
| 214 | |
| 215 | private: |
| 216 | void Set(const ast::Type* t) { type = t; } |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 217 | void Set(const ast::Expression* c) { initializer = c; } |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 218 | void Set(utils::VectorRef<const ast::Attribute*> l) { attributes = std::move(l); } |
| 219 | void Set(const ast::Attribute* a) { attributes.Push(a); } |
| 220 | }; |
| 221 | |
| 222 | /// ConstOptions is a helper for accepting an arbitrary number of order independent options for |
| 223 | /// constructing an ast::Const. |
| 224 | struct ConstOptions { |
| 225 | template <typename... ARGS> |
| 226 | explicit ConstOptions(ARGS&&... args) { |
| 227 | static constexpr bool has_init = |
| 228 | (traits::IsTypeOrDerived<std::remove_pointer_t<std::remove_reference_t<ARGS>>, |
| 229 | ast::Expression> || |
| 230 | ...); |
| 231 | static_assert(has_init, "Const() must be constructed with an initializer expression"); |
| 232 | (Set(std::forward<ARGS>(args)), ...); |
| 233 | } |
| 234 | ~ConstOptions(); |
| 235 | |
| 236 | const ast::Type* type = nullptr; |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 237 | const ast::Expression* initializer = nullptr; |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 238 | utils::Vector<const ast::Attribute*, 4> attributes; |
| 239 | |
| 240 | private: |
| 241 | void Set(const ast::Type* t) { type = t; } |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 242 | void Set(const ast::Expression* c) { initializer = c; } |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 243 | void Set(utils::VectorRef<const ast::Attribute*> l) { attributes = std::move(l); } |
| 244 | void Set(const ast::Attribute* a) { attributes.Push(a); } |
| 245 | }; |
| 246 | |
| 247 | /// OverrideOptions is a helper for accepting an arbitrary number of order independent options |
| 248 | /// for constructing an ast::Override. |
| 249 | struct OverrideOptions { |
| 250 | template <typename... ARGS> |
| 251 | explicit OverrideOptions(ARGS&&... args) { |
| 252 | (Set(std::forward<ARGS>(args)), ...); |
| 253 | } |
| 254 | ~OverrideOptions(); |
| 255 | |
| 256 | const ast::Type* type = nullptr; |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 257 | const ast::Expression* initializer = nullptr; |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 258 | utils::Vector<const ast::Attribute*, 4> attributes; |
| 259 | |
| 260 | private: |
| 261 | void Set(const ast::Type* t) { type = t; } |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 262 | void Set(const ast::Expression* c) { initializer = c; } |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 263 | void Set(utils::VectorRef<const ast::Attribute*> l) { attributes = std::move(l); } |
| 264 | void Set(const ast::Attribute* a) { attributes.Push(a); } |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 265 | }; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 266 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 267 | public: |
| 268 | /// ASTNodeAllocator is an alias to BlockAllocator<ast::Node> |
| 269 | using ASTNodeAllocator = utils::BlockAllocator<ast::Node>; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 270 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 271 | /// SemNodeAllocator is an alias to BlockAllocator<sem::Node> |
| 272 | using SemNodeAllocator = utils::BlockAllocator<sem::Node>; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 273 | |
dan sinclair | b53b8cf | 2022-12-15 16:25:31 +0000 | [diff] [blame] | 274 | /// ConstantAllocator is an alias to BlockAllocator<constant::Value> |
| 275 | using ConstantAllocator = utils::BlockAllocator<constant::Value>; |
Ben Clayton | aa037ac | 2022-06-29 19:07:30 +0000 | [diff] [blame] | 276 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 277 | /// Constructor |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 278 | ProgramBuilder(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 279 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 280 | /// Move constructor |
| 281 | /// @param rhs the builder to move |
| 282 | ProgramBuilder(ProgramBuilder&& rhs); |
| 283 | |
| 284 | /// Destructor |
| 285 | virtual ~ProgramBuilder(); |
| 286 | |
| 287 | /// Move assignment operator |
| 288 | /// @param rhs the builder to move |
| 289 | /// @return this builder |
| 290 | ProgramBuilder& operator=(ProgramBuilder&& rhs); |
| 291 | |
| 292 | /// Wrap returns a new ProgramBuilder wrapping the Program `program` without |
| 293 | /// making a deep clone of the Program contents. |
| 294 | /// ProgramBuilder returned by Wrap() is intended to temporarily extend an |
| 295 | /// existing immutable program. |
| 296 | /// As the returned ProgramBuilder wraps `program`, `program` must not be |
| 297 | /// destructed or assigned while using the returned ProgramBuilder. |
| 298 | /// TODO(bclayton) - Evaluate whether there are safer alternatives to this |
| 299 | /// function. See crbug.com/tint/460. |
| 300 | /// @param program the immutable Program to wrap |
| 301 | /// @return the ProgramBuilder that wraps `program` |
| 302 | static ProgramBuilder Wrap(const Program* program); |
| 303 | |
| 304 | /// @returns the unique identifier for this program |
| 305 | ProgramID ID() const { return id_; } |
| 306 | |
| 307 | /// @returns a reference to the program's types |
dan sinclair | 837b804 | 2022-12-09 05:00:07 +0000 | [diff] [blame] | 308 | type::Manager& Types() { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 309 | AssertNotMoved(); |
| 310 | return types_; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 311 | } |
| 312 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 313 | /// @returns a reference to the program's types |
dan sinclair | 837b804 | 2022-12-09 05:00:07 +0000 | [diff] [blame] | 314 | const type::Manager& Types() const { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 315 | AssertNotMoved(); |
| 316 | return types_; |
| 317 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 318 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 319 | /// @returns a reference to the program's AST nodes storage |
| 320 | ASTNodeAllocator& ASTNodes() { |
| 321 | AssertNotMoved(); |
| 322 | return ast_nodes_; |
| 323 | } |
| 324 | |
| 325 | /// @returns a reference to the program's AST nodes storage |
| 326 | const ASTNodeAllocator& ASTNodes() const { |
| 327 | AssertNotMoved(); |
| 328 | return ast_nodes_; |
| 329 | } |
| 330 | |
| 331 | /// @returns a reference to the program's semantic nodes storage |
| 332 | SemNodeAllocator& SemNodes() { |
| 333 | AssertNotMoved(); |
| 334 | return sem_nodes_; |
| 335 | } |
| 336 | |
| 337 | /// @returns a reference to the program's semantic nodes storage |
| 338 | const SemNodeAllocator& SemNodes() const { |
| 339 | AssertNotMoved(); |
| 340 | return sem_nodes_; |
| 341 | } |
| 342 | |
Ben Clayton | aa037ac | 2022-06-29 19:07:30 +0000 | [diff] [blame] | 343 | /// @returns a reference to the program's semantic constant storage |
| 344 | ConstantAllocator& ConstantNodes() { |
| 345 | AssertNotMoved(); |
| 346 | return constant_nodes_; |
| 347 | } |
| 348 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 349 | /// @returns a reference to the program's AST root Module |
| 350 | ast::Module& AST() { |
| 351 | AssertNotMoved(); |
| 352 | return *ast_; |
| 353 | } |
| 354 | |
| 355 | /// @returns a reference to the program's AST root Module |
| 356 | const ast::Module& AST() const { |
| 357 | AssertNotMoved(); |
| 358 | return *ast_; |
| 359 | } |
| 360 | |
| 361 | /// @returns a reference to the program's semantic info |
| 362 | sem::Info& Sem() { |
| 363 | AssertNotMoved(); |
| 364 | return sem_; |
| 365 | } |
| 366 | |
| 367 | /// @returns a reference to the program's semantic info |
| 368 | const sem::Info& Sem() const { |
| 369 | AssertNotMoved(); |
| 370 | return sem_; |
| 371 | } |
| 372 | |
| 373 | /// @returns a reference to the program's SymbolTable |
| 374 | SymbolTable& Symbols() { |
| 375 | AssertNotMoved(); |
| 376 | return symbols_; |
| 377 | } |
| 378 | |
| 379 | /// @returns a reference to the program's SymbolTable |
| 380 | const SymbolTable& Symbols() const { |
| 381 | AssertNotMoved(); |
| 382 | return symbols_; |
| 383 | } |
| 384 | |
| 385 | /// @returns a reference to the program's diagnostics |
| 386 | diag::List& Diagnostics() { |
| 387 | AssertNotMoved(); |
| 388 | return diagnostics_; |
| 389 | } |
| 390 | |
| 391 | /// @returns a reference to the program's diagnostics |
| 392 | const diag::List& Diagnostics() const { |
| 393 | AssertNotMoved(); |
| 394 | return diagnostics_; |
| 395 | } |
| 396 | |
| 397 | /// Controls whether the Resolver will be run on the program when it is built. |
| 398 | /// @param enable the new flag value (defaults to true) |
| 399 | void SetResolveOnBuild(bool enable) { resolve_on_build_ = enable; } |
| 400 | |
| 401 | /// @return true if the Resolver will be run on the program when it is |
| 402 | /// built. |
| 403 | bool ResolveOnBuild() const { return resolve_on_build_; } |
| 404 | |
| 405 | /// @returns true if the program has no error diagnostics and is not missing |
| 406 | /// information |
| 407 | bool IsValid() const; |
| 408 | |
Ben Clayton | 4a92a3c | 2022-07-18 20:50:02 +0000 | [diff] [blame] | 409 | /// @returns the last allocated (numerically highest) AST node identifier. |
| 410 | ast::NodeID LastAllocatedNodeID() const { return last_ast_node_id_; } |
| 411 | |
| 412 | /// @returns the next sequentially unique node identifier. |
| 413 | ast::NodeID AllocateNodeID() { |
| 414 | auto out = ast::NodeID{last_ast_node_id_.value + 1}; |
| 415 | last_ast_node_id_ = out; |
| 416 | return out; |
| 417 | } |
| 418 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 419 | /// Creates a new ast::Node owned by the ProgramBuilder. When the |
| 420 | /// ProgramBuilder is destructed, the ast::Node will also be destructed. |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 421 | /// @param source the Source of the node |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 422 | /// @param args the arguments to pass to the type constructor |
| 423 | /// @returns the node pointer |
| 424 | template <typename T, typename... ARGS> |
| 425 | traits::EnableIfIsType<T, ast::Node>* create(const Source& source, ARGS&&... args) { |
| 426 | AssertNotMoved(); |
Ben Clayton | 4a92a3c | 2022-07-18 20:50:02 +0000 | [diff] [blame] | 427 | return ast_nodes_.Create<T>(id_, AllocateNodeID(), source, std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 428 | } |
| 429 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 430 | /// Creates a new ast::Node owned by the ProgramBuilder, injecting the current |
| 431 | /// Source as set by the last call to SetSource() as the only argument to the |
| 432 | /// constructor. |
| 433 | /// When the ProgramBuilder is destructed, the ast::Node will also be |
| 434 | /// destructed. |
| 435 | /// @returns the node pointer |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 436 | template <typename T> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 437 | traits::EnableIfIsType<T, ast::Node>* create() { |
| 438 | AssertNotMoved(); |
Ben Clayton | 4a92a3c | 2022-07-18 20:50:02 +0000 | [diff] [blame] | 439 | return ast_nodes_.Create<T>(id_, AllocateNodeID(), source_); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 440 | } |
| 441 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 442 | /// Creates a new ast::Node owned by the ProgramBuilder, injecting the current |
| 443 | /// Source as set by the last call to SetSource() as the first argument to the |
| 444 | /// constructor. |
| 445 | /// When the ProgramBuilder is destructed, the ast::Node will also be |
| 446 | /// destructed. |
| 447 | /// @param arg0 the first arguments to pass to the type constructor |
| 448 | /// @param args the remaining arguments to pass to the type constructor |
| 449 | /// @returns the node pointer |
| 450 | template <typename T, typename ARG0, typename... ARGS> |
| 451 | traits::EnableIf</* T is ast::Node and ARG0 is not Source */ |
| 452 | traits::IsTypeOrDerived<T, ast::Node> && |
| 453 | !traits::IsTypeOrDerived<ARG0, Source>, |
| 454 | T>* |
| 455 | create(ARG0&& arg0, ARGS&&... args) { |
| 456 | AssertNotMoved(); |
Ben Clayton | 4a92a3c | 2022-07-18 20:50:02 +0000 | [diff] [blame] | 457 | return ast_nodes_.Create<T>(id_, AllocateNodeID(), source_, std::forward<ARG0>(arg0), |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 458 | std::forward<ARGS>(args)...); |
| 459 | } |
| 460 | |
| 461 | /// Creates a new sem::Node owned by the ProgramBuilder. |
Ben Clayton | aa037ac | 2022-06-29 19:07:30 +0000 | [diff] [blame] | 462 | /// When the ProgramBuilder is destructed, the sem::Node will also be destructed. |
| 463 | /// @param args the arguments to pass to the constructor |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 464 | /// @returns the node pointer |
| 465 | template <typename T, typename... ARGS> |
| 466 | traits::EnableIf<traits::IsTypeOrDerived<T, sem::Node> && |
dan sinclair | 5f764d8 | 2022-12-08 00:32:27 +0000 | [diff] [blame] | 467 | !traits::IsTypeOrDerived<T, type::Node>, |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 468 | T>* |
| 469 | create(ARGS&&... args) { |
| 470 | AssertNotMoved(); |
| 471 | return sem_nodes_.Create<T>(std::forward<ARGS>(args)...); |
| 472 | } |
| 473 | |
dan sinclair | b53b8cf | 2022-12-15 16:25:31 +0000 | [diff] [blame] | 474 | /// Creates a new constant::Value owned by the ProgramBuilder. |
Ben Clayton | aa037ac | 2022-06-29 19:07:30 +0000 | [diff] [blame] | 475 | /// When the ProgramBuilder is destructed, the sem::Node will also be destructed. |
| 476 | /// @param args the arguments to pass to the constructor |
| 477 | /// @returns the node pointer |
| 478 | template <typename T, typename... ARGS> |
dan sinclair | 02b466f | 2022-12-15 21:56:32 +0000 | [diff] [blame] | 479 | traits::EnableIf<traits::IsTypeOrDerived<T, constant::Value> && |
| 480 | !traits::IsTypeOrDerived<T, constant::Composite> && |
| 481 | !traits::IsTypeOrDerived<T, constant::Splat>, |
| 482 | T>* |
| 483 | create(ARGS&&... args) { |
Ben Clayton | aa037ac | 2022-06-29 19:07:30 +0000 | [diff] [blame] | 484 | AssertNotMoved(); |
| 485 | return constant_nodes_.Create<T>(std::forward<ARGS>(args)...); |
| 486 | } |
| 487 | |
dan sinclair | 02b466f | 2022-12-15 21:56:32 +0000 | [diff] [blame] | 488 | /// Constructs a constant of a vector, matrix or array type. |
| 489 | /// |
| 490 | /// Examines the element values and will return either a constant::Composite or a |
| 491 | /// constant::Splat, depending on the element types and values. |
| 492 | /// |
| 493 | /// @param type the composite type |
| 494 | /// @param elements the composite elements |
| 495 | /// @returns the node pointer |
| 496 | template <typename T> |
| 497 | traits::EnableIf<traits::IsTypeOrDerived<T, constant::Composite> || |
| 498 | traits::IsTypeOrDerived<T, constant::Splat>, |
| 499 | const constant::Value>* |
| 500 | create(const type::Type* type, utils::VectorRef<const constant::Value*> elements) { |
| 501 | AssertNotMoved(); |
| 502 | if (elements.IsEmpty()) { |
| 503 | return nullptr; |
| 504 | } |
| 505 | |
| 506 | bool any_zero = false; |
| 507 | bool all_zero = true; |
| 508 | bool all_equal = true; |
| 509 | auto* first = elements.Front(); |
| 510 | for (auto* el : elements) { |
| 511 | if (!el) { |
| 512 | return nullptr; |
| 513 | } |
| 514 | if (!any_zero && el->AnyZero()) { |
| 515 | any_zero = true; |
| 516 | } |
| 517 | if (all_zero && !el->AllZero()) { |
| 518 | all_zero = false; |
| 519 | } |
| 520 | if (all_equal && el != first) { |
| 521 | if (!el->Equal(first)) { |
| 522 | all_equal = false; |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | if (all_equal) { |
| 527 | return create<constant::Splat>(type, elements[0], elements.Length()); |
| 528 | } |
| 529 | |
| 530 | return constant_nodes_.Create<constant::Composite>(type, std::move(elements), all_zero, |
| 531 | any_zero); |
| 532 | } |
| 533 | |
| 534 | /// Constructs a splat constant. |
| 535 | /// @param type the splat type |
| 536 | /// @param element the splat element |
| 537 | /// @param n the number of elements |
| 538 | /// @returns the node pointer |
| 539 | template <typename T> |
| 540 | traits::EnableIf<traits::IsTypeOrDerived<T, constant::Splat>, const constant::Splat>* |
| 541 | create(const type::Type* type, const constant::Value* element, size_t n) { |
| 542 | AssertNotMoved(); |
| 543 | return constant_nodes_.Create<constant::Splat>(type, element, n); |
| 544 | } |
| 545 | |
Ben Clayton | 7c3e9a6 | 2022-12-16 15:31:19 +0000 | [diff] [blame] | 546 | /// Creates a new type::Node owned by the ProgramBuilder. |
| 547 | /// When the ProgramBuilder is destructed, owned ProgramBuilder and the returned node will also |
| 548 | /// be destructed. If T derives from type::UniqueNode, then the calling create() for the same |
| 549 | /// `T` and arguments will return the same pointer. |
| 550 | /// @param args the arguments to pass to the constructor |
| 551 | /// @returns the new, or existing node |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 552 | template <typename T, typename... ARGS> |
Ben Clayton | 7c3e9a6 | 2022-12-16 15:31:19 +0000 | [diff] [blame] | 553 | traits::EnableIfIsType<T, type::Node>* create(ARGS&&... args) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 554 | AssertNotMoved(); |
| 555 | return types_.Get<T>(std::forward<ARGS>(args)...); |
| 556 | } |
dan sinclair | 5f764d8 | 2022-12-08 00:32:27 +0000 | [diff] [blame] | 557 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 558 | /// Marks this builder as moved, preventing any further use of the builder. |
| 559 | void MarkAsMoved(); |
| 560 | |
| 561 | ////////////////////////////////////////////////////////////////////////////// |
| 562 | // TypesBuilder |
| 563 | ////////////////////////////////////////////////////////////////////////////// |
| 564 | |
| 565 | /// TypesBuilder holds basic `tint` types and methods for constructing |
| 566 | /// complex types. |
| 567 | class TypesBuilder { |
| 568 | public: |
| 569 | /// Constructor |
| 570 | /// @param builder the program builder |
| 571 | explicit TypesBuilder(ProgramBuilder* builder); |
| 572 | |
| 573 | /// @return the tint AST type for the C type `T`. |
| 574 | template <typename T> |
| 575 | const ast::Type* Of() const { |
| 576 | return CToAST<T>::get(this); |
| 577 | } |
| 578 | |
| 579 | /// @returns a boolean type |
| 580 | const ast::Bool* bool_() const { return builder->create<ast::Bool>(); } |
| 581 | |
| 582 | /// @param source the Source of the node |
| 583 | /// @returns a boolean type |
| 584 | const ast::Bool* bool_(const Source& source) const { |
| 585 | return builder->create<ast::Bool>(source); |
| 586 | } |
| 587 | |
Zhaoming Jiang | 62bfd31 | 2022-05-13 12:01:11 +0000 | [diff] [blame] | 588 | /// @returns a f16 type |
| 589 | const ast::F16* f16() const { return builder->create<ast::F16>(); } |
| 590 | |
| 591 | /// @param source the Source of the node |
| 592 | /// @returns a f16 type |
| 593 | const ast::F16* f16(const Source& source) const { |
| 594 | return builder->create<ast::F16>(source); |
| 595 | } |
| 596 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 597 | /// @returns a f32 type |
| 598 | const ast::F32* f32() const { return builder->create<ast::F32>(); } |
| 599 | |
| 600 | /// @param source the Source of the node |
| 601 | /// @returns a f32 type |
| 602 | const ast::F32* f32(const Source& source) const { |
| 603 | return builder->create<ast::F32>(source); |
| 604 | } |
| 605 | |
| 606 | /// @returns a i32 type |
| 607 | const ast::I32* i32() const { return builder->create<ast::I32>(); } |
| 608 | |
| 609 | /// @param source the Source of the node |
| 610 | /// @returns a i32 type |
| 611 | const ast::I32* i32(const Source& source) const { |
| 612 | return builder->create<ast::I32>(source); |
| 613 | } |
| 614 | |
| 615 | /// @returns a u32 type |
| 616 | const ast::U32* u32() const { return builder->create<ast::U32>(); } |
| 617 | |
| 618 | /// @param source the Source of the node |
| 619 | /// @returns a u32 type |
| 620 | const ast::U32* u32(const Source& source) const { |
| 621 | return builder->create<ast::U32>(source); |
| 622 | } |
| 623 | |
| 624 | /// @returns a void type |
| 625 | const ast::Void* void_() const { return builder->create<ast::Void>(); } |
| 626 | |
| 627 | /// @param source the Source of the node |
| 628 | /// @returns a void type |
| 629 | const ast::Void* void_(const Source& source) const { |
| 630 | return builder->create<ast::Void>(source); |
| 631 | } |
| 632 | |
| 633 | /// @param type vector subtype |
| 634 | /// @param n vector width in elements |
| 635 | /// @return the tint AST type for a `n`-element vector of `type`. |
| 636 | const ast::Vector* vec(const ast::Type* type, uint32_t n) const { |
| 637 | return builder->create<ast::Vector>(type, n); |
| 638 | } |
| 639 | |
| 640 | /// @param source the Source of the node |
| 641 | /// @param type vector subtype |
| 642 | /// @param n vector width in elements |
| 643 | /// @return the tint AST type for a `n`-element vector of `type`. |
| 644 | const ast::Vector* vec(const Source& source, const ast::Type* type, uint32_t n) const { |
| 645 | return builder->create<ast::Vector>(source, type, n); |
| 646 | } |
| 647 | |
| 648 | /// @param type vector subtype |
| 649 | /// @return the tint AST type for a 2-element vector of `type`. |
| 650 | const ast::Vector* vec2(const ast::Type* type) const { return vec(type, 2u); } |
| 651 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 652 | /// @param source the vector source |
| 653 | /// @param type vector subtype |
| 654 | /// @return the tint AST type for a 2-element vector of `type`. |
| 655 | const ast::Vector* vec2(const Source& source, const ast::Type* type) const { |
| 656 | return vec(source, type, 2u); |
| 657 | } |
| 658 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 659 | /// @param type vector subtype |
| 660 | /// @return the tint AST type for a 3-element vector of `type`. |
| 661 | const ast::Vector* vec3(const ast::Type* type) const { return vec(type, 3u); } |
| 662 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 663 | /// @param source the vector source |
| 664 | /// @param type vector subtype |
| 665 | /// @return the tint AST type for a 3-element vector of `type`. |
| 666 | const ast::Vector* vec3(const Source& source, const ast::Type* type) const { |
| 667 | return vec(source, type, 3u); |
| 668 | } |
| 669 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 670 | /// @param type vector subtype |
| 671 | /// @return the tint AST type for a 4-element vector of `type`. |
| 672 | const ast::Vector* vec4(const ast::Type* type) const { return vec(type, 4u); } |
| 673 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 674 | /// @param source the vector source |
| 675 | /// @param type vector subtype |
| 676 | /// @return the tint AST type for a 4-element vector of `type`. |
| 677 | const ast::Vector* vec4(const Source& source, const ast::Type* type) const { |
| 678 | return vec(source, type, 4u); |
| 679 | } |
| 680 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 681 | /// @param n vector width in elements |
| 682 | /// @return the tint AST type for a `n`-element vector of `type`. |
| 683 | template <typename T> |
| 684 | const ast::Vector* vec(uint32_t n) const { |
| 685 | return vec(Of<T>(), n); |
| 686 | } |
| 687 | |
| 688 | /// @return the tint AST type for a 2-element vector of the C type `T`. |
| 689 | template <typename T> |
| 690 | const ast::Vector* vec2() const { |
| 691 | return vec2(Of<T>()); |
| 692 | } |
| 693 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 694 | /// @param source the Source of the node |
| 695 | /// @return the tint AST type for a 2-element vector of the C type `T`. |
| 696 | template <typename T> |
| 697 | const ast::Vector* vec2(const Source& source) const { |
| 698 | return vec2(source, Of<T>()); |
| 699 | } |
| 700 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 701 | /// @return the tint AST type for a 3-element vector of the C type `T`. |
| 702 | template <typename T> |
| 703 | const ast::Vector* vec3() const { |
| 704 | return vec3(Of<T>()); |
| 705 | } |
| 706 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 707 | /// @param source the Source of the node |
| 708 | /// @return the tint AST type for a 3-element vector of the C type `T`. |
| 709 | template <typename T> |
| 710 | const ast::Vector* vec3(const Source& source) const { |
| 711 | return vec3(source, Of<T>()); |
| 712 | } |
| 713 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 714 | /// @return the tint AST type for a 4-element vector of the C type `T`. |
| 715 | template <typename T> |
| 716 | const ast::Vector* vec4() const { |
| 717 | return vec4(Of<T>()); |
| 718 | } |
| 719 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 720 | /// @param source the Source of the node |
| 721 | /// @return the tint AST type for a 4-element vector of the C type `T`. |
| 722 | template <typename T> |
| 723 | const ast::Vector* vec4(const Source& source) const { |
| 724 | return vec4(source, Of<T>()); |
| 725 | } |
| 726 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 727 | /// @param type matrix subtype |
| 728 | /// @param columns number of columns for the matrix |
| 729 | /// @param rows number of rows for the matrix |
| 730 | /// @return the tint AST type for a matrix of `type` |
| 731 | const ast::Matrix* mat(const ast::Type* type, uint32_t columns, uint32_t rows) const { |
| 732 | return builder->create<ast::Matrix>(type, rows, columns); |
| 733 | } |
| 734 | |
| 735 | /// @param source the Source of the node |
| 736 | /// @param type matrix subtype |
| 737 | /// @param columns number of columns for the matrix |
| 738 | /// @param rows number of rows for the matrix |
| 739 | /// @return the tint AST type for a matrix of `type` |
| 740 | const ast::Matrix* mat(const Source& source, |
| 741 | const ast::Type* type, |
| 742 | uint32_t columns, |
| 743 | uint32_t rows) const { |
| 744 | return builder->create<ast::Matrix>(source, type, rows, columns); |
| 745 | } |
| 746 | |
| 747 | /// @param type matrix subtype |
| 748 | /// @return the tint AST type for a 2x3 matrix of `type`. |
| 749 | const ast::Matrix* mat2x2(const ast::Type* type) const { return mat(type, 2u, 2u); } |
| 750 | |
| 751 | /// @param type matrix subtype |
| 752 | /// @return the tint AST type for a 2x3 matrix of `type`. |
| 753 | const ast::Matrix* mat2x3(const ast::Type* type) const { return mat(type, 2u, 3u); } |
| 754 | |
| 755 | /// @param type matrix subtype |
| 756 | /// @return the tint AST type for a 2x4 matrix of `type`. |
| 757 | const ast::Matrix* mat2x4(const ast::Type* type) const { return mat(type, 2u, 4u); } |
| 758 | |
| 759 | /// @param type matrix subtype |
| 760 | /// @return the tint AST type for a 3x2 matrix of `type`. |
| 761 | const ast::Matrix* mat3x2(const ast::Type* type) const { return mat(type, 3u, 2u); } |
| 762 | |
| 763 | /// @param type matrix subtype |
| 764 | /// @return the tint AST type for a 3x3 matrix of `type`. |
| 765 | const ast::Matrix* mat3x3(const ast::Type* type) const { return mat(type, 3u, 3u); } |
| 766 | |
| 767 | /// @param type matrix subtype |
| 768 | /// @return the tint AST type for a 3x4 matrix of `type`. |
| 769 | const ast::Matrix* mat3x4(const ast::Type* type) const { return mat(type, 3u, 4u); } |
| 770 | |
| 771 | /// @param type matrix subtype |
| 772 | /// @return the tint AST type for a 4x2 matrix of `type`. |
| 773 | const ast::Matrix* mat4x2(const ast::Type* type) const { return mat(type, 4u, 2u); } |
| 774 | |
| 775 | /// @param type matrix subtype |
| 776 | /// @return the tint AST type for a 4x3 matrix of `type`. |
| 777 | const ast::Matrix* mat4x3(const ast::Type* type) const { return mat(type, 4u, 3u); } |
| 778 | |
| 779 | /// @param type matrix subtype |
| 780 | /// @return the tint AST type for a 4x4 matrix of `type`. |
| 781 | const ast::Matrix* mat4x4(const ast::Type* type) const { return mat(type, 4u, 4u); } |
| 782 | |
| 783 | /// @param columns number of columns for the matrix |
| 784 | /// @param rows number of rows for the matrix |
| 785 | /// @return the tint AST type for a matrix of `type` |
| 786 | template <typename T> |
| 787 | const ast::Matrix* mat(uint32_t columns, uint32_t rows) const { |
| 788 | return mat(Of<T>(), columns, rows); |
| 789 | } |
| 790 | |
| 791 | /// @return the tint AST type for a 2x3 matrix of the C type `T`. |
| 792 | template <typename T> |
| 793 | const ast::Matrix* mat2x2() const { |
| 794 | return mat2x2(Of<T>()); |
| 795 | } |
| 796 | |
| 797 | /// @return the tint AST type for a 2x3 matrix of the C type `T`. |
| 798 | template <typename T> |
| 799 | const ast::Matrix* mat2x3() const { |
| 800 | return mat2x3(Of<T>()); |
| 801 | } |
| 802 | |
| 803 | /// @return the tint AST type for a 2x4 matrix of the C type `T`. |
| 804 | template <typename T> |
| 805 | const ast::Matrix* mat2x4() const { |
| 806 | return mat2x4(Of<T>()); |
| 807 | } |
| 808 | |
| 809 | /// @return the tint AST type for a 3x2 matrix of the C type `T`. |
| 810 | template <typename T> |
| 811 | const ast::Matrix* mat3x2() const { |
| 812 | return mat3x2(Of<T>()); |
| 813 | } |
| 814 | |
| 815 | /// @return the tint AST type for a 3x3 matrix of the C type `T`. |
| 816 | template <typename T> |
| 817 | const ast::Matrix* mat3x3() const { |
| 818 | return mat3x3(Of<T>()); |
| 819 | } |
| 820 | |
| 821 | /// @return the tint AST type for a 3x4 matrix of the C type `T`. |
| 822 | template <typename T> |
| 823 | const ast::Matrix* mat3x4() const { |
| 824 | return mat3x4(Of<T>()); |
| 825 | } |
| 826 | |
| 827 | /// @return the tint AST type for a 4x2 matrix of the C type `T`. |
| 828 | template <typename T> |
| 829 | const ast::Matrix* mat4x2() const { |
| 830 | return mat4x2(Of<T>()); |
| 831 | } |
| 832 | |
| 833 | /// @return the tint AST type for a 4x3 matrix of the C type `T`. |
| 834 | template <typename T> |
| 835 | const ast::Matrix* mat4x3() const { |
| 836 | return mat4x3(Of<T>()); |
| 837 | } |
| 838 | |
| 839 | /// @return the tint AST type for a 4x4 matrix of the C type `T`. |
| 840 | template <typename T> |
| 841 | const ast::Matrix* mat4x4() const { |
| 842 | return mat4x4(Of<T>()); |
| 843 | } |
| 844 | |
| 845 | /// @param subtype the array element type |
| 846 | /// @param n the array size. nullptr represents a runtime-array |
| 847 | /// @param attrs the optional attributes for the array |
| 848 | /// @return the tint AST type for a array of size `n` of type `T` |
| 849 | template <typename EXPR = ast::Expression*> |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 850 | const ast::Array* array( |
| 851 | const ast::Type* subtype, |
| 852 | EXPR&& n = nullptr, |
| 853 | utils::VectorRef<const ast::Attribute*> attrs = utils::Empty) const { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 854 | return builder->create<ast::Array>(subtype, builder->Expr(std::forward<EXPR>(n)), |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 855 | std::move(attrs)); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /// @param source the Source of the node |
| 859 | /// @param subtype the array element type |
| 860 | /// @param n the array size. nullptr represents a runtime-array |
| 861 | /// @param attrs the optional attributes for the array |
| 862 | /// @return the tint AST type for a array of size `n` of type `T` |
| 863 | template <typename EXPR = ast::Expression*> |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 864 | const ast::Array* array( |
| 865 | const Source& source, |
| 866 | const ast::Type* subtype, |
| 867 | EXPR&& n = nullptr, |
| 868 | utils::VectorRef<const ast::Attribute*> attrs = utils::Empty) const { |
| 869 | return builder->create<ast::Array>( |
| 870 | source, subtype, builder->Expr(std::forward<EXPR>(n)), std::move(attrs)); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /// @param subtype the array element type |
| 874 | /// @param n the array size. nullptr represents a runtime-array |
| 875 | /// @param stride the array stride. 0 represents implicit stride |
| 876 | /// @return the tint AST type for a array of size `n` of type `T` |
| 877 | template <typename EXPR> |
| 878 | const ast::Array* array(const ast::Type* subtype, EXPR&& n, uint32_t stride) const { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 879 | utils::Vector<const ast::Attribute*, 2> attrs; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 880 | if (stride) { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 881 | attrs.Push(builder->create<ast::StrideAttribute>(stride)); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 882 | } |
| 883 | return array(subtype, std::forward<EXPR>(n), std::move(attrs)); |
| 884 | } |
| 885 | |
| 886 | /// @param source the Source of the node |
| 887 | /// @param subtype the array element type |
| 888 | /// @param n the array size. nullptr represents a runtime-array |
| 889 | /// @param stride the array stride. 0 represents implicit stride |
| 890 | /// @return the tint AST type for a array of size `n` of type `T` |
| 891 | template <typename EXPR> |
| 892 | const ast::Array* array(const Source& source, |
| 893 | const ast::Type* subtype, |
| 894 | EXPR&& n, |
| 895 | uint32_t stride) const { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 896 | utils::Vector<const ast::Attribute*, 2> attrs; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 897 | if (stride) { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 898 | attrs.Push(builder->create<ast::StrideAttribute>(stride)); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 899 | } |
| 900 | return array(source, subtype, std::forward<EXPR>(n), std::move(attrs)); |
| 901 | } |
| 902 | |
| 903 | /// @return the tint AST type for a runtime-sized array of type `T` |
| 904 | template <typename T> |
| 905 | const ast::Array* array() const { |
| 906 | return array(Of<T>(), nullptr); |
| 907 | } |
| 908 | |
| 909 | /// @return the tint AST type for an array of size `N` of type `T` |
| 910 | template <typename T, int N> |
| 911 | const ast::Array* array() const { |
Ben Clayton | 0ce9ab0 | 2022-05-05 20:23:40 +0000 | [diff] [blame] | 912 | return array(Of<T>(), builder->Expr(tint::u32(N))); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /// @param stride the array stride |
| 916 | /// @return the tint AST type for a runtime-sized array of type `T` |
| 917 | template <typename T> |
| 918 | const ast::Array* array(uint32_t stride) const { |
| 919 | return array(Of<T>(), nullptr, stride); |
| 920 | } |
| 921 | |
| 922 | /// @param stride the array stride |
| 923 | /// @return the tint AST type for an array of size `N` of type `T` |
| 924 | template <typename T, int N> |
| 925 | const ast::Array* array(uint32_t stride) const { |
Ben Clayton | 0ce9ab0 | 2022-05-05 20:23:40 +0000 | [diff] [blame] | 926 | return array(Of<T>(), builder->Expr(tint::u32(N)), stride); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | /// Creates a type name |
| 930 | /// @param name the name |
| 931 | /// @returns the type name |
| 932 | template <typename NAME> |
| 933 | const ast::TypeName* type_name(NAME&& name) const { |
| 934 | return builder->create<ast::TypeName>(builder->Sym(std::forward<NAME>(name))); |
| 935 | } |
| 936 | |
| 937 | /// Creates a type name |
| 938 | /// @param source the Source of the node |
| 939 | /// @param name the name |
| 940 | /// @returns the type name |
| 941 | template <typename NAME> |
| 942 | const ast::TypeName* type_name(const Source& source, NAME&& name) const { |
| 943 | return builder->create<ast::TypeName>(source, builder->Sym(std::forward<NAME>(name))); |
| 944 | } |
| 945 | |
| 946 | /// Creates an alias type |
| 947 | /// @param name the alias name |
| 948 | /// @param type the alias type |
| 949 | /// @returns the alias pointer |
| 950 | template <typename NAME> |
| 951 | const ast::Alias* alias(NAME&& name, const ast::Type* type) const { |
| 952 | auto sym = builder->Sym(std::forward<NAME>(name)); |
| 953 | return builder->create<ast::Alias>(sym, type); |
| 954 | } |
| 955 | |
| 956 | /// Creates an alias type |
| 957 | /// @param source the Source of the node |
| 958 | /// @param name the alias name |
| 959 | /// @param type the alias type |
| 960 | /// @returns the alias pointer |
| 961 | template <typename NAME> |
| 962 | const ast::Alias* alias(const Source& source, NAME&& name, const ast::Type* type) const { |
| 963 | auto sym = builder->Sym(std::forward<NAME>(name)); |
| 964 | return builder->create<ast::Alias>(source, sym, type); |
| 965 | } |
| 966 | |
| 967 | /// @param type the type of the pointer |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 968 | /// @param address_space the address space of the pointer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 969 | /// @param access the optional access control of the pointer |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 970 | /// @return the pointer to `type` with the given ast::AddressSpace |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 971 | const ast::Pointer* pointer(const ast::Type* type, |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 972 | ast::AddressSpace address_space, |
Ben Clayton | d2e0db3 | 2022-10-12 18:49:15 +0000 | [diff] [blame] | 973 | ast::Access access = ast::Access::kUndefined) const { |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 974 | return builder->create<ast::Pointer>(type, address_space, access); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | /// @param source the Source of the node |
| 978 | /// @param type the type of the pointer |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 979 | /// @param address_space the address space of the pointer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 980 | /// @param access the optional access control of the pointer |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 981 | /// @return the pointer to `type` with the given ast::AddressSpace |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 982 | const ast::Pointer* pointer(const Source& source, |
| 983 | const ast::Type* type, |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 984 | ast::AddressSpace address_space, |
Ben Clayton | d2e0db3 | 2022-10-12 18:49:15 +0000 | [diff] [blame] | 985 | ast::Access access = ast::Access::kUndefined) const { |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 986 | return builder->create<ast::Pointer>(source, type, address_space, access); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 987 | } |
| 988 | |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 989 | /// @param address_space the address space of the pointer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 990 | /// @param access the optional access control of the pointer |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 991 | /// @return the pointer to type `T` with the given ast::AddressSpace. |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 992 | template <typename T> |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 993 | const ast::Pointer* pointer(ast::AddressSpace address_space, |
Ben Clayton | d2e0db3 | 2022-10-12 18:49:15 +0000 | [diff] [blame] | 994 | ast::Access access = ast::Access::kUndefined) const { |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 995 | return pointer(Of<T>(), address_space, access); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | /// @param source the Source of the node |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 999 | /// @param address_space the address space of the pointer |
Ben Clayton | cfe07a1 | 2022-07-15 13:01:49 +0000 | [diff] [blame] | 1000 | /// @param access the optional access control of the pointer |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 1001 | /// @return the pointer to type `T` with the given ast::AddressSpace. |
Ben Clayton | cfe07a1 | 2022-07-15 13:01:49 +0000 | [diff] [blame] | 1002 | template <typename T> |
| 1003 | const ast::Pointer* pointer(const Source& source, |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 1004 | ast::AddressSpace address_space, |
Ben Clayton | d2e0db3 | 2022-10-12 18:49:15 +0000 | [diff] [blame] | 1005 | ast::Access access = ast::Access::kUndefined) const { |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 1006 | return pointer(source, Of<T>(), address_space, access); |
Ben Clayton | cfe07a1 | 2022-07-15 13:01:49 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | /// @param source the Source of the node |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1010 | /// @param type the type of the atomic |
| 1011 | /// @return the atomic to `type` |
| 1012 | const ast::Atomic* atomic(const Source& source, const ast::Type* type) const { |
| 1013 | return builder->create<ast::Atomic>(source, type); |
| 1014 | } |
| 1015 | |
| 1016 | /// @param type the type of the atomic |
| 1017 | /// @return the atomic to `type` |
| 1018 | const ast::Atomic* atomic(const ast::Type* type) const { |
| 1019 | return builder->create<ast::Atomic>(type); |
| 1020 | } |
| 1021 | |
| 1022 | /// @return the atomic to type `T` |
| 1023 | template <typename T> |
| 1024 | const ast::Atomic* atomic() const { |
| 1025 | return atomic(Of<T>()); |
| 1026 | } |
| 1027 | |
| 1028 | /// @param kind the kind of sampler |
| 1029 | /// @returns the sampler |
| 1030 | const ast::Sampler* sampler(ast::SamplerKind kind) const { |
| 1031 | return builder->create<ast::Sampler>(kind); |
| 1032 | } |
| 1033 | |
| 1034 | /// @param source the Source of the node |
| 1035 | /// @param kind the kind of sampler |
| 1036 | /// @returns the sampler |
| 1037 | const ast::Sampler* sampler(const Source& source, ast::SamplerKind kind) const { |
| 1038 | return builder->create<ast::Sampler>(source, kind); |
| 1039 | } |
| 1040 | |
| 1041 | /// @param dims the dimensionality of the texture |
| 1042 | /// @returns the depth texture |
| 1043 | const ast::DepthTexture* depth_texture(ast::TextureDimension dims) const { |
| 1044 | return builder->create<ast::DepthTexture>(dims); |
| 1045 | } |
| 1046 | |
| 1047 | /// @param source the Source of the node |
| 1048 | /// @param dims the dimensionality of the texture |
| 1049 | /// @returns the depth texture |
| 1050 | const ast::DepthTexture* depth_texture(const Source& source, |
| 1051 | ast::TextureDimension dims) const { |
| 1052 | return builder->create<ast::DepthTexture>(source, dims); |
| 1053 | } |
| 1054 | |
| 1055 | /// @param dims the dimensionality of the texture |
| 1056 | /// @returns the multisampled depth texture |
| 1057 | const ast::DepthMultisampledTexture* depth_multisampled_texture( |
| 1058 | ast::TextureDimension dims) const { |
| 1059 | return builder->create<ast::DepthMultisampledTexture>(dims); |
| 1060 | } |
| 1061 | |
| 1062 | /// @param source the Source of the node |
| 1063 | /// @param dims the dimensionality of the texture |
| 1064 | /// @returns the multisampled depth texture |
| 1065 | const ast::DepthMultisampledTexture* depth_multisampled_texture( |
| 1066 | const Source& source, |
| 1067 | ast::TextureDimension dims) const { |
| 1068 | return builder->create<ast::DepthMultisampledTexture>(source, dims); |
| 1069 | } |
| 1070 | |
| 1071 | /// @param dims the dimensionality of the texture |
| 1072 | /// @param subtype the texture subtype. |
| 1073 | /// @returns the sampled texture |
| 1074 | const ast::SampledTexture* sampled_texture(ast::TextureDimension dims, |
| 1075 | const ast::Type* subtype) const { |
| 1076 | return builder->create<ast::SampledTexture>(dims, subtype); |
| 1077 | } |
| 1078 | |
| 1079 | /// @param source the Source of the node |
| 1080 | /// @param dims the dimensionality of the texture |
| 1081 | /// @param subtype the texture subtype. |
| 1082 | /// @returns the sampled texture |
| 1083 | const ast::SampledTexture* sampled_texture(const Source& source, |
| 1084 | ast::TextureDimension dims, |
| 1085 | const ast::Type* subtype) const { |
| 1086 | return builder->create<ast::SampledTexture>(source, dims, subtype); |
| 1087 | } |
| 1088 | |
| 1089 | /// @param dims the dimensionality of the texture |
| 1090 | /// @param subtype the texture subtype. |
| 1091 | /// @returns the multisampled texture |
| 1092 | const ast::MultisampledTexture* multisampled_texture(ast::TextureDimension dims, |
| 1093 | const ast::Type* subtype) const { |
| 1094 | return builder->create<ast::MultisampledTexture>(dims, subtype); |
| 1095 | } |
| 1096 | |
| 1097 | /// @param source the Source of the node |
| 1098 | /// @param dims the dimensionality of the texture |
| 1099 | /// @param subtype the texture subtype. |
| 1100 | /// @returns the multisampled texture |
| 1101 | const ast::MultisampledTexture* multisampled_texture(const Source& source, |
| 1102 | ast::TextureDimension dims, |
| 1103 | const ast::Type* subtype) const { |
| 1104 | return builder->create<ast::MultisampledTexture>(source, dims, subtype); |
| 1105 | } |
| 1106 | |
| 1107 | /// @param dims the dimensionality of the texture |
| 1108 | /// @param format the texel format of the texture |
| 1109 | /// @param access the access control of the texture |
| 1110 | /// @returns the storage texture |
| 1111 | const ast::StorageTexture* storage_texture(ast::TextureDimension dims, |
| 1112 | ast::TexelFormat format, |
| 1113 | ast::Access access) const { |
| 1114 | auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder); |
| 1115 | return builder->create<ast::StorageTexture>(dims, format, subtype, access); |
| 1116 | } |
| 1117 | |
| 1118 | /// @param source the Source of the node |
| 1119 | /// @param dims the dimensionality of the texture |
| 1120 | /// @param format the texel format of the texture |
| 1121 | /// @param access the access control of the texture |
| 1122 | /// @returns the storage texture |
| 1123 | const ast::StorageTexture* storage_texture(const Source& source, |
| 1124 | ast::TextureDimension dims, |
| 1125 | ast::TexelFormat format, |
| 1126 | ast::Access access) const { |
| 1127 | auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder); |
| 1128 | return builder->create<ast::StorageTexture>(source, dims, format, subtype, access); |
| 1129 | } |
| 1130 | |
| 1131 | /// @returns the external texture |
| 1132 | const ast::ExternalTexture* external_texture() const { |
| 1133 | return builder->create<ast::ExternalTexture>(); |
| 1134 | } |
| 1135 | |
| 1136 | /// @param source the Source of the node |
| 1137 | /// @returns the external texture |
| 1138 | const ast::ExternalTexture* external_texture(const Source& source) const { |
| 1139 | return builder->create<ast::ExternalTexture>(source); |
| 1140 | } |
| 1141 | |
| 1142 | /// Constructs a TypeName for the type declaration. |
| 1143 | /// @param type the type |
| 1144 | /// @return either type or a pointer to a new ast::TypeName |
| 1145 | const ast::TypeName* Of(const ast::TypeDecl* type) const; |
| 1146 | |
| 1147 | /// The ProgramBuilder |
| 1148 | ProgramBuilder* const builder; |
| 1149 | |
| 1150 | private: |
| 1151 | /// CToAST<T> is specialized for various `T` types and each specialization |
| 1152 | /// contains a single static `get()` method for obtaining the corresponding |
| 1153 | /// AST type for the C type `T`. |
| 1154 | /// `get()` has the signature: |
| 1155 | /// `static const ast::Type* get(Types* t)` |
| 1156 | template <typename T> |
| 1157 | struct CToAST {}; |
| 1158 | }; |
| 1159 | |
| 1160 | ////////////////////////////////////////////////////////////////////////////// |
| 1161 | // AST helper methods |
| 1162 | ////////////////////////////////////////////////////////////////////////////// |
| 1163 | |
| 1164 | /// @return a new unnamed symbol |
| 1165 | Symbol Sym() { return Symbols().New(); } |
| 1166 | |
| 1167 | /// @param name the symbol string |
| 1168 | /// @return a Symbol with the given name |
| 1169 | Symbol Sym(const std::string& name) { return Symbols().Register(name); } |
| 1170 | |
| 1171 | /// @param sym the symbol |
| 1172 | /// @return `sym` |
| 1173 | Symbol Sym(Symbol sym) { return sym; } |
| 1174 | |
| 1175 | /// @param expr the expression |
| 1176 | /// @return expr |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1177 | template <typename T> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1178 | traits::EnableIfIsType<T, ast::Expression>* Expr(T* expr) { |
| 1179 | return expr; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1182 | /// Passthrough for nullptr |
| 1183 | /// @return nullptr |
| 1184 | const ast::IdentifierExpression* Expr(std::nullptr_t) { return nullptr; } |
| 1185 | |
| 1186 | /// @param source the source information |
| 1187 | /// @param symbol the identifier symbol |
| 1188 | /// @return an ast::IdentifierExpression with the given symbol |
| 1189 | const ast::IdentifierExpression* Expr(const Source& source, Symbol symbol) { |
| 1190 | return create<ast::IdentifierExpression>(source, symbol); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1193 | /// @param symbol the identifier symbol |
| 1194 | /// @return an ast::IdentifierExpression with the given symbol |
| 1195 | const ast::IdentifierExpression* Expr(Symbol symbol) { |
| 1196 | return create<ast::IdentifierExpression>(symbol); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1199 | /// @param source the source information |
| 1200 | /// @param variable the AST variable |
| 1201 | /// @return an ast::IdentifierExpression with the variable's symbol |
| 1202 | const ast::IdentifierExpression* Expr(const Source& source, const ast::Variable* variable) { |
| 1203 | return create<ast::IdentifierExpression>(source, variable->symbol); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1206 | /// @param variable the AST variable |
| 1207 | /// @return an ast::IdentifierExpression with the variable's symbol |
| 1208 | const ast::IdentifierExpression* Expr(const ast::Variable* variable) { |
| 1209 | return create<ast::IdentifierExpression>(variable->symbol); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1212 | /// @param source the source information |
| 1213 | /// @param name the identifier name |
| 1214 | /// @return an ast::IdentifierExpression with the given name |
| 1215 | const ast::IdentifierExpression* Expr(const Source& source, const char* name) { |
| 1216 | return create<ast::IdentifierExpression>(source, Symbols().Register(name)); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1219 | /// @param name the identifier name |
| 1220 | /// @return an ast::IdentifierExpression with the given name |
| 1221 | const ast::IdentifierExpression* Expr(const char* name) { |
| 1222 | return create<ast::IdentifierExpression>(Symbols().Register(name)); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1223 | } |
| 1224 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1225 | /// @param source the source information |
| 1226 | /// @param name the identifier name |
| 1227 | /// @return an ast::IdentifierExpression with the given name |
| 1228 | const ast::IdentifierExpression* Expr(const Source& source, const std::string& name) { |
| 1229 | return create<ast::IdentifierExpression>(source, Symbols().Register(name)); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1232 | /// @param name the identifier name |
| 1233 | /// @return an ast::IdentifierExpression with the given name |
| 1234 | const ast::IdentifierExpression* Expr(const std::string& name) { |
| 1235 | return create<ast::IdentifierExpression>(Symbols().Register(name)); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1238 | /// @param source the source information |
| 1239 | /// @param value the boolean value |
| 1240 | /// @return a Scalar constructor for the given value |
Ben Clayton | 17fa42d | 2022-05-10 15:29:14 +0000 | [diff] [blame] | 1241 | template <typename BOOL> |
| 1242 | std::enable_if_t<std::is_same_v<BOOL, bool>, const ast::BoolLiteralExpression*> Expr( |
| 1243 | const Source& source, |
| 1244 | BOOL value) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1245 | return create<ast::BoolLiteralExpression>(source, value); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1248 | /// @param value the boolean value |
| 1249 | /// @return a Scalar constructor for the given value |
Ben Clayton | 17fa42d | 2022-05-10 15:29:14 +0000 | [diff] [blame] | 1250 | template <typename BOOL> |
| 1251 | std::enable_if_t<std::is_same_v<BOOL, bool>, const ast::BoolLiteralExpression*> Expr( |
| 1252 | BOOL value) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1253 | return create<ast::BoolLiteralExpression>(value); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1256 | /// @param source the source information |
| 1257 | /// @param value the float value |
Ben Clayton | 41285aa | 2022-05-10 14:55:34 +0000 | [diff] [blame] | 1258 | /// @return a 'f'-suffixed FloatLiteralExpression for the f32 value |
| 1259 | const ast::FloatLiteralExpression* Expr(const Source& source, f32 value) { |
| 1260 | return create<ast::FloatLiteralExpression>(source, static_cast<double>(value.value), |
| 1261 | ast::FloatLiteralExpression::Suffix::kF); |
| 1262 | } |
| 1263 | |
| 1264 | /// @param value the float value |
| 1265 | /// @return a 'f'-suffixed FloatLiteralExpression for the f32 value |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1266 | const ast::FloatLiteralExpression* Expr(f32 value) { |
Ben Clayton | 41285aa | 2022-05-10 14:55:34 +0000 | [diff] [blame] | 1267 | return create<ast::FloatLiteralExpression>(static_cast<double>(value.value), |
| 1268 | ast::FloatLiteralExpression::Suffix::kF); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1271 | /// @param source the source information |
Zhaoming Jiang | 62bfd31 | 2022-05-13 12:01:11 +0000 | [diff] [blame] | 1272 | /// @param value the float value |
| 1273 | /// @return a 'h'-suffixed FloatLiteralExpression for the f16 value |
| 1274 | const ast::FloatLiteralExpression* Expr(const Source& source, f16 value) { |
| 1275 | return create<ast::FloatLiteralExpression>(source, static_cast<double>(value.value), |
| 1276 | ast::FloatLiteralExpression::Suffix::kH); |
| 1277 | } |
| 1278 | |
| 1279 | /// @param value the float value |
| 1280 | /// @return a 'h'-suffixed FloatLiteralExpression for the f16 value |
| 1281 | const ast::FloatLiteralExpression* Expr(f16 value) { |
| 1282 | return create<ast::FloatLiteralExpression>(static_cast<double>(value.value), |
| 1283 | ast::FloatLiteralExpression::Suffix::kH); |
| 1284 | } |
| 1285 | |
| 1286 | /// @param source the source information |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1287 | /// @param value the integer value |
Ben Clayton | 508e4a5 | 2022-05-10 22:08:04 +0000 | [diff] [blame] | 1288 | /// @return an unsuffixed IntLiteralExpression for the AInt value |
| 1289 | const ast::IntLiteralExpression* Expr(const Source& source, AInt value) { |
| 1290 | return create<ast::IntLiteralExpression>(source, value, |
| 1291 | ast::IntLiteralExpression::Suffix::kNone); |
| 1292 | } |
| 1293 | |
| 1294 | /// @param value the integer value |
| 1295 | /// @return an unsuffixed IntLiteralExpression for the AInt value |
| 1296 | const ast::IntLiteralExpression* Expr(AInt value) { |
| 1297 | return create<ast::IntLiteralExpression>(value, ast::IntLiteralExpression::Suffix::kNone); |
| 1298 | } |
| 1299 | |
| 1300 | /// @param source the source information |
| 1301 | /// @param value the integer value |
| 1302 | /// @return an unsuffixed FloatLiteralExpression for the AFloat value |
| 1303 | const ast::FloatLiteralExpression* Expr(const Source& source, AFloat value) { |
| 1304 | return create<ast::FloatLiteralExpression>(source, value.value, |
| 1305 | ast::FloatLiteralExpression::Suffix::kNone); |
| 1306 | } |
| 1307 | |
| 1308 | /// @param value the integer value |
| 1309 | /// @return an unsuffixed FloatLiteralExpression for the AFloat value |
| 1310 | const ast::FloatLiteralExpression* Expr(AFloat value) { |
| 1311 | return create<ast::FloatLiteralExpression>(value.value, |
| 1312 | ast::FloatLiteralExpression::Suffix::kNone); |
| 1313 | } |
| 1314 | |
| 1315 | /// @param source the source information |
| 1316 | /// @param value the integer value |
Ben Clayton | 41285aa | 2022-05-10 14:55:34 +0000 | [diff] [blame] | 1317 | /// @return a signed 'i'-suffixed IntLiteralExpression for the i32 value |
Ben Clayton | 8822e29 | 2022-05-04 22:18:49 +0000 | [diff] [blame] | 1318 | const ast::IntLiteralExpression* Expr(const Source& source, i32 value) { |
| 1319 | return create<ast::IntLiteralExpression>(source, value, |
Ben Clayton | 0ce9ab0 | 2022-05-05 20:23:40 +0000 | [diff] [blame] | 1320 | ast::IntLiteralExpression::Suffix::kI); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1323 | /// @param value the integer value |
Ben Clayton | 41285aa | 2022-05-10 14:55:34 +0000 | [diff] [blame] | 1324 | /// @return a signed 'i'-suffixed IntLiteralExpression for the i32 value |
Ben Clayton | 8822e29 | 2022-05-04 22:18:49 +0000 | [diff] [blame] | 1325 | const ast::IntLiteralExpression* Expr(i32 value) { |
Ben Clayton | 0ce9ab0 | 2022-05-05 20:23:40 +0000 | [diff] [blame] | 1326 | return create<ast::IntLiteralExpression>(value, ast::IntLiteralExpression::Suffix::kI); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1329 | /// @param source the source information |
| 1330 | /// @param value the unsigned int value |
Ben Clayton | 41285aa | 2022-05-10 14:55:34 +0000 | [diff] [blame] | 1331 | /// @return an unsigned 'u'-suffixed IntLiteralExpression for the u32 value |
Ben Clayton | 8822e29 | 2022-05-04 22:18:49 +0000 | [diff] [blame] | 1332 | const ast::IntLiteralExpression* Expr(const Source& source, u32 value) { |
| 1333 | return create<ast::IntLiteralExpression>(source, value, |
| 1334 | ast::IntLiteralExpression::Suffix::kU); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1337 | /// @param value the unsigned int value |
Ben Clayton | 41285aa | 2022-05-10 14:55:34 +0000 | [diff] [blame] | 1338 | /// @return an unsigned 'u'-suffixed IntLiteralExpression for the u32 value |
Ben Clayton | 8822e29 | 2022-05-04 22:18:49 +0000 | [diff] [blame] | 1339 | const ast::IntLiteralExpression* Expr(u32 value) { |
| 1340 | return create<ast::IntLiteralExpression>(value, ast::IntLiteralExpression::Suffix::kU); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1343 | /// Converts `arg` to an `ast::Expression` using `Expr()`, then appends it to |
| 1344 | /// `list`. |
| 1345 | /// @param list the list to append too |
| 1346 | /// @param arg the arg to create |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1347 | template <size_t N, typename ARG> |
| 1348 | void Append(utils::Vector<const ast::Expression*, N>& list, ARG&& arg) { |
| 1349 | list.Push(Expr(std::forward<ARG>(arg))); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1352 | /// Converts `arg0` and `args` to `ast::Expression`s using `Expr()`, |
| 1353 | /// then appends them to `list`. |
| 1354 | /// @param list the list to append too |
| 1355 | /// @param arg0 the first argument |
| 1356 | /// @param args the rest of the arguments |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1357 | template <size_t N, typename ARG0, typename... ARGS> |
| 1358 | void Append(utils::Vector<const ast::Expression*, N>& list, ARG0&& arg0, ARGS&&... args) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1359 | Append(list, std::forward<ARG0>(arg0)); |
| 1360 | Append(list, std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1363 | /// @return utils::EmptyType |
| 1364 | utils::EmptyType ExprList() { return utils::Empty; } |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1365 | |
| 1366 | /// @param args the list of expressions |
| 1367 | /// @return the list of expressions converted to `ast::Expression`s using |
| 1368 | /// `Expr()`, |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1369 | template <typename... ARGS, typename = DisableIfVectorLike<ARGS...>> |
| 1370 | auto ExprList(ARGS&&... args) { |
| 1371 | utils::Vector<const ast::Expression*, sizeof...(ARGS)> list; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1372 | Append(list, std::forward<ARGS>(args)...); |
| 1373 | return list; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1376 | /// @param list the list of expressions |
| 1377 | /// @return `list` |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1378 | template <typename T, size_t N> |
| 1379 | utils::Vector<T, N> ExprList(utils::Vector<T, N>&& list) { |
| 1380 | return std::move(list); |
| 1381 | } |
| 1382 | |
| 1383 | /// @param list the list of expressions |
| 1384 | /// @return `list` |
| 1385 | utils::VectorRef<const ast::Expression*> ExprList( |
| 1386 | utils::VectorRef<const ast::Expression*> list) { |
| 1387 | return list; |
| 1388 | } |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1389 | |
| 1390 | /// @param args the arguments for the type constructor |
| 1391 | /// @return an `ast::CallExpression` of type `ty`, with the values |
| 1392 | /// of `args` converted to `ast::Expression`s using `Expr()` |
| 1393 | template <typename T, typename... ARGS> |
| 1394 | const ast::CallExpression* Construct(ARGS&&... args) { |
| 1395 | return Construct(ty.Of<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1398 | /// @param type the type to construct |
| 1399 | /// @param args the arguments for the constructor |
| 1400 | /// @return an `ast::CallExpression` of `type` constructed with the |
| 1401 | /// values `args`. |
| 1402 | template <typename... ARGS> |
| 1403 | const ast::CallExpression* Construct(const ast::Type* type, ARGS&&... args) { |
| 1404 | return Construct(source_, type, std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1407 | /// @param source the source information |
| 1408 | /// @param type the type to construct |
| 1409 | /// @param args the arguments for the constructor |
| 1410 | /// @return an `ast::CallExpression` of `type` constructed with the |
| 1411 | /// values `args`. |
| 1412 | template <typename... ARGS> |
| 1413 | const ast::CallExpression* Construct(const Source& source, |
| 1414 | const ast::Type* type, |
| 1415 | ARGS&&... args) { |
| 1416 | return create<ast::CallExpression>(source, type, ExprList(std::forward<ARGS>(args)...)); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1419 | /// @param expr the expression for the bitcast |
| 1420 | /// @return an `ast::BitcastExpression` of type `ty`, with the values of |
| 1421 | /// `expr` converted to `ast::Expression`s using `Expr()` |
| 1422 | template <typename T, typename EXPR> |
| 1423 | const ast::BitcastExpression* Bitcast(EXPR&& expr) { |
| 1424 | return Bitcast(ty.Of<T>(), std::forward<EXPR>(expr)); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1427 | /// @param type the type to cast to |
| 1428 | /// @param expr the expression for the bitcast |
| 1429 | /// @return an `ast::BitcastExpression` of `type` constructed with the values |
| 1430 | /// `expr`. |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1431 | template <typename EXPR> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1432 | const ast::BitcastExpression* Bitcast(const ast::Type* type, EXPR&& expr) { |
| 1433 | return create<ast::BitcastExpression>(type, Expr(std::forward<EXPR>(expr))); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1436 | /// @param source the source information |
| 1437 | /// @param type the type to cast to |
| 1438 | /// @param expr the expression for the bitcast |
| 1439 | /// @return an `ast::BitcastExpression` of `type` constructed with the values |
| 1440 | /// `expr`. |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1441 | template <typename EXPR> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1442 | const ast::BitcastExpression* Bitcast(const Source& source, |
| 1443 | const ast::Type* type, |
| 1444 | EXPR&& expr) { |
| 1445 | return create<ast::BitcastExpression>(source, type, Expr(std::forward<EXPR>(expr))); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1448 | /// @param args the arguments for the vector initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1449 | /// @param type the vector type |
| 1450 | /// @param size the vector size |
| 1451 | /// @return an `ast::CallExpression` of a `size`-element vector of |
| 1452 | /// type `type`, constructed with the values `args`. |
| 1453 | template <typename... ARGS> |
| 1454 | const ast::CallExpression* vec(const ast::Type* type, uint32_t size, ARGS&&... args) { |
| 1455 | return Construct(ty.vec(type, size), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1458 | /// @param args the arguments for the vector initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1459 | /// @return an `ast::CallExpression` of a 2-element vector of type |
| 1460 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1461 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1462 | const ast::CallExpression* vec2(ARGS&&... args) { |
| 1463 | return Construct(ty.vec2<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1466 | /// @param source the vector source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1467 | /// @param args the arguments for the vector initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1468 | /// @return an `ast::CallExpression` of a 2-element vector of type |
| 1469 | /// `T`, constructed with the values `args`. |
| 1470 | template <typename T, typename... ARGS> |
| 1471 | const ast::CallExpression* vec2(const Source& source, ARGS&&... args) { |
| 1472 | return Construct(source, ty.vec2<T>(), std::forward<ARGS>(args)...); |
| 1473 | } |
| 1474 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1475 | /// @param args the arguments for the vector initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1476 | /// @return an `ast::CallExpression` of a 3-element vector of type |
| 1477 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1478 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1479 | const ast::CallExpression* vec3(ARGS&&... args) { |
| 1480 | return Construct(ty.vec3<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1483 | /// @param source the vector source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1484 | /// @param args the arguments for the vector initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1485 | /// @return an `ast::CallExpression` of a 3-element vector of type |
| 1486 | /// `T`, constructed with the values `args`. |
| 1487 | template <typename T, typename... ARGS> |
| 1488 | const ast::CallExpression* vec3(const Source& source, ARGS&&... args) { |
| 1489 | return Construct(source, ty.vec3<T>(), std::forward<ARGS>(args)...); |
| 1490 | } |
| 1491 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1492 | /// @param args the arguments for the vector initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1493 | /// @return an `ast::CallExpression` of a 4-element vector of type |
| 1494 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1495 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1496 | const ast::CallExpression* vec4(ARGS&&... args) { |
| 1497 | return Construct(ty.vec4<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1500 | /// @param source the vector source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1501 | /// @param args the arguments for the vector initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1502 | /// @return an `ast::CallExpression` of a 4-element vector of type |
| 1503 | /// `T`, constructed with the values `args`. |
| 1504 | template <typename T, typename... ARGS> |
| 1505 | const ast::CallExpression* vec4(const Source& source, ARGS&&... args) { |
| 1506 | return Construct(source, ty.vec4<T>(), std::forward<ARGS>(args)...); |
| 1507 | } |
| 1508 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1509 | /// @param args the arguments for the matrix initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1510 | /// @return an `ast::CallExpression` of a 2x2 matrix of type |
| 1511 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1512 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1513 | const ast::CallExpression* mat2x2(ARGS&&... args) { |
| 1514 | return Construct(ty.mat2x2<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1517 | /// @param source the matrix source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1518 | /// @param args the arguments for the matrix initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1519 | /// @return an `ast::CallExpression` of a 2x2 matrix of type |
| 1520 | /// `T`, constructed with the values `args`. |
| 1521 | template <typename T, typename... ARGS> |
| 1522 | const ast::CallExpression* mat2x2(const Source& source, ARGS&&... args) { |
| 1523 | return Construct(source, ty.mat2x2<T>(), std::forward<ARGS>(args)...); |
| 1524 | } |
| 1525 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1526 | /// @param args the arguments for the matrix initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1527 | /// @return an `ast::CallExpression` of a 2x3 matrix of type |
| 1528 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1529 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1530 | const ast::CallExpression* mat2x3(ARGS&&... args) { |
| 1531 | return Construct(ty.mat2x3<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1534 | /// @param source the matrix source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1535 | /// @param args the arguments for the matrix initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1536 | /// @return an `ast::CallExpression` of a 2x3 matrix of type |
| 1537 | /// `T`, constructed with the values `args`. |
| 1538 | template <typename T, typename... ARGS> |
| 1539 | const ast::CallExpression* mat2x3(const Source& source, ARGS&&... args) { |
| 1540 | return Construct(source, ty.mat2x3<T>(), std::forward<ARGS>(args)...); |
| 1541 | } |
| 1542 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1543 | /// @param args the arguments for the matrix initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1544 | /// @return an `ast::CallExpression` of a 2x4 matrix of type |
| 1545 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1546 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1547 | const ast::CallExpression* mat2x4(ARGS&&... args) { |
| 1548 | return Construct(ty.mat2x4<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1551 | /// @param source the matrix source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1552 | /// @param args the arguments for the matrix initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1553 | /// @return an `ast::CallExpression` of a 2x4 matrix of type |
| 1554 | /// `T`, constructed with the values `args`. |
| 1555 | template <typename T, typename... ARGS> |
| 1556 | const ast::CallExpression* mat2x4(const Source& source, ARGS&&... args) { |
| 1557 | return Construct(source, ty.mat2x4<T>(), std::forward<ARGS>(args)...); |
| 1558 | } |
| 1559 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1560 | /// @param args the arguments for the matrix initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1561 | /// @return an `ast::CallExpression` of a 3x2 matrix of type |
| 1562 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1563 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1564 | const ast::CallExpression* mat3x2(ARGS&&... args) { |
| 1565 | return Construct(ty.mat3x2<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1568 | /// @param source the matrix source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1569 | /// @param args the arguments for the matrix initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1570 | /// @return an `ast::CallExpression` of a 3x2 matrix of type |
| 1571 | /// `T`, constructed with the values `args`. |
| 1572 | template <typename T, typename... ARGS> |
| 1573 | const ast::CallExpression* mat3x2(const Source& source, ARGS&&... args) { |
| 1574 | return Construct(source, ty.mat3x2<T>(), std::forward<ARGS>(args)...); |
| 1575 | } |
| 1576 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1577 | /// @param args the arguments for the matrix initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1578 | /// @return an `ast::CallExpression` of a 3x3 matrix of type |
| 1579 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1580 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1581 | const ast::CallExpression* mat3x3(ARGS&&... args) { |
| 1582 | return Construct(ty.mat3x3<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1585 | /// @param source the matrix source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1586 | /// @param args the arguments for the matrix initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1587 | /// @return an `ast::CallExpression` of a 3x3 matrix of type |
| 1588 | /// `T`, constructed with the values `args`. |
| 1589 | template <typename T, typename... ARGS> |
| 1590 | const ast::CallExpression* mat3x3(const Source& source, ARGS&&... args) { |
| 1591 | return Construct(source, ty.mat3x3<T>(), std::forward<ARGS>(args)...); |
| 1592 | } |
| 1593 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1594 | /// @param args the arguments for the matrix initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1595 | /// @return an `ast::CallExpression` of a 3x4 matrix of type |
| 1596 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1597 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1598 | const ast::CallExpression* mat3x4(ARGS&&... args) { |
| 1599 | return Construct(ty.mat3x4<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1602 | /// @param source the matrix source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1603 | /// @param args the arguments for the matrix initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1604 | /// @return an `ast::CallExpression` of a 3x4 matrix of type |
| 1605 | /// `T`, constructed with the values `args`. |
| 1606 | template <typename T, typename... ARGS> |
| 1607 | const ast::CallExpression* mat3x4(const Source& source, ARGS&&... args) { |
| 1608 | return Construct(source, ty.mat3x4<T>(), std::forward<ARGS>(args)...); |
| 1609 | } |
| 1610 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1611 | /// @param args the arguments for the matrix initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1612 | /// @return an `ast::CallExpression` of a 4x2 matrix of type |
| 1613 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1614 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1615 | const ast::CallExpression* mat4x2(ARGS&&... args) { |
| 1616 | return Construct(ty.mat4x2<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1619 | /// @param source the matrix source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1620 | /// @param args the arguments for the matrix initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1621 | /// @return an `ast::CallExpression` of a 4x2 matrix of type |
| 1622 | /// `T`, constructed with the values `args`. |
| 1623 | template <typename T, typename... ARGS> |
| 1624 | const ast::CallExpression* mat4x2(const Source& source, ARGS&&... args) { |
| 1625 | return Construct(source, ty.mat4x2<T>(), std::forward<ARGS>(args)...); |
| 1626 | } |
| 1627 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1628 | /// @param args the arguments for the matrix initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1629 | /// @return an `ast::CallExpression` of a 4x3 matrix of type |
| 1630 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1631 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1632 | const ast::CallExpression* mat4x3(ARGS&&... args) { |
| 1633 | return Construct(ty.mat4x3<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1636 | /// @param source the matrix source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1637 | /// @param args the arguments for the matrix initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1638 | /// @return an `ast::CallExpression` of a 4x3 matrix of type |
| 1639 | /// `T`, constructed with the values `args`. |
| 1640 | template <typename T, typename... ARGS> |
| 1641 | const ast::CallExpression* mat4x3(const Source& source, ARGS&&... args) { |
| 1642 | return Construct(source, ty.mat4x3<T>(), std::forward<ARGS>(args)...); |
| 1643 | } |
| 1644 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1645 | /// @param args the arguments for the matrix initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1646 | /// @return an `ast::CallExpression` of a 4x4 matrix of type |
| 1647 | /// `T`, constructed with the values `args`. |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1648 | template <typename T, typename... ARGS, typename _ = DisableIfSource<ARGS...>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1649 | const ast::CallExpression* mat4x4(ARGS&&... args) { |
| 1650 | return Construct(ty.mat4x4<T>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1653 | /// @param source the matrix source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1654 | /// @param args the arguments for the matrix initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1655 | /// @return an `ast::CallExpression` of a 4x4 matrix of type |
| 1656 | /// `T`, constructed with the values `args`. |
| 1657 | template <typename T, typename... ARGS> |
| 1658 | const ast::CallExpression* mat4x4(const Source& source, ARGS&&... args) { |
| 1659 | return Construct(source, ty.mat4x4<T>(), std::forward<ARGS>(args)...); |
| 1660 | } |
| 1661 | |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1662 | /// @param args the arguments for the array initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1663 | /// @return an `ast::CallExpression` of an array with element type |
| 1664 | /// `T` and size `N`, constructed with the values `args`. |
| 1665 | template <typename T, int N, typename... ARGS> |
| 1666 | const ast::CallExpression* array(ARGS&&... args) { |
| 1667 | return Construct(ty.array<T, N>(), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1670 | /// @param source the array source |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1671 | /// @param args the arguments for the array initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1672 | /// @return an `ast::CallExpression` of an array with element type |
| 1673 | /// `T` and size `N`, constructed with the values `args`. |
| 1674 | template <typename T, int N, typename... ARGS> |
| 1675 | const ast::CallExpression* array(const Source& source, ARGS&&... args) { |
| 1676 | return Construct(source, ty.array<T, N>(), std::forward<ARGS>(args)...); |
| 1677 | } |
| 1678 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1679 | /// @param subtype the array element type |
| 1680 | /// @param n the array size. nullptr represents a runtime-array. |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1681 | /// @param args the arguments for the array initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1682 | /// @return an `ast::CallExpression` of an array with element type |
| 1683 | /// `subtype`, constructed with the values `args`. |
| 1684 | template <typename EXPR, typename... ARGS> |
| 1685 | const ast::CallExpression* array(const ast::Type* subtype, EXPR&& n, ARGS&&... args) { |
| 1686 | return Construct(ty.array(subtype, std::forward<EXPR>(n)), std::forward<ARGS>(args)...); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1689 | /// @param source the array source |
| 1690 | /// @param subtype the array element type |
| 1691 | /// @param n the array size. nullptr represents a runtime-array. |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1692 | /// @param args the arguments for the array initializer |
Ben Clayton | 6315a27 | 2022-08-01 17:18:04 +0000 | [diff] [blame] | 1693 | /// @return an `ast::CallExpression` of an array with element type |
| 1694 | /// `subtype`, constructed with the values `args`. |
| 1695 | template <typename EXPR, typename... ARGS> |
| 1696 | const ast::CallExpression* array(const Source& source, |
| 1697 | const ast::Type* subtype, |
| 1698 | EXPR&& n, |
| 1699 | ARGS&&... args) { |
| 1700 | return Construct(source, ty.array(subtype, std::forward<EXPR>(n)), |
| 1701 | std::forward<ARGS>(args)...); |
| 1702 | } |
| 1703 | |
Ben Clayton | 7f2b8cd | 2022-05-18 22:41:48 +0000 | [diff] [blame] | 1704 | /// Adds the extension to the list of enable directives at the top of the module. |
| 1705 | /// @param ext the extension to enable |
| 1706 | /// @return an `ast::Enable` enabling the given extension. |
| 1707 | const ast::Enable* Enable(ast::Extension ext) { |
| 1708 | auto* enable = create<ast::Enable>(ext); |
| 1709 | AST().AddEnable(enable); |
| 1710 | return enable; |
| 1711 | } |
| 1712 | |
Ben Clayton | 1a56778 | 2022-10-14 13:38:27 +0000 | [diff] [blame] | 1713 | /// Adds the extension to the list of enable directives at the top of the module. |
| 1714 | /// @param source the enable source |
| 1715 | /// @param ext the extension to enable |
| 1716 | /// @return an `ast::Enable` enabling the given extension. |
| 1717 | const ast::Enable* Enable(const Source& source, ast::Extension ext) { |
| 1718 | auto* enable = create<ast::Enable>(source, ext); |
| 1719 | AST().AddEnable(enable); |
| 1720 | return enable; |
| 1721 | } |
| 1722 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1723 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1724 | /// @param options the extra options passed to the ast::Var initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1725 | /// Can be any of the following, in any order: |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1726 | /// * ast::Type* - specifies the variable type |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 1727 | /// * ast::AddressSpace - specifies the variable address space |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1728 | /// * ast::Access - specifies the variable's access control |
| 1729 | /// * ast::Expression* - specifies the variable's initializer expression |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1730 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1731 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 1732 | /// @returns a `ast::Var` with the given name, type and additional |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1733 | /// options |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1734 | template <typename NAME, typename... OPTIONS, typename = DisableIfSource<NAME>> |
| 1735 | const ast::Var* Var(NAME&& name, OPTIONS&&... options) { |
| 1736 | VarOptions opts(std::forward<OPTIONS>(options)...); |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 1737 | return create<ast::Var>(Sym(std::forward<NAME>(name)), opts.type, opts.address_space, |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1738 | opts.access, opts.initializer, std::move(opts.attributes)); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1741 | /// @param source the variable source |
| 1742 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1743 | /// @param options the extra options passed to the ast::Var initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1744 | /// Can be any of the following, in any order: |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1745 | /// * ast::Type* - specifies the variable type |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 1746 | /// * ast::AddressSpace - specifies the variable address space |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1747 | /// * ast::Access - specifies the variable's access control |
| 1748 | /// * ast::Expression* - specifies the variable's initializer expression |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1749 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1750 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 1751 | /// @returns a `ast::Var` with the given name, address_space and type |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1752 | template <typename NAME, typename... OPTIONS> |
| 1753 | const ast::Var* Var(const Source& source, NAME&& name, OPTIONS&&... options) { |
| 1754 | VarOptions opts(std::forward<OPTIONS>(options)...); |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 1755 | return create<ast::Var>(source, Sym(std::forward<NAME>(name)), opts.type, |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1756 | opts.address_space, opts.access, opts.initializer, |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 1757 | std::move(opts.attributes)); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1761 | /// @param options the extra options passed to the ast::Var initializer |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1762 | /// Can be any of the following, in any order: |
| 1763 | /// * ast::Expression* - specifies the variable's initializer expression (required) |
| 1764 | /// * ast::Type* - specifies the variable type |
| 1765 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1766 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
| 1767 | /// @returns an `ast::Const` with the given name, type and additional options |
| 1768 | template <typename NAME, typename... OPTIONS, typename = DisableIfSource<NAME>> |
| 1769 | const ast::Const* Const(NAME&& name, OPTIONS&&... options) { |
| 1770 | ConstOptions opts(std::forward<OPTIONS>(options)...); |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1771 | return create<ast::Const>(Sym(std::forward<NAME>(name)), opts.type, opts.initializer, |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1772 | std::move(opts.attributes)); |
Ben Clayton | e3834c4 | 2022-06-25 23:21:39 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | /// @param source the variable source |
| 1776 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1777 | /// @param options the extra options passed to the ast::Var initializer |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1778 | /// Can be any of the following, in any order: |
| 1779 | /// * ast::Expression* - specifies the variable's initializer expression (required) |
| 1780 | /// * ast::Type* - specifies the variable type |
| 1781 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1782 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
| 1783 | /// @returns an `ast::Const` with the given name, type and additional options |
| 1784 | template <typename NAME, typename... OPTIONS> |
| 1785 | const ast::Const* Const(const Source& source, NAME&& name, OPTIONS&&... options) { |
| 1786 | ConstOptions opts(std::forward<OPTIONS>(options)...); |
| 1787 | return create<ast::Const>(source, Sym(std::forward<NAME>(name)), opts.type, |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1788 | opts.initializer, std::move(opts.attributes)); |
Ben Clayton | e3834c4 | 2022-06-25 23:21:39 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1792 | /// @param options the extra options passed to the ast::Var initializer |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1793 | /// Can be any of the following, in any order: |
| 1794 | /// * ast::Expression* - specifies the variable's initializer expression (required) |
| 1795 | /// * ast::Type* - specifies the variable type |
| 1796 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1797 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
| 1798 | /// @returns an `ast::Let` with the given name, type and additional options |
| 1799 | template <typename NAME, typename... OPTIONS, typename = DisableIfSource<NAME>> |
| 1800 | const ast::Let* Let(NAME&& name, OPTIONS&&... options) { |
| 1801 | LetOptions opts(std::forward<OPTIONS>(options)...); |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1802 | return create<ast::Let>(Sym(std::forward<NAME>(name)), opts.type, opts.initializer, |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1803 | std::move(opts.attributes)); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1804 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1805 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1806 | /// @param source the variable source |
| 1807 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1808 | /// @param options the extra options passed to the ast::Var initializer |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1809 | /// Can be any of the following, in any order: |
| 1810 | /// * ast::Expression* - specifies the variable's initializer expression (required) |
| 1811 | /// * ast::Type* - specifies the variable type |
| 1812 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1813 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
| 1814 | /// @returns an `ast::Let` with the given name, type and additional options |
| 1815 | template <typename NAME, typename... OPTIONS> |
| 1816 | const ast::Let* Let(const Source& source, NAME&& name, OPTIONS&&... options) { |
| 1817 | LetOptions opts(std::forward<OPTIONS>(options)...); |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1818 | return create<ast::Let>(source, Sym(std::forward<NAME>(name)), opts.type, opts.initializer, |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1819 | std::move(opts.attributes)); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1820 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1821 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1822 | /// @param name the parameter name |
| 1823 | /// @param type the parameter type |
| 1824 | /// @param attributes optional parameter attributes |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 1825 | /// @returns an `ast::Parameter` with the given name and type |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1826 | template <typename NAME> |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 1827 | const ast::Parameter* Param(NAME&& name, |
| 1828 | const ast::Type* type, |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1829 | utils::VectorRef<const ast::Attribute*> attributes = utils::Empty) { |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 1830 | return create<ast::Parameter>(Sym(std::forward<NAME>(name)), type, attributes); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1831 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1832 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1833 | /// @param source the parameter source |
| 1834 | /// @param name the parameter name |
| 1835 | /// @param type the parameter type |
| 1836 | /// @param attributes optional parameter attributes |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 1837 | /// @returns an `ast::Parameter` with the given name and type |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1838 | template <typename NAME> |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 1839 | const ast::Parameter* Param(const Source& source, |
| 1840 | NAME&& name, |
| 1841 | const ast::Type* type, |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 1842 | utils::VectorRef<const ast::Attribute*> attributes = utils::Empty) { |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 1843 | return create<ast::Parameter>(source, Sym(std::forward<NAME>(name)), type, attributes); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1844 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1845 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1846 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1847 | /// @param options the extra options passed to the ast::Var initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1848 | /// Can be any of the following, in any order: |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1849 | /// * ast::Type* - specifies the variable type |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 1850 | /// * ast::AddressSpace - specifies the variable address space |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1851 | /// * ast::Access - specifies the variable's access control |
| 1852 | /// * ast::Expression* - specifies the variable's initializer expression |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1853 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1854 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 1855 | /// @returns a new `ast::Var`, which is automatically registered as a global variable with the |
| 1856 | /// ast::Module. |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1857 | template <typename NAME, typename... OPTIONS, typename = DisableIfSource<NAME>> |
| 1858 | const ast::Var* GlobalVar(NAME&& name, OPTIONS&&... options) { |
| 1859 | auto* variable = Var(std::forward<NAME>(name), std::forward<OPTIONS>(options)...); |
| 1860 | AST().AddGlobalVariable(variable); |
| 1861 | return variable; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1862 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1863 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1864 | /// @param source the variable source |
| 1865 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1866 | /// @param options the extra options passed to the ast::Var initializer |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1867 | /// Can be any of the following, in any order: |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1868 | /// * ast::Type* - specifies the variable type |
dan sinclair | ff7cf21 | 2022-10-03 14:05:23 +0000 | [diff] [blame] | 1869 | /// * ast::AddressSpace - specifies the variable address space |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1870 | /// * ast::Access - specifies the variable's access control |
| 1871 | /// * ast::Expression* - specifies the variable's initializer expression |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1872 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1873 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
Ben Clayton | dcdf66e | 2022-06-17 12:48:51 +0000 | [diff] [blame] | 1874 | /// @returns a new `ast::Var`, which is automatically registered as a global variable with the |
| 1875 | /// ast::Module. |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1876 | template <typename NAME, typename... OPTIONS> |
| 1877 | const ast::Var* GlobalVar(const Source& source, NAME&& name, OPTIONS&&... options) { |
| 1878 | auto* variable = Var(source, std::forward<NAME>(name), std::forward<OPTIONS>(options)...); |
| 1879 | AST().AddGlobalVariable(variable); |
| 1880 | return variable; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1881 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1882 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1883 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1884 | /// @param options the extra options passed to the ast::Const initializer |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1885 | /// Can be any of the following, in any order: |
| 1886 | /// * ast::Expression* - specifies the variable's initializer expression (required) |
| 1887 | /// * ast::Type* - specifies the variable type |
| 1888 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1889 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
| 1890 | /// @returns an `ast::Const` with the given name, type and additional options, which is |
| 1891 | /// automatically registered as a global variable with the ast::Module. |
| 1892 | template <typename NAME, typename... OPTIONS, typename = DisableIfSource<NAME>> |
| 1893 | const ast::Const* GlobalConst(NAME&& name, OPTIONS&&... options) { |
| 1894 | auto* variable = Const(std::forward<NAME>(name), std::forward<OPTIONS>(options)...); |
| 1895 | AST().AddGlobalVariable(variable); |
| 1896 | return variable; |
Ben Clayton | e3834c4 | 2022-06-25 23:21:39 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | /// @param source the variable source |
| 1900 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1901 | /// @param options the extra options passed to the ast::Const initializer |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1902 | /// Can be any of the following, in any order: |
| 1903 | /// * ast::Expression* - specifies the variable's initializer expression (required) |
| 1904 | /// * ast::Type* - specifies the variable type |
| 1905 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1906 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
| 1907 | /// @returns an `ast::Const` with the given name, type and additional options, which is |
| 1908 | /// automatically registered as a global variable with the ast::Module. |
| 1909 | template <typename NAME, typename... OPTIONS> |
| 1910 | const ast::Const* GlobalConst(const Source& source, NAME&& name, OPTIONS&&... options) { |
| 1911 | auto* variable = Const(source, std::forward<NAME>(name), std::forward<OPTIONS>(options)...); |
| 1912 | AST().AddGlobalVariable(variable); |
| 1913 | return variable; |
Ben Clayton | e3834c4 | 2022-06-25 23:21:39 +0000 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1917 | /// @param options the extra options passed to the ast::Override initializer |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1918 | /// Can be any of the following, in any order: |
| 1919 | /// * ast::Expression* - specifies the variable's initializer expression (required) |
| 1920 | /// * ast::Type* - specifies the variable type |
| 1921 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1922 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
| 1923 | /// @returns an `ast::Override` with the given name, type and additional options, which is |
| 1924 | /// automatically registered as a global variable with the ast::Module. |
| 1925 | template <typename NAME, typename... OPTIONS, typename = DisableIfSource<NAME>> |
| 1926 | const ast::Override* Override(NAME&& name, OPTIONS&&... options) { |
| 1927 | OverrideOptions opts(std::forward<OPTIONS>(options)...); |
| 1928 | auto* variable = create<ast::Override>(Sym(std::forward<NAME>(name)), opts.type, |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1929 | opts.initializer, std::move(opts.attributes)); |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1930 | AST().AddGlobalVariable(variable); |
| 1931 | return variable; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1932 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1933 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1934 | /// @param source the variable source |
| 1935 | /// @param name the variable name |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1936 | /// @param options the extra options passed to the ast::Override initializer |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1937 | /// Can be any of the following, in any order: |
| 1938 | /// * ast::Expression* - specifies the variable's initializer expression (required) |
| 1939 | /// * ast::Type* - specifies the variable type |
| 1940 | /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) |
| 1941 | /// Note that non-repeatable arguments of the same type will use the last argument's value. |
| 1942 | /// @returns an `ast::Override` with the given name, type and additional options, which is |
| 1943 | /// automatically registered as a global variable with the ast::Module. |
| 1944 | template <typename NAME, typename... OPTIONS> |
| 1945 | const ast::Override* Override(const Source& source, NAME&& name, OPTIONS&&... options) { |
| 1946 | OverrideOptions opts(std::forward<OPTIONS>(options)...); |
| 1947 | auto* variable = create<ast::Override>(source, Sym(std::forward<NAME>(name)), opts.type, |
dan sinclair | 6e77b47 | 2022-10-20 13:38:28 +0000 | [diff] [blame] | 1948 | opts.initializer, std::move(opts.attributes)); |
Ben Clayton | 58794ae | 2022-08-19 17:28:53 +0000 | [diff] [blame] | 1949 | AST().AddGlobalVariable(variable); |
| 1950 | return variable; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1951 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1952 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1953 | /// @param source the source information |
Ben Clayton | bfd1a81 | 2022-08-02 23:16:25 +0000 | [diff] [blame] | 1954 | /// @param condition the assertion condition |
| 1955 | /// @returns a new `ast::StaticAssert`, which is automatically registered as a global statement |
| 1956 | /// with the ast::Module. |
| 1957 | template <typename EXPR> |
| 1958 | const ast::StaticAssert* GlobalStaticAssert(const Source& source, EXPR&& condition) { |
| 1959 | auto* sa = StaticAssert(source, std::forward<EXPR>(condition)); |
| 1960 | AST().AddStaticAssert(sa); |
| 1961 | return sa; |
| 1962 | } |
| 1963 | |
| 1964 | /// @param condition the assertion condition |
| 1965 | /// @returns a new `ast::StaticAssert`, which is automatically registered as a global statement |
| 1966 | /// with the ast::Module. |
| 1967 | template <typename EXPR, typename = DisableIfSource<EXPR>> |
| 1968 | const ast::StaticAssert* GlobalStaticAssert(EXPR&& condition) { |
| 1969 | auto* sa = StaticAssert(std::forward<EXPR>(condition)); |
| 1970 | AST().AddStaticAssert(sa); |
| 1971 | return sa; |
| 1972 | } |
| 1973 | |
| 1974 | /// @param source the source information |
| 1975 | /// @param condition the assertion condition |
| 1976 | /// @returns a new `ast::StaticAssert` with the given assertion condition |
| 1977 | template <typename EXPR> |
| 1978 | const ast::StaticAssert* StaticAssert(const Source& source, EXPR&& condition) { |
| 1979 | return create<ast::StaticAssert>(source, Expr(std::forward<EXPR>(condition))); |
| 1980 | } |
| 1981 | |
| 1982 | /// @param condition the assertion condition |
| 1983 | /// @returns a new `ast::StaticAssert` with the given assertion condition |
| 1984 | template <typename EXPR, typename = DisableIfSource<EXPR>> |
| 1985 | const ast::StaticAssert* StaticAssert(EXPR&& condition) { |
| 1986 | return create<ast::StaticAssert>(Expr(std::forward<EXPR>(condition))); |
| 1987 | } |
| 1988 | |
| 1989 | /// @param source the source information |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1990 | /// @param expr the expression to take the address of |
| 1991 | /// @return an ast::UnaryOpExpression that takes the address of `expr` |
| 1992 | template <typename EXPR> |
| 1993 | const ast::UnaryOpExpression* AddressOf(const Source& source, EXPR&& expr) { |
| 1994 | return create<ast::UnaryOpExpression>(source, ast::UnaryOp::kAddressOf, |
| 1995 | Expr(std::forward<EXPR>(expr))); |
| 1996 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1997 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 1998 | /// @param expr the expression to take the address of |
| 1999 | /// @return an ast::UnaryOpExpression that takes the address of `expr` |
| 2000 | template <typename EXPR> |
| 2001 | const ast::UnaryOpExpression* AddressOf(EXPR&& expr) { |
| 2002 | return create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, |
| 2003 | Expr(std::forward<EXPR>(expr))); |
| 2004 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2005 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2006 | /// @param source the source information |
| 2007 | /// @param expr the expression to perform an indirection on |
| 2008 | /// @return an ast::UnaryOpExpression that dereferences the pointer `expr` |
| 2009 | template <typename EXPR> |
| 2010 | const ast::UnaryOpExpression* Deref(const Source& source, EXPR&& expr) { |
| 2011 | return create<ast::UnaryOpExpression>(source, ast::UnaryOp::kIndirection, |
| 2012 | Expr(std::forward<EXPR>(expr))); |
| 2013 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2014 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2015 | /// @param expr the expression to perform an indirection on |
| 2016 | /// @return an ast::UnaryOpExpression that dereferences the pointer `expr` |
| 2017 | template <typename EXPR> |
| 2018 | const ast::UnaryOpExpression* Deref(EXPR&& expr) { |
| 2019 | return create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, |
| 2020 | Expr(std::forward<EXPR>(expr))); |
| 2021 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2022 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2023 | /// @param expr the expression to perform a unary not on |
| 2024 | /// @return an ast::UnaryOpExpression that is the unary not of the input |
| 2025 | /// expression |
| 2026 | template <typename EXPR> |
| 2027 | const ast::UnaryOpExpression* Not(EXPR&& expr) { |
| 2028 | return create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, Expr(std::forward<EXPR>(expr))); |
| 2029 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2030 | |
Antonio Maiorano | 28779af | 2022-12-09 21:28:51 +0000 | [diff] [blame] | 2031 | /// @param source the source information |
| 2032 | /// @param expr the expression to perform a unary not on |
| 2033 | /// @return an ast::UnaryOpExpression that is the unary not of the input |
| 2034 | /// expression |
| 2035 | template <typename EXPR> |
| 2036 | const ast::UnaryOpExpression* Not(const Source& source, EXPR&& expr) { |
| 2037 | return create<ast::UnaryOpExpression>(source, ast::UnaryOp::kNot, |
| 2038 | Expr(std::forward<EXPR>(expr))); |
| 2039 | } |
| 2040 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2041 | /// @param expr the expression to perform a unary complement on |
| 2042 | /// @return an ast::UnaryOpExpression that is the unary complement of the |
| 2043 | /// input expression |
| 2044 | template <typename EXPR> |
| 2045 | const ast::UnaryOpExpression* Complement(EXPR&& expr) { |
| 2046 | return create<ast::UnaryOpExpression>(ast::UnaryOp::kComplement, |
| 2047 | Expr(std::forward<EXPR>(expr))); |
| 2048 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2049 | |
Author: Shiyu Liu | b3aab09 | 2022-05-04 13:07:29 +0000 | [diff] [blame] | 2050 | /// @param expr the expression to perform a unary negation on |
| 2051 | /// @return an ast::UnaryOpExpression that is the unary negation of the |
| 2052 | /// input expression |
| 2053 | template <typename EXPR> |
| 2054 | const ast::UnaryOpExpression* Negation(EXPR&& expr) { |
| 2055 | return create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, |
| 2056 | Expr(std::forward<EXPR>(expr))); |
| 2057 | } |
| 2058 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2059 | /// @param source the source information |
| 2060 | /// @param func the function name |
| 2061 | /// @param args the function call arguments |
| 2062 | /// @returns a `ast::CallExpression` to the function `func`, with the |
| 2063 | /// arguments of `args` converted to `ast::Expression`s using `Expr()`. |
| 2064 | template <typename NAME, typename... ARGS> |
| 2065 | const ast::CallExpression* Call(const Source& source, NAME&& func, ARGS&&... args) { |
| 2066 | return create<ast::CallExpression>(source, Expr(func), |
| 2067 | ExprList(std::forward<ARGS>(args)...)); |
| 2068 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2069 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2070 | /// @param func the function name |
| 2071 | /// @param args the function call arguments |
| 2072 | /// @returns a `ast::CallExpression` to the function `func`, with the |
| 2073 | /// arguments of `args` converted to `ast::Expression`s using `Expr()`. |
| 2074 | template <typename NAME, typename... ARGS, typename = DisableIfSource<NAME>> |
| 2075 | const ast::CallExpression* Call(NAME&& func, ARGS&&... args) { |
| 2076 | return create<ast::CallExpression>(Expr(func), ExprList(std::forward<ARGS>(args)...)); |
| 2077 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2078 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2079 | /// @param source the source information |
| 2080 | /// @param call the call expression to wrap in a call statement |
| 2081 | /// @returns a `ast::CallStatement` for the given call expression |
| 2082 | const ast::CallStatement* CallStmt(const Source& source, const ast::CallExpression* call) { |
| 2083 | return create<ast::CallStatement>(source, call); |
| 2084 | } |
James Price | c022ff5 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 2085 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2086 | /// @param call the call expression to wrap in a call statement |
| 2087 | /// @returns a `ast::CallStatement` for the given call expression |
| 2088 | const ast::CallStatement* CallStmt(const ast::CallExpression* call) { |
| 2089 | return create<ast::CallStatement>(call); |
| 2090 | } |
James Price | c022ff5 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 2091 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2092 | /// @param source the source information |
| 2093 | /// @returns a `ast::PhonyExpression` |
| 2094 | const ast::PhonyExpression* Phony(const Source& source) { |
| 2095 | return create<ast::PhonyExpression>(source); |
| 2096 | } |
James Price | ebe9741 | 2022-04-07 13:42:45 +0000 | [diff] [blame] | 2097 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2098 | /// @returns a `ast::PhonyExpression` |
| 2099 | const ast::PhonyExpression* Phony() { return create<ast::PhonyExpression>(); } |
James Price | ebe9741 | 2022-04-07 13:42:45 +0000 | [diff] [blame] | 2100 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2101 | /// @param expr the expression to ignore |
| 2102 | /// @returns a `ast::AssignmentStatement` that assigns 'expr' to the phony |
| 2103 | /// (underscore) variable. |
| 2104 | template <typename EXPR> |
| 2105 | const ast::AssignmentStatement* Ignore(EXPR&& expr) { |
| 2106 | return create<ast::AssignmentStatement>(Phony(), Expr(expr)); |
| 2107 | } |
James Price | ebe9741 | 2022-04-07 13:42:45 +0000 | [diff] [blame] | 2108 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2109 | /// @param lhs the left hand argument to the addition operation |
| 2110 | /// @param rhs the right hand argument to the addition operation |
| 2111 | /// @returns a `ast::BinaryExpression` summing the arguments `lhs` and `rhs` |
| 2112 | template <typename LHS, typename RHS> |
| 2113 | const ast::BinaryExpression* Add(LHS&& lhs, RHS&& rhs) { |
| 2114 | return create<ast::BinaryExpression>(ast::BinaryOp::kAdd, Expr(std::forward<LHS>(lhs)), |
| 2115 | Expr(std::forward<RHS>(rhs))); |
| 2116 | } |
James Price | ebe9741 | 2022-04-07 13:42:45 +0000 | [diff] [blame] | 2117 | |
Antonio Maiorano | 7058a17 | 2022-08-10 18:06:43 +0000 | [diff] [blame] | 2118 | /// @param source the source information |
| 2119 | /// @param lhs the left hand argument to the addition operation |
| 2120 | /// @param rhs the right hand argument to the addition operation |
| 2121 | /// @returns a `ast::BinaryExpression` summing the arguments `lhs` and `rhs` |
| 2122 | template <typename LHS, typename RHS> |
| 2123 | const ast::BinaryExpression* Add(const Source& source, LHS&& lhs, RHS&& rhs) { |
| 2124 | return create<ast::BinaryExpression>(source, ast::BinaryOp::kAdd, |
| 2125 | Expr(std::forward<LHS>(lhs)), |
| 2126 | Expr(std::forward<RHS>(rhs))); |
| 2127 | } |
| 2128 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2129 | /// @param lhs the left hand argument to the and operation |
| 2130 | /// @param rhs the right hand argument to the and operation |
| 2131 | /// @returns a `ast::BinaryExpression` bitwise anding `lhs` and `rhs` |
| 2132 | template <typename LHS, typename RHS> |
| 2133 | const ast::BinaryExpression* And(LHS&& lhs, RHS&& rhs) { |
| 2134 | return create<ast::BinaryExpression>(ast::BinaryOp::kAnd, Expr(std::forward<LHS>(lhs)), |
| 2135 | Expr(std::forward<RHS>(rhs))); |
| 2136 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2137 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2138 | /// @param lhs the left hand argument to the or operation |
| 2139 | /// @param rhs the right hand argument to the or operation |
| 2140 | /// @returns a `ast::BinaryExpression` bitwise or-ing `lhs` and `rhs` |
| 2141 | template <typename LHS, typename RHS> |
| 2142 | const ast::BinaryExpression* Or(LHS&& lhs, RHS&& rhs) { |
| 2143 | return create<ast::BinaryExpression>(ast::BinaryOp::kOr, Expr(std::forward<LHS>(lhs)), |
| 2144 | Expr(std::forward<RHS>(rhs))); |
| 2145 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2146 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2147 | /// @param lhs the left hand argument to the subtraction operation |
| 2148 | /// @param rhs the right hand argument to the subtraction operation |
| 2149 | /// @returns a `ast::BinaryExpression` subtracting `rhs` from `lhs` |
| 2150 | template <typename LHS, typename RHS> |
| 2151 | const ast::BinaryExpression* Sub(LHS&& lhs, RHS&& rhs) { |
| 2152 | return create<ast::BinaryExpression>(ast::BinaryOp::kSubtract, Expr(std::forward<LHS>(lhs)), |
| 2153 | Expr(std::forward<RHS>(rhs))); |
| 2154 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2155 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2156 | /// @param lhs the left hand argument to the multiplication operation |
| 2157 | /// @param rhs the right hand argument to the multiplication operation |
| 2158 | /// @returns a `ast::BinaryExpression` multiplying `rhs` from `lhs` |
| 2159 | template <typename LHS, typename RHS> |
| 2160 | const ast::BinaryExpression* Mul(LHS&& lhs, RHS&& rhs) { |
| 2161 | return create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, Expr(std::forward<LHS>(lhs)), |
| 2162 | Expr(std::forward<RHS>(rhs))); |
| 2163 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2164 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2165 | /// @param source the source information |
| 2166 | /// @param lhs the left hand argument to the multiplication operation |
| 2167 | /// @param rhs the right hand argument to the multiplication operation |
| 2168 | /// @returns a `ast::BinaryExpression` multiplying `rhs` from `lhs` |
| 2169 | template <typename LHS, typename RHS> |
| 2170 | const ast::BinaryExpression* Mul(const Source& source, LHS&& lhs, RHS&& rhs) { |
| 2171 | return create<ast::BinaryExpression>(source, ast::BinaryOp::kMultiply, |
| 2172 | Expr(std::forward<LHS>(lhs)), |
| 2173 | Expr(std::forward<RHS>(rhs))); |
| 2174 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2175 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2176 | /// @param lhs the left hand argument to the division operation |
| 2177 | /// @param rhs the right hand argument to the division operation |
| 2178 | /// @returns a `ast::BinaryExpression` dividing `lhs` by `rhs` |
| 2179 | template <typename LHS, typename RHS> |
| 2180 | const ast::BinaryExpression* Div(LHS&& lhs, RHS&& rhs) { |
| 2181 | return create<ast::BinaryExpression>(ast::BinaryOp::kDivide, Expr(std::forward<LHS>(lhs)), |
| 2182 | Expr(std::forward<RHS>(rhs))); |
| 2183 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2184 | |
Antonio Maiorano | 28779af | 2022-12-09 21:28:51 +0000 | [diff] [blame] | 2185 | /// @param source the source information |
| 2186 | /// @param lhs the left hand argument to the division operation |
| 2187 | /// @param rhs the right hand argument to the division operation |
| 2188 | /// @returns a `ast::BinaryExpression` dividing `lhs` by `rhs` |
| 2189 | template <typename LHS, typename RHS> |
| 2190 | const ast::BinaryExpression* Div(const Source& source, LHS&& lhs, RHS&& rhs) { |
| 2191 | return create<ast::BinaryExpression>(source, ast::BinaryOp::kDivide, |
| 2192 | Expr(std::forward<LHS>(lhs)), |
| 2193 | Expr(std::forward<RHS>(rhs))); |
| 2194 | } |
| 2195 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2196 | /// @param lhs the left hand argument to the modulo operation |
| 2197 | /// @param rhs the right hand argument to the modulo operation |
| 2198 | /// @returns a `ast::BinaryExpression` applying modulo of `lhs` by `rhs` |
| 2199 | template <typename LHS, typename RHS> |
| 2200 | const ast::BinaryExpression* Mod(LHS&& lhs, RHS&& rhs) { |
| 2201 | return create<ast::BinaryExpression>(ast::BinaryOp::kModulo, Expr(std::forward<LHS>(lhs)), |
| 2202 | Expr(std::forward<RHS>(rhs))); |
| 2203 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2204 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2205 | /// @param lhs the left hand argument to the bit shift right operation |
| 2206 | /// @param rhs the right hand argument to the bit shift right operation |
| 2207 | /// @returns a `ast::BinaryExpression` bit shifting right `lhs` by `rhs` |
| 2208 | template <typename LHS, typename RHS> |
| 2209 | const ast::BinaryExpression* Shr(LHS&& lhs, RHS&& rhs) { |
| 2210 | return create<ast::BinaryExpression>( |
| 2211 | ast::BinaryOp::kShiftRight, Expr(std::forward<LHS>(lhs)), Expr(std::forward<RHS>(rhs))); |
| 2212 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2213 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2214 | /// @param lhs the left hand argument to the bit shift left operation |
| 2215 | /// @param rhs the right hand argument to the bit shift left operation |
| 2216 | /// @returns a `ast::BinaryExpression` bit shifting left `lhs` by `rhs` |
| 2217 | template <typename LHS, typename RHS> |
| 2218 | const ast::BinaryExpression* Shl(LHS&& lhs, RHS&& rhs) { |
| 2219 | return create<ast::BinaryExpression>( |
| 2220 | ast::BinaryOp::kShiftLeft, Expr(std::forward<LHS>(lhs)), Expr(std::forward<RHS>(rhs))); |
| 2221 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2222 | |
Antonio Maiorano | 5f33fac | 2022-09-23 21:58:29 +0000 | [diff] [blame] | 2223 | /// @param source the source information |
| 2224 | /// @param lhs the left hand argument to the bit shift left operation |
| 2225 | /// @param rhs the right hand argument to the bit shift left operation |
| 2226 | /// @returns a `ast::BinaryExpression` bit shifting left `lhs` by `rhs` |
| 2227 | template <typename LHS, typename RHS> |
| 2228 | const ast::BinaryExpression* Shl(const Source& source, LHS&& lhs, RHS&& rhs) { |
| 2229 | return create<ast::BinaryExpression>(source, ast::BinaryOp::kShiftLeft, |
| 2230 | Expr(std::forward<LHS>(lhs)), |
| 2231 | Expr(std::forward<RHS>(rhs))); |
| 2232 | } |
| 2233 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2234 | /// @param lhs the left hand argument to the xor operation |
| 2235 | /// @param rhs the right hand argument to the xor operation |
| 2236 | /// @returns a `ast::BinaryExpression` bitwise xor-ing `lhs` and `rhs` |
| 2237 | template <typename LHS, typename RHS> |
| 2238 | const ast::BinaryExpression* Xor(LHS&& lhs, RHS&& rhs) { |
| 2239 | return create<ast::BinaryExpression>(ast::BinaryOp::kXor, Expr(std::forward<LHS>(lhs)), |
| 2240 | Expr(std::forward<RHS>(rhs))); |
| 2241 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2242 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2243 | /// @param lhs the left hand argument to the logical and operation |
| 2244 | /// @param rhs the right hand argument to the logical and operation |
| 2245 | /// @returns a `ast::BinaryExpression` of `lhs` && `rhs` |
| 2246 | template <typename LHS, typename RHS> |
| 2247 | const ast::BinaryExpression* LogicalAnd(LHS&& lhs, RHS&& rhs) { |
| 2248 | return create<ast::BinaryExpression>( |
| 2249 | ast::BinaryOp::kLogicalAnd, Expr(std::forward<LHS>(lhs)), Expr(std::forward<RHS>(rhs))); |
| 2250 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2251 | |
Antonio Maiorano | 28779af | 2022-12-09 21:28:51 +0000 | [diff] [blame] | 2252 | /// @param source the source information |
| 2253 | /// @param lhs the left hand argument to the logical and operation |
| 2254 | /// @param rhs the right hand argument to the logical and operation |
| 2255 | /// @returns a `ast::BinaryExpression` of `lhs` && `rhs` |
| 2256 | template <typename LHS, typename RHS> |
| 2257 | const ast::BinaryExpression* LogicalAnd(const Source& source, LHS&& lhs, RHS&& rhs) { |
| 2258 | return create<ast::BinaryExpression>(source, ast::BinaryOp::kLogicalAnd, |
| 2259 | Expr(std::forward<LHS>(lhs)), |
| 2260 | Expr(std::forward<RHS>(rhs))); |
| 2261 | } |
| 2262 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2263 | /// @param lhs the left hand argument to the logical or operation |
| 2264 | /// @param rhs the right hand argument to the logical or operation |
| 2265 | /// @returns a `ast::BinaryExpression` of `lhs` || `rhs` |
| 2266 | template <typename LHS, typename RHS> |
| 2267 | const ast::BinaryExpression* LogicalOr(LHS&& lhs, RHS&& rhs) { |
| 2268 | return create<ast::BinaryExpression>( |
| 2269 | ast::BinaryOp::kLogicalOr, Expr(std::forward<LHS>(lhs)), Expr(std::forward<RHS>(rhs))); |
| 2270 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2271 | |
Antonio Maiorano | 28779af | 2022-12-09 21:28:51 +0000 | [diff] [blame] | 2272 | /// @param source the source information |
| 2273 | /// @param lhs the left hand argument to the logical or operation |
| 2274 | /// @param rhs the right hand argument to the logical or operation |
| 2275 | /// @returns a `ast::BinaryExpression` of `lhs` || `rhs` |
| 2276 | template <typename LHS, typename RHS> |
| 2277 | const ast::BinaryExpression* LogicalOr(const Source& source, LHS&& lhs, RHS&& rhs) { |
| 2278 | return create<ast::BinaryExpression>(source, ast::BinaryOp::kLogicalOr, |
| 2279 | Expr(std::forward<LHS>(lhs)), |
| 2280 | Expr(std::forward<RHS>(rhs))); |
| 2281 | } |
| 2282 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2283 | /// @param lhs the left hand argument to the greater than operation |
| 2284 | /// @param rhs the right hand argument to the greater than operation |
| 2285 | /// @returns a `ast::BinaryExpression` of `lhs` > `rhs` |
| 2286 | template <typename LHS, typename RHS> |
| 2287 | const ast::BinaryExpression* GreaterThan(LHS&& lhs, RHS&& rhs) { |
| 2288 | return create<ast::BinaryExpression>(ast::BinaryOp::kGreaterThan, |
| 2289 | Expr(std::forward<LHS>(lhs)), |
| 2290 | Expr(std::forward<RHS>(rhs))); |
| 2291 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2292 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2293 | /// @param lhs the left hand argument to the greater than or equal operation |
| 2294 | /// @param rhs the right hand argument to the greater than or equal operation |
| 2295 | /// @returns a `ast::BinaryExpression` of `lhs` >= `rhs` |
| 2296 | template <typename LHS, typename RHS> |
| 2297 | const ast::BinaryExpression* GreaterThanEqual(LHS&& lhs, RHS&& rhs) { |
| 2298 | return create<ast::BinaryExpression>(ast::BinaryOp::kGreaterThanEqual, |
| 2299 | Expr(std::forward<LHS>(lhs)), |
| 2300 | Expr(std::forward<RHS>(rhs))); |
| 2301 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2302 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2303 | /// @param lhs the left hand argument to the less than operation |
| 2304 | /// @param rhs the right hand argument to the less than operation |
| 2305 | /// @returns a `ast::BinaryExpression` of `lhs` < `rhs` |
| 2306 | template <typename LHS, typename RHS> |
| 2307 | const ast::BinaryExpression* LessThan(LHS&& lhs, RHS&& rhs) { |
| 2308 | return create<ast::BinaryExpression>(ast::BinaryOp::kLessThan, Expr(std::forward<LHS>(lhs)), |
| 2309 | Expr(std::forward<RHS>(rhs))); |
| 2310 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2311 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2312 | /// @param lhs the left hand argument to the less than or equal operation |
| 2313 | /// @param rhs the right hand argument to the less than or equal operation |
| 2314 | /// @returns a `ast::BinaryExpression` of `lhs` <= `rhs` |
| 2315 | template <typename LHS, typename RHS> |
| 2316 | const ast::BinaryExpression* LessThanEqual(LHS&& lhs, RHS&& rhs) { |
| 2317 | return create<ast::BinaryExpression>(ast::BinaryOp::kLessThanEqual, |
| 2318 | Expr(std::forward<LHS>(lhs)), |
| 2319 | Expr(std::forward<RHS>(rhs))); |
| 2320 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2321 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2322 | /// @param lhs the left hand argument to the equal expression |
| 2323 | /// @param rhs the right hand argument to the equal expression |
| 2324 | /// @returns a `ast::BinaryExpression` comparing `lhs` equal to `rhs` |
| 2325 | template <typename LHS, typename RHS> |
| 2326 | const ast::BinaryExpression* Equal(LHS&& lhs, RHS&& rhs) { |
| 2327 | return create<ast::BinaryExpression>(ast::BinaryOp::kEqual, Expr(std::forward<LHS>(lhs)), |
| 2328 | Expr(std::forward<RHS>(rhs))); |
| 2329 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2330 | |
Antonio Maiorano | 28779af | 2022-12-09 21:28:51 +0000 | [diff] [blame] | 2331 | /// @param source the source information |
| 2332 | /// @param lhs the left hand argument to the equal expression |
| 2333 | /// @param rhs the right hand argument to the equal expression |
| 2334 | /// @returns a `ast::BinaryExpression` comparing `lhs` equal to `rhs` |
| 2335 | template <typename LHS, typename RHS> |
| 2336 | const ast::BinaryExpression* Equal(const Source& source, LHS&& lhs, RHS&& rhs) { |
| 2337 | return create<ast::BinaryExpression>(source, ast::BinaryOp::kEqual, |
| 2338 | Expr(std::forward<LHS>(lhs)), |
| 2339 | Expr(std::forward<RHS>(rhs))); |
| 2340 | } |
| 2341 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2342 | /// @param lhs the left hand argument to the not-equal expression |
| 2343 | /// @param rhs the right hand argument to the not-equal expression |
| 2344 | /// @returns a `ast::BinaryExpression` comparing `lhs` equal to `rhs` for |
| 2345 | /// disequality |
| 2346 | template <typename LHS, typename RHS> |
| 2347 | const ast::BinaryExpression* NotEqual(LHS&& lhs, RHS&& rhs) { |
| 2348 | return create<ast::BinaryExpression>(ast::BinaryOp::kNotEqual, Expr(std::forward<LHS>(lhs)), |
| 2349 | Expr(std::forward<RHS>(rhs))); |
| 2350 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2351 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2352 | /// @param source the source information |
| 2353 | /// @param obj the object for the index accessor expression |
| 2354 | /// @param idx the index argument for the index accessor expression |
| 2355 | /// @returns a `ast::IndexAccessorExpression` that indexes `arr` with `idx` |
| 2356 | template <typename OBJ, typename IDX> |
| 2357 | const ast::IndexAccessorExpression* IndexAccessor(const Source& source, OBJ&& obj, IDX&& idx) { |
| 2358 | return create<ast::IndexAccessorExpression>(source, Expr(std::forward<OBJ>(obj)), |
| 2359 | Expr(std::forward<IDX>(idx))); |
| 2360 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2361 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2362 | /// @param obj the object for the index accessor expression |
| 2363 | /// @param idx the index argument for the index accessor expression |
| 2364 | /// @returns a `ast::IndexAccessorExpression` that indexes `arr` with `idx` |
| 2365 | template <typename OBJ, typename IDX> |
| 2366 | const ast::IndexAccessorExpression* IndexAccessor(OBJ&& obj, IDX&& idx) { |
| 2367 | return create<ast::IndexAccessorExpression>(Expr(std::forward<OBJ>(obj)), |
| 2368 | Expr(std::forward<IDX>(idx))); |
| 2369 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2370 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2371 | /// @param source the source information |
| 2372 | /// @param obj the object for the member accessor expression |
| 2373 | /// @param idx the index argument for the member accessor expression |
| 2374 | /// @returns a `ast::MemberAccessorExpression` that indexes `obj` with `idx` |
| 2375 | template <typename OBJ, typename IDX> |
| 2376 | const ast::MemberAccessorExpression* MemberAccessor(const Source& source, |
| 2377 | OBJ&& obj, |
| 2378 | IDX&& idx) { |
| 2379 | return create<ast::MemberAccessorExpression>(source, Expr(std::forward<OBJ>(obj)), |
| 2380 | Expr(std::forward<IDX>(idx))); |
| 2381 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2382 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2383 | /// @param obj the object for the member accessor expression |
| 2384 | /// @param idx the index argument for the member accessor expression |
| 2385 | /// @returns a `ast::MemberAccessorExpression` that indexes `obj` with `idx` |
| 2386 | template <typename OBJ, typename IDX> |
| 2387 | const ast::MemberAccessorExpression* MemberAccessor(OBJ&& obj, IDX&& idx) { |
| 2388 | return create<ast::MemberAccessorExpression>(Expr(std::forward<OBJ>(obj)), |
| 2389 | Expr(std::forward<IDX>(idx))); |
| 2390 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2391 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2392 | /// Creates a ast::StructMemberOffsetAttribute |
dan sinclair | 93df967 | 2022-09-09 14:49:09 +0000 | [diff] [blame] | 2393 | /// @param val the offset expression |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2394 | /// @returns the offset attribute pointer |
dan sinclair | 93df967 | 2022-09-09 14:49:09 +0000 | [diff] [blame] | 2395 | template <typename EXPR> |
| 2396 | const ast::StructMemberOffsetAttribute* MemberOffset(EXPR&& val) { |
| 2397 | return create<ast::StructMemberOffsetAttribute>(source_, Expr(std::forward<EXPR>(val))); |
| 2398 | } |
| 2399 | |
| 2400 | /// Creates a ast::StructMemberOffsetAttribute |
| 2401 | /// @param source the source information |
| 2402 | /// @param val the offset expression |
| 2403 | /// @returns the offset attribute pointer |
| 2404 | template <typename EXPR> |
| 2405 | const ast::StructMemberOffsetAttribute* MemberOffset(const Source& source, EXPR&& val) { |
| 2406 | return create<ast::StructMemberOffsetAttribute>(source, Expr(std::forward<EXPR>(val))); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2407 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2408 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2409 | /// Creates a ast::StructMemberSizeAttribute |
| 2410 | /// @param source the source information |
| 2411 | /// @param val the size value |
| 2412 | /// @returns the size attribute pointer |
dan sinclair | 93df967 | 2022-09-09 14:49:09 +0000 | [diff] [blame] | 2413 | template <typename EXPR> |
| 2414 | const ast::StructMemberSizeAttribute* MemberSize(const Source& source, EXPR&& val) { |
| 2415 | return create<ast::StructMemberSizeAttribute>(source, Expr(std::forward<EXPR>(val))); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2416 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2417 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2418 | /// Creates a ast::StructMemberSizeAttribute |
| 2419 | /// @param val the size value |
| 2420 | /// @returns the size attribute pointer |
dan sinclair | 93df967 | 2022-09-09 14:49:09 +0000 | [diff] [blame] | 2421 | template <typename EXPR> |
| 2422 | const ast::StructMemberSizeAttribute* MemberSize(EXPR&& val) { |
| 2423 | return create<ast::StructMemberSizeAttribute>(source_, Expr(std::forward<EXPR>(val))); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2424 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2425 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2426 | /// Creates a ast::StructMemberAlignAttribute |
| 2427 | /// @param source the source information |
dan sinclair | 4964d9b | 2022-08-23 13:28:44 +0000 | [diff] [blame] | 2428 | /// @param val the align value expression |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2429 | /// @returns the align attribute pointer |
dan sinclair | 4964d9b | 2022-08-23 13:28:44 +0000 | [diff] [blame] | 2430 | template <typename EXPR> |
| 2431 | const ast::StructMemberAlignAttribute* MemberAlign(const Source& source, EXPR&& val) { |
| 2432 | return create<ast::StructMemberAlignAttribute>(source, Expr(std::forward<EXPR>(val))); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2433 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2434 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2435 | /// Creates a ast::StructMemberAlignAttribute |
dan sinclair | 4964d9b | 2022-08-23 13:28:44 +0000 | [diff] [blame] | 2436 | /// @param val the align value expression |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2437 | /// @returns the align attribute pointer |
dan sinclair | 4964d9b | 2022-08-23 13:28:44 +0000 | [diff] [blame] | 2438 | template <typename EXPR> |
| 2439 | const ast::StructMemberAlignAttribute* MemberAlign(EXPR&& val) { |
| 2440 | return create<ast::StructMemberAlignAttribute>(source_, Expr(std::forward<EXPR>(val))); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2441 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2442 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2443 | /// Creates the ast::GroupAttribute |
dan sinclair | be4c9f4 | 2022-08-29 21:22:31 +0000 | [diff] [blame] | 2444 | /// @param value group attribute index expresion |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2445 | /// @returns the group attribute pointer |
dan sinclair | be4c9f4 | 2022-08-29 21:22:31 +0000 | [diff] [blame] | 2446 | template <typename EXPR> |
| 2447 | const ast::GroupAttribute* Group(EXPR&& value) { |
| 2448 | return create<ast::GroupAttribute>(Expr(std::forward<EXPR>(value))); |
| 2449 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2450 | |
dan sinclair | f9b831c | 2022-08-29 21:13:00 +0000 | [diff] [blame] | 2451 | /// Creates the ast::GroupAttribute |
| 2452 | /// @param source the source |
dan sinclair | be4c9f4 | 2022-08-29 21:22:31 +0000 | [diff] [blame] | 2453 | /// @param value group attribute index expression |
dan sinclair | f9b831c | 2022-08-29 21:13:00 +0000 | [diff] [blame] | 2454 | /// @returns the group attribute pointer |
dan sinclair | be4c9f4 | 2022-08-29 21:22:31 +0000 | [diff] [blame] | 2455 | template <typename EXPR> |
| 2456 | const ast::GroupAttribute* Group(const Source& source, EXPR&& value) { |
| 2457 | return create<ast::GroupAttribute>(source, Expr(std::forward<EXPR>(value))); |
dan sinclair | f9b831c | 2022-08-29 21:13:00 +0000 | [diff] [blame] | 2458 | } |
| 2459 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2460 | /// Creates the ast::BindingAttribute |
dan sinclair | f9b831c | 2022-08-29 21:13:00 +0000 | [diff] [blame] | 2461 | /// @param value the binding index expression |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2462 | /// @returns the binding deocration pointer |
dan sinclair | f9b831c | 2022-08-29 21:13:00 +0000 | [diff] [blame] | 2463 | template <typename EXPR> |
| 2464 | const ast::BindingAttribute* Binding(EXPR&& value) { |
| 2465 | return create<ast::BindingAttribute>(Expr(std::forward<EXPR>(value))); |
| 2466 | } |
| 2467 | |
| 2468 | /// Creates the ast::BindingAttribute |
| 2469 | /// @param source the source |
| 2470 | /// @param value the binding index expression |
| 2471 | /// @returns the binding deocration pointer |
| 2472 | template <typename EXPR> |
| 2473 | const ast::BindingAttribute* Binding(const Source& source, EXPR&& value) { |
| 2474 | return create<ast::BindingAttribute>(source, Expr(std::forward<EXPR>(value))); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2475 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2476 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2477 | /// Creates an ast::Function and registers it with the ast::Module. |
| 2478 | /// @param source the source information |
| 2479 | /// @param name the function name |
| 2480 | /// @param params the function parameters |
| 2481 | /// @param type the function return type |
| 2482 | /// @param body the function body |
| 2483 | /// @param attributes the optional function attributes |
| 2484 | /// @param return_type_attributes the optional function return type |
| 2485 | /// attributes |
| 2486 | /// @returns the function pointer |
| 2487 | template <typename NAME> |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2488 | const ast::Function* Func( |
| 2489 | const Source& source, |
| 2490 | NAME&& name, |
| 2491 | utils::VectorRef<const ast::Parameter*> params, |
| 2492 | const ast::Type* type, |
| 2493 | utils::VectorRef<const ast::Statement*> body, |
| 2494 | utils::VectorRef<const ast::Attribute*> attributes = utils::Empty, |
| 2495 | utils::VectorRef<const ast::Attribute*> return_type_attributes = utils::Empty) { |
| 2496 | auto* func = |
| 2497 | create<ast::Function>(source, Sym(std::forward<NAME>(name)), std::move(params), type, |
| 2498 | create<ast::BlockStatement>(std::move(body)), |
| 2499 | std::move(attributes), std::move(return_type_attributes)); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2500 | AST().AddFunction(func); |
| 2501 | return func; |
| 2502 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2503 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2504 | /// Creates an ast::Function and registers it with the ast::Module. |
| 2505 | /// @param name the function name |
| 2506 | /// @param params the function parameters |
| 2507 | /// @param type the function return type |
| 2508 | /// @param body the function body |
| 2509 | /// @param attributes the optional function attributes |
| 2510 | /// @param return_type_attributes the optional function return type |
| 2511 | /// attributes |
| 2512 | /// @returns the function pointer |
| 2513 | template <typename NAME> |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2514 | const ast::Function* Func( |
| 2515 | NAME&& name, |
| 2516 | utils::VectorRef<const ast::Parameter*> params, |
| 2517 | const ast::Type* type, |
| 2518 | utils::VectorRef<const ast::Statement*> body, |
| 2519 | utils::VectorRef<const ast::Attribute*> attributes = utils::Empty, |
| 2520 | utils::VectorRef<const ast::Attribute*> return_type_attributes = utils::Empty) { |
| 2521 | auto* func = |
| 2522 | create<ast::Function>(Sym(std::forward<NAME>(name)), std::move(params), type, |
| 2523 | create<ast::BlockStatement>(std::move(body)), |
| 2524 | std::move(attributes), std::move(return_type_attributes)); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2525 | AST().AddFunction(func); |
| 2526 | return func; |
| 2527 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2528 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2529 | /// Creates an ast::BreakStatement |
| 2530 | /// @param source the source information |
| 2531 | /// @returns the break statement pointer |
| 2532 | const ast::BreakStatement* Break(const Source& source) { |
| 2533 | return create<ast::BreakStatement>(source); |
| 2534 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2535 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2536 | /// Creates an ast::BreakStatement |
| 2537 | /// @returns the break statement pointer |
| 2538 | const ast::BreakStatement* Break() { return create<ast::BreakStatement>(); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2539 | |
dan sinclair | b8b0c21 | 2022-10-20 22:45:50 +0000 | [diff] [blame] | 2540 | /// Creates a ast::BreakIfStatement with input condition |
| 2541 | /// @param source the source information for the if statement |
| 2542 | /// @param condition the if statement condition expression |
| 2543 | /// @returns the break-if statement pointer |
| 2544 | template <typename CONDITION> |
| 2545 | const ast::BreakIfStatement* BreakIf(const Source& source, CONDITION&& condition) { |
| 2546 | return create<ast::BreakIfStatement>(source, Expr(std::forward<CONDITION>(condition))); |
| 2547 | } |
| 2548 | |
| 2549 | /// Creates a ast::BreakIfStatement with input condition |
| 2550 | /// @param condition the if statement condition expression |
| 2551 | /// @returns the break-if statement pointer |
| 2552 | template <typename CONDITION> |
| 2553 | const ast::BreakIfStatement* BreakIf(CONDITION&& condition) { |
| 2554 | return create<ast::BreakIfStatement>(Expr(std::forward<CONDITION>(condition))); |
| 2555 | } |
| 2556 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2557 | /// Creates an ast::ContinueStatement |
| 2558 | /// @param source the source information |
| 2559 | /// @returns the continue statement pointer |
| 2560 | const ast::ContinueStatement* Continue(const Source& source) { |
| 2561 | return create<ast::ContinueStatement>(source); |
| 2562 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2563 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2564 | /// Creates an ast::ContinueStatement |
| 2565 | /// @returns the continue statement pointer |
| 2566 | const ast::ContinueStatement* Continue() { return create<ast::ContinueStatement>(); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2567 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2568 | /// Creates an ast::ReturnStatement with no return value |
| 2569 | /// @param source the source information |
| 2570 | /// @returns the return statement pointer |
| 2571 | const ast::ReturnStatement* Return(const Source& source) { |
| 2572 | return create<ast::ReturnStatement>(source); |
| 2573 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2574 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2575 | /// Creates an ast::ReturnStatement with no return value |
| 2576 | /// @returns the return statement pointer |
| 2577 | const ast::ReturnStatement* Return() { return create<ast::ReturnStatement>(); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2578 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2579 | /// Creates an ast::ReturnStatement with the given return value |
| 2580 | /// @param source the source information |
| 2581 | /// @param val the return value |
| 2582 | /// @returns the return statement pointer |
| 2583 | template <typename EXPR> |
| 2584 | const ast::ReturnStatement* Return(const Source& source, EXPR&& val) { |
| 2585 | return create<ast::ReturnStatement>(source, Expr(std::forward<EXPR>(val))); |
| 2586 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2587 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2588 | /// Creates an ast::ReturnStatement with the given return value |
| 2589 | /// @param val the return value |
| 2590 | /// @returns the return statement pointer |
| 2591 | template <typename EXPR, typename = DisableIfSource<EXPR>> |
| 2592 | const ast::ReturnStatement* Return(EXPR&& val) { |
| 2593 | return create<ast::ReturnStatement>(Expr(std::forward<EXPR>(val))); |
| 2594 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2595 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2596 | /// Creates an ast::DiscardStatement |
| 2597 | /// @param source the source information |
| 2598 | /// @returns the discard statement pointer |
| 2599 | const ast::DiscardStatement* Discard(const Source& source) { |
| 2600 | return create<ast::DiscardStatement>(source); |
| 2601 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2602 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2603 | /// Creates an ast::DiscardStatement |
| 2604 | /// @returns the discard statement pointer |
| 2605 | const ast::DiscardStatement* Discard() { return create<ast::DiscardStatement>(); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2606 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2607 | /// Creates a ast::Alias registering it with the AST().TypeDecls(). |
| 2608 | /// @param source the source information |
| 2609 | /// @param name the alias name |
| 2610 | /// @param type the alias target type |
| 2611 | /// @returns the alias type |
| 2612 | template <typename NAME> |
| 2613 | const ast::Alias* Alias(const Source& source, NAME&& name, const ast::Type* type) { |
| 2614 | auto* out = ty.alias(source, std::forward<NAME>(name), type); |
| 2615 | AST().AddTypeDecl(out); |
| 2616 | return out; |
| 2617 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2618 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2619 | /// Creates a ast::Alias registering it with the AST().TypeDecls(). |
| 2620 | /// @param name the alias name |
| 2621 | /// @param type the alias target type |
| 2622 | /// @returns the alias type |
| 2623 | template <typename NAME> |
| 2624 | const ast::Alias* Alias(NAME&& name, const ast::Type* type) { |
| 2625 | auto* out = ty.alias(std::forward<NAME>(name), type); |
| 2626 | AST().AddTypeDecl(out); |
| 2627 | return out; |
| 2628 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2629 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2630 | /// Creates a ast::Struct registering it with the AST().TypeDecls(). |
| 2631 | /// @param source the source information |
| 2632 | /// @param name the struct name |
| 2633 | /// @param members the struct members |
| 2634 | /// @returns the struct type |
| 2635 | template <typename NAME> |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2636 | const ast::Struct* Structure(const Source& source, |
| 2637 | NAME&& name, |
| 2638 | utils::VectorRef<const ast::StructMember*> members) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2639 | auto sym = Sym(std::forward<NAME>(name)); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2640 | auto* type = create<ast::Struct>(source, sym, std::move(members), utils::Empty); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2641 | AST().AddTypeDecl(type); |
| 2642 | return type; |
| 2643 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2644 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2645 | /// Creates a ast::Struct registering it with the AST().TypeDecls(). |
| 2646 | /// @param name the struct name |
| 2647 | /// @param members the struct members |
| 2648 | /// @returns the struct type |
| 2649 | template <typename NAME> |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2650 | const ast::Struct* Structure(NAME&& name, utils::VectorRef<const ast::StructMember*> members) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2651 | auto sym = Sym(std::forward<NAME>(name)); |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2652 | auto* type = create<ast::Struct>(sym, std::move(members), utils::Empty); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2653 | AST().AddTypeDecl(type); |
| 2654 | return type; |
| 2655 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2656 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2657 | /// Creates a ast::StructMember |
| 2658 | /// @param source the source information |
| 2659 | /// @param name the struct member name |
| 2660 | /// @param type the struct member type |
| 2661 | /// @param attributes the optional struct member attributes |
| 2662 | /// @returns the struct member pointer |
| 2663 | template <typename NAME> |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2664 | const ast::StructMember* Member( |
| 2665 | const Source& source, |
| 2666 | NAME&& name, |
| 2667 | const ast::Type* type, |
| 2668 | utils::VectorRef<const ast::Attribute*> attributes = utils::Empty) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2669 | return create<ast::StructMember>(source, Sym(std::forward<NAME>(name)), type, |
| 2670 | std::move(attributes)); |
| 2671 | } |
| 2672 | |
| 2673 | /// Creates a ast::StructMember |
| 2674 | /// @param name the struct member name |
| 2675 | /// @param type the struct member type |
| 2676 | /// @param attributes the optional struct member attributes |
| 2677 | /// @returns the struct member pointer |
| 2678 | template <typename NAME> |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2679 | const ast::StructMember* Member( |
| 2680 | NAME&& name, |
| 2681 | const ast::Type* type, |
| 2682 | utils::VectorRef<const ast::Attribute*> attributes = utils::Empty) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2683 | return create<ast::StructMember>(source_, Sym(std::forward<NAME>(name)), type, |
| 2684 | std::move(attributes)); |
| 2685 | } |
| 2686 | |
| 2687 | /// Creates a ast::StructMember with the given byte offset |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2688 | /// @param offset the offset to use in the StructMemberOffsetAttribute |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2689 | /// @param name the struct member name |
| 2690 | /// @param type the struct member type |
| 2691 | /// @returns the struct member pointer |
| 2692 | template <typename NAME> |
| 2693 | const ast::StructMember* Member(uint32_t offset, NAME&& name, const ast::Type* type) { |
| 2694 | return create<ast::StructMember>(source_, Sym(std::forward<NAME>(name)), type, |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2695 | utils::Vector<const ast::Attribute*, 1>{ |
dan sinclair | 93df967 | 2022-09-09 14:49:09 +0000 | [diff] [blame] | 2696 | MemberOffset(AInt(offset)), |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2697 | }); |
| 2698 | } |
| 2699 | |
| 2700 | /// Creates a ast::BlockStatement with input statements |
| 2701 | /// @param source the source information for the block |
| 2702 | /// @param statements statements of block |
| 2703 | /// @returns the block statement pointer |
| 2704 | template <typename... Statements> |
| 2705 | const ast::BlockStatement* Block(const Source& source, Statements&&... statements) { |
| 2706 | return create<ast::BlockStatement>( |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2707 | source, utils::Vector<const ast::Statement*, sizeof...(statements)>{ |
| 2708 | std::forward<Statements>(statements)..., |
| 2709 | }); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2710 | } |
| 2711 | |
| 2712 | /// Creates a ast::BlockStatement with input statements |
| 2713 | /// @param statements statements of block |
| 2714 | /// @returns the block statement pointer |
| 2715 | template <typename... STATEMENTS, typename = DisableIfSource<STATEMENTS...>> |
| 2716 | const ast::BlockStatement* Block(STATEMENTS&&... statements) { |
| 2717 | return create<ast::BlockStatement>( |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2718 | utils::Vector<const ast::Statement*, sizeof...(statements)>{ |
| 2719 | std::forward<STATEMENTS>(statements)..., |
| 2720 | }); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
James Price | 8aff0ed | 2022-05-02 14:53:36 +0000 | [diff] [blame] | 2723 | /// A wrapper type for the Else statement used to create If statements. |
| 2724 | struct ElseStmt { |
| 2725 | /// Default constructor - no else statement. |
| 2726 | ElseStmt() : stmt(nullptr) {} |
| 2727 | /// Constructor |
| 2728 | /// @param s The else statement |
| 2729 | explicit ElseStmt(const ast::Statement* s) : stmt(s) {} |
| 2730 | /// The else statement, or nullptr. |
| 2731 | const ast::Statement* stmt; |
| 2732 | }; |
| 2733 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2734 | /// Creates a ast::IfStatement with input condition, body, and optional |
| 2735 | /// else statement |
| 2736 | /// @param source the source information for the if statement |
| 2737 | /// @param condition the if statement condition expression |
| 2738 | /// @param body the if statement body |
| 2739 | /// @param else_stmt optional else statement |
| 2740 | /// @returns the if statement pointer |
| 2741 | template <typename CONDITION> |
| 2742 | const ast::IfStatement* If(const Source& source, |
| 2743 | CONDITION&& condition, |
| 2744 | const ast::BlockStatement* body, |
James Price | 8aff0ed | 2022-05-02 14:53:36 +0000 | [diff] [blame] | 2745 | const ElseStmt else_stmt = ElseStmt()) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2746 | return create<ast::IfStatement>(source, Expr(std::forward<CONDITION>(condition)), body, |
James Price | 8aff0ed | 2022-05-02 14:53:36 +0000 | [diff] [blame] | 2747 | else_stmt.stmt); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | /// Creates a ast::IfStatement with input condition, body, and optional |
| 2751 | /// else statement |
| 2752 | /// @param condition the if statement condition expression |
| 2753 | /// @param body the if statement body |
| 2754 | /// @param else_stmt optional else statement |
| 2755 | /// @returns the if statement pointer |
| 2756 | template <typename CONDITION> |
| 2757 | const ast::IfStatement* If(CONDITION&& condition, |
| 2758 | const ast::BlockStatement* body, |
James Price | 8aff0ed | 2022-05-02 14:53:36 +0000 | [diff] [blame] | 2759 | const ElseStmt else_stmt = ElseStmt()) { |
| 2760 | return create<ast::IfStatement>(Expr(std::forward<CONDITION>(condition)), body, |
| 2761 | else_stmt.stmt); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2762 | } |
| 2763 | |
James Price | 8aff0ed | 2022-05-02 14:53:36 +0000 | [diff] [blame] | 2764 | /// Creates an Else object. |
| 2765 | /// @param stmt else statement |
| 2766 | /// @returns the Else object |
| 2767 | ElseStmt Else(const ast::Statement* stmt) { return ElseStmt(stmt); } |
| 2768 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2769 | /// Creates a ast::AssignmentStatement with input lhs and rhs expressions |
| 2770 | /// @param source the source information |
| 2771 | /// @param lhs the left hand side expression initializer |
| 2772 | /// @param rhs the right hand side expression initializer |
| 2773 | /// @returns the assignment statement pointer |
| 2774 | template <typename LhsExpressionInit, typename RhsExpressionInit> |
| 2775 | const ast::AssignmentStatement* Assign(const Source& source, |
| 2776 | LhsExpressionInit&& lhs, |
| 2777 | RhsExpressionInit&& rhs) { |
| 2778 | return create<ast::AssignmentStatement>(source, Expr(std::forward<LhsExpressionInit>(lhs)), |
| 2779 | Expr(std::forward<RhsExpressionInit>(rhs))); |
| 2780 | } |
| 2781 | |
| 2782 | /// Creates a ast::AssignmentStatement with input lhs and rhs expressions |
| 2783 | /// @param lhs the left hand side expression initializer |
| 2784 | /// @param rhs the right hand side expression initializer |
| 2785 | /// @returns the assignment statement pointer |
| 2786 | template <typename LhsExpressionInit, typename RhsExpressionInit> |
| 2787 | const ast::AssignmentStatement* Assign(LhsExpressionInit&& lhs, RhsExpressionInit&& rhs) { |
| 2788 | return create<ast::AssignmentStatement>(Expr(std::forward<LhsExpressionInit>(lhs)), |
| 2789 | Expr(std::forward<RhsExpressionInit>(rhs))); |
| 2790 | } |
| 2791 | |
| 2792 | /// Creates a ast::CompoundAssignmentStatement with input lhs and rhs |
| 2793 | /// expressions, and a binary operator. |
| 2794 | /// @param source the source information |
| 2795 | /// @param lhs the left hand side expression initializer |
| 2796 | /// @param rhs the right hand side expression initializer |
| 2797 | /// @param op the binary operator |
| 2798 | /// @returns the compound assignment statement pointer |
| 2799 | template <typename LhsExpressionInit, typename RhsExpressionInit> |
| 2800 | const ast::CompoundAssignmentStatement* CompoundAssign(const Source& source, |
| 2801 | LhsExpressionInit&& lhs, |
| 2802 | RhsExpressionInit&& rhs, |
| 2803 | ast::BinaryOp op) { |
| 2804 | return create<ast::CompoundAssignmentStatement>( |
| 2805 | source, Expr(std::forward<LhsExpressionInit>(lhs)), |
| 2806 | Expr(std::forward<RhsExpressionInit>(rhs)), op); |
| 2807 | } |
| 2808 | |
| 2809 | /// Creates a ast::CompoundAssignmentStatement with input lhs and rhs |
| 2810 | /// expressions, and a binary operator. |
| 2811 | /// @param lhs the left hand side expression initializer |
| 2812 | /// @param rhs the right hand side expression initializer |
| 2813 | /// @param op the binary operator |
| 2814 | /// @returns the compound assignment statement pointer |
| 2815 | template <typename LhsExpressionInit, typename RhsExpressionInit> |
| 2816 | const ast::CompoundAssignmentStatement* CompoundAssign(LhsExpressionInit&& lhs, |
| 2817 | RhsExpressionInit&& rhs, |
| 2818 | ast::BinaryOp op) { |
| 2819 | return create<ast::CompoundAssignmentStatement>(Expr(std::forward<LhsExpressionInit>(lhs)), |
| 2820 | Expr(std::forward<RhsExpressionInit>(rhs)), |
| 2821 | op); |
| 2822 | } |
| 2823 | |
| 2824 | /// Creates an ast::IncrementDecrementStatement with input lhs. |
| 2825 | /// @param source the source information |
| 2826 | /// @param lhs the left hand side expression initializer |
| 2827 | /// @returns the increment decrement statement pointer |
| 2828 | template <typename LhsExpressionInit> |
| 2829 | const ast::IncrementDecrementStatement* Increment(const Source& source, |
| 2830 | LhsExpressionInit&& lhs) { |
| 2831 | return create<ast::IncrementDecrementStatement>( |
| 2832 | source, Expr(std::forward<LhsExpressionInit>(lhs)), true); |
| 2833 | } |
| 2834 | |
| 2835 | /// Creates a ast::IncrementDecrementStatement with input lhs. |
| 2836 | /// @param lhs the left hand side expression initializer |
| 2837 | /// @returns the increment decrement statement pointer |
| 2838 | template <typename LhsExpressionInit> |
| 2839 | const ast::IncrementDecrementStatement* Increment(LhsExpressionInit&& lhs) { |
| 2840 | return create<ast::IncrementDecrementStatement>(Expr(std::forward<LhsExpressionInit>(lhs)), |
| 2841 | true); |
| 2842 | } |
| 2843 | |
| 2844 | /// Creates an ast::IncrementDecrementStatement with input lhs. |
| 2845 | /// @param source the source information |
| 2846 | /// @param lhs the left hand side expression initializer |
| 2847 | /// @returns the increment decrement statement pointer |
| 2848 | template <typename LhsExpressionInit> |
| 2849 | const ast::IncrementDecrementStatement* Decrement(const Source& source, |
| 2850 | LhsExpressionInit&& lhs) { |
| 2851 | return create<ast::IncrementDecrementStatement>( |
| 2852 | source, Expr(std::forward<LhsExpressionInit>(lhs)), false); |
| 2853 | } |
| 2854 | |
| 2855 | /// Creates a ast::IncrementDecrementStatement with input lhs. |
| 2856 | /// @param lhs the left hand side expression initializer |
| 2857 | /// @returns the increment decrement statement pointer |
| 2858 | template <typename LhsExpressionInit> |
| 2859 | const ast::IncrementDecrementStatement* Decrement(LhsExpressionInit&& lhs) { |
| 2860 | return create<ast::IncrementDecrementStatement>(Expr(std::forward<LhsExpressionInit>(lhs)), |
| 2861 | false); |
| 2862 | } |
| 2863 | |
| 2864 | /// Creates a ast::LoopStatement with input body and optional continuing |
| 2865 | /// @param source the source information |
| 2866 | /// @param body the loop body |
| 2867 | /// @param continuing the optional continuing block |
| 2868 | /// @returns the loop statement pointer |
| 2869 | const ast::LoopStatement* Loop(const Source& source, |
| 2870 | const ast::BlockStatement* body, |
| 2871 | const ast::BlockStatement* continuing = nullptr) { |
| 2872 | return create<ast::LoopStatement>(source, body, continuing); |
| 2873 | } |
| 2874 | |
| 2875 | /// Creates a ast::LoopStatement with input body and optional continuing |
| 2876 | /// @param body the loop body |
| 2877 | /// @param continuing the optional continuing block |
| 2878 | /// @returns the loop statement pointer |
| 2879 | const ast::LoopStatement* Loop(const ast::BlockStatement* body, |
| 2880 | const ast::BlockStatement* continuing = nullptr) { |
| 2881 | return create<ast::LoopStatement>(body, continuing); |
| 2882 | } |
| 2883 | |
| 2884 | /// Creates a ast::ForLoopStatement with input body and optional initializer, |
| 2885 | /// condition and continuing. |
| 2886 | /// @param source the source information |
| 2887 | /// @param init the optional loop initializer |
| 2888 | /// @param cond the optional loop condition |
| 2889 | /// @param cont the optional loop continuing |
| 2890 | /// @param body the loop body |
| 2891 | /// @returns the for loop statement pointer |
| 2892 | template <typename COND> |
| 2893 | const ast::ForLoopStatement* For(const Source& source, |
| 2894 | const ast::Statement* init, |
| 2895 | COND&& cond, |
| 2896 | const ast::Statement* cont, |
| 2897 | const ast::BlockStatement* body) { |
| 2898 | return create<ast::ForLoopStatement>(source, init, Expr(std::forward<COND>(cond)), cont, |
| 2899 | body); |
| 2900 | } |
| 2901 | |
| 2902 | /// Creates a ast::ForLoopStatement with input body and optional initializer, |
| 2903 | /// condition and continuing. |
| 2904 | /// @param init the optional loop initializer |
| 2905 | /// @param cond the optional loop condition |
| 2906 | /// @param cont the optional loop continuing |
| 2907 | /// @param body the loop body |
| 2908 | /// @returns the for loop statement pointer |
| 2909 | template <typename COND> |
| 2910 | const ast::ForLoopStatement* For(const ast::Statement* init, |
| 2911 | COND&& cond, |
| 2912 | const ast::Statement* cont, |
| 2913 | const ast::BlockStatement* body) { |
| 2914 | return create<ast::ForLoopStatement>(init, Expr(std::forward<COND>(cond)), cont, body); |
| 2915 | } |
| 2916 | |
dan sinclair | 49d1a2d | 2022-06-16 12:01:27 +0000 | [diff] [blame] | 2917 | /// Creates a ast::WhileStatement with input body and condition. |
| 2918 | /// @param source the source information |
| 2919 | /// @param cond the loop condition |
| 2920 | /// @param body the loop body |
| 2921 | /// @returns the while statement pointer |
| 2922 | template <typename COND> |
| 2923 | const ast::WhileStatement* While(const Source& source, |
| 2924 | COND&& cond, |
| 2925 | const ast::BlockStatement* body) { |
| 2926 | return create<ast::WhileStatement>(source, Expr(std::forward<COND>(cond)), body); |
| 2927 | } |
| 2928 | |
| 2929 | /// Creates a ast::WhileStatement with given condition and body. |
| 2930 | /// @param cond the condition |
| 2931 | /// @param body the loop body |
| 2932 | /// @returns the while loop statement pointer |
| 2933 | template <typename COND> |
| 2934 | const ast::WhileStatement* While(COND&& cond, const ast::BlockStatement* body) { |
| 2935 | return create<ast::WhileStatement>(Expr(std::forward<COND>(cond)), body); |
| 2936 | } |
| 2937 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2938 | /// Creates a ast::VariableDeclStatement for the input variable |
| 2939 | /// @param source the source information |
| 2940 | /// @param var the variable to wrap in a decl statement |
| 2941 | /// @returns the variable decl statement pointer |
| 2942 | const ast::VariableDeclStatement* Decl(const Source& source, const ast::Variable* var) { |
| 2943 | return create<ast::VariableDeclStatement>(source, var); |
| 2944 | } |
| 2945 | |
| 2946 | /// Creates a ast::VariableDeclStatement for the input variable |
| 2947 | /// @param var the variable to wrap in a decl statement |
| 2948 | /// @returns the variable decl statement pointer |
| 2949 | const ast::VariableDeclStatement* Decl(const ast::Variable* var) { |
| 2950 | return create<ast::VariableDeclStatement>(var); |
| 2951 | } |
| 2952 | |
| 2953 | /// Creates a ast::SwitchStatement with input expression and cases |
| 2954 | /// @param source the source information |
| 2955 | /// @param condition the condition expression initializer |
| 2956 | /// @param cases case statements |
| 2957 | /// @returns the switch statement pointer |
| 2958 | template <typename ExpressionInit, typename... Cases> |
| 2959 | const ast::SwitchStatement* Switch(const Source& source, |
| 2960 | ExpressionInit&& condition, |
| 2961 | Cases&&... cases) { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2962 | return create<ast::SwitchStatement>( |
| 2963 | source, Expr(std::forward<ExpressionInit>(condition)), |
| 2964 | utils::Vector<const ast::CaseStatement*, sizeof...(cases)>{ |
| 2965 | std::forward<Cases>(cases)...}); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | /// Creates a ast::SwitchStatement with input expression and cases |
| 2969 | /// @param condition the condition expression initializer |
| 2970 | /// @param cases case statements |
| 2971 | /// @returns the switch statement pointer |
| 2972 | template <typename ExpressionInit, |
| 2973 | typename... Cases, |
| 2974 | typename = DisableIfSource<ExpressionInit>> |
| 2975 | const ast::SwitchStatement* Switch(ExpressionInit&& condition, Cases&&... cases) { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 2976 | return create<ast::SwitchStatement>( |
| 2977 | Expr(std::forward<ExpressionInit>(condition)), |
| 2978 | utils::Vector<const ast::CaseStatement*, sizeof...(cases)>{ |
| 2979 | std::forward<Cases>(cases)...}); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | /// Creates a ast::CaseStatement with input list of selectors, and body |
| 2983 | /// @param source the source information |
| 2984 | /// @param selectors list of selectors |
| 2985 | /// @param body the case body |
| 2986 | /// @returns the case statement pointer |
| 2987 | const ast::CaseStatement* Case(const Source& source, |
dan sinclair | f148f08 | 2022-10-19 15:55:02 +0000 | [diff] [blame] | 2988 | utils::VectorRef<const ast::CaseSelector*> selectors, |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2989 | const ast::BlockStatement* body = nullptr) { |
| 2990 | return create<ast::CaseStatement>(source, std::move(selectors), body ? body : Block()); |
| 2991 | } |
| 2992 | |
| 2993 | /// Creates a ast::CaseStatement with input list of selectors, and body |
| 2994 | /// @param selectors list of selectors |
| 2995 | /// @param body the case body |
| 2996 | /// @returns the case statement pointer |
dan sinclair | f148f08 | 2022-10-19 15:55:02 +0000 | [diff] [blame] | 2997 | const ast::CaseStatement* Case(utils::VectorRef<const ast::CaseSelector*> selectors, |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 2998 | const ast::BlockStatement* body = nullptr) { |
| 2999 | return create<ast::CaseStatement>(std::move(selectors), body ? body : Block()); |
| 3000 | } |
| 3001 | |
| 3002 | /// Convenient overload that takes a single selector |
| 3003 | /// @param selector a single case selector |
| 3004 | /// @param body the case body |
| 3005 | /// @returns the case statement pointer |
dan sinclair | f148f08 | 2022-10-19 15:55:02 +0000 | [diff] [blame] | 3006 | const ast::CaseStatement* Case(const ast::CaseSelector* selector, |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3007 | const ast::BlockStatement* body = nullptr) { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 3008 | return Case(utils::Vector{selector}, body); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | /// Convenience function that creates a 'default' ast::CaseStatement |
| 3012 | /// @param source the source information |
| 3013 | /// @param body the case body |
| 3014 | /// @returns the case statement pointer |
| 3015 | const ast::CaseStatement* DefaultCase(const Source& source, |
| 3016 | const ast::BlockStatement* body = nullptr) { |
dan sinclair | f148f08 | 2022-10-19 15:55:02 +0000 | [diff] [blame] | 3017 | return Case(source, utils::Vector{DefaultCaseSelector(source)}, body); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | /// Convenience function that creates a 'default' ast::CaseStatement |
| 3021 | /// @param body the case body |
| 3022 | /// @returns the case statement pointer |
| 3023 | const ast::CaseStatement* DefaultCase(const ast::BlockStatement* body = nullptr) { |
dan sinclair | f148f08 | 2022-10-19 15:55:02 +0000 | [diff] [blame] | 3024 | return Case(utils::Vector{DefaultCaseSelector()}, body); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3025 | } |
| 3026 | |
dan sinclair | f148f08 | 2022-10-19 15:55:02 +0000 | [diff] [blame] | 3027 | /// Convenience function that creates a case selector |
| 3028 | /// @param source the source information |
| 3029 | /// @param expr the selector expression |
| 3030 | /// @returns the selector pointer |
| 3031 | template <typename EXPR> |
| 3032 | const ast::CaseSelector* CaseSelector(const Source& source, EXPR&& expr) { |
| 3033 | return create<ast::CaseSelector>(source, Expr(std::forward<EXPR>(expr))); |
| 3034 | } |
| 3035 | |
| 3036 | /// Convenience function that creates a case selector |
| 3037 | /// @param expr the selector expression |
| 3038 | /// @returns the selector pointer |
| 3039 | template <typename EXPR> |
| 3040 | const ast::CaseSelector* CaseSelector(EXPR&& expr) { |
| 3041 | return create<ast::CaseSelector>(source_, Expr(std::forward<EXPR>(expr))); |
| 3042 | } |
| 3043 | |
| 3044 | /// Convenience function that creates a default case selector |
| 3045 | /// @param source the source information |
| 3046 | /// @returns the selector pointer |
| 3047 | const ast::CaseSelector* DefaultCaseSelector(const Source& source) { |
| 3048 | return create<ast::CaseSelector>(source, nullptr); |
| 3049 | } |
| 3050 | |
| 3051 | /// Convenience function that creates a default case selector |
| 3052 | /// @returns the selector pointer |
| 3053 | const ast::CaseSelector* DefaultCaseSelector() { return create<ast::CaseSelector>(nullptr); } |
| 3054 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3055 | /// Creates an ast::BuiltinAttribute |
| 3056 | /// @param source the source information |
| 3057 | /// @param builtin the builtin value |
| 3058 | /// @returns the builtin attribute pointer |
Ben Clayton | f330229 | 2022-07-27 18:48:06 +0000 | [diff] [blame] | 3059 | const ast::BuiltinAttribute* Builtin(const Source& source, ast::BuiltinValue builtin) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3060 | return create<ast::BuiltinAttribute>(source, builtin); |
| 3061 | } |
| 3062 | |
| 3063 | /// Creates an ast::BuiltinAttribute |
| 3064 | /// @param builtin the builtin value |
| 3065 | /// @returns the builtin attribute pointer |
Ben Clayton | f330229 | 2022-07-27 18:48:06 +0000 | [diff] [blame] | 3066 | const ast::BuiltinAttribute* Builtin(ast::BuiltinValue builtin) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3067 | return create<ast::BuiltinAttribute>(source_, builtin); |
| 3068 | } |
| 3069 | |
| 3070 | /// Creates an ast::InterpolateAttribute |
| 3071 | /// @param source the source information |
| 3072 | /// @param type the interpolation type |
| 3073 | /// @param sampling the interpolation sampling |
| 3074 | /// @returns the interpolate attribute pointer |
| 3075 | const ast::InterpolateAttribute* Interpolate( |
| 3076 | const Source& source, |
| 3077 | ast::InterpolationType type, |
Ben Clayton | d2e0db3 | 2022-10-12 18:49:15 +0000 | [diff] [blame] | 3078 | ast::InterpolationSampling sampling = ast::InterpolationSampling::kUndefined) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3079 | return create<ast::InterpolateAttribute>(source, type, sampling); |
| 3080 | } |
| 3081 | |
| 3082 | /// Creates an ast::InterpolateAttribute |
| 3083 | /// @param type the interpolation type |
| 3084 | /// @param sampling the interpolation sampling |
| 3085 | /// @returns the interpolate attribute pointer |
| 3086 | const ast::InterpolateAttribute* Interpolate( |
| 3087 | ast::InterpolationType type, |
Ben Clayton | d2e0db3 | 2022-10-12 18:49:15 +0000 | [diff] [blame] | 3088 | ast::InterpolationSampling sampling = ast::InterpolationSampling::kUndefined) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3089 | return create<ast::InterpolateAttribute>(source_, type, sampling); |
| 3090 | } |
| 3091 | |
| 3092 | /// Creates an ast::InterpolateAttribute using flat interpolation |
| 3093 | /// @param source the source information |
| 3094 | /// @returns the interpolate attribute pointer |
| 3095 | const ast::InterpolateAttribute* Flat(const Source& source) { |
| 3096 | return Interpolate(source, ast::InterpolationType::kFlat); |
| 3097 | } |
| 3098 | |
| 3099 | /// Creates an ast::InterpolateAttribute using flat interpolation |
| 3100 | /// @returns the interpolate attribute pointer |
| 3101 | const ast::InterpolateAttribute* Flat() { return Interpolate(ast::InterpolationType::kFlat); } |
| 3102 | |
| 3103 | /// Creates an ast::InvariantAttribute |
| 3104 | /// @param source the source information |
| 3105 | /// @returns the invariant attribute pointer |
| 3106 | const ast::InvariantAttribute* Invariant(const Source& source) { |
| 3107 | return create<ast::InvariantAttribute>(source); |
| 3108 | } |
| 3109 | |
| 3110 | /// Creates an ast::InvariantAttribute |
| 3111 | /// @returns the invariant attribute pointer |
| 3112 | const ast::InvariantAttribute* Invariant() { return create<ast::InvariantAttribute>(source_); } |
| 3113 | |
| 3114 | /// Creates an ast::LocationAttribute |
| 3115 | /// @param source the source information |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 3116 | /// @param location the location value expression |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3117 | /// @returns the location attribute pointer |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 3118 | template <typename EXPR> |
| 3119 | const ast::LocationAttribute* Location(const Source& source, EXPR&& location) { |
| 3120 | return create<ast::LocationAttribute>(source, Expr(std::forward<EXPR>(location))); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | /// Creates an ast::LocationAttribute |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 3124 | /// @param location the location value expression |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3125 | /// @returns the location attribute pointer |
dan sinclair | f9eeed6 | 2022-09-07 22:25:24 +0000 | [diff] [blame] | 3126 | template <typename EXPR> |
| 3127 | const ast::LocationAttribute* Location(EXPR&& location) { |
| 3128 | return create<ast::LocationAttribute>(source_, Expr(std::forward<EXPR>(location))); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | /// Creates an ast::IdAttribute |
| 3132 | /// @param source the source information |
| 3133 | /// @param id the id value |
| 3134 | /// @returns the override attribute pointer |
Ben Clayton | 9a6acc4 | 2022-07-27 20:50:40 +0000 | [diff] [blame] | 3135 | const ast::IdAttribute* Id(const Source& source, OverrideId id) { |
dan sinclair | 5361d9e | 2022-08-31 13:39:48 +0000 | [diff] [blame] | 3136 | return create<ast::IdAttribute>(source, Expr(AInt(id.value))); |
Ben Clayton | 9a6acc4 | 2022-07-27 20:50:40 +0000 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | /// Creates an ast::IdAttribute with an override identifier |
| 3140 | /// @param id the optional id value |
| 3141 | /// @returns the override attribute pointer |
dan sinclair | 5361d9e | 2022-08-31 13:39:48 +0000 | [diff] [blame] | 3142 | const ast::IdAttribute* Id(OverrideId id) { |
| 3143 | return create<ast::IdAttribute>(Expr(AInt(id.value))); |
| 3144 | } |
Ben Clayton | 9a6acc4 | 2022-07-27 20:50:40 +0000 | [diff] [blame] | 3145 | |
| 3146 | /// Creates an ast::IdAttribute |
| 3147 | /// @param source the source information |
dan sinclair | 5361d9e | 2022-08-31 13:39:48 +0000 | [diff] [blame] | 3148 | /// @param id the id value expression |
Ben Clayton | 9a6acc4 | 2022-07-27 20:50:40 +0000 | [diff] [blame] | 3149 | /// @returns the override attribute pointer |
dan sinclair | 5361d9e | 2022-08-31 13:39:48 +0000 | [diff] [blame] | 3150 | template <typename EXPR> |
| 3151 | const ast::IdAttribute* Id(const Source& source, EXPR&& id) { |
| 3152 | return create<ast::IdAttribute>(source, Expr(std::forward<EXPR>(id))); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
Ben Clayton | 9a6acc4 | 2022-07-27 20:50:40 +0000 | [diff] [blame] | 3155 | /// Creates an ast::IdAttribute with an override identifier |
dan sinclair | 5361d9e | 2022-08-31 13:39:48 +0000 | [diff] [blame] | 3156 | /// @param id the optional id value expression |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3157 | /// @returns the override attribute pointer |
dan sinclair | 5361d9e | 2022-08-31 13:39:48 +0000 | [diff] [blame] | 3158 | template <typename EXPR> |
| 3159 | const ast::IdAttribute* Id(EXPR&& id) { |
| 3160 | return create<ast::IdAttribute>(Expr(std::forward<EXPR>(id))); |
| 3161 | } |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3162 | |
| 3163 | /// Creates an ast::StageAttribute |
| 3164 | /// @param source the source information |
| 3165 | /// @param stage the pipeline stage |
| 3166 | /// @returns the stage attribute pointer |
| 3167 | const ast::StageAttribute* Stage(const Source& source, ast::PipelineStage stage) { |
| 3168 | return create<ast::StageAttribute>(source, stage); |
| 3169 | } |
| 3170 | |
| 3171 | /// Creates an ast::StageAttribute |
| 3172 | /// @param stage the pipeline stage |
| 3173 | /// @returns the stage attribute pointer |
| 3174 | const ast::StageAttribute* Stage(ast::PipelineStage stage) { |
| 3175 | return create<ast::StageAttribute>(source_, stage); |
| 3176 | } |
| 3177 | |
| 3178 | /// Creates an ast::WorkgroupAttribute |
| 3179 | /// @param x the x dimension expression |
| 3180 | /// @returns the workgroup attribute pointer |
| 3181 | template <typename EXPR_X> |
| 3182 | const ast::WorkgroupAttribute* WorkgroupSize(EXPR_X&& x) { |
| 3183 | return WorkgroupSize(std::forward<EXPR_X>(x), nullptr, nullptr); |
| 3184 | } |
| 3185 | |
| 3186 | /// Creates an ast::WorkgroupAttribute |
Ben Clayton | b8ac933 | 2022-05-28 10:34:06 +0000 | [diff] [blame] | 3187 | /// @param source the source information |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3188 | /// @param x the x dimension expression |
dan sinclair | 7517e21 | 2022-08-24 21:31:45 +0000 | [diff] [blame] | 3189 | /// @returns the workgroup attribute pointer |
| 3190 | template <typename EXPR_X> |
| 3191 | const ast::WorkgroupAttribute* WorkgroupSize(const Source& source, EXPR_X&& x) { |
| 3192 | return WorkgroupSize(source, std::forward<EXPR_X>(x), nullptr, nullptr); |
| 3193 | } |
| 3194 | |
| 3195 | /// Creates an ast::WorkgroupAttribute |
| 3196 | /// @param source the source information |
| 3197 | /// @param x the x dimension expression |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3198 | /// @param y the y dimension expression |
| 3199 | /// @returns the workgroup attribute pointer |
| 3200 | template <typename EXPR_X, typename EXPR_Y> |
Ben Clayton | b8ac933 | 2022-05-28 10:34:06 +0000 | [diff] [blame] | 3201 | const ast::WorkgroupAttribute* WorkgroupSize(const Source& source, EXPR_X&& x, EXPR_Y&& y) { |
| 3202 | return WorkgroupSize(source, std::forward<EXPR_X>(x), std::forward<EXPR_Y>(y), nullptr); |
| 3203 | } |
| 3204 | |
| 3205 | /// Creates an ast::WorkgroupAttribute |
| 3206 | /// @param x the x dimension expression |
| 3207 | /// @param y the y dimension expression |
| 3208 | /// @returns the workgroup attribute pointer |
| 3209 | template <typename EXPR_X, typename EXPR_Y, typename = DisableIfSource<EXPR_X>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3210 | const ast::WorkgroupAttribute* WorkgroupSize(EXPR_X&& x, EXPR_Y&& y) { |
| 3211 | return WorkgroupSize(std::forward<EXPR_X>(x), std::forward<EXPR_Y>(y), nullptr); |
| 3212 | } |
| 3213 | |
| 3214 | /// Creates an ast::WorkgroupAttribute |
| 3215 | /// @param source the source information |
| 3216 | /// @param x the x dimension expression |
| 3217 | /// @param y the y dimension expression |
| 3218 | /// @param z the z dimension expression |
| 3219 | /// @returns the workgroup attribute pointer |
| 3220 | template <typename EXPR_X, typename EXPR_Y, typename EXPR_Z> |
| 3221 | const ast::WorkgroupAttribute* WorkgroupSize(const Source& source, |
| 3222 | EXPR_X&& x, |
| 3223 | EXPR_Y&& y, |
| 3224 | EXPR_Z&& z) { |
| 3225 | return create<ast::WorkgroupAttribute>(source, Expr(std::forward<EXPR_X>(x)), |
| 3226 | Expr(std::forward<EXPR_Y>(y)), |
| 3227 | Expr(std::forward<EXPR_Z>(z))); |
| 3228 | } |
| 3229 | |
| 3230 | /// Creates an ast::WorkgroupAttribute |
| 3231 | /// @param x the x dimension expression |
| 3232 | /// @param y the y dimension expression |
| 3233 | /// @param z the z dimension expression |
| 3234 | /// @returns the workgroup attribute pointer |
Ben Clayton | b8ac933 | 2022-05-28 10:34:06 +0000 | [diff] [blame] | 3235 | template <typename EXPR_X, typename EXPR_Y, typename EXPR_Z, typename = DisableIfSource<EXPR_X>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3236 | const ast::WorkgroupAttribute* WorkgroupSize(EXPR_X&& x, EXPR_Y&& y, EXPR_Z&& z) { |
| 3237 | return create<ast::WorkgroupAttribute>(source_, Expr(std::forward<EXPR_X>(x)), |
| 3238 | Expr(std::forward<EXPR_Y>(y)), |
| 3239 | Expr(std::forward<EXPR_Z>(z))); |
| 3240 | } |
| 3241 | |
| 3242 | /// Creates an ast::DisableValidationAttribute |
| 3243 | /// @param validation the validation to disable |
| 3244 | /// @returns the disable validation attribute pointer |
| 3245 | const ast::DisableValidationAttribute* Disable(ast::DisabledValidation validation) { |
Ben Clayton | 4a92a3c | 2022-07-18 20:50:02 +0000 | [diff] [blame] | 3246 | return ASTNodes().Create<ast::DisableValidationAttribute>(ID(), AllocateNodeID(), |
| 3247 | validation); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | /// Sets the current builder source to `src` |
| 3251 | /// @param src the Source used for future create() calls |
| 3252 | void SetSource(const Source& src) { |
| 3253 | AssertNotMoved(); |
| 3254 | source_ = src; |
| 3255 | } |
| 3256 | |
| 3257 | /// Sets the current builder source to `loc` |
| 3258 | /// @param loc the Source used for future create() calls |
| 3259 | void SetSource(const Source::Location& loc) { |
| 3260 | AssertNotMoved(); |
| 3261 | source_ = Source(loc); |
| 3262 | } |
| 3263 | |
| 3264 | /// Helper for returning the resolved semantic type of the expression `expr`. |
| 3265 | /// @note As the Resolver is run when the Program is built, this will only be |
| 3266 | /// useful for the Resolver itself and tests that use their own Resolver. |
| 3267 | /// @param expr the AST expression |
| 3268 | /// @return the resolved semantic type for the expression, or nullptr if the |
| 3269 | /// expression has no resolved type. |
dan sinclair | 5f764d8 | 2022-12-08 00:32:27 +0000 | [diff] [blame] | 3270 | const type::Type* TypeOf(const ast::Expression* expr) const; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3271 | |
| 3272 | /// Helper for returning the resolved semantic type of the variable `var`. |
| 3273 | /// @note As the Resolver is run when the Program is built, this will only be |
| 3274 | /// useful for the Resolver itself and tests that use their own Resolver. |
| 3275 | /// @param var the AST variable |
| 3276 | /// @return the resolved semantic type for the variable, or nullptr if the |
| 3277 | /// variable has no resolved type. |
dan sinclair | 5f764d8 | 2022-12-08 00:32:27 +0000 | [diff] [blame] | 3278 | const type::Type* TypeOf(const ast::Variable* var) const; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3279 | |
| 3280 | /// Helper for returning the resolved semantic type of the AST type `type`. |
| 3281 | /// @note As the Resolver is run when the Program is built, this will only be |
| 3282 | /// useful for the Resolver itself and tests that use their own Resolver. |
| 3283 | /// @param type the AST type |
| 3284 | /// @return the resolved semantic type for the type, or nullptr if the type |
| 3285 | /// has no resolved type. |
dan sinclair | 5f764d8 | 2022-12-08 00:32:27 +0000 | [diff] [blame] | 3286 | const type::Type* TypeOf(const ast::Type* type) const; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3287 | |
| 3288 | /// Helper for returning the resolved semantic type of the AST type |
| 3289 | /// declaration `type_decl`. |
| 3290 | /// @note As the Resolver is run when the Program is built, this will only be |
| 3291 | /// useful for the Resolver itself and tests that use their own Resolver. |
| 3292 | /// @param type_decl the AST type declaration |
| 3293 | /// @return the resolved semantic type for the type declaration, or nullptr if |
| 3294 | /// the type declaration has no resolved type. |
dan sinclair | 5f764d8 | 2022-12-08 00:32:27 +0000 | [diff] [blame] | 3295 | const type::Type* TypeOf(const ast::TypeDecl* type_decl) const; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3296 | |
Ben Clayton | 1b35e3f | 2022-05-19 21:55:29 +0000 | [diff] [blame] | 3297 | /// @param type a type |
| 3298 | /// @returns the name for `type` that closely resembles how it would be |
| 3299 | /// declared in WGSL. |
Ben Clayton | d7d7188 | 2022-09-05 20:51:23 +0000 | [diff] [blame] | 3300 | std::string FriendlyName(const ast::Type* type) const; |
Ben Clayton | 1b35e3f | 2022-05-19 21:55:29 +0000 | [diff] [blame] | 3301 | |
| 3302 | /// @param type a type |
| 3303 | /// @returns the name for `type` that closely resembles how it would be |
| 3304 | /// declared in WGSL. |
dan sinclair | 5f764d8 | 2022-12-08 00:32:27 +0000 | [diff] [blame] | 3305 | std::string FriendlyName(const type::Type* type) const; |
Ben Clayton | 1b35e3f | 2022-05-19 21:55:29 +0000 | [diff] [blame] | 3306 | |
| 3307 | /// Overload of FriendlyName, which removes an ambiguity when passing nullptr. |
| 3308 | /// Simplifies test code. |
| 3309 | /// @returns "<null>" |
Ben Clayton | d7d7188 | 2022-09-05 20:51:23 +0000 | [diff] [blame] | 3310 | std::string FriendlyName(std::nullptr_t) const; |
Ben Clayton | 1b35e3f | 2022-05-19 21:55:29 +0000 | [diff] [blame] | 3311 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3312 | /// Wraps the ast::Expression in a statement. This is used by tests that |
| 3313 | /// construct a partial AST and require the Resolver to reach these |
| 3314 | /// nodes. |
| 3315 | /// @param expr the ast::Expression to be wrapped by an ast::Statement |
| 3316 | /// @return the ast::Statement that wraps the ast::Expression |
| 3317 | const ast::Statement* WrapInStatement(const ast::Expression* expr); |
| 3318 | /// Wraps the ast::Variable in a ast::VariableDeclStatement. This is used by |
| 3319 | /// tests that construct a partial AST and require the Resolver to reach |
| 3320 | /// these nodes. |
| 3321 | /// @param v the ast::Variable to be wrapped by an ast::VariableDeclStatement |
| 3322 | /// @return the ast::VariableDeclStatement that wraps the ast::Variable |
| 3323 | const ast::VariableDeclStatement* WrapInStatement(const ast::Variable* v); |
| 3324 | /// Returns the statement argument. Used as a passthrough-overload by |
| 3325 | /// WrapInFunction(). |
| 3326 | /// @param stmt the ast::Statement |
| 3327 | /// @return `stmt` |
| 3328 | const ast::Statement* WrapInStatement(const ast::Statement* stmt); |
| 3329 | /// Wraps the list of arguments in a simple function so that each is reachable |
| 3330 | /// by the Resolver. |
| 3331 | /// @param args a mix of ast::Expression, ast::Statement, ast::Variables. |
| 3332 | /// @returns the function |
Antonio Maiorano | dfa92a9 | 2022-12-23 17:56:56 +0000 | [diff] [blame^] | 3333 | template <typename... ARGS, |
| 3334 | typename = traits::EnableIf<(CanWrapInStatement<ARGS>::value && ...)>> |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3335 | const ast::Function* WrapInFunction(ARGS&&... args) { |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 3336 | utils::Vector stmts{ |
| 3337 | WrapInStatement(std::forward<ARGS>(args))..., |
| 3338 | }; |
Antonio Maiorano | dfa92a9 | 2022-12-23 17:56:56 +0000 | [diff] [blame^] | 3339 | return WrapInFunction(std::move(stmts)); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3340 | } |
| 3341 | /// @param stmts a list of ast::Statement that will be wrapped by a function, |
| 3342 | /// so that each statement is reachable by the Resolver. |
| 3343 | /// @returns the function |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 3344 | const ast::Function* WrapInFunction(utils::VectorRef<const ast::Statement*> stmts); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3345 | |
| 3346 | /// The builder types |
| 3347 | TypesBuilder const ty{this}; |
| 3348 | |
| 3349 | protected: |
| 3350 | /// Asserts that the builder has not been moved. |
| 3351 | void AssertNotMoved() const; |
| 3352 | |
| 3353 | private: |
| 3354 | ProgramID id_; |
Ben Clayton | 4a92a3c | 2022-07-18 20:50:02 +0000 | [diff] [blame] | 3355 | ast::NodeID last_ast_node_id_ = ast::NodeID{static_cast<decltype(ast::NodeID::value)>(0) - 1}; |
dan sinclair | 837b804 | 2022-12-09 05:00:07 +0000 | [diff] [blame] | 3356 | type::Manager types_; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3357 | ASTNodeAllocator ast_nodes_; |
| 3358 | SemNodeAllocator sem_nodes_; |
Ben Clayton | aa037ac | 2022-06-29 19:07:30 +0000 | [diff] [blame] | 3359 | ConstantAllocator constant_nodes_; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3360 | ast::Module* ast_; |
| 3361 | sem::Info sem_; |
| 3362 | SymbolTable symbols_{id_}; |
| 3363 | diag::List diagnostics_; |
| 3364 | |
| 3365 | /// The source to use when creating AST nodes without providing a Source as |
| 3366 | /// the first argument. |
| 3367 | Source source_; |
| 3368 | |
| 3369 | /// Set by SetResolveOnBuild(). If set, the Resolver will be run on the |
| 3370 | /// program when built. |
| 3371 | bool resolve_on_build_ = true; |
| 3372 | |
| 3373 | /// Set by MarkAsMoved(). Once set, no methods may be called on this builder. |
| 3374 | bool moved_ = false; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 3375 | }; |
| 3376 | |
| 3377 | //! @cond Doxygen_Suppress |
| 3378 | // Various template specializations for ProgramBuilder::TypesBuilder::CToAST. |
| 3379 | template <> |
Ben Clayton | 46ee639 | 2022-11-09 22:04:11 +0000 | [diff] [blame] | 3380 | struct ProgramBuilder::TypesBuilder::CToAST<AInt> { |
| 3381 | static const ast::Type* get(const ProgramBuilder::TypesBuilder*) { return nullptr; } |
| 3382 | }; |
| 3383 | template <> |
| 3384 | struct ProgramBuilder::TypesBuilder::CToAST<AFloat> { |
| 3385 | static const ast::Type* get(const ProgramBuilder::TypesBuilder*) { return nullptr; } |
| 3386 | }; |
| 3387 | template <> |
Ben Clayton | 0ce9ab0 | 2022-05-05 20:23:40 +0000 | [diff] [blame] | 3388 | struct ProgramBuilder::TypesBuilder::CToAST<i32> { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3389 | static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->i32(); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 3390 | }; |
| 3391 | template <> |
Ben Clayton | 0ce9ab0 | 2022-05-05 20:23:40 +0000 | [diff] [blame] | 3392 | struct ProgramBuilder::TypesBuilder::CToAST<u32> { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3393 | static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->u32(); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 3394 | }; |
| 3395 | template <> |
Ben Clayton | 0ce9ab0 | 2022-05-05 20:23:40 +0000 | [diff] [blame] | 3396 | struct ProgramBuilder::TypesBuilder::CToAST<f32> { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3397 | static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->f32(); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 3398 | }; |
| 3399 | template <> |
Zhaoming Jiang | 62bfd31 | 2022-05-13 12:01:11 +0000 | [diff] [blame] | 3400 | struct ProgramBuilder::TypesBuilder::CToAST<f16> { |
| 3401 | static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->f16(); } |
| 3402 | }; |
| 3403 | template <> |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 3404 | struct ProgramBuilder::TypesBuilder::CToAST<bool> { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3405 | static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->bool_(); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 3406 | }; |
| 3407 | template <> |
| 3408 | struct ProgramBuilder::TypesBuilder::CToAST<void> { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3409 | static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->void_(); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 3410 | }; |
| 3411 | //! @endcond |
| 3412 | |
| 3413 | /// @param builder the ProgramBuilder |
| 3414 | /// @returns the ProgramID of the ProgramBuilder |
| 3415 | inline ProgramID ProgramIDOf(const ProgramBuilder* builder) { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 3416 | return builder->ID(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 3417 | } |
| 3418 | |
Antonio Maiorano | dfa92a9 | 2022-12-23 17:56:56 +0000 | [diff] [blame^] | 3419 | // Primary template for metafunction that evaluates to true iff T can be wrapped in a statement. |
| 3420 | template <typename T, typename /* = void */> |
| 3421 | struct CanWrapInStatement : std::false_type {}; |
| 3422 | |
| 3423 | // Specialization of CanWrapInStatement |
| 3424 | template <typename T> |
| 3425 | struct CanWrapInStatement< |
| 3426 | T, |
| 3427 | std::void_t<decltype(std::declval<ProgramBuilder>().WrapInStatement(std::declval<T>()))>> |
| 3428 | : std::true_type {}; |
| 3429 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 3430 | } // namespace tint |
| 3431 | |
| 3432 | #endif // SRC_TINT_PROGRAM_BUILDER_H_ |