OLD | NEW |
| (Empty) |
1 // Copyright 2013 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_COMPILER_GRAPH_BUILDER_H_ | |
6 #define V8_COMPILER_GRAPH_BUILDER_H_ | |
7 | |
8 #include "src/allocation.h" | |
9 #include "src/compiler/common-operator.h" | |
10 #include "src/compiler/graph.h" | |
11 #include "src/compiler/node.h" | |
12 #include "src/unique.h" | |
13 | |
14 namespace v8 { | |
15 namespace internal { | |
16 namespace compiler { | |
17 | |
18 // A common base class for anything that creates nodes in a graph. | |
19 class GraphBuilder { | |
20 public: | |
21 GraphBuilder(Isolate* isolate, Graph* graph) | |
22 : isolate_(isolate), graph_(graph) {} | |
23 virtual ~GraphBuilder() {} | |
24 | |
25 Node* NewNode(const Operator* op, bool incomplete = false) { | |
26 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); | |
27 } | |
28 | |
29 Node* NewNode(const Operator* op, Node* n1) { | |
30 return MakeNode(op, 1, &n1, false); | |
31 } | |
32 | |
33 Node* NewNode(const Operator* op, Node* n1, Node* n2) { | |
34 Node* buffer[] = {n1, n2}; | |
35 return MakeNode(op, arraysize(buffer), buffer, false); | |
36 } | |
37 | |
38 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3) { | |
39 Node* buffer[] = {n1, n2, n3}; | |
40 return MakeNode(op, arraysize(buffer), buffer, false); | |
41 } | |
42 | |
43 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) { | |
44 Node* buffer[] = {n1, n2, n3, n4}; | |
45 return MakeNode(op, arraysize(buffer), buffer, false); | |
46 } | |
47 | |
48 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, | |
49 Node* n5) { | |
50 Node* buffer[] = {n1, n2, n3, n4, n5}; | |
51 return MakeNode(op, arraysize(buffer), buffer, false); | |
52 } | |
53 | |
54 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, | |
55 Node* n5, Node* n6) { | |
56 Node* nodes[] = {n1, n2, n3, n4, n5, n6}; | |
57 return MakeNode(op, arraysize(nodes), nodes, false); | |
58 } | |
59 | |
60 Node* NewNode(const Operator* op, int value_input_count, Node** value_inputs, | |
61 bool incomplete = false) { | |
62 return MakeNode(op, value_input_count, value_inputs, incomplete); | |
63 } | |
64 | |
65 Isolate* isolate() const { return isolate_; } | |
66 Graph* graph() const { return graph_; } | |
67 | |
68 protected: | |
69 // Base implementation used by all factory methods. | |
70 virtual Node* MakeNode(const Operator* op, int value_input_count, | |
71 Node** value_inputs, bool incomplete) = 0; | |
72 | |
73 private: | |
74 Isolate* isolate_; | |
75 Graph* graph_; | |
76 }; | |
77 | |
78 } // namespace compiler | |
79 } // namespace internal | |
80 } // namespace v8 | |
81 | |
82 #endif // V8_COMPILER_GRAPH_BUILDER_H__ | |
OLD | NEW |