ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SKSL_COMPILER |
| 9 | #define SKSL_COMPILER |
| 10 | |
| 11 | #include <vector> |
| 12 | #include "ir/SkSLProgram.h" |
| 13 | #include "ir/SkSLSymbolTable.h" |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 14 | #include "SkSLContext.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 15 | #include "SkSLErrorReporter.h" |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 16 | #include "SkSLGLSLCodeGenerator.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 17 | |
ethannicholas | dcfe6db | 2016-10-10 10:09:00 -0700 | [diff] [blame^] | 18 | #define SK_FRAGCOLOR_BUILTIN 10001 |
| 19 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 20 | namespace SkSL { |
| 21 | |
| 22 | class IRGenerator; |
| 23 | |
| 24 | /** |
| 25 | * Main compiler entry point. This is a traditional compiler design which first parses the .sksl |
| 26 | * file into an abstract syntax tree (a tree of ASTNodes), then performs semantic analysis to |
| 27 | * produce a Program (a tree of IRNodes), then feeds the Program into a CodeGenerator to produce |
| 28 | * compiled output. |
ethannicholas | dcfe6db | 2016-10-10 10:09:00 -0700 | [diff] [blame^] | 29 | * |
| 30 | * See the README for information about SkSL. |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 31 | */ |
| 32 | class Compiler : public ErrorReporter { |
| 33 | public: |
| 34 | Compiler(); |
| 35 | |
| 36 | ~Compiler(); |
| 37 | |
| 38 | std::unique_ptr<Program> convertProgram(Program::Kind kind, std::string text); |
| 39 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 40 | bool toSPIRV(Program::Kind kind, const std::string& text, std::ostream& out); |
| 41 | |
| 42 | bool toSPIRV(Program::Kind kind, const std::string& text, std::string* out); |
| 43 | |
| 44 | bool toGLSL(Program::Kind kind, const std::string& text, GLCaps caps, std::ostream& out); |
| 45 | |
| 46 | bool toGLSL(Program::Kind kind, const std::string& text, GLCaps caps, std::string* out); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 47 | |
| 48 | void error(Position position, std::string msg) override; |
| 49 | |
| 50 | std::string errorText(); |
| 51 | |
| 52 | void writeErrorCount(); |
| 53 | |
| 54 | private: |
| 55 | |
| 56 | void internalConvertProgram(std::string text, |
ethannicholas | dcfe6db | 2016-10-10 10:09:00 -0700 | [diff] [blame^] | 57 | Modifiers::Flag* defaultPrecision, |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 58 | std::vector<std::unique_ptr<ProgramElement>>* result); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 59 | |
| 60 | std::shared_ptr<SymbolTable> fTypes; |
| 61 | IRGenerator* fIRGenerator; |
| 62 | std::string fSkiaVertText; // FIXME store parsed version instead |
| 63 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 64 | Context fContext; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 65 | int fErrorCount; |
| 66 | std::string fErrorText; |
| 67 | }; |
| 68 | |
| 69 | } // namespace |
| 70 | |
| 71 | #endif |