Rename 'as' to 'bitcast'
This CL updates Tint to use 'bitcast' instead of 'as' for the OpBitcast
conversions.
Bug: tint:241
Change-Id: I53a80de10421b2d9cc009527eebe5ff07e1285c2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28801
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index e522f12..1110d6c 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -219,14 +219,14 @@
sources = [
"src/ast/array_accessor_expression.cc",
"src/ast/array_accessor_expression.h",
- "src/ast/as_expression.cc",
- "src/ast/as_expression.h",
"src/ast/assignment_statement.cc",
"src/ast/assignment_statement.h",
"src/ast/binary_expression.cc",
"src/ast/binary_expression.h",
"src/ast/binding_decoration.cc",
"src/ast/binding_decoration.h",
+ "src/ast/bitcast_expression.cc",
+ "src/ast/bitcast_expression.h",
"src/ast/block_statement.cc",
"src/ast/block_statement.h",
"src/ast/bool_literal.cc",
@@ -686,10 +686,10 @@
source_set("tint_unittests_core_src") {
sources = [
"src/ast/array_accessor_expression_test.cc",
- "src/ast/as_expression_test.cc",
"src/ast/assignment_statement_test.cc",
"src/ast/binary_expression_test.cc",
"src/ast/binding_decoration_test.cc",
+ "src/ast/bitcast_expression_test.cc",
"src/ast/block_statement_test.cc",
"src/ast/bool_literal_test.cc",
"src/ast/break_statement_test.cc",
@@ -826,9 +826,9 @@
sources = [
"src/writer/spirv/binary_writer_test.cc",
"src/writer/spirv/builder_accessor_expression_test.cc",
- "src/writer/spirv/builder_as_expression_test.cc",
"src/writer/spirv/builder_assign_test.cc",
"src/writer/spirv/builder_binary_expression_test.cc",
+ "src/writer/spirv/builder_bitcast_expression_test.cc",
"src/writer/spirv/builder_block_test.cc",
"src/writer/spirv/builder_call_test.cc",
"src/writer/spirv/builder_cast_expression_test.cc",
@@ -972,9 +972,9 @@
sources = [
"src/writer/wgsl/generator_impl_alias_type_test.cc",
"src/writer/wgsl/generator_impl_array_accessor_test.cc",
- "src/writer/wgsl/generator_impl_as_test.cc",
"src/writer/wgsl/generator_impl_assign_test.cc",
"src/writer/wgsl/generator_impl_binary_test.cc",
+ "src/writer/wgsl/generator_impl_bitcast_test.cc",
"src/writer/wgsl/generator_impl_block_test.cc",
"src/writer/wgsl/generator_impl_break_test.cc",
"src/writer/wgsl/generator_impl_call_test.cc",
@@ -1021,9 +1021,9 @@
sources = [
"src/writer/msl/generator_impl_alias_type_test.cc",
"src/writer/msl/generator_impl_array_accessor_test.cc",
- "src/writer/msl/generator_impl_as_test.cc",
"src/writer/msl/generator_impl_assign_test.cc",
"src/writer/msl/generator_impl_binary_test.cc",
+ "src/writer/msl/generator_impl_bitcast_test.cc",
"src/writer/msl/generator_impl_block_test.cc",
"src/writer/msl/generator_impl_break_test.cc",
"src/writer/msl/generator_impl_call_test.cc",
@@ -1073,9 +1073,9 @@
sources = [
"src/writer/hlsl/generator_impl_alias_type_test.cc",
"src/writer/hlsl/generator_impl_array_accessor_test.cc",
- "src/writer/hlsl/generator_impl_as_test.cc",
"src/writer/hlsl/generator_impl_assign_test.cc",
"src/writer/hlsl/generator_impl_binary_test.cc",
+ "src/writer/hlsl/generator_impl_bitcast_test.cc",
"src/writer/hlsl/generator_impl_block_test.cc",
"src/writer/hlsl/generator_impl_break_test.cc",
"src/writer/hlsl/generator_impl_call_test.cc",
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 58129fb..16409aa 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -40,14 +40,14 @@
../include/tint/tint.h
ast/array_accessor_expression.cc
ast/array_accessor_expression.h
- ast/as_expression.cc
- ast/as_expression.h
ast/assignment_statement.cc
ast/assignment_statement.h
ast/binary_expression.cc
ast/binary_expression.h
ast/binding_decoration.cc
ast/binding_decoration.h
+ ast/bitcast_expression.cc
+ ast/bitcast_expression.h
ast/block_statement.cc
ast/block_statement.h
ast/bool_literal.h
@@ -296,9 +296,9 @@
set(TINT_TEST_SRCS
ast/array_accessor_expression_test.cc
- ast/as_expression_test.cc
ast/assignment_statement_test.cc
ast/binding_decoration_test.cc
+ ast/bitcast_expression_test.cc
ast/block_statement_test.cc
ast/bool_literal_test.cc
ast/break_statement_test.cc
@@ -484,9 +484,9 @@
list(APPEND TINT_TEST_SRCS
writer/spirv/binary_writer_test.cc
writer/spirv/builder_accessor_expression_test.cc
- writer/spirv/builder_as_expression_test.cc
writer/spirv/builder_assign_test.cc
writer/spirv/builder_binary_expression_test.cc
+ writer/spirv/builder_bitcast_expression_test.cc
writer/spirv/builder_block_test.cc
writer/spirv/builder_call_test.cc
writer/spirv/builder_cast_expression_test.cc
@@ -519,9 +519,9 @@
writer/wgsl/generator_impl_test.cc
writer/wgsl/generator_impl_alias_type_test.cc
writer/wgsl/generator_impl_array_accessor_test.cc
- writer/wgsl/generator_impl_as_test.cc
writer/wgsl/generator_impl_assign_test.cc
writer/wgsl/generator_impl_binary_test.cc
+ writer/wgsl/generator_impl_bitcast_test.cc
writer/wgsl/generator_impl_block_test.cc
writer/wgsl/generator_impl_break_test.cc
writer/wgsl/generator_impl_call_test.cc
@@ -549,9 +549,9 @@
list(APPEND TINT_TEST_SRCS
writer/msl/generator_impl_alias_type_test.cc
writer/msl/generator_impl_array_accessor_test.cc
- writer/msl/generator_impl_as_test.cc
writer/msl/generator_impl_assign_test.cc
writer/msl/generator_impl_binary_test.cc
+ writer/msl/generator_impl_bitcast_test.cc
writer/msl/generator_impl_block_test.cc
writer/msl/generator_impl_break_test.cc
writer/msl/generator_impl_call_test.cc
@@ -583,9 +583,9 @@
list(APPEND TINT_TEST_SRCS
writer/hlsl/generator_impl_alias_type_test.cc
writer/hlsl/generator_impl_array_accessor_test.cc
- writer/hlsl/generator_impl_as_test.cc
writer/hlsl/generator_impl_assign_test.cc
writer/hlsl/generator_impl_binary_test.cc
+ writer/hlsl/generator_impl_bitcast_test.cc
writer/hlsl/generator_impl_block_test.cc
writer/hlsl/generator_impl_break_test.cc
writer/hlsl/generator_impl_call_test.cc
diff --git a/src/ast/as_expression.cc b/src/ast/as_expression.cc
deleted file mode 100644
index 65705cc..0000000
--- a/src/ast/as_expression.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2020 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/ast/as_expression.h"
-
-namespace tint {
-namespace ast {
-
-AsExpression::AsExpression() : Expression() {}
-
-AsExpression::AsExpression(type::Type* type, std::unique_ptr<Expression> expr)
- : Expression(), type_(type), expr_(std::move(expr)) {}
-
-AsExpression::AsExpression(const Source& source,
- type::Type* type,
- std::unique_ptr<Expression> expr)
- : Expression(source), type_(type), expr_(std::move(expr)) {}
-
-AsExpression::AsExpression(AsExpression&&) = default;
-AsExpression::~AsExpression() = default;
-
-bool AsExpression::IsAs() const {
- return true;
-}
-
-bool AsExpression::IsValid() const {
- if (expr_ == nullptr || !expr_->IsValid())
- return false;
- return type_ != nullptr;
-}
-
-void AsExpression::to_str(std::ostream& out, size_t indent) const {
- make_indent(out, indent);
- out << "As<" << type_->type_name() << ">{" << std::endl;
- expr_->to_str(out, indent + 2);
- make_indent(out, indent);
- out << "}" << std::endl;
-}
-
-} // namespace ast
-} // namespace tint
diff --git a/src/ast/bitcast_expression.cc b/src/ast/bitcast_expression.cc
new file mode 100644
index 0000000..8f83477
--- /dev/null
+++ b/src/ast/bitcast_expression.cc
@@ -0,0 +1,53 @@
+// Copyright 2020 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/ast/bitcast_expression.h"
+
+namespace tint {
+namespace ast {
+
+BitcastExpression::BitcastExpression() : Expression() {}
+
+BitcastExpression::BitcastExpression(type::Type* type,
+ std::unique_ptr<Expression> expr)
+ : Expression(), type_(type), expr_(std::move(expr)) {}
+
+BitcastExpression::BitcastExpression(const Source& source,
+ type::Type* type,
+ std::unique_ptr<Expression> expr)
+ : Expression(source), type_(type), expr_(std::move(expr)) {}
+
+BitcastExpression::BitcastExpression(BitcastExpression&&) = default;
+BitcastExpression::~BitcastExpression() = default;
+
+bool BitcastExpression::IsBitcast() const {
+ return true;
+}
+
+bool BitcastExpression::IsValid() const {
+ if (expr_ == nullptr || !expr_->IsValid())
+ return false;
+ return type_ != nullptr;
+}
+
+void BitcastExpression::to_str(std::ostream& out, size_t indent) const {
+ make_indent(out, indent);
+ out << "Bitcast<" << type_->type_name() << ">{" << std::endl;
+ expr_->to_str(out, indent + 2);
+ make_indent(out, indent);
+ out << "}" << std::endl;
+}
+
+} // namespace ast
+} // namespace tint
diff --git a/src/ast/as_expression.h b/src/ast/bitcast_expression.h
similarity index 72%
rename from src/ast/as_expression.h
rename to src/ast/bitcast_expression.h
index e8feeb6..c74fc7b 100644
--- a/src/ast/as_expression.h
+++ b/src/ast/bitcast_expression.h
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#ifndef SRC_AST_AS_EXPRESSION_H_
-#define SRC_AST_AS_EXPRESSION_H_
+#ifndef SRC_AST_BITCAST_EXPRESSION_H_
+#define SRC_AST_BITCAST_EXPRESSION_H_
#include <memory>
#include <utility>
@@ -25,25 +25,25 @@
namespace tint {
namespace ast {
-/// An as expression
-class AsExpression : public Expression {
+/// A bitcast expression
+class BitcastExpression : public Expression {
public:
/// Constructor
- AsExpression();
+ BitcastExpression();
/// Constructor
/// @param type the type
/// @param expr the expr
- AsExpression(type::Type* type, std::unique_ptr<Expression> expr);
+ BitcastExpression(type::Type* type, std::unique_ptr<Expression> expr);
/// Constructor
- /// @param source the as expression source
+ /// @param source the bitcast expression source
/// @param type the type
/// @param expr the expr
- AsExpression(const Source& source,
- type::Type* type,
- std::unique_ptr<Expression> expr);
+ BitcastExpression(const Source& source,
+ type::Type* type,
+ std::unique_ptr<Expression> expr);
/// Move constructor
- AsExpression(AsExpression&&);
- ~AsExpression() override;
+ BitcastExpression(BitcastExpression&&);
+ ~BitcastExpression() override;
/// Sets the type
/// @param type the type
@@ -57,8 +57,8 @@
/// @returns the expression
Expression* expr() const { return expr_.get(); }
- /// @returns true if this is an as expression
- bool IsAs() const override;
+ /// @returns true if this is a bitcast expression
+ bool IsBitcast() const override;
/// @returns true if the node is valid
bool IsValid() const override;
@@ -69,7 +69,7 @@
void to_str(std::ostream& out, size_t indent) const override;
private:
- AsExpression(const AsExpression&) = delete;
+ BitcastExpression(const BitcastExpression&) = delete;
type::Type* type_ = nullptr;
std::unique_ptr<Expression> expr_;
@@ -78,4 +78,4 @@
} // namespace ast
} // namespace tint
-#endif // SRC_AST_AS_EXPRESSION_H_
+#endif // SRC_AST_BITCAST_EXPRESSION_H_
diff --git a/src/ast/as_expression_test.cc b/src/ast/bitcast_expression_test.cc
similarity index 67%
rename from src/ast/as_expression_test.cc
rename to src/ast/bitcast_expression_test.cc
index e29a89d..accd1ff 100644
--- a/src/ast/as_expression_test.cc
+++ b/src/ast/bitcast_expression_test.cc
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "src/ast/as_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "gtest/gtest.h"
#include "src/ast/identifier_expression.h"
@@ -22,74 +22,74 @@
namespace ast {
namespace {
-using AsExpressionTest = testing::Test;
+using BitcastExpressionTest = testing::Test;
-TEST_F(AsExpressionTest, Create) {
+TEST_F(BitcastExpressionTest, Create) {
type::F32Type f32;
auto expr = std::make_unique<IdentifierExpression>("expr");
auto* expr_ptr = expr.get();
- AsExpression exp(&f32, std::move(expr));
+ BitcastExpression exp(&f32, std::move(expr));
ASSERT_EQ(exp.type(), &f32);
ASSERT_EQ(exp.expr(), expr_ptr);
}
-TEST_F(AsExpressionTest, CreateWithSource) {
+TEST_F(BitcastExpressionTest, CreateWithSource) {
type::F32Type f32;
auto expr = std::make_unique<IdentifierExpression>("expr");
- AsExpression exp(Source{20, 2}, &f32, std::move(expr));
+ BitcastExpression exp(Source{20, 2}, &f32, std::move(expr));
auto src = exp.source();
EXPECT_EQ(src.line, 20u);
EXPECT_EQ(src.column, 2u);
}
-TEST_F(AsExpressionTest, IsAs) {
- AsExpression exp;
- EXPECT_TRUE(exp.IsAs());
+TEST_F(BitcastExpressionTest, IsBitcast) {
+ BitcastExpression exp;
+ EXPECT_TRUE(exp.IsBitcast());
}
-TEST_F(AsExpressionTest, IsValid) {
+TEST_F(BitcastExpressionTest, IsValid) {
type::F32Type f32;
auto expr = std::make_unique<IdentifierExpression>("expr");
- AsExpression exp(&f32, std::move(expr));
+ BitcastExpression exp(&f32, std::move(expr));
EXPECT_TRUE(exp.IsValid());
}
-TEST_F(AsExpressionTest, IsValid_MissingType) {
+TEST_F(BitcastExpressionTest, IsValid_MissingType) {
auto expr = std::make_unique<IdentifierExpression>("expr");
- AsExpression exp;
+ BitcastExpression exp;
exp.set_expr(std::move(expr));
EXPECT_FALSE(exp.IsValid());
}
-TEST_F(AsExpressionTest, IsValid_MissingExpr) {
+TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
type::F32Type f32;
- AsExpression exp;
+ BitcastExpression exp;
exp.set_type(&f32);
EXPECT_FALSE(exp.IsValid());
}
-TEST_F(AsExpressionTest, IsValid_InvalidExpr) {
+TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) {
type::F32Type f32;
auto expr = std::make_unique<IdentifierExpression>("");
- AsExpression e(&f32, std::move(expr));
+ BitcastExpression e(&f32, std::move(expr));
EXPECT_FALSE(e.IsValid());
}
-TEST_F(AsExpressionTest, ToStr) {
+TEST_F(BitcastExpressionTest, ToStr) {
type::F32Type f32;
auto expr = std::make_unique<IdentifierExpression>("expr");
- AsExpression exp(&f32, std::move(expr));
+ BitcastExpression exp(&f32, std::move(expr));
std::ostringstream out;
exp.to_str(out, 2);
- EXPECT_EQ(out.str(), R"( As<__f32>{
+ EXPECT_EQ(out.str(), R"( Bitcast<__f32>{
Identifier{expr}
}
)");
diff --git a/src/ast/expression.cc b/src/ast/expression.cc
index c1c9765..2e1ad97 100644
--- a/src/ast/expression.cc
+++ b/src/ast/expression.cc
@@ -17,8 +17,8 @@
#include <assert.h>
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
#include "src/ast/binary_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/call_expression.h"
#include "src/ast/cast_expression.h"
#include "src/ast/constructor_expression.h"
@@ -45,7 +45,7 @@
return false;
}
-bool Expression::IsAs() const {
+bool Expression::IsBitcast() const {
return false;
}
@@ -81,9 +81,9 @@
return static_cast<const ArrayAccessorExpression*>(this);
}
-const AsExpression* Expression::AsAs() const {
- assert(IsAs());
- return static_cast<const AsExpression*>(this);
+const BitcastExpression* Expression::AsBitcast() const {
+ assert(IsBitcast());
+ return static_cast<const BitcastExpression*>(this);
}
const BinaryExpression* Expression::AsBinary() const {
@@ -126,9 +126,9 @@
return static_cast<ArrayAccessorExpression*>(this);
}
-AsExpression* Expression::AsAs() {
- assert(IsAs());
- return static_cast<AsExpression*>(this);
+BitcastExpression* Expression::AsBitcast() {
+ assert(IsBitcast());
+ return static_cast<BitcastExpression*>(this);
}
BinaryExpression* Expression::AsBinary() {
diff --git a/src/ast/expression.h b/src/ast/expression.h
index 43c4c40..b69e9da 100644
--- a/src/ast/expression.h
+++ b/src/ast/expression.h
@@ -25,8 +25,8 @@
namespace ast {
class ArrayAccessorExpression;
-class AsExpression;
class BinaryExpression;
+class BitcastExpression;
class CallExpression;
class CastExpression;
class IdentifierExpression;
@@ -47,8 +47,8 @@
/// @returns true if this is an array accessor expression
virtual bool IsArrayAccessor() const;
- /// @returns true if this is an as expression
- virtual bool IsAs() const;
+ /// @returns true if this is a bitcast expression
+ virtual bool IsBitcast() const;
/// @returns true if this is a call expression
virtual bool IsCall() const;
/// @returns true if this is a cast expression
@@ -66,8 +66,8 @@
/// @returns the expression as an array accessor
const ArrayAccessorExpression* AsArrayAccessor() const;
- /// @returns the expression as an as
- const AsExpression* AsAs() const;
+ /// @returns the expression as a bitcast
+ const BitcastExpression* AsBitcast() const;
/// @returns the expression as a call
const CallExpression* AsCall() const;
/// @returns the expression as a cast
@@ -85,8 +85,8 @@
/// @returns the expression as an array accessor
ArrayAccessorExpression* AsArrayAccessor();
- /// @returns the expression as an as
- AsExpression* AsAs();
+ /// @returns the expression as a bitcast
+ BitcastExpression* AsBitcast();
/// @returns the expression as a call
CallExpression* AsCall();
/// @returns the expression as a cast
diff --git a/src/ast/transform/vertex_pulling_transform.cc b/src/ast/transform/vertex_pulling_transform.cc
index 69b9f43..23fd90b 100644
--- a/src/ast/transform/vertex_pulling_transform.cc
+++ b/src/ast/transform/vertex_pulling_transform.cc
@@ -15,9 +15,9 @@
#include "src/ast/transform/vertex_pulling_transform.h"
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/decorated_variable.h"
#include "src/ast/expression.h"
#include "src/ast/member_accessor_expression.h"
@@ -361,16 +361,16 @@
uint32_t buffer,
std::unique_ptr<Expression> pos) {
// as<T> reinterprets bits
- return std::make_unique<AsExpression>(GetI32Type(),
- AccessU32(buffer, std::move(pos)));
+ return std::make_unique<BitcastExpression>(GetI32Type(),
+ AccessU32(buffer, std::move(pos)));
}
std::unique_ptr<Expression> VertexPullingTransform::AccessF32(
uint32_t buffer,
std::unique_ptr<Expression> pos) {
// as<T> reinterprets bits
- return std::make_unique<AsExpression>(GetF32Type(),
- AccessU32(buffer, std::move(pos)));
+ return std::make_unique<BitcastExpression>(GetF32Type(),
+ AccessU32(buffer, std::move(pos)));
}
std::unique_ptr<Expression> VertexPullingTransform::AccessPrimitive(
diff --git a/src/ast/transform/vertex_pulling_transform_test.cc b/src/ast/transform/vertex_pulling_transform_test.cc
index caf4e4a..e2569b2 100644
--- a/src/ast/transform/vertex_pulling_transform_test.cc
+++ b/src/ast/transform/vertex_pulling_transform_test.cc
@@ -185,7 +185,7 @@
}
Assignment{
Identifier{var_a}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0}
@@ -266,7 +266,7 @@
}
Assignment{
Identifier{var_a}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0}
@@ -347,7 +347,7 @@
}
Assignment{
Identifier{var_a}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0}
@@ -480,7 +480,7 @@
}
Assignment{
Identifier{var_a}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0}
@@ -508,7 +508,7 @@
}
Assignment{
Identifier{var_b}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_1}
@@ -599,7 +599,7 @@
}
Assignment{
Identifier{var_a}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0}
@@ -629,7 +629,7 @@
Identifier{var_b}
TypeConstructor{
__vec_4__f32
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0}
@@ -646,7 +646,7 @@
}
}
}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0}
@@ -663,7 +663,7 @@
}
}
}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0}
@@ -680,7 +680,7 @@
}
}
}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0}
@@ -805,7 +805,7 @@
Identifier{var_a}
TypeConstructor{
__vec_2__f32
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0}
@@ -822,7 +822,7 @@
}
}
}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0}
@@ -857,7 +857,7 @@
Identifier{var_b}
TypeConstructor{
__vec_3__f32
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_1}
@@ -874,7 +874,7 @@
}
}
}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_1}
@@ -891,7 +891,7 @@
}
}
}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_1}
@@ -926,7 +926,7 @@
Identifier{var_c}
TypeConstructor{
__vec_4__f32
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_2}
@@ -943,7 +943,7 @@
}
}
}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_2}
@@ -960,7 +960,7 @@
}
}
}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_2}
@@ -977,7 +977,7 @@
}
}
}
- As<__f32>{
+ Bitcast<__f32>{
ArrayAccessor{
MemberAccessor{
Identifier{tint_pulling_vertex_buffer_2}
diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc
index 320dd08..bc59df1 100644
--- a/src/reader/spirv/function.cc
+++ b/src/reader/spirv/function.cc
@@ -28,9 +28,9 @@
#include "source/opt/module.h"
#include "spirv/unified1/GLSL.std.450.h"
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/bool_literal.h"
#include "src/ast/break_statement.h"
#include "src/ast/call_expression.h"
@@ -2719,7 +2719,7 @@
}
if (opcode == SpvOpBitcast) {
- return {ast_type, std::make_unique<ast::AsExpression>(
+ return {ast_type, std::make_unique<ast::BitcastExpression>(
ast_type, MakeOperand(inst, 0).expr)};
}
@@ -3469,7 +3469,7 @@
if (requested_type == expr_type) {
return result;
}
- return {requested_type, std::make_unique<ast::AsExpression>(
+ return {requested_type, std::make_unique<ast::BitcastExpression>(
requested_type, std::move(result.expr))};
}
diff --git a/src/reader/spirv/function_arithmetic_test.cc b/src/reader/spirv/function_arithmetic_test.cc
index ba9656d..94632c2 100644
--- a/src/reader/spirv/function_arithmetic_test.cc
+++ b/src/reader/spirv/function_arithmetic_test.cc
@@ -96,7 +96,7 @@
})";
}
if (assembly == "cast_int_v2uint_10_20") {
- return R"(As<__vec_2__i32>{
+ return R"(Bitcast<__vec_2__i32>{
TypeConstructor{
__vec_2__u32
ScalarConstructor{10}
@@ -170,7 +170,7 @@
{
UnaryOp{
negation
- As<__i32>{
+ Bitcast<__i32>{
ScalarConstructor{10}
}
}
@@ -197,7 +197,7 @@
none
__u32
{
- As<__u32>{
+ Bitcast<__u32>{
UnaryOp{
negation
ScalarConstructor{30}
@@ -226,10 +226,10 @@
none
__u32
{
- As<__u32>{
+ Bitcast<__u32>{
UnaryOp{
negation
- As<__i32>{
+ Bitcast<__i32>{
ScalarConstructor{10}
}
}
@@ -290,7 +290,7 @@
{
UnaryOp{
negation
- As<__vec_2__i32>{
+ Bitcast<__vec_2__i32>{
TypeConstructor{
__vec_2__u32
ScalarConstructor{10}
@@ -321,7 +321,7 @@
none
__vec_2__u32
{
- As<__vec_2__u32>{
+ Bitcast<__vec_2__u32>{
UnaryOp{
negation
TypeConstructor{
@@ -354,10 +354,10 @@
none
__vec_2__u32
{
- As<__vec_2__u32>{
+ Bitcast<__vec_2__u32>{
UnaryOp{
negation
- As<__vec_2__i32>{
+ Bitcast<__vec_2__i32>{
TypeConstructor{
__vec_2__u32
ScalarConstructor{10}
@@ -654,12 +654,12 @@
// Mixed, returning int, second arg uint
BinaryData{"int", "int_30", "OpSDiv", "uint_10", "__i32",
"ScalarConstructor{30}", "divide",
- R"(As<__i32>{
+ R"(Bitcast<__i32>{
ScalarConstructor{10}
})"},
// Mixed, returning int, first arg uint
BinaryData{"int", "uint_10", "OpSDiv", "int_30", "__i32",
- R"(As<__i32>{
+ R"(Bitcast<__i32>{
ScalarConstructor{10}
})",
"divide", "ScalarConstructor{30}"},
@@ -696,7 +696,7 @@
none
__u32
{
- As<__u32>{
+ Bitcast<__u32>{
Binary{
ScalarConstructor{30}
divide
@@ -731,7 +731,7 @@
none
__vec_2__u32
{
- As<__vec_2__u32>{
+ Bitcast<__vec_2__u32>{
Binary{
TypeConstructor{
__vec_2__i32
@@ -798,12 +798,12 @@
// Mixed, returning int, second arg uint
BinaryData{"int", "int_30", "OpSMod", "uint_10", "__i32",
"ScalarConstructor{30}", "modulo",
- R"(As<__i32>{
+ R"(Bitcast<__i32>{
ScalarConstructor{10}
})"},
// Mixed, returning int, first arg uint
BinaryData{"int", "uint_10", "OpSMod", "int_30", "__i32",
- R"(As<__i32>{
+ R"(Bitcast<__i32>{
ScalarConstructor{10}
})",
"modulo", "ScalarConstructor{30}"},
@@ -840,7 +840,7 @@
none
__u32
{
- As<__u32>{
+ Bitcast<__u32>{
Binary{
ScalarConstructor{30}
modulo
@@ -875,7 +875,7 @@
none
__vec_2__u32
{
- As<__vec_2__u32>{
+ Bitcast<__vec_2__u32>{
Binary{
TypeConstructor{
__vec_2__i32
diff --git a/src/reader/spirv/function_bit_test.cc b/src/reader/spirv/function_bit_test.cc
index 01a7b98..a68362b 100644
--- a/src/reader/spirv/function_bit_test.cc
+++ b/src/reader/spirv/function_bit_test.cc
@@ -91,7 +91,7 @@
})";
}
if (assembly == "cast_int_v2uint_10_20") {
- return R"(As<__vec_2__i32>{
+ return R"(Bitcast<__vec_2__i32>{
TypeConstructor{
__vec_2__u32
ScalarConstructor{10}
@@ -421,7 +421,7 @@
none
__i32
{
- As<__i32>{
+ Bitcast<__i32>{
UnaryOp{
not
ScalarConstructor{10}
@@ -450,7 +450,7 @@
none
__u32
{
- As<__u32>{
+ Bitcast<__u32>{
UnaryOp{
not
ScalarConstructor{30}
@@ -537,7 +537,7 @@
none
__vec_2__i32
{
- As<__vec_2__i32>{
+ Bitcast<__vec_2__i32>{
UnaryOp{
not
TypeConstructor{
@@ -570,7 +570,7 @@
none
__vec_2__u32
{
- As<__vec_2__u32>{
+ Bitcast<__vec_2__u32>{
UnaryOp{
not
TypeConstructor{
diff --git a/src/reader/spirv/function_conversion_test.cc b/src/reader/spirv/function_conversion_test.cc
index 1500eb4..37525b9 100644
--- a/src/reader/spirv/function_conversion_test.cc
+++ b/src/reader/spirv/function_conversion_test.cc
@@ -88,7 +88,7 @@
none
__u32
{
- As<__u32>{
+ Bitcast<__u32>{
ScalarConstructor{50.000000}
}
}
@@ -114,7 +114,7 @@
none
__vec_2__f32
{
- As<__vec_2__f32>{
+ Bitcast<__vec_2__f32>{
TypeConstructor{
__vec_2__u32
ScalarConstructor{10}
@@ -270,7 +270,7 @@
__f32
{
Cast<__f32>(
- As<__i32>{
+ Bitcast<__i32>{
Identifier{x_30}
}
)
@@ -324,7 +324,7 @@
__vec_2__f32
{
Cast<__vec_2__f32>(
- As<__vec_2__i32>{
+ Bitcast<__vec_2__i32>{
Identifier{x_30}
}
)
@@ -385,7 +385,7 @@
__f32
{
Cast<__f32>(
- As<__u32>{
+ Bitcast<__u32>{
Identifier{x_30}
}
)
@@ -439,7 +439,7 @@
__vec_2__f32
{
Cast<__vec_2__f32>(
- As<__vec_2__u32>{
+ Bitcast<__vec_2__u32>{
Identifier{x_30}
}
)
@@ -552,7 +552,7 @@
none
__u32
{
- As<__u32>{
+ Bitcast<__u32>{
Cast<__i32>(
Identifier{x_30}
)
@@ -606,7 +606,7 @@
none
__vec_2__u32
{
- As<__vec_2__u32>{
+ Bitcast<__vec_2__u32>{
Cast<__vec_2__i32>(
Identifier{x_30}
)
@@ -668,7 +668,7 @@
none
__i32
{
- As<__i32>{
+ Bitcast<__i32>{
Cast<__u32>(
Identifier{x_30}
)
@@ -722,7 +722,7 @@
none
__vec_2__i32
{
- As<__vec_2__i32>{
+ Bitcast<__vec_2__i32>{
Cast<__vec_2__u32>(
Identifier{x_30}
)
diff --git a/src/reader/spirv/function_logical_test.cc b/src/reader/spirv/function_logical_test.cc
index 24793d1..6e1c336 100644
--- a/src/reader/spirv/function_logical_test.cc
+++ b/src/reader/spirv/function_logical_test.cc
@@ -92,17 +92,17 @@
})";
}
if (assembly == "cast_uint_10") {
- return R"(As<__i32>{
+ return R"(Bitcast<__i32>{
ScalarConstructor{10}
})";
}
if (assembly == "cast_uint_20") {
- return R"(As<__i32>{
+ return R"(Bitcast<__i32>{
ScalarConstructor{20}
})";
}
if (assembly == "cast_v2uint_10_20") {
- return R"(As<__vec_2__i32>{
+ return R"(Bitcast<__vec_2__i32>{
TypeConstructor{
__vec_2__u32
ScalarConstructor{10}
@@ -118,7 +118,7 @@
})";
}
if (assembly == "cast_v2uint_20_10") {
- return R"(As<__vec_2__i32>{
+ return R"(Bitcast<__vec_2__i32>{
TypeConstructor{
__vec_2__u32
ScalarConstructor{20}
@@ -127,12 +127,12 @@
})";
}
if (assembly == "cast_int_30") {
- return R"(As<__u32>{
+ return R"(Bitcast<__u32>{
ScalarConstructor{30}
})";
}
if (assembly == "cast_int_40") {
- return R"(As<__u32>{
+ return R"(Bitcast<__u32>{
ScalarConstructor{40}
})";
}
@@ -144,7 +144,7 @@
})";
}
if (assembly == "cast_v2int_30_40") {
- return R"(As<__vec_2__u32>{
+ return R"(Bitcast<__vec_2__u32>{
TypeConstructor{
__vec_2__i32
ScalarConstructor{30}
@@ -160,7 +160,7 @@
})";
}
if (assembly == "cast_v2int_40_30") {
- return R"(As<__vec_2__u32>{
+ return R"(Bitcast<__vec_2__u32>{
TypeConstructor{
__vec_2__i32
ScalarConstructor{40}
diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc
index 9c6c87d..a21bf6d 100644
--- a/src/reader/spirv/parser_impl.cc
+++ b/src/reader/spirv/parser_impl.cc
@@ -34,9 +34,9 @@
#include "source/opt/type_manager.h"
#include "source/opt/types.h"
#include "spirv-tools/libspirv.hpp"
-#include "src/ast/as_expression.h"
#include "src/ast/binary_expression.h"
#include "src/ast/binding_decoration.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/bool_literal.h"
#include "src/ast/builtin.h"
#include "src/ast/builtin_decoration.h"
@@ -1302,14 +1302,14 @@
auto* unsigned_ty = unsigned_type_for_[type];
if (unsigned_ty != nullptr) {
// Conversion is required.
- return {unsigned_ty, std::make_unique<ast::AsExpression>(
+ return {unsigned_ty, std::make_unique<ast::BitcastExpression>(
unsigned_ty, std::move(expr.expr))};
}
} else if (requires_signed) {
auto* signed_ty = signed_type_for_[type];
if (signed_ty != nullptr) {
// Conversion is required.
- return {signed_ty, std::make_unique<ast::AsExpression>(
+ return {signed_ty, std::make_unique<ast::BitcastExpression>(
signed_ty, std::move(expr.expr))};
}
}
@@ -1373,8 +1373,8 @@
if ((forced_result_ty == nullptr) || (forced_result_ty == expr.type)) {
return expr;
}
- return {expr.type,
- std::make_unique<ast::AsExpression>(expr.type, std::move(expr.expr))};
+ return {expr.type, std::make_unique<ast::BitcastExpression>(
+ expr.type, std::move(expr.expr))};
}
bool ParserImpl::EmitFunctions() {
diff --git a/src/reader/wgsl/lexer.cc b/src/reader/wgsl/lexer.cc
index 76d71e5..87b678f 100644
--- a/src/reader/wgsl/lexer.cc
+++ b/src/reader/wgsl/lexer.cc
@@ -471,10 +471,10 @@
Token Lexer::check_keyword(const Source& source, const std::string& str) {
if (str == "array")
return {Token::Type::kArray, source, "array"};
- if (str == "as")
- return {Token::Type::kAs, source, "as"};
if (str == "binding")
return {Token::Type::kBinding, source, "binding"};
+ if (str == "bitcast")
+ return {Token::Type::kBitcast, source, "bitcast"};
if (str == "block")
return {Token::Type::kBlock, source, "block"};
if (str == "bool")
diff --git a/src/reader/wgsl/lexer_test.cc b/src/reader/wgsl/lexer_test.cc
index 1e90cdb..c3b456e 100644
--- a/src/reader/wgsl/lexer_test.cc
+++ b/src/reader/wgsl/lexer_test.cc
@@ -413,8 +413,8 @@
KeywordTest,
testing::Values(
TokenData{"array", Token::Type::kArray},
- TokenData{"as", Token::Type::kAs},
TokenData{"binding", Token::Type::kBinding},
+ TokenData{"bitcast", Token::Type::kBitcast},
TokenData{"block", Token::Type::kBlock},
TokenData{"bool", Token::Type::kBool},
TokenData{"break", Token::Type::kBreak},
diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc
index 64a0649..1616ea8 100644
--- a/src/reader/wgsl/parser_impl.cc
+++ b/src/reader/wgsl/parser_impl.cc
@@ -18,9 +18,9 @@
#include <vector>
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
#include "src/ast/binary_expression.h"
#include "src/ast/binding_decoration.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/bool_literal.h"
#include "src/ast/break_statement.h"
#include "src/ast/builtin_decoration.h"
@@ -2790,7 +2790,7 @@
return paren;
}
- if (t.IsCast() || t.IsAs()) {
+ if (t.IsCast() || t.IsBitcast()) {
auto src = t;
next(); // Consume the peek
@@ -2827,8 +2827,8 @@
return std::make_unique<ast::CastExpression>(source, type,
std::move(params));
} else {
- return std::make_unique<ast::AsExpression>(source, type,
- std::move(params));
+ return std::make_unique<ast::BitcastExpression>(source, type,
+ std::move(params));
}
} else if (t.IsIdentifier()) {
diff --git a/src/reader/wgsl/parser_impl_primary_expression_test.cc b/src/reader/wgsl/parser_impl_primary_expression_test.cc
index e6a4265..bd459e1 100644
--- a/src/reader/wgsl/parser_impl_primary_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_primary_expression_test.cc
@@ -14,7 +14,7 @@
#include "gtest/gtest.h"
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/bool_literal.h"
#include "src/ast/cast_expression.h"
#include "src/ast/identifier_expression.h"
@@ -239,76 +239,76 @@
EXPECT_EQ(p->error(), "1:11: unable to parse expression");
}
-TEST_F(ParserImplTest, PrimaryExpression_As) {
+TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
auto* f32_type = tm()->Get(std::make_unique<ast::type::F32Type>());
- auto* p = parser("as<f32>(1)");
+ auto* p = parser("bitcast<f32>(1)");
auto e = p->primary_expression();
ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr);
- ASSERT_TRUE(e->IsAs());
+ ASSERT_TRUE(e->IsBitcast());
- auto* c = e->AsAs();
+ auto* c = e->AsBitcast();
ASSERT_EQ(c->type(), f32_type);
ASSERT_TRUE(c->expr()->IsConstructor());
ASSERT_TRUE(c->expr()->AsConstructor()->IsScalarConstructor());
}
-TEST_F(ParserImplTest, PrimaryExpression_As_MissingGreaterThan) {
- auto* p = parser("as<f32(1)");
+TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingGreaterThan) {
+ auto* p = parser("bitcast<f32(1)");
auto e = p->primary_expression();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:7: missing > for as expression");
+ EXPECT_EQ(p->error(), "1:12: missing > for bitcast expression");
}
-TEST_F(ParserImplTest, PrimaryExpression_As_MissingType) {
- auto* p = parser("as<>(1)");
+TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingType) {
+ auto* p = parser("bitcast<>(1)");
auto e = p->primary_expression();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:4: missing type for as expression");
+ EXPECT_EQ(p->error(), "1:9: missing type for bitcast expression");
}
-TEST_F(ParserImplTest, PrimaryExpression_As_InvalidType) {
- auto* p = parser("as<invalid>(1)");
+TEST_F(ParserImplTest, PrimaryExpression_Bitcast_InvalidType) {
+ auto* p = parser("bitcast<invalid>(1)");
auto e = p->primary_expression();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:4: unknown type alias 'invalid'");
+ EXPECT_EQ(p->error(), "1:9: unknown type alias 'invalid'");
}
-TEST_F(ParserImplTest, PrimaryExpression_As_MissingLeftParen) {
- auto* p = parser("as<f32>1)");
+TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingLeftParen) {
+ auto* p = parser("bitcast<f32>1)");
auto e = p->primary_expression();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:8: expected (");
+ EXPECT_EQ(p->error(), "1:13: expected (");
}
-TEST_F(ParserImplTest, PrimaryExpression_As_MissingRightParen) {
- auto* p = parser("as<f32>(1");
+TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingRightParen) {
+ auto* p = parser("bitcast<f32>(1");
auto e = p->primary_expression();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:10: expected )");
+ EXPECT_EQ(p->error(), "1:15: expected )");
}
-TEST_F(ParserImplTest, PrimaryExpression_As_MissingExpression) {
- auto* p = parser("as<f32>()");
+TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingExpression) {
+ auto* p = parser("bitcast<f32>()");
auto e = p->primary_expression();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:9: unable to parse expression");
+ EXPECT_EQ(p->error(), "1:14: unable to parse expression");
}
-TEST_F(ParserImplTest, PrimaryExpression_As_InvalidExpression) {
- auto* p = parser("as<f32>(if (a) {})");
+TEST_F(ParserImplTest, PrimaryExpression_bitcast_InvalidExpression) {
+ auto* p = parser("bitcast<f32>(if (a) {})");
auto e = p->primary_expression();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:9: unable to parse expression");
+ EXPECT_EQ(p->error(), "1:14: unable to parse expression");
}
} // namespace
diff --git a/src/reader/wgsl/token.cc b/src/reader/wgsl/token.cc
index 7afd80c..f836c0c 100644
--- a/src/reader/wgsl/token.cc
+++ b/src/reader/wgsl/token.cc
@@ -107,10 +107,10 @@
case Token::Type::kArray:
return "array";
- case Token::Type::kAs:
- return "as";
case Token::Type::kBinding:
return "binding";
+ case Token::Type::kBitcast:
+ return "bitcast";
case Token::Type::kBlock:
return "block";
case Token::Type::kBool:
diff --git a/src/reader/wgsl/token.h b/src/reader/wgsl/token.h
index c67ef34..ebd39e6 100644
--- a/src/reader/wgsl/token.h
+++ b/src/reader/wgsl/token.h
@@ -118,10 +118,10 @@
/// A 'array'
kArray,
- /// A 'as'
- kAs,
/// A 'binding'
kBinding,
+ /// A 'bitcast'
+ kBitcast,
/// A 'bool'
kBool,
/// A 'block'
@@ -495,10 +495,10 @@
/// @returns true if token is a 'array'
bool IsArray() const { return type_ == Type::kArray; }
- /// @returns true if token is a 'as'
- bool IsAs() const { return type_ == Type::kAs; }
/// @returns true if token is a 'binding'
bool IsBinding() const { return type_ == Type::kBinding; }
+ /// @returns true if token is a 'bitcast'
+ bool IsBitcast() const { return type_ == Type::kBitcast; }
/// @returns true if token is a 'block'
bool IsBlock() const { return type_ == Type::kBlock; }
/// @returns true if token is a 'bool'
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index 0c31e5a..dedf1f0 100644
--- a/src/type_determiner.cc
+++ b/src/type_determiner.cc
@@ -18,9 +18,9 @@
#include <vector>
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/block_statement.h"
#include "src/ast/break_statement.h"
#include "src/ast/call_expression.h"
@@ -296,12 +296,12 @@
if (expr->IsArrayAccessor()) {
return DetermineArrayAccessor(expr->AsArrayAccessor());
}
- if (expr->IsAs()) {
- return DetermineAs(expr->AsAs());
- }
if (expr->IsBinary()) {
return DetermineBinary(expr->AsBinary());
}
+ if (expr->IsBitcast()) {
+ return DetermineBitcast(expr->AsBitcast());
+ }
if (expr->IsCall()) {
return DetermineCall(expr->AsCall());
}
@@ -362,7 +362,7 @@
return true;
}
-bool TypeDeterminer::DetermineAs(ast::AsExpression* expr) {
+bool TypeDeterminer::DetermineBitcast(ast::BitcastExpression* expr) {
if (!DetermineResultType(expr->expr())) {
return false;
}
diff --git a/src/type_determiner.h b/src/type_determiner.h
index a7b689d..6ba3833 100644
--- a/src/type_determiner.h
+++ b/src/type_determiner.h
@@ -27,8 +27,8 @@
namespace ast {
class ArrayAccessorExpression;
-class AsExpression;
class BinaryExpression;
+class BitcastExpression;
class CallExpression;
class CastExpression;
class ConstructorExpression;
@@ -117,8 +117,8 @@
void set_entry_points(const std::string& fn_name, const std::string& ep_name);
bool DetermineArrayAccessor(ast::ArrayAccessorExpression* expr);
- bool DetermineAs(ast::AsExpression* expr);
bool DetermineBinary(ast::BinaryExpression* expr);
+ bool DetermineBitcast(ast::BitcastExpression* expr);
bool DetermineCall(ast::CallExpression* expr);
bool DetermineCast(ast::CastExpression* expr);
bool DetermineConstructor(ast::ConstructorExpression* expr);
diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc
index 21c29d4..9a6bd20 100644
--- a/src/type_determiner_test.cc
+++ b/src/type_determiner_test.cc
@@ -20,9 +20,9 @@
#include "gtest/gtest.h"
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/block_statement.h"
#include "src/ast/bool_literal.h"
#include "src/ast/break_statement.h"
@@ -611,14 +611,14 @@
EXPECT_TRUE(ptr->type()->IsF32());
}
-TEST_F(TypeDeterminerTest, Expr_As) {
+TEST_F(TypeDeterminerTest, Expr_Bitcast) {
ast::type::F32Type f32;
- ast::AsExpression as(&f32,
- std::make_unique<ast::IdentifierExpression>("name"));
+ ast::BitcastExpression bitcast(
+ &f32, std::make_unique<ast::IdentifierExpression>("name"));
- EXPECT_TRUE(td()->DetermineResultType(&as));
- ASSERT_NE(as.result_type(), nullptr);
- EXPECT_TRUE(as.result_type()->IsF32());
+ EXPECT_TRUE(td()->DetermineResultType(&bitcast));
+ ASSERT_NE(bitcast.result_type(), nullptr);
+ EXPECT_TRUE(bitcast.result_type()->IsF32());
}
TEST_F(TypeDeterminerTest, Expr_Call) {
diff --git a/src/validator_test.cc b/src/validator_test.cc
index 8381e5c..b97b58a 100644
--- a/src/validator_test.cc
+++ b/src/validator_test.cc
@@ -17,7 +17,6 @@
#include "gtest/gtest.h"
#include "spirv/unified1/GLSL.std.450.h"
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
#include "src/ast/bool_literal.h"
diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc
index bd20995..68a33ca 100644
--- a/src/writer/hlsl/generator_impl.cc
+++ b/src/writer/hlsl/generator_impl.cc
@@ -17,9 +17,9 @@
#include <sstream>
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/bool_literal.h"
#include "src/ast/call_expression.h"
#include "src/ast/call_statement.h"
@@ -238,12 +238,12 @@
return true;
}
-bool GeneratorImpl::EmitAs(std::ostream& pre,
- std::ostream& out,
- ast::AsExpression* expr) {
+bool GeneratorImpl::EmitBitcast(std::ostream& pre,
+ std::ostream& out,
+ ast::BitcastExpression* expr) {
if (!expr->type()->IsF32() && !expr->type()->IsI32() &&
!expr->type()->IsU32()) {
- error_ = "Unable to do as cast to type " + expr->type()->type_name();
+ error_ = "Unable to do bitcast to type " + expr->type()->type_name();
return false;
}
@@ -856,15 +856,15 @@
bool GeneratorImpl::EmitExpression(std::ostream& pre,
std::ostream& out,
ast::Expression* expr) {
- if (expr->IsAs()) {
- return EmitAs(pre, out, expr->AsAs());
- }
if (expr->IsArrayAccessor()) {
return EmitArrayAccessor(pre, out, expr->AsArrayAccessor());
}
if (expr->IsBinary()) {
return EmitBinary(pre, out, expr->AsBinary());
}
+ if (expr->IsBitcast()) {
+ return EmitBitcast(pre, out, expr->AsBitcast());
+ }
if (expr->IsCall()) {
return EmitCall(pre, out, expr->AsCall());
}
diff --git a/src/writer/hlsl/generator_impl.h b/src/writer/hlsl/generator_impl.h
index 031cf7e..e30c363 100644
--- a/src/writer/hlsl/generator_impl.h
+++ b/src/writer/hlsl/generator_impl.h
@@ -73,12 +73,6 @@
bool EmitArrayAccessor(std::ostream& pre,
std::ostream& out,
ast::ArrayAccessorExpression* expr);
- /// Handles generating an as expression
- /// @param pre the preamble for the expression stream
- /// @param out the output of the expression stream
- /// @param expr the as expression
- /// @returns true if the as was emitted
- bool EmitAs(std::ostream& pre, std::ostream& out, ast::AsExpression* expr);
/// Handles an assignment statement
/// @param out the output stream
/// @param stmt the statement to emit
@@ -92,6 +86,14 @@
bool EmitBinary(std::ostream& pre,
std::ostream& out,
ast::BinaryExpression* expr);
+ /// Handles generating a bitcast expression
+ /// @param pre the preamble for the expression stream
+ /// @param out the output of the expression stream
+ /// @param expr the as expression
+ /// @returns true if the bitcast was emitted
+ bool EmitBitcast(std::ostream& pre,
+ std::ostream& out,
+ ast::BitcastExpression* expr);
/// Handles a block statement
/// @param out the output stream
/// @param stmt the statement to emit
diff --git a/src/writer/hlsl/generator_impl_binary_test.cc b/src/writer/hlsl/generator_impl_binary_test.cc
index e6c515f..bec7a6d 100644
--- a/src/writer/hlsl/generator_impl_binary_test.cc
+++ b/src/writer/hlsl/generator_impl_binary_test.cc
@@ -14,9 +14,9 @@
#include <memory>
-#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/call_expression.h"
#include "src/ast/call_statement.h"
#include "src/ast/else_statement.h"
@@ -295,7 +295,7 @@
)");
}
-TEST_F(HlslGeneratorImplTest_Binary, As_WithLogical) {
+TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) {
// as<i32>(a && (b || c))
ast::type::I32Type i32;
@@ -303,7 +303,7 @@
auto b = std::make_unique<ast::IdentifierExpression>("b");
auto c = std::make_unique<ast::IdentifierExpression>("c");
- ast::AsExpression expr(
+ ast::BitcastExpression expr(
&i32, std::make_unique<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, std::move(a),
std::make_unique<ast::BinaryExpression>(
diff --git a/src/writer/hlsl/generator_impl_as_test.cc b/src/writer/hlsl/generator_impl_bitcast_test.cc
similarity index 66%
rename from src/writer/hlsl/generator_impl_as_test.cc
rename to src/writer/hlsl/generator_impl_bitcast_test.cc
index 663b1db..ffe34d7 100644
--- a/src/writer/hlsl/generator_impl_as_test.cc
+++ b/src/writer/hlsl/generator_impl_bitcast_test.cc
@@ -14,7 +14,7 @@
#include <memory>
-#include "src/ast/as_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/module.h"
#include "src/ast/type/f32_type.h"
@@ -27,32 +27,32 @@
namespace hlsl {
namespace {
-using HlslGeneratorImplTest_As = TestHelper;
+using HlslGeneratorImplTest_Bitcast = TestHelper;
-TEST_F(HlslGeneratorImplTest_As, EmitExpression_As_Float) {
+TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
ast::type::F32Type f32;
auto id = std::make_unique<ast::IdentifierExpression>("id");
- ast::AsExpression as(&f32, std::move(id));
+ ast::BitcastExpression bitcast(&f32, std::move(id));
- ASSERT_TRUE(gen().EmitExpression(pre(), out(), &as)) << gen().error();
+ ASSERT_TRUE(gen().EmitExpression(pre(), out(), &bitcast)) << gen().error();
EXPECT_EQ(result(), "asfloat(id)");
}
-TEST_F(HlslGeneratorImplTest_As, EmitExpression_As_Int) {
+TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
ast::type::I32Type i32;
auto id = std::make_unique<ast::IdentifierExpression>("id");
- ast::AsExpression as(&i32, std::move(id));
+ ast::BitcastExpression bitcast(&i32, std::move(id));
- ASSERT_TRUE(gen().EmitExpression(pre(), out(), &as)) << gen().error();
+ ASSERT_TRUE(gen().EmitExpression(pre(), out(), &bitcast)) << gen().error();
EXPECT_EQ(result(), "asint(id)");
}
-TEST_F(HlslGeneratorImplTest_As, EmitExpression_As_Uint) {
+TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
ast::type::U32Type u32;
auto id = std::make_unique<ast::IdentifierExpression>("id");
- ast::AsExpression as(&u32, std::move(id));
+ ast::BitcastExpression bitcast(&u32, std::move(id));
- ASSERT_TRUE(gen().EmitExpression(pre(), out(), &as)) << gen().error();
+ ASSERT_TRUE(gen().EmitExpression(pre(), out(), &bitcast)) << gen().error();
EXPECT_EQ(result(), "asuint(id)");
}
diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc
index c4f2329..b3efd73 100644
--- a/src/writer/msl/generator_impl.cc
+++ b/src/writer/msl/generator_impl.cc
@@ -15,9 +15,9 @@
#include "src/writer/msl/generator_impl.h"
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/block_statement.h"
#include "src/ast/bool_literal.h"
#include "src/ast/break_statement.h"
@@ -265,7 +265,7 @@
return true;
}
-bool GeneratorImpl::EmitAs(ast::AsExpression* expr) {
+bool GeneratorImpl::EmitBitcast(ast::BitcastExpression* expr) {
out_ << "as_type<";
if (!EmitType(expr->type(), "")) {
return false;
@@ -973,12 +973,12 @@
if (expr->IsArrayAccessor()) {
return EmitArrayAccessor(expr->AsArrayAccessor());
}
- if (expr->IsAs()) {
- return EmitAs(expr->AsAs());
- }
if (expr->IsBinary()) {
return EmitBinary(expr->AsBinary());
}
+ if (expr->IsBitcast()) {
+ return EmitBitcast(expr->AsBitcast());
+ }
if (expr->IsCall()) {
return EmitCall(expr->AsCall());
}
diff --git a/src/writer/msl/generator_impl.h b/src/writer/msl/generator_impl.h
index 68f5574..cc458d2 100644
--- a/src/writer/msl/generator_impl.h
+++ b/src/writer/msl/generator_impl.h
@@ -62,10 +62,6 @@
/// @param expr the expression to emit
/// @returns true if the array accessor was emitted
bool EmitArrayAccessor(ast::ArrayAccessorExpression* expr);
- /// Handles generating an as expression
- /// @param expr the as expression
- /// @returns true if the as was emitted
- bool EmitAs(ast::AsExpression* expr);
/// Handles an assignment statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
@@ -74,6 +70,10 @@
/// @param expr the binary expression
/// @returns true if the expression was emitted, false otherwise
bool EmitBinary(ast::BinaryExpression* expr);
+ /// Handles generating a bitcast expression
+ /// @param expr the bitcast expression
+ /// @returns true if the bitcast was emitted
+ bool EmitBitcast(ast::BitcastExpression* expr);
/// Handles a block statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
diff --git a/src/writer/msl/generator_impl_as_test.cc b/src/writer/msl/generator_impl_bitcast_test.cc
similarity index 84%
rename from src/writer/msl/generator_impl_as_test.cc
rename to src/writer/msl/generator_impl_bitcast_test.cc
index debc9f8..94474d7 100644
--- a/src/writer/msl/generator_impl_as_test.cc
+++ b/src/writer/msl/generator_impl_bitcast_test.cc
@@ -15,7 +15,7 @@
#include <memory>
#include "gtest/gtest.h"
-#include "src/ast/as_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/module.h"
#include "src/ast/type/f32_type.h"
@@ -28,14 +28,14 @@
using MslGeneratorImplTest = testing::Test;
-TEST_F(MslGeneratorImplTest, EmitExpression_As) {
+TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
ast::type::F32Type f32;
auto id = std::make_unique<ast::IdentifierExpression>("id");
- ast::AsExpression as(&f32, std::move(id));
+ ast::BitcastExpression bitcast(&f32, std::move(id));
ast::Module m;
GeneratorImpl g(&m);
- ASSERT_TRUE(g.EmitExpression(&as)) << g.error();
+ ASSERT_TRUE(g.EmitExpression(&bitcast)) << g.error();
EXPECT_EQ(g.result(), "as_type<float>(id)");
}
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index 529286f..a1a004e 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -20,10 +20,10 @@
#include "spirv/unified1/GLSL.std.450.h"
#include "spirv/unified1/spirv.h"
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
#include "src/ast/binding_decoration.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/block_statement.h"
#include "src/ast/bool_literal.h"
#include "src/ast/builtin_decoration.h"
@@ -456,12 +456,12 @@
if (expr->IsArrayAccessor()) {
return GenerateAccessorExpression(expr->AsArrayAccessor());
}
- if (expr->IsAs()) {
- return GenerateAsExpression(expr->AsAs());
- }
if (expr->IsBinary()) {
return GenerateBinaryExpression(expr->AsBinary());
}
+ if (expr->IsBitcast()) {
+ return GenerateBitcastExpression(expr->AsBitcast());
+ }
if (expr->IsCall()) {
return GenerateCallExpression(expr->AsCall());
}
@@ -1696,24 +1696,24 @@
return sampled_image.to_i();
}
-uint32_t Builder::GenerateAsExpression(ast::AsExpression* as) {
+uint32_t Builder::GenerateBitcastExpression(ast::BitcastExpression* expr) {
auto result = result_op();
auto result_id = result.to_i();
- auto result_type_id = GenerateTypeIfNeeded(as->result_type());
+ auto result_type_id = GenerateTypeIfNeeded(expr->result_type());
if (result_type_id == 0) {
return 0;
}
- auto val_id = GenerateExpression(as->expr());
+ auto val_id = GenerateExpression(expr->expr());
if (val_id == 0) {
return 0;
}
- val_id = GenerateLoadIfNeeded(as->expr()->result_type(), val_id);
+ val_id = GenerateLoadIfNeeded(expr->expr()->result_type(), val_id);
// Bitcast does not allow same types, just emit a CopyObject
- auto* to_type = as->result_type()->UnwrapPtrIfNeeded();
- auto* from_type = as->expr()->result_type()->UnwrapPtrIfNeeded();
+ auto* to_type = expr->result_type()->UnwrapPtrIfNeeded();
+ auto* from_type = expr->expr()->result_type()->UnwrapPtrIfNeeded();
if (to_type->type_name() == from_type->type_name()) {
push_function_inst(spv::Op::OpCopyObject, {Operand::Int(result_type_id),
result, Operand::Int(val_id)});
diff --git a/src/writer/spirv/builder.h b/src/writer/spirv/builder.h
index 7b809f3..a0c33d6 100644
--- a/src/writer/spirv/builder.h
+++ b/src/writer/spirv/builder.h
@@ -265,14 +265,14 @@
/// @param lit the literal to generate
/// @returns the ID on success or 0 on failure
uint32_t GenerateLiteralIfNeeded(ast::Literal* lit);
- /// Generates an as expression
- /// @param expr the expression to generate
- /// @returns the expression ID on success or 0 otherwise
- uint32_t GenerateAsExpression(ast::AsExpression* expr);
/// Generates a binary expression
/// @param expr the expression to generate
/// @returns the expression ID on success or 0 otherwise
uint32_t GenerateBinaryExpression(ast::BinaryExpression* expr);
+ /// Generates a bitcast expression
+ /// @param expr the expression to generate
+ /// @returns the expression ID on success or 0 otherwise
+ uint32_t GenerateBitcastExpression(ast::BitcastExpression* expr);
/// Generates a short circuting binary expression
/// @param expr the expression to generate
/// @returns teh expression ID on success or 0 otherwise
diff --git a/src/writer/spirv/builder_as_expression_test.cc b/src/writer/spirv/builder_bitcast_expression_test.cc
similarity index 73%
rename from src/writer/spirv/builder_as_expression_test.cc
rename to src/writer/spirv/builder_bitcast_expression_test.cc
index c650e53..04b6665 100644
--- a/src/writer/spirv/builder_as_expression_test.cc
+++ b/src/writer/spirv/builder_bitcast_expression_test.cc
@@ -13,7 +13,7 @@
// limitations under the License.
#include "gtest/gtest.h"
-#include "src/ast/as_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/float_literal.h"
#include "src/ast/module.h"
#include "src/ast/scalar_constructor_expression.h"
@@ -31,22 +31,22 @@
using BuilderTest = testing::Test;
-TEST_F(BuilderTest, As) {
+TEST_F(BuilderTest, Bitcast) {
ast::type::U32Type u32;
ast::type::F32Type f32;
- ast::AsExpression as(&u32,
- std::make_unique<ast::ScalarConstructorExpression>(
- std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
+ ast::BitcastExpression bitcast(
+ &u32, std::make_unique<ast::ScalarConstructorExpression>(
+ std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
Context ctx;
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
- ASSERT_TRUE(td.DetermineResultType(&as)) << td.error();
+ ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
Builder b(&mod);
b.push_function(Function{});
- EXPECT_EQ(b.GenerateAsExpression(&as), 1u);
+ EXPECT_EQ(b.GenerateBitcastExpression(&bitcast), 1u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
%3 = OpTypeFloat 32
@@ -57,21 +57,21 @@
)");
}
-TEST_F(BuilderTest, As_DuplicateType) {
+TEST_F(BuilderTest, Bitcast_DuplicateType) {
ast::type::F32Type f32;
- ast::AsExpression as(&f32,
- std::make_unique<ast::ScalarConstructorExpression>(
- std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
+ ast::BitcastExpression bitcast(
+ &f32, std::make_unique<ast::ScalarConstructorExpression>(
+ std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
Context ctx;
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
- ASSERT_TRUE(td.DetermineResultType(&as)) << td.error();
+ ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
Builder b(&mod);
b.push_function(Function{});
- EXPECT_EQ(b.GenerateAsExpression(&as), 1u);
+ EXPECT_EQ(b.GenerateBitcastExpression(&bitcast), 1u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%3 = OpConstant %2 2.4000001
diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc
index 6f0073c..4389ae1 100644
--- a/src/writer/wgsl/generator_impl.cc
+++ b/src/writer/wgsl/generator_impl.cc
@@ -18,10 +18,10 @@
#include <limits>
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
#include "src/ast/binding_decoration.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/block_statement.h"
#include "src/ast/bool_literal.h"
#include "src/ast/break_statement.h"
@@ -177,12 +177,12 @@
if (expr->IsArrayAccessor()) {
return EmitArrayAccessor(expr->AsArrayAccessor());
}
- if (expr->IsAs()) {
- return EmitAs(expr->AsAs());
- }
if (expr->IsBinary()) {
return EmitBinary(expr->AsBinary());
}
+ if (expr->IsBitcast()) {
+ return EmitBitcast(expr->AsBitcast());
+ }
if (expr->IsCall()) {
return EmitCall(expr->AsCall());
}
@@ -230,8 +230,8 @@
return EmitExpression(expr->member());
}
-bool GeneratorImpl::EmitAs(ast::AsExpression* expr) {
- out_ << "as<";
+bool GeneratorImpl::EmitBitcast(ast::BitcastExpression* expr) {
+ out_ << "bitcast<";
if (!EmitType(expr->type())) {
return false;
}
diff --git a/src/writer/wgsl/generator_impl.h b/src/writer/wgsl/generator_impl.h
index 43947a0..5805f09 100644
--- a/src/writer/wgsl/generator_impl.h
+++ b/src/writer/wgsl/generator_impl.h
@@ -62,10 +62,6 @@
/// @param expr the expression to emit
/// @returns true if the array accessor was emitted
bool EmitArrayAccessor(ast::ArrayAccessorExpression* expr);
- /// Handles generating an as expression
- /// @param expr the as expression
- /// @returns true if the as was emitted
- bool EmitAs(ast::AsExpression* expr);
/// Handles an assignment statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
@@ -74,6 +70,10 @@
/// @param expr the binary expression
/// @returns true if the expression was emitted, false otherwise
bool EmitBinary(ast::BinaryExpression* expr);
+ /// Handles generating a bitcast expression
+ /// @param expr the bitcast expression
+ /// @returns true if the bitcast was emitted
+ bool EmitBitcast(ast::BitcastExpression* expr);
/// Handles a block statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
diff --git a/src/writer/wgsl/generator_impl_as_test.cc b/src/writer/wgsl/generator_impl_bitcast_test.cc
similarity index 80%
rename from src/writer/wgsl/generator_impl_as_test.cc
rename to src/writer/wgsl/generator_impl_bitcast_test.cc
index 958bff2..ac2b940 100644
--- a/src/writer/wgsl/generator_impl_as_test.cc
+++ b/src/writer/wgsl/generator_impl_bitcast_test.cc
@@ -15,7 +15,7 @@
#include <memory>
#include "gtest/gtest.h"
-#include "src/ast/as_expression.h"
+#include "src/ast/bitcast_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/type/f32_type.h"
#include "src/writer/wgsl/generator_impl.h"
@@ -27,14 +27,14 @@
using WgslGeneratorImplTest = testing::Test;
-TEST_F(WgslGeneratorImplTest, EmitExpression_As) {
+TEST_F(WgslGeneratorImplTest, EmitExpression_Bitcast) {
ast::type::F32Type f32;
auto id = std::make_unique<ast::IdentifierExpression>("id");
- ast::AsExpression as(&f32, std::move(id));
+ ast::BitcastExpression bitcast(&f32, std::move(id));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitExpression(&as)) << g.error();
- EXPECT_EQ(g.result(), "as<f32>(id)");
+ ASSERT_TRUE(g.EmitExpression(&bitcast)) << g.error();
+ EXPECT_EQ(g.result(), "bitcast<f32>(id)");
}
} // namespace