blob: 9cd1eac3f94f75520d789a63ece3b8e8d9ea4330 [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"
ethannicholasd598f792016-07-25 10:08:54 -070014#include "SkSLContext.h"
ethannicholasb3058bd2016-07-01 08:22:01 -070015#include "SkSLErrorReporter.h"
ethannicholasf789b382016-08-03 12:43:36 -070016#include "SkSLGLSLCodeGenerator.h"
ethannicholasb3058bd2016-07-01 08:22:01 -070017
18namespace SkSL {
19
20class 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 */
28class Compiler : public ErrorReporter {
29public:
30 Compiler();
31
32 ~Compiler();
33
34 std::unique_ptr<Program> convertProgram(Program::Kind kind, std::string text);
35
ethannicholasf789b382016-08-03 12:43:36 -070036 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);
ethannicholasb3058bd2016-07-01 08:22:01 -070043
44 void error(Position position, std::string msg) override;
45
46 std::string errorText();
47
48 void writeErrorCount();
49
50private:
51
52 void internalConvertProgram(std::string text,
ethannicholasf789b382016-08-03 12:43:36 -070053 std::vector<std::unique_ptr<ProgramElement>>* result);
ethannicholasb3058bd2016-07-01 08:22:01 -070054
55 std::shared_ptr<SymbolTable> fTypes;
56 IRGenerator* fIRGenerator;
57 std::string fSkiaVertText; // FIXME store parsed version instead
58
ethannicholasd598f792016-07-25 10:08:54 -070059 Context fContext;
ethannicholasb3058bd2016-07-01 08:22:01 -070060 int fErrorCount;
61 std::string fErrorText;
62};
63
64} // namespace
65
66#endif