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 | |
| 18 | namespace SkSL { |
| 19 | |
| 20 | class IRGenerator; |
| 21 | |
| 22 | /** |
| 23 | * Main compiler entry point. This is a traditional compiler design which first parses the .sksl |
| 24 | * file into an abstract syntax tree (a tree of ASTNodes), then performs semantic analysis to |
| 25 | * produce a Program (a tree of IRNodes), then feeds the Program into a CodeGenerator to produce |
| 26 | * compiled output. |
| 27 | */ |
| 28 | class Compiler : public ErrorReporter { |
| 29 | public: |
| 30 | Compiler(); |
| 31 | |
| 32 | ~Compiler(); |
| 33 | |
| 34 | std::unique_ptr<Program> convertProgram(Program::Kind kind, std::string text); |
| 35 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 36 | bool toSPIRV(Program::Kind kind, const std::string& text, std::ostream& out); |
| 37 | |
| 38 | bool toSPIRV(Program::Kind kind, const std::string& text, std::string* out); |
| 39 | |
| 40 | bool toGLSL(Program::Kind kind, const std::string& text, GLCaps caps, std::ostream& out); |
| 41 | |
| 42 | 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] | 43 | |
| 44 | void error(Position position, std::string msg) override; |
| 45 | |
| 46 | std::string errorText(); |
| 47 | |
| 48 | void writeErrorCount(); |
| 49 | |
| 50 | private: |
| 51 | |
| 52 | void internalConvertProgram(std::string text, |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 53 | std::vector<std::unique_ptr<ProgramElement>>* result); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 54 | |
| 55 | std::shared_ptr<SymbolTable> fTypes; |
| 56 | IRGenerator* fIRGenerator; |
| 57 | std::string fSkiaVertText; // FIXME store parsed version instead |
| 58 | |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 59 | Context fContext; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 60 | int fErrorCount; |
| 61 | std::string fErrorText; |
| 62 | }; |
| 63 | |
| 64 | } // namespace |
| 65 | |
| 66 | #endif |