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:
parent
b4fee2f824
commit
a7d498e060
14
BUILD.gn
14
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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Expression> expr)
|
||||
BitcastExpression::BitcastExpression(type::Type* type,
|
||||
std::unique_ptr<Expression> expr)
|
||||
: Expression(), type_(type), expr_(std::move(expr)) {}
|
||||
|
||||
AsExpression::AsExpression(const Source& source,
|
||||
BitcastExpression::BitcastExpression(const Source& source,
|
||||
type::Type* type,
|
||||
std::unique_ptr<Expression> expr)
|
||||
: Expression(source), type_(type), expr_(std::move(expr)) {}
|
||||
|
||||
AsExpression::AsExpression(AsExpression&&) = default;
|
||||
AsExpression::~AsExpression() = default;
|
||||
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;
|
|
@ -12,8 +12,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_AST_AS_EXPRESSION_H_
|
||||
#define SRC_AST_AS_EXPRESSION_H_
|
||||
#ifndef SRC_AST_BITCAST_EXPRESSION_H_
|
||||
#define SRC_AST_BITCAST_EXPRESSION_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
@ -25,25 +25,25 @@
|
|||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// An as expression
|
||||
class AsExpression : public Expression {
|
||||
/// A bitcast expression
|
||||
class BitcastExpression : public Expression {
|
||||
public:
|
||||
/// Constructor
|
||||
AsExpression();
|
||||
BitcastExpression();
|
||||
/// Constructor
|
||||
/// @param type the type
|
||||
/// @param expr the expr
|
||||
AsExpression(type::Type* type, std::unique_ptr<Expression> expr);
|
||||
BitcastExpression(type::Type* type, std::unique_ptr<Expression> expr);
|
||||
/// Constructor
|
||||
/// @param source the as expression source
|
||||
/// @param source the bitcast expression source
|
||||
/// @param type the type
|
||||
/// @param expr the expr
|
||||
AsExpression(const Source& source,
|
||||
BitcastExpression(const Source& source,
|
||||
type::Type* type,
|
||||
std::unique_ptr<Expression> expr);
|
||||
/// Move constructor
|
||||
AsExpression(AsExpression&&);
|
||||
~AsExpression() override;
|
||||
BitcastExpression(BitcastExpression&&);
|
||||
~BitcastExpression() override;
|
||||
|
||||
/// Sets the type
|
||||
/// @param type the type
|
||||
|
@ -57,8 +57,8 @@ 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<Expression> 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_
|
|
@ -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<IdentifierExpression>("expr");
|
||||
|
||||
auto* expr_ptr = expr.get();
|
||||
|
||||
AsExpression exp(&f32, std::move(expr));
|
||||
BitcastExpression exp(&f32, std::move(expr));
|
||||
ASSERT_EQ(exp.type(), &f32);
|
||||
ASSERT_EQ(exp.expr(), expr_ptr);
|
||||
}
|
||||
|
||||
TEST_F(AsExpressionTest, CreateWithSource) {
|
||||
TEST_F(BitcastExpressionTest, CreateWithSource) {
|
||||
type::F32Type f32;
|
||||
auto expr = std::make_unique<IdentifierExpression>("expr");
|
||||
|
||||
AsExpression exp(Source{20, 2}, &f32, std::move(expr));
|
||||
BitcastExpression exp(Source{20, 2}, &f32, std::move(expr));
|
||||
auto src = exp.source();
|
||||
EXPECT_EQ(src.line, 20u);
|
||||
EXPECT_EQ(src.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(AsExpressionTest, IsAs) {
|
||||
AsExpression exp;
|
||||
EXPECT_TRUE(exp.IsAs());
|
||||
TEST_F(BitcastExpressionTest, IsBitcast) {
|
||||
BitcastExpression exp;
|
||||
EXPECT_TRUE(exp.IsBitcast());
|
||||
}
|
||||
|
||||
TEST_F(AsExpressionTest, IsValid) {
|
||||
TEST_F(BitcastExpressionTest, IsValid) {
|
||||
type::F32Type f32;
|
||||
auto expr = std::make_unique<IdentifierExpression>("expr");
|
||||
|
||||
AsExpression exp(&f32, std::move(expr));
|
||||
BitcastExpression exp(&f32, std::move(expr));
|
||||
EXPECT_TRUE(exp.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(AsExpressionTest, IsValid_MissingType) {
|
||||
TEST_F(BitcastExpressionTest, IsValid_MissingType) {
|
||||
auto expr = std::make_unique<IdentifierExpression>("expr");
|
||||
|
||||
AsExpression exp;
|
||||
BitcastExpression exp;
|
||||
exp.set_expr(std::move(expr));
|
||||
EXPECT_FALSE(exp.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(AsExpressionTest, IsValid_MissingExpr) {
|
||||
TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
|
||||
type::F32Type f32;
|
||||
|
||||
AsExpression exp;
|
||||
BitcastExpression exp;
|
||||
exp.set_type(&f32);
|
||||
EXPECT_FALSE(exp.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(AsExpressionTest, IsValid_InvalidExpr) {
|
||||
TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) {
|
||||
type::F32Type f32;
|
||||
auto expr = std::make_unique<IdentifierExpression>("");
|
||||
AsExpression e(&f32, std::move(expr));
|
||||
BitcastExpression e(&f32, std::move(expr));
|
||||
EXPECT_FALSE(e.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(AsExpressionTest, ToStr) {
|
||||
TEST_F(BitcastExpressionTest, ToStr) {
|
||||
type::F32Type f32;
|
||||
auto expr = std::make_unique<IdentifierExpression>("expr");
|
||||
|
||||
AsExpression exp(&f32, std::move(expr));
|
||||
BitcastExpression exp(&f32, std::move(expr));
|
||||
std::ostringstream out;
|
||||
exp.to_str(out, 2);
|
||||
|
||||
EXPECT_EQ(out.str(), R"( As<__f32>{
|
||||
EXPECT_EQ(out.str(), R"( Bitcast<__f32>{
|
||||
Identifier{expr}
|
||||
}
|
||||
)");
|
|
@ -17,8 +17,8 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "src/ast/array_accessor_expression.h"
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/bitcast_expression.h"
|
||||
#include "src/ast/call_expression.h"
|
||||
#include "src/ast/cast_expression.h"
|
||||
#include "src/ast/constructor_expression.h"
|
||||
|
@ -45,7 +45,7 @@ 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<const ArrayAccessorExpression*>(this);
|
||||
}
|
||||
|
||||
const AsExpression* Expression::AsAs() const {
|
||||
assert(IsAs());
|
||||
return static_cast<const AsExpression*>(this);
|
||||
const BitcastExpression* Expression::AsBitcast() const {
|
||||
assert(IsBitcast());
|
||||
return static_cast<const BitcastExpression*>(this);
|
||||
}
|
||||
|
||||
const BinaryExpression* Expression::AsBinary() const {
|
||||
|
@ -126,9 +126,9 @@ ArrayAccessorExpression* Expression::AsArrayAccessor() {
|
|||
return static_cast<ArrayAccessorExpression*>(this);
|
||||
}
|
||||
|
||||
AsExpression* Expression::AsAs() {
|
||||
assert(IsAs());
|
||||
return static_cast<AsExpression*>(this);
|
||||
BitcastExpression* Expression::AsBitcast() {
|
||||
assert(IsBitcast());
|
||||
return static_cast<BitcastExpression*>(this);
|
||||
}
|
||||
|
||||
BinaryExpression* Expression::AsBinary() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,7 +361,7 @@ std::unique_ptr<Expression> VertexPullingTransform::AccessI32(
|
|||
uint32_t buffer,
|
||||
std::unique_ptr<Expression> pos) {
|
||||
// as<T> reinterprets bits
|
||||
return std::make_unique<AsExpression>(GetI32Type(),
|
||||
return std::make_unique<BitcastExpression>(GetI32Type(),
|
||||
AccessU32(buffer, std::move(pos)));
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,7 @@ std::unique_ptr<Expression> VertexPullingTransform::AccessF32(
|
|||
uint32_t buffer,
|
||||
std::unique_ptr<Expression> pos) {
|
||||
// as<T> reinterprets bits
|
||||
return std::make_unique<AsExpression>(GetF32Type(),
|
||||
return std::make_unique<BitcastExpression>(GetF32Type(),
|
||||
AccessU32(buffer, std::move(pos)));
|
||||
}
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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<ast::AsExpression>(
|
||||
return {ast_type, std::make_unique<ast::BitcastExpression>(
|
||||
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<ast::AsExpression>(
|
||||
return {requested_type, std::make_unique<ast::BitcastExpression>(
|
||||
requested_type, std::move(result.expr))};
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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}
|
||||
)
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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<ast::AsExpression>(
|
||||
return {unsigned_ty, std::make_unique<ast::BitcastExpression>(
|
||||
unsigned_ty, std::move(expr.expr))};
|
||||
}
|
||||
} else if (requires_signed) {
|
||||
auto* signed_ty = signed_type_for_[type];
|
||||
if (signed_ty != nullptr) {
|
||||
// Conversion is required.
|
||||
return {signed_ty, std::make_unique<ast::AsExpression>(
|
||||
return {signed_ty, std::make_unique<ast::BitcastExpression>(
|
||||
signed_ty, std::move(expr.expr))};
|
||||
}
|
||||
}
|
||||
|
@ -1373,8 +1373,8 @@ TypedExpression ParserImpl::RectifyForcedResultType(
|
|||
if ((forced_result_ty == nullptr) || (forced_result_ty == expr.type)) {
|
||||
return expr;
|
||||
}
|
||||
return {expr.type,
|
||||
std::make_unique<ast::AsExpression>(expr.type, std::move(expr.expr))};
|
||||
return {expr.type, std::make_unique<ast::BitcastExpression>(
|
||||
expr.type, std::move(expr.expr))};
|
||||
}
|
||||
|
||||
bool ParserImpl::EmitFunctions() {
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
#include <vector>
|
||||
|
||||
#include "src/ast/array_accessor_expression.h"
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/binding_decoration.h"
|
||||
#include "src/ast/bitcast_expression.h"
|
||||
#include "src/ast/bool_literal.h"
|
||||
#include "src/ast/break_statement.h"
|
||||
#include "src/ast/builtin_decoration.h"
|
||||
|
@ -2790,7 +2790,7 @@ std::unique_ptr<ast::Expression> ParserImpl::primary_expression() {
|
|||
return paren;
|
||||
}
|
||||
|
||||
if (t.IsCast() || t.IsAs()) {
|
||||
if (t.IsCast() || t.IsBitcast()) {
|
||||
auto src = t;
|
||||
|
||||
next(); // Consume the peek
|
||||
|
@ -2827,7 +2827,7 @@ std::unique_ptr<ast::Expression> ParserImpl::primary_expression() {
|
|||
return std::make_unique<ast::CastExpression>(source, type,
|
||||
std::move(params));
|
||||
} else {
|
||||
return std::make_unique<ast::AsExpression>(source, type,
|
||||
return std::make_unique<ast::BitcastExpression>(source, type,
|
||||
std::move(params));
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ast::type::F32Type>());
|
||||
|
||||
auto* p = parser("as<f32>(1)");
|
||||
auto* p = parser("bitcast<f32>(1)");
|
||||
auto e = p->primary_expression();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_NE(e, nullptr);
|
||||
ASSERT_TRUE(e->IsAs());
|
||||
ASSERT_TRUE(e->IsBitcast());
|
||||
|
||||
auto* c = e->AsAs();
|
||||
auto* c = e->AsBitcast();
|
||||
ASSERT_EQ(c->type(), f32_type);
|
||||
|
||||
ASSERT_TRUE(c->expr()->IsConstructor());
|
||||
ASSERT_TRUE(c->expr()->AsConstructor()->IsScalarConstructor());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, PrimaryExpression_As_MissingGreaterThan) {
|
||||
auto* p = parser("as<f32(1)");
|
||||
TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingGreaterThan) {
|
||||
auto* p = parser("bitcast<f32(1)");
|
||||
auto e = p->primary_expression();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:7: missing > for as expression");
|
||||
EXPECT_EQ(p->error(), "1:12: missing > for bitcast expression");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, PrimaryExpression_As_MissingType) {
|
||||
auto* p = parser("as<>(1)");
|
||||
TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingType) {
|
||||
auto* p = parser("bitcast<>(1)");
|
||||
auto e = p->primary_expression();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:4: missing type for as expression");
|
||||
EXPECT_EQ(p->error(), "1:9: missing type for bitcast expression");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, PrimaryExpression_As_InvalidType) {
|
||||
auto* p = parser("as<invalid>(1)");
|
||||
TEST_F(ParserImplTest, PrimaryExpression_Bitcast_InvalidType) {
|
||||
auto* p = parser("bitcast<invalid>(1)");
|
||||
auto e = p->primary_expression();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:4: unknown type alias 'invalid'");
|
||||
EXPECT_EQ(p->error(), "1:9: unknown type alias 'invalid'");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, PrimaryExpression_As_MissingLeftParen) {
|
||||
auto* p = parser("as<f32>1)");
|
||||
TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingLeftParen) {
|
||||
auto* p = parser("bitcast<f32>1)");
|
||||
auto e = p->primary_expression();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:8: expected (");
|
||||
EXPECT_EQ(p->error(), "1:13: expected (");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, PrimaryExpression_As_MissingRightParen) {
|
||||
auto* p = parser("as<f32>(1");
|
||||
TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingRightParen) {
|
||||
auto* p = parser("bitcast<f32>(1");
|
||||
auto e = p->primary_expression();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:10: expected )");
|
||||
EXPECT_EQ(p->error(), "1:15: expected )");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, PrimaryExpression_As_MissingExpression) {
|
||||
auto* p = parser("as<f32>()");
|
||||
TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingExpression) {
|
||||
auto* p = parser("bitcast<f32>()");
|
||||
auto e = p->primary_expression();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:9: unable to parse expression");
|
||||
EXPECT_EQ(p->error(), "1:14: unable to parse expression");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, PrimaryExpression_As_InvalidExpression) {
|
||||
auto* p = parser("as<f32>(if (a) {})");
|
||||
TEST_F(ParserImplTest, PrimaryExpression_bitcast_InvalidExpression) {
|
||||
auto* p = parser("bitcast<f32>(if (a) {})");
|
||||
auto e = p->primary_expression();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:9: unable to parse expression");
|
||||
EXPECT_EQ(p->error(), "1:14: unable to parse expression");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
#include <vector>
|
||||
|
||||
#include "src/ast/array_accessor_expression.h"
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/assignment_statement.h"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/bitcast_expression.h"
|
||||
#include "src/ast/block_statement.h"
|
||||
#include "src/ast/break_statement.h"
|
||||
#include "src/ast/call_expression.h"
|
||||
|
@ -296,12 +296,12 @@ 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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<ast::IdentifierExpression>("name"));
|
||||
ast::BitcastExpression bitcast(
|
||||
&f32, std::make_unique<ast::IdentifierExpression>("name"));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineResultType(&as));
|
||||
ASSERT_NE(as.result_type(), nullptr);
|
||||
EXPECT_TRUE(as.result_type()->IsF32());
|
||||
EXPECT_TRUE(td()->DetermineResultType(&bitcast));
|
||||
ASSERT_NE(bitcast.result_type(), nullptr);
|
||||
EXPECT_TRUE(bitcast.result_type()->IsF32());
|
||||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_Call) {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
#include <sstream>
|
||||
|
||||
#include "src/ast/array_accessor_expression.h"
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/assignment_statement.h"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/bitcast_expression.h"
|
||||
#include "src/ast/bool_literal.h"
|
||||
#include "src/ast/call_expression.h"
|
||||
#include "src/ast/call_statement.h"
|
||||
|
@ -238,12 +238,12 @@ bool GeneratorImpl::EmitArrayAccessor(std::ostream& pre,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitAs(std::ostream& pre,
|
||||
bool GeneratorImpl::EmitBitcast(std::ostream& pre,
|
||||
std::ostream& out,
|
||||
ast::AsExpression* expr) {
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/assignment_statement.h"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/bitcast_expression.h"
|
||||
#include "src/ast/call_expression.h"
|
||||
#include "src/ast/call_statement.h"
|
||||
#include "src/ast/else_statement.h"
|
||||
|
@ -295,7 +295,7 @@ bool a = (_tint_tmp_0);
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Binary, As_WithLogical) {
|
||||
TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) {
|
||||
// as<i32>(a && (b || c))
|
||||
ast::type::I32Type i32;
|
||||
|
||||
|
@ -303,7 +303,7 @@ TEST_F(HlslGeneratorImplTest_Binary, As_WithLogical) {
|
|||
auto b = std::make_unique<ast::IdentifierExpression>("b");
|
||||
auto c = std::make_unique<ast::IdentifierExpression>("c");
|
||||
|
||||
ast::AsExpression expr(
|
||||
ast::BitcastExpression expr(
|
||||
&i32, std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLogicalAnd, std::move(a),
|
||||
std::make_unique<ast::BinaryExpression>(
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/bitcast_expression.h"
|
||||
#include "src/ast/identifier_expression.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
|
@ -27,32 +27,32 @@ namespace 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<ast::IdentifierExpression>("id");
|
||||
ast::AsExpression as(&f32, std::move(id));
|
||||
ast::BitcastExpression bitcast(&f32, std::move(id));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &as)) << gen().error();
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &bitcast)) << gen().error();
|
||||
EXPECT_EQ(result(), "asfloat(id)");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_As, EmitExpression_As_Int) {
|
||||
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
|
||||
ast::type::I32Type i32;
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("id");
|
||||
ast::AsExpression as(&i32, std::move(id));
|
||||
ast::BitcastExpression bitcast(&i32, std::move(id));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &as)) << gen().error();
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &bitcast)) << gen().error();
|
||||
EXPECT_EQ(result(), "asint(id)");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_As, EmitExpression_As_Uint) {
|
||||
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
|
||||
ast::type::U32Type u32;
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("id");
|
||||
ast::AsExpression as(&u32, std::move(id));
|
||||
ast::BitcastExpression bitcast(&u32, std::move(id));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &as)) << gen().error();
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &bitcast)) << gen().error();
|
||||
EXPECT_EQ(result(), "asuint(id)");
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <memory>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/bitcast_expression.h"
|
||||
#include "src/ast/identifier_expression.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
|
@ -28,14 +28,14 @@ namespace {
|
|||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_As) {
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
|
||||
ast::type::F32Type f32;
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("id");
|
||||
ast::AsExpression as(&f32, std::move(id));
|
||||
ast::BitcastExpression bitcast(&f32, std::move(id));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&as)) << g.error();
|
||||
ASSERT_TRUE(g.EmitExpression(&bitcast)) << g.error();
|
||||
EXPECT_EQ(g.result(), "as_type<float>(id)");
|
||||
}
|
||||
|
|
@ -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)});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<ast::ScalarConstructorExpression>(
|
||||
ast::BitcastExpression bitcast(
|
||||
&u32, std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&as)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateAsExpression(&as), 1u);
|
||||
EXPECT_EQ(b.GenerateBitcastExpression(&bitcast), 1u);
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
|
||||
%3 = OpTypeFloat 32
|
||||
|
@ -57,21 +57,21 @@ TEST_F(BuilderTest, As) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest, As_DuplicateType) {
|
||||
TEST_F(BuilderTest, Bitcast_DuplicateType) {
|
||||
ast::type::F32Type f32;
|
||||
|
||||
ast::AsExpression as(&f32,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
ast::BitcastExpression bitcast(
|
||||
&f32, std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&as)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateAsExpression(&as), 1u);
|
||||
EXPECT_EQ(b.GenerateBitcastExpression(&bitcast), 1u);
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%3 = OpConstant %2 2.4000001
|
|
@ -18,10 +18,10 @@
|
|||
#include <limits>
|
||||
|
||||
#include "src/ast/array_accessor_expression.h"
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/assignment_statement.h"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/binding_decoration.h"
|
||||
#include "src/ast/bitcast_expression.h"
|
||||
#include "src/ast/block_statement.h"
|
||||
#include "src/ast/bool_literal.h"
|
||||
#include "src/ast/break_statement.h"
|
||||
|
@ -177,12 +177,12 @@ 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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <memory>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/bitcast_expression.h"
|
||||
#include "src/ast/identifier_expression.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/writer/wgsl/generator_impl.h"
|
||||
|
@ -27,14 +27,14 @@ namespace {
|
|||
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, EmitExpression_As) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitExpression_Bitcast) {
|
||||
ast::type::F32Type f32;
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("id");
|
||||
ast::AsExpression as(&f32, std::move(id));
|
||||
ast::BitcastExpression bitcast(&f32, std::move(id));
|
||||
|
||||
GeneratorImpl g;
|
||||
ASSERT_TRUE(g.EmitExpression(&as)) << g.error();
|
||||
EXPECT_EQ(g.result(), "as<f32>(id)");
|
||||
ASSERT_TRUE(g.EmitExpression(&bitcast)) << g.error();
|
||||
EXPECT_EQ(g.result(), "bitcast<f32>(id)");
|
||||
}
|
||||
|
||||
} // namespace
|
Loading…
Reference in New Issue