tint: Add sem::Load node

This change adds the node, but this is (currently) not generated or used.

Bug: tint:1654
Change-Id: Id38e531bf811833cf576085805cb00f444ea5451
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99581
Commit-Queue: James Price <jrprice@google.com>
Kokoro: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2022-12-14 01:50:52 +00:00 committed by Dawn LUCI CQ
parent 6b4a9b5e9b
commit fbb339ff97
5 changed files with 93 additions and 1 deletions

View File

@ -429,6 +429,7 @@ libtint_source_set("libtint_core_all_src") {
"sem/if_statement.h",
"sem/index_accessor_expression.h",
"sem/info.h",
"sem/load.h",
"sem/loop_statement.h",
"sem/materialize.h",
"sem/module.h",
@ -662,6 +663,8 @@ libtint_source_set("libtint_sem_src") {
"sem/index_accessor_expression.h",
"sem/info.cc",
"sem/info.h",
"sem/load.cc",
"sem/load.h",
"sem/loop_statement.cc",
"sem/loop_statement.h",
"sem/materialize.cc",

View File

@ -322,6 +322,8 @@ list(APPEND TINT_LIB_SRCS
sem/index_accessor_expression.h
sem/info.cc
sem/info.h
sem/load.cc
sem/load.h
sem/loop_statement.cc
sem/loop_statement.h
sem/materialize.cc

37
src/tint/sem/load.cc Normal file
View File

@ -0,0 +1,37 @@
// Copyright 2022 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/tint/sem/load.h"
#include "src/tint/debug.h"
#include "src/tint/type/reference.h"
TINT_INSTANTIATE_TYPEINFO(tint::sem::Load);
namespace tint::sem {
Load::Load(const Expression* ref, const Statement* statement)
: Base(/* declaration */ ref->Declaration(),
/* type */ ref->Type()->UnwrapRef(),
/* stage */ EvaluationStage::kRuntime, // Loads can only be runtime
/* statement */ statement,
/* constant */ nullptr,
/* has_side_effects */ ref->HasSideEffects(),
/* root_ident */ ref->RootIdentifier()),
reference_(ref) {
TINT_ASSERT(Semantic, ref->Type()->Is<type::Reference>());
}
Load::~Load() = default;
} // namespace tint::sem

50
src/tint/sem/load.h Normal file
View File

@ -0,0 +1,50 @@
// Copyright 2022 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_TINT_SEM_LOAD_H_
#define SRC_TINT_SEM_LOAD_H_
#include "src/tint/sem/expression.h"
#include "src/tint/type/reference.h"
namespace tint::sem {
/// Load is a semantic expression which represents the load of a reference to a non-reference value.
/// Loads from reference types are implicit in WGSL, so the Load semantic node shares the same AST
/// node as the inner semantic node.
class Load final : public Castable<Load, Expression> {
public:
/// Constructor
/// @param reference the reference expression being loaded
/// @param statement the statement that owns this expression
Load(const Expression* reference, const Statement* statement);
/// Destructor
~Load() override;
/// @return the reference being loaded
const Expression* Reference() const { return reference_; }
/// @returns the type of the loaded reference.
const type::Reference* ReferenceType() const {
return static_cast<const type::Reference*>(reference_->Type());
}
private:
Expression const* const reference_;
};
} // namespace tint::sem
#endif // SRC_TINT_SEM_LOAD_H_

View File

@ -40,7 +40,7 @@ class Materialize final : public Castable<Materialize, Expression> {
/// Destructor
~Materialize() override;
/// @return the target of the call
/// @return the expression being materialized
const Expression* Expr() const { return expr_; }
private: