From b2a0c8aee74b9f564eef84c0f9c92c8121065e1e Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 24 Sep 2020 15:12:55 +0000 Subject: [PATCH] [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 Reviewed-by: Ryan Harrison --- src/writer/hlsl/generator_impl.cc | 22 +++++++------- src/writer/hlsl/generator_impl.h | 12 +++----- src/writer/msl/generator_impl.cc | 32 +++++++++++--------- src/writer/msl/generator_impl.h | 8 ++--- src/writer/msl/generator_impl_import_test.cc | 4 +-- 5 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 6e9189457c..2b54bac117 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -587,7 +587,8 @@ bool GeneratorImpl::EmitCall(std::ostream& pre, 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 @@ bool GeneratorImpl::EmitCall(std::ostream& pre, 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 @@ bool GeneratorImpl::EmitBuiltinName(std::ostream&, 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 1e231a6af0..4ba5176338 100644 --- a/src/writer/hlsl/generator_impl.h +++ b/src/writer/hlsl/generator_impl.h @@ -201,14 +201,6 @@ class GeneratorImpl { /// @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 @@ class GeneratorImpl { /// @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 6f26ffa2c0..cd92b1c416 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -517,7 +517,8 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) { error_ = "Textures not implemented yet"; return false; } - if (!EmitBuiltinName(ident)) { + name = generate_builtin_name(ident); + if (name.empty()) { return false; } } @@ -622,8 +623,9 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) { 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 @@ bool GeneratorImpl::EmitBuiltinName(ast::IdentifierExpression* ident) { 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 f33a143425..3582e19b40 100644 --- a/src/writer/msl/generator_impl.h +++ b/src/writer/msl/generator_impl.h @@ -147,10 +147,6 @@ class GeneratorImpl : public TextGenerator { /// @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 @@ class GeneratorImpl : public TextGenerator { /// @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 358838f56f..1e56fc8d1d 100644 --- a/src/writer/msl/generator_impl_import_test.cc +++ b/src/writer/msl/generator_impl_import_test.cc @@ -70,8 +70,8 @@ TEST_P(MslImportData_SingleParamTest, FloatScalar) { 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,