blob: 7c75161d9d2c092624fe3b247d5808476594f52c [file] [log] [blame]
Emily Bernierd0a1eb72015-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#ifndef V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_
6#define V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_
7
8#include "src/compiler/common-operator.h"
9#include "src/compiler/graph.h"
10#include "src/compiler/typer.h"
11#include "test/unittests/test-utils.h"
12#include "testing/gmock/include/gmock/gmock.h"
13
14namespace v8 {
15namespace internal {
16
17// Forward declarations.
18template <class T>
19class Handle;
20class HeapObject;
21template <class T>
22class Unique;
23
24namespace compiler {
25
26using ::testing::Matcher;
27
28
29class GraphTest : public TestWithContext, public TestWithZone {
30 public:
31 explicit GraphTest(int num_parameters = 1);
32 ~GraphTest() OVERRIDE;
33
34 protected:
35 Node* Parameter(int32_t index = 0);
36 Node* Float32Constant(volatile float value);
37 Node* Float64Constant(volatile double value);
38 Node* Int32Constant(int32_t value);
39 Node* Uint32Constant(uint32_t value) {
40 return Int32Constant(bit_cast<int32_t>(value));
41 }
42 Node* Int64Constant(int64_t value);
43 Node* NumberConstant(volatile double value);
44 Node* HeapConstant(const Handle<HeapObject>& value);
45 Node* HeapConstant(const Unique<HeapObject>& value);
46 Node* FalseConstant();
47 Node* TrueConstant();
48 Node* UndefinedConstant();
49
50 Matcher<Node*> IsFalseConstant();
51 Matcher<Node*> IsTrueConstant();
52
53 CommonOperatorBuilder* common() { return &common_; }
54 Graph* graph() { return &graph_; }
55
56 private:
57 CommonOperatorBuilder common_;
58 Graph graph_;
59};
60
61
62class TypedGraphTest : public GraphTest {
63 public:
64 explicit TypedGraphTest(int num_parameters = 1);
65 ~TypedGraphTest() OVERRIDE;
66
67 protected:
68 Node* Parameter(int32_t index = 0) { return GraphTest::Parameter(index); }
69 Node* Parameter(Type* type, int32_t index = 0);
70
71 Typer* typer() { return &typer_; }
72
73 private:
74 Typer typer_;
75};
76
77} // namespace compiler
78} // namespace internal
79} // namespace v8
80
81#endif // V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_