Convert IRGenerator::convertPostfixExpr to PostfixExpr::Make.
We have no optimizations on postfix-expressions at all so this is a very straightforward cut-and-paste. Change-Id: I73b3bc73ad833e668306301e6d6859e44230393a Bug: skia:11342 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/376846 Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
b0eb20f83a
commit
52d3b01da8
@ -120,6 +120,7 @@ skia_sksl_sources = [
|
||||
"$_src/sksl/ir/SkSLModifiers.h",
|
||||
"$_src/sksl/ir/SkSLModifiersDeclaration.h",
|
||||
"$_src/sksl/ir/SkSLNop.h",
|
||||
"$_src/sksl/ir/SkSLPostfixExpression.cpp",
|
||||
"$_src/sksl/ir/SkSLPostfixExpression.h",
|
||||
"$_src/sksl/ir/SkSLPrefixExpression.cpp",
|
||||
"$_src/sksl/ir/SkSLPrefixExpression.h",
|
||||
|
@ -769,7 +769,8 @@ std::unique_ptr<Block> IRGenerator::applyInvocationIDWorkaround(std::unique_ptr<
|
||||
Token::Kind::TK_LT,
|
||||
std::make_unique<IntLiteral>(fContext, /*offset=*/-1, fInvocations),
|
||||
fContext.fTypes.fBool.get());
|
||||
auto next = std::make_unique<PostfixExpression>(
|
||||
auto next = PostfixExpression::Make(
|
||||
fContext,
|
||||
std::make_unique<VariableReference>(/*offset=*/-1, loopIdx,
|
||||
VariableReference::RefKind::kReadWrite),
|
||||
Token::Kind::TK_PLUSPLUS);
|
||||
@ -2408,23 +2409,7 @@ std::unique_ptr<Expression> IRGenerator::convertPostfixExpression(const ASTNode&
|
||||
if (!base) {
|
||||
return nullptr;
|
||||
}
|
||||
return this->convertPostfixExpression(std::move(base), expression.getOperator());
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> IRGenerator::convertPostfixExpression(std::unique_ptr<Expression> base,
|
||||
Operator op) {
|
||||
const Type& baseType = base->type();
|
||||
if (!baseType.isNumber()) {
|
||||
this->errorReporter().error(base->fOffset,
|
||||
"'" + String(op.operatorName()) +
|
||||
"' cannot operate on '" + baseType.displayName() + "'");
|
||||
return nullptr;
|
||||
}
|
||||
if (!Analysis::MakeAssignmentExpr(base.get(), VariableReference::RefKind::kReadWrite,
|
||||
&fContext.fErrors)) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<PostfixExpression>(std::move(base), op);
|
||||
return PostfixExpression::Make(fContext, std::move(base), expression.getOperator());
|
||||
}
|
||||
|
||||
void IRGenerator::checkValid(const Expression& expr) {
|
||||
|
@ -221,8 +221,6 @@ private:
|
||||
std::unique_ptr<Expression> convertIndexExpression(const ASTNode& expression);
|
||||
std::unique_ptr<Expression> convertIndex(std::unique_ptr<Expression> base,
|
||||
std::unique_ptr<Expression> index);
|
||||
std::unique_ptr<Expression> convertPostfixExpression(std::unique_ptr<Expression> base,
|
||||
Operator op);
|
||||
std::unique_ptr<Expression> convertPostfixExpression(const ASTNode& expression);
|
||||
std::unique_ptr<Expression> convertScopeExpression(const ASTNode& expression);
|
||||
std::unique_ptr<StructDefinition> convertStructDefinition(const ASTNode& expression);
|
||||
|
@ -367,7 +367,7 @@ std::unique_ptr<Expression> Inliner::inlineExpression(int offset,
|
||||
}
|
||||
case Expression::Kind::kPostfix: {
|
||||
const PostfixExpression& p = expression.as<PostfixExpression>();
|
||||
return std::make_unique<PostfixExpression>(expr(p.operand()), p.getOperator());
|
||||
return PostfixExpression::Make(*fContext, expr(p.operand()), p.getOperator());
|
||||
}
|
||||
case Expression::Kind::kSetting:
|
||||
return expression.clone();
|
||||
@ -716,7 +716,8 @@ Inliner::InlinedCall Inliner::inlineCall(FunctionCall* call,
|
||||
fContext->fTypes.fBool.get());
|
||||
|
||||
// _1_loop++
|
||||
std::unique_ptr<Expression> increment = std::make_unique<PostfixExpression>(
|
||||
std::unique_ptr<Expression> increment = PostfixExpression::Make(
|
||||
*fContext,
|
||||
std::make_unique<VariableReference>(/*offset=*/-1, loopVar.fVarSymbol,
|
||||
VariableReference::RefKind::kReadWrite),
|
||||
Token::Kind::TK_PLUSPLUS);
|
||||
|
@ -503,7 +503,7 @@ std::unique_ptr<Expression> Rehydrator::expression() {
|
||||
case Rehydrator::kPostfix_Command: {
|
||||
Token::Kind op = (Token::Kind) this->readU8();
|
||||
std::unique_ptr<Expression> operand = this->expression();
|
||||
return std::make_unique<PostfixExpression>(std::move(operand), op);
|
||||
return PostfixExpression::Make(fContext, std::move(operand), op);
|
||||
}
|
||||
case Rehydrator::kPrefix_Command: {
|
||||
Token::Kind op = (Token::Kind) this->readU8();
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "src/sksl/dsl/DSLCore.h"
|
||||
#include "src/sksl/dsl/DSLErrorHandling.h"
|
||||
#include "src/sksl/ir/SkSLConstructor.h"
|
||||
#include "src/sksl/ir/SkSLPostfixExpression.h"
|
||||
#include "src/sksl/ir/SkSLPrefixExpression.h"
|
||||
#include "src/sksl/ir/SkSLSwitchStatement.h"
|
||||
|
||||
@ -132,7 +133,7 @@ std::unique_ptr<SkSL::Expression> DSLWriter::ConvertIndex(std::unique_ptr<Expres
|
||||
|
||||
std::unique_ptr<SkSL::Expression> DSLWriter::ConvertPostfix(std::unique_ptr<Expression> expr,
|
||||
Operator op) {
|
||||
return IRGenerator().convertPostfixExpression(std::move(expr), op);
|
||||
return PostfixExpression::Make(Context(), std::move(expr), op);
|
||||
}
|
||||
|
||||
std::unique_ptr<SkSL::Expression> DSLWriter::ConvertPrefix(Operator op,
|
||||
|
31
src/sksl/ir/SkSLPostfixExpression.cpp
Normal file
31
src/sksl/ir/SkSLPostfixExpression.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2021 Google LLC
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "src/sksl/SkSLAnalysis.h"
|
||||
#include "src/sksl/SkSLContext.h"
|
||||
#include "src/sksl/ir/SkSLPostfixExpression.h"
|
||||
#include "src/sksl/ir/SkSLVariableReference.h"
|
||||
|
||||
namespace SkSL {
|
||||
|
||||
std::unique_ptr<Expression> PostfixExpression::Make(const Context& context,
|
||||
std::unique_ptr<Expression> base,
|
||||
Operator op) {
|
||||
const Type& baseType = base->type();
|
||||
if (!baseType.isNumber()) {
|
||||
context.fErrors.error(base->fOffset,
|
||||
"'" + String(op.operatorName()) + "' cannot operate on '" +
|
||||
baseType.displayName() + "'");
|
||||
return nullptr;
|
||||
}
|
||||
if (!Analysis::MakeAssignmentExpr(base.get(), VariableRefKind::kReadWrite, &context.fErrors)) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<PostfixExpression>(std::move(base), op);
|
||||
}
|
||||
|
||||
} // namespace SkSL
|
@ -26,6 +26,9 @@ public:
|
||||
, fOperand(std::move(operand))
|
||||
, fOperator(op) {}
|
||||
|
||||
static std::unique_ptr<Expression> Make(const Context& context,
|
||||
std::unique_ptr<Expression> base,
|
||||
Operator op);
|
||||
Operator getOperator() const {
|
||||
return fOperator;
|
||||
}
|
||||
@ -39,15 +42,12 @@ public:
|
||||
}
|
||||
|
||||
bool hasProperty(Property property) const override {
|
||||
if (property == Property::kSideEffects) {
|
||||
return true;
|
||||
}
|
||||
return this->operand()->hasProperty(property);
|
||||
return (property == Property::kSideEffects) ||
|
||||
this->operand()->hasProperty(property);
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> clone() const override {
|
||||
return std::unique_ptr<Expression>(new PostfixExpression(this->operand()->clone(),
|
||||
this->getOperator()));
|
||||
return std::make_unique<PostfixExpression>(this->operand()->clone(), this->getOperator());
|
||||
}
|
||||
|
||||
String description() const override {
|
||||
|
Loading…
Reference in New Issue
Block a user