John Stiles | dc8ec31 | 2021-01-11 11:05:21 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2020 Google LLC |
| 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_CONSTANT_FOLDER |
| 9 | #define SKSL_CONSTANT_FOLDER |
| 10 | |
| 11 | #include <memory> |
| 12 | |
| 13 | #include "src/sksl/SkSLLexer.h" |
| 14 | |
| 15 | namespace SkSL { |
| 16 | |
| 17 | class Context; |
| 18 | class ErrorReporter; |
| 19 | class Expression; |
| 20 | |
| 21 | /** |
| 22 | * Performs constant folding on IR expressions. This simplifies expressions containing |
| 23 | * compile-time constants, such as replacing `IntLiteral(2) + IntLiteral(2)` with `IntLiteral(4)`. |
| 24 | */ |
| 25 | class ConstantFolder { |
| 26 | public: |
| 27 | /** Simplifies the binary expression `left OP right`. Returns null if it can't be simplified. */ |
| 28 | static std::unique_ptr<Expression> Simplify(const Context& context, |
| 29 | ErrorReporter& errors, |
| 30 | const Expression& left, |
| 31 | Token::Kind op, |
| 32 | const Expression& right); |
| 33 | }; |
| 34 | |
| 35 | } // namespace SkSL |
| 36 | |
| 37 | #endif // SKSL_CONSTANT_FOLDER |