mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-06 06:33:30 +00:00
Pull the mutable semantic fields from ast::Function and into a new semantic::Function node. Have the TypeDeterminer create these semantic::Function nodes. Bug: tint:390 Change-Id: I237b1bed8709dd9a3cfa24d85d48fc77b7e532da Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39902 Reviewed-by: David Neto <dneto@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
108 lines
3.9 KiB
C++
108 lines
3.9 KiB
C++
// Copyright 2021 The Tint Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "src/semantic/function.h"
|
|
|
|
#include "src/ast/builtin_decoration.h"
|
|
#include "src/ast/location_decoration.h"
|
|
#include "src/semantic/test_helper.h"
|
|
|
|
namespace tint {
|
|
namespace semantic {
|
|
namespace {
|
|
|
|
using FunctionTest = TestHelper;
|
|
|
|
TEST_F(FunctionTest, GetReferenceLocations) {
|
|
auto* loc1 = Var("loc1", ast::StorageClass::kInput, ty.i32(), nullptr,
|
|
ast::VariableDecorationList{
|
|
create<ast::LocationDecoration>(0),
|
|
});
|
|
|
|
auto* loc2 = Var("loc2", ast::StorageClass::kInput, ty.i32(), nullptr,
|
|
ast::VariableDecorationList{
|
|
create<ast::LocationDecoration>(1),
|
|
});
|
|
|
|
auto* builtin1 =
|
|
Var("builtin1", ast::StorageClass::kInput, ty.i32(), nullptr,
|
|
ast::VariableDecorationList{
|
|
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
|
|
});
|
|
|
|
auto* builtin2 =
|
|
Var("builtin2", ast::StorageClass::kInput, ty.i32(), nullptr,
|
|
ast::VariableDecorationList{
|
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
|
});
|
|
|
|
auto* f = create<Function>(
|
|
/* referenced_module_vars */ std::vector<ast::Variable*>{loc1, builtin1,
|
|
loc2, builtin2},
|
|
/* local_referenced_module_vars */ std::vector<ast::Variable*>{},
|
|
/* ancestor_entry_points */ std::vector<Symbol>{});
|
|
|
|
ASSERT_EQ(f->ReferencedModuleVariables().size(), 4u);
|
|
|
|
auto ref_locs = f->ReferencedLocationVariables();
|
|
ASSERT_EQ(ref_locs.size(), 2u);
|
|
EXPECT_EQ(ref_locs[0].first, loc1);
|
|
EXPECT_EQ(ref_locs[0].second->value(), 0u);
|
|
EXPECT_EQ(ref_locs[1].first, loc2);
|
|
EXPECT_EQ(ref_locs[1].second->value(), 1u);
|
|
}
|
|
|
|
TEST_F(FunctionTest, GetReferenceBuiltins) {
|
|
auto* loc1 = Var("loc1", ast::StorageClass::kInput, ty.i32(), nullptr,
|
|
ast::VariableDecorationList{
|
|
create<ast::LocationDecoration>(0),
|
|
});
|
|
|
|
auto* loc2 = Var("loc2", ast::StorageClass::kInput, ty.i32(), nullptr,
|
|
ast::VariableDecorationList{
|
|
create<ast::LocationDecoration>(1),
|
|
});
|
|
|
|
auto* builtin1 =
|
|
Var("builtin1", ast::StorageClass::kInput, ty.i32(), nullptr,
|
|
ast::VariableDecorationList{
|
|
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
|
|
});
|
|
|
|
auto* builtin2 =
|
|
Var("builtin2", ast::StorageClass::kInput, ty.i32(), nullptr,
|
|
ast::VariableDecorationList{
|
|
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
|
});
|
|
|
|
auto* f = create<Function>(
|
|
/* referenced_module_vars */ std::vector<ast::Variable*>{loc1, builtin1,
|
|
loc2, builtin2},
|
|
/* local_referenced_module_vars */ std::vector<ast::Variable*>{},
|
|
/* ancestor_entry_points */ std::vector<Symbol>{});
|
|
|
|
ASSERT_EQ(f->ReferencedModuleVariables().size(), 4u);
|
|
|
|
auto ref_locs = f->ReferencedBuiltinVariables();
|
|
ASSERT_EQ(ref_locs.size(), 2u);
|
|
EXPECT_EQ(ref_locs[0].first, builtin1);
|
|
EXPECT_EQ(ref_locs[0].second->value(), ast::Builtin::kPosition);
|
|
EXPECT_EQ(ref_locs[1].first, builtin2);
|
|
EXPECT_EQ(ref_locs[1].second->value(), ast::Builtin::kFragDepth);
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace semantic
|
|
} // namespace tint
|