]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGAdjacencyList.h
JavaScriptCore-1097.3.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGAdjacencyList.h
1 /*
2 * Copyright (C) 2011 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 DFGAdjacencyList_h
27 #define DFGAdjacencyList_h
28
29 #include <wtf/Platform.h>
30
31 #if ENABLE(DFG_JIT)
32
33 #include "DFGCommon.h"
34 #include "DFGEdge.h"
35
36 namespace JSC { namespace DFG {
37
38 class AdjacencyList {
39 public:
40 enum Kind {
41 Fixed,
42 Variable
43 };
44
45 AdjacencyList(Kind kind)
46 #if !ASSERT_DISABLED
47 : m_kind(kind)
48 #endif
49 {
50 if (kind == Variable) {
51 m_words[0].m_encodedWord = UINT_MAX;
52 m_words[1].m_encodedWord = UINT_MAX;
53 }
54 }
55
56 AdjacencyList(Kind kind, NodeIndex child1, NodeIndex child2, NodeIndex child3)
57 #if !ASSERT_DISABLED
58 : m_kind(Fixed)
59 #endif
60 {
61 ASSERT_UNUSED(kind, kind == Fixed);
62 initialize(child1, child2, child3);
63 }
64
65 AdjacencyList(Kind kind, unsigned firstChild, unsigned numChildren)
66 #if !ASSERT_DISABLED
67 : m_kind(Variable)
68 #endif
69 {
70 ASSERT_UNUSED(kind, kind == Variable);
71 setFirstChild(firstChild);
72 setNumChildren(numChildren);
73 }
74
75 const Edge& child(unsigned i) const
76 {
77 ASSERT(i < 3);
78 ASSERT(m_kind == Fixed);
79 return m_words[i];
80 }
81
82 Edge& child(unsigned i)
83 {
84 ASSERT(i < 3);
85 ASSERT(m_kind == Fixed);
86 return m_words[i];
87 }
88
89 void setChild(unsigned i, Edge nodeUse)
90 {
91 ASSERT(i < 30);
92 ASSERT(m_kind == Fixed);
93 m_words[i] = nodeUse;
94 }
95
96 Edge child1() const { return child(0); }
97 Edge child2() const { return child(1); }
98 Edge child3() const { return child(2); }
99
100 Edge& child1() { return child(0); }
101 Edge& child2() { return child(1); }
102 Edge& child3() { return child(2); }
103
104 void setChild1(Edge nodeUse) { setChild(0, nodeUse); }
105 void setChild2(Edge nodeUse) { setChild(1, nodeUse); }
106 void setChild3(Edge nodeUse) { setChild(2, nodeUse); }
107
108 Edge child1Unchecked() const { return m_words[0]; }
109
110 void initialize(Edge child1, Edge child2, Edge child3)
111 {
112 child(0) = child1;
113 child(1) = child2;
114 child(2) = child3;
115 }
116
117 void initialize(NodeIndex child1, NodeIndex child2, NodeIndex child3)
118 {
119 initialize(Edge(child1), Edge(child2), Edge(child3));
120 }
121
122 unsigned firstChild() const
123 {
124 ASSERT(m_kind == Variable);
125 return m_words[0].m_encodedWord;
126 }
127 void setFirstChild(unsigned firstChild)
128 {
129 ASSERT(m_kind == Variable);
130 m_words[0].m_encodedWord = firstChild;
131 }
132
133 unsigned numChildren() const
134 {
135 ASSERT(m_kind == Variable);
136 return m_words[1].m_encodedWord;
137 }
138 void setNumChildren(unsigned numChildren)
139 {
140 ASSERT(m_kind == Variable);
141 m_words[1].m_encodedWord = numChildren;
142 }
143
144 private:
145 Edge m_words[3];
146 #if !ASSERT_DISABLED
147 Kind m_kind;
148 #endif
149 };
150
151 } } // namespace JSC::DFG
152
153 #endif // ENABLE(DFG_JIT)
154
155 #endif // DFGAdjacencyList_h