mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Add a symbol to the Function AST node.
This Cl adds a Symbol representing the function name to the function AST. The symbol is added alongside the name for now. When all usages of the function name are removed then the string version will be removed from the constructor. Change-Id: Ib2450e5fe531e988b25bb7d2937acc6af2187871 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35220 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com> Auto-Submit: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
cd9e5f6e91
commit
a41132fcd8
@@ -761,9 +761,10 @@ bool FunctionEmitter::Emit() {
|
||||
}
|
||||
|
||||
auto* body = statements_stack_[0].statements_;
|
||||
ast_module_.AddFunction(create<ast::Function>(
|
||||
decl.source, decl.name, std::move(decl.params), decl.return_type, body,
|
||||
std::move(decl.decorations)));
|
||||
ast_module_.AddFunction(
|
||||
create<ast::Function>(decl.source, ast_module_.RegisterSymbol(decl.name),
|
||||
decl.name, std::move(decl.params), decl.return_type,
|
||||
body, std::move(decl.decorations)));
|
||||
|
||||
// Maintain the invariant by repopulating the one and only element.
|
||||
statements_stack_.clear();
|
||||
|
||||
@@ -46,14 +46,16 @@ TEST_F(SpvParserTest, EmitStatement_VoidCallNoParams) {
|
||||
OpFunctionEnd
|
||||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
|
||||
const auto module_ast_str = p->module().to_str();
|
||||
const auto module_ast_str = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast_str, Eq(R"(Module{
|
||||
Function x_50 -> __void
|
||||
Function )" + p->get_module().GetSymbol("x_50").to_str() +
|
||||
R"( -> __void
|
||||
()
|
||||
{
|
||||
Return{}
|
||||
}
|
||||
Function x_100 -> __void
|
||||
Function )" + p->get_module().GetSymbol("x_100").to_str() +
|
||||
R"( -> __void
|
||||
()
|
||||
{
|
||||
Call[not set]{
|
||||
@@ -214,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->module().to_str();
|
||||
const auto module_ast_str = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast_str, HasSubstr(R"(Module{
|
||||
Function x_50 -> __u32
|
||||
Function )" + p->get_module().GetSymbol("x_50").to_str() +
|
||||
R"( -> __u32
|
||||
(
|
||||
VariableConst{
|
||||
x_51
|
||||
@@ -240,7 +243,8 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Function x_100 -> __void
|
||||
Function )" + p->get_module().GetSymbol("x_100").to_str() +
|
||||
R"( -> __void
|
||||
()
|
||||
{
|
||||
VariableDeclStatement{
|
||||
|
||||
@@ -59,9 +59,10 @@ 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->module().to_str();
|
||||
auto* expect = R"(Module{
|
||||
Function x_100 -> __void
|
||||
auto got = p->get_module().to_str();
|
||||
auto expect = R"(Module{
|
||||
Function )" + p->get_module().GetSymbol("x_100").to_str() +
|
||||
R"( -> __void
|
||||
()
|
||||
{
|
||||
Return{}
|
||||
@@ -83,9 +84,10 @@ TEST_F(SpvParserTest, Emit_NonVoidResultType) {
|
||||
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
|
||||
EXPECT_TRUE(fe.Emit());
|
||||
|
||||
auto got = p->module().to_str();
|
||||
auto* expect = R"(Module{
|
||||
Function x_100 -> __f32
|
||||
auto got = p->get_module().to_str();
|
||||
auto expect = R"(Module{
|
||||
Function )" + p->get_module().GetSymbol("x_100").to_str() +
|
||||
R"( -> __f32
|
||||
()
|
||||
{
|
||||
Return{
|
||||
@@ -115,9 +117,10 @@ TEST_F(SpvParserTest, Emit_MixedParamTypes) {
|
||||
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
|
||||
EXPECT_TRUE(fe.Emit());
|
||||
|
||||
auto got = p->module().to_str();
|
||||
auto* expect = R"(Module{
|
||||
Function x_100 -> __void
|
||||
auto got = p->get_module().to_str();
|
||||
auto expect = R"(Module{
|
||||
Function )" + p->get_module().GetSymbol("x_100").to_str() +
|
||||
R"( -> __void
|
||||
(
|
||||
VariableConst{
|
||||
a
|
||||
@@ -159,9 +162,10 @@ TEST_F(SpvParserTest, Emit_GenerateParamNames) {
|
||||
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
|
||||
EXPECT_TRUE(fe.Emit());
|
||||
|
||||
auto got = p->module().to_str();
|
||||
auto* expect = R"(Module{
|
||||
Function x_100 -> __void
|
||||
auto got = p->get_module().to_str();
|
||||
auto expect = R"(Module{
|
||||
Function )" + p->get_module().GetSymbol("x_100").to_str() +
|
||||
R"( -> __void
|
||||
(
|
||||
VariableConst{
|
||||
x_14
|
||||
|
||||
@@ -53,7 +53,7 @@ TEST_F(SpvParserTest, EmitFunctions_NoFunctions) {
|
||||
auto p = parser(test::Assemble(CommonTypes()));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_ast = p->module().to_str();
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast, Not(HasSubstr("Function{")));
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ TEST_F(SpvParserTest, EmitFunctions_FunctionWithoutBody) {
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_ast = p->module().to_str();
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast, Not(HasSubstr("Function{")));
|
||||
}
|
||||
|
||||
@@ -79,9 +79,10 @@ OpFunctionEnd)";
|
||||
auto p = parser(test::Assemble(input));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
const auto module_ast = p->module().to_str();
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function main -> __void
|
||||
Function )" + p->get_module().GetSymbol("main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{vertex}
|
||||
()
|
||||
{)"));
|
||||
@@ -98,9 +99,10 @@ OpFunctionEnd)";
|
||||
auto p = parser(test::Assemble(input));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
const auto module_ast = p->module().to_str();
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function main -> __void
|
||||
Function )" + p->get_module().GetSymbol("main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{fragment}
|
||||
()
|
||||
{)"));
|
||||
@@ -117,9 +119,10 @@ OpFunctionEnd)";
|
||||
auto p = parser(test::Assemble(input));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
const auto module_ast = p->module().to_str();
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function main -> __void
|
||||
Function )" + p->get_module().GetSymbol("main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{compute}
|
||||
()
|
||||
{)"));
|
||||
@@ -138,14 +141,16 @@ OpFunctionEnd)";
|
||||
auto p = parser(test::Assemble(input));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
const auto module_ast = p->module().to_str();
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function frag_main -> __void
|
||||
Function )" + p->get_module().GetSymbol("frag_main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{fragment}
|
||||
()
|
||||
{)"));
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function comp_main -> __void
|
||||
Function )" + p->get_module().GetSymbol("comp_main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{compute}
|
||||
()
|
||||
{)"));
|
||||
@@ -160,9 +165,10 @@ TEST_F(SpvParserTest, EmitFunctions_VoidFunctionWithoutParams) {
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_ast = p->module().to_str();
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function main -> __void
|
||||
Function )" + p->get_module().GetSymbol("main").to_str() +
|
||||
R"( -> __void
|
||||
()
|
||||
{)"));
|
||||
}
|
||||
@@ -193,9 +199,10 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) {
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_ast = p->module().to_str();
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function leaf -> __u32
|
||||
Function )" + p->get_module().GetSymbol("leaf").to_str() +
|
||||
R"( -> __u32
|
||||
()
|
||||
{
|
||||
Return{
|
||||
@@ -204,7 +211,8 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Function branch -> __u32
|
||||
Function )" + p->get_module().GetSymbol("branch").to_str() +
|
||||
R"( -> __u32
|
||||
()
|
||||
{
|
||||
VariableDeclStatement{
|
||||
@@ -227,7 +235,8 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Function root -> __void
|
||||
Function )" + p->get_module().GetSymbol("root").to_str() +
|
||||
R"( -> __void
|
||||
()
|
||||
{
|
||||
VariableDeclStatement{
|
||||
@@ -260,9 +269,10 @@ TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) {
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_ast = p->module().to_str();
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function ret_float -> __f32
|
||||
Function )" + p->get_module().GetSymbol("ret_float").to_str() +
|
||||
R"( -> __f32
|
||||
()
|
||||
{
|
||||
Return{
|
||||
@@ -289,9 +299,10 @@ TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) {
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_ast = p->module().to_str();
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function mixed_params -> __void
|
||||
Function )" + p->get_module().GetSymbol("mixed_params").to_str() +
|
||||
R"( -> __void
|
||||
(
|
||||
VariableConst{
|
||||
a
|
||||
@@ -328,9 +339,10 @@ TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) {
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_ast = p->module().to_str();
|
||||
const auto module_ast = p->get_module().to_str();
|
||||
EXPECT_THAT(module_ast, HasSubstr(R"(
|
||||
Function mixed_params -> __void
|
||||
Function )" + p->get_module().GetSymbol("mixed_params").to_str() +
|
||||
R"( -> __void
|
||||
(
|
||||
VariableConst{
|
||||
x_14
|
||||
|
||||
@@ -1280,9 +1280,9 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
|
||||
if (errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
return create<ast::Function>(header->source, header->name, header->params,
|
||||
header->return_type, body.value,
|
||||
func_decos.value);
|
||||
return create<ast::Function>(
|
||||
header->source, module_.RegisterSymbol(header->name), header->name,
|
||||
header->params, header->return_type, body.value, func_decos.value);
|
||||
}
|
||||
|
||||
// function_type_decl
|
||||
|
||||
Reference in New Issue
Block a user