blob: 666cb844f7a931eca41a87aaf84f1568524cc657 [file] [log] [blame]
John Stilesdc8ec312021-01-11 11:05:21 -05001/*
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
15namespace SkSL {
16
17class Context;
18class ErrorReporter;
19class 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 */
25class ConstantFolder {
26public:
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