ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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_VARIABLE |
| 9 | #define SKSL_VARIABLE |
| 10 | |
| 11 | #include "SkSLModifiers.h" |
| 12 | #include "SkSLPosition.h" |
| 13 | #include "SkSLSymbol.h" |
| 14 | #include "SkSLType.h" |
| 15 | |
| 16 | namespace SkSL { |
| 17 | |
| 18 | /** |
| 19 | * Represents a variable, whether local, global, or a function parameter. This represents the |
| 20 | * variable itself (the storage location), which is shared between all VariableReferences which |
| 21 | * read or write that storage location. |
| 22 | */ |
| 23 | struct Variable : public Symbol { |
| 24 | enum Storage { |
| 25 | kGlobal_Storage, |
| 26 | kLocal_Storage, |
| 27 | kParameter_Storage |
| 28 | }; |
| 29 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 30 | Variable(Position position, Modifiers modifiers, SkString name, const Type& type, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 31 | Storage storage) |
| 32 | : INHERITED(position, kVariable_Kind, std::move(name)) |
| 33 | , fModifiers(modifiers) |
| 34 | , fType(type) |
| 35 | , fStorage(storage) |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame^] | 36 | , fReadCount(0) |
| 37 | , fWriteCount(0) {} |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 38 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame] | 39 | virtual SkString description() const override { |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 40 | return fModifiers.description() + fType.fName + " " + fName; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 41 | } |
| 42 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 43 | mutable Modifiers fModifiers; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 44 | const Type& fType; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 45 | const Storage fStorage; |
| 46 | |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame^] | 47 | // Tracks how many sites read from the variable. If this is zero for a non-out variable (or |
| 48 | // becomes zero during optimization), the variable is dead and may be eliminated. |
| 49 | mutable int fReadCount; |
| 50 | // Tracks how many sites write to the variable. If this is zero, the variable is dead and may be |
| 51 | // eliminated. |
| 52 | mutable int fWriteCount; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 53 | |
| 54 | typedef Symbol INHERITED; |
| 55 | }; |
| 56 | |
| 57 | } // namespace SkSL |
| 58 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 59 | #endif |