blob: 31bae6d41545f46593ce1a0f3ad1b8f665fcb74d [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;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040021
22namespace compiler {
23
24using ::testing::Matcher;
25
26
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000027class GraphTest : public TestWithContext, public TestWithIsolateAndZone {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040028 public:
29 explicit GraphTest(int num_parameters = 1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000030 ~GraphTest() override;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040031
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000032 Node* start() { return graph()->start(); }
33 Node* end() { return graph()->end(); }
34
Emily Bernierd0a1eb72015-03-24 16:35:39 -040035 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);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040045 Node* FalseConstant();
46 Node* TrueConstant();
47 Node* UndefinedConstant();
48
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049 Node* EmptyFrameState();
50
Emily Bernierd0a1eb72015-03-24 16:35:39 -040051 Matcher<Node*> IsFalseConstant();
52 Matcher<Node*> IsTrueConstant();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000053 Matcher<Node*> IsUndefinedConstant();
Emily Bernierd0a1eb72015-03-24 16:35:39 -040054
55 CommonOperatorBuilder* common() { return &common_; }
56 Graph* graph() { return &graph_; }
57
58 private:
59 CommonOperatorBuilder common_;
60 Graph graph_;
61};
62
63
64class TypedGraphTest : public GraphTest {
65 public:
66 explicit TypedGraphTest(int num_parameters = 1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000067 ~TypedGraphTest() override;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040068
69 protected:
70 Node* Parameter(int32_t index = 0) { return GraphTest::Parameter(index); }
71 Node* Parameter(Type* type, int32_t index = 0);
72
73 Typer* typer() { return &typer_; }
74
75 private:
76 Typer typer_;
77};
78
79} // namespace compiler
80} // namespace internal
81} // namespace v8
82
83#endif // V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_