Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(916)

Unified Diff: src/sksl/SkSLIRGenerator.h

Issue 1984363002: initial checkin of SkSL compiler (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: more cleanups Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/sksl/SkSLIRGenerator.h
diff --git a/src/sksl/SkSLIRGenerator.h b/src/sksl/SkSLIRGenerator.h
new file mode 100644
index 0000000000000000000000000000000000000000..3d8e315ad041126b14ecf597f228b6225a762d1f
--- /dev/null
+++ b/src/sksl/SkSLIRGenerator.h
@@ -0,0 +1,120 @@
+/*
+ * 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_IRGENERATOR
+#define SKSL_IRGENERATOR
+
+#include "SkSLErrorReporter.h"
+#include "ast/SkSLASTBinaryExpression.h"
+#include "ast/SkSLASTBlock.h"
+#include "ast/SkSLASTBreakStatement.h"
+#include "ast/SkSLASTCallSuffix.h"
+#include "ast/SkSLASTContinueStatement.h"
+#include "ast/SkSLASTDiscardStatement.h"
+#include "ast/SkSLASTDoStatement.h"
+#include "ast/SkSLASTExpression.h"
+#include "ast/SkSLASTExpressionStatement.h"
+#include "ast/SkSLASTExtension.h"
+#include "ast/SkSLASTForStatement.h"
+#include "ast/SkSLASTFunction.h"
+#include "ast/SkSLASTIdentifier.h"
+#include "ast/SkSLASTIfStatement.h"
+#include "ast/SkSLASTInterfaceBlock.h"
+#include "ast/SkSLASTModifiers.h"
+#include "ast/SkSLASTPrefixExpression.h"
+#include "ast/SkSLASTReturnStatement.h"
+#include "ast/SkSLASTStatement.h"
+#include "ast/SkSLASTSuffixExpression.h"
+#include "ast/SkSLASTTernaryExpression.h"
+#include "ast/SkSLASTVarDeclaration.h"
+#include "ast/SkSLASTVarDeclarationStatement.h"
+#include "ast/SkSLASTWhileStatement.h"
+#include "ir/SkSLBlock.h"
+#include "ir/SkSLExpression.h"
+#include "ir/SkSLExtension.h"
+#include "ir/SkSLFunctionDefinition.h"
+#include "ir/SkSLInterfaceBlock.h"
+#include "ir/SkSLModifiers.h"
+#include "ir/SkSLSymbolTable.h"
+#include "ir/SkSLStatement.h"
+#include "ir/SkSLType.h"
+#include "ir/SkSLTypeReference.h"
+#include "ir/SkSLVarDeclaration.h"
+
+namespace SkSL {
+
+/**
+ * Performs semantic analysis on an abstract syntax tree (AST) and produces the corresponding
+ * (unoptimized) intermediate representation (IR).
+ */
+class IRGenerator {
+public:
+ IRGenerator(std::shared_ptr<SymbolTable> root, ErrorReporter& errorReporter);
dogben 2016/06/23 15:25:12 nit: if the caller will hang on to SymbolTable for
+
+ std::unique_ptr<VarDeclaration> convertVarDeclaration(ASTVarDeclaration& decl,
dogben 2016/06/23 15:25:12 nit: document how each method will modify the AST
+ Variable::Storage storage);
+ std::unique_ptr<FunctionDefinition> convertFunction(ASTFunction& f);
+ std::unique_ptr<Statement> convertStatement(ASTStatement& statement);
+ std::unique_ptr<Expression> convertExpression(ASTExpression& expression);
+
+private:
+ void pushSymbolTable();
+ void popSymbolTable();
+
+ std::shared_ptr<Type> convertType(ASTType& type);
+ std::unique_ptr<Expression> call(Position position,
+ std::shared_ptr<FunctionDeclaration> function,
+ std::vector<std::unique_ptr<Expression>> parameters);
dogben 2016/06/23 15:25:12 nit: s/parameters/arguments/, several places in th
+ bool determineCallCost(std::shared_ptr<FunctionDeclaration> function,
+ std::vector<std::unique_ptr<Expression>>& parameters,
+ int* outCost);
+ std::unique_ptr<Expression> call(Position position, std::unique_ptr<Expression> function,
+ std::vector<std::unique_ptr<Expression>> parameters);
+ std::unique_ptr<Expression> coerce(std::unique_ptr<Expression> expr,
+ std::shared_ptr<Type> type);
+ std::unique_ptr<Block> convertBlock(ASTBlock& block);
+ std::unique_ptr<Statement> convertBreak(ASTBreakStatement& b);
+ std::unique_ptr<Expression> convertConstructor(Position position,
+ std::shared_ptr<Type> type,
+ std::vector<std::unique_ptr<Expression>> params);
+ std::unique_ptr<Statement> convertContinue(ASTContinueStatement& c);
+ std::unique_ptr<Statement> convertDiscard(ASTDiscardStatement& d);
+ std::unique_ptr<Statement> convertDo(ASTDoStatement& d);
+ std::unique_ptr<Expression> convertBinaryExpression(ASTBinaryExpression& expression);
+ std::unique_ptr<Extension> convertExtension(ASTExtension& e);
+ std::unique_ptr<Statement> convertExpressionStatement(ASTExpressionStatement& s);
+ std::unique_ptr<Statement> convertFor(ASTForStatement& f);
+ std::unique_ptr<Expression> convertIdentifier(ASTIdentifier& identifier);
+ std::unique_ptr<Statement> convertIf(ASTIfStatement& s);
+ std::unique_ptr<Expression> convertIndex(std::unique_ptr<Expression> base,
+ ASTExpression& index);
+ std::unique_ptr<InterfaceBlock> convertInterfaceBlock(ASTInterfaceBlock& s);
+ Modifiers convertModifiers(const ASTModifiers& m);
+ std::unique_ptr<Expression> convertPrefixExpression(ASTPrefixExpression& expression);
+ std::unique_ptr<Statement> convertReturn(ASTReturnStatement& r);
+ std::unique_ptr<Expression> convertSuffixExpression(ASTSuffixExpression& expression);
+ std::unique_ptr<Expression> convertField(std::unique_ptr<Expression> base, std::string field);
+ std::unique_ptr<Expression> convertSwizzle(std::unique_ptr<Expression> base,
+ std::string fields);
+ std::unique_ptr<Expression> convertTernaryExpression(ASTTernaryExpression& expression);
+ std::unique_ptr<Statement> convertVarDeclarationStatement(ASTVarDeclarationStatement& s);
+ std::unique_ptr<Statement> convertWhile(ASTWhileStatement& w);
+
+ void markReadFrom(std::shared_ptr<Variable> var);
+ void markWrittenTo(Expression& expr);
+
+ std::shared_ptr<FunctionDeclaration> fCurrentFunction;
+ std::shared_ptr<SymbolTable> fSymbolTable;
+ ErrorReporter& fErrors;
+
+ friend class AutoSymbolTable;
+ friend class Compiler;
+};
+
+}
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698