diff --git a/BUILD.gn b/BUILD.gn index e522f1211e..1110d6ce8c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -219,14 +219,14 @@ source_set("libtint_core_src") { 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 @@ config("tint_unittests_config") { 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 @@ source_set("tint_unittests_spv_writer_src") { 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 @@ source_set("tint_unittests_wgsl_writer_src") { 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 @@ source_set("tint_unittests_msl_writer_src") { 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 @@ source_set("tint_unittests_hlsl_writer_src") { 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 58129fb2de..16409aabc1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,14 +40,14 @@ set(TINT_LIB_SRCS ../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 @@ endif() 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 @@ if(${TINT_BUILD_SPV_WRITER}) 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 @@ if(${TINT_BUILD_WGSL_WRITER}) 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 @@ if(${TINT_BUILD_MSL_WRITER}) 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 @@ if (${TINT_BUILD_HLSL_WRITER}) 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/bitcast_expression.cc similarity index 57% rename from src/ast/as_expression.cc rename to src/ast/bitcast_expression.cc index 65705cc99f..8f834772b9 100644 --- a/src/ast/as_expression.cc +++ b/src/ast/bitcast_expression.cc @@ -12,37 +12,38 @@ // 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" namespace tint { namespace ast { -AsExpression::AsExpression() : Expression() {} +BitcastExpression::BitcastExpression() : Expression() {} -AsExpression::AsExpression(type::Type* type, std::unique_ptr expr) +BitcastExpression::BitcastExpression(type::Type* type, + std::unique_ptr expr) : Expression(), type_(type), expr_(std::move(expr)) {} -AsExpression::AsExpression(const Source& source, - type::Type* type, - std::unique_ptr expr) +BitcastExpression::BitcastExpression(const Source& source, + type::Type* type, + std::unique_ptr expr) : Expression(source), type_(type), expr_(std::move(expr)) {} -AsExpression::AsExpression(AsExpression&&) = default; -AsExpression::~AsExpression() = default; +BitcastExpression::BitcastExpression(BitcastExpression&&) = default; +BitcastExpression::~BitcastExpression() = default; -bool AsExpression::IsAs() const { +bool BitcastExpression::IsBitcast() const { return true; } -bool AsExpression::IsValid() const { +bool BitcastExpression::IsValid() const { if (expr_ == nullptr || !expr_->IsValid()) return false; return type_ != nullptr; } -void AsExpression::to_str(std::ostream& out, size_t indent) const { +void BitcastExpression::to_str(std::ostream& out, size_t indent) const { make_indent(out, indent); - out << "As<" << type_->type_name() << ">{" << std::endl; + out << "Bitcast<" << type_->type_name() << ">{" << std::endl; expr_->to_str(out, indent + 2); make_indent(out, indent); out << "}" << std::endl; 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 e8feeb6995..c74fc7b092 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 #include @@ -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 expr); + BitcastExpression(type::Type* type, std::unique_ptr 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 expr); + BitcastExpression(const Source& source, + type::Type* type, + std::unique_ptr expr); /// Move constructor - AsExpression(AsExpression&&); - ~AsExpression() override; + BitcastExpression(BitcastExpression&&); + ~BitcastExpression() override; /// Sets the type /// @param type the type @@ -57,8 +57,8 @@ class AsExpression : public Expression { /// @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 @@ class AsExpression : public Expression { 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 expr_; @@ -78,4 +78,4 @@ class AsExpression : public Expression { } // 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 e29a89d662..accd1ff0bd 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 tint { 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("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("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("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("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(""); - 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("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 c1c97656c9..2e1ad978a2 100644 --- a/src/ast/expression.cc +++ b/src/ast/expression.cc @@ -17,8 +17,8 @@ #include #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 @@ bool Expression::IsArrayAccessor() const { return false; } -bool Expression::IsAs() const { +bool Expression::IsBitcast() const { return false; } @@ -81,9 +81,9 @@ const ArrayAccessorExpression* Expression::AsArrayAccessor() const { return static_cast(this); } -const AsExpression* Expression::AsAs() const { - assert(IsAs()); - return static_cast(this); +const BitcastExpression* Expression::AsBitcast() const { + assert(IsBitcast()); + return static_cast(this); } const BinaryExpression* Expression::AsBinary() const { @@ -126,9 +126,9 @@ ArrayAccessorExpression* Expression::AsArrayAccessor() { return static_cast(this); } -AsExpression* Expression::AsAs() { - assert(IsAs()); - return static_cast(this); +BitcastExpression* Expression::AsBitcast() { + assert(IsBitcast()); + return static_cast(this); } BinaryExpression* Expression::AsBinary() { diff --git a/src/ast/expression.h b/src/ast/expression.h index 43c4c40884..b69e9da767 100644 --- a/src/ast/expression.h +++ b/src/ast/expression.h @@ -25,8 +25,8 @@ namespace tint { namespace ast { class ArrayAccessorExpression; -class AsExpression; class BinaryExpression; +class BitcastExpression; class CallExpression; class CastExpression; class IdentifierExpression; @@ -47,8 +47,8 @@ class Expression : public Node { /// @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 @@ class Expression : public Node { /// @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 @@ class Expression : public Node { /// @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 69b9f43745..23fd90b614 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 @@ std::unique_ptr VertexPullingTransform::AccessI32( uint32_t buffer, std::unique_ptr pos) { // as reinterprets bits - return std::make_unique(GetI32Type(), - AccessU32(buffer, std::move(pos))); + return std::make_unique(GetI32Type(), + AccessU32(buffer, std::move(pos))); } std::unique_ptr VertexPullingTransform::AccessF32( uint32_t buffer, std::unique_ptr pos) { // as reinterprets bits - return std::make_unique(GetF32Type(), - AccessU32(buffer, std::move(pos))); + return std::make_unique(GetF32Type(), + AccessU32(buffer, std::move(pos))); } std::unique_ptr VertexPullingTransform::AccessPrimitive( diff --git a/src/ast/transform/vertex_pulling_transform_test.cc b/src/ast/transform/vertex_pulling_transform_test.cc index caf4e4a734..e2569b22f5 100644 --- a/src/ast/transform/vertex_pulling_transform_test.cc +++ b/src/ast/transform/vertex_pulling_transform_test.cc @@ -185,7 +185,7 @@ TEST_F(VertexPullingTransformTest, OneAttribute) { } Assignment{ Identifier{var_a} - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_0} @@ -266,7 +266,7 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) { } Assignment{ Identifier{var_a} - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_0} @@ -347,7 +347,7 @@ TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) { } Assignment{ Identifier{var_a} - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_0} @@ -480,7 +480,7 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { } Assignment{ Identifier{var_a} - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_0} @@ -508,7 +508,7 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { } Assignment{ Identifier{var_b} - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_1} @@ -599,7 +599,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) { } Assignment{ Identifier{var_a} - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_0} @@ -629,7 +629,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) { Identifier{var_b} TypeConstructor{ __vec_4__f32 - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_0} @@ -646,7 +646,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) { } } } - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_0} @@ -663,7 +663,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) { } } } - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_0} @@ -680,7 +680,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) { } } } - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_0} @@ -805,7 +805,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { Identifier{var_a} TypeConstructor{ __vec_2__f32 - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_0} @@ -822,7 +822,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { } } } - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_0} @@ -857,7 +857,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { Identifier{var_b} TypeConstructor{ __vec_3__f32 - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_1} @@ -874,7 +874,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { } } } - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_1} @@ -891,7 +891,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { } } } - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_1} @@ -926,7 +926,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { Identifier{var_c} TypeConstructor{ __vec_4__f32 - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_2} @@ -943,7 +943,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { } } } - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_2} @@ -960,7 +960,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { } } } - As<__f32>{ + Bitcast<__f32>{ ArrayAccessor{ MemberAccessor{ Identifier{tint_pulling_vertex_buffer_2} @@ -977,7 +977,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { } } } - 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 320dd084c6..bc59df1aa9 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 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue( } if (opcode == SpvOpBitcast) { - return {ast_type, std::make_unique( + return {ast_type, std::make_unique( ast_type, MakeOperand(inst, 0).expr)}; } @@ -3469,7 +3469,7 @@ TypedExpression FunctionEmitter::MakeNumericConversion( if (requested_type == expr_type) { return result; } - return {requested_type, std::make_unique( + return {requested_type, std::make_unique( 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 ba9656d2de..94632c2d4a 100644 --- a/src/reader/spirv/function_arithmetic_test.cc +++ b/src/reader/spirv/function_arithmetic_test.cc @@ -96,7 +96,7 @@ std::string AstFor(std::string assembly) { })"; } 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 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) { { UnaryOp{ negation - As<__i32>{ + Bitcast<__i32>{ ScalarConstructor{10} } } @@ -197,7 +197,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) { none __u32 { - As<__u32>{ + Bitcast<__u32>{ UnaryOp{ negation ScalarConstructor{30} @@ -226,10 +226,10 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) { none __u32 { - As<__u32>{ + Bitcast<__u32>{ UnaryOp{ negation - As<__i32>{ + Bitcast<__i32>{ ScalarConstructor{10} } } @@ -290,7 +290,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) { { UnaryOp{ negation - As<__vec_2__i32>{ + Bitcast<__vec_2__i32>{ TypeConstructor{ __vec_2__u32 ScalarConstructor{10} @@ -321,7 +321,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) { none __vec_2__u32 { - As<__vec_2__u32>{ + Bitcast<__vec_2__u32>{ UnaryOp{ negation TypeConstructor{ @@ -354,10 +354,10 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) { 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 @@ INSTANTIATE_TEST_SUITE_P( // 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 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Scalar_UnsignedResult) { none __u32 { - As<__u32>{ + Bitcast<__u32>{ Binary{ ScalarConstructor{30} divide @@ -731,7 +731,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Vector_UnsignedResult) { none __vec_2__u32 { - As<__vec_2__u32>{ + Bitcast<__vec_2__u32>{ Binary{ TypeConstructor{ __vec_2__i32 @@ -798,12 +798,12 @@ INSTANTIATE_TEST_SUITE_P( // 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 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Scalar_UnsignedResult) { none __u32 { - As<__u32>{ + Bitcast<__u32>{ Binary{ ScalarConstructor{30} modulo @@ -875,7 +875,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Vector_UnsignedResult) { 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 01a7b987e1..a68362b553 100644 --- a/src/reader/spirv/function_bit_test.cc +++ b/src/reader/spirv/function_bit_test.cc @@ -91,7 +91,7 @@ std::string AstFor(std::string assembly) { })"; } 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 @@ TEST_F(SpvUnaryBitTest, Not_Int_Uint) { none __i32 { - As<__i32>{ + Bitcast<__i32>{ UnaryOp{ not ScalarConstructor{10} @@ -450,7 +450,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Int) { none __u32 { - As<__u32>{ + Bitcast<__u32>{ UnaryOp{ not ScalarConstructor{30} @@ -537,7 +537,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) { none __vec_2__i32 { - As<__vec_2__i32>{ + Bitcast<__vec_2__i32>{ UnaryOp{ not TypeConstructor{ @@ -570,7 +570,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) { 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 1500eb4183..37525b9a36 100644 --- a/src/reader/spirv/function_conversion_test.cc +++ b/src/reader/spirv/function_conversion_test.cc @@ -88,7 +88,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Scalar) { none __u32 { - As<__u32>{ + Bitcast<__u32>{ ScalarConstructor{50.000000} } } @@ -114,7 +114,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Vector) { none __vec_2__f32 { - As<__vec_2__f32>{ + Bitcast<__vec_2__f32>{ TypeConstructor{ __vec_2__u32 ScalarConstructor{10} @@ -270,7 +270,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) { __f32 { Cast<__f32>( - As<__i32>{ + Bitcast<__i32>{ Identifier{x_30} } ) @@ -324,7 +324,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) { __vec_2__f32 { Cast<__vec_2__f32>( - As<__vec_2__i32>{ + Bitcast<__vec_2__i32>{ Identifier{x_30} } ) @@ -385,7 +385,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromSigned) { __f32 { Cast<__f32>( - As<__u32>{ + Bitcast<__u32>{ Identifier{x_30} } ) @@ -439,7 +439,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) { __vec_2__f32 { Cast<__vec_2__f32>( - As<__vec_2__u32>{ + Bitcast<__vec_2__u32>{ Identifier{x_30} } ) @@ -552,7 +552,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) { none __u32 { - As<__u32>{ + Bitcast<__u32>{ Cast<__i32>( Identifier{x_30} ) @@ -606,7 +606,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) { none __vec_2__u32 { - As<__vec_2__u32>{ + Bitcast<__vec_2__u32>{ Cast<__vec_2__i32>( Identifier{x_30} ) @@ -668,7 +668,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToSigned) { none __i32 { - As<__i32>{ + Bitcast<__i32>{ Cast<__u32>( Identifier{x_30} ) @@ -722,7 +722,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) { 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 24793d1270..6e1c336d01 100644 --- a/src/reader/spirv/function_logical_test.cc +++ b/src/reader/spirv/function_logical_test.cc @@ -92,17 +92,17 @@ std::string AstFor(std::string assembly) { })"; } 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 @@ std::string AstFor(std::string assembly) { })"; } 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 @@ std::string AstFor(std::string assembly) { })"; } 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 @@ std::string AstFor(std::string assembly) { })"; } 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 @@ std::string AstFor(std::string assembly) { })"; } 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 9c6c87df01..a21bf6dab2 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 @@ TypedExpression ParserImpl::RectifyOperandSignedness(SpvOp op, auto* unsigned_ty = unsigned_type_for_[type]; if (unsigned_ty != nullptr) { // Conversion is required. - return {unsigned_ty, std::make_unique( + return {unsigned_ty, std::make_unique( 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( + return {signed_ty, std::make_unique( signed_ty, std::move(expr.expr))}; } } @@ -1373,8 +1373,8 @@ TypedExpression ParserImpl::RectifyForcedResultType( if ((forced_result_ty == nullptr) || (forced_result_ty == expr.type)) { return expr; } - return {expr.type, - std::make_unique(expr.type, std::move(expr.expr))}; + return {expr.type, std::make_unique( + expr.type, std::move(expr.expr))}; } bool ParserImpl::EmitFunctions() { diff --git a/src/reader/wgsl/lexer.cc b/src/reader/wgsl/lexer.cc index 76d71e5097..87b678f9a5 100644 --- a/src/reader/wgsl/lexer.cc +++ b/src/reader/wgsl/lexer.cc @@ -471,10 +471,10 @@ Token Lexer::try_punctuation() { 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 1e90cdbf79..c3b456ef51 100644 --- a/src/reader/wgsl/lexer_test.cc +++ b/src/reader/wgsl/lexer_test.cc @@ -413,8 +413,8 @@ INSTANTIATE_TEST_SUITE_P( 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 64a0649a8c..1616ea8344 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -18,9 +18,9 @@ #include #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 @@ std::unique_ptr ParserImpl::primary_expression() { return paren; } - if (t.IsCast() || t.IsAs()) { + if (t.IsCast() || t.IsBitcast()) { auto src = t; next(); // Consume the peek @@ -2827,8 +2827,8 @@ std::unique_ptr ParserImpl::primary_expression() { return std::make_unique(source, type, std::move(params)); } else { - return std::make_unique(source, type, - std::move(params)); + return std::make_unique(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 e6a42656e6..bd459e130e 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 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast_InvalidExpression) { 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()); - auto* p = parser("as(1)"); + auto* p = parser("bitcast(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("asprimary_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(1)"); +TEST_F(ParserImplTest, PrimaryExpression_Bitcast_InvalidType) { + 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: unknown type alias 'invalid'"); + EXPECT_EQ(p->error(), "1:9: unknown type alias 'invalid'"); } -TEST_F(ParserImplTest, PrimaryExpression_As_MissingLeftParen) { - auto* p = parser("as1)"); +TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingLeftParen) { + auto* p = parser("bitcast1)"); 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(1"); +TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingRightParen) { + auto* p = parser("bitcast(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()"); +TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingExpression) { + auto* p = parser("bitcast()"); 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(if (a) {})"); +TEST_F(ParserImplTest, PrimaryExpression_bitcast_InvalidExpression) { + auto* p = parser("bitcast(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 7afd80c490..f836c0cae0 100644 --- a/src/reader/wgsl/token.cc +++ b/src/reader/wgsl/token.cc @@ -107,10 +107,10 @@ std::string Token::TypeToName(Type type) { 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 c67ef3484d..ebd39e6929 100644 --- a/src/reader/wgsl/token.h +++ b/src/reader/wgsl/token.h @@ -118,10 +118,10 @@ class Token { /// A 'array' kArray, - /// A 'as' - kAs, /// A 'binding' kBinding, + /// A 'bitcast' + kBitcast, /// A 'bool' kBool, /// A 'block' @@ -495,10 +495,10 @@ class Token { /// @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 0c31e5a3d2..dedf1f04cb 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -18,9 +18,9 @@ #include #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 @@ bool TypeDeterminer::DetermineResultType(ast::Expression* expr) { 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 @@ bool TypeDeterminer::DetermineArrayAccessor( 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 a7b689d654..6ba38339cb 100644 --- a/src/type_determiner.h +++ b/src/type_determiner.h @@ -27,8 +27,8 @@ namespace tint { namespace ast { class ArrayAccessorExpression; -class AsExpression; class BinaryExpression; +class BitcastExpression; class CallExpression; class CastExpression; class ConstructorExpression; @@ -117,8 +117,8 @@ class TypeDeterminer { 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 21c29d4396..9a6bd20d9f 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 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Vector) { 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("name")); + ast::BitcastExpression bitcast( + &f32, std::make_unique("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 8381e5cca9..b97b58ade4 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 bd20995acb..68a33cac19 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -17,9 +17,9 @@ #include #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 @@ bool GeneratorImpl::EmitArrayAccessor(std::ostream& pre, 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::EmitDiscard(std::ostream& out, ast::DiscardStatement*) { 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 031cf7e18e..e30c363256 100644 --- a/src/writer/hlsl/generator_impl.h +++ b/src/writer/hlsl/generator_impl.h @@ -73,12 +73,6 @@ class GeneratorImpl { 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 @@ class GeneratorImpl { 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 e6c515f1a6..bec7a6d08f 100644 --- a/src/writer/hlsl/generator_impl_binary_test.cc +++ b/src/writer/hlsl/generator_impl_binary_test.cc @@ -14,9 +14,9 @@ #include -#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 @@ bool a = (_tint_tmp_0); )"); } -TEST_F(HlslGeneratorImplTest_Binary, As_WithLogical) { +TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) { // as(a && (b || c)) ast::type::I32Type i32; @@ -303,7 +303,7 @@ TEST_F(HlslGeneratorImplTest_Binary, As_WithLogical) { auto b = std::make_unique("b"); auto c = std::make_unique("c"); - ast::AsExpression expr( + ast::BitcastExpression expr( &i32, std::make_unique( ast::BinaryOp::kLogicalAnd, std::move(a), std::make_unique( 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 663b1db432..ffe34d7bf1 100644 --- a/src/writer/hlsl/generator_impl_as_test.cc +++ b/src/writer/hlsl/generator_impl_bitcast_test.cc @@ -14,7 +14,7 @@ #include -#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 writer { 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("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("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("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 c4f23291ba..b3efd7329e 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 @@ bool GeneratorImpl::EmitArrayAccessor(ast::ArrayAccessorExpression* expr) { 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 @@ bool GeneratorImpl::EmitExpression(ast::Expression* expr) { 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 68f5574566..cc458d2625 100644 --- a/src/writer/msl/generator_impl.h +++ b/src/writer/msl/generator_impl.h @@ -62,10 +62,6 @@ class GeneratorImpl : public TextGenerator { /// @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 @@ class GeneratorImpl : public TextGenerator { /// @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 debc9f823e..94474d7972 100644 --- a/src/writer/msl/generator_impl_as_test.cc +++ b/src/writer/msl/generator_impl_bitcast_test.cc @@ -15,7 +15,7 @@ #include #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 @@ namespace { using MslGeneratorImplTest = testing::Test; -TEST_F(MslGeneratorImplTest, EmitExpression_As) { +TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) { ast::type::F32Type f32; auto id = std::make_unique("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(id)"); } diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 529286fa7c..a1a004ed1f 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 @@ uint32_t Builder::GenerateExpression(ast::Expression* expr) { 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 @@ uint32_t Builder::GenerateSampledImage(ast::type::Type* texture_type, 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 7b809f3840..a0c33d64ab 100644 --- a/src/writer/spirv/builder.h +++ b/src/writer/spirv/builder.h @@ -265,14 +265,14 @@ class Builder { /// @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 c650e537e7..04b6665c97 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 @@ namespace { 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( - std::make_unique(&f32, 2.4))); + ast::BitcastExpression bitcast( + &u32, std::make_unique( + std::make_unique(&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) { )"); } -TEST_F(BuilderTest, As_DuplicateType) { +TEST_F(BuilderTest, Bitcast_DuplicateType) { ast::type::F32Type f32; - ast::AsExpression as(&f32, - std::make_unique( - std::make_unique(&f32, 2.4))); + ast::BitcastExpression bitcast( + &f32, std::make_unique( + std::make_unique(&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 6f0073cd31..4389ae1c93 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -18,10 +18,10 @@ #include #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 @@ bool GeneratorImpl::EmitExpression(ast::Expression* expr) { 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 @@ bool GeneratorImpl::EmitMemberAccessor(ast::MemberAccessorExpression* expr) { 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 43947a0edf..5805f09260 100644 --- a/src/writer/wgsl/generator_impl.h +++ b/src/writer/wgsl/generator_impl.h @@ -62,10 +62,6 @@ class GeneratorImpl : public TextGenerator { /// @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 @@ class GeneratorImpl : public TextGenerator { /// @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 958bff2a34..ac2b9409c8 100644 --- a/src/writer/wgsl/generator_impl_as_test.cc +++ b/src/writer/wgsl/generator_impl_bitcast_test.cc @@ -15,7 +15,7 @@ #include #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 @@ namespace { using WgslGeneratorImplTest = testing::Test; -TEST_F(WgslGeneratorImplTest, EmitExpression_As) { +TEST_F(WgslGeneratorImplTest, EmitExpression_Bitcast) { ast::type::F32Type f32; auto id = std::make_unique("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(id)"); + ASSERT_TRUE(g.EmitExpression(&bitcast)) << g.error(); + EXPECT_EQ(g.result(), "bitcast(id)"); } } // namespace