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:
dan sinclair
2020-12-16 21:42:30 +00:00
committed by Commit Bot service account
parent b5839939e1
commit a57f842be9
19 changed files with 242 additions and 242 deletions

View File

@@ -2248,8 +2248,9 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
if (!guard_name.empty()) {
// Declare the guard variable just before the "if", initialized to true.
auto* guard_var =
create<ast::Variable>(Source{}, // source
guard_name, // name
create<ast::Variable>(Source{}, // source
ast_module_.RegisterSymbol(guard_name), // symbol
guard_name, // name
ast::StorageClass::kFunction, // storage_class
parser_impl_.Bool(), // type
false, // is_const
@@ -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

View File

@@ -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}

View File

@@ -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

View File

@@ -1297,13 +1297,15 @@ ast::Variable* ParserImpl::MakeVariable(
}
}
return create<ast::Variable>(Source{}, // source
namer_.Name(id), // name
sc, // storage_class
type, // type
is_const, // is_const
constructor, // constructor
decorations); // decorations
std::string name = namer_.Name(id);
return create<ast::Variable>(Source{}, // source
ast_module_.RegisterSymbol(name), // symbol
name, // name
sc, // storage_class
type, // type
is_const, // is_const
constructor, // constructor
decorations); // decorations
}
TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {

View File

@@ -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

View File

@@ -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

View File

@@ -431,8 +431,9 @@ Maybe<ast::Variable*> ParserImpl::global_variable_decl(
constructor = expr.value;
}
return create<ast::Variable>(decl->source, // source
decl->name, // name
return create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
decl->storage_class, // storage_class
decl->type, // type
false, // is_const
@@ -459,8 +460,9 @@ Maybe<ast::Variable*> ParserImpl::global_constant_decl() {
if (init.errored)
return Failure::kErrored;
return create<ast::Variable>(decl->source, // source
decl->name, // name
return create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
ast::StorageClass::kNone, // storage_class
decl->type, // type
true, // is_const
@@ -1353,8 +1355,9 @@ Expect<ast::VariableList> ParserImpl::expect_param_list() {
ast::VariableList ret;
for (;;) {
auto* var =
create<ast::Variable>(decl->source, // source
decl->name, // name
create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
ast::StorageClass::kNone, // storage_class
decl->type, // type
true, // is_const
@@ -1624,8 +1627,9 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
return add_error(peek(), "missing constructor for const declaration");
auto* var =
create<ast::Variable>(decl->source, // source
decl->name, // name
create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
ast::StorageClass::kNone, // storage_class
decl->type, // type
true, // is_const
@@ -1653,8 +1657,9 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
}
auto* var =
create<ast::Variable>(decl->source, // source
decl->name, // name
create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
decl->storage_class, // storage_class
decl->type, // type
false, // is_const