Add semantic::CallTarget, have Function derive from it
CallTarget holds parameter information. This is simple to extract from an ast::Function.
CallTarget will also be used for intrinsics, which can be overloaded. CallTarget will hold the resolved overload parameter signature.
Bug: tint:361
Change-Id: I4dadc4a99293f12ede9e9cbd9132ba5f9b9830ed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40284
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 5e3dbff..6b49645 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -383,6 +383,7 @@
"src/semantic/intrinsic.h",
"src/semantic/node.h",
"src/semantic/sem_call.cc",
+ "src/semantic/sem_call_target.cc",
"src/semantic/sem_expression.cc",
"src/semantic/sem_function.cc",
"src/semantic/sem_info.cc",
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3b417f0..556e803 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -197,6 +197,7 @@
semantic/intrinsic.h
semantic/node.h
semantic/sem_call.cc
+ semantic/sem_call_target.cc
semantic/sem_expression.cc
semantic/sem_member_accessor_expression.cc
semantic/sem_function.cc
diff --git a/src/semantic/call_target.h b/src/semantic/call_target.h
new file mode 100644
index 0000000..ddb6aac
--- /dev/null
+++ b/src/semantic/call_target.h
@@ -0,0 +1,61 @@
+// 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.
+
+#ifndef SRC_SEMANTIC_CALL_TARGET_H_
+#define SRC_SEMANTIC_CALL_TARGET_H_
+
+#include <utility>
+#include <vector>
+
+#include "src/semantic/node.h"
+#include "src/type/sampler_type.h"
+
+namespace tint {
+
+// Forward declarations
+namespace type {
+class Type;
+} // namespace type
+
+namespace semantic {
+
+/// Parameter describes a single parameter of a call target
+struct Parameter {
+ /// Parameter type
+ type::Type* type;
+};
+
+using Parameters = std::vector<Parameter>;
+
+/// CallTarget is the base for callable functions
+class CallTarget : public Castable<CallTarget, Node> {
+ public:
+ /// Constructor
+ /// @param parameters the parameters for the call target
+ explicit CallTarget(const semantic::Parameters& parameters);
+
+ /// Destructor
+ ~CallTarget() override;
+
+ /// @return the parameters of the call target
+ const Parameters& Parameters() const { return parameters_; }
+
+ private:
+ semantic::Parameters parameters_;
+};
+
+} // namespace semantic
+} // namespace tint
+
+#endif // SRC_SEMANTIC_CALL_TARGET_H_
diff --git a/src/semantic/function.h b/src/semantic/function.h
index 70708d9..652e14d 100644
--- a/src/semantic/function.h
+++ b/src/semantic/function.h
@@ -1,7 +1,6 @@
// 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
//
@@ -19,7 +18,7 @@
#include <utility>
#include <vector>
-#include "src/semantic/node.h"
+#include "src/semantic/call_target.h"
#include "src/type/sampler_type.h"
namespace tint {
@@ -27,20 +26,18 @@
// Forward declarations
namespace ast {
class BindingDecoration;
+class BuiltinDecoration;
+class Function;
class GroupDecoration;
class LocationDecoration;
-class BuiltinDecoration;
} // namespace ast
-namespace type {
-class Type;
-} // namespace type
namespace semantic {
class Variable;
/// Function holds the semantic information for function nodes.
-class Function : public Castable<Function, Node> {
+class Function : public Castable<Function, CallTarget> {
public:
/// Information about a binding
struct BindingInfo {
@@ -51,13 +48,15 @@
};
/// Constructor
+ /// @param ast the ast::Function
/// @param referenced_module_vars the referenced module variables
/// @param local_referenced_module_vars the locally referenced module
/// variables
/// @param ancestor_entry_points the ancestor entry points
- explicit Function(std::vector<const Variable*> referenced_module_vars,
- std::vector<const Variable*> local_referenced_module_vars,
- std::vector<Symbol> ancestor_entry_points);
+ Function(ast::Function* ast,
+ std::vector<const Variable*> referenced_module_vars,
+ std::vector<const Variable*> local_referenced_module_vars,
+ std::vector<Symbol> ancestor_entry_points);
/// Destructor
~Function() override;
diff --git a/src/semantic/sem_call.cc b/src/semantic/sem_call.cc
index fa6de41..72be60a 100644
--- a/src/semantic/sem_call.cc
+++ b/src/semantic/sem_call.cc
@@ -1,7 +1,6 @@
// 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
//
diff --git a/src/semantic/sem_call_target.cc b/src/semantic/sem_call_target.cc
new file mode 100644
index 0000000..3b79a55
--- /dev/null
+++ b/src/semantic/sem_call_target.cc
@@ -0,0 +1,30 @@
+// 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/call_target.h"
+
+#include "src/type/type.h"
+
+TINT_INSTANTIATE_CLASS_ID(tint::semantic::CallTarget);
+
+namespace tint {
+namespace semantic {
+
+CallTarget::CallTarget(const semantic::Parameters& parameters)
+ : parameters_(parameters) {}
+
+CallTarget::~CallTarget() = default;
+
+} // namespace semantic
+} // namespace tint
diff --git a/src/semantic/sem_function.cc b/src/semantic/sem_function.cc
index 26768ec..8c8d16c 100644
--- a/src/semantic/sem_function.cc
+++ b/src/semantic/sem_function.cc
@@ -16,6 +16,7 @@
#include "src/ast/binding_decoration.h"
#include "src/ast/builtin_decoration.h"
+#include "src/ast/function.h"
#include "src/ast/group_decoration.h"
#include "src/ast/location_decoration.h"
#include "src/ast/variable.h"
@@ -30,10 +31,25 @@
namespace tint {
namespace semantic {
-Function::Function(std::vector<const Variable*> referenced_module_vars,
+namespace {
+
+Parameters GetParameters(ast::Function* ast) {
+ semantic::Parameters parameters;
+ parameters.reserve(ast->params().size());
+ for (auto* param : ast->params()) {
+ parameters.emplace_back(Parameter{param->type()});
+ }
+ return parameters;
+}
+
+} // namespace
+
+Function::Function(ast::Function* ast,
+ std::vector<const Variable*> referenced_module_vars,
std::vector<const Variable*> local_referenced_module_vars,
std::vector<Symbol> ancestor_entry_points)
- : referenced_module_vars_(std::move(referenced_module_vars)),
+ : Base(GetParameters(ast)),
+ referenced_module_vars_(std::move(referenced_module_vars)),
local_referenced_module_vars_(std::move(local_referenced_module_vars)),
ancestor_entry_points_(std::move(ancestor_entry_points)) {}
diff --git a/src/semantic/variable.h b/src/semantic/variable.h
index 6f15dc7..9032fe9 100644
--- a/src/semantic/variable.h
+++ b/src/semantic/variable.h
@@ -1,7 +1,6 @@
// 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
//
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index 8665519..2e72f4a 100644
--- a/src/type_determiner.cc
+++ b/src/type_determiner.cc
@@ -1201,10 +1201,11 @@
for (auto it : function_to_info_) {
auto* func = it.first;
auto* info = it.second;
- sem.Add(func, builder_->create<semantic::Function>(
- remap_vars(info->referenced_module_vars),
- remap_vars(info->local_referenced_module_vars),
- info->ancestor_entry_points));
+ sem.Add(func,
+ builder_->create<semantic::Function>(
+ info->declaration, remap_vars(info->referenced_module_vars),
+ remap_vars(info->local_referenced_module_vars),
+ info->ancestor_entry_points));
}
}
diff --git a/src/writer/spirv/test_helper.h b/src/writer/spirv/test_helper.h
index ec017ca..aafc15d 100644
--- a/src/writer/spirv/test_helper.h
+++ b/src/writer/spirv/test_helper.h
@@ -16,6 +16,7 @@
#define SRC_WRITER_SPIRV_TEST_HELPER_H_
#include <memory>
+#include <string>
#include <utility>
#include "gtest/gtest.h"