mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-12 06:45:16 +00:00
Add helper for function creation.
This CL adds a Func helper to the ast builder class. The helper is then used through the various files to simplify function creation. Change-Id: Ie93777586e9311d82cff5932dfba2c4ca763ae08 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35823 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
5e5e36e7d2
commit
181d8baf8f
@@ -93,10 +93,8 @@ class BoundArrayAccessorsTest : public testing::Test {
|
||||
struct ModuleBuilder : public ast::BuilderWithModule {
|
||||
ast::Module Module() {
|
||||
Build();
|
||||
auto* body = create<ast::BlockStatement>(statements);
|
||||
mod->AddFunction(create<ast::Function>(mod->RegisterSymbol("func"), "func",
|
||||
ast::VariableList{}, ty.void_, body,
|
||||
ast::FunctionDecorationList{}));
|
||||
mod->AddFunction(Func("func", ast::VariableList{}, ty.void_, statements,
|
||||
ast::FunctionDecorationList{}));
|
||||
return std::move(*mod);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,31 +53,25 @@ struct ModuleBuilder : public ast::BuilderWithModule {
|
||||
TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
|
||||
struct Builder : ModuleBuilder {
|
||||
void Build() override {
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("builtin_assignments_should_happen_before_this",
|
||||
tint::ast::StorageClass::kFunction, ty.f32)),
|
||||
});
|
||||
mod->AddFunction(Func("non_entry_a", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{},
|
||||
ast::FunctionDecorationList{}));
|
||||
|
||||
auto a_sym = mod->RegisterSymbol("non_entry_a");
|
||||
mod->AddFunction(create<ast::Function>(
|
||||
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>(
|
||||
entry_sym, "entry", ast::VariableList{}, ty.void_, block,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
auto* entry =
|
||||
Func("entry", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("builtin_assignments_should_happen_before_this",
|
||||
tint::ast::StorageClass::kFunction, ty.f32)),
|
||||
},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
mod->AddFunction(entry);
|
||||
|
||||
auto b_sym = mod->RegisterSymbol("non_entry_b");
|
||||
mod->AddFunction(create<ast::Function>(
|
||||
b_sym, "non_entry_b", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{}));
|
||||
mod->AddFunction(Func("non_entry_b", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{},
|
||||
ast::FunctionDecorationList{}));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -127,25 +121,19 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
|
||||
TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
|
||||
struct Builder : ModuleBuilder {
|
||||
void Build() override {
|
||||
auto a_sym = mod->RegisterSymbol("non_entry_a");
|
||||
mod->AddFunction(create<ast::Function>(
|
||||
a_sym, "non_entry_a", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{}));
|
||||
mod->AddFunction(Func("non_entry_a", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{},
|
||||
ast::FunctionDecorationList{}));
|
||||
|
||||
auto entry_sym = mod->RegisterSymbol("entry");
|
||||
mod->AddFunction(create<ast::Function>(
|
||||
entry_sym, "entry", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
}));
|
||||
mod->AddFunction(
|
||||
Func("entry", ast::VariableList{}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
}));
|
||||
|
||||
auto b_sym = mod->RegisterSymbol("non_entry_b");
|
||||
mod->AddFunction(create<ast::Function>(
|
||||
b_sym, "non_entry_b", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{}));
|
||||
mod->AddFunction(Func("non_entry_b", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{},
|
||||
ast::FunctionDecorationList{}));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -188,19 +176,15 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
|
||||
TEST_F(EmitVertexPointSizeTest, NonVertexStage) {
|
||||
struct Builder : ModuleBuilder {
|
||||
void Build() override {
|
||||
auto frag_sym = mod->RegisterSymbol("fragment_entry");
|
||||
auto* fragment_entry = create<ast::Function>(
|
||||
frag_sym, "fragment_entry", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
auto* fragment_entry = Func(
|
||||
"fragment_entry", ast::VariableList{}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
mod->AddFunction(fragment_entry);
|
||||
|
||||
auto comp_sym = mod->RegisterSymbol("compute_entry");
|
||||
auto* compute_entry = create<ast::Function>(
|
||||
comp_sym, "compute_entry", ast::VariableList{}, ty.void_,
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
auto* compute_entry = Func(
|
||||
"compute_entry", ast::VariableList{}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
@@ -58,9 +58,8 @@ struct ModuleBuilder : public ast::BuilderWithModule {
|
||||
|
||||
ast::Function* AddFunction(const std::string& name,
|
||||
ast::StatementList stmts) {
|
||||
auto* func = create<ast::Function>(
|
||||
mod->RegisterSymbol(name), name, ast::VariableList{}, ty.u32,
|
||||
create<ast::BlockStatement>(stmts), ast::FunctionDecorationList{});
|
||||
auto* func = Func(name, ast::VariableList{}, ty.u32, stmts,
|
||||
ast::FunctionDecorationList{});
|
||||
mod->AddFunction(func);
|
||||
return func;
|
||||
}
|
||||
|
||||
@@ -46,12 +46,10 @@ class VertexPullingHelper : public ast::BuilderWithModule {
|
||||
|
||||
// Create basic module with an entry point and vertex function
|
||||
void InitBasicModule() {
|
||||
auto* func = create<ast::Function>(
|
||||
mod->RegisterSymbol("main"), "main", ast::VariableList{},
|
||||
mod->create<ast::type::Void>(),
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
|
||||
auto* func =
|
||||
Func("main", ast::VariableList{}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
|
||||
mod->AddFunction(func);
|
||||
}
|
||||
|
||||
@@ -115,13 +113,11 @@ TEST_F(VertexPullingTest, Error_InvalidEntryPoint) {
|
||||
}
|
||||
|
||||
TEST_F(VertexPullingTest, Error_EntryPointWrongStage) {
|
||||
auto* func = create<ast::Function>(
|
||||
mod->RegisterSymbol("main"), "main", ast::VariableList{},
|
||||
mod->create<ast::type::Void>(),
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", ast::VariableList{}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
mod->AddFunction(func);
|
||||
|
||||
InitTransform({});
|
||||
|
||||
Reference in New Issue
Block a user