blob: 2c3391dfa207057ea7da07c77e14e3d7d056c189 [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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
16namespace 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 */
23struct Variable : public Symbol {
24 enum Storage {
25 kGlobal_Storage,
26 kLocal_Storage,
27 kParameter_Storage
28 };
29
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050030 Variable(Position position, Modifiers modifiers, SkString name, const Type& type,
ethannicholasb3058bd2016-07-01 08:22:01 -070031 Storage storage)
32 : INHERITED(position, kVariable_Kind, std::move(name))
33 , fModifiers(modifiers)
34 , fType(type)
35 , fStorage(storage)
Ethan Nicholas86a43402017-01-19 13:32:00 -050036 , fReadCount(0)
37 , fWriteCount(0) {}
ethannicholasb3058bd2016-07-01 08:22:01 -070038
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050039 virtual SkString description() const override {
ethannicholasd598f792016-07-25 10:08:54 -070040 return fModifiers.description() + fType.fName + " " + fName;
ethannicholasb3058bd2016-07-01 08:22:01 -070041 }
42
ethannicholasf789b382016-08-03 12:43:36 -070043 mutable Modifiers fModifiers;
ethannicholasd598f792016-07-25 10:08:54 -070044 const Type& fType;
ethannicholasb3058bd2016-07-01 08:22:01 -070045 const Storage fStorage;
46
Ethan Nicholas86a43402017-01-19 13:32:00 -050047 // 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;
ethannicholasb3058bd2016-07-01 08:22:01 -070053
54 typedef Symbol INHERITED;
55};
56
57} // namespace SkSL
58
ethannicholasb3058bd2016-07-01 08:22:01 -070059#endif