| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 | 8 |
| 9 #include "graph-tester.h" | 9 #include "graph-tester.h" |
| 10 #include "src/compiler/common-operator.h" | 10 #include "src/compiler/common-operator.h" |
| 11 #include "src/compiler/graph.h" | 11 #include "src/compiler/graph.h" |
| 12 #include "src/compiler/graph-inl.h" |
| 12 #include "src/compiler/graph-visualizer.h" | 13 #include "src/compiler/graph-visualizer.h" |
| 13 #include "src/compiler/node.h" | 14 #include "src/compiler/node.h" |
| 14 #include "src/compiler/operator.h" | 15 #include "src/compiler/operator.h" |
| 15 | 16 |
| 16 using namespace v8::internal; | 17 using namespace v8::internal; |
| 17 using namespace v8::internal::compiler; | 18 using namespace v8::internal::compiler; |
| 18 | 19 |
| 19 static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite, | 20 static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite, |
| 20 "dummy", 0, 0, 0, 1, 0, 0); | 21 "dummy", 0, 0, 0, 1, 0, 0); |
| 21 | 22 |
| 23 class PreNodeVisitor : public NullNodeVisitor { |
| 24 public: |
| 25 void Pre(Node* node) { |
| 26 printf("NODE ID: %d\n", node->id()); |
| 27 nodes_.push_back(node); |
| 28 } |
| 29 std::vector<Node*> nodes_; |
| 30 }; |
| 31 |
| 32 |
| 33 class PostNodeVisitor : public NullNodeVisitor { |
| 34 public: |
| 35 void Post(Node* node) { |
| 36 printf("NODE ID: %d\n", node->id()); |
| 37 nodes_.push_back(node); |
| 38 } |
| 39 std::vector<Node*> nodes_; |
| 40 }; |
| 41 |
| 42 |
| 43 TEST(TestInputNodePreOrderVisitSimple) { |
| 44 GraphWithStartNodeTester graph; |
| 45 Node* n2 = graph.NewNode(&dummy_operator, graph.start()); |
| 46 Node* n3 = graph.NewNode(&dummy_operator, n2); |
| 47 Node* n4 = graph.NewNode(&dummy_operator, n2, n3); |
| 48 Node* n5 = graph.NewNode(&dummy_operator, n4, n2); |
| 49 graph.SetEnd(n5); |
| 50 |
| 51 PreNodeVisitor node_visitor; |
| 52 graph.VisitNodeInputsFromEnd(&node_visitor); |
| 53 CHECK_EQ(5, static_cast<int>(node_visitor.nodes_.size())); |
| 54 CHECK(n5->id() == node_visitor.nodes_[0]->id()); |
| 55 CHECK(n4->id() == node_visitor.nodes_[1]->id()); |
| 56 CHECK(n2->id() == node_visitor.nodes_[2]->id()); |
| 57 CHECK(graph.start()->id() == node_visitor.nodes_[3]->id()); |
| 58 CHECK(n3->id() == node_visitor.nodes_[4]->id()); |
| 59 } |
| 60 |
| 61 |
| 22 TEST(TestPrintNodeGraphToNodeGraphviz) { | 62 TEST(TestPrintNodeGraphToNodeGraphviz) { |
| 23 GraphWithStartNodeTester graph; | 63 GraphWithStartNodeTester graph; |
| 24 Node* n2 = graph.NewNode(&dummy_operator, graph.start()); | 64 Node* n2 = graph.NewNode(&dummy_operator, graph.start()); |
| 25 Node* n3 = graph.NewNode(&dummy_operator, graph.start()); | 65 Node* n3 = graph.NewNode(&dummy_operator, graph.start()); |
| 26 Node* n4 = graph.NewNode(&dummy_operator, n2); | 66 Node* n4 = graph.NewNode(&dummy_operator, n2); |
| 27 Node* n5 = graph.NewNode(&dummy_operator, n2); | 67 Node* n5 = graph.NewNode(&dummy_operator, n2); |
| 28 Node* n6 = graph.NewNode(&dummy_operator, n3); | 68 Node* n6 = graph.NewNode(&dummy_operator, n3); |
| 29 Node* n7 = graph.NewNode(&dummy_operator, n3); | 69 Node* n7 = graph.NewNode(&dummy_operator, n3); |
| 30 Node* n8 = graph.NewNode(&dummy_operator, n5); | 70 Node* n8 = graph.NewNode(&dummy_operator, n5); |
| 31 Node* n9 = graph.NewNode(&dummy_operator, n5); | 71 Node* n9 = graph.NewNode(&dummy_operator, n5); |
| 32 Node* n10 = graph.NewNode(&dummy_operator, n9); | 72 Node* n10 = graph.NewNode(&dummy_operator, n9); |
| 33 Node* n11 = graph.NewNode(&dummy_operator, n9); | 73 Node* n11 = graph.NewNode(&dummy_operator, n9); |
| 34 Node* end_dependencies[6] = {n4, n8, n10, n11, n6, n7}; | 74 Node* end_dependencies[6] = {n4, n8, n10, n11, n6, n7}; |
| 35 Node* n12 = graph.NewNode(&dummy_operator, 6, end_dependencies); | 75 Node* n12 = graph.NewNode(&dummy_operator, 6, end_dependencies); |
| 36 graph.SetEnd(n12); | 76 graph.SetEnd(n12); |
| 37 | 77 |
| 38 OFStream os(stdout); | 78 OFStream os(stdout); |
| 39 os << AsDOT(graph); | 79 os << AsDOT(graph); |
| 40 } | 80 } |
| OLD | NEW |