]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGEpoch.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGEpoch.h
1 /*
2 * Copyright (C) 2015 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef DFGEpoch_h
27 #define DFGEpoch_h
28
29 #if ENABLE(DFG_JIT)
30
31 #include <wtf/PrintStream.h>
32
33 namespace JSC { namespace DFG {
34
35 // Utility class for epoch-based analyses.
36
37 class Epoch {
38 public:
39 Epoch()
40 : m_epoch(s_none)
41 {
42 }
43
44 static Epoch fromUnsigned(unsigned value)
45 {
46 Epoch result;
47 result.m_epoch = value;
48 return result;
49 }
50
51 unsigned toUnsigned() const
52 {
53 return m_epoch;
54 }
55
56 static Epoch first()
57 {
58 Epoch result;
59 result.m_epoch = s_first;
60 return result;
61 }
62
63 bool operator!() const
64 {
65 return m_epoch == s_none;
66 }
67
68 Epoch next() const
69 {
70 Epoch result;
71 result.m_epoch = m_epoch + 1;
72 return result;
73 }
74
75 void bump()
76 {
77 *this = next();
78 }
79
80 bool operator==(const Epoch& other) const
81 {
82 return m_epoch == other.m_epoch;
83 }
84
85 bool operator!=(const Epoch& other) const
86 {
87 return !(*this == other);
88 }
89
90 bool operator<(const Epoch& other) const
91 {
92 return m_epoch < other.m_epoch;
93 }
94
95 bool operator>(const Epoch& other) const
96 {
97 return other < *this;
98 }
99
100 bool operator<=(const Epoch& other) const
101 {
102 return !(*this > other);
103 }
104
105 bool operator>=(const Epoch& other) const
106 {
107 return !(*this < other);
108 }
109
110 void dump(PrintStream&) const;
111
112 private:
113 static const unsigned s_none = 0;
114 static const unsigned s_first = 1;
115
116 unsigned m_epoch;
117 };
118
119 } } // namespace JSC::DFG
120
121 #endif // ENABLE(DFG_JIT)
122
123 #endif // DFGEpoch_h
124