[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>
This commit is contained in:
dan sinclair 2020-09-24 15:12:55 +00:00 committed by Commit Bot service account
parent 3c02592718
commit b2a0c8aee7
5 changed files with 38 additions and 40 deletions

View File

@ -587,7 +587,8 @@ bool GeneratorImpl::EmitCall(std::ostream& pre,
error_ = "Textures not implemented yet"; error_ = "Textures not implemented yet";
return false; return false;
} }
if (!EmitBuiltinName(pre, out, expr)) { name = generate_builtin_name(expr);
if (name.empty()) {
return false; return false;
} }
} }
@ -662,9 +663,8 @@ bool GeneratorImpl::EmitCall(std::ostream& pre,
return true; return true;
} }
bool GeneratorImpl::EmitBuiltinName(std::ostream&, std::string GeneratorImpl::generate_builtin_name(ast::CallExpression* expr) {
std::ostream& out, std::string out;
ast::CallExpression* expr) {
auto* ident = expr->func()->AsIdentifier(); auto* ident = expr->func()->AsIdentifier();
switch (ident->intrinsic()) { switch (ident->intrinsic()) {
case ast::Intrinsic::kAcos: case ast::Intrinsic::kAcos:
@ -701,26 +701,26 @@ bool GeneratorImpl::EmitBuiltinName(std::ostream&,
case ast::Intrinsic::kMax: case ast::Intrinsic::kMax:
case ast::Intrinsic::kMin: case ast::Intrinsic::kMin:
case ast::Intrinsic::kClamp: case ast::Intrinsic::kClamp:
out << ident->name(); out = ident->name();
break; break;
case ast::Intrinsic::kFaceForward: case ast::Intrinsic::kFaceForward:
out << "faceforward"; out = "faceforward";
break; break;
case ast::Intrinsic::kFract: case ast::Intrinsic::kFract:
out << "frac"; out = "frac";
break; break;
case ast::Intrinsic::kInverseSqrt: case ast::Intrinsic::kInverseSqrt:
out << "rsqrt"; out = "rsqrt";
break; break;
case ast::Intrinsic::kSmoothStep: case ast::Intrinsic::kSmoothStep:
out << "smoothstep"; out = "smoothstep";
break; break;
default: default:
error_ = "Unknown builtin method: " + ident->name(); error_ = "Unknown builtin method: " + ident->name();
return false; return "";
} }
return true; return out;
} }
bool GeneratorImpl::EmitCase(std::ostream& out, ast::CaseStatement* stmt) { bool GeneratorImpl::EmitCase(std::ostream& out, ast::CaseStatement* stmt) {

View File

@ -201,14 +201,6 @@ class GeneratorImpl {
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted /// @returns true if the statement was successfully emitted
bool EmitIf(std::ostream& out, ast::IfStatement* stmt); 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 /// Handles a literal
/// @param out the output stream /// @param out the output stream
/// @param lit the literal to emit /// @param lit the literal to emit
@ -325,6 +317,10 @@ class GeneratorImpl {
/// @param intrinsic the intrinsic to convert to a name /// @param intrinsic the intrinsic to convert to a name
/// @returns the intrinsic name or blank on error /// @returns the intrinsic name or blank on error
std::string generate_intrinsic_name(ast::Intrinsic intrinsic); 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 /// Converts a builtin to an attribute name
/// @param builtin the builtin to convert /// @param builtin the builtin to convert
/// @returns the string name of the builtin or blank on error /// @returns the string name of the builtin or blank on error

View File

@ -517,7 +517,8 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
error_ = "Textures not implemented yet"; error_ = "Textures not implemented yet";
return false; return false;
} }
if (!EmitBuiltinName(ident)) { name = generate_builtin_name(ident);
if (name.empty()) {
return false; return false;
} }
} }
@ -622,8 +623,9 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
return true; return true;
} }
bool GeneratorImpl::EmitBuiltinName(ast::IdentifierExpression* ident) { std::string GeneratorImpl::generate_builtin_name(
out_ << "metal::"; ast::IdentifierExpression* ident) {
std::string out = "metal::";
switch (ident->intrinsic()) { switch (ident->intrinsic()) {
case ast::Intrinsic::kAcos: case ast::Intrinsic::kAcos:
case ast::Intrinsic::kAsin: case ast::Intrinsic::kAsin:
@ -657,46 +659,46 @@ bool GeneratorImpl::EmitBuiltinName(ast::IdentifierExpression* ident) {
case ast::Intrinsic::kTrunc: case ast::Intrinsic::kTrunc:
case ast::Intrinsic::kSign: case ast::Intrinsic::kSign:
case ast::Intrinsic::kClamp: case ast::Intrinsic::kClamp:
out_ << ident->name(); out += ident->name();
break; break;
case ast::Intrinsic::kAbs: case ast::Intrinsic::kAbs:
if (ident->result_type()->IsF32()) { if (ident->result_type()->IsF32()) {
out_ << "fabs"; out += "fabs";
} else if (ident->result_type()->IsU32() || } else if (ident->result_type()->IsU32() ||
ident->result_type()->IsI32()) { ident->result_type()->IsI32()) {
out_ << "abs"; out += "abs";
} }
break; break;
case ast::Intrinsic::kMax: case ast::Intrinsic::kMax:
if (ident->result_type()->IsF32()) { if (ident->result_type()->IsF32()) {
out_ << "fmax"; out += "fmax";
} else if (ident->result_type()->IsU32() || } else if (ident->result_type()->IsU32() ||
ident->result_type()->IsI32()) { ident->result_type()->IsI32()) {
out_ << "max"; out += "max";
} }
break; break;
case ast::Intrinsic::kMin: case ast::Intrinsic::kMin:
if (ident->result_type()->IsF32()) { if (ident->result_type()->IsF32()) {
out_ << "fmin"; out += "fmin";
} else if (ident->result_type()->IsU32() || } else if (ident->result_type()->IsU32() ||
ident->result_type()->IsI32()) { ident->result_type()->IsI32()) {
out_ << "min"; out += "min";
} }
break; break;
case ast::Intrinsic::kFaceForward: case ast::Intrinsic::kFaceForward:
out_ << "faceforward"; out += "faceforward";
break; break;
case ast::Intrinsic::kSmoothStep: case ast::Intrinsic::kSmoothStep:
out_ << "smoothstep"; out += "smoothstep";
break; break;
case ast::Intrinsic::kInverseSqrt: case ast::Intrinsic::kInverseSqrt:
out_ << "rsqrt"; out += "rsqrt";
break; break;
default: default:
error_ = "Unknown import method: " + ident->name(); error_ = "Unknown import method: " + ident->name();
return false; return "";
} }
return true; return out;
} }
bool GeneratorImpl::EmitCase(ast::CaseStatement* stmt) { bool GeneratorImpl::EmitCase(ast::CaseStatement* stmt) {

View File

@ -147,10 +147,6 @@ class GeneratorImpl : public TextGenerator {
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted /// @returns true if the statement was successfully emitted
bool EmitIf(ast::IfStatement* stmt); 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 /// Handles a literal
/// @param lit the literal to emit /// @param lit the literal to emit
/// @returns true if the literal was successfully emitted /// @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 /// @param intrinsic the intrinsic to convert to an method name
/// @returns the intrinsic name or blank on error /// @returns the intrinsic name or blank on error
std::string generate_intrinsic_name(ast::Intrinsic intrinsic); 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 /// Checks if the global variable is in an input or output struct
/// @param var the variable to check /// @param var the variable to check

View File

@ -70,8 +70,8 @@ TEST_P(MslImportData_SingleParamTest, FloatScalar) {
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();
GeneratorImpl g(&mod); GeneratorImpl g(&mod);
ASSERT_TRUE(g.EmitBuiltinName(ident_ptr)) << g.error(); ASSERT_EQ(g.generate_builtin_name(ident_ptr),
EXPECT_EQ(g.result(), std::string("metal::") + param.msl_name); std::string("metal::") + param.msl_name);
} }
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest, INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
MslImportData_SingleParamTest, MslImportData_SingleParamTest,