tint: Add ast::ParameterList, use it
This is currently identical to ast::VariableList, but once we break ast::Variable up, this will become a different vector type. Bug: tint:1580 Change-Id: Ib2db5772996a63cd1989e36f1034dc1fbd3b371a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93601 Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
parent
7164b97272
commit
2ae29830db
|
@ -25,7 +25,7 @@ namespace tint::ast {
|
|||
Function::Function(ProgramID pid,
|
||||
const Source& src,
|
||||
Symbol sym,
|
||||
VariableList parameters,
|
||||
ParameterList parameters,
|
||||
const Type* return_ty,
|
||||
const BlockStatement* b,
|
||||
AttributeList attrs,
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
|
||||
namespace tint::ast {
|
||||
|
||||
/// ParameterList is a list of function parameters
|
||||
using ParameterList = std::vector<const Variable*>;
|
||||
|
||||
/// A Function statement.
|
||||
class Function final : public Castable<Function, Node> {
|
||||
public:
|
||||
|
@ -46,7 +49,7 @@ class Function final : public Castable<Function, Node> {
|
|||
Function(ProgramID program_id,
|
||||
const Source& source,
|
||||
Symbol symbol,
|
||||
VariableList params,
|
||||
ParameterList params,
|
||||
const Type* return_type,
|
||||
const BlockStatement* body,
|
||||
AttributeList attributes,
|
||||
|
@ -72,7 +75,7 @@ class Function final : public Castable<Function, Node> {
|
|||
const Symbol symbol;
|
||||
|
||||
/// The function params
|
||||
const VariableList params;
|
||||
const ParameterList params;
|
||||
|
||||
/// The function return type
|
||||
const Type* const return_type;
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace {
|
|||
using FunctionTest = TestHelper;
|
||||
|
||||
TEST_F(FunctionTest, Creation) {
|
||||
VariableList params{Param("var", ty.i32())};
|
||||
ParameterList params{Param("var", ty.i32())};
|
||||
auto* var = params[0];
|
||||
|
||||
auto* f = Func("func", params, ty.void_(), {});
|
||||
|
@ -37,7 +37,7 @@ TEST_F(FunctionTest, Creation) {
|
|||
}
|
||||
|
||||
TEST_F(FunctionTest, Creation_WithSource) {
|
||||
VariableList params{Param("var", ty.i32())};
|
||||
ParameterList params{Param("var", ty.i32())};
|
||||
|
||||
auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(), {});
|
||||
auto src = f->source;
|
||||
|
@ -67,7 +67,7 @@ TEST_F(FunctionTest, Assert_Null_Param) {
|
|||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
VariableList params;
|
||||
ParameterList params;
|
||||
params.push_back(b.Param("var", b.ty.i32()));
|
||||
params.push_back(nullptr);
|
||||
|
||||
|
@ -126,7 +126,7 @@ TEST_F(FunctionTest, Assert_NonConstParam) {
|
|||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
VariableList params;
|
||||
ParameterList params;
|
||||
params.push_back(b.Var("var", b.ty.i32(), ast::StorageClass::kNone));
|
||||
|
||||
b.Func("f", params, b.ty.void_(), {});
|
||||
|
|
|
@ -61,7 +61,7 @@ TEST_F(ModuleTest, Assert_DifferentProgramID_Function) {
|
|||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.AST().AddFunction(b2.create<ast::Function>(b2.Symbols().Register("func"),
|
||||
VariableList{}, b2.ty.f32(), b2.Block(),
|
||||
ParameterList{}, b2.ty.f32(), b2.Block(),
|
||||
AttributeList{}, AttributeList{}));
|
||||
},
|
||||
"internal compiler error");
|
||||
|
|
|
@ -1941,7 +1941,7 @@ class ProgramBuilder {
|
|||
template <typename NAME>
|
||||
const ast::Function* Func(const Source& source,
|
||||
NAME&& name,
|
||||
ast::VariableList params,
|
||||
ast::ParameterList params,
|
||||
const ast::Type* type,
|
||||
ast::StatementList body,
|
||||
ast::AttributeList attributes = {},
|
||||
|
@ -1964,7 +1964,7 @@ class ProgramBuilder {
|
|||
/// @returns the function pointer
|
||||
template <typename NAME>
|
||||
const ast::Function* Func(NAME&& name,
|
||||
ast::VariableList params,
|
||||
ast::ParameterList params,
|
||||
const ast::Type* type,
|
||||
ast::StatementList body,
|
||||
ast::AttributeList attributes = {},
|
||||
|
|
|
@ -949,7 +949,7 @@ bool FunctionEmitter::EmitPipelineInput(std::string var_name,
|
|||
std::vector<int> index_prefix,
|
||||
const Type* tip_type,
|
||||
const Type* forced_param_type,
|
||||
ast::VariableList* params,
|
||||
ast::ParameterList* params,
|
||||
ast::StatementList* statements) {
|
||||
// TODO(dneto): Handle structs where the locations are annotated on members.
|
||||
tip_type = tip_type->UnwrapAlias();
|
||||
|
@ -1399,7 +1399,7 @@ bool FunctionEmitter::ParseFunctionDeclaration(FunctionDeclaration* decl) {
|
|||
<< function_.result_id();
|
||||
}
|
||||
|
||||
ast::VariableList ast_params;
|
||||
ast::ParameterList ast_params;
|
||||
function_.ForEachParam([this, &ast_params](const spvtools::opt::Instruction* param) {
|
||||
auto* type = parser_impl_.ConvertType(param->type_id());
|
||||
if (type != nullptr) {
|
||||
|
|
|
@ -459,7 +459,7 @@ class FunctionEmitter {
|
|||
std::vector<int> index_prefix,
|
||||
const Type* tip_type,
|
||||
const Type* forced_param_type,
|
||||
ast::VariableList* params,
|
||||
ast::ParameterList* params,
|
||||
ast::StatementList* statements);
|
||||
|
||||
/// Creates one or more struct members from an output variable, and the
|
||||
|
@ -951,7 +951,7 @@ class FunctionEmitter {
|
|||
/// Function name
|
||||
std::string name;
|
||||
/// Function parameters
|
||||
ast::VariableList params;
|
||||
ast::ParameterList params;
|
||||
/// Function return type
|
||||
const Type* return_type;
|
||||
/// Function attributes
|
||||
|
|
|
@ -210,7 +210,7 @@ ParserImpl::FunctionHeader::FunctionHeader(const FunctionHeader&) = default;
|
|||
|
||||
ParserImpl::FunctionHeader::FunctionHeader(Source src,
|
||||
std::string n,
|
||||
ast::VariableList p,
|
||||
ast::ParameterList p,
|
||||
const ast::Type* ret_ty,
|
||||
ast::AttributeList ret_attrs)
|
||||
: source(src), name(n), params(p), return_type(ret_ty), return_type_attributes(ret_attrs) {}
|
||||
|
@ -1443,8 +1443,8 @@ Maybe<ParserImpl::FunctionHeader> ParserImpl::function_header() {
|
|||
// param_list
|
||||
// :
|
||||
// | (param COMMA)* param COMMA?
|
||||
Expect<ast::VariableList> ParserImpl::expect_param_list() {
|
||||
ast::VariableList ret;
|
||||
Expect<ast::ParameterList> ParserImpl::expect_param_list() {
|
||||
ast::ParameterList ret;
|
||||
while (continue_parsing()) {
|
||||
// Check for the end of the list.
|
||||
auto t = peek();
|
||||
|
|
|
@ -232,7 +232,7 @@ class ParserImpl {
|
|||
/// @param ret_attrs return type attributes
|
||||
FunctionHeader(Source src,
|
||||
std::string n,
|
||||
ast::VariableList p,
|
||||
ast::ParameterList p,
|
||||
const ast::Type* ret_ty,
|
||||
ast::AttributeList ret_attrs);
|
||||
/// Destructor
|
||||
|
@ -247,7 +247,7 @@ class ParserImpl {
|
|||
/// Function name
|
||||
std::string name;
|
||||
/// Function parameters
|
||||
ast::VariableList params;
|
||||
ast::ParameterList params;
|
||||
/// Function return type
|
||||
const ast::Type* return_type = nullptr;
|
||||
/// Function return type attributes
|
||||
|
@ -459,7 +459,7 @@ class ParserImpl {
|
|||
Maybe<FunctionHeader> function_header();
|
||||
/// Parses a `param_list` grammar element, erroring on parse failure.
|
||||
/// @returns the parsed variables
|
||||
Expect<ast::VariableList> expect_param_list();
|
||||
Expect<ast::ParameterList> expect_param_list();
|
||||
/// Parses a `param` grammar element, erroring on parse failure.
|
||||
/// @returns the parsed variable
|
||||
Expect<ast::Variable*> expect_param();
|
||||
|
|
|
@ -81,7 +81,7 @@ static constexpr Params all_param_types[] = {
|
|||
};
|
||||
|
||||
TEST_F(ResolverCallTest, Valid) {
|
||||
ast::VariableList params;
|
||||
ast::ParameterList params;
|
||||
ast::ExpressionList args;
|
||||
for (auto& p : all_param_types) {
|
||||
params.push_back(Param(Sym(), p.create_type(*this)));
|
||||
|
|
|
@ -384,11 +384,11 @@ struct SymbolTestHelper {
|
|||
/// The program builder
|
||||
ProgramBuilder* const builder;
|
||||
/// Parameters to a function that may need to be built
|
||||
std::vector<const ast::Variable*> parameters;
|
||||
ast::ParameterList parameters;
|
||||
/// Shallow function var / let declaration statements
|
||||
std::vector<const ast::Statement*> statements;
|
||||
ast::StatementList statements;
|
||||
/// Nested function local var / let declaration statements
|
||||
std::vector<const ast::Statement*> nested_statements;
|
||||
ast::StatementList nested_statements;
|
||||
/// Function attributes
|
||||
ast::AttributeList func_attrs;
|
||||
|
||||
|
@ -717,8 +717,10 @@ TEST_F(ResolverDependencyGraphUsedBeforeDeclTest, VarUsed) {
|
|||
// }
|
||||
// var G: f32 = 2.1;
|
||||
|
||||
Func("F", ast::VariableList{}, ty.void_(),
|
||||
{Block(Assign(Expr(Source{{12, 34}}, "G"), 3.14_f))});
|
||||
Func("F", {}, ty.void_(),
|
||||
{
|
||||
Block(Assign(Expr(Source{{12, 34}}, "G"), 3.14_f)),
|
||||
});
|
||||
|
||||
Global(Source{{56, 78}}, "G", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1_f));
|
||||
|
||||
|
|
|
@ -733,7 +733,7 @@ TEST_F(ResolverFunctionValidationTest, ParameterSotreType_AtomicFree) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, ParametersAtLimit) {
|
||||
ast::VariableList params;
|
||||
ast::ParameterList params;
|
||||
for (int i = 0; i < 255; i++) {
|
||||
params.emplace_back(Param("param_" + std::to_string(i), ty.i32()));
|
||||
}
|
||||
|
@ -743,7 +743,7 @@ TEST_F(ResolverFunctionValidationTest, ParametersAtLimit) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, ParametersOverLimit) {
|
||||
ast::VariableList params;
|
||||
ast::ParameterList params;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
params.emplace_back(Param("param_" + std::to_string(i), ty.i32()));
|
||||
}
|
||||
|
|
|
@ -5001,7 +5001,7 @@ TEST_F(UniformityAnalysisTest, MaximumNumberOfPointerParameters) {
|
|||
// ...
|
||||
// *p254 = rhs;
|
||||
// }
|
||||
ast::VariableList params;
|
||||
ast::ParameterList params;
|
||||
ast::StatementList foo_body;
|
||||
const ast::Expression* rhs_init = b.Deref("p0");
|
||||
for (int i = 1; i < 255; i++) {
|
||||
|
|
|
@ -98,7 +98,7 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) cons
|
|||
ctx.dst->Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
|
||||
ctx.dst->AST().AddFunction(ctx.dst->create<ast::Function>(
|
||||
name,
|
||||
ast::VariableList{
|
||||
ast::ParameterList{
|
||||
// Note: The buffer parameter requires the kStorage StorageClass
|
||||
// in order for HLSL to emit this as a ByteAddressBuffer.
|
||||
ctx.dst->create<ast::Variable>(ctx.dst->Sym("buffer"),
|
||||
|
|
|
@ -100,7 +100,7 @@ struct CanonicalizeEntryPointIO::State {
|
|||
const sem::Function* func_sem;
|
||||
|
||||
/// The new entry point wrapper function's parameters.
|
||||
ast::VariableList wrapper_ep_parameters;
|
||||
ast::ParameterList wrapper_ep_parameters;
|
||||
/// The members of the wrapper function's struct parameter.
|
||||
ast::StructMemberList wrapper_struct_param_members;
|
||||
/// The name of the wrapper function's struct parameter.
|
||||
|
|
|
@ -169,7 +169,7 @@ struct CombineSamplers::State {
|
|||
if (pairs.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
ast::VariableList params;
|
||||
ast::ParameterList params;
|
||||
for (auto pair : func->TextureSamplerPairs()) {
|
||||
const sem::Variable* texture_var = pair.first;
|
||||
const sem::Variable* sampler_var = pair.second;
|
||||
|
|
|
@ -437,7 +437,7 @@ struct DecomposeMemoryAccess::State {
|
|||
auto* disable_validation =
|
||||
b.Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
|
||||
|
||||
ast::VariableList params = {
|
||||
ast::ParameterList params = {
|
||||
// Note: The buffer parameter requires the StorageClass in
|
||||
// order for HLSL to emit this as a ByteAddressBuffer or cbuffer
|
||||
// array.
|
||||
|
@ -528,7 +528,7 @@ struct DecomposeMemoryAccess::State {
|
|||
auto* el_ast_ty = CreateASTTypeFor(ctx, el_ty);
|
||||
auto* disable_validation =
|
||||
b.Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
|
||||
ast::VariableList params{
|
||||
ast::ParameterList params{
|
||||
// Note: The buffer parameter requires the StorageClass in
|
||||
// order for HLSL to emit this as a ByteAddressBuffer.
|
||||
|
||||
|
@ -621,7 +621,7 @@ struct DecomposeMemoryAccess::State {
|
|||
// The first parameter to all WGSL atomics is the expression to the
|
||||
// atomic. This is replaced with two parameters: the buffer and offset.
|
||||
|
||||
ast::VariableList params = {
|
||||
ast::ParameterList params = {
|
||||
// Note: The buffer parameter requires the kStorage StorageClass in
|
||||
// order for HLSL to emit this as a ByteAddressBuffer.
|
||||
b.create<ast::Variable>(b.Sym("buffer"), ast::StorageClass::kStorage,
|
||||
|
|
|
@ -132,7 +132,7 @@ void RemovePhonies::Run(CloneContext& ctx, const DataMap&, DataMap&) const {
|
|||
}
|
||||
auto sink = utils::GetOrCreate(sinks, sig, [&] {
|
||||
auto name = ctx.dst->Symbols().New("phony_sink");
|
||||
ast::VariableList params;
|
||||
ast::ParameterList params;
|
||||
for (auto* ty : sig.types) {
|
||||
auto* ast_ty = CreateASTTypeFor(ctx, ty);
|
||||
params.push_back(
|
||||
|
|
|
@ -228,7 +228,7 @@ struct State {
|
|||
Symbol pulling_position_name;
|
||||
Symbol struct_buffer_name;
|
||||
std::unordered_map<uint32_t, Symbol> vertex_buffer_names;
|
||||
ast::VariableList new_function_parameters;
|
||||
ast::ParameterList new_function_parameters;
|
||||
|
||||
/// Generate the vertex buffer binding name
|
||||
/// @param index index to append to buffer name
|
||||
|
|
Loading…
Reference in New Issue