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