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>
This commit is contained in:
dan sinclair 2020-09-22 22:07:13 +00:00 committed by Commit Bot service account
parent b4fee2f824
commit a7d498e060
38 changed files with 288 additions and 286 deletions

View File

@ -219,14 +219,14 @@ source_set("libtint_core_src") {
sources = [ sources = [
"src/ast/array_accessor_expression.cc", "src/ast/array_accessor_expression.cc",
"src/ast/array_accessor_expression.h", "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.cc",
"src/ast/assignment_statement.h", "src/ast/assignment_statement.h",
"src/ast/binary_expression.cc", "src/ast/binary_expression.cc",
"src/ast/binary_expression.h", "src/ast/binary_expression.h",
"src/ast/binding_decoration.cc", "src/ast/binding_decoration.cc",
"src/ast/binding_decoration.h", "src/ast/binding_decoration.h",
"src/ast/bitcast_expression.cc",
"src/ast/bitcast_expression.h",
"src/ast/block_statement.cc", "src/ast/block_statement.cc",
"src/ast/block_statement.h", "src/ast/block_statement.h",
"src/ast/bool_literal.cc", "src/ast/bool_literal.cc",
@ -686,10 +686,10 @@ config("tint_unittests_config") {
source_set("tint_unittests_core_src") { source_set("tint_unittests_core_src") {
sources = [ sources = [
"src/ast/array_accessor_expression_test.cc", "src/ast/array_accessor_expression_test.cc",
"src/ast/as_expression_test.cc",
"src/ast/assignment_statement_test.cc", "src/ast/assignment_statement_test.cc",
"src/ast/binary_expression_test.cc", "src/ast/binary_expression_test.cc",
"src/ast/binding_decoration_test.cc", "src/ast/binding_decoration_test.cc",
"src/ast/bitcast_expression_test.cc",
"src/ast/block_statement_test.cc", "src/ast/block_statement_test.cc",
"src/ast/bool_literal_test.cc", "src/ast/bool_literal_test.cc",
"src/ast/break_statement_test.cc", "src/ast/break_statement_test.cc",
@ -826,9 +826,9 @@ source_set("tint_unittests_spv_writer_src") {
sources = [ sources = [
"src/writer/spirv/binary_writer_test.cc", "src/writer/spirv/binary_writer_test.cc",
"src/writer/spirv/builder_accessor_expression_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_assign_test.cc",
"src/writer/spirv/builder_binary_expression_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_block_test.cc",
"src/writer/spirv/builder_call_test.cc", "src/writer/spirv/builder_call_test.cc",
"src/writer/spirv/builder_cast_expression_test.cc", "src/writer/spirv/builder_cast_expression_test.cc",
@ -972,9 +972,9 @@ source_set("tint_unittests_wgsl_writer_src") {
sources = [ sources = [
"src/writer/wgsl/generator_impl_alias_type_test.cc", "src/writer/wgsl/generator_impl_alias_type_test.cc",
"src/writer/wgsl/generator_impl_array_accessor_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_assign_test.cc",
"src/writer/wgsl/generator_impl_binary_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_block_test.cc",
"src/writer/wgsl/generator_impl_break_test.cc", "src/writer/wgsl/generator_impl_break_test.cc",
"src/writer/wgsl/generator_impl_call_test.cc", "src/writer/wgsl/generator_impl_call_test.cc",
@ -1021,9 +1021,9 @@ source_set("tint_unittests_msl_writer_src") {
sources = [ sources = [
"src/writer/msl/generator_impl_alias_type_test.cc", "src/writer/msl/generator_impl_alias_type_test.cc",
"src/writer/msl/generator_impl_array_accessor_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_assign_test.cc",
"src/writer/msl/generator_impl_binary_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_block_test.cc",
"src/writer/msl/generator_impl_break_test.cc", "src/writer/msl/generator_impl_break_test.cc",
"src/writer/msl/generator_impl_call_test.cc", "src/writer/msl/generator_impl_call_test.cc",
@ -1073,9 +1073,9 @@ source_set("tint_unittests_hlsl_writer_src") {
sources = [ sources = [
"src/writer/hlsl/generator_impl_alias_type_test.cc", "src/writer/hlsl/generator_impl_alias_type_test.cc",
"src/writer/hlsl/generator_impl_array_accessor_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_assign_test.cc",
"src/writer/hlsl/generator_impl_binary_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_block_test.cc",
"src/writer/hlsl/generator_impl_break_test.cc", "src/writer/hlsl/generator_impl_break_test.cc",
"src/writer/hlsl/generator_impl_call_test.cc", "src/writer/hlsl/generator_impl_call_test.cc",

View File

@ -40,14 +40,14 @@ set(TINT_LIB_SRCS
../include/tint/tint.h ../include/tint/tint.h
ast/array_accessor_expression.cc ast/array_accessor_expression.cc
ast/array_accessor_expression.h ast/array_accessor_expression.h
ast/as_expression.cc
ast/as_expression.h
ast/assignment_statement.cc ast/assignment_statement.cc
ast/assignment_statement.h ast/assignment_statement.h
ast/binary_expression.cc ast/binary_expression.cc
ast/binary_expression.h ast/binary_expression.h
ast/binding_decoration.cc ast/binding_decoration.cc
ast/binding_decoration.h ast/binding_decoration.h
ast/bitcast_expression.cc
ast/bitcast_expression.h
ast/block_statement.cc ast/block_statement.cc
ast/block_statement.h ast/block_statement.h
ast/bool_literal.h ast/bool_literal.h
@ -296,9 +296,9 @@ endif()
set(TINT_TEST_SRCS set(TINT_TEST_SRCS
ast/array_accessor_expression_test.cc ast/array_accessor_expression_test.cc
ast/as_expression_test.cc
ast/assignment_statement_test.cc ast/assignment_statement_test.cc
ast/binding_decoration_test.cc ast/binding_decoration_test.cc
ast/bitcast_expression_test.cc
ast/block_statement_test.cc ast/block_statement_test.cc
ast/bool_literal_test.cc ast/bool_literal_test.cc
ast/break_statement_test.cc ast/break_statement_test.cc
@ -484,9 +484,9 @@ if(${TINT_BUILD_SPV_WRITER})
list(APPEND TINT_TEST_SRCS list(APPEND TINT_TEST_SRCS
writer/spirv/binary_writer_test.cc writer/spirv/binary_writer_test.cc
writer/spirv/builder_accessor_expression_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_assign_test.cc
writer/spirv/builder_binary_expression_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_block_test.cc
writer/spirv/builder_call_test.cc writer/spirv/builder_call_test.cc
writer/spirv/builder_cast_expression_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_test.cc
writer/wgsl/generator_impl_alias_type_test.cc writer/wgsl/generator_impl_alias_type_test.cc
writer/wgsl/generator_impl_array_accessor_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_assign_test.cc
writer/wgsl/generator_impl_binary_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_block_test.cc
writer/wgsl/generator_impl_break_test.cc writer/wgsl/generator_impl_break_test.cc
writer/wgsl/generator_impl_call_test.cc writer/wgsl/generator_impl_call_test.cc
@ -549,9 +549,9 @@ if(${TINT_BUILD_MSL_WRITER})
list(APPEND TINT_TEST_SRCS list(APPEND TINT_TEST_SRCS
writer/msl/generator_impl_alias_type_test.cc writer/msl/generator_impl_alias_type_test.cc
writer/msl/generator_impl_array_accessor_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_assign_test.cc
writer/msl/generator_impl_binary_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_block_test.cc
writer/msl/generator_impl_break_test.cc writer/msl/generator_impl_break_test.cc
writer/msl/generator_impl_call_test.cc writer/msl/generator_impl_call_test.cc
@ -583,9 +583,9 @@ if (${TINT_BUILD_HLSL_WRITER})
list(APPEND TINT_TEST_SRCS list(APPEND TINT_TEST_SRCS
writer/hlsl/generator_impl_alias_type_test.cc writer/hlsl/generator_impl_alias_type_test.cc
writer/hlsl/generator_impl_array_accessor_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_assign_test.cc
writer/hlsl/generator_impl_binary_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_block_test.cc
writer/hlsl/generator_impl_break_test.cc writer/hlsl/generator_impl_break_test.cc
writer/hlsl/generator_impl_call_test.cc writer/hlsl/generator_impl_call_test.cc

View File

@ -12,37 +12,38 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "src/ast/as_expression.h" #include "src/ast/bitcast_expression.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
AsExpression::AsExpression() : Expression() {} BitcastExpression::BitcastExpression() : Expression() {}
AsExpression::AsExpression(type::Type* type, std::unique_ptr<Expression> expr) BitcastExpression::BitcastExpression(type::Type* type,
std::unique_ptr<Expression> expr)
: Expression(), type_(type), expr_(std::move(expr)) {} : Expression(), type_(type), expr_(std::move(expr)) {}
AsExpression::AsExpression(const Source& source, BitcastExpression::BitcastExpression(const Source& source,
type::Type* type, type::Type* type,
std::unique_ptr<Expression> expr) std::unique_ptr<Expression> expr)
: Expression(source), type_(type), expr_(std::move(expr)) {} : Expression(source), type_(type), expr_(std::move(expr)) {}
AsExpression::AsExpression(AsExpression&&) = default; BitcastExpression::BitcastExpression(BitcastExpression&&) = default;
AsExpression::~AsExpression() = default; BitcastExpression::~BitcastExpression() = default;
bool AsExpression::IsAs() const { bool BitcastExpression::IsBitcast() const {
return true; return true;
} }
bool AsExpression::IsValid() const { bool BitcastExpression::IsValid() const {
if (expr_ == nullptr || !expr_->IsValid()) if (expr_ == nullptr || !expr_->IsValid())
return false; return false;
return type_ != nullptr; 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); make_indent(out, indent);
out << "As<" << type_->type_name() << ">{" << std::endl; out << "Bitcast<" << type_->type_name() << ">{" << std::endl;
expr_->to_str(out, indent + 2); expr_->to_str(out, indent + 2);
make_indent(out, indent); make_indent(out, indent);
out << "}" << std::endl; out << "}" << std::endl;

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef SRC_AST_AS_EXPRESSION_H_ #ifndef SRC_AST_BITCAST_EXPRESSION_H_
#define SRC_AST_AS_EXPRESSION_H_ #define SRC_AST_BITCAST_EXPRESSION_H_
#include <memory> #include <memory>
#include <utility> #include <utility>
@ -25,25 +25,25 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
/// An as expression /// A bitcast expression
class AsExpression : public Expression { class BitcastExpression : public Expression {
public: public:
/// Constructor /// Constructor
AsExpression(); BitcastExpression();
/// Constructor /// Constructor
/// @param type the type /// @param type the type
/// @param expr the expr /// @param expr the expr
AsExpression(type::Type* type, std::unique_ptr<Expression> expr); BitcastExpression(type::Type* type, std::unique_ptr<Expression> expr);
/// Constructor /// Constructor
/// @param source the as expression source /// @param source the bitcast expression source
/// @param type the type /// @param type the type
/// @param expr the expr /// @param expr the expr
AsExpression(const Source& source, BitcastExpression(const Source& source,
type::Type* type, type::Type* type,
std::unique_ptr<Expression> expr); std::unique_ptr<Expression> expr);
/// Move constructor /// Move constructor
AsExpression(AsExpression&&); BitcastExpression(BitcastExpression&&);
~AsExpression() override; ~BitcastExpression() override;
/// Sets the type /// Sets the type
/// @param type the type /// @param type the type
@ -57,8 +57,8 @@ class AsExpression : public Expression {
/// @returns the expression /// @returns the expression
Expression* expr() const { return expr_.get(); } Expression* expr() const { return expr_.get(); }
/// @returns true if this is an as expression /// @returns true if this is a bitcast expression
bool IsAs() const override; bool IsBitcast() const override;
/// @returns true if the node is valid /// @returns true if the node is valid
bool IsValid() const override; bool IsValid() const override;
@ -69,7 +69,7 @@ class AsExpression : public Expression {
void to_str(std::ostream& out, size_t indent) const override; void to_str(std::ostream& out, size_t indent) const override;
private: private:
AsExpression(const AsExpression&) = delete; BitcastExpression(const BitcastExpression&) = delete;
type::Type* type_ = nullptr; type::Type* type_ = nullptr;
std::unique_ptr<Expression> expr_; std::unique_ptr<Expression> expr_;
@ -78,4 +78,4 @@ class AsExpression : public Expression {
} // namespace ast } // namespace ast
} // namespace tint } // namespace tint
#endif // SRC_AST_AS_EXPRESSION_H_ #endif // SRC_AST_BITCAST_EXPRESSION_H_

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "src/ast/as_expression.h" #include "src/ast/bitcast_expression.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/identifier_expression.h" #include "src/ast/identifier_expression.h"
@ -22,74 +22,74 @@ namespace tint {
namespace ast { namespace ast {
namespace { namespace {
using AsExpressionTest = testing::Test; using BitcastExpressionTest = testing::Test;
TEST_F(AsExpressionTest, Create) { TEST_F(BitcastExpressionTest, Create) {
type::F32Type f32; type::F32Type f32;
auto expr = std::make_unique<IdentifierExpression>("expr"); auto expr = std::make_unique<IdentifierExpression>("expr");
auto* expr_ptr = expr.get(); 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.type(), &f32);
ASSERT_EQ(exp.expr(), expr_ptr); ASSERT_EQ(exp.expr(), expr_ptr);
} }
TEST_F(AsExpressionTest, CreateWithSource) { TEST_F(BitcastExpressionTest, CreateWithSource) {
type::F32Type f32; type::F32Type f32;
auto expr = std::make_unique<IdentifierExpression>("expr"); 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(); auto src = exp.source();
EXPECT_EQ(src.line, 20u); EXPECT_EQ(src.line, 20u);
EXPECT_EQ(src.column, 2u); EXPECT_EQ(src.column, 2u);
} }
TEST_F(AsExpressionTest, IsAs) { TEST_F(BitcastExpressionTest, IsBitcast) {
AsExpression exp; BitcastExpression exp;
EXPECT_TRUE(exp.IsAs()); EXPECT_TRUE(exp.IsBitcast());
} }
TEST_F(AsExpressionTest, IsValid) { TEST_F(BitcastExpressionTest, IsValid) {
type::F32Type f32; type::F32Type f32;
auto expr = std::make_unique<IdentifierExpression>("expr"); auto expr = std::make_unique<IdentifierExpression>("expr");
AsExpression exp(&f32, std::move(expr)); BitcastExpression exp(&f32, std::move(expr));
EXPECT_TRUE(exp.IsValid()); EXPECT_TRUE(exp.IsValid());
} }
TEST_F(AsExpressionTest, IsValid_MissingType) { TEST_F(BitcastExpressionTest, IsValid_MissingType) {
auto expr = std::make_unique<IdentifierExpression>("expr"); auto expr = std::make_unique<IdentifierExpression>("expr");
AsExpression exp; BitcastExpression exp;
exp.set_expr(std::move(expr)); exp.set_expr(std::move(expr));
EXPECT_FALSE(exp.IsValid()); EXPECT_FALSE(exp.IsValid());
} }
TEST_F(AsExpressionTest, IsValid_MissingExpr) { TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
type::F32Type f32; type::F32Type f32;
AsExpression exp; BitcastExpression exp;
exp.set_type(&f32); exp.set_type(&f32);
EXPECT_FALSE(exp.IsValid()); EXPECT_FALSE(exp.IsValid());
} }
TEST_F(AsExpressionTest, IsValid_InvalidExpr) { TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) {
type::F32Type f32; type::F32Type f32;
auto expr = std::make_unique<IdentifierExpression>(""); auto expr = std::make_unique<IdentifierExpression>("");
AsExpression e(&f32, std::move(expr)); BitcastExpression e(&f32, std::move(expr));
EXPECT_FALSE(e.IsValid()); EXPECT_FALSE(e.IsValid());
} }
TEST_F(AsExpressionTest, ToStr) { TEST_F(BitcastExpressionTest, ToStr) {
type::F32Type f32; type::F32Type f32;
auto expr = std::make_unique<IdentifierExpression>("expr"); auto expr = std::make_unique<IdentifierExpression>("expr");
AsExpression exp(&f32, std::move(expr)); BitcastExpression exp(&f32, std::move(expr));
std::ostringstream out; std::ostringstream out;
exp.to_str(out, 2); exp.to_str(out, 2);
EXPECT_EQ(out.str(), R"( As<__f32>{ EXPECT_EQ(out.str(), R"( Bitcast<__f32>{
Identifier{expr} Identifier{expr}
} }
)"); )");

View File

@ -17,8 +17,8 @@
#include <assert.h> #include <assert.h>
#include "src/ast/array_accessor_expression.h" #include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/call_expression.h" #include "src/ast/call_expression.h"
#include "src/ast/cast_expression.h" #include "src/ast/cast_expression.h"
#include "src/ast/constructor_expression.h" #include "src/ast/constructor_expression.h"
@ -45,7 +45,7 @@ bool Expression::IsArrayAccessor() const {
return false; return false;
} }
bool Expression::IsAs() const { bool Expression::IsBitcast() const {
return false; return false;
} }
@ -81,9 +81,9 @@ const ArrayAccessorExpression* Expression::AsArrayAccessor() const {
return static_cast<const ArrayAccessorExpression*>(this); return static_cast<const ArrayAccessorExpression*>(this);
} }
const AsExpression* Expression::AsAs() const { const BitcastExpression* Expression::AsBitcast() const {
assert(IsAs()); assert(IsBitcast());
return static_cast<const AsExpression*>(this); return static_cast<const BitcastExpression*>(this);
} }
const BinaryExpression* Expression::AsBinary() const { const BinaryExpression* Expression::AsBinary() const {
@ -126,9 +126,9 @@ ArrayAccessorExpression* Expression::AsArrayAccessor() {
return static_cast<ArrayAccessorExpression*>(this); return static_cast<ArrayAccessorExpression*>(this);
} }
AsExpression* Expression::AsAs() { BitcastExpression* Expression::AsBitcast() {
assert(IsAs()); assert(IsBitcast());
return static_cast<AsExpression*>(this); return static_cast<BitcastExpression*>(this);
} }
BinaryExpression* Expression::AsBinary() { BinaryExpression* Expression::AsBinary() {

View File

@ -25,8 +25,8 @@ namespace tint {
namespace ast { namespace ast {
class ArrayAccessorExpression; class ArrayAccessorExpression;
class AsExpression;
class BinaryExpression; class BinaryExpression;
class BitcastExpression;
class CallExpression; class CallExpression;
class CastExpression; class CastExpression;
class IdentifierExpression; class IdentifierExpression;
@ -47,8 +47,8 @@ class Expression : public Node {
/// @returns true if this is an array accessor expression /// @returns true if this is an array accessor expression
virtual bool IsArrayAccessor() const; virtual bool IsArrayAccessor() const;
/// @returns true if this is an as expression /// @returns true if this is a bitcast expression
virtual bool IsAs() const; virtual bool IsBitcast() const;
/// @returns true if this is a call expression /// @returns true if this is a call expression
virtual bool IsCall() const; virtual bool IsCall() const;
/// @returns true if this is a cast expression /// @returns true if this is a cast expression
@ -66,8 +66,8 @@ class Expression : public Node {
/// @returns the expression as an array accessor /// @returns the expression as an array accessor
const ArrayAccessorExpression* AsArrayAccessor() const; const ArrayAccessorExpression* AsArrayAccessor() const;
/// @returns the expression as an as /// @returns the expression as a bitcast
const AsExpression* AsAs() const; const BitcastExpression* AsBitcast() const;
/// @returns the expression as a call /// @returns the expression as a call
const CallExpression* AsCall() const; const CallExpression* AsCall() const;
/// @returns the expression as a cast /// @returns the expression as a cast
@ -85,8 +85,8 @@ class Expression : public Node {
/// @returns the expression as an array accessor /// @returns the expression as an array accessor
ArrayAccessorExpression* AsArrayAccessor(); ArrayAccessorExpression* AsArrayAccessor();
/// @returns the expression as an as /// @returns the expression as a bitcast
AsExpression* AsAs(); BitcastExpression* AsBitcast();
/// @returns the expression as a call /// @returns the expression as a call
CallExpression* AsCall(); CallExpression* AsCall();
/// @returns the expression as a cast /// @returns the expression as a cast

View File

@ -15,9 +15,9 @@
#include "src/ast/transform/vertex_pulling_transform.h" #include "src/ast/transform/vertex_pulling_transform.h"
#include "src/ast/array_accessor_expression.h" #include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/decorated_variable.h" #include "src/ast/decorated_variable.h"
#include "src/ast/expression.h" #include "src/ast/expression.h"
#include "src/ast/member_accessor_expression.h" #include "src/ast/member_accessor_expression.h"
@ -361,16 +361,16 @@ std::unique_ptr<Expression> VertexPullingTransform::AccessI32(
uint32_t buffer, uint32_t buffer,
std::unique_ptr<Expression> pos) { std::unique_ptr<Expression> pos) {
// as<T> reinterprets bits // as<T> reinterprets bits
return std::make_unique<AsExpression>(GetI32Type(), return std::make_unique<BitcastExpression>(GetI32Type(),
AccessU32(buffer, std::move(pos))); AccessU32(buffer, std::move(pos)));
} }
std::unique_ptr<Expression> VertexPullingTransform::AccessF32( std::unique_ptr<Expression> VertexPullingTransform::AccessF32(
uint32_t buffer, uint32_t buffer,
std::unique_ptr<Expression> pos) { std::unique_ptr<Expression> pos) {
// as<T> reinterprets bits // as<T> reinterprets bits
return std::make_unique<AsExpression>(GetF32Type(), return std::make_unique<BitcastExpression>(GetF32Type(),
AccessU32(buffer, std::move(pos))); AccessU32(buffer, std::move(pos)));
} }
std::unique_ptr<Expression> VertexPullingTransform::AccessPrimitive( std::unique_ptr<Expression> VertexPullingTransform::AccessPrimitive(

View File

@ -185,7 +185,7 @@ TEST_F(VertexPullingTransformTest, OneAttribute) {
} }
Assignment{ Assignment{
Identifier{var_a} Identifier{var_a}
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0} Identifier{tint_pulling_vertex_buffer_0}
@ -266,7 +266,7 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) {
} }
Assignment{ Assignment{
Identifier{var_a} Identifier{var_a}
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0} Identifier{tint_pulling_vertex_buffer_0}
@ -347,7 +347,7 @@ TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) {
} }
Assignment{ Assignment{
Identifier{var_a} Identifier{var_a}
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0} Identifier{tint_pulling_vertex_buffer_0}
@ -480,7 +480,7 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
} }
Assignment{ Assignment{
Identifier{var_a} Identifier{var_a}
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0} Identifier{tint_pulling_vertex_buffer_0}
@ -508,7 +508,7 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
} }
Assignment{ Assignment{
Identifier{var_b} Identifier{var_b}
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_1} Identifier{tint_pulling_vertex_buffer_1}
@ -599,7 +599,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
} }
Assignment{ Assignment{
Identifier{var_a} Identifier{var_a}
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0} Identifier{tint_pulling_vertex_buffer_0}
@ -629,7 +629,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
Identifier{var_b} Identifier{var_b}
TypeConstructor{ TypeConstructor{
__vec_4__f32 __vec_4__f32
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0} Identifier{tint_pulling_vertex_buffer_0}
@ -646,7 +646,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
} }
} }
} }
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0} Identifier{tint_pulling_vertex_buffer_0}
@ -663,7 +663,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
} }
} }
} }
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0} Identifier{tint_pulling_vertex_buffer_0}
@ -680,7 +680,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
} }
} }
} }
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0} Identifier{tint_pulling_vertex_buffer_0}
@ -805,7 +805,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
Identifier{var_a} Identifier{var_a}
TypeConstructor{ TypeConstructor{
__vec_2__f32 __vec_2__f32
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0} Identifier{tint_pulling_vertex_buffer_0}
@ -822,7 +822,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
} }
} }
} }
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_0} Identifier{tint_pulling_vertex_buffer_0}
@ -857,7 +857,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
Identifier{var_b} Identifier{var_b}
TypeConstructor{ TypeConstructor{
__vec_3__f32 __vec_3__f32
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_1} Identifier{tint_pulling_vertex_buffer_1}
@ -874,7 +874,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
} }
} }
} }
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_1} Identifier{tint_pulling_vertex_buffer_1}
@ -891,7 +891,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
} }
} }
} }
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_1} Identifier{tint_pulling_vertex_buffer_1}
@ -926,7 +926,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
Identifier{var_c} Identifier{var_c}
TypeConstructor{ TypeConstructor{
__vec_4__f32 __vec_4__f32
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_2} Identifier{tint_pulling_vertex_buffer_2}
@ -943,7 +943,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
} }
} }
} }
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_2} Identifier{tint_pulling_vertex_buffer_2}
@ -960,7 +960,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
} }
} }
} }
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_2} Identifier{tint_pulling_vertex_buffer_2}
@ -977,7 +977,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
} }
} }
} }
As<__f32>{ Bitcast<__f32>{
ArrayAccessor{ ArrayAccessor{
MemberAccessor{ MemberAccessor{
Identifier{tint_pulling_vertex_buffer_2} Identifier{tint_pulling_vertex_buffer_2}

View File

@ -28,9 +28,9 @@
#include "source/opt/module.h" #include "source/opt/module.h"
#include "spirv/unified1/GLSL.std.450.h" #include "spirv/unified1/GLSL.std.450.h"
#include "src/ast/array_accessor_expression.h" #include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/bool_literal.h" #include "src/ast/bool_literal.h"
#include "src/ast/break_statement.h" #include "src/ast/break_statement.h"
#include "src/ast/call_expression.h" #include "src/ast/call_expression.h"
@ -2719,7 +2719,7 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
} }
if (opcode == SpvOpBitcast) { 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)}; ast_type, MakeOperand(inst, 0).expr)};
} }
@ -3469,7 +3469,7 @@ TypedExpression FunctionEmitter::MakeNumericConversion(
if (requested_type == expr_type) { if (requested_type == expr_type) {
return result; return result;
} }
return {requested_type, std::make_unique<ast::AsExpression>( return {requested_type, std::make_unique<ast::BitcastExpression>(
requested_type, std::move(result.expr))}; requested_type, std::move(result.expr))};
} }

View File

@ -96,7 +96,7 @@ std::string AstFor(std::string assembly) {
})"; })";
} }
if (assembly == "cast_int_v2uint_10_20") { if (assembly == "cast_int_v2uint_10_20") {
return R"(As<__vec_2__i32>{ return R"(Bitcast<__vec_2__i32>{
TypeConstructor{ TypeConstructor{
__vec_2__u32 __vec_2__u32
ScalarConstructor{10} ScalarConstructor{10}
@ -170,7 +170,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) {
{ {
UnaryOp{ UnaryOp{
negation negation
As<__i32>{ Bitcast<__i32>{
ScalarConstructor{10} ScalarConstructor{10}
} }
} }
@ -197,7 +197,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) {
none none
__u32 __u32
{ {
As<__u32>{ Bitcast<__u32>{
UnaryOp{ UnaryOp{
negation negation
ScalarConstructor{30} ScalarConstructor{30}
@ -226,10 +226,10 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) {
none none
__u32 __u32
{ {
As<__u32>{ Bitcast<__u32>{
UnaryOp{ UnaryOp{
negation negation
As<__i32>{ Bitcast<__i32>{
ScalarConstructor{10} ScalarConstructor{10}
} }
} }
@ -290,7 +290,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) {
{ {
UnaryOp{ UnaryOp{
negation negation
As<__vec_2__i32>{ Bitcast<__vec_2__i32>{
TypeConstructor{ TypeConstructor{
__vec_2__u32 __vec_2__u32
ScalarConstructor{10} ScalarConstructor{10}
@ -321,7 +321,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) {
none none
__vec_2__u32 __vec_2__u32
{ {
As<__vec_2__u32>{ Bitcast<__vec_2__u32>{
UnaryOp{ UnaryOp{
negation negation
TypeConstructor{ TypeConstructor{
@ -354,10 +354,10 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) {
none none
__vec_2__u32 __vec_2__u32
{ {
As<__vec_2__u32>{ Bitcast<__vec_2__u32>{
UnaryOp{ UnaryOp{
negation negation
As<__vec_2__i32>{ Bitcast<__vec_2__i32>{
TypeConstructor{ TypeConstructor{
__vec_2__u32 __vec_2__u32
ScalarConstructor{10} ScalarConstructor{10}
@ -654,12 +654,12 @@ INSTANTIATE_TEST_SUITE_P(
// Mixed, returning int, second arg uint // Mixed, returning int, second arg uint
BinaryData{"int", "int_30", "OpSDiv", "uint_10", "__i32", BinaryData{"int", "int_30", "OpSDiv", "uint_10", "__i32",
"ScalarConstructor{30}", "divide", "ScalarConstructor{30}", "divide",
R"(As<__i32>{ R"(Bitcast<__i32>{
ScalarConstructor{10} ScalarConstructor{10}
})"}, })"},
// Mixed, returning int, first arg uint // Mixed, returning int, first arg uint
BinaryData{"int", "uint_10", "OpSDiv", "int_30", "__i32", BinaryData{"int", "uint_10", "OpSDiv", "int_30", "__i32",
R"(As<__i32>{ R"(Bitcast<__i32>{
ScalarConstructor{10} ScalarConstructor{10}
})", })",
"divide", "ScalarConstructor{30}"}, "divide", "ScalarConstructor{30}"},
@ -696,7 +696,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Scalar_UnsignedResult) {
none none
__u32 __u32
{ {
As<__u32>{ Bitcast<__u32>{
Binary{ Binary{
ScalarConstructor{30} ScalarConstructor{30}
divide divide
@ -731,7 +731,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Vector_UnsignedResult) {
none none
__vec_2__u32 __vec_2__u32
{ {
As<__vec_2__u32>{ Bitcast<__vec_2__u32>{
Binary{ Binary{
TypeConstructor{ TypeConstructor{
__vec_2__i32 __vec_2__i32
@ -798,12 +798,12 @@ INSTANTIATE_TEST_SUITE_P(
// Mixed, returning int, second arg uint // Mixed, returning int, second arg uint
BinaryData{"int", "int_30", "OpSMod", "uint_10", "__i32", BinaryData{"int", "int_30", "OpSMod", "uint_10", "__i32",
"ScalarConstructor{30}", "modulo", "ScalarConstructor{30}", "modulo",
R"(As<__i32>{ R"(Bitcast<__i32>{
ScalarConstructor{10} ScalarConstructor{10}
})"}, })"},
// Mixed, returning int, first arg uint // Mixed, returning int, first arg uint
BinaryData{"int", "uint_10", "OpSMod", "int_30", "__i32", BinaryData{"int", "uint_10", "OpSMod", "int_30", "__i32",
R"(As<__i32>{ R"(Bitcast<__i32>{
ScalarConstructor{10} ScalarConstructor{10}
})", })",
"modulo", "ScalarConstructor{30}"}, "modulo", "ScalarConstructor{30}"},
@ -840,7 +840,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Scalar_UnsignedResult) {
none none
__u32 __u32
{ {
As<__u32>{ Bitcast<__u32>{
Binary{ Binary{
ScalarConstructor{30} ScalarConstructor{30}
modulo modulo
@ -875,7 +875,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Vector_UnsignedResult) {
none none
__vec_2__u32 __vec_2__u32
{ {
As<__vec_2__u32>{ Bitcast<__vec_2__u32>{
Binary{ Binary{
TypeConstructor{ TypeConstructor{
__vec_2__i32 __vec_2__i32

View File

@ -91,7 +91,7 @@ std::string AstFor(std::string assembly) {
})"; })";
} }
if (assembly == "cast_int_v2uint_10_20") { if (assembly == "cast_int_v2uint_10_20") {
return R"(As<__vec_2__i32>{ return R"(Bitcast<__vec_2__i32>{
TypeConstructor{ TypeConstructor{
__vec_2__u32 __vec_2__u32
ScalarConstructor{10} ScalarConstructor{10}
@ -421,7 +421,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Uint) {
none none
__i32 __i32
{ {
As<__i32>{ Bitcast<__i32>{
UnaryOp{ UnaryOp{
not not
ScalarConstructor{10} ScalarConstructor{10}
@ -450,7 +450,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Int) {
none none
__u32 __u32
{ {
As<__u32>{ Bitcast<__u32>{
UnaryOp{ UnaryOp{
not not
ScalarConstructor{30} ScalarConstructor{30}
@ -537,7 +537,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) {
none none
__vec_2__i32 __vec_2__i32
{ {
As<__vec_2__i32>{ Bitcast<__vec_2__i32>{
UnaryOp{ UnaryOp{
not not
TypeConstructor{ TypeConstructor{
@ -570,7 +570,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) {
none none
__vec_2__u32 __vec_2__u32
{ {
As<__vec_2__u32>{ Bitcast<__vec_2__u32>{
UnaryOp{ UnaryOp{
not not
TypeConstructor{ TypeConstructor{

View File

@ -88,7 +88,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Scalar) {
none none
__u32 __u32
{ {
As<__u32>{ Bitcast<__u32>{
ScalarConstructor{50.000000} ScalarConstructor{50.000000}
} }
} }
@ -114,7 +114,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Vector) {
none none
__vec_2__f32 __vec_2__f32
{ {
As<__vec_2__f32>{ Bitcast<__vec_2__f32>{
TypeConstructor{ TypeConstructor{
__vec_2__u32 __vec_2__u32
ScalarConstructor{10} ScalarConstructor{10}
@ -270,7 +270,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) {
__f32 __f32
{ {
Cast<__f32>( Cast<__f32>(
As<__i32>{ Bitcast<__i32>{
Identifier{x_30} Identifier{x_30}
} }
) )
@ -324,7 +324,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) {
__vec_2__f32 __vec_2__f32
{ {
Cast<__vec_2__f32>( Cast<__vec_2__f32>(
As<__vec_2__i32>{ Bitcast<__vec_2__i32>{
Identifier{x_30} Identifier{x_30}
} }
) )
@ -385,7 +385,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromSigned) {
__f32 __f32
{ {
Cast<__f32>( Cast<__f32>(
As<__u32>{ Bitcast<__u32>{
Identifier{x_30} Identifier{x_30}
} }
) )
@ -439,7 +439,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) {
__vec_2__f32 __vec_2__f32
{ {
Cast<__vec_2__f32>( Cast<__vec_2__f32>(
As<__vec_2__u32>{ Bitcast<__vec_2__u32>{
Identifier{x_30} Identifier{x_30}
} }
) )
@ -552,7 +552,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) {
none none
__u32 __u32
{ {
As<__u32>{ Bitcast<__u32>{
Cast<__i32>( Cast<__i32>(
Identifier{x_30} Identifier{x_30}
) )
@ -606,7 +606,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) {
none none
__vec_2__u32 __vec_2__u32
{ {
As<__vec_2__u32>{ Bitcast<__vec_2__u32>{
Cast<__vec_2__i32>( Cast<__vec_2__i32>(
Identifier{x_30} Identifier{x_30}
) )
@ -668,7 +668,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToSigned) {
none none
__i32 __i32
{ {
As<__i32>{ Bitcast<__i32>{
Cast<__u32>( Cast<__u32>(
Identifier{x_30} Identifier{x_30}
) )
@ -722,7 +722,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) {
none none
__vec_2__i32 __vec_2__i32
{ {
As<__vec_2__i32>{ Bitcast<__vec_2__i32>{
Cast<__vec_2__u32>( Cast<__vec_2__u32>(
Identifier{x_30} Identifier{x_30}
) )

View File

@ -92,17 +92,17 @@ std::string AstFor(std::string assembly) {
})"; })";
} }
if (assembly == "cast_uint_10") { if (assembly == "cast_uint_10") {
return R"(As<__i32>{ return R"(Bitcast<__i32>{
ScalarConstructor{10} ScalarConstructor{10}
})"; })";
} }
if (assembly == "cast_uint_20") { if (assembly == "cast_uint_20") {
return R"(As<__i32>{ return R"(Bitcast<__i32>{
ScalarConstructor{20} ScalarConstructor{20}
})"; })";
} }
if (assembly == "cast_v2uint_10_20") { if (assembly == "cast_v2uint_10_20") {
return R"(As<__vec_2__i32>{ return R"(Bitcast<__vec_2__i32>{
TypeConstructor{ TypeConstructor{
__vec_2__u32 __vec_2__u32
ScalarConstructor{10} ScalarConstructor{10}
@ -118,7 +118,7 @@ std::string AstFor(std::string assembly) {
})"; })";
} }
if (assembly == "cast_v2uint_20_10") { if (assembly == "cast_v2uint_20_10") {
return R"(As<__vec_2__i32>{ return R"(Bitcast<__vec_2__i32>{
TypeConstructor{ TypeConstructor{
__vec_2__u32 __vec_2__u32
ScalarConstructor{20} ScalarConstructor{20}
@ -127,12 +127,12 @@ std::string AstFor(std::string assembly) {
})"; })";
} }
if (assembly == "cast_int_30") { if (assembly == "cast_int_30") {
return R"(As<__u32>{ return R"(Bitcast<__u32>{
ScalarConstructor{30} ScalarConstructor{30}
})"; })";
} }
if (assembly == "cast_int_40") { if (assembly == "cast_int_40") {
return R"(As<__u32>{ return R"(Bitcast<__u32>{
ScalarConstructor{40} ScalarConstructor{40}
})"; })";
} }
@ -144,7 +144,7 @@ std::string AstFor(std::string assembly) {
})"; })";
} }
if (assembly == "cast_v2int_30_40") { if (assembly == "cast_v2int_30_40") {
return R"(As<__vec_2__u32>{ return R"(Bitcast<__vec_2__u32>{
TypeConstructor{ TypeConstructor{
__vec_2__i32 __vec_2__i32
ScalarConstructor{30} ScalarConstructor{30}
@ -160,7 +160,7 @@ std::string AstFor(std::string assembly) {
})"; })";
} }
if (assembly == "cast_v2int_40_30") { if (assembly == "cast_v2int_40_30") {
return R"(As<__vec_2__u32>{ return R"(Bitcast<__vec_2__u32>{
TypeConstructor{ TypeConstructor{
__vec_2__i32 __vec_2__i32
ScalarConstructor{40} ScalarConstructor{40}

View File

@ -34,9 +34,9 @@
#include "source/opt/type_manager.h" #include "source/opt/type_manager.h"
#include "source/opt/types.h" #include "source/opt/types.h"
#include "spirv-tools/libspirv.hpp" #include "spirv-tools/libspirv.hpp"
#include "src/ast/as_expression.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/binding_decoration.h" #include "src/ast/binding_decoration.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/bool_literal.h" #include "src/ast/bool_literal.h"
#include "src/ast/builtin.h" #include "src/ast/builtin.h"
#include "src/ast/builtin_decoration.h" #include "src/ast/builtin_decoration.h"
@ -1302,14 +1302,14 @@ TypedExpression ParserImpl::RectifyOperandSignedness(SpvOp op,
auto* unsigned_ty = unsigned_type_for_[type]; auto* unsigned_ty = unsigned_type_for_[type];
if (unsigned_ty != nullptr) { if (unsigned_ty != nullptr) {
// Conversion is required. // 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))}; unsigned_ty, std::move(expr.expr))};
} }
} else if (requires_signed) { } else if (requires_signed) {
auto* signed_ty = signed_type_for_[type]; auto* signed_ty = signed_type_for_[type];
if (signed_ty != nullptr) { if (signed_ty != nullptr) {
// Conversion is required. // 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))}; signed_ty, std::move(expr.expr))};
} }
} }
@ -1373,8 +1373,8 @@ TypedExpression ParserImpl::RectifyForcedResultType(
if ((forced_result_ty == nullptr) || (forced_result_ty == expr.type)) { if ((forced_result_ty == nullptr) || (forced_result_ty == expr.type)) {
return expr; return expr;
} }
return {expr.type, return {expr.type, std::make_unique<ast::BitcastExpression>(
std::make_unique<ast::AsExpression>(expr.type, std::move(expr.expr))}; expr.type, std::move(expr.expr))};
} }
bool ParserImpl::EmitFunctions() { bool ParserImpl::EmitFunctions() {

View File

@ -471,10 +471,10 @@ Token Lexer::try_punctuation() {
Token Lexer::check_keyword(const Source& source, const std::string& str) { Token Lexer::check_keyword(const Source& source, const std::string& str) {
if (str == "array") if (str == "array")
return {Token::Type::kArray, source, "array"}; return {Token::Type::kArray, source, "array"};
if (str == "as")
return {Token::Type::kAs, source, "as"};
if (str == "binding") if (str == "binding")
return {Token::Type::kBinding, source, "binding"}; return {Token::Type::kBinding, source, "binding"};
if (str == "bitcast")
return {Token::Type::kBitcast, source, "bitcast"};
if (str == "block") if (str == "block")
return {Token::Type::kBlock, source, "block"}; return {Token::Type::kBlock, source, "block"};
if (str == "bool") if (str == "bool")

View File

@ -413,8 +413,8 @@ INSTANTIATE_TEST_SUITE_P(
KeywordTest, KeywordTest,
testing::Values( testing::Values(
TokenData{"array", Token::Type::kArray}, TokenData{"array", Token::Type::kArray},
TokenData{"as", Token::Type::kAs},
TokenData{"binding", Token::Type::kBinding}, TokenData{"binding", Token::Type::kBinding},
TokenData{"bitcast", Token::Type::kBitcast},
TokenData{"block", Token::Type::kBlock}, TokenData{"block", Token::Type::kBlock},
TokenData{"bool", Token::Type::kBool}, TokenData{"bool", Token::Type::kBool},
TokenData{"break", Token::Type::kBreak}, TokenData{"break", Token::Type::kBreak},

View File

@ -18,9 +18,9 @@
#include <vector> #include <vector>
#include "src/ast/array_accessor_expression.h" #include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/binding_decoration.h" #include "src/ast/binding_decoration.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/bool_literal.h" #include "src/ast/bool_literal.h"
#include "src/ast/break_statement.h" #include "src/ast/break_statement.h"
#include "src/ast/builtin_decoration.h" #include "src/ast/builtin_decoration.h"
@ -2790,7 +2790,7 @@ std::unique_ptr<ast::Expression> ParserImpl::primary_expression() {
return paren; return paren;
} }
if (t.IsCast() || t.IsAs()) { if (t.IsCast() || t.IsBitcast()) {
auto src = t; auto src = t;
next(); // Consume the peek next(); // Consume the peek
@ -2827,8 +2827,8 @@ std::unique_ptr<ast::Expression> ParserImpl::primary_expression() {
return std::make_unique<ast::CastExpression>(source, type, return std::make_unique<ast::CastExpression>(source, type,
std::move(params)); std::move(params));
} else { } else {
return std::make_unique<ast::AsExpression>(source, type, return std::make_unique<ast::BitcastExpression>(source, type,
std::move(params)); std::move(params));
} }
} else if (t.IsIdentifier()) { } else if (t.IsIdentifier()) {

View File

@ -14,7 +14,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/array_accessor_expression.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/bool_literal.h"
#include "src/ast/cast_expression.h" #include "src/ast/cast_expression.h"
#include "src/ast/identifier_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"); 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* 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(); auto e = p->primary_expression();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr); 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_EQ(c->type(), f32_type);
ASSERT_TRUE(c->expr()->IsConstructor()); ASSERT_TRUE(c->expr()->IsConstructor());
ASSERT_TRUE(c->expr()->AsConstructor()->IsScalarConstructor()); ASSERT_TRUE(c->expr()->AsConstructor()->IsScalarConstructor());
} }
TEST_F(ParserImplTest, PrimaryExpression_As_MissingGreaterThan) { TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingGreaterThan) {
auto* p = parser("as<f32(1)"); auto* p = parser("bitcast<f32(1)");
auto e = p->primary_expression(); auto e = p->primary_expression();
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr); 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) { TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingType) {
auto* p = parser("as<>(1)"); auto* p = parser("bitcast<>(1)");
auto e = p->primary_expression(); auto e = p->primary_expression();
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr); 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) { TEST_F(ParserImplTest, PrimaryExpression_Bitcast_InvalidType) {
auto* p = parser("as<invalid>(1)"); auto* p = parser("bitcast<invalid>(1)");
auto e = p->primary_expression(); auto e = p->primary_expression();
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr); 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) { TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingLeftParen) {
auto* p = parser("as<f32>1)"); auto* p = parser("bitcast<f32>1)");
auto e = p->primary_expression(); auto e = p->primary_expression();
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr); ASSERT_EQ(e, nullptr);
EXPECT_EQ(p->error(), "1:8: expected ("); EXPECT_EQ(p->error(), "1:13: expected (");
} }
TEST_F(ParserImplTest, PrimaryExpression_As_MissingRightParen) { TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingRightParen) {
auto* p = parser("as<f32>(1"); auto* p = parser("bitcast<f32>(1");
auto e = p->primary_expression(); auto e = p->primary_expression();
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr); ASSERT_EQ(e, nullptr);
EXPECT_EQ(p->error(), "1:10: expected )"); EXPECT_EQ(p->error(), "1:15: expected )");
} }
TEST_F(ParserImplTest, PrimaryExpression_As_MissingExpression) { TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingExpression) {
auto* p = parser("as<f32>()"); auto* p = parser("bitcast<f32>()");
auto e = p->primary_expression(); auto e = p->primary_expression();
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr); 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) { TEST_F(ParserImplTest, PrimaryExpression_bitcast_InvalidExpression) {
auto* p = parser("as<f32>(if (a) {})"); auto* p = parser("bitcast<f32>(if (a) {})");
auto e = p->primary_expression(); auto e = p->primary_expression();
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr); 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 } // namespace

View File

@ -107,10 +107,10 @@ std::string Token::TypeToName(Type type) {
case Token::Type::kArray: case Token::Type::kArray:
return "array"; return "array";
case Token::Type::kAs:
return "as";
case Token::Type::kBinding: case Token::Type::kBinding:
return "binding"; return "binding";
case Token::Type::kBitcast:
return "bitcast";
case Token::Type::kBlock: case Token::Type::kBlock:
return "block"; return "block";
case Token::Type::kBool: case Token::Type::kBool:

View File

@ -118,10 +118,10 @@ class Token {
/// A 'array' /// A 'array'
kArray, kArray,
/// A 'as'
kAs,
/// A 'binding' /// A 'binding'
kBinding, kBinding,
/// A 'bitcast'
kBitcast,
/// A 'bool' /// A 'bool'
kBool, kBool,
/// A 'block' /// A 'block'
@ -495,10 +495,10 @@ class Token {
/// @returns true if token is a 'array' /// @returns true if token is a 'array'
bool IsArray() const { return type_ == Type::kArray; } 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' /// @returns true if token is a 'binding'
bool IsBinding() const { return type_ == Type::kBinding; } 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' /// @returns true if token is a 'block'
bool IsBlock() const { return type_ == Type::kBlock; } bool IsBlock() const { return type_ == Type::kBlock; }
/// @returns true if token is a 'bool' /// @returns true if token is a 'bool'

View File

@ -18,9 +18,9 @@
#include <vector> #include <vector>
#include "src/ast/array_accessor_expression.h" #include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/block_statement.h" #include "src/ast/block_statement.h"
#include "src/ast/break_statement.h" #include "src/ast/break_statement.h"
#include "src/ast/call_expression.h" #include "src/ast/call_expression.h"
@ -296,12 +296,12 @@ bool TypeDeterminer::DetermineResultType(ast::Expression* expr) {
if (expr->IsArrayAccessor()) { if (expr->IsArrayAccessor()) {
return DetermineArrayAccessor(expr->AsArrayAccessor()); return DetermineArrayAccessor(expr->AsArrayAccessor());
} }
if (expr->IsAs()) {
return DetermineAs(expr->AsAs());
}
if (expr->IsBinary()) { if (expr->IsBinary()) {
return DetermineBinary(expr->AsBinary()); return DetermineBinary(expr->AsBinary());
} }
if (expr->IsBitcast()) {
return DetermineBitcast(expr->AsBitcast());
}
if (expr->IsCall()) { if (expr->IsCall()) {
return DetermineCall(expr->AsCall()); return DetermineCall(expr->AsCall());
} }
@ -362,7 +362,7 @@ bool TypeDeterminer::DetermineArrayAccessor(
return true; return true;
} }
bool TypeDeterminer::DetermineAs(ast::AsExpression* expr) { bool TypeDeterminer::DetermineBitcast(ast::BitcastExpression* expr) {
if (!DetermineResultType(expr->expr())) { if (!DetermineResultType(expr->expr())) {
return false; return false;
} }

View File

@ -27,8 +27,8 @@ namespace tint {
namespace ast { namespace ast {
class ArrayAccessorExpression; class ArrayAccessorExpression;
class AsExpression;
class BinaryExpression; class BinaryExpression;
class BitcastExpression;
class CallExpression; class CallExpression;
class CastExpression; class CastExpression;
class ConstructorExpression; class ConstructorExpression;
@ -117,8 +117,8 @@ class TypeDeterminer {
void set_entry_points(const std::string& fn_name, const std::string& ep_name); void set_entry_points(const std::string& fn_name, const std::string& ep_name);
bool DetermineArrayAccessor(ast::ArrayAccessorExpression* expr); bool DetermineArrayAccessor(ast::ArrayAccessorExpression* expr);
bool DetermineAs(ast::AsExpression* expr);
bool DetermineBinary(ast::BinaryExpression* expr); bool DetermineBinary(ast::BinaryExpression* expr);
bool DetermineBitcast(ast::BitcastExpression* expr);
bool DetermineCall(ast::CallExpression* expr); bool DetermineCall(ast::CallExpression* expr);
bool DetermineCast(ast::CastExpression* expr); bool DetermineCast(ast::CastExpression* expr);
bool DetermineConstructor(ast::ConstructorExpression* expr); bool DetermineConstructor(ast::ConstructorExpression* expr);

View File

@ -20,9 +20,9 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/array_accessor_expression.h" #include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/block_statement.h" #include "src/ast/block_statement.h"
#include "src/ast/bool_literal.h" #include "src/ast/bool_literal.h"
#include "src/ast/break_statement.h" #include "src/ast/break_statement.h"
@ -611,14 +611,14 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Vector) {
EXPECT_TRUE(ptr->type()->IsF32()); EXPECT_TRUE(ptr->type()->IsF32());
} }
TEST_F(TypeDeterminerTest, Expr_As) { TEST_F(TypeDeterminerTest, Expr_Bitcast) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::AsExpression as(&f32, ast::BitcastExpression bitcast(
std::make_unique<ast::IdentifierExpression>("name")); &f32, std::make_unique<ast::IdentifierExpression>("name"));
EXPECT_TRUE(td()->DetermineResultType(&as)); EXPECT_TRUE(td()->DetermineResultType(&bitcast));
ASSERT_NE(as.result_type(), nullptr); ASSERT_NE(bitcast.result_type(), nullptr);
EXPECT_TRUE(as.result_type()->IsF32()); EXPECT_TRUE(bitcast.result_type()->IsF32());
} }
TEST_F(TypeDeterminerTest, Expr_Call) { TEST_F(TypeDeterminerTest, Expr_Call) {

View File

@ -17,7 +17,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "spirv/unified1/GLSL.std.450.h" #include "spirv/unified1/GLSL.std.450.h"
#include "src/ast/array_accessor_expression.h" #include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/bool_literal.h" #include "src/ast/bool_literal.h"

View File

@ -17,9 +17,9 @@
#include <sstream> #include <sstream>
#include "src/ast/array_accessor_expression.h" #include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/bool_literal.h" #include "src/ast/bool_literal.h"
#include "src/ast/call_expression.h" #include "src/ast/call_expression.h"
#include "src/ast/call_statement.h" #include "src/ast/call_statement.h"
@ -238,12 +238,12 @@ bool GeneratorImpl::EmitArrayAccessor(std::ostream& pre,
return true; return true;
} }
bool GeneratorImpl::EmitAs(std::ostream& pre, bool GeneratorImpl::EmitBitcast(std::ostream& pre,
std::ostream& out, std::ostream& out,
ast::AsExpression* expr) { ast::BitcastExpression* expr) {
if (!expr->type()->IsF32() && !expr->type()->IsI32() && if (!expr->type()->IsF32() && !expr->type()->IsI32() &&
!expr->type()->IsU32()) { !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; return false;
} }
@ -856,15 +856,15 @@ bool GeneratorImpl::EmitDiscard(std::ostream& out, ast::DiscardStatement*) {
bool GeneratorImpl::EmitExpression(std::ostream& pre, bool GeneratorImpl::EmitExpression(std::ostream& pre,
std::ostream& out, std::ostream& out,
ast::Expression* expr) { ast::Expression* expr) {
if (expr->IsAs()) {
return EmitAs(pre, out, expr->AsAs());
}
if (expr->IsArrayAccessor()) { if (expr->IsArrayAccessor()) {
return EmitArrayAccessor(pre, out, expr->AsArrayAccessor()); return EmitArrayAccessor(pre, out, expr->AsArrayAccessor());
} }
if (expr->IsBinary()) { if (expr->IsBinary()) {
return EmitBinary(pre, out, expr->AsBinary()); return EmitBinary(pre, out, expr->AsBinary());
} }
if (expr->IsBitcast()) {
return EmitBitcast(pre, out, expr->AsBitcast());
}
if (expr->IsCall()) { if (expr->IsCall()) {
return EmitCall(pre, out, expr->AsCall()); return EmitCall(pre, out, expr->AsCall());
} }

View File

@ -73,12 +73,6 @@ class GeneratorImpl {
bool EmitArrayAccessor(std::ostream& pre, bool EmitArrayAccessor(std::ostream& pre,
std::ostream& out, std::ostream& out,
ast::ArrayAccessorExpression* expr); 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 /// Handles an assignment statement
/// @param out the output stream /// @param out the output stream
/// @param stmt the statement to emit /// @param stmt the statement to emit
@ -92,6 +86,14 @@ class GeneratorImpl {
bool EmitBinary(std::ostream& pre, bool EmitBinary(std::ostream& pre,
std::ostream& out, std::ostream& out,
ast::BinaryExpression* expr); 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 /// Handles a block statement
/// @param out the output stream /// @param out the output stream
/// @param stmt the statement to emit /// @param stmt the statement to emit

View File

@ -14,9 +14,9 @@
#include <memory> #include <memory>
#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/call_expression.h" #include "src/ast/call_expression.h"
#include "src/ast/call_statement.h" #include "src/ast/call_statement.h"
#include "src/ast/else_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<i32>(a && (b || c)) // as<i32>(a && (b || c))
ast::type::I32Type i32; ast::type::I32Type i32;
@ -303,7 +303,7 @@ TEST_F(HlslGeneratorImplTest_Binary, As_WithLogical) {
auto b = std::make_unique<ast::IdentifierExpression>("b"); auto b = std::make_unique<ast::IdentifierExpression>("b");
auto c = std::make_unique<ast::IdentifierExpression>("c"); auto c = std::make_unique<ast::IdentifierExpression>("c");
ast::AsExpression expr( ast::BitcastExpression expr(
&i32, std::make_unique<ast::BinaryExpression>( &i32, std::make_unique<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, std::move(a), ast::BinaryOp::kLogicalAnd, std::move(a),
std::make_unique<ast::BinaryExpression>( std::make_unique<ast::BinaryExpression>(

View File

@ -14,7 +14,7 @@
#include <memory> #include <memory>
#include "src/ast/as_expression.h" #include "src/ast/bitcast_expression.h"
#include "src/ast/identifier_expression.h" #include "src/ast/identifier_expression.h"
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
@ -27,32 +27,32 @@ namespace writer {
namespace hlsl { namespace hlsl {
namespace { 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; ast::type::F32Type f32;
auto id = std::make_unique<ast::IdentifierExpression>("id"); 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)"); EXPECT_EQ(result(), "asfloat(id)");
} }
TEST_F(HlslGeneratorImplTest_As, EmitExpression_As_Int) { TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto id = std::make_unique<ast::IdentifierExpression>("id"); 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)"); EXPECT_EQ(result(), "asint(id)");
} }
TEST_F(HlslGeneratorImplTest_As, EmitExpression_As_Uint) { TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
ast::type::U32Type u32; ast::type::U32Type u32;
auto id = std::make_unique<ast::IdentifierExpression>("id"); 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)"); EXPECT_EQ(result(), "asuint(id)");
} }

View File

@ -15,9 +15,9 @@
#include "src/writer/msl/generator_impl.h" #include "src/writer/msl/generator_impl.h"
#include "src/ast/array_accessor_expression.h" #include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/block_statement.h" #include "src/ast/block_statement.h"
#include "src/ast/bool_literal.h" #include "src/ast/bool_literal.h"
#include "src/ast/break_statement.h" #include "src/ast/break_statement.h"
@ -265,7 +265,7 @@ bool GeneratorImpl::EmitArrayAccessor(ast::ArrayAccessorExpression* expr) {
return true; return true;
} }
bool GeneratorImpl::EmitAs(ast::AsExpression* expr) { bool GeneratorImpl::EmitBitcast(ast::BitcastExpression* expr) {
out_ << "as_type<"; out_ << "as_type<";
if (!EmitType(expr->type(), "")) { if (!EmitType(expr->type(), "")) {
return false; return false;
@ -973,12 +973,12 @@ bool GeneratorImpl::EmitExpression(ast::Expression* expr) {
if (expr->IsArrayAccessor()) { if (expr->IsArrayAccessor()) {
return EmitArrayAccessor(expr->AsArrayAccessor()); return EmitArrayAccessor(expr->AsArrayAccessor());
} }
if (expr->IsAs()) {
return EmitAs(expr->AsAs());
}
if (expr->IsBinary()) { if (expr->IsBinary()) {
return EmitBinary(expr->AsBinary()); return EmitBinary(expr->AsBinary());
} }
if (expr->IsBitcast()) {
return EmitBitcast(expr->AsBitcast());
}
if (expr->IsCall()) { if (expr->IsCall()) {
return EmitCall(expr->AsCall()); return EmitCall(expr->AsCall());
} }

View File

@ -62,10 +62,6 @@ class GeneratorImpl : public TextGenerator {
/// @param expr the expression to emit /// @param expr the expression to emit
/// @returns true if the array accessor was emitted /// @returns true if the array accessor was emitted
bool EmitArrayAccessor(ast::ArrayAccessorExpression* expr); 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 /// Handles an assignment statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully /// @returns true if the statement was emitted successfully
@ -74,6 +70,10 @@ class GeneratorImpl : public TextGenerator {
/// @param expr the binary expression /// @param expr the binary expression
/// @returns true if the expression was emitted, false otherwise /// @returns true if the expression was emitted, false otherwise
bool EmitBinary(ast::BinaryExpression* expr); 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 /// Handles a block statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully /// @returns true if the statement was emitted successfully

View File

@ -15,7 +15,7 @@
#include <memory> #include <memory>
#include "gtest/gtest.h" #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/identifier_expression.h"
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
@ -28,14 +28,14 @@ namespace {
using MslGeneratorImplTest = testing::Test; using MslGeneratorImplTest = testing::Test;
TEST_F(MslGeneratorImplTest, EmitExpression_As) { TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto id = std::make_unique<ast::IdentifierExpression>("id"); 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; ast::Module m;
GeneratorImpl g(&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)"); EXPECT_EQ(g.result(), "as_type<float>(id)");
} }

View File

@ -20,10 +20,10 @@
#include "spirv/unified1/GLSL.std.450.h" #include "spirv/unified1/GLSL.std.450.h"
#include "spirv/unified1/spirv.h" #include "spirv/unified1/spirv.h"
#include "src/ast/array_accessor_expression.h" #include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/binding_decoration.h" #include "src/ast/binding_decoration.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/block_statement.h" #include "src/ast/block_statement.h"
#include "src/ast/bool_literal.h" #include "src/ast/bool_literal.h"
#include "src/ast/builtin_decoration.h" #include "src/ast/builtin_decoration.h"
@ -456,12 +456,12 @@ uint32_t Builder::GenerateExpression(ast::Expression* expr) {
if (expr->IsArrayAccessor()) { if (expr->IsArrayAccessor()) {
return GenerateAccessorExpression(expr->AsArrayAccessor()); return GenerateAccessorExpression(expr->AsArrayAccessor());
} }
if (expr->IsAs()) {
return GenerateAsExpression(expr->AsAs());
}
if (expr->IsBinary()) { if (expr->IsBinary()) {
return GenerateBinaryExpression(expr->AsBinary()); return GenerateBinaryExpression(expr->AsBinary());
} }
if (expr->IsBitcast()) {
return GenerateBitcastExpression(expr->AsBitcast());
}
if (expr->IsCall()) { if (expr->IsCall()) {
return GenerateCallExpression(expr->AsCall()); return GenerateCallExpression(expr->AsCall());
} }
@ -1696,24 +1696,24 @@ uint32_t Builder::GenerateSampledImage(ast::type::Type* texture_type,
return sampled_image.to_i(); 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 = result_op();
auto result_id = result.to_i(); 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) { if (result_type_id == 0) {
return 0; return 0;
} }
auto val_id = GenerateExpression(as->expr()); auto val_id = GenerateExpression(expr->expr());
if (val_id == 0) { if (val_id == 0) {
return 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 // Bitcast does not allow same types, just emit a CopyObject
auto* to_type = as->result_type()->UnwrapPtrIfNeeded(); auto* to_type = expr->result_type()->UnwrapPtrIfNeeded();
auto* from_type = as->expr()->result_type()->UnwrapPtrIfNeeded(); auto* from_type = expr->expr()->result_type()->UnwrapPtrIfNeeded();
if (to_type->type_name() == from_type->type_name()) { if (to_type->type_name() == from_type->type_name()) {
push_function_inst(spv::Op::OpCopyObject, {Operand::Int(result_type_id), push_function_inst(spv::Op::OpCopyObject, {Operand::Int(result_type_id),
result, Operand::Int(val_id)}); result, Operand::Int(val_id)});

View File

@ -265,14 +265,14 @@ class Builder {
/// @param lit the literal to generate /// @param lit the literal to generate
/// @returns the ID on success or 0 on failure /// @returns the ID on success or 0 on failure
uint32_t GenerateLiteralIfNeeded(ast::Literal* lit); 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 /// Generates a binary expression
/// @param expr the expression to generate /// @param expr the expression to generate
/// @returns the expression ID on success or 0 otherwise /// @returns the expression ID on success or 0 otherwise
uint32_t GenerateBinaryExpression(ast::BinaryExpression* expr); 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 /// Generates a short circuting binary expression
/// @param expr the expression to generate /// @param expr the expression to generate
/// @returns teh expression ID on success or 0 otherwise /// @returns teh expression ID on success or 0 otherwise

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
#include "gtest/gtest.h" #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/float_literal.h"
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/ast/scalar_constructor_expression.h" #include "src/ast/scalar_constructor_expression.h"
@ -31,22 +31,22 @@ namespace {
using BuilderTest = testing::Test; using BuilderTest = testing::Test;
TEST_F(BuilderTest, As) { TEST_F(BuilderTest, Bitcast) {
ast::type::U32Type u32; ast::type::U32Type u32;
ast::type::F32Type f32; ast::type::F32Type f32;
ast::AsExpression as(&u32, ast::BitcastExpression bitcast(
std::make_unique<ast::ScalarConstructorExpression>( &u32, std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.4))); std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
Context ctx; Context ctx;
ast::Module mod; ast::Module mod;
TypeDeterminer td(&ctx, &mod); TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&as)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
Builder b(&mod); Builder b(&mod);
b.push_function(Function{}); 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
%3 = OpTypeFloat 32 %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::type::F32Type f32;
ast::AsExpression as(&f32, ast::BitcastExpression bitcast(
std::make_unique<ast::ScalarConstructorExpression>( &f32, std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.4))); std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
Context ctx; Context ctx;
ast::Module mod; ast::Module mod;
TypeDeterminer td(&ctx, &mod); TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&as)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
Builder b(&mod); Builder b(&mod);
b.push_function(Function{}); 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%3 = OpConstant %2 2.4000001 %3 = OpConstant %2 2.4000001

View File

@ -18,10 +18,10 @@
#include <limits> #include <limits>
#include "src/ast/array_accessor_expression.h" #include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h" #include "src/ast/binary_expression.h"
#include "src/ast/binding_decoration.h" #include "src/ast/binding_decoration.h"
#include "src/ast/bitcast_expression.h"
#include "src/ast/block_statement.h" #include "src/ast/block_statement.h"
#include "src/ast/bool_literal.h" #include "src/ast/bool_literal.h"
#include "src/ast/break_statement.h" #include "src/ast/break_statement.h"
@ -177,12 +177,12 @@ bool GeneratorImpl::EmitExpression(ast::Expression* expr) {
if (expr->IsArrayAccessor()) { if (expr->IsArrayAccessor()) {
return EmitArrayAccessor(expr->AsArrayAccessor()); return EmitArrayAccessor(expr->AsArrayAccessor());
} }
if (expr->IsAs()) {
return EmitAs(expr->AsAs());
}
if (expr->IsBinary()) { if (expr->IsBinary()) {
return EmitBinary(expr->AsBinary()); return EmitBinary(expr->AsBinary());
} }
if (expr->IsBitcast()) {
return EmitBitcast(expr->AsBitcast());
}
if (expr->IsCall()) { if (expr->IsCall()) {
return EmitCall(expr->AsCall()); return EmitCall(expr->AsCall());
} }
@ -230,8 +230,8 @@ bool GeneratorImpl::EmitMemberAccessor(ast::MemberAccessorExpression* expr) {
return EmitExpression(expr->member()); return EmitExpression(expr->member());
} }
bool GeneratorImpl::EmitAs(ast::AsExpression* expr) { bool GeneratorImpl::EmitBitcast(ast::BitcastExpression* expr) {
out_ << "as<"; out_ << "bitcast<";
if (!EmitType(expr->type())) { if (!EmitType(expr->type())) {
return false; return false;
} }

View File

@ -62,10 +62,6 @@ class GeneratorImpl : public TextGenerator {
/// @param expr the expression to emit /// @param expr the expression to emit
/// @returns true if the array accessor was emitted /// @returns true if the array accessor was emitted
bool EmitArrayAccessor(ast::ArrayAccessorExpression* expr); 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 /// Handles an assignment statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully /// @returns true if the statement was emitted successfully
@ -74,6 +70,10 @@ class GeneratorImpl : public TextGenerator {
/// @param expr the binary expression /// @param expr the binary expression
/// @returns true if the expression was emitted, false otherwise /// @returns true if the expression was emitted, false otherwise
bool EmitBinary(ast::BinaryExpression* expr); 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 /// Handles a block statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully /// @returns true if the statement was emitted successfully

View File

@ -15,7 +15,7 @@
#include <memory> #include <memory>
#include "gtest/gtest.h" #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/identifier_expression.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/generator_impl.h"
@ -27,14 +27,14 @@ namespace {
using WgslGeneratorImplTest = testing::Test; using WgslGeneratorImplTest = testing::Test;
TEST_F(WgslGeneratorImplTest, EmitExpression_As) { TEST_F(WgslGeneratorImplTest, EmitExpression_Bitcast) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto id = std::make_unique<ast::IdentifierExpression>("id"); auto id = std::make_unique<ast::IdentifierExpression>("id");
ast::AsExpression as(&f32, std::move(id)); ast::BitcastExpression bitcast(&f32, std::move(id));
GeneratorImpl g; GeneratorImpl g;
ASSERT_TRUE(g.EmitExpression(&as)) << g.error(); ASSERT_TRUE(g.EmitExpression(&bitcast)) << g.error();
EXPECT_EQ(g.result(), "as<f32>(id)"); EXPECT_EQ(g.result(), "bitcast<f32>(id)");
} }
} // namespace } // namespace