aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLCompiler.h
blob: 9cd1eac3f94f75520d789a63ece3b8e8d9ea4330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
 
#ifndef SKSL_COMPILER
#define SKSL_COMPILER

#include <vector>
#include "ir/SkSLProgram.h"
#include "ir/SkSLSymbolTable.h"
#include "SkSLContext.h"
#include "SkSLErrorReporter.h"
#include "SkSLGLSLCodeGenerator.h"

namespace SkSL {

class IRGenerator;

/**
 * Main compiler entry point. This is a traditional compiler design which first parses the .sksl
 * file into an abstract syntax tree (a tree of ASTNodes), then performs semantic analysis to 
 * produce a Program (a tree of IRNodes), then feeds the Program into a CodeGenerator to produce
 * compiled output.
 */
class Compiler : public ErrorReporter {
public:
    Compiler();

    ~Compiler();

    std::unique_ptr<Program> convertProgram(Program::Kind kind, std::string text);

    bool toSPIRV(Program::Kind kind, const std::string& text, std::ostream& out);
    
    bool toSPIRV(Program::Kind kind, const std::string& text, std::string* out);

    bool toGLSL(Program::Kind kind, const std::string& text, GLCaps caps, std::ostream& out);
    
    bool toGLSL(Program::Kind kind, const std::string& text, GLCaps caps, std::string* out);

    void error(Position position, std::string msg) override;

    std::string errorText();

    void writeErrorCount();

private:

    void internalConvertProgram(std::string text,
                                std::vector<std::unique_ptr<ProgramElement>>* result);

    std::shared_ptr<SymbolTable> fTypes;
    IRGenerator* fIRGenerator;
    std::string fSkiaVertText; // FIXME store parsed version instead

    Context fContext;
    int fErrorCount;
    std::string fErrorText;
};

} // namespace

#endif