mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-02 03:13:50 +00:00
sem: Add new TypeConstructor and TypeCast CallTargets
Nothing yet creates or uses these. Also add Constant to sem::Call. These will be needed for TypeConstructors / TypeCasts. Bug: tint:888 Change-Id: I5b8c64062f3262bdffd210bb012db980c5610b26 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69107 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
parent
2194a842ba
commit
5a40c6564c
@ -408,6 +408,8 @@ libtint_source_set("libtint_core_all_src") {
|
|||||||
"sem/storage_texture_type.h",
|
"sem/storage_texture_type.h",
|
||||||
"sem/switch_statement.h",
|
"sem/switch_statement.h",
|
||||||
"sem/texture_type.h",
|
"sem/texture_type.h",
|
||||||
|
"sem/type_cast.h",
|
||||||
|
"sem/type_constructor.h",
|
||||||
"sem/type.h",
|
"sem/type.h",
|
||||||
"sem/type_manager.h",
|
"sem/type_manager.h",
|
||||||
"sem/type_mappings.h",
|
"sem/type_mappings.h",
|
||||||
@ -574,6 +576,10 @@ libtint_source_set("libtint_sem_src") {
|
|||||||
"sem/switch_statement.h",
|
"sem/switch_statement.h",
|
||||||
"sem/texture_type.cc",
|
"sem/texture_type.cc",
|
||||||
"sem/texture_type.h",
|
"sem/texture_type.h",
|
||||||
|
"sem/type_cast.cc",
|
||||||
|
"sem/type_cast.h",
|
||||||
|
"sem/type_constructor.cc",
|
||||||
|
"sem/type_constructor.h",
|
||||||
"sem/type.cc",
|
"sem/type.cc",
|
||||||
"sem/type.h",
|
"sem/type.h",
|
||||||
"sem/type_manager.cc",
|
"sem/type_manager.cc",
|
||||||
|
@ -379,6 +379,10 @@ set(TINT_LIB_SRCS
|
|||||||
sem/switch_statement.h
|
sem/switch_statement.h
|
||||||
sem/texture_type.cc
|
sem/texture_type.cc
|
||||||
sem/texture_type.h
|
sem/texture_type.h
|
||||||
|
sem/type_cast.cc
|
||||||
|
sem/type_cast.h
|
||||||
|
sem/type_constructor.cc
|
||||||
|
sem/type_constructor.h
|
||||||
sem/type.cc
|
sem/type.cc
|
||||||
sem/type.h
|
sem/type.h
|
||||||
sem/type_manager.cc
|
sem/type_manager.cc
|
||||||
|
@ -2500,7 +2500,7 @@ sem::Call* Resolver::IntrinsicCall(const ast::CallExpression* expr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto* call = builder_->create<sem::Call>(expr, intrinsic, std::move(args),
|
auto* call = builder_->create<sem::Call>(expr, intrinsic, std::move(args),
|
||||||
current_statement_);
|
current_statement_, sem::Constant{});
|
||||||
|
|
||||||
current_function_->AddDirectlyCalledIntrinsic(intrinsic);
|
current_function_->AddDirectlyCalledIntrinsic(intrinsic);
|
||||||
|
|
||||||
@ -2544,7 +2544,7 @@ sem::Call* Resolver::FunctionCall(const ast::CallExpression* expr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto* call = builder_->create<sem::Call>(expr, target, std::move(args),
|
auto* call = builder_->create<sem::Call>(expr, target, std::move(args),
|
||||||
current_statement_);
|
current_statement_, sem::Constant{});
|
||||||
|
|
||||||
if (current_function_) {
|
if (current_function_) {
|
||||||
target->AddCallSite(call);
|
target->AddCallSite(call);
|
||||||
|
@ -25,8 +25,9 @@ namespace sem {
|
|||||||
Call::Call(const ast::CallExpression* declaration,
|
Call::Call(const ast::CallExpression* declaration,
|
||||||
const CallTarget* target,
|
const CallTarget* target,
|
||||||
std::vector<const sem::Expression*> arguments,
|
std::vector<const sem::Expression*> arguments,
|
||||||
Statement* statement)
|
const Statement* statement,
|
||||||
: Base(declaration, target->ReturnType(), statement, Constant{}),
|
Constant constant)
|
||||||
|
: Base(declaration, target->ReturnType(), statement, std::move(constant)),
|
||||||
target_(target),
|
target_(target),
|
||||||
arguments_(std::move(arguments)) {}
|
arguments_(std::move(arguments)) {}
|
||||||
|
|
||||||
|
@ -32,10 +32,12 @@ class Call : public Castable<Call, Expression> {
|
|||||||
/// @param target the call target
|
/// @param target the call target
|
||||||
/// @param arguments the call arguments
|
/// @param arguments the call arguments
|
||||||
/// @param statement the statement that owns this expression
|
/// @param statement the statement that owns this expression
|
||||||
|
/// @param constant the constant value of this expression
|
||||||
Call(const ast::CallExpression* declaration,
|
Call(const ast::CallExpression* declaration,
|
||||||
const CallTarget* target,
|
const CallTarget* target,
|
||||||
std::vector<const sem::Expression*> arguments,
|
std::vector<const sem::Expression*> arguments,
|
||||||
Statement* statement);
|
const Statement* statement,
|
||||||
|
Constant constant);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Call() override;
|
~Call() override;
|
||||||
|
@ -56,7 +56,8 @@ struct CallTargetSignature {
|
|||||||
int IndexOf(ParameterUsage usage) const;
|
int IndexOf(ParameterUsage usage) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// CallTarget is the base for callable functions
|
/// CallTarget is the base for callable functions, intrinsics, type constructors
|
||||||
|
/// and type casts.
|
||||||
class CallTarget : public Castable<CallTarget, Node> {
|
class CallTarget : public Castable<CallTarget, Node> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
|
@ -41,6 +41,9 @@ class Expression : public Castable<Expression, Node> {
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
~Expression() override;
|
~Expression() override;
|
||||||
|
|
||||||
|
/// @returns the AST node
|
||||||
|
const ast::Expression* Declaration() const { return declaration_; }
|
||||||
|
|
||||||
/// @return the resolved type of the expression
|
/// @return the resolved type of the expression
|
||||||
const sem::Type* Type() const { return type_; }
|
const sem::Type* Type() const { return type_; }
|
||||||
|
|
||||||
@ -50,9 +53,6 @@ class Expression : public Castable<Expression, Node> {
|
|||||||
/// @return the constant value of this expression
|
/// @return the constant value of this expression
|
||||||
const Constant& ConstantValue() const { return constant_; }
|
const Constant& ConstantValue() const { return constant_; }
|
||||||
|
|
||||||
/// @returns the AST node
|
|
||||||
const ast::Expression* Declaration() const { return declaration_; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// The AST expression node for this semantic expression
|
/// The AST expression node for this semantic expression
|
||||||
const ast::Expression* const declaration_;
|
const ast::Expression* const declaration_;
|
||||||
|
28
src/sem/type_cast.cc
Normal file
28
src/sem/type_cast.cc
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// 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/sem/type_cast.h"
|
||||||
|
|
||||||
|
TINT_INSTANTIATE_TYPEINFO(tint::sem::TypeCast);
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace sem {
|
||||||
|
|
||||||
|
TypeCast::TypeCast(const sem::Type* type, const sem::Parameter* parameter)
|
||||||
|
: Base(type, ParameterList{parameter}) {}
|
||||||
|
|
||||||
|
TypeCast::~TypeCast() = default;
|
||||||
|
|
||||||
|
} // namespace sem
|
||||||
|
} // namespace tint
|
44
src/sem/type_cast.h
Normal file
44
src/sem/type_cast.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// 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_SEM_TYPE_CAST_H_
|
||||||
|
#define SRC_SEM_TYPE_CAST_H_
|
||||||
|
|
||||||
|
#include "src/sem/call_target.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace sem {
|
||||||
|
|
||||||
|
/// TypeCast is the CallTarget for a type cast.
|
||||||
|
class TypeCast : public Castable<TypeCast, CallTarget> {
|
||||||
|
public:
|
||||||
|
/// Constructor
|
||||||
|
/// @param type the target type of the cast
|
||||||
|
/// @param parameter the type cast parameter
|
||||||
|
TypeCast(const sem::Type* type, const sem::Parameter* parameter);
|
||||||
|
|
||||||
|
/// Destructor
|
||||||
|
~TypeCast() override;
|
||||||
|
|
||||||
|
/// @returns the cast source type
|
||||||
|
const sem::Type* Source() const { return Parameters()[0]->Type(); }
|
||||||
|
|
||||||
|
/// @returns the cast target type
|
||||||
|
const sem::Type* Target() const { return ReturnType(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sem
|
||||||
|
} // namespace tint
|
||||||
|
|
||||||
|
#endif // SRC_SEM_TYPE_CAST_H_
|
29
src/sem/type_constructor.cc
Normal file
29
src/sem/type_constructor.cc
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// 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/sem/type_constructor.h"
|
||||||
|
|
||||||
|
TINT_INSTANTIATE_TYPEINFO(tint::sem::TypeConstructor);
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace sem {
|
||||||
|
|
||||||
|
TypeConstructor::TypeConstructor(const sem::Type* type,
|
||||||
|
const ParameterList& parameters)
|
||||||
|
: Base(type, parameters) {}
|
||||||
|
|
||||||
|
TypeConstructor::~TypeConstructor() = default;
|
||||||
|
|
||||||
|
} // namespace sem
|
||||||
|
} // namespace tint
|
38
src/sem/type_constructor.h
Normal file
38
src/sem/type_constructor.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// 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_SEM_TYPE_CONSTRUCTOR_H_
|
||||||
|
#define SRC_SEM_TYPE_CONSTRUCTOR_H_
|
||||||
|
|
||||||
|
#include "src/sem/call_target.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace sem {
|
||||||
|
|
||||||
|
/// TypeConstructor is the CallTarget for a type constructor.
|
||||||
|
class TypeConstructor : public Castable<TypeConstructor, CallTarget> {
|
||||||
|
public:
|
||||||
|
/// Constructor
|
||||||
|
/// @param type the type that's being constructed
|
||||||
|
/// @param parameters the type constructor parameters
|
||||||
|
TypeConstructor(const sem::Type* type, const ParameterList& parameters);
|
||||||
|
|
||||||
|
/// Destructor
|
||||||
|
~TypeConstructor() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sem
|
||||||
|
} // namespace tint
|
||||||
|
|
||||||
|
#endif // SRC_SEM_TYPE_CONSTRUCTOR_H_
|
@ -188,7 +188,7 @@ class Parameter : public Castable<Parameter, Variable> {
|
|||||||
private:
|
private:
|
||||||
const uint32_t index_;
|
const uint32_t index_;
|
||||||
const ParameterUsage usage_;
|
const ParameterUsage usage_;
|
||||||
CallTarget const* owner_;
|
CallTarget const* owner_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// ParameterList is a list of Parameter
|
/// ParameterList is a list of Parameter
|
||||||
|
Loading…
x
Reference in New Issue
Block a user