Add Symbol to Variable.
This CL adds a Symbol to the Variable AST node along side the name. The name will be removed in a future CL. Change-Id: I1c05e5595392b1c4a0afa82387d97b2b4472bade Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35881 Commit-Queue: dan sinclair <dsinclair@chromium.org> Auto-Submit: dan sinclair <dsinclair@chromium.org> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
b5839939e1
commit
a57f842be9
|
@ -40,8 +40,8 @@ Variable* Builder::Var(const std::string& name,
|
|||
type::Type* type,
|
||||
Expression* constructor,
|
||||
VariableDecorationList decorations) {
|
||||
auto* var =
|
||||
create<Variable>(name, storage, type, false, constructor, decorations);
|
||||
auto* var = create<Variable>(mod->RegisterSymbol(name), name, storage, type,
|
||||
false, constructor, decorations);
|
||||
OnVariableBuilt(var);
|
||||
return var;
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ Variable* Builder::Var(const Source& source,
|
|||
type::Type* type,
|
||||
Expression* constructor,
|
||||
VariableDecorationList decorations) {
|
||||
auto* var = create<Variable>(source, name, storage, type, false, constructor,
|
||||
decorations);
|
||||
auto* var = create<Variable>(source, mod->RegisterSymbol(name), name, storage,
|
||||
type, false, constructor, decorations);
|
||||
OnVariableBuilt(var);
|
||||
return var;
|
||||
}
|
||||
|
@ -69,8 +69,8 @@ Variable* Builder::Const(const std::string& name,
|
|||
type::Type* type,
|
||||
Expression* constructor,
|
||||
VariableDecorationList decorations) {
|
||||
auto* var =
|
||||
create<Variable>(name, storage, type, true, constructor, decorations);
|
||||
auto* var = create<Variable>(mod->RegisterSymbol(name), name, storage, type,
|
||||
true, constructor, decorations);
|
||||
OnVariableBuilt(var);
|
||||
return var;
|
||||
}
|
||||
|
@ -81,8 +81,8 @@ Variable* Builder::Const(const Source& source,
|
|||
type::Type* type,
|
||||
Expression* constructor,
|
||||
VariableDecorationList decorations) {
|
||||
auto* var = create<Variable>(source, name, storage, type, true, constructor,
|
||||
decorations);
|
||||
auto* var = create<Variable>(source, mod->RegisterSymbol(name), name, storage,
|
||||
type, true, constructor, decorations);
|
||||
OnVariableBuilt(var);
|
||||
return var;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace tint {
|
|||
namespace ast {
|
||||
|
||||
Variable::Variable(const Source& source,
|
||||
const Symbol& sym,
|
||||
const std::string& name,
|
||||
StorageClass sc,
|
||||
type::Type* type,
|
||||
|
@ -33,6 +34,7 @@ Variable::Variable(const Source& source,
|
|||
Expression* constructor,
|
||||
VariableDecorationList decorations)
|
||||
: Base(source),
|
||||
symbol_(sym),
|
||||
name_(name),
|
||||
type_(type),
|
||||
is_const_(is_const),
|
||||
|
@ -82,13 +84,14 @@ uint32_t Variable::constant_id() const {
|
|||
}
|
||||
|
||||
Variable* Variable::Clone(CloneContext* ctx) const {
|
||||
return ctx->mod->create<Variable>(
|
||||
ctx->Clone(source()), name(), storage_class(), ctx->Clone(type()),
|
||||
is_const_, ctx->Clone(constructor()), ctx->Clone(decorations_));
|
||||
return ctx->mod->create<Variable>(ctx->Clone(source()), ctx->Clone(symbol_),
|
||||
name(), storage_class(), ctx->Clone(type()),
|
||||
is_const_, ctx->Clone(constructor()),
|
||||
ctx->Clone(decorations_));
|
||||
}
|
||||
|
||||
bool Variable::IsValid() const {
|
||||
if (name_.length() == 0) {
|
||||
if (name_.length() == 0 || !symbol_.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
if (type_ == nullptr) {
|
||||
|
@ -102,7 +105,7 @@ bool Variable::IsValid() const {
|
|||
|
||||
void Variable::info_to_str(std::ostream& out, size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << name_ << std::endl;
|
||||
out << symbol_.to_str() << std::endl;
|
||||
make_indent(out, indent);
|
||||
out << storage_class_ << std::endl;
|
||||
make_indent(out, indent);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "src/ast/storage_class.h"
|
||||
#include "src/ast/type/type.h"
|
||||
#include "src/ast/variable_decoration.h"
|
||||
#include "src/symbol.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -81,6 +82,7 @@ class Variable : public Castable<Variable, Node> {
|
|||
public:
|
||||
/// Create a variable
|
||||
/// @param source the variable source
|
||||
/// @param sym the variable symbol
|
||||
/// @param name the variables name
|
||||
/// @param sc the variable storage class
|
||||
/// @param type the value type
|
||||
|
@ -88,6 +90,7 @@ class Variable : public Castable<Variable, Node> {
|
|||
/// @param constructor the constructor expression
|
||||
/// @param decorations the variable decorations
|
||||
Variable(const Source& source,
|
||||
const Symbol& sym,
|
||||
const std::string& name,
|
||||
StorageClass sc,
|
||||
type::Type* type,
|
||||
|
@ -99,6 +102,8 @@ class Variable : public Castable<Variable, Node> {
|
|||
|
||||
~Variable() override;
|
||||
|
||||
/// @returns the variable symbol
|
||||
const Symbol& symbol() const { return symbol_; }
|
||||
/// @returns the variable name
|
||||
const std::string& name() const { return name_; }
|
||||
|
||||
|
@ -141,7 +146,7 @@ class Variable : public Castable<Variable, Node> {
|
|||
/// @return the newly cloned node
|
||||
Variable* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// @returns true if the name and path are both present
|
||||
/// @returns true if the variable is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
|
@ -162,6 +167,7 @@ class Variable : public Castable<Variable, Node> {
|
|||
private:
|
||||
Variable(const Variable&) = delete;
|
||||
|
||||
Symbol const symbol_;
|
||||
std::string const name_;
|
||||
// The value type if a const or formal paramter, and the store type if a var
|
||||
type::Type* const type_;
|
||||
|
|
|
@ -72,7 +72,7 @@ TEST_F(VariableDeclStatementTest, ToStr) {
|
|||
create<VariableDeclStatement>(Source{Source::Location{20, 2}}, var);
|
||||
std::ostringstream out;
|
||||
stmt->to_str(out, 2);
|
||||
EXPECT_EQ(out.str(), R"( VariableDeclStatement{
|
||||
EXPECT_EQ(demangle(out.str()), R"( VariableDeclStatement{
|
||||
Variable{
|
||||
a
|
||||
none
|
||||
|
|
|
@ -29,6 +29,7 @@ using VariableTest = TestHelper;
|
|||
TEST_F(VariableTest, Creation) {
|
||||
auto* v = Var("my_var", StorageClass::kFunction, ty.i32);
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->name(), "my_var");
|
||||
EXPECT_EQ(v->storage_class(), StorageClass::kFunction);
|
||||
EXPECT_EQ(v->type(), ty.i32);
|
||||
|
@ -43,6 +44,7 @@ TEST_F(VariableTest, CreationWithSource) {
|
|||
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}},
|
||||
"i", StorageClass::kPrivate, ty.f32, nullptr, VariableDecorationList{});
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->name(), "i");
|
||||
EXPECT_EQ(v->storage_class(), StorageClass::kPrivate);
|
||||
EXPECT_EQ(v->type(), ty.f32);
|
||||
|
@ -58,6 +60,7 @@ TEST_F(VariableTest, CreationEmpty) {
|
|||
"a_var", StorageClass::kWorkgroup, ty.i32, nullptr,
|
||||
VariableDecorationList{});
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->name(), "a_var");
|
||||
EXPECT_EQ(v->storage_class(), StorageClass::kWorkgroup);
|
||||
EXPECT_EQ(v->type(), ty.i32);
|
||||
|
@ -78,7 +81,7 @@ TEST_F(VariableTest, IsValid_WithConstructor) {
|
|||
EXPECT_TRUE(v->IsValid());
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, IsValid_MissinName) {
|
||||
TEST_F(VariableTest, IsValid_MissingSymbol) {
|
||||
auto* v = Var("", StorageClass::kNone, ty.i32);
|
||||
EXPECT_FALSE(v->IsValid());
|
||||
}
|
||||
|
@ -104,7 +107,7 @@ TEST_F(VariableTest, to_str) {
|
|||
ast::VariableDecorationList{});
|
||||
std::ostringstream out;
|
||||
v->to_str(out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Variable{
|
||||
EXPECT_EQ(demangle(out.str()), R"( Variable{
|
||||
my_var
|
||||
function
|
||||
__f32
|
||||
|
|
|
@ -2249,6 +2249,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
|
|||
// Declare the guard variable just before the "if", initialized to true.
|
||||
auto* guard_var =
|
||||
create<ast::Variable>(Source{}, // source
|
||||
ast_module_.RegisterSymbol(guard_name), // symbol
|
||||
guard_name, // name
|
||||
ast::StorageClass::kFunction, // storage_class
|
||||
parser_impl_.Bool(), // type
|
||||
|
@ -2777,6 +2778,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
|
|||
assert(!phi_var_name.empty());
|
||||
auto* var = create<ast::Variable>(
|
||||
Source{}, // source
|
||||
ast_module_.RegisterSymbol(phi_var_name), // symbol
|
||||
phi_var_name, // name
|
||||
ast::StorageClass::kFunction, // storage_class
|
||||
parser_impl_.ConvertType(def_inst->type_id()), // type
|
||||
|
|
|
@ -216,9 +216,10 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_ast_str = p->get_module().to_str();
|
||||
const auto module_ast_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_ast_str, HasSubstr(R"(Module{
|
||||
Function tint_symbol_3 -> __u32
|
||||
Function x_50 -> __u32
|
||||
(
|
||||
VariableConst{
|
||||
x_51
|
||||
|
@ -235,15 +236,14 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
|
|||
Return{
|
||||
{
|
||||
Binary[not set]{
|
||||
Identifier[not set]{tint_symbol_1}
|
||||
Identifier[not set]{x_51}
|
||||
add
|
||||
Identifier[not set]{tint_symbol_2}
|
||||
Identifier[not set]{x_52}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Function )" + p->get_module().GetSymbol("x_100").to_str() +
|
||||
R"( -> __void
|
||||
Function x_100 -> __void
|
||||
()
|
||||
{
|
||||
VariableDeclStatement{
|
||||
|
@ -253,7 +253,7 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
|
|||
__u32
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{tint_symbol_3}
|
||||
Identifier[not set]{x_50}
|
||||
(
|
||||
ScalarConstructor[not set]{42}
|
||||
ScalarConstructor[not set]{84}
|
||||
|
|
|
@ -59,10 +59,9 @@ TEST_F(SpvParserTest, Emit_VoidFunctionWithoutParams) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
|
||||
EXPECT_TRUE(fe.Emit());
|
||||
auto got = p->get_module().to_str();
|
||||
auto expect = R"(Module{
|
||||
Function )" + p->get_module().GetSymbol("x_100").to_str() +
|
||||
R"( -> __void
|
||||
auto got = Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
std::string expect = R"(Module{
|
||||
Function x_100 -> __void
|
||||
()
|
||||
{
|
||||
Return{}
|
||||
|
@ -84,10 +83,9 @@ TEST_F(SpvParserTest, Emit_NonVoidResultType) {
|
|||
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
|
||||
EXPECT_TRUE(fe.Emit());
|
||||
|
||||
auto got = p->get_module().to_str();
|
||||
auto expect = R"(Module{
|
||||
Function )" + p->get_module().GetSymbol("x_100").to_str() +
|
||||
R"( -> __f32
|
||||
auto got = Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
std::string expect = R"(Module{
|
||||
Function x_100 -> __f32
|
||||
()
|
||||
{
|
||||
Return{
|
||||
|
@ -117,10 +115,9 @@ TEST_F(SpvParserTest, Emit_MixedParamTypes) {
|
|||
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
|
||||
EXPECT_TRUE(fe.Emit());
|
||||
|
||||
auto got = p->get_module().to_str();
|
||||
auto expect = R"(Module{
|
||||
Function )" + p->get_module().GetSymbol("x_100").to_str() +
|
||||
R"( -> __void
|
||||
auto got = Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
std::string expect = R"(Module{
|
||||
Function x_100 -> __void
|
||||
(
|
||||
VariableConst{
|
||||
a
|
||||
|
@ -162,10 +159,9 @@ TEST_F(SpvParserTest, Emit_GenerateParamNames) {
|
|||
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
|
||||
EXPECT_TRUE(fe.Emit());
|
||||
|
||||
auto got = p->get_module().to_str();
|
||||
auto expect = R"(Module{
|
||||
Function )" + p->get_module().GetSymbol("x_100").to_str() +
|
||||
R"( -> __void
|
||||
auto got = Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
std::string expect = R"(Module{
|
||||
Function x_100 -> __void
|
||||
(
|
||||
VariableConst{
|
||||
x_14
|
||||
|
|
|
@ -1297,8 +1297,10 @@ ast::Variable* ParserImpl::MakeVariable(
|
|||
}
|
||||
}
|
||||
|
||||
std::string name = namer_.Name(id);
|
||||
return create<ast::Variable>(Source{}, // source
|
||||
namer_.Name(id), // name
|
||||
ast_module_.RegisterSymbol(name), // symbol
|
||||
name, // name
|
||||
sc, // storage_class
|
||||
type, // type
|
||||
is_const, // is_const
|
||||
|
|
|
@ -267,10 +267,10 @@ TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) {
|
|||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
const auto module_ast =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function )" + p->get_module().GetSymbol("ret_float").to_str() +
|
||||
R"( -> __f32
|
||||
Function ret_float -> __f32
|
||||
()
|
||||
{
|
||||
Return{
|
||||
|
@ -297,10 +297,10 @@ TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) {
|
|||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
const auto module_ast =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function )" + p->get_module().GetSymbol("mixed_params").to_str() +
|
||||
R"( -> __void
|
||||
Function mixed_params -> __void
|
||||
(
|
||||
VariableConst{
|
||||
a
|
||||
|
@ -337,10 +337,10 @@ TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) {
|
|||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
const auto module_ast =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function )" + p->get_module().GetSymbol("mixed_params").to_str() +
|
||||
R"( -> __void
|
||||
Function mixed_params -> __void
|
||||
(
|
||||
VariableConst{
|
||||
x_14
|
||||
|
|
|
@ -141,7 +141,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_AnonWorkgroupVar) {
|
|||
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
Variable{
|
||||
x_52
|
||||
|
@ -160,7 +161,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_NamedWorkgroupVar) {
|
|||
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
Variable{
|
||||
the_counter
|
||||
|
@ -179,7 +181,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_PrivateVar) {
|
|||
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
Variable{
|
||||
my_own_private_idaho
|
||||
|
@ -198,7 +201,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_BuiltinVertexIndex) {
|
|||
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
Variable{
|
||||
Decorations{
|
||||
|
@ -248,7 +252,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_BuiltinPosition_MapsToModuleScopeVec4Var) {
|
|||
EXPECT_EQ(position_info.pointer_type_id, 11u);
|
||||
EXPECT_EQ(position_info.storage_class, SpvStorageClassOutput);
|
||||
EXPECT_EQ(position_info.per_vertex_var_id, 1u);
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
Variable{
|
||||
Decorations{
|
||||
|
@ -718,7 +723,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ScalarInitializers) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_1
|
||||
private
|
||||
|
@ -775,7 +781,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ScalarNullInitializers) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_1
|
||||
private
|
||||
|
@ -824,7 +831,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ScalarUndefInitializers) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_1
|
||||
private
|
||||
|
@ -868,7 +876,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -891,7 +900,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorBoolNullInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -914,7 +924,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorBoolUndefInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -937,7 +948,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorUintNullInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -960,7 +972,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorUintUndefInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -983,7 +996,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorIntNullInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -1006,7 +1020,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorIntUndefInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -1029,7 +1044,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorFloatNullInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -1052,7 +1068,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorFloatUndefInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -1081,7 +1098,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_MatrixInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -1117,7 +1135,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_MatrixNullInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -1153,7 +1172,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_MatrixUndefInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -1190,7 +1210,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ArrayInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -1213,7 +1234,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ArrayNullInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -1236,7 +1258,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ArrayUndefInitializer) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
|
||||
x_200
|
||||
private
|
||||
|
@ -1353,7 +1376,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_LocationDecoration_Valid) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
Variable{
|
||||
Decorations{
|
||||
|
@ -1716,7 +1740,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ScalarSpecConstant_DeclareConst_True) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
VariableConst{
|
||||
Decorations{
|
||||
|
@ -1741,7 +1766,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ScalarSpecConstant_DeclareConst_False) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
VariableConst{
|
||||
Decorations{
|
||||
|
@ -1766,7 +1792,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ScalarSpecConstant_DeclareConst_U32) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
VariableConst{
|
||||
Decorations{
|
||||
|
@ -1791,7 +1818,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ScalarSpecConstant_DeclareConst_I32) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
VariableConst{
|
||||
Decorations{
|
||||
|
@ -1816,7 +1844,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ScalarSpecConstant_DeclareConst_F32) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
VariableConst{
|
||||
Decorations{
|
||||
|
@ -1842,7 +1871,8 @@ TEST_F(SpvParserTest,
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->module().to_str();
|
||||
const auto module_str =
|
||||
Demangler().Demangle(p->get_module(), p->get_module().to_str());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
VariableConst{
|
||||
myconst
|
||||
|
|
|
@ -432,6 +432,7 @@ Maybe<ast::Variable*> ParserImpl::global_variable_decl(
|
|||
}
|
||||
|
||||
return create<ast::Variable>(decl->source, // source
|
||||
module_.RegisterSymbol(decl->name), // symbol
|
||||
decl->name, // name
|
||||
decl->storage_class, // storage_class
|
||||
decl->type, // type
|
||||
|
@ -460,6 +461,7 @@ Maybe<ast::Variable*> ParserImpl::global_constant_decl() {
|
|||
return Failure::kErrored;
|
||||
|
||||
return create<ast::Variable>(decl->source, // source
|
||||
module_.RegisterSymbol(decl->name), // symbol
|
||||
decl->name, // name
|
||||
ast::StorageClass::kNone, // storage_class
|
||||
decl->type, // type
|
||||
|
@ -1354,6 +1356,7 @@ Expect<ast::VariableList> ParserImpl::expect_param_list() {
|
|||
for (;;) {
|
||||
auto* var =
|
||||
create<ast::Variable>(decl->source, // source
|
||||
module_.RegisterSymbol(decl->name), // symbol
|
||||
decl->name, // name
|
||||
ast::StorageClass::kNone, // storage_class
|
||||
decl->type, // type
|
||||
|
@ -1625,6 +1628,7 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
|
|||
|
||||
auto* var =
|
||||
create<ast::Variable>(decl->source, // source
|
||||
module_.RegisterSymbol(decl->name), // symbol
|
||||
decl->name, // name
|
||||
ast::StorageClass::kNone, // storage_class
|
||||
decl->type, // type
|
||||
|
@ -1654,6 +1658,7 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
|
|||
|
||||
auto* var =
|
||||
create<ast::Variable>(decl->source, // source
|
||||
module_.RegisterSymbol(decl->name), // symbol
|
||||
decl->name, // name
|
||||
decl->storage_class, // storage_class
|
||||
decl->type, // type
|
||||
|
|
|
@ -14,13 +14,14 @@
|
|||
#include "src/scope_stack.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/builder.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/variable.h"
|
||||
|
||||
namespace tint {
|
||||
namespace {
|
||||
|
||||
using ScopeStackTest = testing::Test;
|
||||
class ScopeStackTest : public ast::BuilderWithModule, public testing::Test {};
|
||||
|
||||
TEST_F(ScopeStackTest, Global) {
|
||||
ScopeStack<uint32_t> s;
|
||||
|
@ -32,12 +33,9 @@ TEST_F(ScopeStackTest, Global) {
|
|||
}
|
||||
|
||||
TEST_F(ScopeStackTest, Global_SetWithPointer) {
|
||||
ast::type::F32 f32;
|
||||
ast::Variable v(Source{}, "my_var", ast::StorageClass::kNone, &f32, false,
|
||||
nullptr, ast::VariableDecorationList{});
|
||||
|
||||
auto* v = Var("my_var", ast::StorageClass::kNone, ty.f32);
|
||||
ScopeStack<ast::Variable*> s;
|
||||
s.set_global("var", &v);
|
||||
s.set_global("var", v);
|
||||
|
||||
ast::Variable* v2 = nullptr;
|
||||
EXPECT_TRUE(s.get("var", &v2));
|
||||
|
|
|
@ -52,6 +52,7 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
|
|||
// Declare the pointsize builtin output variable.
|
||||
auto* pointsize_var = out.module.create<ast::Variable>(
|
||||
Source{}, // source
|
||||
out.module.RegisterSymbol(kPointSizeVar), // symbol
|
||||
kPointSizeVar, // name
|
||||
ast::StorageClass::kOutput, // storage_class
|
||||
f32, // type
|
||||
|
|
|
@ -66,6 +66,7 @@ ast::Variable* clone_variable_with_new_name(ast::CloneContext* ctx,
|
|||
std::string new_name) {
|
||||
return ctx->mod->create<ast::Variable>(
|
||||
ctx->Clone(in->source()), // source
|
||||
ctx->mod->RegisterSymbol(new_name), // symbol
|
||||
new_name, // name
|
||||
in->storage_class(), // storage_class
|
||||
ctx->Clone(in->type()), // type
|
||||
|
@ -227,6 +228,7 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) {
|
|||
|
||||
auto* idx_var = mod->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
mod->RegisterSymbol(kBufferName), // symbol
|
||||
kBufferName, // name
|
||||
ast::StorageClass::kUniform, // storage_class
|
||||
struct_type, // type
|
||||
|
@ -262,6 +264,7 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
|
|||
Source{}, mod->RegisterSymbol(field_name), field_name)));
|
||||
auto* var =
|
||||
mod->create<ast::Variable>(Source{}, // source
|
||||
mod->RegisterSymbol(original_name), // symbol
|
||||
original_name, // name
|
||||
ast::StorageClass::kNone, // storage_class
|
||||
mod->create<ast::type::U32>(), // type
|
||||
|
|
|
@ -165,8 +165,9 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
|
|||
// We didn't find a vertex index builtin, so create one
|
||||
vertex_index_name = kDefaultVertexIndexName;
|
||||
|
||||
auto* var =
|
||||
out->create<ast::Variable>(Source{}, // source
|
||||
auto* var = out->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
out->RegisterSymbol(vertex_index_name), // symbol
|
||||
vertex_index_name, // name
|
||||
ast::StorageClass::kInput, // storage_class
|
||||
GetI32Type(), // type
|
||||
|
@ -174,8 +175,8 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
|
|||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
// decorations
|
||||
out->create<ast::BuiltinDecoration>(
|
||||
Source{}, ast::Builtin::kVertexIdx),
|
||||
out->create<ast::BuiltinDecoration>(Source{},
|
||||
ast::Builtin::kVertexIdx),
|
||||
});
|
||||
|
||||
out->AddGlobalVariable(var);
|
||||
|
@ -212,8 +213,9 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
|
|||
// We didn't find an instance index builtin, so create one
|
||||
instance_index_name = kDefaultInstanceIndexName;
|
||||
|
||||
auto* var =
|
||||
out->create<ast::Variable>(Source{}, // source
|
||||
auto* var = out->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
out->RegisterSymbol(instance_index_name), // symbol
|
||||
instance_index_name, // name
|
||||
ast::StorageClass::kInput, // storage_class
|
||||
GetI32Type(), // type
|
||||
|
@ -221,8 +223,8 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
|
|||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
// decorations
|
||||
out->create<ast::BuiltinDecoration>(
|
||||
Source{}, ast::Builtin::kInstanceIdx),
|
||||
out->create<ast::BuiltinDecoration>(Source{},
|
||||
ast::Builtin::kInstanceIdx),
|
||||
});
|
||||
out->AddGlobalVariable(var);
|
||||
}
|
||||
|
@ -241,6 +243,7 @@ void VertexPulling::State::ConvertVertexInputVariablesToPrivate() {
|
|||
// place in the AST.
|
||||
v = out->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
v->symbol(), // symbol
|
||||
v->name(), // name
|
||||
ast::StorageClass::kPrivate, // storage_class
|
||||
v->type(), // type
|
||||
|
@ -282,9 +285,11 @@ void VertexPulling::State::AddVertexStorageBuffers() {
|
|||
|
||||
for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) {
|
||||
// The decorated variable with struct type
|
||||
std::string name = GetVertexBufferName(i);
|
||||
auto* var = out->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
GetVertexBufferName(i), // name
|
||||
out->RegisterSymbol(name), // symbol
|
||||
name, // name
|
||||
ast::StorageClass::kStorageBuffer, // storage_class
|
||||
struct_type, // type
|
||||
false, // is_const
|
||||
|
@ -309,6 +314,7 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
|
|||
auto* pos_declaration = out->create<ast::VariableDeclStatement>(
|
||||
Source{}, out->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
out->RegisterSymbol(kPullingPosVarName), // symbol
|
||||
kPullingPosVarName, // name
|
||||
ast::StorageClass::kFunction, // storage_class
|
||||
GetI32Type(), // type
|
||||
|
|
|
@ -50,6 +50,7 @@ class VertexPullingHelper : public ast::BuilderWithModule {
|
|||
Func("main", ast::VariableList{}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
|
||||
|
||||
mod->AddFunction(func);
|
||||
}
|
||||
|
||||
|
@ -399,20 +400,17 @@ TEST_F(VertexPullingTest, OneAttributeDifferentOutputSet) {
|
|||
TEST_F(VertexPullingTest, ExistingVertexIndexAndInstanceIndex) {
|
||||
InitBasicModule();
|
||||
|
||||
ast::type::F32 f32;
|
||||
AddVertexInputVariable(0, "var_a", &f32);
|
||||
AddVertexInputVariable(1, "var_b", &f32);
|
||||
|
||||
ast::type::I32 i32;
|
||||
AddVertexInputVariable(0, "var_a", ty.f32);
|
||||
AddVertexInputVariable(1, "var_b", ty.f32);
|
||||
|
||||
mod->AddGlobalVariable(
|
||||
Var("custom_vertex_index", ast::StorageClass::kInput, &i32, nullptr,
|
||||
Var("custom_vertex_index", ast::StorageClass::kInput, ty.i32, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kVertexIdx),
|
||||
}));
|
||||
|
||||
mod->AddGlobalVariable(
|
||||
Var("custom_instance_index", ast::StorageClass::kInput, &i32, nullptr,
|
||||
Var("custom_instance_index", ast::StorageClass::kInput, ty.i32, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kInstanceIdx),
|
||||
}));
|
||||
|
|
|
@ -35,45 +35,20 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Array ary(&f32, 3, ast::ArrayDecorationList{});
|
||||
|
||||
ast::ExpressionList exprs;
|
||||
exprs.push_back(create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
||||
exprs.push_back(create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f)));
|
||||
exprs.push_back(create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.0f)));
|
||||
|
||||
auto* var =
|
||||
create<ast::Variable>(Source{}, // source
|
||||
"pos", // name
|
||||
ast::StorageClass::kNone, // storage_class
|
||||
&ary, // type
|
||||
true, // is_const
|
||||
ast::type::Array ary(ty.f32, 3, ast::ArrayDecorationList{});
|
||||
auto* var = Const(
|
||||
"pos", ast::StorageClass::kNone, &ary,
|
||||
create<ast::TypeConstructorExpression>(
|
||||
Source{}, &ary, exprs), // constructor
|
||||
ast::VariableDecorationList{}); // decorations
|
||||
Source{}, &ary, ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)}),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "constant float pos[3] = {1.0f, 2.0f, 3.0f};\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_SpecConstant) {
|
||||
ast::type::F32 f32;
|
||||
|
||||
auto* var = create<ast::Variable>(
|
||||
Source{}, // source
|
||||
"pos", // name
|
||||
ast::StorageClass::kNone, // storage_class
|
||||
&f32, // type
|
||||
true, // is_const
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{},
|
||||
create<ast::FloatLiteral>(Source{}, &f32, 3.0f)), // constructor
|
||||
auto* var = Const("pos", ast::StorageClass::kNone, ty.f32, Expr(3.f),
|
||||
ast::VariableDecorationList{
|
||||
// decorations
|
||||
create<ast::ConstantIdDecoration>(Source{}, 23),
|
||||
});
|
||||
|
||||
|
|
|
@ -45,12 +45,10 @@ namespace {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
|
||||
ast::type::F32 f32;
|
||||
ast::Variable v(Source{}, "var", ast::StorageClass::kNone, &f32, false,
|
||||
nullptr, ast::VariableDecorationList{});
|
||||
auto* v = Var("var", ast::StorageClass::kNone, ty.f32);
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
|
@ -65,28 +63,17 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Vector vec(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.0f)));
|
||||
|
||||
auto* init = create<ast::TypeConstructorExpression>(Source{}, &vec, vals);
|
||||
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
ast::Variable v(Source{}, "var", ast::StorageClass::kOutput, &f32, false,
|
||||
init, ast::VariableDecorationList{});
|
||||
|
||||
td.RegisterVariableForTesting(&v);
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
ast::VariableDecorationList{});
|
||||
td.RegisterVariableForTesting(v);
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "var"
|
||||
|
@ -107,31 +94,16 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Vector vec(&f32, 2);
|
||||
|
||||
auto* rel = create<ast::BinaryExpression>(
|
||||
Source{}, ast::BinaryOp::kAdd,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.0f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.0f)));
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
|
||||
vals.push_back(rel);
|
||||
|
||||
auto* init = create<ast::TypeConstructorExpression>(Source{}, &vec, vals);
|
||||
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec2<f32>(), ast::ExpressionList{Expr(1.f), Add(3.f, 3.f)});
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
ast::Variable v(Source{}, "var", ast::StorageClass::kFunction, &vec, false,
|
||||
init, ast::VariableDecorationList{});
|
||||
auto* v = Var("var", ast::StorageClass::kFunction, ty.vec2<f32>(), init,
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
td.RegisterVariableForTesting(&v);
|
||||
td.RegisterVariableForTesting(v);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %7 "var"
|
||||
|
|
Loading…
Reference in New Issue