1/*
2 * Copyright 2019 Google Inc.
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_DEFINES
9#define SKSL_DEFINES
10
11#include <cstdint>
12
13#include "include/core/SkTypes.h"
14#include "include/private/SkTArray.h"
15
16using SKSL_INT = int64_t;
17using SKSL_FLOAT = float;
18
19namespace SkSL {
20
21class Expression;
22class Statement;
23
24using ComponentArray = SkSTArray<4, int8_t>; // for Swizzles
25using ExpressionArray = SkSTArray<2, std::unique_ptr<Expression>>;
26using StatementArray = SkSTArray<2, std::unique_ptr<Statement>>;
27
28// Functions larger than this (measured in IR nodes) will not be inlined. This growth factor
29// accounts for the number of calls being inlined--i.e., a function called five times (that is, with
30// five inlining opportunities) would be considered 5x larger than if it were called once. This
31// default threshold value is arbitrary, but tends to work well in practice.
32static constexpr int kDefaultInlineThreshold = 50;
33
34// A hard upper limit on the number of variable slots allowed in a function/global scope.
35// This is an arbitrary limit, but is needed to prevent code generation from taking unbounded
36// amounts of time or space.
37static constexpr int kVariableSlotLimit = 100000;
38
39// The SwizzleComponent namespace is used both by the SkSL::Swizzle expression, and the DSL swizzle.
40// This namespace is injected into SkSL::dsl so that `using namespace SkSL::dsl` enables DSL code
41// like `Swizzle(var, X, Y, ONE)` to compile without any extra qualifications.
42namespace SwizzleComponent {
43
44enum Type : int8_t {
45    X  =  0,  Y =  1,  Z =  2,  W =  3,
46    R  =  4,  G =  5,  B =  6,  A =  7,
47    S  =  8,  T =  9,  P = 10,  Q = 11,
48    UL = 12, UT = 13, UR = 14, UB = 15,
49    ZERO,
50    ONE
51};
52
53}  // namespace SwizzleComponent
54}  // namespace SkSL
55
56#endif
57