summaryrefslogtreecommitdiff
path: root/deps/v8/test/unittests/compiler/graph-unittest.h
blob: 8317ebf2798a9d6b9d1d8a0916179cb013472949 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_
#define V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_

#include "src/compiler/common-operator.h"
#include "src/compiler/compiler-source-position-table.h"
#include "src/compiler/graph.h"
#include "src/compiler/node-origin-table.h"
#include "src/compiler/typer.h"
#include "src/handles.h"
#include "test/unittests/test-utils.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace v8 {
namespace internal {

// Forward declarations.
class HeapObject;

namespace compiler {

using ::testing::Matcher;

class GraphTest : public virtual TestWithNativeContext,
                  public virtual TestWithIsolateAndZone {
 public:
  explicit GraphTest(int num_parameters = 1);
  ~GraphTest() override;

  Node* start() { return graph()->start(); }
  Node* end() { return graph()->end(); }

  Node* Parameter(int32_t index = 0);
  Node* Parameter(Type type, int32_t index = 0);
  Node* Float32Constant(volatile float value);
  Node* Float64Constant(volatile double value);
  Node* Int32Constant(int32_t value);
  Node* Uint32Constant(uint32_t value) {
    return Int32Constant(bit_cast<int32_t>(value));
  }
  Node* Int64Constant(int64_t value);
  Node* NumberConstant(volatile double value);
  Node* HeapConstant(const Handle<HeapObject>& value);
  Node* FalseConstant();
  Node* TrueConstant();
  Node* UndefinedConstant();

  Node* EmptyFrameState();

  Matcher<Node*> IsBooleanConstant(bool value) {
    return value ? IsTrueConstant() : IsFalseConstant();
  }
  Matcher<Node*> IsFalseConstant();
  Matcher<Node*> IsTrueConstant();
  Matcher<Node*> IsNullConstant();
  Matcher<Node*> IsUndefinedConstant();

  CommonOperatorBuilder* common() { return &common_; }
  Graph* graph() { return &graph_; }
  SourcePositionTable* source_positions() { return &source_positions_; }
  NodeOriginTable* node_origins() { return &node_origins_; }
  JSHeapBroker* js_heap_broker() { return &js_heap_broker_; }

 private:
  CanonicalHandleScope canonical_;
  CommonOperatorBuilder common_;
  Graph graph_;
  JSHeapBroker js_heap_broker_;
  SourcePositionTable source_positions_;
  NodeOriginTable node_origins_;
};


class TypedGraphTest : public GraphTest {
 public:
  explicit TypedGraphTest(int num_parameters = 1);
  ~TypedGraphTest() override;

 protected:
  Typer* typer() { return &typer_; }

 private:
  Typer typer_;
};

}  //  namespace compiler
}  //  namespace internal
}  //  namespace v8

#endif  // V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_