Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/unittests/compiler/test-instruction-selector.h

Issue 439863004: Initial import of unittests using GTest/GMock. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #ifndef V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_TEST_H_
6 #define V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_TEST_H_
7
8 #include <deque>
9
10 #include "src/compiler/instruction-selector.h"
11 #include "src/compiler/raw-machine-assembler.h"
12 #include "test/unittests/test-zone.h"
13
14 namespace v8 {
15 namespace internal {
16 namespace compiler {
17
18 class InstructionSelectorTest : public ContextTest, public ZoneTest {
19 public:
20 InstructionSelectorTest() {}
21
22 protected:
23 class Stream;
24
25 enum StreamBuilderMode { kAllInstructions, kTargetInstructions };
26
27 class StreamBuilder : public RawMachineAssembler {
28 public:
29 StreamBuilder(InstructionSelectorTest* test,
30 MachineRepresentation return_type)
31 : RawMachineAssembler(new (test->zone()) Graph(test->zone()),
32 CallDescriptorBuilder(test->zone(), return_type)),
33 test_(test) {}
34
35 Stream Build(StreamBuilderMode mode = kTargetInstructions);
36
37 private:
38 MachineCallDescriptorBuilder* CallDescriptorBuilder(
39 Zone* zone, MachineRepresentation return_type) {
40 return new (zone) MachineCallDescriptorBuilder(return_type, 0, NULL);
41 }
42
43 private:
44 InstructionSelectorTest* test_;
45 };
46
47 class Stream {
48 public:
49 size_t size() const { return instructions_.size(); }
50 const Instruction* operator[](size_t index) const {
51 EXPECT_LT(index, size());
52 return instructions_[index];
53 }
54
55 int32_t ToInt32(const InstructionOperand* operand) const {
56 return ToConstant(operand).ToInt32();
57 }
58
59 private:
60 Constant ToConstant(const InstructionOperand* operand) const {
61 ConstantMap::const_iterator i;
62 if (operand->IsConstant()) {
63 i = constants_.find(operand->index());
64 EXPECT_NE(constants_.end(), i);
65 } else {
66 EXPECT_EQ(InstructionOperand::IMMEDIATE, operand->kind());
67 i = immediates_.find(operand->index());
68 EXPECT_NE(immediates_.end(), i);
69 }
70 EXPECT_EQ(operand->index(), i->first);
71 return i->second;
72 }
73
74 friend class StreamBuilder;
75
76 typedef std::map<int, Constant> ConstantMap;
77
78 ConstantMap constants_;
79 ConstantMap immediates_;
80 std::deque<Instruction*> instructions_;
81 };
82 };
83
84 } // namespace compiler
85 } // namespace internal
86 } // namespace v8
87
88 #endif // V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_TEST_H_
OLDNEW
« no previous file with comments | « test/unittests/compiler/arm/test-instruction-selector-arm.cc ('k') | test/unittests/compiler/test-instruction-selector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698