OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SKSL_IRGENERATOR | 8 #ifndef SKSL_IRGENERATOR |
9 #define SKSL_IRGENERATOR | 9 #define SKSL_IRGENERATOR |
10 | 10 |
11 #include "SkSLErrorReporter.h" | 11 #include "SkSLErrorReporter.h" |
12 #include "ast/SkSLASTBinaryExpression.h" | 12 #include "ast/SkSLASTBinaryExpression.h" |
13 #include "ast/SkSLASTBlock.h" | 13 #include "ast/SkSLASTBlock.h" |
14 #include "ast/SkSLASTBreakStatement.h" | 14 #include "ast/SkSLASTBreakStatement.h" |
15 #include "ast/SkSLASTCallSuffix.h" | 15 #include "ast/SkSLASTCallSuffix.h" |
16 #include "ast/SkSLASTContinueStatement.h" | 16 #include "ast/SkSLASTContinueStatement.h" |
17 #include "ast/SkSLASTDiscardStatement.h" | 17 #include "ast/SkSLASTDiscardStatement.h" |
18 #include "ast/SkSLASTDoStatement.h" | 18 #include "ast/SkSLASTDoStatement.h" |
19 #include "ast/SkSLASTExpression.h" | 19 #include "ast/SkSLASTExpression.h" |
20 #include "ast/SkSLASTExpressionStatement.h" | 20 #include "ast/SkSLASTExpressionStatement.h" |
21 #include "ast/SkSLASTExtension.h" | 21 #include "ast/SkSLASTExtension.h" |
22 #include "ast/SkSLASTForStatement.h" | 22 #include "ast/SkSLASTForStatement.h" |
23 #include "ast/SkSLASTFunction.h" | 23 #include "ast/SkSLASTFunction.h" |
24 #include "ast/SkSLASTIdentifier.h" | 24 #include "ast/SkSLASTIdentifier.h" |
25 #include "ast/SkSLASTIfStatement.h" | 25 #include "ast/SkSLASTIfStatement.h" |
26 #include "ast/SkSLASTInterfaceBlock.h" | 26 #include "ast/SkSLASTInterfaceBlock.h" |
27 #include "ast/SkSLASTModifiers.h" | 27 #include "ast/SkSLASTModifiers.h" |
28 #include "ast/SkSLASTModifiersDeclaration.h" | |
29 #include "ast/SkSLASTPrefixExpression.h" | 28 #include "ast/SkSLASTPrefixExpression.h" |
30 #include "ast/SkSLASTReturnStatement.h" | 29 #include "ast/SkSLASTReturnStatement.h" |
31 #include "ast/SkSLASTStatement.h" | 30 #include "ast/SkSLASTStatement.h" |
32 #include "ast/SkSLASTSuffixExpression.h" | 31 #include "ast/SkSLASTSuffixExpression.h" |
33 #include "ast/SkSLASTTernaryExpression.h" | 32 #include "ast/SkSLASTTernaryExpression.h" |
34 #include "ast/SkSLASTVarDeclaration.h" | 33 #include "ast/SkSLASTVarDeclaration.h" |
35 #include "ast/SkSLASTVarDeclarationStatement.h" | 34 #include "ast/SkSLASTVarDeclarationStatement.h" |
36 #include "ast/SkSLASTWhileStatement.h" | 35 #include "ast/SkSLASTWhileStatement.h" |
37 #include "ir/SkSLBlock.h" | 36 #include "ir/SkSLBlock.h" |
38 #include "ir/SkSLExpression.h" | 37 #include "ir/SkSLExpression.h" |
39 #include "ir/SkSLExtension.h" | 38 #include "ir/SkSLExtension.h" |
40 #include "ir/SkSLFunctionDefinition.h" | 39 #include "ir/SkSLFunctionDefinition.h" |
41 #include "ir/SkSLInterfaceBlock.h" | 40 #include "ir/SkSLInterfaceBlock.h" |
42 #include "ir/SkSLModifiers.h" | 41 #include "ir/SkSLModifiers.h" |
43 #include "ir/SkSLModifiersDeclaration.h" | |
44 #include "ir/SkSLSymbolTable.h" | 42 #include "ir/SkSLSymbolTable.h" |
45 #include "ir/SkSLStatement.h" | 43 #include "ir/SkSLStatement.h" |
46 #include "ir/SkSLType.h" | 44 #include "ir/SkSLType.h" |
47 #include "ir/SkSLTypeReference.h" | 45 #include "ir/SkSLTypeReference.h" |
48 #include "ir/SkSLVarDeclaration.h" | 46 #include "ir/SkSLVarDeclaration.h" |
49 | 47 |
50 namespace SkSL { | 48 namespace SkSL { |
51 | 49 |
52 /** | 50 /** |
53 * Performs semantic analysis on an abstract syntax tree (AST) and produces the
corresponding | 51 * Performs semantic analysis on an abstract syntax tree (AST) and produces the
corresponding |
54 * (unoptimized) intermediate representation (IR). | 52 * (unoptimized) intermediate representation (IR). |
55 */ | 53 */ |
56 class IRGenerator { | 54 class IRGenerator { |
57 public: | 55 public: |
58 IRGenerator(const Context* context, std::shared_ptr<SymbolTable> root, | 56 IRGenerator(const Context* context, std::shared_ptr<SymbolTable> root, |
59 ErrorReporter& errorReporter); | 57 ErrorReporter& errorReporter); |
60 | 58 |
61 std::unique_ptr<VarDeclarations> convertVarDeclarations(const ASTVarDeclarat
ions& decl, | 59 std::unique_ptr<VarDeclarations> convertVarDeclarations(const ASTVarDeclarat
ions& decl, |
62 Variable::Storage st
orage); | 60 Variable::Storage st
orage); |
63 std::unique_ptr<FunctionDefinition> convertFunction(const ASTFunction& f); | 61 std::unique_ptr<FunctionDefinition> convertFunction(const ASTFunction& f); |
64 std::unique_ptr<Statement> convertStatement(const ASTStatement& statement); | 62 std::unique_ptr<Statement> convertStatement(const ASTStatement& statement); |
65 std::unique_ptr<Expression> convertExpression(const ASTExpression& expressio
n); | 63 std::unique_ptr<Expression> convertExpression(const ASTExpression& expressio
n); |
66 std::unique_ptr<ModifiersDeclaration> convertModifiersDeclaration( | |
67 const ASTModif
iersDeclaration& m); | |
68 | 64 |
69 private: | 65 private: |
70 void pushSymbolTable(); | 66 void pushSymbolTable(); |
71 void popSymbolTable(); | 67 void popSymbolTable(); |
72 | 68 |
73 const Type* convertType(const ASTType& type); | 69 const Type* convertType(const ASTType& type); |
74 std::unique_ptr<Expression> call(Position position, | 70 std::unique_ptr<Expression> call(Position position, |
75 const FunctionDeclaration& function, | 71 const FunctionDeclaration& function, |
76 std::vector<std::unique_ptr<Expression>> ar
guments); | 72 std::vector<std::unique_ptr<Expression>> ar
guments); |
77 bool determineCallCost(const FunctionDeclaration& function, | 73 bool determineCallCost(const FunctionDeclaration& function, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 std::shared_ptr<SymbolTable> fSymbolTable; | 114 std::shared_ptr<SymbolTable> fSymbolTable; |
119 ErrorReporter& fErrors; | 115 ErrorReporter& fErrors; |
120 | 116 |
121 friend class AutoSymbolTable; | 117 friend class AutoSymbolTable; |
122 friend class Compiler; | 118 friend class Compiler; |
123 }; | 119 }; |
124 | 120 |
125 } | 121 } |
126 | 122 |
127 #endif | 123 #endif |
OLD | NEW |