Chromium Code Reviews| 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 // TODO(titzer): use c-signature.h instead of ReturnValueTraits |
| 27 template <typename R> | 27 template <typename R> |
| 28 struct ReturnValueTraits { | 28 struct ReturnValueTraits { |
| 29 static R Cast(uintptr_t r) { return reinterpret_cast<R>(r); } | 29 static R Cast(uintptr_t r) { return reinterpret_cast<R>(r); } |
| 30 static MachineType Representation() { | 30 static MachineType Representation() { |
| 31 // 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 |
| 32 // type check. | 32 // type check. |
| 33 while (false) { | 33 while (false) { |
| 34 *(static_cast<Object* volatile*>(0)) = static_cast<R>(0); | 34 *(static_cast<Object* volatile*>(0)) = static_cast<R>(0); |
| 35 } | 35 } |
| 36 return kMachAnyTagged; | 36 return kMachAnyTagged; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 static uintptr_t Cast(int* r) { return reinterpret_cast<uintptr_t>(r); } | 123 static uintptr_t Cast(int* r) { return reinterpret_cast<uintptr_t>(r); } |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 template <typename T> | 126 template <typename T> |
| 127 struct ParameterTraits<T*> { | 127 struct ParameterTraits<T*> { |
| 128 static uintptr_t Cast(void* r) { return reinterpret_cast<uintptr_t>(r); } | 128 static uintptr_t Cast(void* r) { return reinterpret_cast<uintptr_t>(r); } |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 class CallHelper { | 131 class CallHelper { |
| 132 public: | 132 public: |
| 133 explicit CallHelper(Isolate* isolate) : isolate_(isolate) { USE(isolate_); } | 133 explicit CallHelper(Isolate* isolate, MachineSignature* machine_sig) |
| 134 : machine_sig_(machine_sig), isolate_(isolate) { | |
| 135 USE(isolate_); | |
| 136 } | |
| 134 virtual ~CallHelper() {} | 137 virtual ~CallHelper() {} |
| 135 | 138 |
| 136 static MachineCallDescriptorBuilder* ToCallDescriptorBuilder( | 139 static MachineSignature* MakeMachineSignature( |
| 137 Zone* zone, MachineType return_type, MachineType p0 = kMachNone, | 140 Zone* zone, MachineType return_type, MachineType p0 = kMachNone, |
| 138 MachineType p1 = kMachNone, MachineType p2 = kMachNone, | 141 MachineType p1 = kMachNone, MachineType p2 = kMachNone, |
| 139 MachineType p3 = kMachNone, MachineType p4 = kMachNone) { | 142 MachineType p3 = kMachNone, MachineType p4 = kMachNone) { |
| 140 const int kSize = 5; | 143 // Count the number of parameters. |
| 141 MachineType* params = zone->NewArray<MachineType>(kSize); | 144 int param_count = 5; |
|
Benedikt Meurer
2014/09/02 08:37:42
Nit: size_t
titzer
2014/09/02 12:13:53
Done.
| |
| 142 params[0] = p0; | 145 MachineType types[] = {p0, p1, p2, p3, p4}; |
| 143 params[1] = p1; | 146 for (int i = param_count - 1; i >= 0; i--) { |
|
Benedikt Meurer
2014/09/02 08:37:42
for (; param_count != 0 && types[param_count - 1]
titzer
2014/09/02 12:13:53
Done.
| |
| 144 params[2] = p2; | 147 if (types[i] == kMachNone) param_count = i; |
| 145 params[3] = p3; | |
| 146 params[4] = p4; | |
| 147 int parameter_count = 0; | |
| 148 for (int i = 0; i < kSize; ++i) { | |
| 149 if (params[i] == kMachNone) { | |
| 150 break; | |
| 151 } | |
| 152 parameter_count++; | |
| 153 } | 148 } |
| 154 return new (zone) | 149 int return_count = return_type == kMachNone ? 0 : 1; |
|
Benedikt Meurer
2014/09/02 08:37:42
size_t
titzer
2014/09/02 12:13:53
Done.
| |
| 155 MachineCallDescriptorBuilder(return_type, parameter_count, params); | 150 |
| 151 // Build the machine signature. | |
| 152 MachineSignature::Builder builder(zone, return_count, param_count); | |
| 153 if (return_count > 0) builder.AddReturn(return_type); | |
| 154 for (int i = 0; i < param_count; i++) { | |
|
Benedikt Meurer
2014/09/02 08:37:42
size_t
titzer
2014/09/02 12:13:53
Done.
| |
| 155 builder.AddParam(types[i]); | |
| 156 } | |
| 157 return builder.Build(); | |
| 156 } | 158 } |
| 157 | 159 |
| 158 protected: | 160 protected: |
| 159 virtual void VerifyParameters(int parameter_count, | 161 MachineSignature* machine_sig_; |
| 160 MachineType* parameters) = 0; | 162 void VerifyParameters(int parameter_count, MachineType* parameter_types) { |
|
Benedikt Meurer
2014/09/02 08:37:42
size_t
| |
| 163 CHECK_EQ(machine_sig_->ParamCount(), parameter_count); | |
| 164 for (int i = 0; i < parameter_count; i++) { | |
|
Benedikt Meurer
2014/09/02 08:37:42
size_t
| |
| 165 CHECK_EQ(machine_sig_->GetParam(i), parameter_types[i]); | |
| 166 } | |
| 167 } | |
| 161 virtual byte* Generate() = 0; | 168 virtual byte* Generate() = 0; |
| 162 | 169 |
| 163 private: | 170 private: |
| 164 #if USE_SIMULATOR && V8_TARGET_ARCH_ARM64 | 171 #if USE_SIMULATOR && V8_TARGET_ARCH_ARM64 |
| 165 uintptr_t CallSimulator(byte* f, Simulator::CallArgument* args) { | 172 uintptr_t CallSimulator(byte* f, Simulator::CallArgument* args) { |
| 166 Simulator* simulator = Simulator::current(isolate_); | 173 Simulator* simulator = Simulator::current(isolate_); |
| 167 return static_cast<uintptr_t>(simulator->CallInt64(f, args)); | 174 return static_cast<uintptr_t>(simulator->CallInt64(f, args)); |
| 168 } | 175 } |
| 169 | 176 |
| 170 template <typename R, typename F> | 177 template <typename R, typename F> |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 | 385 |
| 379 private: | 386 private: |
| 380 CallHelper* helper() { return static_cast<C*>(this); } | 387 CallHelper* helper() { return static_cast<C*>(this); } |
| 381 }; | 388 }; |
| 382 | 389 |
| 383 } // namespace compiler | 390 } // namespace compiler |
| 384 } // namespace internal | 391 } // namespace internal |
| 385 } // namespace v8 | 392 } // namespace v8 |
| 386 | 393 |
| 387 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_ | 394 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_ |
| OLD | NEW |