blob: 2209427eef058b17107d9ba302f6590a2ac1e0ab [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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
16namespace SkSL {
17
18class 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 */
26class Compiler : public ErrorReporter {
27public:
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
44private:
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