aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLInterpreter.h
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2018-03-27 14:10:52 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-27 18:39:13 +0000
commit26a9aad63b60c9cbbdfa87c212a4e76ce55e7373 (patch)
treed4a42afd75bdff6c7815be7bf78b42cab742df19 /src/sksl/SkSLInterpreter.h
parent3560b58de36988e1fba54d9ac341735ab849e913 (diff)
initial SkSLJIT checkin
Docs-Preview: https://skia.org/?cl=112204 Bug: skia: Change-Id: I10042a0200db00bd8ff8078467c409b1cf191f50 Reviewed-on: https://skia-review.googlesource.com/112204 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/sksl/SkSLInterpreter.h')
-rw-r--r--src/sksl/SkSLInterpreter.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/sksl/SkSLInterpreter.h b/src/sksl/SkSLInterpreter.h
new file mode 100644
index 0000000000..93f32a1617
--- /dev/null
+++ b/src/sksl/SkSLInterpreter.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SKSL_INTERPRETER
+#define SKSL_INTERPRETER
+
+#include "ir/SkSLAppendStage.h"
+#include "ir/SkSLExpression.h"
+#include "ir/SkSLFunctionCall.h"
+#include "ir/SkSLFunctionDefinition.h"
+#include "ir/SkSLProgram.h"
+#include "ir/SkSLStatement.h"
+
+#include <stack>
+
+class SkRasterPipeline;
+
+namespace SkSL {
+
+class Interpreter {
+ typedef int StackIndex;
+
+ struct StatementIndex {
+ const Statement* fStatement;
+ size_t fIndex;
+ };
+
+public:
+ union Value {
+ Value(float f)
+ : fFloat(f) {}
+
+ Value(int i)
+ : fInt(i) {}
+
+ Value(bool b)
+ : fBool(b) {}
+
+ float fFloat;
+ int fInt;
+ bool fBool;
+ };
+
+ enum TypeKind {
+ kFloat_TypeKind,
+ kInt_TypeKind,
+ kBool_TypeKind
+ };
+
+ Interpreter(std::unique_ptr<Program> program, SkRasterPipeline* pipeline, std::vector<Value>* stack)
+ : fProgram(std::move(program))
+ , fPipeline(*pipeline)
+ , fStack(*stack) {}
+
+ void run();
+
+ void run(const FunctionDefinition& f);
+
+ void push(Value value);
+
+ Value pop();
+
+ StackIndex stackAlloc(int count);
+
+ void runStatement();
+
+ StackIndex getLValue(const Expression& expr);
+
+ Value call(const FunctionCall& c);
+
+ void appendStage(const AppendStage& c);
+
+ Value evaluate(const Expression& expr);
+
+private:
+ std::unique_ptr<Program> fProgram;
+ SkRasterPipeline& fPipeline;
+ std::vector<StatementIndex> fCurrentIndex;
+ std::vector<std::map<const Variable*, StackIndex>> fVars;
+ std::vector<Value> &fStack;
+};
+
+} // namespace
+
+#endif