Add a symbol to the Identifier AST node

This CL adds a Symbol to the identifier to represent the name. The name
still exists but will be removed in a future CL when the namers are in
place.

Change-Id: Ic3cc8ad0d99e3bea6eb1ff1ce212e7de67991aec
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35460
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair
2020-12-11 19:16:13 +00:00
committed by Commit Bot service account
parent 5b3c9f1c62
commit 6b59bf45aa
113 changed files with 2525 additions and 1750 deletions

View File

@@ -135,7 +135,9 @@ ast::ArrayAccessorExpression* BoundArrayAccessors::Transform(
ctx->mod->create<ast::UintLiteral>(u32, size - 1)));
auto* call_expr = ctx->mod->create<ast::CallExpression>(
ctx->mod->create<ast::IdentifierExpression>("min"), std::move(params));
ctx->mod->create<ast::IdentifierExpression>(
ctx->mod->RegisterSymbol("min"), "min"),
std::move(params));
call_expr->set_result_type(u32);
idx_expr = call_expr;

View File

@@ -67,8 +67,8 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
// Build the AST expression & statement for assigning pointsize one.
auto* one = mod->create<ast::ScalarConstructorExpression>(
mod->create<ast::FloatLiteral>(f32, 1.0f));
auto* pointsize_ident =
mod->create<ast::IdentifierExpression>(Source{}, kPointSizeVar);
auto* pointsize_ident = mod->create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(kPointSizeVar), kPointSizeVar);
auto* pointsize_assign =
mod->create<ast::AssignmentStatement>(pointsize_ident, one);

View File

@@ -21,6 +21,7 @@
#include "src/ast/builder.h"
#include "src/ast/stage_decoration.h"
#include "src/ast/variable_decl_statement.h"
#include "src/demangler.h"
#include "src/diagnostic/formatter.h"
#include "src/transform/manager.h"
@@ -85,7 +86,7 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
ASSERT_FALSE(result.diagnostics.contains_errors())
<< diag::Formatter().format(result.diagnostics);
auto expected = R"(Module{
auto* expected = R"(Module{
Variable{
Decorations{
BuiltinDecoration{pointsize}
@@ -94,13 +95,11 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
out
__f32
}
Function )" + result.module.RegisterSymbol("non_entry_a").to_str() +
R"( -> __void
Function non_entry_a -> __void
()
{
}
Function )" + result.module.RegisterSymbol("entry").to_str() +
R"( -> __void
Function entry -> __void
StageDecoration{vertex}
()
{
@@ -116,14 +115,14 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
}
}
}
Function )" + result.module.RegisterSymbol("non_entry_b").to_str() +
R"( -> __void
Function non_entry_b -> __void
()
{
}
}
)";
EXPECT_EQ(expected, result.module.to_str());
EXPECT_EQ(expected,
Demangler().Demangle(result.module, result.module.to_str()));
}
TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
@@ -156,7 +155,7 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
ASSERT_FALSE(result.diagnostics.contains_errors())
<< diag::Formatter().format(result.diagnostics);
auto expected = R"(Module{
auto* expected = R"(Module{
Variable{
Decorations{
BuiltinDecoration{pointsize}
@@ -165,13 +164,11 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
out
__f32
}
Function )" + result.module.RegisterSymbol("non_entry_a").to_str() +
R"( -> __void
Function non_entry_a -> __void
()
{
}
Function )" + result.module.RegisterSymbol("entry").to_str() +
R"( -> __void
Function entry -> __void
StageDecoration{vertex}
()
{
@@ -180,14 +177,14 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
ScalarConstructor[__f32]{1.000000}
}
}
Function )" + result.module.RegisterSymbol("non_entry_b").to_str() +
R"( -> __void
Function non_entry_b -> __void
()
{
}
}
)";
EXPECT_EQ(expected, result.module.to_str());
EXPECT_EQ(expected,
Demangler().Demangle(result.module, result.module.to_str()));
}
TEST_F(EmitVertexPointSizeTest, NonVertexStage) {
@@ -219,22 +216,21 @@ TEST_F(EmitVertexPointSizeTest, NonVertexStage) {
ASSERT_FALSE(result.diagnostics.contains_errors())
<< diag::Formatter().format(result.diagnostics);
auto expected = R"(Module{
Function )" + result.module.RegisterSymbol("fragment_entry").to_str() +
R"( -> __void
auto* expected = R"(Module{
Function fragment_entry -> __void
StageDecoration{fragment}
()
{
}
Function )" + result.module.RegisterSymbol("compute_entry").to_str() +
R"( -> __void
Function compute_entry -> __void
StageDecoration{compute}
()
{
}
}
)";
EXPECT_EQ(expected, result.module.to_str());
EXPECT_EQ(expected,
Demangler().Demangle(result.module, result.module.to_str()));
}
} // namespace

View File

@@ -251,13 +251,16 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
const std::string& field_name,
ast::Variable* buffer_var,
ast::Module* mod) {
auto* buffer = mod->create<ast::IdentifierExpression>(buffer_var->name());
auto* buffer = mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(buffer_var->name()), buffer_var->name());
auto* constructor = mod->create<ast::BinaryExpression>(
ast::BinaryOp::kAdd,
mod->create<ast::IdentifierExpression>(kIndexOffsetPrefix +
original_name),
mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(kIndexOffsetPrefix + original_name),
kIndexOffsetPrefix + original_name),
mod->create<ast::MemberAccessorExpression>(
buffer, mod->create<ast::IdentifierExpression>(field_name)));
buffer, mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(field_name), field_name)));
auto* var =
mod->create<ast::Variable>(Source{}, // source
original_name, // name

View File

@@ -74,7 +74,8 @@ TEST_F(FirstIndexOffsetTest, Error_AlreadyTransformed) {
void Build() override {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("vert_idx")));
Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("vert_idx"), "vert_idx")));
}
};
@@ -115,7 +116,8 @@ TEST_F(FirstIndexOffsetTest, BasicModuleVertexIndex) {
void Build() override {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("vert_idx")));
Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("vert_idx"), "vert_idx")));
}
};
@@ -191,7 +193,8 @@ TEST_F(FirstIndexOffsetTest, BasicModuleInstanceIndex) {
void Build() override {
AddBuiltinInput("inst_idx", ast::Builtin::kInstanceIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("inst_idx")));
Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("inst_idx"), "inst_idx")));
}
};
@@ -344,11 +347,13 @@ TEST_F(FirstIndexOffsetTest, NestedCalls) {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
ast::Function* func1 = AddFunction("func1");
func1->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("vert_idx")));
Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("vert_idx"), "vert_idx")));
ast::Function* func2 = AddFunction("func2");
func2->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::CallExpression>(
create<ast::IdentifierExpression>("func1"),
create<ast::IdentifierExpression>(
mod->RegisterSymbol("func1"), "func1"),
ast::ExpressionList{})));
}
};

View File

@@ -321,11 +321,12 @@ void VertexPulling::State::AddVertexPullingPreamble(
}
auto* v = it->second;
auto name = buffer_layout.step_mode == InputStepMode::kVertex
? vertex_index_name
: instance_index_name;
// Identifier to index by
auto* index_identifier = mod->create<ast::IdentifierExpression>(
buffer_layout.step_mode == InputStepMode::kVertex
? vertex_index_name
: instance_index_name);
mod->RegisterSymbol(name), name);
// An expression for the start of the read in the buffer in bytes
auto* pos_value = mod->create<ast::BinaryExpression>(
@@ -341,7 +342,8 @@ void VertexPulling::State::AddVertexPullingPreamble(
block->append(set_pos_expr);
block->append(mod->create<ast::AssignmentStatement>(
mod->create<ast::IdentifierExpression>(v->name()),
mod->create<ast::IdentifierExpression>(mod->RegisterSymbol(v->name()),
v->name()),
AccessByFormat(i, attribute_desc.format)));
}
}
@@ -355,7 +357,8 @@ ast::Expression* VertexPulling::State::GenUint(uint32_t value) {
}
ast::Expression* VertexPulling::State::CreatePullingPositionIdent() {
return mod->create<ast::IdentifierExpression>(kPullingPosVarName);
return mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(kPullingPosVarName), kPullingPosVarName);
}
ast::Expression* VertexPulling::State::AccessByFormat(uint32_t buffer,
@@ -392,10 +395,13 @@ ast::Expression* VertexPulling::State::AccessU32(uint32_t buffer,
// by dividing. Then, that element is going to be read, and if needed,
// unpacked into an appropriate variable. All reads should end up here as a
// base case.
auto vbuf_name = GetVertexBufferName(buffer);
return mod->create<ast::ArrayAccessorExpression>(
mod->create<ast::MemberAccessorExpression>(
mod->create<ast::IdentifierExpression>(GetVertexBufferName(buffer)),
mod->create<ast::IdentifierExpression>(kStructBufferName)),
mod->create<ast::IdentifierExpression>(mod->RegisterSymbol(vbuf_name),
vbuf_name),
mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(kStructBufferName), kStructBufferName)),
mod->create<ast::BinaryExpression>(ast::BinaryOp::kDivide, pos,
GenUint(4)));
}

View File

@@ -24,7 +24,7 @@
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/void_type.h"
#include "src/ast/variable.h"
#include "src/demangler.h"
#include "src/diagnostic/formatter.h"
#include "src/transform/manager.h"
#include "src/type_determiner.h"
@@ -195,8 +195,7 @@ TEST_F(VertexPullingTest, OneAttribute) {
storage_buffer
__struct_TintVertexData
}
Function )" + result.module.GetSymbol("main").to_str() +
R"( -> __void
Function main -> __void
StageDecoration{vertex}
()
{
@@ -240,7 +239,7 @@ TEST_F(VertexPullingTest, OneAttribute) {
}
}
)",
result.module.to_str());
Demangler().Demangle(result.module, result.module.to_str()));
}
TEST_F(VertexPullingTest, OneInstancedAttribute) {
@@ -283,8 +282,7 @@ TEST_F(VertexPullingTest, OneInstancedAttribute) {
storage_buffer
__struct_TintVertexData
}
Function )" + result.module.GetSymbol("main").to_str() +
R"( -> __void
Function main -> __void
StageDecoration{vertex}
()
{
@@ -328,7 +326,7 @@ TEST_F(VertexPullingTest, OneInstancedAttribute) {
}
}
)",
result.module.to_str());
Demangler().Demangle(result.module, result.module.to_str()));
}
TEST_F(VertexPullingTest, OneAttributeDifferentOutputSet) {
@@ -371,8 +369,7 @@ TEST_F(VertexPullingTest, OneAttributeDifferentOutputSet) {
storage_buffer
__struct_TintVertexData
}
Function )" + result.module.GetSymbol("main").to_str() +
R"( -> __void
Function main -> __void
StageDecoration{vertex}
()
{
@@ -416,7 +413,7 @@ TEST_F(VertexPullingTest, OneAttributeDifferentOutputSet) {
}
}
)",
result.module.to_str());
Demangler().Demangle(result.module, result.module.to_str()));
}
// We expect the transform to use an existing builtin variables if it finds them
@@ -510,8 +507,7 @@ TEST_F(VertexPullingTest, ExistingVertexIndexAndInstanceIndex) {
storage_buffer
__struct_TintVertexData
}
Function )" + result.module.GetSymbol("main").to_str() +
R"( -> __void
Function main -> __void
StageDecoration{vertex}
()
{
@@ -583,7 +579,7 @@ TEST_F(VertexPullingTest, ExistingVertexIndexAndInstanceIndex) {
}
}
)",
result.module.to_str());
Demangler().Demangle(result.module, result.module.to_str()));
}
TEST_F(VertexPullingTest, TwoAttributesSameBuffer) {
@@ -636,8 +632,7 @@ TEST_F(VertexPullingTest, TwoAttributesSameBuffer) {
storage_buffer
__struct_TintVertexData
}
Function )" + result.module.GetSymbol("main").to_str() +
R"( -> __void
Function main -> __void
StageDecoration{vertex}
()
{
@@ -767,7 +762,7 @@ TEST_F(VertexPullingTest, TwoAttributesSameBuffer) {
}
}
)",
result.module.to_str());
Demangler().Demangle(result.module, result.module.to_str()));
}
TEST_F(VertexPullingTest, FloatVectorAttributes) {
@@ -847,8 +842,7 @@ TEST_F(VertexPullingTest, FloatVectorAttributes) {
storage_buffer
__struct_TintVertexData
}
Function )" + result.module.GetSymbol("main").to_str() +
R"( -> __void
Function main -> __void
StageDecoration{vertex}
()
{
@@ -1071,7 +1065,7 @@ TEST_F(VertexPullingTest, FloatVectorAttributes) {
}
}
)",
result.module.to_str());
Demangler().Demangle(result.module, result.module.to_str()));
}
} // namespace