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

Side by Side Diff: test/cctest/compiler/codegen-tester.h

Issue 456333002: Move MachineRepresentation to machine-type.h and rename to MachineType in preparation for merging i… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
« no previous file with comments | « test/cctest/compiler/call-tester.h ('k') | test/cctest/compiler/graph-builder-tester.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_CCTEST_COMPILER_CODEGEN_TESTER_H_ 5 #ifndef V8_CCTEST_COMPILER_CODEGEN_TESTER_H_
6 #define V8_CCTEST_COMPILER_CODEGEN_TESTER_H_ 6 #define V8_CCTEST_COMPILER_CODEGEN_TESTER_H_
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/compiler/pipeline.h" 10 #include "src/compiler/pipeline.h"
11 #include "src/compiler/raw-machine-assembler.h" 11 #include "src/compiler/raw-machine-assembler.h"
12 #include "src/compiler/structured-machine-assembler.h" 12 #include "src/compiler/structured-machine-assembler.h"
13 #include "src/simulator.h" 13 #include "src/simulator.h"
14 #include "test/cctest/compiler/call-tester.h" 14 #include "test/cctest/compiler/call-tester.h"
15 15
16 namespace v8 { 16 namespace v8 {
17 namespace internal { 17 namespace internal {
18 namespace compiler { 18 namespace compiler {
19 19
20 template <typename MachineAssembler> 20 template <typename MachineAssembler>
21 class MachineAssemblerTester : public HandleAndZoneScope, 21 class MachineAssemblerTester : public HandleAndZoneScope,
22 public CallHelper, 22 public CallHelper,
23 public MachineAssembler { 23 public MachineAssembler {
24 public: 24 public:
25 MachineAssemblerTester(MachineRepresentation return_type, 25 MachineAssemblerTester(MachineType return_type, MachineType p0,
26 MachineRepresentation p0, MachineRepresentation p1, 26 MachineType p1, MachineType p2, MachineType p3,
27 MachineRepresentation p2, MachineRepresentation p3, 27 MachineType p4)
28 MachineRepresentation p4)
29 : HandleAndZoneScope(), 28 : HandleAndZoneScope(),
30 CallHelper(main_isolate()), 29 CallHelper(main_isolate()),
31 MachineAssembler(new (main_zone()) Graph(main_zone()), 30 MachineAssembler(new (main_zone()) Graph(main_zone()),
32 ToCallDescriptorBuilder(main_zone(), return_type, p0, 31 ToCallDescriptorBuilder(main_zone(), return_type, p0,
33 p1, p2, p3, p4), 32 p1, p2, p3, p4),
34 MachineOperatorBuilder::pointer_rep()) {} 33 MachineOperatorBuilder::pointer_rep()) {}
35 34
36 Node* LoadFromPointer(void* address, MachineRepresentation rep, 35 Node* LoadFromPointer(void* address, MachineType rep, int32_t offset = 0) {
37 int32_t offset = 0) {
38 return this->Load(rep, this->PointerConstant(address), 36 return this->Load(rep, this->PointerConstant(address),
39 this->Int32Constant(offset)); 37 this->Int32Constant(offset));
40 } 38 }
41 39
42 void StoreToPointer(void* address, MachineRepresentation rep, Node* node) { 40 void StoreToPointer(void* address, MachineType rep, Node* node) {
43 this->Store(rep, this->PointerConstant(address), node); 41 this->Store(rep, this->PointerConstant(address), node);
44 } 42 }
45 43
46 Node* StringConstant(const char* string) { 44 Node* StringConstant(const char* string) {
47 return this->HeapConstant( 45 return this->HeapConstant(
48 this->isolate()->factory()->InternalizeUtf8String(string)); 46 this->isolate()->factory()->InternalizeUtf8String(string));
49 } 47 }
50 48
51 void CheckNumber(double expected, Object* number) { 49 void CheckNumber(double expected, Object* number) {
52 CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number)); 50 CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number));
53 } 51 }
54 52
55 void CheckString(const char* expected, Object* string) { 53 void CheckString(const char* expected, Object* string) {
56 CHECK( 54 CHECK(
57 this->isolate()->factory()->InternalizeUtf8String(expected)->SameValue( 55 this->isolate()->factory()->InternalizeUtf8String(expected)->SameValue(
58 string)); 56 string));
59 } 57 }
60 58
61 void GenerateCode() { Generate(); } 59 void GenerateCode() { Generate(); }
62 60
63 protected: 61 protected:
64 virtual void VerifyParameters(int parameter_count, 62 virtual void VerifyParameters(int parameter_count,
65 MachineRepresentation* parameter_types) { 63 MachineType* parameter_types) {
66 CHECK_EQ(this->parameter_count(), parameter_count); 64 CHECK_EQ(this->parameter_count(), parameter_count);
67 const MachineRepresentation* expected_types = this->parameter_types(); 65 const MachineType* expected_types = this->parameter_types();
68 for (int i = 0; i < parameter_count; i++) { 66 for (int i = 0; i < parameter_count; i++) {
69 CHECK_EQ(expected_types[i], parameter_types[i]); 67 CHECK_EQ(expected_types[i], parameter_types[i]);
70 } 68 }
71 } 69 }
72 70
73 virtual byte* Generate() { 71 virtual byte* Generate() {
74 if (code_.is_null()) { 72 if (code_.is_null()) {
75 Schedule* schedule = this->Export(); 73 Schedule* schedule = this->Export();
76 CallDescriptor* call_descriptor = this->call_descriptor(); 74 CallDescriptor* call_descriptor = this->call_descriptor();
77 Graph* graph = this->graph(); 75 Graph* graph = this->graph();
78 CompilationInfo info(graph->zone()->isolate(), graph->zone()); 76 CompilationInfo info(graph->zone()->isolate(), graph->zone());
79 Linkage linkage(&info, call_descriptor); 77 Linkage linkage(&info, call_descriptor);
80 Pipeline pipeline(&info); 78 Pipeline pipeline(&info);
81 code_ = pipeline.GenerateCodeForMachineGraph(&linkage, graph, schedule); 79 code_ = pipeline.GenerateCodeForMachineGraph(&linkage, graph, schedule);
82 } 80 }
83 return this->code_.ToHandleChecked()->entry(); 81 return this->code_.ToHandleChecked()->entry();
84 } 82 }
85 83
86 private: 84 private:
87 MaybeHandle<Code> code_; 85 MaybeHandle<Code> code_;
88 }; 86 };
89 87
90 88
91 template <typename ReturnType> 89 template <typename ReturnType>
92 class RawMachineAssemblerTester 90 class RawMachineAssemblerTester
93 : public MachineAssemblerTester<RawMachineAssembler>, 91 : public MachineAssemblerTester<RawMachineAssembler>,
94 public CallHelper2<ReturnType, RawMachineAssemblerTester<ReturnType> > { 92 public CallHelper2<ReturnType, RawMachineAssemblerTester<ReturnType> > {
95 public: 93 public:
96 RawMachineAssemblerTester(MachineRepresentation p0 = kMachineLast, 94 RawMachineAssemblerTester(MachineType p0 = kMachineLast,
97 MachineRepresentation p1 = kMachineLast, 95 MachineType p1 = kMachineLast,
98 MachineRepresentation p2 = kMachineLast, 96 MachineType p2 = kMachineLast,
99 MachineRepresentation p3 = kMachineLast, 97 MachineType p3 = kMachineLast,
100 MachineRepresentation p4 = kMachineLast) 98 MachineType p4 = kMachineLast)
101 : MachineAssemblerTester<RawMachineAssembler>( 99 : MachineAssemblerTester<RawMachineAssembler>(
102 ReturnValueTraits<ReturnType>::Representation(), p0, p1, p2, p3, 100 ReturnValueTraits<ReturnType>::Representation(), p0, p1, p2, p3,
103 p4) {} 101 p4) {}
104 102
105 template <typename Ci, typename Fn> 103 template <typename Ci, typename Fn>
106 void Run(const Ci& ci, const Fn& fn) { 104 void Run(const Ci& ci, const Fn& fn) {
107 typename Ci::const_iterator i; 105 typename Ci::const_iterator i;
108 for (i = ci.begin(); i != ci.end(); ++i) { 106 for (i = ci.begin(); i != ci.end(); ++i) {
109 CHECK_EQ(fn(*i), this->Call(*i)); 107 CHECK_EQ(fn(*i), this->Call(*i));
110 } 108 }
(...skipping 11 matching lines...) Expand all
122 } 120 }
123 }; 121 };
124 122
125 123
126 template <typename ReturnType> 124 template <typename ReturnType>
127 class StructuredMachineAssemblerTester 125 class StructuredMachineAssemblerTester
128 : public MachineAssemblerTester<StructuredMachineAssembler>, 126 : public MachineAssemblerTester<StructuredMachineAssembler>,
129 public CallHelper2<ReturnType, 127 public CallHelper2<ReturnType,
130 StructuredMachineAssemblerTester<ReturnType> > { 128 StructuredMachineAssemblerTester<ReturnType> > {
131 public: 129 public:
132 StructuredMachineAssemblerTester(MachineRepresentation p0 = kMachineLast, 130 StructuredMachineAssemblerTester(MachineType p0 = kMachineLast,
133 MachineRepresentation p1 = kMachineLast, 131 MachineType p1 = kMachineLast,
134 MachineRepresentation p2 = kMachineLast, 132 MachineType p2 = kMachineLast,
135 MachineRepresentation p3 = kMachineLast, 133 MachineType p3 = kMachineLast,
136 MachineRepresentation p4 = kMachineLast) 134 MachineType p4 = kMachineLast)
137 : MachineAssemblerTester<StructuredMachineAssembler>( 135 : MachineAssemblerTester<StructuredMachineAssembler>(
138 ReturnValueTraits<ReturnType>::Representation(), p0, p1, p2, p3, 136 ReturnValueTraits<ReturnType>::Representation(), p0, p1, p2, p3,
139 p4) {} 137 p4) {}
140 }; 138 };
141 139
142 140
143 static const bool USE_RESULT_BUFFER = true; 141 static const bool USE_RESULT_BUFFER = true;
144 static const bool USE_RETURN_REGISTER = false; 142 static const bool USE_RETURN_REGISTER = false;
145 static const int32_t CHECK_VALUE = 0x99BEEDCE; 143 static const int32_t CHECK_VALUE = 0x99BEEDCE;
146 144
147 145
148 // TODO(titzer): use the C-style calling convention, or any register-based 146 // TODO(titzer): use the C-style calling convention, or any register-based
149 // calling convention for binop tests. 147 // calling convention for binop tests.
150 template <typename CType, MachineRepresentation rep, bool use_result_buffer> 148 template <typename CType, MachineType rep, bool use_result_buffer>
151 class BinopTester { 149 class BinopTester {
152 public: 150 public:
153 explicit BinopTester(RawMachineAssemblerTester<int32_t>* tester) 151 explicit BinopTester(RawMachineAssemblerTester<int32_t>* tester)
154 : T(tester), 152 : T(tester),
155 param0(T->LoadFromPointer(&p0, rep)), 153 param0(T->LoadFromPointer(&p0, rep)),
156 param1(T->LoadFromPointer(&p1, rep)), 154 param1(T->LoadFromPointer(&p1, rep)),
157 p0(static_cast<CType>(0)), 155 p0(static_cast<CType>(0)),
158 p1(static_cast<CType>(0)), 156 p1(static_cast<CType>(0)),
159 result(static_cast<CType>(0)) {} 157 result(static_cast<CType>(0)) {}
160 158
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 344
347 void Run(RawMachineAssemblerTester<int32_t>* m); 345 void Run(RawMachineAssemblerTester<int32_t>* m);
348 void RunLeft(RawMachineAssemblerTester<int32_t>* m); 346 void RunLeft(RawMachineAssemblerTester<int32_t>* m);
349 void RunRight(RawMachineAssemblerTester<int32_t>* m); 347 void RunRight(RawMachineAssemblerTester<int32_t>* m);
350 }; 348 };
351 } // namespace compiler 349 } // namespace compiler
352 } // namespace internal 350 } // namespace internal
353 } // namespace v8 351 } // namespace v8
354 352
355 #endif // V8_CCTEST_COMPILER_CODEGEN_TESTER_H_ 353 #endif // V8_CCTEST_COMPILER_CODEGEN_TESTER_H_
OLDNEW
« no previous file with comments | « test/cctest/compiler/call-tester.h ('k') | test/cctest/compiler/graph-builder-tester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698