2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
13 #include "ir/SkSLProgram.h"
14 #include "ir/SkSLSymbolTable.h"
15 #include "SkSLCFGGenerator.h"
16 #include "SkSLContext.h"
17 #include "SkSLErrorReporter.h"
18 #include "SkSLIRGenerator.h"
20 #define SK_FRAGCOLOR_BUILTIN 10001
21 #define SK_IN_BUILTIN 10002
22 #define SK_FRAGCOORD_BUILTIN 15
23 #define SK_VERTEXID_BUILTIN 5
24 #define SK_CLIPDISTANCE_BUILTIN 3
25 #define SK_INVOCATIONID_BUILTIN 8
32 * Main compiler entry point. This is a traditional compiler design which first parses the .sksl
33 * file into an abstract syntax tree (a tree of ASTNodes), then performs semantic analysis to
34 * produce a Program (a tree of IRNodes), then feeds the Program into a CodeGenerator to produce
37 * See the README for information about SkSL.
39 class Compiler : public ErrorReporter {
45 std::unique_ptr<Program> convertProgram(Program::Kind kind, SkString text,
46 const Program::Settings& settings);
48 bool toSPIRV(const Program& program, SkWStream& out);
50 bool toSPIRV(const Program& program, SkString* out);
52 bool toGLSL(const Program& program, SkWStream& out);
54 bool toGLSL(const Program& program, SkString* out);
56 void error(Position position, SkString msg) override;
60 void writeErrorCount();
62 int errorCount() override {
67 void addDefinition(const Expression* lvalue, std::unique_ptr<Expression>* expr,
68 DefinitionMap* definitions);
70 void addDefinitions(const BasicBlock::Node& node, DefinitionMap* definitions);
72 void scanCFG(CFG* cfg, BlockId block, std::set<BlockId>* workList);
74 void scanCFG(const FunctionDefinition& f);
76 void internalConvertProgram(SkString text,
77 Modifiers::Flag* defaultPrecision,
78 std::vector<std::unique_ptr<ProgramElement>>* result);
80 std::shared_ptr<SymbolTable> fTypes;
81 IRGenerator* fIRGenerator;
82 SkString fSkiaVertText; // FIXME store parsed version instead