mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-12 06:45:16 +00:00
Start cleaning up tests (1/N)
Remove Source{} with ast::Builder::create<>
Use Builder helpers where possible
Change-Id: Ie404f3a963ed8c40e056590ebb4ae36f67a92753
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35505
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
f4daa505ec
commit
7eaf4b57ae
@@ -93,17 +93,17 @@ class BoundArrayAccessorsTest : public testing::Test {
|
||||
struct ModuleBuilder : public ast::BuilderWithModule {
|
||||
ast::Module Module() {
|
||||
Build();
|
||||
auto* body = create<ast::BlockStatement>(Source{}, statements);
|
||||
mod->AddFunction(create<ast::Function>(
|
||||
Source{}, mod->RegisterSymbol("func"), "func", ast::VariableList{},
|
||||
ty.void_, body, ast::FunctionDecorationList{}));
|
||||
auto* body = create<ast::BlockStatement>(statements);
|
||||
mod->AddFunction(create<ast::Function>(mod->RegisterSymbol("func"), "func",
|
||||
ast::VariableList{}, ty.void_, body,
|
||||
ast::FunctionDecorationList{}));
|
||||
return std::move(*mod);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void Build() = 0;
|
||||
void OnVariableBuilt(ast::Variable* var) override {
|
||||
statements.emplace_back(create<ast::VariableDeclStatement>(Source{}, var));
|
||||
statements.emplace_back(create<ast::VariableDeclStatement>(var));
|
||||
}
|
||||
ast::StatementList statements;
|
||||
};
|
||||
|
||||
@@ -53,33 +53,30 @@ struct ModuleBuilder : public ast::BuilderWithModule {
|
||||
TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
|
||||
struct Builder : ModuleBuilder {
|
||||
void Build() override {
|
||||
auto* block = create<ast::BlockStatement>(
|
||||
Source{},
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Source{}, Var("builtin_assignments_should_happen_before_this",
|
||||
tint::ast::StorageClass::kFunction, ty.f32)),
|
||||
});
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("builtin_assignments_should_happen_before_this",
|
||||
tint::ast::StorageClass::kFunction, ty.f32)),
|
||||
});
|
||||
|
||||
auto a_sym = mod->RegisterSymbol("non_entry_a");
|
||||
mod->AddFunction(create<ast::Function>(
|
||||
Source{}, a_sym, "non_entry_a", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
a_sym, "non_entry_a", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{}));
|
||||
|
||||
auto entry_sym = mod->RegisterSymbol("entry");
|
||||
auto* entry = create<ast::Function>(
|
||||
Source{}, entry_sym, "entry", ast::VariableList{}, ty.void_, block,
|
||||
entry_sym, "entry", ast::VariableList{}, ty.void_, block,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{},
|
||||
ast::PipelineStage::kVertex),
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
mod->AddFunction(entry);
|
||||
|
||||
auto b_sym = mod->RegisterSymbol("non_entry_b");
|
||||
mod->AddFunction(create<ast::Function>(
|
||||
Source{}, b_sym, "non_entry_b", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
b_sym, "non_entry_b", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{}));
|
||||
}
|
||||
};
|
||||
@@ -132,23 +129,22 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
|
||||
void Build() override {
|
||||
auto a_sym = mod->RegisterSymbol("non_entry_a");
|
||||
mod->AddFunction(create<ast::Function>(
|
||||
Source{}, a_sym, "non_entry_a", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
a_sym, "non_entry_a", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{}));
|
||||
|
||||
auto entry_sym = mod->RegisterSymbol("entry");
|
||||
mod->AddFunction(create<ast::Function>(
|
||||
Source{}, entry_sym, "entry", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
entry_sym, "entry", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{},
|
||||
ast::PipelineStage::kVertex),
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
}));
|
||||
|
||||
auto b_sym = mod->RegisterSymbol("non_entry_b");
|
||||
mod->AddFunction(create<ast::Function>(
|
||||
Source{}, b_sym, "non_entry_b", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
b_sym, "non_entry_b", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{}));
|
||||
}
|
||||
};
|
||||
@@ -194,21 +190,19 @@ TEST_F(EmitVertexPointSizeTest, NonVertexStage) {
|
||||
void Build() override {
|
||||
auto frag_sym = mod->RegisterSymbol("fragment_entry");
|
||||
auto* fragment_entry = create<ast::Function>(
|
||||
Source{}, frag_sym, "fragment_entry", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
frag_sym, "fragment_entry", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{},
|
||||
ast::PipelineStage::kFragment),
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
mod->AddFunction(fragment_entry);
|
||||
|
||||
auto comp_sym = mod->RegisterSymbol("compute_entry");
|
||||
auto* compute_entry = create<ast::Function>(
|
||||
Source{}, comp_sym, "compute_entry", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
comp_sym, "compute_entry", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{},
|
||||
ast::PipelineStage::kCompute),
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
mod->AddFunction(compute_entry);
|
||||
}
|
||||
|
||||
@@ -52,17 +52,15 @@ struct ModuleBuilder : public ast::BuilderWithModule {
|
||||
|
||||
protected:
|
||||
void AddBuiltinInput(const std::string& name, ast::Builtin builtin) {
|
||||
mod->AddGlobalVariable(
|
||||
Var(name, ast::StorageClass::kInput, ty.u32, nullptr,
|
||||
{create<ast::BuiltinDecoration>(Source{}, builtin)}));
|
||||
mod->AddGlobalVariable(Var(name, ast::StorageClass::kInput, ty.u32, nullptr,
|
||||
{create<ast::BuiltinDecoration>(builtin)}));
|
||||
}
|
||||
|
||||
ast::Function* AddFunction(const std::string& name,
|
||||
ast::StatementList stmts) {
|
||||
auto* func = create<ast::Function>(
|
||||
Source{}, mod->RegisterSymbol(name), name, ast::VariableList{}, ty.u32,
|
||||
create<ast::BlockStatement>(Source{}, stmts),
|
||||
ast::FunctionDecorationList{});
|
||||
mod->RegisterSymbol(name), name, ast::VariableList{}, ty.u32,
|
||||
create<ast::BlockStatement>(stmts), ast::FunctionDecorationList{});
|
||||
mod->AddFunction(func);
|
||||
return func;
|
||||
}
|
||||
@@ -77,10 +75,8 @@ TEST_F(FirstIndexOffsetTest, Error_AlreadyTransformed) {
|
||||
AddFunction(
|
||||
"test",
|
||||
{
|
||||
create<ast::ReturnStatement>(
|
||||
Source{},
|
||||
create<ast::IdentifierExpression>(
|
||||
Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")),
|
||||
create<ast::ReturnStatement>(create<ast::IdentifierExpression>(
|
||||
mod->RegisterSymbol("vert_idx"), "vert_idx")),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -124,10 +120,8 @@ TEST_F(FirstIndexOffsetTest, BasicModuleVertexIndex) {
|
||||
AddFunction(
|
||||
"test",
|
||||
{
|
||||
create<ast::ReturnStatement>(
|
||||
Source{},
|
||||
create<ast::IdentifierExpression>(
|
||||
Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")),
|
||||
create<ast::ReturnStatement>(create<ast::IdentifierExpression>(
|
||||
mod->RegisterSymbol("vert_idx"), "vert_idx")),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -206,10 +200,8 @@ TEST_F(FirstIndexOffsetTest, BasicModuleInstanceIndex) {
|
||||
AddFunction(
|
||||
"test",
|
||||
{
|
||||
create<ast::ReturnStatement>(
|
||||
Source{},
|
||||
create<ast::IdentifierExpression>(
|
||||
Source{}, mod->RegisterSymbol("inst_idx"), "inst_idx")),
|
||||
create<ast::ReturnStatement>(create<ast::IdentifierExpression>(
|
||||
mod->RegisterSymbol("inst_idx"), "inst_idx")),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -286,7 +278,7 @@ TEST_F(FirstIndexOffsetTest, BasicModuleBothIndex) {
|
||||
AddBuiltinInput("inst_idx", ast::Builtin::kInstanceIdx);
|
||||
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
|
||||
AddFunction("test", {
|
||||
create<ast::ReturnStatement>(Source{}, Expr(1u)),
|
||||
create<ast::ReturnStatement>(Expr(1u)),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -365,22 +357,16 @@ TEST_F(FirstIndexOffsetTest, NestedCalls) {
|
||||
AddFunction(
|
||||
"func1",
|
||||
{
|
||||
create<ast::ReturnStatement>(
|
||||
Source{},
|
||||
create<ast::IdentifierExpression>(
|
||||
Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")),
|
||||
});
|
||||
AddFunction(
|
||||
"func2",
|
||||
{
|
||||
create<ast::ReturnStatement>(
|
||||
Source{},
|
||||
create<ast::CallExpression>(
|
||||
Source{},
|
||||
create<ast::IdentifierExpression>(
|
||||
Source{}, mod->RegisterSymbol("func1"), "func1"),
|
||||
ast::ExpressionList{})),
|
||||
create<ast::ReturnStatement>(create<ast::IdentifierExpression>(
|
||||
mod->RegisterSymbol("vert_idx"), "vert_idx")),
|
||||
});
|
||||
AddFunction("func2",
|
||||
{
|
||||
create<ast::ReturnStatement>(create<ast::CallExpression>(
|
||||
create<ast::IdentifierExpression>(
|
||||
mod->RegisterSymbol("func1"), "func1"),
|
||||
ast::ExpressionList{})),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user