From 22f939e849013b7fc51374c289b5bf37e63dfdb1 Mon Sep 17 00:00:00 2001 From: ethannicholas Date: Thu, 13 Oct 2016 13:25:34 -0700 Subject: added basic dataflow analysis to skslc BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2405383003 Review-Url: https://codereview.chromium.org/2405383003 --- src/sksl/ir/SkSLExpression.h | 1 + src/sksl/ir/SkSLIndexExpression.h | 1 + src/sksl/ir/SkSLInterfaceBlock.h | 2 +- src/sksl/ir/SkSLVarDeclaration.h | 83 ------------------------------ src/sksl/ir/SkSLVarDeclarationStatement.h | 35 ------------- src/sksl/ir/SkSLVarDeclarations.h | 83 ++++++++++++++++++++++++++++++ src/sksl/ir/SkSLVarDeclarationsStatement.h | 35 +++++++++++++ 7 files changed, 121 insertions(+), 119 deletions(-) delete mode 100644 src/sksl/ir/SkSLVarDeclaration.h delete mode 100644 src/sksl/ir/SkSLVarDeclarationStatement.h create mode 100644 src/sksl/ir/SkSLVarDeclarations.h create mode 100644 src/sksl/ir/SkSLVarDeclarationsStatement.h (limited to 'src/sksl/ir') diff --git a/src/sksl/ir/SkSLExpression.h b/src/sksl/ir/SkSLExpression.h index 92cb37de77..b4ed37c09a 100644 --- a/src/sksl/ir/SkSLExpression.h +++ b/src/sksl/ir/SkSLExpression.h @@ -33,6 +33,7 @@ struct Expression : public IRNode { kVariableReference_Kind, kTernary_Kind, kTypeReference_Kind, + kDefined_Kind }; Expression(Position position, Kind kind, const Type& type) diff --git a/src/sksl/ir/SkSLIndexExpression.h b/src/sksl/ir/SkSLIndexExpression.h index ea9af3d897..abd8a03fa4 100644 --- a/src/sksl/ir/SkSLIndexExpression.h +++ b/src/sksl/ir/SkSLIndexExpression.h @@ -8,6 +8,7 @@ #ifndef SKSL_INDEX #define SKSL_INDEX +#include "SkSLContext.h" #include "SkSLExpression.h" #include "SkSLUtil.h" diff --git a/src/sksl/ir/SkSLInterfaceBlock.h b/src/sksl/ir/SkSLInterfaceBlock.h index f1121ed707..debde207a1 100644 --- a/src/sksl/ir/SkSLInterfaceBlock.h +++ b/src/sksl/ir/SkSLInterfaceBlock.h @@ -9,7 +9,7 @@ #define SKSL_INTERFACEBLOCK #include "SkSLProgramElement.h" -#include "SkSLVarDeclaration.h" +#include "SkSLVarDeclarations.h" namespace SkSL { diff --git a/src/sksl/ir/SkSLVarDeclaration.h b/src/sksl/ir/SkSLVarDeclaration.h deleted file mode 100644 index e64a874d69..0000000000 --- a/src/sksl/ir/SkSLVarDeclaration.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_VARDECLARATIONS -#define SKSL_VARDECLARATIONS - -#include "SkSLExpression.h" -#include "SkSLStatement.h" -#include "SkSLVariable.h" - -namespace SkSL { - -/** - * A single variable declaration within a var declaration statement. For instance, the statement - * 'int x = 2, y[3];' is a VarDeclarations statement containing two individual VarDeclaration - * instances. - */ -struct VarDeclaration { - VarDeclaration(const Variable* var, - std::vector> sizes, - std::unique_ptr value) - : fVar(var) - , fSizes(std::move(sizes)) - , fValue(std::move(value)) {} - - std::string description() const { - std::string result = fVar->fName; - for (const auto& size : fSizes) { - if (size) { - result += "[" + size->description() + "]"; - } else { - result += "[]"; - } - } - if (fValue) { - result += " = " + fValue->description(); - } - return result; - } - - const Variable* fVar; - std::vector> fSizes; - std::unique_ptr fValue; -}; - -/** - * A variable declaration statement, which may consist of one or more individual variables. - */ -struct VarDeclarations : public ProgramElement { - VarDeclarations(Position position, const Type* baseType, - std::vector vars) - : INHERITED(position, kVar_Kind) - , fBaseType(*baseType) - , fVars(std::move(vars)) {} - - std::string description() const override { - if (!fVars.size()) { - return ""; - } - std::string result = fVars[0].fVar->fModifiers.description() + fBaseType.description() + - " "; - std::string separator = ""; - for (const auto& var : fVars) { - result += separator; - separator = ", "; - result += var.description(); - } - return result; - } - - const Type& fBaseType; - const std::vector fVars; - - typedef ProgramElement INHERITED; -}; - -} // namespace - -#endif diff --git a/src/sksl/ir/SkSLVarDeclarationStatement.h b/src/sksl/ir/SkSLVarDeclarationStatement.h deleted file mode 100644 index 59d37ab915..0000000000 --- a/src/sksl/ir/SkSLVarDeclarationStatement.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_VARDECLARATIONSTATEMENT -#define SKSL_VARDECLARATIONSTATEMENT - -#include "SkSLStatement.h" -#include "SkSLVarDeclaration.h" - -namespace SkSL { - -/** - * One or more variable declarations appearing as a statement within a function. - */ -struct VarDeclarationsStatement : public Statement { - VarDeclarationsStatement(std::unique_ptr decl) - : INHERITED(decl->fPosition, kVarDeclarations_Kind) - , fDeclaration(std::move(decl)) {} - - std::string description() const override { - return fDeclaration->description(); - } - - const std::shared_ptr fDeclaration; - - typedef Statement INHERITED; -}; - -} // namespace - -#endif diff --git a/src/sksl/ir/SkSLVarDeclarations.h b/src/sksl/ir/SkSLVarDeclarations.h new file mode 100644 index 0000000000..e64a874d69 --- /dev/null +++ b/src/sksl/ir/SkSLVarDeclarations.h @@ -0,0 +1,83 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_VARDECLARATIONS +#define SKSL_VARDECLARATIONS + +#include "SkSLExpression.h" +#include "SkSLStatement.h" +#include "SkSLVariable.h" + +namespace SkSL { + +/** + * A single variable declaration within a var declaration statement. For instance, the statement + * 'int x = 2, y[3];' is a VarDeclarations statement containing two individual VarDeclaration + * instances. + */ +struct VarDeclaration { + VarDeclaration(const Variable* var, + std::vector> sizes, + std::unique_ptr value) + : fVar(var) + , fSizes(std::move(sizes)) + , fValue(std::move(value)) {} + + std::string description() const { + std::string result = fVar->fName; + for (const auto& size : fSizes) { + if (size) { + result += "[" + size->description() + "]"; + } else { + result += "[]"; + } + } + if (fValue) { + result += " = " + fValue->description(); + } + return result; + } + + const Variable* fVar; + std::vector> fSizes; + std::unique_ptr fValue; +}; + +/** + * A variable declaration statement, which may consist of one or more individual variables. + */ +struct VarDeclarations : public ProgramElement { + VarDeclarations(Position position, const Type* baseType, + std::vector vars) + : INHERITED(position, kVar_Kind) + , fBaseType(*baseType) + , fVars(std::move(vars)) {} + + std::string description() const override { + if (!fVars.size()) { + return ""; + } + std::string result = fVars[0].fVar->fModifiers.description() + fBaseType.description() + + " "; + std::string separator = ""; + for (const auto& var : fVars) { + result += separator; + separator = ", "; + result += var.description(); + } + return result; + } + + const Type& fBaseType; + const std::vector fVars; + + typedef ProgramElement INHERITED; +}; + +} // namespace + +#endif diff --git a/src/sksl/ir/SkSLVarDeclarationsStatement.h b/src/sksl/ir/SkSLVarDeclarationsStatement.h new file mode 100644 index 0000000000..0b62edb866 --- /dev/null +++ b/src/sksl/ir/SkSLVarDeclarationsStatement.h @@ -0,0 +1,35 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_VARDECLARATIONSSTATEMENT +#define SKSL_VARDECLARATIONSSTATEMENT + +#include "SkSLStatement.h" +#include "SkSLVarDeclarations.h" + +namespace SkSL { + +/** + * One or more variable declarations appearing as a statement within a function. + */ +struct VarDeclarationsStatement : public Statement { + VarDeclarationsStatement(std::unique_ptr decl) + : INHERITED(decl->fPosition, kVarDeclarations_Kind) + , fDeclaration(std::move(decl)) {} + + std::string description() const override { + return fDeclaration->description(); + } + + const std::shared_ptr fDeclaration; + + typedef Statement INHERITED; +}; + +} // namespace + +#endif -- cgit v1.2.3