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