graph-unittest.h 2.67 KB
Newer Older
1 2 3 4
// 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.

5 6
#ifndef V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_
#define V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_
7

8
#include "src/codegen/tick-counter.h"
9
#include "src/compiler/common-operator.h"
10
#include "src/compiler/compiler-source-position-table.h"
11
#include "src/compiler/graph.h"
12
#include "src/compiler/js-heap-broker.h"
13
#include "src/compiler/node-origin-table.h"
14
#include "src/compiler/typer.h"
15
#include "src/handles/handles.h"
16
#include "test/unittests/test-utils.h"
17 18 19 20 21 22 23 24 25 26
#include "testing/gmock/include/gmock/gmock.h"

namespace v8 {
namespace internal {

// Forward declarations.
class HeapObject;

namespace compiler {

27 28
using ::testing::Matcher;

29
class GraphTest : public TestWithNativeContextAndZone {
30
 public:
31
  explicit GraphTest(int num_parameters = 1);
32
  ~GraphTest() override;
33

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

37
  Node* Parameter(int32_t index = 0);
38
  Node* Parameter(Type type, int32_t index = 0);
39 40
  Node* Float32Constant(volatile float value);
  Node* Float64Constant(volatile double value);
41
  Node* Int32Constant(int32_t value);
42 43 44
  Node* Uint32Constant(uint32_t value) {
    return Int32Constant(bit_cast<int32_t>(value));
  }
45
  Node* Int64Constant(int64_t value);
46
  Node* NumberConstant(volatile double value);
47
  Node* HeapConstant(const Handle<HeapObject>& value);
48 49
  Node* FalseConstant();
  Node* TrueConstant();
50
  Node* UndefinedConstant();
51

52 53
  Node* EmptyFrameState();

54 55 56
  Matcher<Node*> IsBooleanConstant(bool value) {
    return value ? IsTrueConstant() : IsFalseConstant();
  }
57 58
  Matcher<Node*> IsFalseConstant();
  Matcher<Node*> IsTrueConstant();
59
  Matcher<Node*> IsNullConstant();
60
  Matcher<Node*> IsUndefinedConstant();
61

62
  CommonOperatorBuilder* common() { return &common_; }
63
  Graph* graph() { return &graph_; }
64
  SourcePositionTable* source_positions() { return &source_positions_; }
65
  NodeOriginTable* node_origins() { return &node_origins_; }
66
  JSHeapBroker* broker() { return &broker_; }
67
  TickCounter* tick_counter() { return &tick_counter_; }
68 69

 private:
70
  CanonicalHandleScope canonical_;
71
  CommonOperatorBuilder common_;
72
  Graph graph_;
73
  JSHeapBroker broker_;
74
  SourcePositionTable source_positions_;
75
  NodeOriginTable node_origins_;
76
  TickCounter tick_counter_;
77 78 79 80 81
};


class TypedGraphTest : public GraphTest {
 public:
82
  explicit TypedGraphTest(int num_parameters = 1);
83
  ~TypedGraphTest() override;
84 85 86 87 88 89

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

 private:
  Typer typer_;
90 91
};

92 93 94 95
}  //  namespace compiler
}  //  namespace internal
}  //  namespace v8

96
#endif  // V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_