[msl-writer][hlsl-writer] Remove space between builtin and (. The builting CL accidentally inserted indenting between the name of the builtin and the opening paren. This CL removes the extraneous spacing. Change-Id: If684ec6f2fb4bf13b559c16b246f57f7975d019d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28944 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 6e91894..2b54bac 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc
@@ -587,7 +587,8 @@ error_ = "Textures not implemented yet"; return false; } - if (!EmitBuiltinName(pre, out, expr)) { + name = generate_builtin_name(expr); + if (name.empty()) { return false; } } @@ -662,9 +663,8 @@ return true; } -bool GeneratorImpl::EmitBuiltinName(std::ostream&, - std::ostream& out, - ast::CallExpression* expr) { +std::string GeneratorImpl::generate_builtin_name(ast::CallExpression* expr) { + std::string out; auto* ident = expr->func()->AsIdentifier(); switch (ident->intrinsic()) { case ast::Intrinsic::kAcos: @@ -701,26 +701,26 @@ case ast::Intrinsic::kMax: case ast::Intrinsic::kMin: case ast::Intrinsic::kClamp: - out << ident->name(); + out = ident->name(); break; case ast::Intrinsic::kFaceForward: - out << "faceforward"; + out = "faceforward"; break; case ast::Intrinsic::kFract: - out << "frac"; + out = "frac"; break; case ast::Intrinsic::kInverseSqrt: - out << "rsqrt"; + out = "rsqrt"; break; case ast::Intrinsic::kSmoothStep: - out << "smoothstep"; + out = "smoothstep"; break; default: error_ = "Unknown builtin method: " + ident->name(); - return false; + return ""; } - return true; + return out; } bool GeneratorImpl::EmitCase(std::ostream& out, ast::CaseStatement* stmt) {
diff --git a/src/writer/hlsl/generator_impl.h b/src/writer/hlsl/generator_impl.h index 1e231a6..4ba5176 100644 --- a/src/writer/hlsl/generator_impl.h +++ b/src/writer/hlsl/generator_impl.h
@@ -201,14 +201,6 @@ /// @param stmt the statement to emit /// @returns true if the statement was successfully emitted bool EmitIf(std::ostream& out, ast::IfStatement* stmt); - /// Handles generating a builtin method name - /// @param pre the preamble for the expression stream - /// @param out the output of the expression stream - /// @param expr the expression - /// @returns true if the name was successfully emitted. - bool EmitBuiltinName(std::ostream& pre, - std::ostream& out, - ast::CallExpression* expr); /// Handles a literal /// @param out the output stream /// @param lit the literal to emit @@ -325,6 +317,10 @@ /// @param intrinsic the intrinsic to convert to a name /// @returns the intrinsic name or blank on error std::string generate_intrinsic_name(ast::Intrinsic intrinsic); + /// Handles generating a builtin method name + /// @param expr the expression + /// @returns the name or "" if not valid + std::string generate_builtin_name(ast::CallExpression* expr); /// Converts a builtin to an attribute name /// @param builtin the builtin to convert /// @returns the string name of the builtin or blank on error
diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 6f26ffa..cd92b1c 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc
@@ -517,7 +517,8 @@ error_ = "Textures not implemented yet"; return false; } - if (!EmitBuiltinName(ident)) { + name = generate_builtin_name(ident); + if (name.empty()) { return false; } } @@ -622,8 +623,9 @@ return true; } -bool GeneratorImpl::EmitBuiltinName(ast::IdentifierExpression* ident) { - out_ << "metal::"; +std::string GeneratorImpl::generate_builtin_name( + ast::IdentifierExpression* ident) { + std::string out = "metal::"; switch (ident->intrinsic()) { case ast::Intrinsic::kAcos: case ast::Intrinsic::kAsin: @@ -657,46 +659,46 @@ case ast::Intrinsic::kTrunc: case ast::Intrinsic::kSign: case ast::Intrinsic::kClamp: - out_ << ident->name(); + out += ident->name(); break; case ast::Intrinsic::kAbs: if (ident->result_type()->IsF32()) { - out_ << "fabs"; + out += "fabs"; } else if (ident->result_type()->IsU32() || ident->result_type()->IsI32()) { - out_ << "abs"; + out += "abs"; } break; case ast::Intrinsic::kMax: if (ident->result_type()->IsF32()) { - out_ << "fmax"; + out += "fmax"; } else if (ident->result_type()->IsU32() || ident->result_type()->IsI32()) { - out_ << "max"; + out += "max"; } break; case ast::Intrinsic::kMin: if (ident->result_type()->IsF32()) { - out_ << "fmin"; + out += "fmin"; } else if (ident->result_type()->IsU32() || ident->result_type()->IsI32()) { - out_ << "min"; + out += "min"; } break; case ast::Intrinsic::kFaceForward: - out_ << "faceforward"; + out += "faceforward"; break; case ast::Intrinsic::kSmoothStep: - out_ << "smoothstep"; + out += "smoothstep"; break; case ast::Intrinsic::kInverseSqrt: - out_ << "rsqrt"; + out += "rsqrt"; break; default: error_ = "Unknown import method: " + ident->name(); - return false; + return ""; } - return true; + return out; } bool GeneratorImpl::EmitCase(ast::CaseStatement* stmt) {
diff --git a/src/writer/msl/generator_impl.h b/src/writer/msl/generator_impl.h index f33a143..3582e19 100644 --- a/src/writer/msl/generator_impl.h +++ b/src/writer/msl/generator_impl.h
@@ -147,10 +147,6 @@ /// @param stmt the statement to emit /// @returns true if the statement was successfully emitted bool EmitIf(ast::IfStatement* stmt); - /// Handles generating a builtin name - /// @param ident the identifier to build the name from - /// @returns true if the name was successfully emitted. - bool EmitBuiltinName(ast::IdentifierExpression* ident); /// Handles a literal /// @param lit the literal to emit /// @returns true if the literal was successfully emitted @@ -230,6 +226,10 @@ /// @param intrinsic the intrinsic to convert to an method name /// @returns the intrinsic name or blank on error std::string generate_intrinsic_name(ast::Intrinsic intrinsic); + /// Handles generating a builtin name + /// @param ident the identifier to build the name from + /// @returns the name or "" if not valid + std::string generate_builtin_name(ast::IdentifierExpression* ident); /// Checks if the global variable is in an input or output struct /// @param var the variable to check
diff --git a/src/writer/msl/generator_impl_import_test.cc b/src/writer/msl/generator_impl_import_test.cc index 358838f..1e56fc8 100644 --- a/src/writer/msl/generator_impl_import_test.cc +++ b/src/writer/msl/generator_impl_import_test.cc
@@ -70,8 +70,8 @@ ASSERT_TRUE(td.DetermineResultType(&call)) << td.error(); GeneratorImpl g(&mod); - ASSERT_TRUE(g.EmitBuiltinName(ident_ptr)) << g.error(); - EXPECT_EQ(g.result(), std::string("metal::") + param.msl_name); + ASSERT_EQ(g.generate_builtin_name(ident_ptr), + std::string("metal::") + param.msl_name); } INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest, MslImportData_SingleParamTest,