OLD | NEW |
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 // TODO(titzer): move MachineType selection for C types into machine-type.h |
26 template <typename R> | 27 template <typename R> |
27 struct ReturnValueTraits { | 28 struct ReturnValueTraits { |
28 static R Cast(uintptr_t r) { return reinterpret_cast<R>(r); } | 29 static R Cast(uintptr_t r) { return reinterpret_cast<R>(r); } |
29 static MachineType Representation() { | 30 static MachineType Representation() { |
30 // TODO(dcarney): detect when R is of a subclass of Object* instead of this | 31 // TODO(dcarney): detect when R is of a subclass of Object* instead of this |
31 // type check. | 32 // type check. |
32 while (false) { | 33 while (false) { |
33 *(static_cast<Object* volatile*>(0)) = static_cast<R>(0); | 34 *(static_cast<Object* volatile*>(0)) = static_cast<R>(0); |
34 } | 35 } |
35 return kMachineTagged; | 36 return kMachAnyTagged; |
36 } | 37 } |
37 }; | 38 }; |
38 | 39 |
39 template <> | 40 template <> |
40 struct ReturnValueTraits<int32_t*> { | 41 struct ReturnValueTraits<int32_t*> { |
41 static int32_t* Cast(uintptr_t r) { return reinterpret_cast<int32_t*>(r); } | 42 static int32_t* Cast(uintptr_t r) { return reinterpret_cast<int32_t*>(r); } |
42 static MachineType Representation() { | 43 static MachineType Representation() { return kMachPtr; } |
43 return MachineOperatorBuilder::pointer_rep(); | |
44 } | |
45 }; | 44 }; |
46 | 45 |
47 template <> | 46 template <> |
48 struct ReturnValueTraits<void> { | 47 struct ReturnValueTraits<void> { |
49 static void Cast(uintptr_t r) {} | 48 static void Cast(uintptr_t r) {} |
50 static MachineType Representation() { | 49 static MachineType Representation() { return kMachPtr; } |
51 return MachineOperatorBuilder::pointer_rep(); | |
52 } | |
53 }; | 50 }; |
54 | 51 |
55 template <> | 52 template <> |
56 struct ReturnValueTraits<bool> { | 53 struct ReturnValueTraits<bool> { |
57 static bool Cast(uintptr_t r) { return static_cast<bool>(r); } | 54 static bool Cast(uintptr_t r) { return static_cast<bool>(r); } |
58 static MachineType Representation() { | 55 static MachineType Representation() { return kRepBit; } |
59 return MachineOperatorBuilder::pointer_rep(); | |
60 } | |
61 }; | 56 }; |
62 | 57 |
63 template <> | 58 template <> |
64 struct ReturnValueTraits<int32_t> { | 59 struct ReturnValueTraits<int32_t> { |
65 static int32_t Cast(uintptr_t r) { return static_cast<int32_t>(r); } | 60 static int32_t Cast(uintptr_t r) { return static_cast<int32_t>(r); } |
66 static MachineType Representation() { return kMachineWord32; } | 61 static MachineType Representation() { return kMachInt32; } |
67 }; | 62 }; |
68 | 63 |
69 template <> | 64 template <> |
70 struct ReturnValueTraits<uint32_t> { | 65 struct ReturnValueTraits<uint32_t> { |
71 static uint32_t Cast(uintptr_t r) { return static_cast<uint32_t>(r); } | 66 static uint32_t Cast(uintptr_t r) { return static_cast<uint32_t>(r); } |
72 static MachineType Representation() { return kMachineWord32; } | 67 static MachineType Representation() { return kMachUint32; } |
73 }; | 68 }; |
74 | 69 |
75 template <> | 70 template <> |
76 struct ReturnValueTraits<int64_t> { | 71 struct ReturnValueTraits<int64_t> { |
77 static int64_t Cast(uintptr_t r) { return static_cast<int64_t>(r); } | 72 static int64_t Cast(uintptr_t r) { return static_cast<int64_t>(r); } |
78 static MachineType Representation() { return kMachineWord64; } | 73 static MachineType Representation() { return kMachInt64; } |
79 }; | 74 }; |
80 | 75 |
81 template <> | 76 template <> |
82 struct ReturnValueTraits<uint64_t> { | 77 struct ReturnValueTraits<uint64_t> { |
83 static uint64_t Cast(uintptr_t r) { return static_cast<uint64_t>(r); } | 78 static uint64_t Cast(uintptr_t r) { return static_cast<uint64_t>(r); } |
84 static MachineType Representation() { return kMachineWord64; } | 79 static MachineType Representation() { return kMachUint64; } |
85 }; | 80 }; |
86 | 81 |
87 template <> | 82 template <> |
88 struct ReturnValueTraits<int16_t> { | 83 struct ReturnValueTraits<int16_t> { |
89 static int16_t Cast(uintptr_t r) { return static_cast<int16_t>(r); } | 84 static int16_t Cast(uintptr_t r) { return static_cast<int16_t>(r); } |
90 static MachineType Representation() { | 85 static MachineType Representation() { return kMachInt16; } |
91 return MachineOperatorBuilder::pointer_rep(); | |
92 } | |
93 }; | 86 }; |
94 | 87 |
95 template <> | 88 template <> |
96 struct ReturnValueTraits<int8_t> { | 89 struct ReturnValueTraits<int8_t> { |
97 static int8_t Cast(uintptr_t r) { return static_cast<int8_t>(r); } | 90 static int8_t Cast(uintptr_t r) { return static_cast<int8_t>(r); } |
98 static MachineType Representation() { | 91 static MachineType Representation() { return kMachInt8; } |
99 return MachineOperatorBuilder::pointer_rep(); | |
100 } | |
101 }; | 92 }; |
102 | 93 |
103 template <> | 94 template <> |
104 struct ReturnValueTraits<double> { | 95 struct ReturnValueTraits<double> { |
105 static double Cast(uintptr_t r) { | 96 static double Cast(uintptr_t r) { |
106 UNREACHABLE(); | 97 UNREACHABLE(); |
107 return 0.0; | 98 return 0.0; |
108 } | 99 } |
109 static MachineType Representation() { return kMachineFloat64; } | 100 static MachineType Representation() { return kMachFloat64; } |
110 }; | 101 }; |
111 | 102 |
112 | 103 |
113 template <typename R> | 104 template <typename R> |
114 struct ParameterTraits { | 105 struct ParameterTraits { |
115 static uintptr_t Cast(R r) { return static_cast<uintptr_t>(r); } | 106 static uintptr_t Cast(R r) { return static_cast<uintptr_t>(r); } |
116 }; | 107 }; |
117 | 108 |
118 template <> | 109 template <> |
119 struct ParameterTraits<int*> { | 110 struct ParameterTraits<int*> { |
120 static uintptr_t Cast(int* r) { return reinterpret_cast<uintptr_t>(r); } | 111 static uintptr_t Cast(int* r) { return reinterpret_cast<uintptr_t>(r); } |
121 }; | 112 }; |
122 | 113 |
123 template <typename T> | 114 template <typename T> |
124 struct ParameterTraits<T*> { | 115 struct ParameterTraits<T*> { |
125 static uintptr_t Cast(void* r) { return reinterpret_cast<uintptr_t>(r); } | 116 static uintptr_t Cast(void* r) { return reinterpret_cast<uintptr_t>(r); } |
126 }; | 117 }; |
127 | 118 |
128 class CallHelper { | 119 class CallHelper { |
129 public: | 120 public: |
130 explicit CallHelper(Isolate* isolate) : isolate_(isolate) { USE(isolate_); } | 121 explicit CallHelper(Isolate* isolate) : isolate_(isolate) { USE(isolate_); } |
131 virtual ~CallHelper() {} | 122 virtual ~CallHelper() {} |
132 | 123 |
133 static MachineCallDescriptorBuilder* ToCallDescriptorBuilder( | 124 static MachineCallDescriptorBuilder* ToCallDescriptorBuilder( |
134 Zone* zone, MachineType return_type, MachineType p0 = kMachineLast, | 125 Zone* zone, MachineType return_type, MachineType p0 = kMachNone, |
135 MachineType p1 = kMachineLast, MachineType p2 = kMachineLast, | 126 MachineType p1 = kMachNone, MachineType p2 = kMachNone, |
136 MachineType p3 = kMachineLast, MachineType p4 = kMachineLast) { | 127 MachineType p3 = kMachNone, MachineType p4 = kMachNone) { |
137 const int kSize = 5; | 128 const int kSize = 5; |
138 MachineType* params = zone->NewArray<MachineType>(kSize); | 129 MachineType* params = zone->NewArray<MachineType>(kSize); |
139 params[0] = p0; | 130 params[0] = p0; |
140 params[1] = p1; | 131 params[1] = p1; |
141 params[2] = p2; | 132 params[2] = p2; |
142 params[3] = p3; | 133 params[3] = p3; |
143 params[4] = p4; | 134 params[4] = p4; |
144 int parameter_count = 0; | 135 int parameter_count = 0; |
145 for (int i = 0; i < kSize; ++i) { | 136 for (int i = 0; i < kSize; ++i) { |
146 if (params[i] == kMachineLast) { | 137 if (params[i] == kMachNone) { |
147 break; | 138 break; |
148 } | 139 } |
149 parameter_count++; | 140 parameter_count++; |
150 } | 141 } |
151 return new (zone) | 142 return new (zone) |
152 MachineCallDescriptorBuilder(return_type, parameter_count, params); | 143 MachineCallDescriptorBuilder(return_type, parameter_count, params); |
153 } | 144 } |
154 | 145 |
155 protected: | 146 protected: |
156 virtual void VerifyParameters(int parameter_count, | 147 virtual void VerifyParameters(int parameter_count, |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 366 |
376 private: | 367 private: |
377 CallHelper* helper() { return static_cast<C*>(this); } | 368 CallHelper* helper() { return static_cast<C*>(this); } |
378 }; | 369 }; |
379 | 370 |
380 } // namespace compiler | 371 } // namespace compiler |
381 } // namespace internal | 372 } // namespace internal |
382 } // namespace v8 | 373 } // namespace v8 |
383 | 374 |
384 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_ | 375 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_ |
OLD | NEW |