blob: 96ae7d06bcc96f0e0631c49c4183028e59c6431b [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
ethannicholasdcfe6db2016-10-10 10:09:00 -070018#define SK_FRAGCOLOR_BUILTIN 10001
19
ethannicholasb3058bd2016-07-01 08:22:01 -070020namespace SkSL {
21
22class 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.
ethannicholasdcfe6db2016-10-10 10:09:00 -070029 *
30 * See the README for information about SkSL.
ethannicholasb3058bd2016-07-01 08:22:01 -070031 */
32class Compiler : public ErrorReporter {
33public:
34 Compiler();
35
36 ~Compiler();
37
38 std::unique_ptr<Program> convertProgram(Program::Kind kind, std::string text);
39
ethannicholasf789b382016-08-03 12:43:36 -070040 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);
ethannicholasb3058bd2016-07-01 08:22:01 -070047
48 void error(Position position, std::string msg) override;
49
50 std::string errorText();
51
52 void writeErrorCount();
53
54private:
55
56 void internalConvertProgram(std::string text,
ethannicholasdcfe6db2016-10-10 10:09:00 -070057 Modifiers::Flag* defaultPrecision,
ethannicholasf789b382016-08-03 12:43:36 -070058 std::vector<std::unique_ptr<ProgramElement>>* result);
ethannicholasb3058bd2016-07-01 08:22:01 -070059
60 std::shared_ptr<SymbolTable> fTypes;
61 IRGenerator* fIRGenerator;
62 std::string fSkiaVertText; // FIXME store parsed version instead
63
ethannicholasd598f792016-07-25 10:08:54 -070064 Context fContext;
ethannicholasb3058bd2016-07-01 08:22:01 -070065 int fErrorCount;
66 std::string fErrorText;
67};
68
69} // namespace
70
71#endif