/* * 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 #include #include "ir/SkSLProgram.h" #include "ir/SkSLSymbolTable.h" #include "SkSLCFGGenerator.h" #include "SkSLContext.h" #include "SkSLErrorReporter.h" #include "SkSLGLSLCodeGenerator.h" #define SK_FRAGCOLOR_BUILTIN 10001 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. * * See the README for information about SkSL. */ class Compiler : public ErrorReporter { public: Compiler(); ~Compiler(); std::unique_ptr 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, const GrGLSLCaps& caps, std::ostream& out); bool toGLSL(Program::Kind kind, const std::string& text, const GrGLSLCaps& caps, std::string* out); void error(Position position, std::string msg) override; std::string errorText(); void writeErrorCount(); private: void addDefinition(const Expression* lvalue, const Expression* expr, std::unordered_map* definitions); void addDefinitions(const BasicBlock::Node& node, std::unordered_map* definitions); void scanCFG(CFG* cfg, BlockId block, std::set* workList); void scanCFG(const FunctionDefinition& f); void internalConvertProgram(std::string text, Modifiers::Flag* defaultPrecision, std::vector>* result); std::shared_ptr fTypes; IRGenerator* fIRGenerator; std::string fSkiaVertText; // FIXME store parsed version instead Context fContext; int fErrorCount; std::string fErrorText; }; } // namespace #endif