From bab3197fdae4e719a1a8a8e3031833497232bb18 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 8 Feb 2021 21:16:21 +0000 Subject: [PATCH] ProgramBuilder: Add more helpers for Members / Arrays Add overloads of TypesBuilder::array() that take a stride parameter. Add overload of ProgramBuilder:Member() that has an offset Change-Id: If8337e410e73eade504432599a9798bbc511382e Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40600 Commit-Queue: Ben Clayton Reviewed-by: dan sinclair --- src/program_builder.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/program_builder.h b/src/program_builder.h index a993063b71..14758e48b8 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -29,6 +29,7 @@ #include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" +#include "src/ast/stride_decoration.h" #include "src/ast/struct.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_offset_decoration.h" @@ -418,12 +419,30 @@ class ProgramBuilder { ast::ArrayDecorationList{}); } + /// @param subtype the array element type + /// @param n the array size. 0 represents a runtime-array. + /// @param stride the array stride. + /// @return the tint AST type for a array of size `n` of type `T` + type::Array* array(type::Type* subtype, uint32_t n, uint32_t stride) const { + return builder->create( + subtype, n, + ast::ArrayDecorationList{ + builder->create(stride), + }); + } + /// @return the tint AST type for an array of size `N` of type `T` template type::Array* array() const { return array(Of(), N); } + /// @param stride the array stride + /// @return the tint AST type for an array of size `N` of type `T` + template + type::Array* array(uint32_t stride) const { + return array(Of(), N, stride); + } /// Creates an alias type /// @param name the alias name /// @param type the alias type @@ -954,6 +973,21 @@ class ProgramBuilder { decorations); } + /// Creates a ast::StructMember with the given byte offset + /// @param offset the offset to use in the StructMemberOffsetDecoration + /// @param name the struct member name + /// @param type the struct member type + /// @returns the struct member pointer + ast::StructMember* Member(uint32_t offset, + const std::string& name, + type::Type* type) { + return create( + source_, Symbols().Register(name), type, + ast::StructMemberDecorationList{ + create(offset), + }); + } + /// Sets the current builder source to `src` /// @param src the Source used for future create() calls void SetSource(const Source& src) {