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" |
| 14 | #include "SkSLErrorReporter.h" |
| 15 | |
| 16 | namespace SkSL { |
| 17 | |
| 18 | class IRGenerator; |
| 19 | |
| 20 | /** |
| 21 | * Main compiler entry point. This is a traditional compiler design which first parses the .sksl |
| 22 | * file into an abstract syntax tree (a tree of ASTNodes), then performs semantic analysis to |
| 23 | * produce a Program (a tree of IRNodes), then feeds the Program into a CodeGenerator to produce |
| 24 | * compiled output. |
| 25 | */ |
| 26 | class Compiler : public ErrorReporter { |
| 27 | public: |
| 28 | Compiler(); |
| 29 | |
| 30 | ~Compiler(); |
| 31 | |
| 32 | std::unique_ptr<Program> convertProgram(Program::Kind kind, std::string text); |
| 33 | |
| 34 | bool toSPIRV(Program::Kind kind, std::string text, std::ostream& out); |
| 35 | |
| 36 | bool toSPIRV(Program::Kind kind, std::string text, std::string* out); |
| 37 | |
| 38 | void error(Position position, std::string msg) override; |
| 39 | |
| 40 | std::string errorText(); |
| 41 | |
| 42 | void writeErrorCount(); |
| 43 | |
| 44 | private: |
| 45 | |
| 46 | void internalConvertProgram(std::string text, |
| 47 | std::vector<std::unique_ptr<ProgramElement>>* result); |
| 48 | |
| 49 | std::shared_ptr<SymbolTable> fTypes; |
| 50 | IRGenerator* fIRGenerator; |
| 51 | std::string fSkiaVertText; // FIXME store parsed version instead |
| 52 | |
| 53 | int fErrorCount; |
| 54 | std::string fErrorText; |
| 55 | }; |
| 56 | |
| 57 | } // namespace |
| 58 | |
| 59 | #endif |