Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / v8 / test / unittests / compiler / graph-unittest.cc
1 // Copyright 2014 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 #include "test/unittests/compiler/graph-unittest.h"
6
7 #include <ostream>  // NOLINT(readability/streams)
8
9 #include "src/compiler/node-properties-inl.h"
10 #include "test/unittests/compiler/node-test-utils.h"
11
12 namespace v8 {
13 namespace internal {
14 namespace compiler {
15
16 GraphTest::GraphTest(int num_parameters) : common_(zone()), graph_(zone()) {
17   graph()->SetStart(graph()->NewNode(common()->Start(num_parameters)));
18 }
19
20
21 GraphTest::~GraphTest() {}
22
23
24 Node* GraphTest::Parameter(int32_t index) {
25   return graph()->NewNode(common()->Parameter(index), graph()->start());
26 }
27
28
29 Node* GraphTest::Float32Constant(volatile float value) {
30   return graph()->NewNode(common()->Float32Constant(value));
31 }
32
33
34 Node* GraphTest::Float64Constant(volatile double value) {
35   return graph()->NewNode(common()->Float64Constant(value));
36 }
37
38
39 Node* GraphTest::Int32Constant(int32_t value) {
40   return graph()->NewNode(common()->Int32Constant(value));
41 }
42
43
44 Node* GraphTest::Int64Constant(int64_t value) {
45   return graph()->NewNode(common()->Int64Constant(value));
46 }
47
48
49 Node* GraphTest::NumberConstant(volatile double value) {
50   return graph()->NewNode(common()->NumberConstant(value));
51 }
52
53
54 Node* GraphTest::HeapConstant(const Handle<HeapObject>& value) {
55   return HeapConstant(Unique<HeapObject>::CreateUninitialized(value));
56 }
57
58
59 Node* GraphTest::HeapConstant(const Unique<HeapObject>& value) {
60   Node* node = graph()->NewNode(common()->HeapConstant(value));
61   Type* type = Type::Constant(value.handle(), zone());
62   NodeProperties::SetBounds(node, Bounds(type));
63   return node;
64 }
65
66
67 Node* GraphTest::FalseConstant() {
68   return HeapConstant(
69       Unique<HeapObject>::CreateImmovable(factory()->false_value()));
70 }
71
72
73 Node* GraphTest::TrueConstant() {
74   return HeapConstant(
75       Unique<HeapObject>::CreateImmovable(factory()->true_value()));
76 }
77
78
79 Node* GraphTest::UndefinedConstant() {
80   return HeapConstant(
81       Unique<HeapObject>::CreateImmovable(factory()->undefined_value()));
82 }
83
84
85 Matcher<Node*> GraphTest::IsFalseConstant() {
86   return IsHeapConstant(
87       Unique<HeapObject>::CreateImmovable(factory()->false_value()));
88 }
89
90
91 Matcher<Node*> GraphTest::IsTrueConstant() {
92   return IsHeapConstant(
93       Unique<HeapObject>::CreateImmovable(factory()->true_value()));
94 }
95
96 }  // namespace compiler
97 }  // namespace internal
98 }  // namespace v8