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/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",

View File

@ -197,6 +197,7 @@ set(TINT_LIB_SRCS
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

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.
//
// 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 @@ namespace tint {
// 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 @@ class Function : public Castable<Function, Node> {
};
/// 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;

View File

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

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/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 @@ TINT_INSTANTIATE_CLASS_ID(tint::semantic::Function);
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)) {}

View File

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

View File

@ -1201,10 +1201,11 @@ void TypeDeterminer::CreateSemanticNodes() const {
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));
}
}

View File

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