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>
This commit is contained in:
Ben Clayton 2021-02-08 19:13:19 +00:00 committed by Commit Bot service account
parent 7efea888fa
commit 2ddb1783c5
10 changed files with 126 additions and 18 deletions

View File

@ -383,6 +383,7 @@ source_set("libtint_core_src") {
"src/semantic/intrinsic.h", "src/semantic/intrinsic.h",
"src/semantic/node.h", "src/semantic/node.h",
"src/semantic/sem_call.cc", "src/semantic/sem_call.cc",
"src/semantic/sem_call_target.cc",
"src/semantic/sem_expression.cc", "src/semantic/sem_expression.cc",
"src/semantic/sem_function.cc", "src/semantic/sem_function.cc",
"src/semantic/sem_info.cc", "src/semantic/sem_info.cc",

View File

@ -197,6 +197,7 @@ set(TINT_LIB_SRCS
semantic/intrinsic.h semantic/intrinsic.h
semantic/node.h semantic/node.h
semantic/sem_call.cc semantic/sem_call.cc
semantic/sem_call_target.cc
semantic/sem_expression.cc semantic/sem_expression.cc
semantic/sem_member_accessor_expression.cc semantic/sem_member_accessor_expression.cc
semantic/sem_function.cc semantic/sem_function.cc

View File

@ -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_

View File

@ -1,7 +1,6 @@
// Copyright 2021 The Tint Authors. // Copyright 2021 The Tint Authors.
// //
// Licensed under the Apache License, Version 2.0(the "License"); // Licensed under the Apache License, Version 2.0(the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
@ -19,7 +18,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "src/semantic/node.h" #include "src/semantic/call_target.h"
#include "src/type/sampler_type.h" #include "src/type/sampler_type.h"
namespace tint { namespace tint {
@ -27,20 +26,18 @@ namespace tint {
// Forward declarations // Forward declarations
namespace ast { namespace ast {
class BindingDecoration; class BindingDecoration;
class BuiltinDecoration;
class Function;
class GroupDecoration; class GroupDecoration;
class LocationDecoration; class LocationDecoration;
class BuiltinDecoration;
} // namespace ast } // namespace ast
namespace type {
class Type;
} // namespace type
namespace semantic { namespace semantic {
class Variable; class Variable;
/// Function holds the semantic information for function nodes. /// Function holds the semantic information for function nodes.
class Function : public Castable<Function, Node> { class Function : public Castable<Function, CallTarget> {
public: public:
/// Information about a binding /// Information about a binding
struct BindingInfo { struct BindingInfo {
@ -51,11 +48,13 @@ class Function : public Castable<Function, Node> {
}; };
/// Constructor /// Constructor
/// @param ast the ast::Function
/// @param referenced_module_vars the referenced module variables /// @param referenced_module_vars the referenced module variables
/// @param local_referenced_module_vars the locally referenced module /// @param local_referenced_module_vars the locally referenced module
/// variables /// variables
/// @param ancestor_entry_points the ancestor entry points /// @param ancestor_entry_points the ancestor entry points
explicit Function(std::vector<const Variable*> referenced_module_vars, Function(ast::Function* ast,
std::vector<const Variable*> referenced_module_vars,
std::vector<const Variable*> local_referenced_module_vars, std::vector<const Variable*> local_referenced_module_vars,
std::vector<Symbol> ancestor_entry_points); std::vector<Symbol> ancestor_entry_points);

View File

@ -1,7 +1,6 @@
// Copyright 2021 The Tint Authors. // Copyright 2021 The Tint Authors.
// //
// Licensed under the Apache License, Version 2.0(the "License"); // Licensed under the Apache License, Version 2.0(the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //

View File

@ -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

View File

@ -16,6 +16,7 @@
#include "src/ast/binding_decoration.h" #include "src/ast/binding_decoration.h"
#include "src/ast/builtin_decoration.h" #include "src/ast/builtin_decoration.h"
#include "src/ast/function.h"
#include "src/ast/group_decoration.h" #include "src/ast/group_decoration.h"
#include "src/ast/location_decoration.h" #include "src/ast/location_decoration.h"
#include "src/ast/variable.h" #include "src/ast/variable.h"
@ -30,10 +31,25 @@ TINT_INSTANTIATE_CLASS_ID(tint::semantic::Function);
namespace tint { namespace tint {
namespace semantic { 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<const Variable*> local_referenced_module_vars,
std::vector<Symbol> ancestor_entry_points) 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)), local_referenced_module_vars_(std::move(local_referenced_module_vars)),
ancestor_entry_points_(std::move(ancestor_entry_points)) {} ancestor_entry_points_(std::move(ancestor_entry_points)) {}

View File

@ -1,7 +1,6 @@
// Copyright 2021 The Tint Authors. // Copyright 2021 The Tint Authors.
// //
// Licensed under the Apache License, Version 2.0(the "License"); // Licensed under the Apache License, Version 2.0(the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //

View File

@ -1201,8 +1201,9 @@ void TypeDeterminer::CreateSemanticNodes() const {
for (auto it : function_to_info_) { for (auto it : function_to_info_) {
auto* func = it.first; auto* func = it.first;
auto* info = it.second; auto* info = it.second;
sem.Add(func, builder_->create<semantic::Function>( sem.Add(func,
remap_vars(info->referenced_module_vars), builder_->create<semantic::Function>(
info->declaration, remap_vars(info->referenced_module_vars),
remap_vars(info->local_referenced_module_vars), remap_vars(info->local_referenced_module_vars),
info->ancestor_entry_points)); info->ancestor_entry_points));
} }

View File

@ -16,6 +16,7 @@
#define SRC_WRITER_SPIRV_TEST_HELPER_H_ #define SRC_WRITER_SPIRV_TEST_HELPER_H_
#include <memory> #include <memory>
#include <string>
#include <utility> #include <utility>
#include "gtest/gtest.h" #include "gtest/gtest.h"