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

Side by Side Diff: test/cctest/compiler/call-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 | « src/compiler/x64/linkage-x64.cc ('k') | test/cctest/compiler/codegen-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_CALL_TESTER_H_ 5 #ifndef V8_CCTEST_COMPILER_CALL_TESTER_H_
6 #define V8_CCTEST_COMPILER_CALL_TESTER_H_ 6 #define V8_CCTEST_COMPILER_CALL_TESTER_H_
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/simulator.h" 10 #include "src/simulator.h"
11 11
12 #if V8_TARGET_ARCH_IA32 12 #if V8_TARGET_ARCH_IA32
13 #if __GNUC__ 13 #if __GNUC__
14 #define V8_CDECL __attribute__((cdecl)) 14 #define V8_CDECL __attribute__((cdecl))
15 #else 15 #else
16 #define V8_CDECL __cdecl 16 #define V8_CDECL __cdecl
17 #endif 17 #endif
18 #else 18 #else
19 #define V8_CDECL 19 #define V8_CDECL
20 #endif 20 #endif
21 21
22 namespace v8 { 22 namespace v8 {
23 namespace internal { 23 namespace internal {
24 namespace compiler { 24 namespace compiler {
25 25
26 template <typename R> 26 template <typename R>
27 struct ReturnValueTraits { 27 struct ReturnValueTraits {
28 static R Cast(uintptr_t r) { return reinterpret_cast<R>(r); } 28 static R Cast(uintptr_t r) { return reinterpret_cast<R>(r); }
29 static MachineRepresentation Representation() { 29 static MachineType Representation() {
30 // TODO(dcarney): detect when R is of a subclass of Object* instead of this 30 // TODO(dcarney): detect when R is of a subclass of Object* instead of this
31 // type check. 31 // type check.
32 while (false) { 32 while (false) {
33 *(static_cast<Object* volatile*>(0)) = static_cast<R>(0); 33 *(static_cast<Object* volatile*>(0)) = static_cast<R>(0);
34 } 34 }
35 return kMachineTagged; 35 return kMachineTagged;
36 } 36 }
37 }; 37 };
38 38
39 template <> 39 template <>
40 struct ReturnValueTraits<int32_t*> { 40 struct ReturnValueTraits<int32_t*> {
41 static int32_t* Cast(uintptr_t r) { return reinterpret_cast<int32_t*>(r); } 41 static int32_t* Cast(uintptr_t r) { return reinterpret_cast<int32_t*>(r); }
42 static MachineRepresentation Representation() { 42 static MachineType Representation() {
43 return MachineOperatorBuilder::pointer_rep(); 43 return MachineOperatorBuilder::pointer_rep();
44 } 44 }
45 }; 45 };
46 46
47 template <> 47 template <>
48 struct ReturnValueTraits<void> { 48 struct ReturnValueTraits<void> {
49 static void Cast(uintptr_t r) {} 49 static void Cast(uintptr_t r) {}
50 static MachineRepresentation Representation() { 50 static MachineType Representation() {
51 return MachineOperatorBuilder::pointer_rep(); 51 return MachineOperatorBuilder::pointer_rep();
52 } 52 }
53 }; 53 };
54 54
55 template <> 55 template <>
56 struct ReturnValueTraits<bool> { 56 struct ReturnValueTraits<bool> {
57 static bool Cast(uintptr_t r) { return static_cast<bool>(r); } 57 static bool Cast(uintptr_t r) { return static_cast<bool>(r); }
58 static MachineRepresentation Representation() { 58 static MachineType Representation() {
59 return MachineOperatorBuilder::pointer_rep(); 59 return MachineOperatorBuilder::pointer_rep();
60 } 60 }
61 }; 61 };
62 62
63 template <> 63 template <>
64 struct ReturnValueTraits<int32_t> { 64 struct ReturnValueTraits<int32_t> {
65 static int32_t Cast(uintptr_t r) { return static_cast<int32_t>(r); } 65 static int32_t Cast(uintptr_t r) { return static_cast<int32_t>(r); }
66 static MachineRepresentation Representation() { return kMachineWord32; } 66 static MachineType Representation() { return kMachineWord32; }
67 }; 67 };
68 68
69 template <> 69 template <>
70 struct ReturnValueTraits<uint32_t> { 70 struct ReturnValueTraits<uint32_t> {
71 static uint32_t Cast(uintptr_t r) { return static_cast<uint32_t>(r); } 71 static uint32_t Cast(uintptr_t r) { return static_cast<uint32_t>(r); }
72 static MachineRepresentation Representation() { return kMachineWord32; } 72 static MachineType Representation() { return kMachineWord32; }
73 }; 73 };
74 74
75 template <> 75 template <>
76 struct ReturnValueTraits<int64_t> { 76 struct ReturnValueTraits<int64_t> {
77 static int64_t Cast(uintptr_t r) { return static_cast<int64_t>(r); } 77 static int64_t Cast(uintptr_t r) { return static_cast<int64_t>(r); }
78 static MachineRepresentation Representation() { return kMachineWord64; } 78 static MachineType Representation() { return kMachineWord64; }
79 }; 79 };
80 80
81 template <> 81 template <>
82 struct ReturnValueTraits<uint64_t> { 82 struct ReturnValueTraits<uint64_t> {
83 static uint64_t Cast(uintptr_t r) { return static_cast<uint64_t>(r); } 83 static uint64_t Cast(uintptr_t r) { return static_cast<uint64_t>(r); }
84 static MachineRepresentation Representation() { return kMachineWord64; } 84 static MachineType Representation() { return kMachineWord64; }
85 }; 85 };
86 86
87 template <> 87 template <>
88 struct ReturnValueTraits<int16_t> { 88 struct ReturnValueTraits<int16_t> {
89 static int16_t Cast(uintptr_t r) { return static_cast<int16_t>(r); } 89 static int16_t Cast(uintptr_t r) { return static_cast<int16_t>(r); }
90 static MachineRepresentation Representation() { 90 static MachineType Representation() {
91 return MachineOperatorBuilder::pointer_rep(); 91 return MachineOperatorBuilder::pointer_rep();
92 } 92 }
93 }; 93 };
94 94
95 template <> 95 template <>
96 struct ReturnValueTraits<int8_t> { 96 struct ReturnValueTraits<int8_t> {
97 static int8_t Cast(uintptr_t r) { return static_cast<int8_t>(r); } 97 static int8_t Cast(uintptr_t r) { return static_cast<int8_t>(r); }
98 static MachineRepresentation Representation() { 98 static MachineType Representation() {
99 return MachineOperatorBuilder::pointer_rep(); 99 return MachineOperatorBuilder::pointer_rep();
100 } 100 }
101 }; 101 };
102 102
103 template <> 103 template <>
104 struct ReturnValueTraits<double> { 104 struct ReturnValueTraits<double> {
105 static double Cast(uintptr_t r) { 105 static double Cast(uintptr_t r) {
106 UNREACHABLE(); 106 UNREACHABLE();
107 return 0.0; 107 return 0.0;
108 } 108 }
109 static MachineRepresentation Representation() { return kMachineFloat64; } 109 static MachineType Representation() { return kMachineFloat64; }
110 }; 110 };
111 111
112 112
113 template <typename R> 113 template <typename R>
114 struct ParameterTraits { 114 struct ParameterTraits {
115 static uintptr_t Cast(R r) { return static_cast<uintptr_t>(r); } 115 static uintptr_t Cast(R r) { return static_cast<uintptr_t>(r); }
116 }; 116 };
117 117
118 template <> 118 template <>
119 struct ParameterTraits<int*> { 119 struct ParameterTraits<int*> {
120 static uintptr_t Cast(int* r) { return reinterpret_cast<uintptr_t>(r); } 120 static uintptr_t Cast(int* r) { return reinterpret_cast<uintptr_t>(r); }
121 }; 121 };
122 122
123 template <typename T> 123 template <typename T>
124 struct ParameterTraits<T*> { 124 struct ParameterTraits<T*> {
125 static uintptr_t Cast(void* r) { return reinterpret_cast<uintptr_t>(r); } 125 static uintptr_t Cast(void* r) { return reinterpret_cast<uintptr_t>(r); }
126 }; 126 };
127 127
128 class CallHelper { 128 class CallHelper {
129 public: 129 public:
130 explicit CallHelper(Isolate* isolate) : isolate_(isolate) { USE(isolate_); } 130 explicit CallHelper(Isolate* isolate) : isolate_(isolate) { USE(isolate_); }
131 virtual ~CallHelper() {} 131 virtual ~CallHelper() {}
132 132
133 static MachineCallDescriptorBuilder* ToCallDescriptorBuilder( 133 static MachineCallDescriptorBuilder* ToCallDescriptorBuilder(
134 Zone* zone, MachineRepresentation return_type, 134 Zone* zone, MachineType return_type, MachineType p0 = kMachineLast,
135 MachineRepresentation p0 = kMachineLast, 135 MachineType p1 = kMachineLast, MachineType p2 = kMachineLast,
136 MachineRepresentation p1 = kMachineLast, 136 MachineType p3 = kMachineLast, MachineType p4 = kMachineLast) {
137 MachineRepresentation p2 = kMachineLast,
138 MachineRepresentation p3 = kMachineLast,
139 MachineRepresentation p4 = kMachineLast) {
140 const int kSize = 5; 137 const int kSize = 5;
141 MachineRepresentation* params = 138 MachineType* params = zone->NewArray<MachineType>(kSize);
142 zone->NewArray<MachineRepresentation>(kSize);
143 params[0] = p0; 139 params[0] = p0;
144 params[1] = p1; 140 params[1] = p1;
145 params[2] = p2; 141 params[2] = p2;
146 params[3] = p3; 142 params[3] = p3;
147 params[4] = p4; 143 params[4] = p4;
148 int parameter_count = 0; 144 int parameter_count = 0;
149 for (int i = 0; i < kSize; ++i) { 145 for (int i = 0; i < kSize; ++i) {
150 if (params[i] == kMachineLast) { 146 if (params[i] == kMachineLast) {
151 break; 147 break;
152 } 148 }
153 parameter_count++; 149 parameter_count++;
154 } 150 }
155 return new (zone) 151 return new (zone)
156 MachineCallDescriptorBuilder(return_type, parameter_count, params); 152 MachineCallDescriptorBuilder(return_type, parameter_count, params);
157 } 153 }
158 154
159 protected: 155 protected:
160 virtual void VerifyParameters(int parameter_count, 156 virtual void VerifyParameters(int parameter_count,
161 MachineRepresentation* parameters) = 0; 157 MachineType* parameters) = 0;
162 virtual byte* Generate() = 0; 158 virtual byte* Generate() = 0;
163 159
164 private: 160 private:
165 #if USE_SIMULATOR && V8_TARGET_ARCH_ARM64 161 #if USE_SIMULATOR && V8_TARGET_ARCH_ARM64
166 uintptr_t CallSimulator(byte* f, Simulator::CallArgument* args) { 162 uintptr_t CallSimulator(byte* f, Simulator::CallArgument* args) {
167 Simulator* simulator = Simulator::current(isolate_); 163 Simulator* simulator = Simulator::current(isolate_);
168 return static_cast<uintptr_t>(simulator->CallInt64(f, args)); 164 return static_cast<uintptr_t>(simulator->CallInt64(f, args));
169 } 165 }
170 166
171 template <typename R, typename F> 167 template <typename R, typename F>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 template <typename P1, typename P2, typename P3> 269 template <typename P1, typename P2, typename P3>
274 void VerifyParameters3() {} 270 void VerifyParameters3() {}
275 271
276 template <typename P1, typename P2, typename P3, typename P4> 272 template <typename P1, typename P2, typename P3, typename P4>
277 void VerifyParameters4() {} 273 void VerifyParameters4() {}
278 #else 274 #else
279 void VerifyParameters0() { VerifyParameters(0, NULL); } 275 void VerifyParameters0() { VerifyParameters(0, NULL); }
280 276
281 template <typename P1> 277 template <typename P1>
282 void VerifyParameters1() { 278 void VerifyParameters1() {
283 MachineRepresentation parameters[] = { 279 MachineType parameters[] = {ReturnValueTraits<P1>::Representation()};
284 ReturnValueTraits<P1>::Representation()};
285 VerifyParameters(ARRAY_SIZE(parameters), parameters); 280 VerifyParameters(ARRAY_SIZE(parameters), parameters);
286 } 281 }
287 282
288 template <typename P1, typename P2> 283 template <typename P1, typename P2>
289 void VerifyParameters2() { 284 void VerifyParameters2() {
290 MachineRepresentation parameters[] = { 285 MachineType parameters[] = {ReturnValueTraits<P1>::Representation(),
291 ReturnValueTraits<P1>::Representation(), 286 ReturnValueTraits<P2>::Representation()};
292 ReturnValueTraits<P2>::Representation()};
293 VerifyParameters(ARRAY_SIZE(parameters), parameters); 287 VerifyParameters(ARRAY_SIZE(parameters), parameters);
294 } 288 }
295 289
296 template <typename P1, typename P2, typename P3> 290 template <typename P1, typename P2, typename P3>
297 void VerifyParameters3() { 291 void VerifyParameters3() {
298 MachineRepresentation parameters[] = { 292 MachineType parameters[] = {ReturnValueTraits<P1>::Representation(),
299 ReturnValueTraits<P1>::Representation(), 293 ReturnValueTraits<P2>::Representation(),
300 ReturnValueTraits<P2>::Representation(), 294 ReturnValueTraits<P3>::Representation()};
301 ReturnValueTraits<P3>::Representation()};
302 VerifyParameters(ARRAY_SIZE(parameters), parameters); 295 VerifyParameters(ARRAY_SIZE(parameters), parameters);
303 } 296 }
304 297
305 template <typename P1, typename P2, typename P3, typename P4> 298 template <typename P1, typename P2, typename P3, typename P4>
306 void VerifyParameters4() { 299 void VerifyParameters4() {
307 MachineRepresentation parameters[] = { 300 MachineType parameters[] = {ReturnValueTraits<P1>::Representation(),
308 ReturnValueTraits<P1>::Representation(), 301 ReturnValueTraits<P2>::Representation(),
309 ReturnValueTraits<P2>::Representation(), 302 ReturnValueTraits<P3>::Representation(),
310 ReturnValueTraits<P3>::Representation(), 303 ReturnValueTraits<P4>::Representation()};
311 ReturnValueTraits<P4>::Representation()};
312 VerifyParameters(ARRAY_SIZE(parameters), parameters); 304 VerifyParameters(ARRAY_SIZE(parameters), parameters);
313 } 305 }
314 #endif 306 #endif
315 307
316 // TODO(dcarney): replace Call() in CallHelper2 with these. 308 // TODO(dcarney): replace Call() in CallHelper2 with these.
317 template <typename R> 309 template <typename R>
318 R Call0() { 310 R Call0() {
319 typedef R V8_CDECL FType(); 311 typedef R V8_CDECL FType();
320 VerifyParameters0(); 312 VerifyParameters0();
321 return DoCall<R>(FUNCTION_CAST<FType*>(Generate())); 313 return DoCall<R>(FUNCTION_CAST<FType*>(Generate()));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 375
384 private: 376 private:
385 CallHelper* helper() { return static_cast<C*>(this); } 377 CallHelper* helper() { return static_cast<C*>(this); }
386 }; 378 };
387 379
388 } // namespace compiler 380 } // namespace compiler
389 } // namespace internal 381 } // namespace internal
390 } // namespace v8 382 } // namespace v8
391 383
392 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_ 384 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_
OLDNEW
« no previous file with comments | « src/compiler/x64/linkage-x64.cc ('k') | test/cctest/compiler/codegen-tester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698