Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +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_PROGRAM_BUILDER_H_ |
| 16 | #define SRC_PROGRAM_BUILDER_H_ |
| 17 | |
| 18 | #include <string> |
Ben Clayton | b5cd10c | 2021-06-25 10:26:26 +0000 | [diff] [blame] | 19 | #include <unordered_set> |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 20 | #include <utility> |
| 21 | |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 22 | #include "src/ast/alias.h" |
Ben Clayton | 7241a50 | 2021-04-22 14:32:53 +0000 | [diff] [blame] | 23 | #include "src/ast/array.h" |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 24 | #include "src/ast/array_accessor_expression.h" |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 25 | #include "src/ast/assignment_statement.h" |
Ben Clayton | 8c7f0da | 2021-06-17 15:48:39 +0000 | [diff] [blame] | 26 | #include "src/ast/atomic.h" |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 27 | #include "src/ast/binary_expression.h" |
Ben Clayton | d960328 | 2021-06-29 12:37:45 +0000 | [diff] [blame^] | 28 | #include "src/ast/bitcast_expression.h" |
Ben Clayton | a922e65 | 2021-04-21 13:37:22 +0000 | [diff] [blame] | 29 | #include "src/ast/bool.h" |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 30 | #include "src/ast/bool_literal.h" |
| 31 | #include "src/ast/call_expression.h" |
Ben Clayton | 7fe0106 | 2021-06-11 13:22:27 +0000 | [diff] [blame] | 32 | #include "src/ast/call_statement.h" |
Antonio Maiorano | cea744d | 2021-03-25 12:55:27 +0000 | [diff] [blame] | 33 | #include "src/ast/case_statement.h" |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 34 | #include "src/ast/depth_texture.h" |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 35 | #include "src/ast/external_texture.h" |
Ben Clayton | a922e65 | 2021-04-21 13:37:22 +0000 | [diff] [blame] | 36 | #include "src/ast/f32.h" |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 37 | #include "src/ast/float_literal.h" |
Ben Clayton | a922e65 | 2021-04-21 13:37:22 +0000 | [diff] [blame] | 38 | #include "src/ast/i32.h" |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 39 | #include "src/ast/if_statement.h" |
James Price | 989a8e4 | 2021-06-28 23:04:43 +0000 | [diff] [blame] | 40 | #include "src/ast/interpolate_decoration.h" |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 41 | #include "src/ast/loop_statement.h" |
Ben Clayton | fdb91fd | 2021-04-22 14:30:53 +0000 | [diff] [blame] | 42 | #include "src/ast/matrix.h" |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 43 | #include "src/ast/member_accessor_expression.h" |
| 44 | #include "src/ast/module.h" |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 45 | #include "src/ast/multisampled_texture.h" |
James Price | f2f3bfc | 2021-05-13 20:32:32 +0000 | [diff] [blame] | 46 | #include "src/ast/override_decoration.h" |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 47 | #include "src/ast/pointer.h" |
Antonio Maiorano | 03c01b5 | 2021-03-19 14:04:51 +0000 | [diff] [blame] | 48 | #include "src/ast/return_statement.h" |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 49 | #include "src/ast/sampled_texture.h" |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 50 | #include "src/ast/scalar_constructor_expression.h" |
| 51 | #include "src/ast/sint_literal.h" |
James Price | 68f558f | 2021-04-06 15:51:47 +0000 | [diff] [blame] | 52 | #include "src/ast/stage_decoration.h" |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 53 | #include "src/ast/storage_texture.h" |
Ben Clayton | bab3197 | 2021-02-08 21:16:21 +0000 | [diff] [blame] | 54 | #include "src/ast/stride_decoration.h" |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 55 | #include "src/ast/struct_member_align_decoration.h" |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 56 | #include "src/ast/struct_member_offset_decoration.h" |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 57 | #include "src/ast/struct_member_size_decoration.h" |
Antonio Maiorano | cea744d | 2021-03-25 12:55:27 +0000 | [diff] [blame] | 58 | #include "src/ast/switch_statement.h" |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 59 | #include "src/ast/type_constructor_expression.h" |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 60 | #include "src/ast/type_name.h" |
Ben Clayton | a922e65 | 2021-04-21 13:37:22 +0000 | [diff] [blame] | 61 | #include "src/ast/u32.h" |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 62 | #include "src/ast/uint_literal.h" |
Ben Clayton | fe0910f | 2021-05-17 15:51:47 +0000 | [diff] [blame] | 63 | #include "src/ast/unary_op_expression.h" |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 64 | #include "src/ast/variable_decl_statement.h" |
Ben Clayton | e30ffeb | 2021-04-22 14:24:43 +0000 | [diff] [blame] | 65 | #include "src/ast/vector.h" |
Ben Clayton | a922e65 | 2021-04-21 13:37:22 +0000 | [diff] [blame] | 66 | #include "src/ast/void.h" |
James Price | 70f80bb | 2021-05-19 13:40:08 +0000 | [diff] [blame] | 67 | #include "src/ast/workgroup_decoration.h" |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 68 | #include "src/program.h" |
Ben Clayton | e6995de | 2021-04-13 23:27:27 +0000 | [diff] [blame] | 69 | #include "src/program_id.h" |
Ben Clayton | 4cd5eea | 2021-05-07 20:58:34 +0000 | [diff] [blame] | 70 | #include "src/sem/array.h" |
Antonio Maiorano | aea9c68 | 2021-04-19 22:54:43 +0000 | [diff] [blame] | 71 | #include "src/sem/bool_type.h" |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 72 | #include "src/sem/depth_texture_type.h" |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 73 | #include "src/sem/external_texture_type.h" |
Antonio Maiorano | aea9c68 | 2021-04-19 22:54:43 +0000 | [diff] [blame] | 74 | #include "src/sem/f32_type.h" |
| 75 | #include "src/sem/i32_type.h" |
| 76 | #include "src/sem/matrix_type.h" |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 77 | #include "src/sem/multisampled_texture_type.h" |
Antonio Maiorano | aea9c68 | 2021-04-19 22:54:43 +0000 | [diff] [blame] | 78 | #include "src/sem/pointer_type.h" |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 79 | #include "src/sem/sampled_texture_type.h" |
| 80 | #include "src/sem/storage_texture_type.h" |
Ben Clayton | ba6ab5e | 2021-05-07 14:49:34 +0000 | [diff] [blame] | 81 | #include "src/sem/struct.h" |
Antonio Maiorano | aea9c68 | 2021-04-19 22:54:43 +0000 | [diff] [blame] | 82 | #include "src/sem/u32_type.h" |
| 83 | #include "src/sem/vector_type.h" |
| 84 | #include "src/sem/void_type.h" |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 85 | |
Ben Clayton | 03d1072 | 2021-06-05 12:45:50 +0000 | [diff] [blame] | 86 | #ifdef INCLUDE_TINT_TINT_H_ |
| 87 | #error "internal tint header being #included from tint.h" |
| 88 | #endif |
| 89 | |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 90 | // Forward declarations |
Ben Clayton | b5cd10c | 2021-06-25 10:26:26 +0000 | [diff] [blame] | 91 | namespace tint { |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 92 | namespace ast { |
| 93 | class VariableDeclStatement; |
| 94 | } // namespace ast |
Ben Clayton | b5cd10c | 2021-06-25 10:26:26 +0000 | [diff] [blame] | 95 | } // namespace tint |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 96 | |
Ben Clayton | b5cd10c | 2021-06-25 10:26:26 +0000 | [diff] [blame] | 97 | namespace tint { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 98 | class CloneContext; |
| 99 | |
| 100 | /// ProgramBuilder is a mutable builder for a Program. |
| 101 | /// To construct a Program, populate the builder and then `std::move` it to a |
| 102 | /// Program. |
| 103 | class ProgramBuilder { |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 104 | /// VarOptionals is a helper for accepting a number of optional, extra |
| 105 | /// arguments for Var() and Global(). |
| 106 | struct VarOptionals { |
| 107 | template <typename... ARGS> |
| 108 | explicit VarOptionals(ARGS&&... args) { |
| 109 | Apply(std::forward<ARGS>(args)...); |
| 110 | } |
| 111 | ~VarOptionals(); |
| 112 | |
| 113 | ast::StorageClass storage = ast::StorageClass::kNone; |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 114 | ast::Access access = ast::Access::kUndefined; |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 115 | ast::Expression* constructor = nullptr; |
| 116 | ast::DecorationList decorations = {}; |
| 117 | |
| 118 | private: |
| 119 | void Set(ast::StorageClass sc) { storage = sc; } |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 120 | void Set(ast::Access ac) { access = ac; } |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 121 | void Set(ast::Expression* c) { constructor = c; } |
| 122 | void Set(const ast::DecorationList& l) { decorations = l; } |
| 123 | |
| 124 | template <typename FIRST, typename... ARGS> |
| 125 | void Apply(FIRST&& first, ARGS&&... args) { |
| 126 | Set(std::forward<FIRST>(first)); |
| 127 | Apply(std::forward<ARGS>(args)...); |
| 128 | } |
| 129 | void Apply() {} |
| 130 | }; |
| 131 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 132 | public: |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 133 | /// ASTNodeAllocator is an alias to BlockAllocator<ast::Node> |
| 134 | using ASTNodeAllocator = BlockAllocator<ast::Node>; |
| 135 | |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 136 | /// SemNodeAllocator is an alias to BlockAllocator<sem::Node> |
| 137 | using SemNodeAllocator = BlockAllocator<sem::Node>; |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 138 | |
| 139 | /// `i32` is a type alias to `int`. |
| 140 | /// Useful for passing to template methods such as `vec2<i32>()` to imitate |
| 141 | /// WGSL syntax. |
| 142 | /// Note: this is intentionally not aliased to uint32_t as we want integer |
| 143 | /// literals passed to the builder to match WGSL's integer literal types. |
| 144 | using i32 = decltype(1); |
| 145 | /// `u32` is a type alias to `unsigned int`. |
| 146 | /// Useful for passing to template methods such as `vec2<u32>()` to imitate |
| 147 | /// WGSL syntax. |
| 148 | /// Note: this is intentionally not aliased to uint32_t as we want integer |
| 149 | /// literals passed to the builder to match WGSL's integer literal types. |
| 150 | using u32 = decltype(1u); |
| 151 | /// `f32` is a type alias to `float` |
| 152 | /// Useful for passing to template methods such as `vec2<f32>()` to imitate |
| 153 | /// WGSL syntax. |
| 154 | using f32 = float; |
| 155 | |
| 156 | /// Constructor |
| 157 | ProgramBuilder(); |
| 158 | |
| 159 | /// Move constructor |
| 160 | /// @param rhs the builder to move |
| 161 | ProgramBuilder(ProgramBuilder&& rhs); |
| 162 | |
| 163 | /// Destructor |
| 164 | virtual ~ProgramBuilder(); |
| 165 | |
| 166 | /// Move assignment operator |
| 167 | /// @param rhs the builder to move |
| 168 | /// @return this builder |
| 169 | ProgramBuilder& operator=(ProgramBuilder&& rhs); |
| 170 | |
Ben Clayton | e43c830 | 2021-01-29 11:59:32 +0000 | [diff] [blame] | 171 | /// Wrap returns a new ProgramBuilder wrapping the Program `program` without |
| 172 | /// making a deep clone of the Program contents. |
| 173 | /// ProgramBuilder returned by Wrap() is intended to temporarily extend an |
| 174 | /// existing immutable program. |
| 175 | /// As the returned ProgramBuilder wraps `program`, `program` must not be |
| 176 | /// destructed or assigned while using the returned ProgramBuilder. |
| 177 | /// TODO(bclayton) - Evaluate whether there are safer alternatives to this |
| 178 | /// function. See crbug.com/tint/460. |
| 179 | /// @param program the immutable Program to wrap |
| 180 | /// @return the ProgramBuilder that wraps `program` |
| 181 | static ProgramBuilder Wrap(const Program* program); |
| 182 | |
Ben Clayton | e6995de | 2021-04-13 23:27:27 +0000 | [diff] [blame] | 183 | /// @returns the unique identifier for this program |
| 184 | ProgramID ID() const { return id_; } |
| 185 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 186 | /// @returns a reference to the program's types |
Antonio Maiorano | 3751fd2 | 2021-04-19 22:51:23 +0000 | [diff] [blame] | 187 | sem::Manager& Types() { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 188 | AssertNotMoved(); |
| 189 | return types_; |
| 190 | } |
| 191 | |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 192 | /// @returns a reference to the program's types |
Antonio Maiorano | 3751fd2 | 2021-04-19 22:51:23 +0000 | [diff] [blame] | 193 | const sem::Manager& Types() const { |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 194 | AssertNotMoved(); |
| 195 | return types_; |
| 196 | } |
| 197 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 198 | /// @returns a reference to the program's AST nodes storage |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 199 | ASTNodeAllocator& ASTNodes() { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 200 | AssertNotMoved(); |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 201 | return ast_nodes_; |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 204 | /// @returns a reference to the program's AST nodes storage |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 205 | const ASTNodeAllocator& ASTNodes() const { |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 206 | AssertNotMoved(); |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 207 | return ast_nodes_; |
| 208 | } |
| 209 | |
| 210 | /// @returns a reference to the program's semantic nodes storage |
| 211 | SemNodeAllocator& SemNodes() { |
| 212 | AssertNotMoved(); |
| 213 | return sem_nodes_; |
| 214 | } |
| 215 | |
| 216 | /// @returns a reference to the program's semantic nodes storage |
| 217 | const SemNodeAllocator& SemNodes() const { |
| 218 | AssertNotMoved(); |
| 219 | return sem_nodes_; |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 222 | /// @returns a reference to the program's AST root Module |
| 223 | ast::Module& AST() { |
| 224 | AssertNotMoved(); |
| 225 | return *ast_; |
| 226 | } |
| 227 | |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 228 | /// @returns a reference to the program's AST root Module |
| 229 | const ast::Module& AST() const { |
| 230 | AssertNotMoved(); |
| 231 | return *ast_; |
| 232 | } |
| 233 | |
| 234 | /// @returns a reference to the program's semantic info |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 235 | sem::Info& Sem() { |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 236 | AssertNotMoved(); |
| 237 | return sem_; |
| 238 | } |
| 239 | |
| 240 | /// @returns a reference to the program's semantic info |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 241 | const sem::Info& Sem() const { |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 242 | AssertNotMoved(); |
| 243 | return sem_; |
| 244 | } |
| 245 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 246 | /// @returns a reference to the program's SymbolTable |
| 247 | SymbolTable& Symbols() { |
| 248 | AssertNotMoved(); |
| 249 | return symbols_; |
| 250 | } |
| 251 | |
Ben Clayton | 708dc2d | 2021-01-29 11:22:40 +0000 | [diff] [blame] | 252 | /// @returns a reference to the program's SymbolTable |
| 253 | const SymbolTable& Symbols() const { |
| 254 | AssertNotMoved(); |
| 255 | return symbols_; |
| 256 | } |
| 257 | |
Ben Clayton | 844217f | 2021-01-27 18:49:05 +0000 | [diff] [blame] | 258 | /// @returns a reference to the program's diagnostics |
| 259 | diag::List& Diagnostics() { |
| 260 | AssertNotMoved(); |
| 261 | return diagnostics_; |
| 262 | } |
| 263 | |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 264 | /// @returns a reference to the program's diagnostics |
| 265 | const diag::List& Diagnostics() const { |
| 266 | AssertNotMoved(); |
| 267 | return diagnostics_; |
| 268 | } |
| 269 | |
Ben Clayton | 5f0ea11 | 2021-03-09 10:54:37 +0000 | [diff] [blame] | 270 | /// Controls whether the Resolver will be run on the program when it is built. |
Ben Clayton | dd69ac3 | 2021-01-27 19:23:55 +0000 | [diff] [blame] | 271 | /// @param enable the new flag value (defaults to true) |
| 272 | void SetResolveOnBuild(bool enable) { resolve_on_build_ = enable; } |
| 273 | |
Ben Clayton | 5f0ea11 | 2021-03-09 10:54:37 +0000 | [diff] [blame] | 274 | /// @return true if the Resolver will be run on the program when it is |
Ben Clayton | dd69ac3 | 2021-01-27 19:23:55 +0000 | [diff] [blame] | 275 | /// built. |
| 276 | bool ResolveOnBuild() const { return resolve_on_build_; } |
| 277 | |
Ben Clayton | 844217f | 2021-01-27 18:49:05 +0000 | [diff] [blame] | 278 | /// @returns true if the program has no error diagnostics and is not missing |
| 279 | /// information |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 280 | bool IsValid() const; |
| 281 | |
Ben Clayton | 708dc2d | 2021-01-29 11:22:40 +0000 | [diff] [blame] | 282 | /// Writes a representation of the node to the output stream |
| 283 | /// @note unlike str(), to_str() does not automatically demangle the string. |
| 284 | /// @param node the AST node |
| 285 | /// @param out the stream to write to |
| 286 | /// @param indent number of spaces to indent the node when writing |
| 287 | void to_str(const ast::Node* node, std::ostream& out, size_t indent) const { |
| 288 | node->to_str(Sem(), out, indent); |
| 289 | } |
| 290 | |
| 291 | /// Returns a demangled, string representation of `node`. |
| 292 | /// @param node the AST node |
| 293 | /// @returns a string representation of the node |
| 294 | std::string str(const ast::Node* node) const; |
| 295 | |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 296 | /// Creates a new ast::Node owned by the ProgramBuilder. When the |
| 297 | /// ProgramBuilder is destructed, the ast::Node will also be destructed. |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 298 | /// @param source the Source of the node |
| 299 | /// @param args the arguments to pass to the type constructor |
| 300 | /// @returns the node pointer |
| 301 | template <typename T, typename... ARGS> |
| 302 | traits::EnableIfIsType<T, ast::Node>* create(const Source& source, |
| 303 | ARGS&&... args) { |
| 304 | AssertNotMoved(); |
Ben Clayton | e6995de | 2021-04-13 23:27:27 +0000 | [diff] [blame] | 305 | return ast_nodes_.Create<T>(id_, source, std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 308 | /// Creates a new ast::Node owned by the ProgramBuilder, injecting the current |
| 309 | /// Source as set by the last call to SetSource() as the only argument to the |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 310 | /// constructor. |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 311 | /// When the ProgramBuilder is destructed, the ast::Node will also be |
| 312 | /// destructed. |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 313 | /// @returns the node pointer |
| 314 | template <typename T> |
| 315 | traits::EnableIfIsType<T, ast::Node>* create() { |
| 316 | AssertNotMoved(); |
Ben Clayton | e6995de | 2021-04-13 23:27:27 +0000 | [diff] [blame] | 317 | return ast_nodes_.Create<T>(id_, source_); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 320 | /// Creates a new ast::Node owned by the ProgramBuilder, injecting the current |
| 321 | /// Source as set by the last call to SetSource() as the first argument to the |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 322 | /// constructor. |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 323 | /// When the ProgramBuilder is destructed, the ast::Node will also be |
| 324 | /// destructed. |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 325 | /// @param arg0 the first arguments to pass to the type constructor |
| 326 | /// @param args the remaining arguments to pass to the type constructor |
| 327 | /// @returns the node pointer |
| 328 | template <typename T, typename ARG0, typename... ARGS> |
| 329 | traits::EnableIf</* T is ast::Node and ARG0 is not Source */ |
| 330 | traits::IsTypeOrDerived<T, ast::Node>::value && |
| 331 | !traits::IsTypeOrDerived<ARG0, Source>::value, |
| 332 | T>* |
| 333 | create(ARG0&& arg0, ARGS&&... args) { |
| 334 | AssertNotMoved(); |
Ben Clayton | e6995de | 2021-04-13 23:27:27 +0000 | [diff] [blame] | 335 | return ast_nodes_.Create<T>(id_, source_, std::forward<ARG0>(arg0), |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 336 | std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 339 | /// Creates a new sem::Node owned by the ProgramBuilder. |
| 340 | /// When the ProgramBuilder is destructed, the sem::Node will also be |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 341 | /// destructed. |
| 342 | /// @param args the arguments to pass to the type constructor |
| 343 | /// @returns the node pointer |
| 344 | template <typename T, typename... ARGS> |
Ben Clayton | 58750ea | 2021-05-06 15:52:33 +0000 | [diff] [blame] | 345 | traits::EnableIf<traits::IsTypeOrDerived<T, sem::Node>::value && |
| 346 | !traits::IsTypeOrDerived<T, sem::Type>::value, |
| 347 | T>* |
| 348 | create(ARGS&&... args) { |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 349 | AssertNotMoved(); |
| 350 | return sem_nodes_.Create<T>(std::forward<ARGS>(args)...); |
| 351 | } |
| 352 | |
Antonio Maiorano | 3751fd2 | 2021-04-19 22:51:23 +0000 | [diff] [blame] | 353 | /// Creates a new sem::Type owned by the ProgramBuilder. |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 354 | /// When the ProgramBuilder is destructed, owned ProgramBuilder and the |
| 355 | /// returned`Type` will also be destructed. |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 356 | /// Types are unique (de-aliased), and so calling create() for the same `T` |
| 357 | /// and arguments will return the same pointer. |
| 358 | /// @warning Use this method to acquire a type only if all of its type |
| 359 | /// information is provided in the constructor arguments `args`.<br> |
| 360 | /// If the type requires additional configuration after construction that |
| 361 | /// affect its fundamental type, build the type with `std::make_unique`, make |
| 362 | /// any necessary alterations and then call unique_type() instead. |
| 363 | /// @param args the arguments to pass to the type constructor |
| 364 | /// @returns the de-aliased type pointer |
| 365 | template <typename T, typename... ARGS> |
Antonio Maiorano | 3751fd2 | 2021-04-19 22:51:23 +0000 | [diff] [blame] | 366 | traits::EnableIfIsType<T, sem::Type>* create(ARGS&&... args) { |
| 367 | static_assert(std::is_base_of<sem::Type, T>::value, |
| 368 | "T does not derive from sem::Type"); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 369 | AssertNotMoved(); |
| 370 | return types_.Get<T>(std::forward<ARGS>(args)...); |
| 371 | } |
| 372 | |
| 373 | /// Marks this builder as moved, preventing any further use of the builder. |
| 374 | void MarkAsMoved(); |
| 375 | |
| 376 | ////////////////////////////////////////////////////////////////////////////// |
| 377 | // TypesBuilder |
| 378 | ////////////////////////////////////////////////////////////////////////////// |
| 379 | |
| 380 | /// TypesBuilder holds basic `tint` types and methods for constructing |
| 381 | /// complex types. |
| 382 | class TypesBuilder { |
| 383 | public: |
| 384 | /// Constructor |
| 385 | /// @param builder the program builder |
| 386 | explicit TypesBuilder(ProgramBuilder* builder); |
| 387 | |
| 388 | /// @return the tint AST type for the C type `T`. |
| 389 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 390 | ast::Type* Of() const { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 391 | return CToAST<T>::get(this); |
| 392 | } |
| 393 | |
| 394 | /// @returns a boolean type |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 395 | ast::Bool* bool_() const { return builder->create<ast::Bool>(); } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 396 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 397 | /// @param source the Source of the node |
| 398 | /// @returns a boolean type |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 399 | ast::Bool* bool_(const Source& source) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 400 | return builder->create<ast::Bool>(source); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 403 | /// @returns a f32 type |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 404 | ast::F32* f32() const { return builder->create<ast::F32>(); } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 405 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 406 | /// @param source the Source of the node |
| 407 | /// @returns a f32 type |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 408 | ast::F32* f32(const Source& source) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 409 | return builder->create<ast::F32>(source); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 412 | /// @returns a i32 type |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 413 | ast::I32* i32() const { return builder->create<ast::I32>(); } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 414 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 415 | /// @param source the Source of the node |
| 416 | /// @returns a i32 type |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 417 | ast::I32* i32(const Source& source) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 418 | return builder->create<ast::I32>(source); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 421 | /// @returns a u32 type |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 422 | ast::U32* u32() const { return builder->create<ast::U32>(); } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 423 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 424 | /// @param source the Source of the node |
| 425 | /// @returns a u32 type |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 426 | ast::U32* u32(const Source& source) const { |
Ben Clayton | 58dec17 | 2021-05-19 17:47:11 +0000 | [diff] [blame] | 427 | return builder->create<ast::U32>(source); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 430 | /// @returns a void type |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 431 | ast::Void* void_() const { return builder->create<ast::Void>(); } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 432 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 433 | /// @param source the Source of the node |
| 434 | /// @returns a void type |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 435 | ast::Void* void_(const Source& source) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 436 | return builder->create<ast::Void>(source); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 439 | /// @param type vector subtype |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 440 | /// @param n vector width in elements |
| 441 | /// @return the tint AST type for a `n`-element vector of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 442 | ast::Vector* vec(ast::Type* type, uint32_t n) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 443 | return builder->create<ast::Vector>(type, n); |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 446 | /// @param source the Source of the node |
| 447 | /// @param type vector subtype |
| 448 | /// @param n vector width in elements |
| 449 | /// @return the tint AST type for a `n`-element vector of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 450 | ast::Vector* vec(const Source& source, ast::Type* type, uint32_t n) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 451 | return builder->create<ast::Vector>(source, type, n); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 454 | /// @param type vector subtype |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 455 | /// @return the tint AST type for a 2-element vector of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 456 | ast::Vector* vec2(ast::Type* type) const { return vec(type, 2u); } |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 457 | |
| 458 | /// @param type vector subtype |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 459 | /// @return the tint AST type for a 3-element vector of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 460 | ast::Vector* vec3(ast::Type* type) const { return vec(type, 3u); } |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 461 | |
| 462 | /// @param type vector subtype |
| 463 | /// @return the tint AST type for a 4-element vector of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 464 | ast::Vector* vec4(ast::Type* type) const { return vec(type, 4u); } |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 465 | |
| 466 | /// @param n vector width in elements |
| 467 | /// @return the tint AST type for a `n`-element vector of `type`. |
| 468 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 469 | ast::Vector* vec(uint32_t n) const { |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 470 | return vec(Of<T>(), n); |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 473 | /// @return the tint AST type for a 2-element vector of the C type `T`. |
| 474 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 475 | ast::Vector* vec2() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 476 | return vec2(Of<T>()); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /// @return the tint AST type for a 3-element vector of the C type `T`. |
| 480 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 481 | ast::Vector* vec3() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 482 | return vec3(Of<T>()); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /// @return the tint AST type for a 4-element vector of the C type `T`. |
| 486 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 487 | ast::Vector* vec4() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 488 | return vec4(Of<T>()); |
| 489 | } |
| 490 | |
| 491 | /// @param type matrix subtype |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 492 | /// @param columns number of columns for the matrix |
| 493 | /// @param rows number of rows for the matrix |
| 494 | /// @return the tint AST type for a matrix of `type` |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 495 | ast::Matrix* mat(ast::Type* type, uint32_t columns, uint32_t rows) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 496 | return builder->create<ast::Matrix>(type, rows, columns); |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 499 | /// @param source the Source of the node |
| 500 | /// @param type matrix subtype |
| 501 | /// @param columns number of columns for the matrix |
| 502 | /// @param rows number of rows for the matrix |
| 503 | /// @return the tint AST type for a matrix of `type` |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 504 | ast::Matrix* mat(const Source& source, |
| 505 | ast::Type* type, |
| 506 | uint32_t columns, |
| 507 | uint32_t rows) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 508 | return builder->create<ast::Matrix>(source, type, rows, columns); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 511 | /// @param type matrix subtype |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 512 | /// @return the tint AST type for a 2x3 matrix of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 513 | ast::Matrix* mat2x2(ast::Type* type) const { return mat(type, 2u, 2u); } |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 514 | |
| 515 | /// @param type matrix subtype |
| 516 | /// @return the tint AST type for a 2x3 matrix of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 517 | ast::Matrix* mat2x3(ast::Type* type) const { return mat(type, 2u, 3u); } |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 518 | |
| 519 | /// @param type matrix subtype |
| 520 | /// @return the tint AST type for a 2x4 matrix of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 521 | ast::Matrix* mat2x4(ast::Type* type) const { return mat(type, 2u, 4u); } |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 522 | |
| 523 | /// @param type matrix subtype |
| 524 | /// @return the tint AST type for a 3x2 matrix of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 525 | ast::Matrix* mat3x2(ast::Type* type) const { return mat(type, 3u, 2u); } |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 526 | |
| 527 | /// @param type matrix subtype |
| 528 | /// @return the tint AST type for a 3x3 matrix of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 529 | ast::Matrix* mat3x3(ast::Type* type) const { return mat(type, 3u, 3u); } |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 530 | |
| 531 | /// @param type matrix subtype |
| 532 | /// @return the tint AST type for a 3x4 matrix of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 533 | ast::Matrix* mat3x4(ast::Type* type) const { return mat(type, 3u, 4u); } |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 534 | |
| 535 | /// @param type matrix subtype |
| 536 | /// @return the tint AST type for a 4x2 matrix of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 537 | ast::Matrix* mat4x2(ast::Type* type) const { return mat(type, 4u, 2u); } |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 538 | |
| 539 | /// @param type matrix subtype |
| 540 | /// @return the tint AST type for a 4x3 matrix of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 541 | ast::Matrix* mat4x3(ast::Type* type) const { return mat(type, 4u, 3u); } |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 542 | |
| 543 | /// @param type matrix subtype |
| 544 | /// @return the tint AST type for a 4x4 matrix of `type`. |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 545 | ast::Matrix* mat4x4(ast::Type* type) const { return mat(type, 4u, 4u); } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 546 | |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 547 | /// @param columns number of columns for the matrix |
| 548 | /// @param rows number of rows for the matrix |
| 549 | /// @return the tint AST type for a matrix of `type` |
| 550 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 551 | ast::Matrix* mat(uint32_t columns, uint32_t rows) const { |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 552 | return mat(Of<T>(), columns, rows); |
| 553 | } |
| 554 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 555 | /// @return the tint AST type for a 2x3 matrix of the C type `T`. |
| 556 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 557 | ast::Matrix* mat2x2() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 558 | return mat2x2(Of<T>()); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | /// @return the tint AST type for a 2x3 matrix of the C type `T`. |
| 562 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 563 | ast::Matrix* mat2x3() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 564 | return mat2x3(Of<T>()); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /// @return the tint AST type for a 2x4 matrix of the C type `T`. |
| 568 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 569 | ast::Matrix* mat2x4() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 570 | return mat2x4(Of<T>()); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /// @return the tint AST type for a 3x2 matrix of the C type `T`. |
| 574 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 575 | ast::Matrix* mat3x2() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 576 | return mat3x2(Of<T>()); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /// @return the tint AST type for a 3x3 matrix of the C type `T`. |
| 580 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 581 | ast::Matrix* mat3x3() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 582 | return mat3x3(Of<T>()); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /// @return the tint AST type for a 3x4 matrix of the C type `T`. |
| 586 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 587 | ast::Matrix* mat3x4() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 588 | return mat3x4(Of<T>()); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | /// @return the tint AST type for a 4x2 matrix of the C type `T`. |
| 592 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 593 | ast::Matrix* mat4x2() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 594 | return mat4x2(Of<T>()); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /// @return the tint AST type for a 4x3 matrix of the C type `T`. |
| 598 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 599 | ast::Matrix* mat4x3() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 600 | return mat4x3(Of<T>()); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | /// @return the tint AST type for a 4x4 matrix of the C type `T`. |
| 604 | template <typename T> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 605 | ast::Matrix* mat4x4() const { |
Antonio Maiorano | 2543686 | 2021-04-13 13:32:33 +0000 | [diff] [blame] | 606 | return mat4x4(Of<T>()); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | /// @param subtype the array element type |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 610 | /// @param n the array size. 0 represents a runtime-array |
| 611 | /// @param decos the optional decorations for the array |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 612 | /// @return the tint AST type for a array of size `n` of type `T` |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 613 | ast::Array* array(ast::Type* subtype, |
Ben Clayton | 4cd5eea | 2021-05-07 20:58:34 +0000 | [diff] [blame] | 614 | uint32_t n = 0, |
| 615 | ast::DecorationList decos = {}) const { |
Ben Clayton | 4cd5eea | 2021-05-07 20:58:34 +0000 | [diff] [blame] | 616 | return builder->create<ast::Array>(subtype, n, decos); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | /// @param source the Source of the node |
| 620 | /// @param subtype the array element type |
| 621 | /// @param n the array size. 0 represents a runtime-array |
| 622 | /// @param decos the optional decorations for the array |
| 623 | /// @return the tint AST type for a array of size `n` of type `T` |
Ben Clayton | 4cd5eea | 2021-05-07 20:58:34 +0000 | [diff] [blame] | 624 | ast::Array* array(const Source& source, |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 625 | ast::Type* subtype, |
Ben Clayton | 4cd5eea | 2021-05-07 20:58:34 +0000 | [diff] [blame] | 626 | uint32_t n = 0, |
| 627 | ast::DecorationList decos = {}) const { |
Ben Clayton | 4cd5eea | 2021-05-07 20:58:34 +0000 | [diff] [blame] | 628 | return builder->create<ast::Array>(source, subtype, n, decos); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 629 | } |
| 630 | |
Ben Clayton | bab3197 | 2021-02-08 21:16:21 +0000 | [diff] [blame] | 631 | /// @param subtype the array element type |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 632 | /// @param n the array size. 0 represents a runtime-array |
Ben Clayton | cbbe576 | 2021-05-10 17:25:21 +0000 | [diff] [blame] | 633 | /// @param stride the array stride. 0 represents implicit stride |
Ben Clayton | bab3197 | 2021-02-08 21:16:21 +0000 | [diff] [blame] | 634 | /// @return the tint AST type for a array of size `n` of type `T` |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 635 | ast::Array* array(ast::Type* subtype, uint32_t n, uint32_t stride) const { |
Ben Clayton | cbbe576 | 2021-05-10 17:25:21 +0000 | [diff] [blame] | 636 | ast::DecorationList decos; |
| 637 | if (stride) { |
| 638 | decos.emplace_back(builder->create<ast::StrideDecoration>(stride)); |
| 639 | } |
| 640 | return array(subtype, n, std::move(decos)); |
Ben Clayton | bab3197 | 2021-02-08 21:16:21 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 643 | /// @param source the Source of the node |
| 644 | /// @param subtype the array element type |
| 645 | /// @param n the array size. 0 represents a runtime-array |
Ben Clayton | cbbe576 | 2021-05-10 17:25:21 +0000 | [diff] [blame] | 646 | /// @param stride the array stride. 0 represents implicit stride |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 647 | /// @return the tint AST type for a array of size `n` of type `T` |
Ben Clayton | 4cd5eea | 2021-05-07 20:58:34 +0000 | [diff] [blame] | 648 | ast::Array* array(const Source& source, |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 649 | ast::Type* subtype, |
Ben Clayton | 4cd5eea | 2021-05-07 20:58:34 +0000 | [diff] [blame] | 650 | uint32_t n, |
| 651 | uint32_t stride) const { |
Ben Clayton | cbbe576 | 2021-05-10 17:25:21 +0000 | [diff] [blame] | 652 | ast::DecorationList decos; |
| 653 | if (stride) { |
| 654 | decos.emplace_back(builder->create<ast::StrideDecoration>(stride)); |
| 655 | } |
| 656 | return array(source, subtype, n, std::move(decos)); |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 657 | } |
| 658 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 659 | /// @return the tint AST type for an array of size `N` of type `T` |
| 660 | template <typename T, int N = 0> |
Ben Clayton | 4cd5eea | 2021-05-07 20:58:34 +0000 | [diff] [blame] | 661 | ast::Array* array() const { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 662 | return array(Of<T>(), N); |
| 663 | } |
| 664 | |
Ben Clayton | bab3197 | 2021-02-08 21:16:21 +0000 | [diff] [blame] | 665 | /// @param stride the array stride |
| 666 | /// @return the tint AST type for an array of size `N` of type `T` |
| 667 | template <typename T, int N = 0> |
Ben Clayton | 4cd5eea | 2021-05-07 20:58:34 +0000 | [diff] [blame] | 668 | ast::Array* array(uint32_t stride) const { |
Ben Clayton | bab3197 | 2021-02-08 21:16:21 +0000 | [diff] [blame] | 669 | return array(Of<T>(), N, stride); |
| 670 | } |
Ben Clayton | 4db10dd | 2021-04-16 08:47:14 +0000 | [diff] [blame] | 671 | |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 672 | /// Creates a type name |
| 673 | /// @param name the name |
| 674 | /// @returns the type name |
| 675 | template <typename NAME> |
| 676 | ast::TypeName* type_name(NAME&& name) const { |
| 677 | return builder->create<ast::TypeName>( |
| 678 | builder->Sym(std::forward<NAME>(name))); |
| 679 | } |
| 680 | |
| 681 | /// Creates a type name |
| 682 | /// @param source the Source of the node |
| 683 | /// @param name the name |
| 684 | /// @returns the type name |
| 685 | template <typename NAME> |
| 686 | ast::TypeName* type_name(const Source& source, NAME&& name) const { |
| 687 | return builder->create<ast::TypeName>( |
| 688 | source, builder->Sym(std::forward<NAME>(name))); |
| 689 | } |
| 690 | |
Ben Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 691 | /// Creates an alias type |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 692 | /// @param name the alias name |
| 693 | /// @param type the alias type |
| 694 | /// @returns the alias pointer |
Ben Clayton | 1d618b1 | 2021-04-09 16:19:48 +0000 | [diff] [blame] | 695 | template <typename NAME> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 696 | ast::Alias* alias(NAME&& name, ast::Type* type) const { |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 697 | auto sym = builder->Sym(std::forward<NAME>(name)); |
Ben Clayton | a34fa0e | 2021-05-10 17:38:01 +0000 | [diff] [blame] | 698 | return builder->create<ast::Alias>(sym, type); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 699 | } |
| 700 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 701 | /// Creates an alias type |
| 702 | /// @param source the Source of the node |
| 703 | /// @param name the alias name |
| 704 | /// @param type the alias type |
| 705 | /// @returns the alias pointer |
| 706 | template <typename NAME> |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 707 | ast::Alias* alias(const Source& source, |
| 708 | NAME&& name, |
| 709 | ast::Type* type) const { |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 710 | auto sym = builder->Sym(std::forward<NAME>(name)); |
Ben Clayton | a34fa0e | 2021-05-10 17:38:01 +0000 | [diff] [blame] | 711 | return builder->create<ast::Alias>(source, sym, type); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Antonio Maiorano | 39a65a1 | 2021-03-31 12:46:52 +0000 | [diff] [blame] | 714 | /// @param type the type of the pointer |
| 715 | /// @param storage_class the storage class of the pointer |
Ben Clayton | 1858854 | 2021-06-04 22:17:37 +0000 | [diff] [blame] | 716 | /// @param access the optional access control of the pointer |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 717 | /// @return the pointer to `type` with the given ast::StorageClass |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 718 | ast::Pointer* pointer(ast::Type* type, |
Ben Clayton | 1858854 | 2021-06-04 22:17:37 +0000 | [diff] [blame] | 719 | ast::StorageClass storage_class, |
| 720 | ast::Access access = ast::Access::kUndefined) const { |
Ben Clayton | 1858854 | 2021-06-04 22:17:37 +0000 | [diff] [blame] | 721 | return builder->create<ast::Pointer>(type, storage_class, access); |
Antonio Maiorano | 39a65a1 | 2021-03-31 12:46:52 +0000 | [diff] [blame] | 722 | } |
| 723 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 724 | /// @param source the Source of the node |
| 725 | /// @param type the type of the pointer |
| 726 | /// @param storage_class the storage class of the pointer |
Ben Clayton | 1858854 | 2021-06-04 22:17:37 +0000 | [diff] [blame] | 727 | /// @param access the optional access control of the pointer |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 728 | /// @return the pointer to `type` with the given ast::StorageClass |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 729 | ast::Pointer* pointer(const Source& source, |
| 730 | ast::Type* type, |
Ben Clayton | 1858854 | 2021-06-04 22:17:37 +0000 | [diff] [blame] | 731 | ast::StorageClass storage_class, |
| 732 | ast::Access access = ast::Access::kUndefined) const { |
Ben Clayton | 1858854 | 2021-06-04 22:17:37 +0000 | [diff] [blame] | 733 | return builder->create<ast::Pointer>(source, type, storage_class, access); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 736 | /// @param storage_class the storage class of the pointer |
Ben Clayton | 1858854 | 2021-06-04 22:17:37 +0000 | [diff] [blame] | 737 | /// @param access the optional access control of the pointer |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 738 | /// @return the pointer to type `T` with the given ast::StorageClass. |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 739 | template <typename T> |
Ben Clayton | 1858854 | 2021-06-04 22:17:37 +0000 | [diff] [blame] | 740 | ast::Pointer* pointer(ast::StorageClass storage_class, |
| 741 | ast::Access access = ast::Access::kUndefined) const { |
| 742 | return pointer(Of<T>(), storage_class, access); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 743 | } |
| 744 | |
Ben Clayton | 8c7f0da | 2021-06-17 15:48:39 +0000 | [diff] [blame] | 745 | /// @param source the Source of the node |
| 746 | /// @param type the type of the atomic |
| 747 | /// @return the atomic to `type` |
| 748 | ast::Atomic* atomic(const Source& source, ast::Type* type) const { |
| 749 | return builder->create<ast::Atomic>(source, type); |
| 750 | } |
| 751 | |
Ben Clayton | 313e618 | 2021-06-17 19:56:14 +0000 | [diff] [blame] | 752 | /// @param type the type of the atomic |
| 753 | /// @return the atomic to `type` |
| 754 | ast::Atomic* atomic(ast::Type* type) const { |
| 755 | return builder->create<ast::Atomic>(type); |
| 756 | } |
| 757 | |
Ben Clayton | 8c7f0da | 2021-06-17 15:48:39 +0000 | [diff] [blame] | 758 | /// @return the atomic to type `T` |
| 759 | template <typename T> |
| 760 | ast::Atomic* atomic() const { |
| 761 | return atomic(Of<T>()); |
| 762 | } |
| 763 | |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 764 | /// @param kind the kind of sampler |
| 765 | /// @returns the sampler |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 766 | ast::Sampler* sampler(ast::SamplerKind kind) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 767 | return builder->create<ast::Sampler>(kind); |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 770 | /// @param source the Source of the node |
| 771 | /// @param kind the kind of sampler |
| 772 | /// @returns the sampler |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 773 | ast::Sampler* sampler(const Source& source, ast::SamplerKind kind) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 774 | return builder->create<ast::Sampler>(source, kind); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 775 | } |
| 776 | |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 777 | /// @param dims the dimensionality of the texture |
| 778 | /// @returns the depth texture |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 779 | ast::DepthTexture* depth_texture(ast::TextureDimension dims) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 780 | return builder->create<ast::DepthTexture>(dims); |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 783 | /// @param source the Source of the node |
| 784 | /// @param dims the dimensionality of the texture |
| 785 | /// @returns the depth texture |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 786 | ast::DepthTexture* depth_texture(const Source& source, |
| 787 | ast::TextureDimension dims) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 788 | return builder->create<ast::DepthTexture>(source, dims); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 791 | /// @param dims the dimensionality of the texture |
| 792 | /// @param subtype the texture subtype. |
| 793 | /// @returns the sampled texture |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 794 | ast::SampledTexture* sampled_texture(ast::TextureDimension dims, |
| 795 | ast::Type* subtype) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 796 | return builder->create<ast::SampledTexture>(dims, subtype); |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 797 | } |
| 798 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 799 | /// @param source the Source of the node |
| 800 | /// @param dims the dimensionality of the texture |
| 801 | /// @param subtype the texture subtype. |
| 802 | /// @returns the sampled texture |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 803 | ast::SampledTexture* sampled_texture(const Source& source, |
| 804 | ast::TextureDimension dims, |
| 805 | ast::Type* subtype) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 806 | return builder->create<ast::SampledTexture>(source, dims, subtype); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 807 | } |
| 808 | |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 809 | /// @param dims the dimensionality of the texture |
| 810 | /// @param subtype the texture subtype. |
| 811 | /// @returns the multisampled texture |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 812 | ast::MultisampledTexture* multisampled_texture(ast::TextureDimension dims, |
| 813 | ast::Type* subtype) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 814 | return builder->create<ast::MultisampledTexture>(dims, subtype); |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 817 | /// @param source the Source of the node |
| 818 | /// @param dims the dimensionality of the texture |
| 819 | /// @param subtype the texture subtype. |
| 820 | /// @returns the multisampled texture |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 821 | ast::MultisampledTexture* multisampled_texture(const Source& source, |
| 822 | ast::TextureDimension dims, |
| 823 | ast::Type* subtype) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 824 | return builder->create<ast::MultisampledTexture>(source, dims, subtype); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 825 | } |
| 826 | |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 827 | /// @param dims the dimensionality of the texture |
| 828 | /// @param format the image format of the texture |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 829 | /// @param access the access control of the texture |
Ben Clayton | e204f27 | 2021-04-22 14:40:23 +0000 | [diff] [blame] | 830 | /// @returns the storage texture |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 831 | ast::StorageTexture* storage_texture(ast::TextureDimension dims, |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 832 | ast::ImageFormat format, |
| 833 | ast::Access access) const { |
Ben Clayton | 55ecfc4 | 2021-05-20 14:42:28 +0000 | [diff] [blame] | 834 | auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder); |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 835 | return builder->create<ast::StorageTexture>(dims, format, subtype, |
| 836 | access); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 839 | /// @param source the Source of the node |
| 840 | /// @param dims the dimensionality of the texture |
| 841 | /// @param format the image format of the texture |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 842 | /// @param access the access control of the texture |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 843 | /// @returns the storage texture |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 844 | ast::StorageTexture* storage_texture(const Source& source, |
| 845 | ast::TextureDimension dims, |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 846 | ast::ImageFormat format, |
| 847 | ast::Access access) const { |
Ben Clayton | 55ecfc4 | 2021-05-20 14:42:28 +0000 | [diff] [blame] | 848 | auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder); |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 849 | return builder->create<ast::StorageTexture>(source, dims, format, subtype, |
| 850 | access); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Brandon Jones | 7b25769 | 2021-05-17 17:40:17 +0000 | [diff] [blame] | 853 | /// @returns the external texture |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 854 | ast::ExternalTexture* external_texture() const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 855 | return builder->create<ast::ExternalTexture>(); |
Brandon Jones | 7b25769 | 2021-05-17 17:40:17 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 858 | /// @param source the Source of the node |
| 859 | /// @returns the external texture |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 860 | ast::ExternalTexture* external_texture(const Source& source) const { |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 861 | return builder->create<ast::ExternalTexture>(source); |
Antonio Maiorano | 4b16a16 | 2021-04-27 17:32:37 +0000 | [diff] [blame] | 862 | } |
| 863 | |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 864 | /// [DEPRECATED]: TODO(crbug.com/tint/745): Migrate to const AST pointers. |
Ben Clayton | 8758f10 | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 865 | /// Constructs a TypeName for the type declaration. |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 866 | /// @param type the type |
| 867 | /// @return either type or a pointer to a new ast::TypeName |
Ben Clayton | 8758f10 | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 868 | ast::TypeName* Of(ast::TypeDecl* type) const; |
Ben Clayton | 19b0319 | 2021-05-20 15:04:08 +0000 | [diff] [blame] | 869 | |
Ben Clayton | 8758f10 | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 870 | /// Constructs a TypeName for the type declaration. |
Ben Clayton | 3b3cf5f | 2021-04-23 15:41:34 +0000 | [diff] [blame] | 871 | /// @param type the type |
| 872 | /// @return either type or a pointer to a new ast::TypeName |
Ben Clayton | 8758f10 | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 873 | const ast::TypeName* Of(const ast::TypeDecl* type) const; |
Ben Clayton | 3b3cf5f | 2021-04-23 15:41:34 +0000 | [diff] [blame] | 874 | |
Ben Clayton | f5f311e | 2021-04-28 14:31:23 +0000 | [diff] [blame] | 875 | /// The ProgramBuilder |
| 876 | ProgramBuilder* const builder; |
| 877 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 878 | private: |
| 879 | /// CToAST<T> is specialized for various `T` types and each specialization |
| 880 | /// contains a single static `get()` method for obtaining the corresponding |
| 881 | /// AST type for the C type `T`. |
| 882 | /// `get()` has the signature: |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 883 | /// `static ast::Type* get(Types* t)` |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 884 | template <typename T> |
| 885 | struct CToAST {}; |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 886 | }; |
| 887 | |
| 888 | ////////////////////////////////////////////////////////////////////////////// |
| 889 | // AST helper methods |
| 890 | ////////////////////////////////////////////////////////////////////////////// |
| 891 | |
James Price | 65ae64d | 2021-04-29 12:59:14 +0000 | [diff] [blame] | 892 | /// @return a new unnamed symbol |
| 893 | Symbol Sym() { return Symbols().New(); } |
| 894 | |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 895 | /// @param name the symbol string |
| 896 | /// @return a Symbol with the given name |
| 897 | Symbol Sym(const std::string& name) { return Symbols().Register(name); } |
| 898 | |
| 899 | /// @param sym the symbol |
| 900 | /// @return `sym` |
| 901 | Symbol Sym(Symbol sym) { return sym; } |
| 902 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 903 | /// @param expr the expression |
| 904 | /// @return expr |
Ben Clayton | 6d612ad | 2021-02-24 14:15:02 +0000 | [diff] [blame] | 905 | template <typename T> |
| 906 | traits::EnableIfIsType<T, ast::Expression>* Expr(T* expr) { |
| 907 | return expr; |
| 908 | } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 909 | |
Ben Clayton | b8ea591 | 2021-04-19 16:52:42 +0000 | [diff] [blame] | 910 | /// Passthrough for nullptr |
| 911 | /// @return nullptr |
| 912 | ast::IdentifierExpression* Expr(std::nullptr_t) { return nullptr; } |
| 913 | |
Ben Clayton | fe0910f | 2021-05-17 15:51:47 +0000 | [diff] [blame] | 914 | /// @param source the source information |
| 915 | /// @param symbol the identifier symbol |
| 916 | /// @return an ast::IdentifierExpression with the given symbol |
| 917 | ast::IdentifierExpression* Expr(const Source& source, Symbol symbol) { |
| 918 | return create<ast::IdentifierExpression>(source, symbol); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Ben Clayton | 46d78d7 | 2021-02-10 21:34:26 +0000 | [diff] [blame] | 921 | /// @param symbol the identifier symbol |
| 922 | /// @return an ast::IdentifierExpression with the given symbol |
| 923 | ast::IdentifierExpression* Expr(Symbol symbol) { |
| 924 | return create<ast::IdentifierExpression>(symbol); |
| 925 | } |
| 926 | |
Ben Clayton | fe0910f | 2021-05-17 15:51:47 +0000 | [diff] [blame] | 927 | /// @param source the source information |
| 928 | /// @param variable the AST variable |
| 929 | /// @return an ast::IdentifierExpression with the variable's symbol |
| 930 | ast::IdentifierExpression* Expr(const Source& source, |
| 931 | ast::Variable* variable) { |
| 932 | return create<ast::IdentifierExpression>(source, variable->symbol()); |
| 933 | } |
| 934 | |
Ben Clayton | b8ea591 | 2021-04-19 16:52:42 +0000 | [diff] [blame] | 935 | /// @param variable the AST variable |
| 936 | /// @return an ast::IdentifierExpression with the variable's symbol |
| 937 | ast::IdentifierExpression* Expr(ast::Variable* variable) { |
| 938 | return create<ast::IdentifierExpression>(variable->symbol()); |
| 939 | } |
| 940 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 941 | /// @param source the source information |
| 942 | /// @param name the identifier name |
| 943 | /// @return an ast::IdentifierExpression with the given name |
Ben Clayton | fe0910f | 2021-05-17 15:51:47 +0000 | [diff] [blame] | 944 | ast::IdentifierExpression* Expr(const Source& source, const char* name) { |
| 945 | return create<ast::IdentifierExpression>(source, Symbols().Register(name)); |
| 946 | } |
| 947 | |
| 948 | /// @param name the identifier name |
| 949 | /// @return an ast::IdentifierExpression with the given name |
| 950 | ast::IdentifierExpression* Expr(const char* name) { |
| 951 | return create<ast::IdentifierExpression>(Symbols().Register(name)); |
| 952 | } |
| 953 | |
| 954 | /// @param source the source information |
| 955 | /// @param name the identifier name |
| 956 | /// @return an ast::IdentifierExpression with the given name |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 957 | ast::IdentifierExpression* Expr(const Source& source, |
| 958 | const std::string& name) { |
| 959 | return create<ast::IdentifierExpression>(source, Symbols().Register(name)); |
| 960 | } |
| 961 | |
| 962 | /// @param name the identifier name |
| 963 | /// @return an ast::IdentifierExpression with the given name |
Ben Clayton | fe0910f | 2021-05-17 15:51:47 +0000 | [diff] [blame] | 964 | ast::IdentifierExpression* Expr(const std::string& name) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 965 | return create<ast::IdentifierExpression>(Symbols().Register(name)); |
| 966 | } |
| 967 | |
Ben Clayton | fe0910f | 2021-05-17 15:51:47 +0000 | [diff] [blame] | 968 | /// @param source the source information |
| 969 | /// @param value the boolean value |
| 970 | /// @return a Scalar constructor for the given value |
| 971 | ast::ScalarConstructorExpression* Expr(const Source& source, bool value) { |
| 972 | return create<ast::ScalarConstructorExpression>(source, Literal(value)); |
| 973 | } |
| 974 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 975 | /// @param value the boolean value |
| 976 | /// @return a Scalar constructor for the given value |
| 977 | ast::ScalarConstructorExpression* Expr(bool value) { |
| 978 | return create<ast::ScalarConstructorExpression>(Literal(value)); |
| 979 | } |
| 980 | |
Ben Clayton | fe0910f | 2021-05-17 15:51:47 +0000 | [diff] [blame] | 981 | /// @param source the source information |
| 982 | /// @param value the float value |
| 983 | /// @return a Scalar constructor for the given value |
| 984 | ast::ScalarConstructorExpression* Expr(const Source& source, f32 value) { |
| 985 | return create<ast::ScalarConstructorExpression>(source, Literal(value)); |
| 986 | } |
| 987 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 988 | /// @param value the float value |
| 989 | /// @return a Scalar constructor for the given value |
| 990 | ast::ScalarConstructorExpression* Expr(f32 value) { |
| 991 | return create<ast::ScalarConstructorExpression>(Literal(value)); |
| 992 | } |
| 993 | |
Ben Clayton | fe0910f | 2021-05-17 15:51:47 +0000 | [diff] [blame] | 994 | /// @param source the source information |
| 995 | /// @param value the integer value |
| 996 | /// @return a Scalar constructor for the given value |
| 997 | ast::ScalarConstructorExpression* Expr(const Source& source, i32 value) { |
| 998 | return create<ast::ScalarConstructorExpression>(source, Literal(value)); |
| 999 | } |
| 1000 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1001 | /// @param value the integer value |
| 1002 | /// @return a Scalar constructor for the given value |
| 1003 | ast::ScalarConstructorExpression* Expr(i32 value) { |
| 1004 | return create<ast::ScalarConstructorExpression>(Literal(value)); |
| 1005 | } |
| 1006 | |
Ben Clayton | fe0910f | 2021-05-17 15:51:47 +0000 | [diff] [blame] | 1007 | /// @param source the source information |
| 1008 | /// @param value the unsigned int value |
| 1009 | /// @return a Scalar constructor for the given value |
| 1010 | ast::ScalarConstructorExpression* Expr(const Source& source, u32 value) { |
| 1011 | return create<ast::ScalarConstructorExpression>(source, Literal(value)); |
| 1012 | } |
| 1013 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1014 | /// @param value the unsigned int value |
| 1015 | /// @return a Scalar constructor for the given value |
| 1016 | ast::ScalarConstructorExpression* Expr(u32 value) { |
| 1017 | return create<ast::ScalarConstructorExpression>(Literal(value)); |
| 1018 | } |
| 1019 | |
| 1020 | /// Converts `arg` to an `ast::Expression` using `Expr()`, then appends it to |
| 1021 | /// `list`. |
| 1022 | /// @param list the list to append too |
| 1023 | /// @param arg the arg to create |
| 1024 | template <typename ARG> |
| 1025 | void Append(ast::ExpressionList& list, ARG&& arg) { |
| 1026 | list.emplace_back(Expr(std::forward<ARG>(arg))); |
| 1027 | } |
| 1028 | |
| 1029 | /// Converts `arg0` and `args` to `ast::Expression`s using `Expr()`, |
| 1030 | /// then appends them to `list`. |
| 1031 | /// @param list the list to append too |
| 1032 | /// @param arg0 the first argument |
| 1033 | /// @param args the rest of the arguments |
| 1034 | template <typename ARG0, typename... ARGS> |
| 1035 | void Append(ast::ExpressionList& list, ARG0&& arg0, ARGS&&... args) { |
| 1036 | Append(list, std::forward<ARG0>(arg0)); |
| 1037 | Append(list, std::forward<ARGS>(args)...); |
| 1038 | } |
| 1039 | |
| 1040 | /// @return an empty list of expressions |
| 1041 | ast::ExpressionList ExprList() { return {}; } |
| 1042 | |
| 1043 | /// @param args the list of expressions |
| 1044 | /// @return the list of expressions converted to `ast::Expression`s using |
| 1045 | /// `Expr()`, |
| 1046 | template <typename... ARGS> |
| 1047 | ast::ExpressionList ExprList(ARGS&&... args) { |
| 1048 | ast::ExpressionList list; |
| 1049 | list.reserve(sizeof...(args)); |
| 1050 | Append(list, std::forward<ARGS>(args)...); |
| 1051 | return list; |
| 1052 | } |
| 1053 | |
| 1054 | /// @param list the list of expressions |
| 1055 | /// @return `list` |
| 1056 | ast::ExpressionList ExprList(ast::ExpressionList list) { return list; } |
| 1057 | |
| 1058 | /// @param val the boolan value |
| 1059 | /// @return a boolean literal with the given value |
Ben Clayton | 109b18f | 2021-04-28 13:50:43 +0000 | [diff] [blame] | 1060 | ast::BoolLiteral* Literal(bool val) { return create<ast::BoolLiteral>(val); } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1061 | |
| 1062 | /// @param val the float value |
| 1063 | /// @return a float literal with the given value |
Ben Clayton | 109b18f | 2021-04-28 13:50:43 +0000 | [diff] [blame] | 1064 | ast::FloatLiteral* Literal(f32 val) { return create<ast::FloatLiteral>(val); } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1065 | |
| 1066 | /// @param val the unsigned int value |
| 1067 | /// @return a ast::UintLiteral with the given value |
Ben Clayton | 109b18f | 2021-04-28 13:50:43 +0000 | [diff] [blame] | 1068 | ast::UintLiteral* Literal(u32 val) { return create<ast::UintLiteral>(val); } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1069 | |
| 1070 | /// @param val the integer value |
| 1071 | /// @return the ast::SintLiteral with the given value |
Ben Clayton | 109b18f | 2021-04-28 13:50:43 +0000 | [diff] [blame] | 1072 | ast::SintLiteral* Literal(i32 val) { return create<ast::SintLiteral>(val); } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1073 | |
| 1074 | /// @param args the arguments for the type constructor |
| 1075 | /// @return an `ast::TypeConstructorExpression` of type `ty`, with the values |
| 1076 | /// of `args` converted to `ast::Expression`s using `Expr()` |
| 1077 | template <typename T, typename... ARGS> |
| 1078 | ast::TypeConstructorExpression* Construct(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1079 | return Construct(ty.Of<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | /// @param type the type to construct |
| 1083 | /// @param args the arguments for the constructor |
| 1084 | /// @return an `ast::TypeConstructorExpression` of `type` constructed with the |
| 1085 | /// values `args`. |
| 1086 | template <typename... ARGS> |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1087 | ast::TypeConstructorExpression* Construct(ast::Type* type, ARGS&&... args) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1088 | return create<ast::TypeConstructorExpression>( |
| 1089 | type, ExprList(std::forward<ARGS>(args)...)); |
| 1090 | } |
| 1091 | |
Ben Clayton | 313e618 | 2021-06-17 19:56:14 +0000 | [diff] [blame] | 1092 | /// @param source the source information |
| 1093 | /// @param type the type to construct |
| 1094 | /// @param args the arguments for the constructor |
| 1095 | /// @return an `ast::TypeConstructorExpression` of `type` constructed with the |
| 1096 | /// values `args`. |
| 1097 | template <typename... ARGS> |
| 1098 | ast::TypeConstructorExpression* Construct(const Source& source, |
| 1099 | ast::Type* type, |
| 1100 | ARGS&&... args) { |
| 1101 | return create<ast::TypeConstructorExpression>( |
| 1102 | source, type, ExprList(std::forward<ARGS>(args)...)); |
| 1103 | } |
| 1104 | |
Ben Clayton | d960328 | 2021-06-29 12:37:45 +0000 | [diff] [blame^] | 1105 | /// @param expr the expression for the bitcast |
| 1106 | /// @return an `ast::BitcastExpression` of type `ty`, with the values of |
| 1107 | /// `expr` converted to `ast::Expression`s using `Expr()` |
| 1108 | template <typename T, typename EXPR> |
| 1109 | ast::BitcastExpression* Bitcast(EXPR&& expr) { |
| 1110 | return Bitcast(ty.Of<T>(), std::forward<EXPR>(expr)); |
| 1111 | } |
| 1112 | |
| 1113 | /// @param type the type to cast to |
| 1114 | /// @param expr the expression for the bitcast |
| 1115 | /// @return an `ast::BitcastExpression` of `type` constructed with the values |
| 1116 | /// `expr`. |
| 1117 | template <typename EXPR> |
| 1118 | ast::BitcastExpression* Bitcast(ast::Type* type, EXPR&& expr) { |
| 1119 | return create<ast::BitcastExpression>(type, Expr(std::forward<EXPR>(expr))); |
| 1120 | } |
| 1121 | |
| 1122 | /// @param source the source information |
| 1123 | /// @param type the type to cast to |
| 1124 | /// @param expr the expression for the bitcast |
| 1125 | /// @return an `ast::BitcastExpression` of `type` constructed with the values |
| 1126 | /// `expr`. |
| 1127 | template <typename EXPR> |
| 1128 | ast::BitcastExpression* Bitcast(const Source& source, |
| 1129 | ast::Type* type, |
| 1130 | EXPR&& expr) { |
| 1131 | return create<ast::BitcastExpression>(source, type, |
| 1132 | Expr(std::forward<EXPR>(expr))); |
| 1133 | } |
| 1134 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1135 | /// @param args the arguments for the vector constructor |
Antonio Maiorano | 0507273 | 2021-06-18 14:59:51 +0000 | [diff] [blame] | 1136 | /// @param type the vector type |
| 1137 | /// @param size the vector size |
| 1138 | /// @return an `ast::TypeConstructorExpression` of a `size`-element vector of |
| 1139 | /// type `type`, constructed with the values `args`. |
| 1140 | template <typename... ARGS> |
| 1141 | ast::TypeConstructorExpression* vec(ast::Type* type, |
| 1142 | uint32_t size, |
| 1143 | ARGS&&... args) { |
| 1144 | return Construct(ty.vec(type, size), std::forward<ARGS>(args)...); |
| 1145 | } |
| 1146 | |
| 1147 | /// @param args the arguments for the vector constructor |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1148 | /// @return an `ast::TypeConstructorExpression` of a 2-element vector of type |
| 1149 | /// `T`, constructed with the values `args`. |
| 1150 | template <typename T, typename... ARGS> |
| 1151 | ast::TypeConstructorExpression* vec2(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1152 | return Construct(ty.vec2<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | /// @param args the arguments for the vector constructor |
| 1156 | /// @return an `ast::TypeConstructorExpression` of a 3-element vector of type |
| 1157 | /// `T`, constructed with the values `args`. |
| 1158 | template <typename T, typename... ARGS> |
| 1159 | ast::TypeConstructorExpression* vec3(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1160 | return Construct(ty.vec3<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | /// @param args the arguments for the vector constructor |
| 1164 | /// @return an `ast::TypeConstructorExpression` of a 4-element vector of type |
| 1165 | /// `T`, constructed with the values `args`. |
| 1166 | template <typename T, typename... ARGS> |
| 1167 | ast::TypeConstructorExpression* vec4(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1168 | return Construct(ty.vec4<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | /// @param args the arguments for the matrix constructor |
| 1172 | /// @return an `ast::TypeConstructorExpression` of a 2x2 matrix of type |
| 1173 | /// `T`, constructed with the values `args`. |
| 1174 | template <typename T, typename... ARGS> |
| 1175 | ast::TypeConstructorExpression* mat2x2(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1176 | return Construct(ty.mat2x2<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | /// @param args the arguments for the matrix constructor |
| 1180 | /// @return an `ast::TypeConstructorExpression` of a 2x3 matrix of type |
| 1181 | /// `T`, constructed with the values `args`. |
| 1182 | template <typename T, typename... ARGS> |
| 1183 | ast::TypeConstructorExpression* mat2x3(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1184 | return Construct(ty.mat2x3<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | /// @param args the arguments for the matrix constructor |
| 1188 | /// @return an `ast::TypeConstructorExpression` of a 2x4 matrix of type |
| 1189 | /// `T`, constructed with the values `args`. |
| 1190 | template <typename T, typename... ARGS> |
| 1191 | ast::TypeConstructorExpression* mat2x4(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1192 | return Construct(ty.mat2x4<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | /// @param args the arguments for the matrix constructor |
| 1196 | /// @return an `ast::TypeConstructorExpression` of a 3x2 matrix of type |
| 1197 | /// `T`, constructed with the values `args`. |
| 1198 | template <typename T, typename... ARGS> |
| 1199 | ast::TypeConstructorExpression* mat3x2(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1200 | return Construct(ty.mat3x2<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | /// @param args the arguments for the matrix constructor |
| 1204 | /// @return an `ast::TypeConstructorExpression` of a 3x3 matrix of type |
| 1205 | /// `T`, constructed with the values `args`. |
| 1206 | template <typename T, typename... ARGS> |
| 1207 | ast::TypeConstructorExpression* mat3x3(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1208 | return Construct(ty.mat3x3<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | /// @param args the arguments for the matrix constructor |
| 1212 | /// @return an `ast::TypeConstructorExpression` of a 3x4 matrix of type |
| 1213 | /// `T`, constructed with the values `args`. |
| 1214 | template <typename T, typename... ARGS> |
| 1215 | ast::TypeConstructorExpression* mat3x4(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1216 | return Construct(ty.mat3x4<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | /// @param args the arguments for the matrix constructor |
| 1220 | /// @return an `ast::TypeConstructorExpression` of a 4x2 matrix of type |
| 1221 | /// `T`, constructed with the values `args`. |
| 1222 | template <typename T, typename... ARGS> |
| 1223 | ast::TypeConstructorExpression* mat4x2(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1224 | return Construct(ty.mat4x2<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | /// @param args the arguments for the matrix constructor |
| 1228 | /// @return an `ast::TypeConstructorExpression` of a 4x3 matrix of type |
| 1229 | /// `T`, constructed with the values `args`. |
| 1230 | template <typename T, typename... ARGS> |
| 1231 | ast::TypeConstructorExpression* mat4x3(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1232 | return Construct(ty.mat4x3<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | /// @param args the arguments for the matrix constructor |
| 1236 | /// @return an `ast::TypeConstructorExpression` of a 4x4 matrix of type |
| 1237 | /// `T`, constructed with the values `args`. |
| 1238 | template <typename T, typename... ARGS> |
| 1239 | ast::TypeConstructorExpression* mat4x4(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1240 | return Construct(ty.mat4x4<T>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | /// @param args the arguments for the array constructor |
| 1244 | /// @return an `ast::TypeConstructorExpression` of an array with element type |
| 1245 | /// `T`, constructed with the values `args`. |
| 1246 | template <typename T, int N = 0, typename... ARGS> |
| 1247 | ast::TypeConstructorExpression* array(ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1248 | return Construct(ty.array<T, N>(), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | /// @param subtype the array element type |
| 1252 | /// @param n the array size. 0 represents a runtime-array. |
| 1253 | /// @param args the arguments for the array constructor |
| 1254 | /// @return an `ast::TypeConstructorExpression` of an array with element type |
| 1255 | /// `subtype`, constructed with the values `args`. |
| 1256 | template <typename... ARGS> |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1257 | ast::TypeConstructorExpression* array(ast::Type* subtype, |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1258 | uint32_t n, |
| 1259 | ARGS&&... args) { |
Ben Clayton | 0f88b31 | 2021-05-04 17:36:31 +0000 | [diff] [blame] | 1260 | return Construct(ty.array(subtype, n), std::forward<ARGS>(args)...); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | /// @param name the variable name |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1264 | /// @param type the variable type |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1265 | /// @param optional the optional variable settings. |
| 1266 | /// Can be any of the following, in any order: |
| 1267 | /// * ast::StorageClass - specifies the variable storage class |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 1268 | /// * ast::Access - specifies the variable's access control |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1269 | /// * ast::Expression* - specifies the variable's initializer expression |
| 1270 | /// * ast::DecorationList - specifies the variable's decorations |
| 1271 | /// Note that repeated arguments of the same type will use the last argument's |
| 1272 | /// value. |
| 1273 | /// @returns a `ast::Variable` with the given name, type and additional |
| 1274 | /// options |
| 1275 | template <typename NAME, typename... OPTIONAL> |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1276 | ast::Variable* Var(NAME&& name, |
Antonio Maiorano | dc4e6c1 | 2021-05-14 17:51:13 +0000 | [diff] [blame] | 1277 | const ast::Type* type, |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1278 | OPTIONAL&&... optional) { |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1279 | VarOptionals opts(std::forward<OPTIONAL>(optional)...); |
| 1280 | return create<ast::Variable>(Sym(std::forward<NAME>(name)), opts.storage, |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 1281 | opts.access, type, false, opts.constructor, |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1282 | std::move(opts.decorations)); |
Ben Clayton | 46d78d7 | 2021-02-10 21:34:26 +0000 | [diff] [blame] | 1283 | } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1284 | |
| 1285 | /// @param source the variable source |
| 1286 | /// @param name the variable name |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1287 | /// @param type the variable type |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1288 | /// @param optional the optional variable settings. |
| 1289 | /// Can be any of the following, in any order: |
| 1290 | /// * ast::StorageClass - specifies the variable storage class |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 1291 | /// * ast::Access - specifies the variable's access control |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1292 | /// * ast::Expression* - specifies the variable's initializer expression |
| 1293 | /// * ast::DecorationList - specifies the variable's decorations |
| 1294 | /// Note that repeated arguments of the same type will use the last argument's |
| 1295 | /// value. |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1296 | /// @returns a `ast::Variable` with the given name, storage and type |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1297 | template <typename NAME, typename... OPTIONAL> |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1298 | ast::Variable* Var(const Source& source, |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1299 | NAME&& name, |
Antonio Maiorano | dc4e6c1 | 2021-05-14 17:51:13 +0000 | [diff] [blame] | 1300 | const ast::Type* type, |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1301 | OPTIONAL&&... optional) { |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1302 | VarOptionals opts(std::forward<OPTIONAL>(optional)...); |
| 1303 | return create<ast::Variable>(source, Sym(std::forward<NAME>(name)), |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 1304 | opts.storage, opts.access, type, false, |
| 1305 | opts.constructor, std::move(opts.decorations)); |
Ben Clayton | 46d78d7 | 2021-02-10 21:34:26 +0000 | [diff] [blame] | 1306 | } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1307 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1308 | /// @param name the variable name |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1309 | /// @param type the variable type |
Antonio Maiorano | e0448d3 | 2021-05-10 20:42:56 +0000 | [diff] [blame] | 1310 | /// @param constructor constructor expression |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1311 | /// @param decorations optional variable decorations |
James Price | daf1f1c | 2021-04-08 22:15:48 +0000 | [diff] [blame] | 1312 | /// @returns a constant `ast::Variable` with the given name and type |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1313 | template <typename NAME> |
| 1314 | ast::Variable* Const(NAME&& name, |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1315 | ast::Type* type, |
Antonio Maiorano | e0448d3 | 2021-05-10 20:42:56 +0000 | [diff] [blame] | 1316 | ast::Expression* constructor, |
James Price | 95d4077 | 2021-03-11 17:39:32 +0000 | [diff] [blame] | 1317 | ast::DecorationList decorations = {}) { |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 1318 | return create<ast::Variable>( |
| 1319 | Sym(std::forward<NAME>(name)), ast::StorageClass::kNone, |
| 1320 | ast::Access::kUndefined, type, true, constructor, decorations); |
Ben Clayton | 46d78d7 | 2021-02-10 21:34:26 +0000 | [diff] [blame] | 1321 | } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1322 | |
| 1323 | /// @param source the variable source |
| 1324 | /// @param name the variable name |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1325 | /// @param type the variable type |
Antonio Maiorano | e0448d3 | 2021-05-10 20:42:56 +0000 | [diff] [blame] | 1326 | /// @param constructor constructor expression |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1327 | /// @param decorations optional variable decorations |
James Price | daf1f1c | 2021-04-08 22:15:48 +0000 | [diff] [blame] | 1328 | /// @returns a constant `ast::Variable` with the given name and type |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1329 | template <typename NAME> |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1330 | ast::Variable* Const(const Source& source, |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1331 | NAME&& name, |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1332 | ast::Type* type, |
Antonio Maiorano | e0448d3 | 2021-05-10 20:42:56 +0000 | [diff] [blame] | 1333 | ast::Expression* constructor, |
James Price | 95d4077 | 2021-03-11 17:39:32 +0000 | [diff] [blame] | 1334 | ast::DecorationList decorations = {}) { |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 1335 | return create<ast::Variable>( |
| 1336 | source, Sym(std::forward<NAME>(name)), ast::StorageClass::kNone, |
| 1337 | ast::Access::kUndefined, type, true, constructor, decorations); |
Ben Clayton | 46d78d7 | 2021-02-10 21:34:26 +0000 | [diff] [blame] | 1338 | } |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1339 | |
James Price | daf1f1c | 2021-04-08 22:15:48 +0000 | [diff] [blame] | 1340 | /// @param name the parameter name |
| 1341 | /// @param type the parameter type |
| 1342 | /// @param decorations optional parameter decorations |
| 1343 | /// @returns a constant `ast::Variable` with the given name and type |
| 1344 | template <typename NAME> |
| 1345 | ast::Variable* Param(NAME&& name, |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1346 | ast::Type* type, |
James Price | daf1f1c | 2021-04-08 22:15:48 +0000 | [diff] [blame] | 1347 | ast::DecorationList decorations = {}) { |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 1348 | return create<ast::Variable>( |
| 1349 | Sym(std::forward<NAME>(name)), ast::StorageClass::kNone, |
| 1350 | ast::Access::kUndefined, type, true, nullptr, decorations); |
James Price | daf1f1c | 2021-04-08 22:15:48 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | /// @param source the parameter source |
| 1354 | /// @param name the parameter name |
| 1355 | /// @param type the parameter type |
| 1356 | /// @param decorations optional parameter decorations |
| 1357 | /// @returns a constant `ast::Variable` with the given name and type |
| 1358 | template <typename NAME> |
| 1359 | ast::Variable* Param(const Source& source, |
| 1360 | NAME&& name, |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1361 | ast::Type* type, |
James Price | daf1f1c | 2021-04-08 22:15:48 +0000 | [diff] [blame] | 1362 | ast::DecorationList decorations = {}) { |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 1363 | return create<ast::Variable>( |
| 1364 | source, Sym(std::forward<NAME>(name)), ast::StorageClass::kNone, |
| 1365 | ast::Access::kUndefined, type, true, nullptr, decorations); |
James Price | daf1f1c | 2021-04-08 22:15:48 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Ben Clayton | 4270834 | 2021-04-21 17:55:12 +0000 | [diff] [blame] | 1368 | /// @param name the variable name |
| 1369 | /// @param type the variable type |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1370 | /// @param optional the optional variable settings. |
| 1371 | /// Can be any of the following, in any order: |
| 1372 | /// * ast::StorageClass - specifies the variable storage class |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 1373 | /// * ast::Access - specifies the variable's access control |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1374 | /// * ast::Expression* - specifies the variable's initializer expression |
| 1375 | /// * ast::DecorationList - specifies the variable's decorations |
| 1376 | /// Note that repeated arguments of the same type will use the last argument's |
| 1377 | /// value. |
Ben Clayton | 4270834 | 2021-04-21 17:55:12 +0000 | [diff] [blame] | 1378 | /// @returns a new `ast::Variable`, which is automatically registered as a |
| 1379 | /// global variable with the ast::Module. |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1380 | template <typename NAME, typename... OPTIONAL> |
Ben Clayton | 4270834 | 2021-04-21 17:55:12 +0000 | [diff] [blame] | 1381 | ast::Variable* Global(NAME&& name, |
Antonio Maiorano | dc4e6c1 | 2021-05-14 17:51:13 +0000 | [diff] [blame] | 1382 | const ast::Type* type, |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1383 | OPTIONAL&&... optional) { |
| 1384 | auto* var = Var(std::forward<NAME>(name), type, |
| 1385 | std::forward<OPTIONAL>(optional)...); |
Ben Clayton | 4270834 | 2021-04-21 17:55:12 +0000 | [diff] [blame] | 1386 | AST().AddGlobalVariable(var); |
| 1387 | return var; |
| 1388 | } |
| 1389 | |
| 1390 | /// @param source the variable source |
| 1391 | /// @param name the variable name |
| 1392 | /// @param type the variable type |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1393 | /// @param optional the optional variable settings. |
| 1394 | /// Can be any of the following, in any order: |
| 1395 | /// * ast::StorageClass - specifies the variable storage class |
Ben Clayton | 93e8f52 | 2021-06-04 20:41:47 +0000 | [diff] [blame] | 1396 | /// * ast::Access - specifies the variable's access control |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1397 | /// * ast::Expression* - specifies the variable's initializer expression |
| 1398 | /// * ast::DecorationList - specifies the variable's decorations |
| 1399 | /// Note that repeated arguments of the same type will use the last argument's |
| 1400 | /// value. |
Ben Clayton | 4270834 | 2021-04-21 17:55:12 +0000 | [diff] [blame] | 1401 | /// @returns a new `ast::Variable`, which is automatically registered as a |
| 1402 | /// global variable with the ast::Module. |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1403 | template <typename NAME, typename... OPTIONAL> |
Ben Clayton | 4270834 | 2021-04-21 17:55:12 +0000 | [diff] [blame] | 1404 | ast::Variable* Global(const Source& source, |
| 1405 | NAME&& name, |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1406 | ast::Type* type, |
Ben Clayton | 620d77e | 2021-06-04 19:55:08 +0000 | [diff] [blame] | 1407 | OPTIONAL&&... optional) { |
| 1408 | auto* var = Var(source, std::forward<NAME>(name), type, |
| 1409 | std::forward<OPTIONAL>(optional)...); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1410 | AST().AddGlobalVariable(var); |
| 1411 | return var; |
| 1412 | } |
| 1413 | |
Antonio Maiorano | e0448d3 | 2021-05-10 20:42:56 +0000 | [diff] [blame] | 1414 | /// @param name the variable name |
| 1415 | /// @param type the variable type |
| 1416 | /// @param constructor constructor expression |
| 1417 | /// @param decorations optional variable decorations |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1418 | /// @returns a const `ast::Variable` constructed by calling Var() with the |
| 1419 | /// arguments of `args`, which is automatically registered as a global |
| 1420 | /// variable with the ast::Module. |
Antonio Maiorano | e0448d3 | 2021-05-10 20:42:56 +0000 | [diff] [blame] | 1421 | template <typename NAME> |
| 1422 | ast::Variable* GlobalConst(NAME&& name, |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 1423 | ast::Type* type, |
Antonio Maiorano | e0448d3 | 2021-05-10 20:42:56 +0000 | [diff] [blame] | 1424 | ast::Expression* constructor, |
| 1425 | ast::DecorationList decorations = {}) { |
| 1426 | auto* var = Const(std::forward<NAME>(name), type, constructor, |
| 1427 | std::move(decorations)); |
| 1428 | AST().AddGlobalVariable(var); |
| 1429 | return var; |
| 1430 | } |
| 1431 | |
| 1432 | /// @param source the variable source |
| 1433 | /// @param name the variable name |
| 1434 | /// @param type the variable type |
| 1435 | /// @param constructor constructor expression |
| 1436 | /// @param decorations optional variable decorations |
| 1437 | /// @returns a const `ast::Variable` constructed by calling Var() with the |
| 1438 | /// arguments of `args`, which is automatically registered as a global |
| 1439 | /// variable with the ast::Module. |
| 1440 | template <typename NAME> |
| 1441 | ast::Variable* GlobalConst(const Source& source, |
| 1442 | NAME&& name, |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 1443 | ast::Type* type, |
Antonio Maiorano | e0448d3 | 2021-05-10 20:42:56 +0000 | [diff] [blame] | 1444 | ast::Expression* constructor, |
| 1445 | ast::DecorationList decorations = {}) { |
| 1446 | auto* var = Const(source, std::forward<NAME>(name), type, constructor, |
| 1447 | std::move(decorations)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 1448 | AST().AddGlobalVariable(var); |
| 1449 | return var; |
| 1450 | } |
| 1451 | |
Ben Clayton | fe0910f | 2021-05-17 15:51:47 +0000 | [diff] [blame] | 1452 | /// @param source the source information |
| 1453 | /// @param expr the expression to take the address of |
| 1454 | /// @return an ast::UnaryOpExpression that takes the address of `expr` |
| 1455 | template <typename EXPR> |
| 1456 | ast::UnaryOpExpression* AddressOf(const Source& source, EXPR&& expr) { |
| 1457 | return create<ast::UnaryOpExpression>(source, ast::UnaryOp::kAddressOf, |
| 1458 | Expr(std::forward<EXPR>(expr))); |
| 1459 | } |
| 1460 | |
| 1461 | /// @param expr the expression to take the address of |
| 1462 | /// @return an ast::UnaryOpExpression that takes the address of `expr` |
| 1463 | template <typename EXPR> |
| 1464 | ast::UnaryOpExpression* AddressOf(EXPR&& expr) { |
| 1465 | return create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, |
| 1466 | Expr(std::forward<EXPR>(expr))); |
| 1467 | } |
| 1468 | |
| 1469 | /// @param source the source information |
| 1470 | /// @param expr the expression to perform an indirection on |
| 1471 | /// @return an ast::UnaryOpExpression that dereferences the pointer `expr` |
| 1472 | template <typename EXPR> |
| 1473 | ast::UnaryOpExpression* Deref(const Source& source, EXPR&& expr) { |
| 1474 | return create<ast::UnaryOpExpression>(source, ast::UnaryOp::kIndirection, |
| 1475 | Expr(std::forward<EXPR>(expr))); |
| 1476 | } |
| 1477 | |
| 1478 | /// @param expr the expression to perform an indirection on |
| 1479 | /// @return an ast::UnaryOpExpression that dereferences the pointer `expr` |
| 1480 | template <typename EXPR> |
| 1481 | ast::UnaryOpExpression* Deref(EXPR&& expr) { |
| 1482 | return create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, |
| 1483 | Expr(std::forward<EXPR>(expr))); |
| 1484 | } |
| 1485 | |
Antonio Maiorano | 14b3403 | 2021-06-09 20:17:59 +0000 | [diff] [blame] | 1486 | /// @param source the source information |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1487 | /// @param func the function name |
| 1488 | /// @param args the function call arguments |
| 1489 | /// @returns a `ast::CallExpression` to the function `func`, with the |
| 1490 | /// arguments of `args` converted to `ast::Expression`s using `Expr()`. |
| 1491 | template <typename NAME, typename... ARGS> |
Antonio Maiorano | 14b3403 | 2021-06-09 20:17:59 +0000 | [diff] [blame] | 1492 | ast::CallExpression* Call(const Source& source, NAME&& func, ARGS&&... args) { |
| 1493 | return create<ast::CallExpression>(source, Expr(func), |
| 1494 | ExprList(std::forward<ARGS>(args)...)); |
| 1495 | } |
| 1496 | |
| 1497 | /// @param func the function name |
| 1498 | /// @param args the function call arguments |
| 1499 | /// @returns a `ast::CallExpression` to the function `func`, with the |
| 1500 | /// arguments of `args` converted to `ast::Expression`s using `Expr()`. |
| 1501 | template <typename NAME, |
| 1502 | typename... ARGS, |
| 1503 | traits::EnableIfIsNotType<traits::Decay<NAME>, Source>* = nullptr> |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1504 | ast::CallExpression* Call(NAME&& func, ARGS&&... args) { |
| 1505 | return create<ast::CallExpression>(Expr(func), |
| 1506 | ExprList(std::forward<ARGS>(args)...)); |
| 1507 | } |
| 1508 | |
Ben Clayton | 7fe0106 | 2021-06-11 13:22:27 +0000 | [diff] [blame] | 1509 | /// @param expr the expression to ignore |
| 1510 | /// @returns a `ast::CallStatement` that calls the `ignore` intrinsic which is |
| 1511 | /// passed the single `expr` argument |
| 1512 | template <typename EXPR> |
| 1513 | ast::CallStatement* Ignore(EXPR&& expr) { |
| 1514 | return create<ast::CallStatement>(Call("ignore", Expr(expr))); |
| 1515 | } |
| 1516 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1517 | /// @param lhs the left hand argument to the addition operation |
| 1518 | /// @param rhs the right hand argument to the addition operation |
| 1519 | /// @returns a `ast::BinaryExpression` summing the arguments `lhs` and `rhs` |
| 1520 | template <typename LHS, typename RHS> |
Antonio Maiorano | 61dabab | 2021-04-01 19:58:37 +0000 | [diff] [blame] | 1521 | ast::BinaryExpression* Add(LHS&& lhs, RHS&& rhs) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1522 | return create<ast::BinaryExpression>(ast::BinaryOp::kAdd, |
| 1523 | Expr(std::forward<LHS>(lhs)), |
| 1524 | Expr(std::forward<RHS>(rhs))); |
| 1525 | } |
| 1526 | |
James Price | c32e8f6 | 2021-06-22 20:08:29 +0000 | [diff] [blame] | 1527 | /// @param lhs the left hand argument to the and operation |
| 1528 | /// @param rhs the right hand argument to the and operation |
| 1529 | /// @returns a `ast::BinaryExpression` bitwise anding `lhs` and `rhs` |
| 1530 | template <typename LHS, typename RHS> |
| 1531 | ast::BinaryExpression* And(LHS&& lhs, RHS&& rhs) { |
| 1532 | return create<ast::BinaryExpression>(ast::BinaryOp::kAnd, |
| 1533 | Expr(std::forward<LHS>(lhs)), |
| 1534 | Expr(std::forward<RHS>(rhs))); |
| 1535 | } |
| 1536 | |
Ben Clayton | d960328 | 2021-06-29 12:37:45 +0000 | [diff] [blame^] | 1537 | /// @param lhs the left hand argument to the or operation |
| 1538 | /// @param rhs the right hand argument to the or operation |
| 1539 | /// @returns a `ast::BinaryExpression` bitwise or-ing `lhs` and `rhs` |
| 1540 | template <typename LHS, typename RHS> |
| 1541 | ast::BinaryExpression* Or(LHS&& lhs, RHS&& rhs) { |
| 1542 | return create<ast::BinaryExpression>(ast::BinaryOp::kOr, |
| 1543 | Expr(std::forward<LHS>(lhs)), |
| 1544 | Expr(std::forward<RHS>(rhs))); |
| 1545 | } |
| 1546 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1547 | /// @param lhs the left hand argument to the subtraction operation |
| 1548 | /// @param rhs the right hand argument to the subtraction operation |
| 1549 | /// @returns a `ast::BinaryExpression` subtracting `rhs` from `lhs` |
| 1550 | template <typename LHS, typename RHS> |
Antonio Maiorano | 61dabab | 2021-04-01 19:58:37 +0000 | [diff] [blame] | 1551 | ast::BinaryExpression* Sub(LHS&& lhs, RHS&& rhs) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1552 | return create<ast::BinaryExpression>(ast::BinaryOp::kSubtract, |
| 1553 | Expr(std::forward<LHS>(lhs)), |
| 1554 | Expr(std::forward<RHS>(rhs))); |
| 1555 | } |
| 1556 | |
| 1557 | /// @param lhs the left hand argument to the multiplication operation |
| 1558 | /// @param rhs the right hand argument to the multiplication operation |
| 1559 | /// @returns a `ast::BinaryExpression` multiplying `rhs` from `lhs` |
| 1560 | template <typename LHS, typename RHS> |
Antonio Maiorano | 61dabab | 2021-04-01 19:58:37 +0000 | [diff] [blame] | 1561 | ast::BinaryExpression* Mul(LHS&& lhs, RHS&& rhs) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1562 | return create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, |
| 1563 | Expr(std::forward<LHS>(lhs)), |
| 1564 | Expr(std::forward<RHS>(rhs))); |
| 1565 | } |
| 1566 | |
Antonio Maiorano | 61dabab | 2021-04-01 19:58:37 +0000 | [diff] [blame] | 1567 | /// @param source the source information |
| 1568 | /// @param lhs the left hand argument to the multiplication operation |
| 1569 | /// @param rhs the right hand argument to the multiplication operation |
| 1570 | /// @returns a `ast::BinaryExpression` multiplying `rhs` from `lhs` |
| 1571 | template <typename LHS, typename RHS> |
| 1572 | ast::BinaryExpression* Mul(const Source& source, LHS&& lhs, RHS&& rhs) { |
| 1573 | return create<ast::BinaryExpression>(source, ast::BinaryOp::kMultiply, |
| 1574 | Expr(std::forward<LHS>(lhs)), |
| 1575 | Expr(std::forward<RHS>(rhs))); |
| 1576 | } |
| 1577 | |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1578 | /// @param lhs the left hand argument to the division operation |
| 1579 | /// @param rhs the right hand argument to the division operation |
| 1580 | /// @returns a `ast::BinaryExpression` dividing `lhs` by `rhs` |
| 1581 | template <typename LHS, typename RHS> |
| 1582 | ast::Expression* Div(LHS&& lhs, RHS&& rhs) { |
| 1583 | return create<ast::BinaryExpression>(ast::BinaryOp::kDivide, |
| 1584 | Expr(std::forward<LHS>(lhs)), |
| 1585 | Expr(std::forward<RHS>(rhs))); |
| 1586 | } |
| 1587 | |
Ben Clayton | d960328 | 2021-06-29 12:37:45 +0000 | [diff] [blame^] | 1588 | /// @param lhs the left hand argument to the bit shift right operation |
| 1589 | /// @param rhs the right hand argument to the bit shift right operation |
| 1590 | /// @returns a `ast::BinaryExpression` bit shifting right `lhs` by `rhs` |
| 1591 | template <typename LHS, typename RHS> |
| 1592 | ast::BinaryExpression* Shr(LHS&& lhs, RHS&& rhs) { |
| 1593 | return create<ast::BinaryExpression>(ast::BinaryOp::kShiftRight, |
| 1594 | Expr(std::forward<LHS>(lhs)), |
| 1595 | Expr(std::forward<RHS>(rhs))); |
| 1596 | } |
| 1597 | |
| 1598 | /// @param lhs the left hand argument to the bit shift left operation |
| 1599 | /// @param rhs the right hand argument to the bit shift left operation |
| 1600 | /// @returns a `ast::BinaryExpression` bit shifting left `lhs` by `rhs` |
| 1601 | template <typename LHS, typename RHS> |
| 1602 | ast::BinaryExpression* Shl(LHS&& lhs, RHS&& rhs) { |
| 1603 | return create<ast::BinaryExpression>(ast::BinaryOp::kShiftLeft, |
| 1604 | Expr(std::forward<LHS>(lhs)), |
| 1605 | Expr(std::forward<RHS>(rhs))); |
| 1606 | } |
| 1607 | |
Ben Clayton | 0597a2b | 2021-06-16 09:19:36 +0000 | [diff] [blame] | 1608 | /// @param source the source information |
| 1609 | /// @param arr the array argument for the array accessor expression |
| 1610 | /// @param idx the index argument for the array accessor expression |
| 1611 | /// @returns a `ast::ArrayAccessorExpression` that indexes `arr` with `idx` |
| 1612 | template <typename ARR, typename IDX> |
| 1613 | ast::ArrayAccessorExpression* IndexAccessor(const Source& source, |
| 1614 | ARR&& arr, |
| 1615 | IDX&& idx) { |
| 1616 | return create<ast::ArrayAccessorExpression>( |
| 1617 | source, Expr(std::forward<ARR>(arr)), Expr(std::forward<IDX>(idx))); |
| 1618 | } |
| 1619 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1620 | /// @param arr the array argument for the array accessor expression |
| 1621 | /// @param idx the index argument for the array accessor expression |
| 1622 | /// @returns a `ast::ArrayAccessorExpression` that indexes `arr` with `idx` |
| 1623 | template <typename ARR, typename IDX> |
Antonio Maiorano | 61dabab | 2021-04-01 19:58:37 +0000 | [diff] [blame] | 1624 | ast::ArrayAccessorExpression* IndexAccessor(ARR&& arr, IDX&& idx) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1625 | return create<ast::ArrayAccessorExpression>(Expr(std::forward<ARR>(arr)), |
| 1626 | Expr(std::forward<IDX>(idx))); |
| 1627 | } |
| 1628 | |
| 1629 | /// @param obj the object for the member accessor expression |
| 1630 | /// @param idx the index argument for the array accessor expression |
| 1631 | /// @returns a `ast::MemberAccessorExpression` that indexes `obj` with `idx` |
| 1632 | template <typename OBJ, typename IDX> |
Ben Clayton | 6d612ad | 2021-02-24 14:15:02 +0000 | [diff] [blame] | 1633 | ast::MemberAccessorExpression* MemberAccessor(OBJ&& obj, IDX&& idx) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1634 | return create<ast::MemberAccessorExpression>(Expr(std::forward<OBJ>(obj)), |
| 1635 | Expr(std::forward<IDX>(idx))); |
| 1636 | } |
| 1637 | |
Ben Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 1638 | /// Creates a ast::StructMemberOffsetDecoration |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1639 | /// @param val the offset value |
| 1640 | /// @returns the offset decoration pointer |
| 1641 | ast::StructMemberOffsetDecoration* MemberOffset(uint32_t val) { |
| 1642 | return create<ast::StructMemberOffsetDecoration>(source_, val); |
| 1643 | } |
| 1644 | |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1645 | /// Creates a ast::StructMemberSizeDecoration |
| 1646 | /// @param source the source information |
| 1647 | /// @param val the size value |
| 1648 | /// @returns the size decoration pointer |
Antonio Maiorano | 101f463 | 2021-04-07 20:35:11 +0000 | [diff] [blame] | 1649 | ast::StructMemberSizeDecoration* MemberSize(const Source& source, |
| 1650 | uint32_t val) { |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1651 | return create<ast::StructMemberSizeDecoration>(source, val); |
| 1652 | } |
| 1653 | |
| 1654 | /// Creates a ast::StructMemberSizeDecoration |
| 1655 | /// @param val the size value |
| 1656 | /// @returns the size decoration pointer |
| 1657 | ast::StructMemberSizeDecoration* MemberSize(uint32_t val) { |
| 1658 | return create<ast::StructMemberSizeDecoration>(source_, val); |
| 1659 | } |
| 1660 | |
| 1661 | /// Creates a ast::StructMemberAlignDecoration |
| 1662 | /// @param source the source information |
| 1663 | /// @param val the align value |
| 1664 | /// @returns the align decoration pointer |
Antonio Maiorano | 101f463 | 2021-04-07 20:35:11 +0000 | [diff] [blame] | 1665 | ast::StructMemberAlignDecoration* MemberAlign(const Source& source, |
| 1666 | uint32_t val) { |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1667 | return create<ast::StructMemberAlignDecoration>(source, val); |
| 1668 | } |
| 1669 | |
| 1670 | /// Creates a ast::StructMemberAlignDecoration |
| 1671 | /// @param val the align value |
| 1672 | /// @returns the align decoration pointer |
| 1673 | ast::StructMemberAlignDecoration* MemberAlign(uint32_t val) { |
| 1674 | return create<ast::StructMemberAlignDecoration>(source_, val); |
| 1675 | } |
| 1676 | |
Ben Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 1677 | /// Creates an ast::Function and registers it with the ast::Module. |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1678 | /// @param source the source information |
| 1679 | /// @param name the function name |
| 1680 | /// @param params the function parameters |
| 1681 | /// @param type the function return type |
| 1682 | /// @param body the function body |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1683 | /// @param decorations the optional function decorations |
| 1684 | /// @param return_type_decorations the optional function return type |
| 1685 | /// decorations |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1686 | /// @returns the function pointer |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1687 | template <typename NAME> |
Antonio Maiorano | 101f463 | 2021-04-07 20:35:11 +0000 | [diff] [blame] | 1688 | ast::Function* Func(const Source& source, |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1689 | NAME&& name, |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1690 | ast::VariableList params, |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1691 | ast::Type* type, |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1692 | ast::StatementList body, |
Ben Clayton | 4f154a8 | 2021-04-06 18:15:17 +0000 | [diff] [blame] | 1693 | ast::DecorationList decorations = {}, |
James Price | feecbe0 | 2021-03-15 17:01:34 +0000 | [diff] [blame] | 1694 | ast::DecorationList return_type_decorations = {}) { |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1695 | auto* func = |
| 1696 | create<ast::Function>(source, Sym(std::forward<NAME>(name)), params, |
| 1697 | type, create<ast::BlockStatement>(body), |
| 1698 | decorations, return_type_decorations); |
James Price | 3eaa450 | 2021-02-09 21:26:21 +0000 | [diff] [blame] | 1699 | AST().AddFunction(func); |
Ben Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 1700 | return func; |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
Ben Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 1703 | /// Creates an ast::Function and registers it with the ast::Module. |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1704 | /// @param name the function name |
| 1705 | /// @param params the function parameters |
| 1706 | /// @param type the function return type |
| 1707 | /// @param body the function body |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1708 | /// @param decorations the optional function decorations |
| 1709 | /// @param return_type_decorations the optional function return type |
| 1710 | /// decorations |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1711 | /// @returns the function pointer |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1712 | template <typename NAME> |
| 1713 | ast::Function* Func(NAME&& name, |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1714 | ast::VariableList params, |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1715 | ast::Type* type, |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1716 | ast::StatementList body, |
Ben Clayton | 4f154a8 | 2021-04-06 18:15:17 +0000 | [diff] [blame] | 1717 | ast::DecorationList decorations = {}, |
James Price | feecbe0 | 2021-03-15 17:01:34 +0000 | [diff] [blame] | 1718 | ast::DecorationList return_type_decorations = {}) { |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1719 | auto* func = create<ast::Function>(Sym(std::forward<NAME>(name)), params, |
| 1720 | type, create<ast::BlockStatement>(body), |
James Price | feecbe0 | 2021-03-15 17:01:34 +0000 | [diff] [blame] | 1721 | decorations, return_type_decorations); |
James Price | 3eaa450 | 2021-02-09 21:26:21 +0000 | [diff] [blame] | 1722 | AST().AddFunction(func); |
Ben Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 1723 | return func; |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
Ben Clayton | 49668bb | 2021-04-17 05:32:01 +0000 | [diff] [blame] | 1726 | /// Creates an ast::ReturnStatement with no return value |
Ben Clayton | 43073d8 | 2021-04-22 13:50:53 +0000 | [diff] [blame] | 1727 | /// @param source the source information |
| 1728 | /// @returns the return statement pointer |
| 1729 | ast::ReturnStatement* Return(const Source& source) { |
| 1730 | return create<ast::ReturnStatement>(source); |
| 1731 | } |
| 1732 | |
| 1733 | /// Creates an ast::ReturnStatement with no return value |
Antonio Maiorano | 03c01b5 | 2021-03-19 14:04:51 +0000 | [diff] [blame] | 1734 | /// @returns the return statement pointer |
Ben Clayton | 49668bb | 2021-04-17 05:32:01 +0000 | [diff] [blame] | 1735 | ast::ReturnStatement* Return() { return create<ast::ReturnStatement>(); } |
| 1736 | |
| 1737 | /// Creates an ast::ReturnStatement with the given return value |
Ben Clayton | 43073d8 | 2021-04-22 13:50:53 +0000 | [diff] [blame] | 1738 | /// @param source the source information |
| 1739 | /// @param val the return value |
| 1740 | /// @returns the return statement pointer |
| 1741 | template <typename EXPR> |
| 1742 | ast::ReturnStatement* Return(const Source& source, EXPR&& val) { |
| 1743 | return create<ast::ReturnStatement>(source, Expr(std::forward<EXPR>(val))); |
| 1744 | } |
| 1745 | |
| 1746 | /// Creates an ast::ReturnStatement with the given return value |
Ben Clayton | 49668bb | 2021-04-17 05:32:01 +0000 | [diff] [blame] | 1747 | /// @param val the return value |
| 1748 | /// @returns the return statement pointer |
| 1749 | template <typename EXPR> |
| 1750 | ast::ReturnStatement* Return(EXPR&& val) { |
| 1751 | return create<ast::ReturnStatement>(Expr(std::forward<EXPR>(val))); |
Antonio Maiorano | 03c01b5 | 2021-03-19 14:04:51 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
Ben Clayton | 950809f | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1754 | /// Creates a ast::Alias registering it with the AST().TypeDecls(). |
Ben Clayton | 6e7d24d | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1755 | /// @param source the source information |
| 1756 | /// @param name the alias name |
| 1757 | /// @param type the alias target type |
| 1758 | /// @returns the alias type |
| 1759 | template <typename NAME> |
| 1760 | ast::Alias* Alias(const Source& source, NAME&& name, ast::Type* type) { |
| 1761 | auto* out = ty.alias(source, std::forward<NAME>(name), type); |
Ben Clayton | 950809f | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1762 | AST().AddTypeDecl(out); |
Ben Clayton | 6e7d24d | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1763 | return out; |
| 1764 | } |
| 1765 | |
Ben Clayton | 950809f | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1766 | /// Creates a ast::Alias registering it with the AST().TypeDecls(). |
Ben Clayton | 6e7d24d | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1767 | /// @param name the alias name |
| 1768 | /// @param type the alias target type |
| 1769 | /// @returns the alias type |
| 1770 | template <typename NAME> |
| 1771 | ast::Alias* Alias(NAME&& name, ast::Type* type) { |
| 1772 | auto* out = ty.alias(std::forward<NAME>(name), type); |
Ben Clayton | 950809f | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1773 | AST().AddTypeDecl(out); |
Ben Clayton | 6e7d24d | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1774 | return out; |
| 1775 | } |
| 1776 | |
Ben Clayton | 950809f | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1777 | /// Creates a ast::Struct registering it with the AST().TypeDecls(). |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1778 | /// @param source the source information |
| 1779 | /// @param name the struct name |
| 1780 | /// @param members the struct members |
| 1781 | /// @param decorations the optional struct decorations |
| 1782 | /// @returns the struct type |
Ben Clayton | 1d618b1 | 2021-04-09 16:19:48 +0000 | [diff] [blame] | 1783 | template <typename NAME> |
Ben Clayton | ba6ab5e | 2021-05-07 14:49:34 +0000 | [diff] [blame] | 1784 | ast::Struct* Structure(const Source& source, |
| 1785 | NAME&& name, |
| 1786 | ast::StructMemberList members, |
| 1787 | ast::DecorationList decorations = {}) { |
Ben Clayton | 8a8d26b | 2021-04-20 15:04:21 +0000 | [diff] [blame] | 1788 | auto sym = Sym(std::forward<NAME>(name)); |
Ben Clayton | ba6ab5e | 2021-05-07 14:49:34 +0000 | [diff] [blame] | 1789 | auto* type = create<ast::Struct>(source, sym, std::move(members), |
Ben Clayton | 8a8d26b | 2021-04-20 15:04:21 +0000 | [diff] [blame] | 1790 | std::move(decorations)); |
Ben Clayton | 950809f | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1791 | AST().AddTypeDecl(type); |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1792 | return type; |
| 1793 | } |
| 1794 | |
Ben Clayton | 950809f | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1795 | /// Creates a ast::Struct registering it with the AST().TypeDecls(). |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1796 | /// @param name the struct name |
| 1797 | /// @param members the struct members |
| 1798 | /// @param decorations the optional struct decorations |
| 1799 | /// @returns the struct type |
Ben Clayton | 1d618b1 | 2021-04-09 16:19:48 +0000 | [diff] [blame] | 1800 | template <typename NAME> |
Ben Clayton | ba6ab5e | 2021-05-07 14:49:34 +0000 | [diff] [blame] | 1801 | ast::Struct* Structure(NAME&& name, |
| 1802 | ast::StructMemberList members, |
| 1803 | ast::DecorationList decorations = {}) { |
Ben Clayton | 8a8d26b | 2021-04-20 15:04:21 +0000 | [diff] [blame] | 1804 | auto sym = Sym(std::forward<NAME>(name)); |
Ben Clayton | ba6ab5e | 2021-05-07 14:49:34 +0000 | [diff] [blame] | 1805 | auto* type = |
Ben Clayton | 8a8d26b | 2021-04-20 15:04:21 +0000 | [diff] [blame] | 1806 | create<ast::Struct>(sym, std::move(members), std::move(decorations)); |
Ben Clayton | 950809f | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 1807 | AST().AddTypeDecl(type); |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1808 | return type; |
| 1809 | } |
| 1810 | |
Ben Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 1811 | /// Creates a ast::StructMember |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1812 | /// @param source the source information |
| 1813 | /// @param name the struct member name |
| 1814 | /// @param type the struct member type |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1815 | /// @param decorations the optional struct member decorations |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1816 | /// @returns the struct member pointer |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1817 | template <typename NAME> |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1818 | ast::StructMember* Member(const Source& source, |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1819 | NAME&& name, |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1820 | ast::Type* type, |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1821 | ast::DecorationList decorations = {}) { |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1822 | return create<ast::StructMember>(source, Sym(std::forward<NAME>(name)), |
| 1823 | type, std::move(decorations)); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
Ben Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 1826 | /// Creates a ast::StructMember |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1827 | /// @param name the struct member name |
| 1828 | /// @param type the struct member type |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1829 | /// @param decorations the optional struct member decorations |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1830 | /// @returns the struct member pointer |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1831 | template <typename NAME> |
| 1832 | ast::StructMember* Member(NAME&& name, |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1833 | ast::Type* type, |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1834 | ast::DecorationList decorations = {}) { |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1835 | return create<ast::StructMember>(source_, Sym(std::forward<NAME>(name)), |
| 1836 | type, std::move(decorations)); |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 1837 | } |
| 1838 | |
Ben Clayton | bab3197 | 2021-02-08 21:16:21 +0000 | [diff] [blame] | 1839 | /// Creates a ast::StructMember with the given byte offset |
| 1840 | /// @param offset the offset to use in the StructMemberOffsetDecoration |
| 1841 | /// @param name the struct member name |
| 1842 | /// @param type the struct member type |
| 1843 | /// @returns the struct member pointer |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1844 | template <typename NAME> |
Ben Clayton | 02ebf0d | 2021-05-05 09:09:41 +0000 | [diff] [blame] | 1845 | ast::StructMember* Member(uint32_t offset, NAME&& name, ast::Type* type) { |
Ben Clayton | bab3197 | 2021-02-08 21:16:21 +0000 | [diff] [blame] | 1846 | return create<ast::StructMember>( |
Ben Clayton | 1b8d9f2 | 2021-04-07 11:16:01 +0000 | [diff] [blame] | 1847 | source_, Sym(std::forward<NAME>(name)), type, |
James Price | 95d4077 | 2021-03-11 17:39:32 +0000 | [diff] [blame] | 1848 | ast::DecorationList{ |
Ben Clayton | bab3197 | 2021-02-08 21:16:21 +0000 | [diff] [blame] | 1849 | create<ast::StructMemberOffsetDecoration>(offset), |
| 1850 | }); |
| 1851 | } |
| 1852 | |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 1853 | /// Creates a ast::BlockStatement with input statements |
| 1854 | /// @param statements statements of block |
| 1855 | /// @returns the block statement pointer |
| 1856 | template <typename... Statements> |
| 1857 | ast::BlockStatement* Block(Statements&&... statements) { |
| 1858 | return create<ast::BlockStatement>( |
| 1859 | ast::StatementList{std::forward<Statements>(statements)...}); |
| 1860 | } |
| 1861 | |
| 1862 | /// Creates a ast::ElseStatement with input condition and body |
| 1863 | /// @param condition the else condition expression |
| 1864 | /// @param body the else body |
| 1865 | /// @returns the else statement pointer |
Ben Clayton | b8ea591 | 2021-04-19 16:52:42 +0000 | [diff] [blame] | 1866 | template <typename CONDITION> |
| 1867 | ast::ElseStatement* Else(CONDITION&& condition, ast::BlockStatement* body) { |
| 1868 | return create<ast::ElseStatement>(Expr(std::forward<CONDITION>(condition)), |
| 1869 | body); |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | /// Creates a ast::IfStatement with input condition, body, and optional |
| 1873 | /// variadic else statements |
| 1874 | /// @param condition the if statement condition expression |
| 1875 | /// @param body the if statement body |
| 1876 | /// @param elseStatements optional variadic else statements |
| 1877 | /// @returns the if statement pointer |
Ben Clayton | b8ea591 | 2021-04-19 16:52:42 +0000 | [diff] [blame] | 1878 | template <typename CONDITION, typename... ELSE_STATEMENTS> |
| 1879 | ast::IfStatement* If(CONDITION&& condition, |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 1880 | ast::BlockStatement* body, |
Ben Clayton | b8ea591 | 2021-04-19 16:52:42 +0000 | [diff] [blame] | 1881 | ELSE_STATEMENTS&&... elseStatements) { |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 1882 | return create<ast::IfStatement>( |
Ben Clayton | b8ea591 | 2021-04-19 16:52:42 +0000 | [diff] [blame] | 1883 | Expr(std::forward<CONDITION>(condition)), body, |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 1884 | ast::ElseStatementList{ |
Ben Clayton | b8ea591 | 2021-04-19 16:52:42 +0000 | [diff] [blame] | 1885 | std::forward<ELSE_STATEMENTS>(elseStatements)...}); |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | /// Creates a ast::AssignmentStatement with input lhs and rhs expressions |
Ben Clayton | 43073d8 | 2021-04-22 13:50:53 +0000 | [diff] [blame] | 1889 | /// @param source the source information |
| 1890 | /// @param lhs the left hand side expression initializer |
| 1891 | /// @param rhs the right hand side expression initializer |
| 1892 | /// @returns the assignment statement pointer |
| 1893 | template <typename LhsExpressionInit, typename RhsExpressionInit> |
| 1894 | ast::AssignmentStatement* Assign(const Source& source, |
| 1895 | LhsExpressionInit&& lhs, |
| 1896 | RhsExpressionInit&& rhs) { |
| 1897 | return create<ast::AssignmentStatement>( |
| 1898 | source, Expr(std::forward<LhsExpressionInit>(lhs)), |
| 1899 | Expr(std::forward<RhsExpressionInit>(rhs))); |
| 1900 | } |
| 1901 | |
| 1902 | /// Creates a ast::AssignmentStatement with input lhs and rhs expressions |
Antonio Maiorano | cea744d | 2021-03-25 12:55:27 +0000 | [diff] [blame] | 1903 | /// @param lhs the left hand side expression initializer |
| 1904 | /// @param rhs the right hand side expression initializer |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 1905 | /// @returns the assignment statement pointer |
Antonio Maiorano | cea744d | 2021-03-25 12:55:27 +0000 | [diff] [blame] | 1906 | template <typename LhsExpressionInit, typename RhsExpressionInit> |
| 1907 | ast::AssignmentStatement* Assign(LhsExpressionInit&& lhs, |
| 1908 | RhsExpressionInit&& rhs) { |
| 1909 | return create<ast::AssignmentStatement>( |
| 1910 | Expr(std::forward<LhsExpressionInit>(lhs)), |
| 1911 | Expr(std::forward<RhsExpressionInit>(rhs))); |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | /// Creates a ast::LoopStatement with input body and optional continuing |
| 1915 | /// @param body the loop body |
| 1916 | /// @param continuing the optional continuing block |
| 1917 | /// @returns the loop statement pointer |
| 1918 | ast::LoopStatement* Loop(ast::BlockStatement* body, |
| 1919 | ast::BlockStatement* continuing = nullptr) { |
| 1920 | return create<ast::LoopStatement>(body, continuing); |
| 1921 | } |
| 1922 | |
| 1923 | /// Creates a ast::VariableDeclStatement for the input variable |
Ben Clayton | 43073d8 | 2021-04-22 13:50:53 +0000 | [diff] [blame] | 1924 | /// @param source the source information |
| 1925 | /// @param var the variable to wrap in a decl statement |
| 1926 | /// @returns the variable decl statement pointer |
| 1927 | ast::VariableDeclStatement* Decl(const Source& source, ast::Variable* var) { |
| 1928 | return create<ast::VariableDeclStatement>(source, var); |
| 1929 | } |
| 1930 | |
| 1931 | /// Creates a ast::VariableDeclStatement for the input variable |
Antonio Maiorano | fd31bbd | 2021-03-09 10:26:57 +0000 | [diff] [blame] | 1932 | /// @param var the variable to wrap in a decl statement |
| 1933 | /// @returns the variable decl statement pointer |
| 1934 | ast::VariableDeclStatement* Decl(ast::Variable* var) { |
| 1935 | return create<ast::VariableDeclStatement>(var); |
| 1936 | } |
| 1937 | |
Antonio Maiorano | cea744d | 2021-03-25 12:55:27 +0000 | [diff] [blame] | 1938 | /// Creates a ast::SwitchStatement with input expression and cases |
| 1939 | /// @param condition the condition expression initializer |
| 1940 | /// @param cases case statements |
| 1941 | /// @returns the switch statement pointer |
| 1942 | template <typename ExpressionInit, typename... Cases> |
| 1943 | ast::SwitchStatement* Switch(ExpressionInit&& condition, Cases&&... cases) { |
| 1944 | return create<ast::SwitchStatement>( |
| 1945 | Expr(std::forward<ExpressionInit>(condition)), |
| 1946 | ast::CaseStatementList{std::forward<Cases>(cases)...}); |
| 1947 | } |
| 1948 | |
| 1949 | /// Creates a ast::CaseStatement with input list of selectors, and body |
| 1950 | /// @param selectors list of selectors |
| 1951 | /// @param body the case body |
| 1952 | /// @returns the case statement pointer |
| 1953 | ast::CaseStatement* Case(ast::CaseSelectorList selectors, |
| 1954 | ast::BlockStatement* body = nullptr) { |
| 1955 | return create<ast::CaseStatement>(std::move(selectors), |
| 1956 | body ? body : Block()); |
| 1957 | } |
| 1958 | |
| 1959 | /// Convenient overload that takes a single selector |
| 1960 | /// @param selector a single case selector |
| 1961 | /// @param body the case body |
| 1962 | /// @returns the case statement pointer |
| 1963 | ast::CaseStatement* Case(ast::IntLiteral* selector, |
| 1964 | ast::BlockStatement* body = nullptr) { |
| 1965 | return Case(ast::CaseSelectorList{selector}, body); |
| 1966 | } |
| 1967 | |
| 1968 | /// Convenience function that creates a 'default' ast::CaseStatement |
| 1969 | /// @param body the case body |
| 1970 | /// @returns the case statement pointer |
| 1971 | ast::CaseStatement* DefaultCase(ast::BlockStatement* body = nullptr) { |
| 1972 | return Case(ast::CaseSelectorList{}, body); |
| 1973 | } |
| 1974 | |
James Price | 68f558f | 2021-04-06 15:51:47 +0000 | [diff] [blame] | 1975 | /// Creates an ast::BuiltinDecoration |
| 1976 | /// @param source the source information |
| 1977 | /// @param builtin the builtin value |
| 1978 | /// @returns the builtin decoration pointer |
Antonio Maiorano | 101f463 | 2021-04-07 20:35:11 +0000 | [diff] [blame] | 1979 | ast::BuiltinDecoration* Builtin(const Source& source, ast::Builtin builtin) { |
James Price | 68f558f | 2021-04-06 15:51:47 +0000 | [diff] [blame] | 1980 | return create<ast::BuiltinDecoration>(source, builtin); |
| 1981 | } |
| 1982 | |
| 1983 | /// Creates an ast::BuiltinDecoration |
| 1984 | /// @param builtin the builtin value |
| 1985 | /// @returns the builtin decoration pointer |
| 1986 | ast::BuiltinDecoration* Builtin(ast::Builtin builtin) { |
| 1987 | return create<ast::BuiltinDecoration>(source_, builtin); |
| 1988 | } |
| 1989 | |
James Price | 989a8e4 | 2021-06-28 23:04:43 +0000 | [diff] [blame] | 1990 | /// Creates an ast::InterpolateDecoration |
| 1991 | /// @param source the source information |
| 1992 | /// @param type the interpolation type |
| 1993 | /// @param sampling the interpolation sampling |
| 1994 | /// @returns the interpolate decoration pointer |
| 1995 | ast::InterpolateDecoration* Interpolate(const Source& source, |
| 1996 | ast::InterpolationType type, |
| 1997 | ast::InterpolationSampling sampling) { |
| 1998 | return create<ast::InterpolateDecoration>(source, type, sampling); |
| 1999 | } |
| 2000 | |
| 2001 | /// Creates an ast::InterpolateDecoration |
| 2002 | /// @param type the interpolation type |
| 2003 | /// @param sampling the interpolation sampling |
| 2004 | /// @returns the interpolate decoration pointer |
| 2005 | ast::InterpolateDecoration* Interpolate(ast::InterpolationType type, |
| 2006 | ast::InterpolationSampling sampling) { |
| 2007 | return create<ast::InterpolateDecoration>(source_, type, sampling); |
| 2008 | } |
| 2009 | |
James Price | 68f558f | 2021-04-06 15:51:47 +0000 | [diff] [blame] | 2010 | /// Creates an ast::LocationDecoration |
| 2011 | /// @param source the source information |
| 2012 | /// @param location the location value |
| 2013 | /// @returns the location decoration pointer |
Antonio Maiorano | 101f463 | 2021-04-07 20:35:11 +0000 | [diff] [blame] | 2014 | ast::LocationDecoration* Location(const Source& source, uint32_t location) { |
James Price | 68f558f | 2021-04-06 15:51:47 +0000 | [diff] [blame] | 2015 | return create<ast::LocationDecoration>(source, location); |
| 2016 | } |
| 2017 | |
| 2018 | /// Creates an ast::LocationDecoration |
| 2019 | /// @param location the location value |
| 2020 | /// @returns the location decoration pointer |
| 2021 | ast::LocationDecoration* Location(uint32_t location) { |
| 2022 | return create<ast::LocationDecoration>(source_, location); |
| 2023 | } |
| 2024 | |
James Price | f2f3bfc | 2021-05-13 20:32:32 +0000 | [diff] [blame] | 2025 | /// Creates an ast::OverrideDecoration with a specific constant ID |
| 2026 | /// @param source the source information |
| 2027 | /// @param id the id value |
| 2028 | /// @returns the override decoration pointer |
| 2029 | ast::OverrideDecoration* Override(const Source& source, uint32_t id) { |
| 2030 | return create<ast::OverrideDecoration>(source, id); |
| 2031 | } |
| 2032 | |
| 2033 | /// Creates an ast::OverrideDecoration with a specific constant ID |
| 2034 | /// @param id the optional id value |
| 2035 | /// @returns the override decoration pointer |
| 2036 | ast::OverrideDecoration* Override(uint32_t id) { |
| 2037 | return Override(source_, id); |
| 2038 | } |
| 2039 | |
| 2040 | /// Creates an ast::OverrideDecoration without a constant ID |
| 2041 | /// @param source the source information |
| 2042 | /// @returns the override decoration pointer |
| 2043 | ast::OverrideDecoration* Override(const Source& source) { |
| 2044 | return create<ast::OverrideDecoration>(source); |
| 2045 | } |
| 2046 | |
| 2047 | /// Creates an ast::OverrideDecoration without a constant ID |
| 2048 | /// @returns the override decoration pointer |
| 2049 | ast::OverrideDecoration* Override() { return Override(source_); } |
| 2050 | |
James Price | 68f558f | 2021-04-06 15:51:47 +0000 | [diff] [blame] | 2051 | /// Creates an ast::StageDecoration |
| 2052 | /// @param source the source information |
| 2053 | /// @param stage the pipeline stage |
| 2054 | /// @returns the stage decoration pointer |
Antonio Maiorano | 101f463 | 2021-04-07 20:35:11 +0000 | [diff] [blame] | 2055 | ast::StageDecoration* Stage(const Source& source, ast::PipelineStage stage) { |
James Price | 68f558f | 2021-04-06 15:51:47 +0000 | [diff] [blame] | 2056 | return create<ast::StageDecoration>(source, stage); |
| 2057 | } |
| 2058 | |
| 2059 | /// Creates an ast::StageDecoration |
| 2060 | /// @param stage the pipeline stage |
| 2061 | /// @returns the stage decoration pointer |
| 2062 | ast::StageDecoration* Stage(ast::PipelineStage stage) { |
| 2063 | return create<ast::StageDecoration>(source_, stage); |
| 2064 | } |
| 2065 | |
James Price | 70f80bb | 2021-05-19 13:40:08 +0000 | [diff] [blame] | 2066 | /// Creates an ast::WorkgroupDecoration |
| 2067 | /// @param x the x dimension expression |
| 2068 | /// @returns the workgroup decoration pointer |
| 2069 | template <typename EXPR_X> |
| 2070 | ast::WorkgroupDecoration* WorkgroupSize(EXPR_X&& x) { |
| 2071 | return WorkgroupSize(std::forward<EXPR_X>(x), nullptr, nullptr); |
| 2072 | } |
| 2073 | |
| 2074 | /// Creates an ast::WorkgroupDecoration |
| 2075 | /// @param x the x dimension expression |
| 2076 | /// @param y the y dimension expression |
| 2077 | /// @returns the workgroup decoration pointer |
| 2078 | template <typename EXPR_X, typename EXPR_Y> |
| 2079 | ast::WorkgroupDecoration* WorkgroupSize(EXPR_X&& x, EXPR_Y&& y) { |
| 2080 | return WorkgroupSize(std::forward<EXPR_X>(x), std::forward<EXPR_Y>(y), |
| 2081 | nullptr); |
| 2082 | } |
| 2083 | |
| 2084 | /// Creates an ast::WorkgroupDecoration |
Ben Clayton | 241c16d | 2021-06-09 18:53:57 +0000 | [diff] [blame] | 2085 | /// @param source the source information |
| 2086 | /// @param x the x dimension expression |
| 2087 | /// @param y the y dimension expression |
| 2088 | /// @param z the z dimension expression |
| 2089 | /// @returns the workgroup decoration pointer |
| 2090 | template <typename EXPR_X, typename EXPR_Y, typename EXPR_Z> |
| 2091 | ast::WorkgroupDecoration* WorkgroupSize(const Source& source, |
| 2092 | EXPR_X&& x, |
| 2093 | EXPR_Y&& y, |
| 2094 | EXPR_Z&& z) { |
| 2095 | return create<ast::WorkgroupDecoration>( |
| 2096 | source, Expr(std::forward<EXPR_X>(x)), Expr(std::forward<EXPR_Y>(y)), |
| 2097 | Expr(std::forward<EXPR_Z>(z))); |
| 2098 | } |
| 2099 | |
| 2100 | /// Creates an ast::WorkgroupDecoration |
James Price | 70f80bb | 2021-05-19 13:40:08 +0000 | [diff] [blame] | 2101 | /// @param x the x dimension expression |
| 2102 | /// @param y the y dimension expression |
| 2103 | /// @param z the z dimension expression |
| 2104 | /// @returns the workgroup decoration pointer |
| 2105 | template <typename EXPR_X, typename EXPR_Y, typename EXPR_Z> |
| 2106 | ast::WorkgroupDecoration* WorkgroupSize(EXPR_X&& x, EXPR_Y&& y, EXPR_Z&& z) { |
| 2107 | return create<ast::WorkgroupDecoration>( |
| 2108 | source_, Expr(std::forward<EXPR_X>(x)), Expr(std::forward<EXPR_Y>(y)), |
| 2109 | Expr(std::forward<EXPR_Z>(z))); |
| 2110 | } |
| 2111 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2112 | /// Sets the current builder source to `src` |
| 2113 | /// @param src the Source used for future create() calls |
| 2114 | void SetSource(const Source& src) { |
| 2115 | AssertNotMoved(); |
| 2116 | source_ = src; |
| 2117 | } |
| 2118 | |
| 2119 | /// Sets the current builder source to `loc` |
| 2120 | /// @param loc the Source used for future create() calls |
| 2121 | void SetSource(const Source::Location& loc) { |
| 2122 | AssertNotMoved(); |
| 2123 | source_ = Source(loc); |
| 2124 | } |
| 2125 | |
Ben Clayton | b5cd10c | 2021-06-25 10:26:26 +0000 | [diff] [blame] | 2126 | /// Marks that the given transform has been applied to this program. |
| 2127 | /// @param transform the transform that has been applied |
| 2128 | void SetTransformApplied(const CastableBase* transform) { |
| 2129 | transforms_applied_.emplace(&transform->TypeInfo()); |
| 2130 | } |
| 2131 | |
| 2132 | /// Marks that the given transform `T` has been applied to this program. |
| 2133 | template <typename T> |
| 2134 | void SetTransformApplied() { |
| 2135 | transforms_applied_.emplace(&TypeInfo::Of<T>()); |
| 2136 | } |
| 2137 | |
| 2138 | /// Marks that the transforms with the given TypeInfos have been applied to |
| 2139 | /// this program. |
| 2140 | /// @param transforms the set of transform TypeInfos that has been applied |
| 2141 | void SetTransformApplied( |
| 2142 | const std::unordered_set<const TypeInfo*>& transforms) { |
| 2143 | for (auto* transform : transforms) { |
| 2144 | transforms_applied_.emplace(transform); |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | /// @returns true if the transform of type `T` was applied. |
| 2149 | template <typename T> |
| 2150 | bool HasTransformApplied() { |
| 2151 | return transforms_applied_.count(&TypeInfo::Of<T>()); |
| 2152 | } |
| 2153 | |
| 2154 | /// @return the TypeInfo pointers of all transforms that have been applied to |
| 2155 | /// this program. |
| 2156 | std::unordered_set<const TypeInfo*> TransformsApplied() const { |
| 2157 | return transforms_applied_; |
| 2158 | } |
| 2159 | |
Ben Clayton | 3335254 | 2021-01-29 16:43:41 +0000 | [diff] [blame] | 2160 | /// Helper for returning the resolved semantic type of the expression `expr`. |
Ben Clayton | 5f0ea11 | 2021-03-09 10:54:37 +0000 | [diff] [blame] | 2161 | /// @note As the Resolver is run when the Program is built, this will only be |
| 2162 | /// useful for the Resolver itself and tests that use their own Resolver. |
Ben Clayton | 3335254 | 2021-01-29 16:43:41 +0000 | [diff] [blame] | 2163 | /// @param expr the AST expression |
| 2164 | /// @return the resolved semantic type for the expression, or nullptr if the |
| 2165 | /// expression has no resolved type. |
Ben Clayton | fbec46f | 2021-04-30 20:20:19 +0000 | [diff] [blame] | 2166 | sem::Type* TypeOf(const ast::Expression* expr) const; |
| 2167 | |
Ben Clayton | fe0910f | 2021-05-17 15:51:47 +0000 | [diff] [blame] | 2168 | /// Helper for returning the resolved semantic type of the variable `var`. |
| 2169 | /// @note As the Resolver is run when the Program is built, this will only be |
| 2170 | /// useful for the Resolver itself and tests that use their own Resolver. |
| 2171 | /// @param var the AST variable |
| 2172 | /// @return the resolved semantic type for the variable, or nullptr if the |
| 2173 | /// variable has no resolved type. |
| 2174 | sem::Type* TypeOf(const ast::Variable* var) const; |
| 2175 | |
Ben Clayton | fbec46f | 2021-04-30 20:20:19 +0000 | [diff] [blame] | 2176 | /// Helper for returning the resolved semantic type of the AST type `type`. |
| 2177 | /// @note As the Resolver is run when the Program is built, this will only be |
| 2178 | /// useful for the Resolver itself and tests that use their own Resolver. |
Ben Clayton | 8758f10 | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 2179 | /// @param type the AST type |
Ben Clayton | fbec46f | 2021-04-30 20:20:19 +0000 | [diff] [blame] | 2180 | /// @return the resolved semantic type for the type, or nullptr if the type |
| 2181 | /// has no resolved type. |
Ben Clayton | 8758f10 | 2021-06-09 14:32:14 +0000 | [diff] [blame] | 2182 | const sem::Type* TypeOf(const ast::Type* type) const; |
| 2183 | |
| 2184 | /// Helper for returning the resolved semantic type of the AST type |
| 2185 | /// declaration `type_decl`. |
| 2186 | /// @note As the Resolver is run when the Program is built, this will only be |
| 2187 | /// useful for the Resolver itself and tests that use their own Resolver. |
| 2188 | /// @param type_decl the AST type declaration |
| 2189 | /// @return the resolved semantic type for the type declaration, or nullptr if |
| 2190 | /// the type declaration has no resolved type. |
| 2191 | const sem::Type* TypeOf(const ast::TypeDecl* type_decl) const; |
Ben Clayton | 3335254 | 2021-01-29 16:43:41 +0000 | [diff] [blame] | 2192 | |
Ben Clayton | 169512e | 2021-04-17 05:52:11 +0000 | [diff] [blame] | 2193 | /// Wraps the ast::Literal in a statement. This is used by tests that |
| 2194 | /// construct a partial AST and require the Resolver to reach these |
| 2195 | /// nodes. |
| 2196 | /// @param lit the ast::Literal to be wrapped by an ast::Statement |
| 2197 | /// @return the ast::Statement that wraps the ast::Statement |
| 2198 | ast::Statement* WrapInStatement(ast::Literal* lit); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 2199 | /// Wraps the ast::Expression in a statement. This is used by tests that |
Ben Clayton | 5f0ea11 | 2021-03-09 10:54:37 +0000 | [diff] [blame] | 2200 | /// construct a partial AST and require the Resolver to reach these |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 2201 | /// nodes. |
| 2202 | /// @param expr the ast::Expression to be wrapped by an ast::Statement |
| 2203 | /// @return the ast::Statement that wraps the ast::Expression |
| 2204 | ast::Statement* WrapInStatement(ast::Expression* expr); |
| 2205 | /// Wraps the ast::Variable in a ast::VariableDeclStatement. This is used by |
Ben Clayton | 5f0ea11 | 2021-03-09 10:54:37 +0000 | [diff] [blame] | 2206 | /// tests that construct a partial AST and require the Resolver to reach |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 2207 | /// these nodes. |
| 2208 | /// @param v the ast::Variable to be wrapped by an ast::VariableDeclStatement |
| 2209 | /// @return the ast::VariableDeclStatement that wraps the ast::Variable |
| 2210 | ast::VariableDeclStatement* WrapInStatement(ast::Variable* v); |
| 2211 | /// Returns the statement argument. Used as a passthrough-overload by |
| 2212 | /// WrapInFunction(). |
| 2213 | /// @param stmt the ast::Statement |
| 2214 | /// @return `stmt` |
| 2215 | ast::Statement* WrapInStatement(ast::Statement* stmt); |
| 2216 | /// Wraps the list of arguments in a simple function so that each is reachable |
Ben Clayton | 5f0ea11 | 2021-03-09 10:54:37 +0000 | [diff] [blame] | 2217 | /// by the Resolver. |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 2218 | /// @param args a mix of ast::Expression, ast::Statement, ast::Variables. |
Antonio Maiorano | 03c01b5 | 2021-03-19 14:04:51 +0000 | [diff] [blame] | 2219 | /// @returns the function |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 2220 | template <typename... ARGS> |
Antonio Maiorano | 03c01b5 | 2021-03-19 14:04:51 +0000 | [diff] [blame] | 2221 | ast::Function* WrapInFunction(ARGS&&... args) { |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 2222 | ast::StatementList stmts{WrapInStatement(std::forward<ARGS>(args))...}; |
Antonio Maiorano | 03c01b5 | 2021-03-19 14:04:51 +0000 | [diff] [blame] | 2223 | return WrapInFunction(std::move(stmts)); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 2224 | } |
| 2225 | /// @param stmts a list of ast::Statement that will be wrapped by a function, |
Ben Clayton | 5f0ea11 | 2021-03-09 10:54:37 +0000 | [diff] [blame] | 2226 | /// so that each statement is reachable by the Resolver. |
Antonio Maiorano | 03c01b5 | 2021-03-19 14:04:51 +0000 | [diff] [blame] | 2227 | /// @returns the function |
| 2228 | ast::Function* WrapInFunction(ast::StatementList stmts); |
Ben Clayton | 401b96b | 2021-02-03 17:19:59 +0000 | [diff] [blame] | 2229 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2230 | /// The builder types |
Ben Clayton | c7ca766 | 2021-02-17 16:23:52 +0000 | [diff] [blame] | 2231 | TypesBuilder const ty{this}; |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2232 | |
| 2233 | protected: |
| 2234 | /// Asserts that the builder has not been moved. |
| 2235 | void AssertNotMoved() const; |
| 2236 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2237 | private: |
Ben Clayton | e6995de | 2021-04-13 23:27:27 +0000 | [diff] [blame] | 2238 | ProgramID id_; |
Antonio Maiorano | 3751fd2 | 2021-04-19 22:51:23 +0000 | [diff] [blame] | 2239 | sem::Manager types_; |
Ben Clayton | 7fdfff1 | 2021-01-29 15:17:30 +0000 | [diff] [blame] | 2240 | ASTNodeAllocator ast_nodes_; |
| 2241 | SemNodeAllocator sem_nodes_; |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2242 | ast::Module* ast_; |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 2243 | sem::Info sem_; |
Ben Clayton | 13ef87c | 2021-04-15 18:20:03 +0000 | [diff] [blame] | 2244 | SymbolTable symbols_{id_}; |
Ben Clayton | 844217f | 2021-01-27 18:49:05 +0000 | [diff] [blame] | 2245 | diag::List diagnostics_; |
Ben Clayton | b5cd10c | 2021-06-25 10:26:26 +0000 | [diff] [blame] | 2246 | std::unordered_set<const TypeInfo*> transforms_applied_; |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2247 | |
| 2248 | /// The source to use when creating AST nodes without providing a Source as |
| 2249 | /// the first argument. |
| 2250 | Source source_; |
| 2251 | |
Ben Clayton | 5f0ea11 | 2021-03-09 10:54:37 +0000 | [diff] [blame] | 2252 | /// Set by SetResolveOnBuild(). If set, the Resolver will be run on the |
Ben Clayton | dd69ac3 | 2021-01-27 19:23:55 +0000 | [diff] [blame] | 2253 | /// program when built. |
| 2254 | bool resolve_on_build_ = true; |
| 2255 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2256 | /// Set by MarkAsMoved(). Once set, no methods may be called on this builder. |
| 2257 | bool moved_ = false; |
| 2258 | }; |
| 2259 | |
| 2260 | //! @cond Doxygen_Suppress |
| 2261 | // Various template specializations for ProgramBuilder::TypesBuilder::CToAST. |
| 2262 | template <> |
| 2263 | struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::i32> { |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 2264 | static ast::Type* get(const ProgramBuilder::TypesBuilder* t) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2265 | return t->i32(); |
| 2266 | } |
| 2267 | }; |
| 2268 | template <> |
| 2269 | struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::u32> { |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 2270 | static ast::Type* get(const ProgramBuilder::TypesBuilder* t) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2271 | return t->u32(); |
| 2272 | } |
| 2273 | }; |
| 2274 | template <> |
| 2275 | struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::f32> { |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 2276 | static ast::Type* get(const ProgramBuilder::TypesBuilder* t) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2277 | return t->f32(); |
| 2278 | } |
| 2279 | }; |
| 2280 | template <> |
| 2281 | struct ProgramBuilder::TypesBuilder::CToAST<bool> { |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 2282 | static ast::Type* get(const ProgramBuilder::TypesBuilder* t) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2283 | return t->bool_(); |
| 2284 | } |
| 2285 | }; |
| 2286 | template <> |
| 2287 | struct ProgramBuilder::TypesBuilder::CToAST<void> { |
Ben Clayton | 19d3205 | 2021-05-20 15:10:48 +0000 | [diff] [blame] | 2288 | static ast::Type* get(const ProgramBuilder::TypesBuilder* t) { |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2289 | return t->void_(); |
| 2290 | } |
| 2291 | }; |
| 2292 | //! @endcond |
| 2293 | |
Ben Clayton | 917b14b | 2021-04-19 16:50:23 +0000 | [diff] [blame] | 2294 | /// @param builder the ProgramBuilder |
| 2295 | /// @returns the ProgramID of the ProgramBuilder |
| 2296 | inline ProgramID ProgramIDOf(const ProgramBuilder* builder) { |
| 2297 | return builder->ID(); |
| 2298 | } |
| 2299 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 2300 | } // namespace tint |
| 2301 | |
| 2302 | #endif // SRC_PROGRAM_BUILDER_H_ |