| 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 size_t param_count = 5; |
| 142 params[0] = p0; | 145 MachineType types[] = {p0, p1, p2, p3, p4}; |
| 143 params[1] = p1; | 146 while (param_count > 0 && types[param_count - 1] == kMachNone) |
| 144 params[2] = p2; | 147 param_count--; |
| 145 params[3] = p3; | 148 size_t return_count = return_type == kMachNone ? 0 : 1; |
| 146 params[4] = p4; | 149 |
| 147 int parameter_count = 0; | 150 // Build the machine signature. |
| 148 for (int i = 0; i < kSize; ++i) { | 151 MachineSignature::Builder builder(zone, return_count, param_count); |
| 149 if (params[i] == kMachNone) { | 152 if (return_count > 0) builder.AddReturn(return_type); |
| 150 break; | 153 for (size_t i = 0; i < param_count; i++) { |
| 151 } | 154 builder.AddParam(types[i]); |
| 152 parameter_count++; | |
| 153 } | 155 } |
| 154 return new (zone) | 156 return builder.Build(); |
| 155 MachineCallDescriptorBuilder(return_type, parameter_count, params); | |
| 156 } | 157 } |
| 157 | 158 |
| 158 protected: | 159 protected: |
| 159 virtual void VerifyParameters(int parameter_count, | 160 MachineSignature* machine_sig_; |
| 160 MachineType* parameters) = 0; | 161 void VerifyParameters(size_t parameter_count, MachineType* parameter_types) { |
| 162 CHECK(machine_sig_->parameter_count() == parameter_count); |
| 163 for (size_t i = 0; i < parameter_count; i++) { |
| 164 CHECK_EQ(machine_sig_->GetParam(i), parameter_types[i]); |
| 165 } |
| 166 } |
| 161 virtual byte* Generate() = 0; | 167 virtual byte* Generate() = 0; |
| 162 | 168 |
| 163 private: | 169 private: |
| 164 #if USE_SIMULATOR && V8_TARGET_ARCH_ARM64 | 170 #if USE_SIMULATOR && V8_TARGET_ARCH_ARM64 |
| 165 uintptr_t CallSimulator(byte* f, Simulator::CallArgument* args) { | 171 uintptr_t CallSimulator(byte* f, Simulator::CallArgument* args) { |
| 166 Simulator* simulator = Simulator::current(isolate_); | 172 Simulator* simulator = Simulator::current(isolate_); |
| 167 return static_cast<uintptr_t>(simulator->CallInt64(f, args)); | 173 return static_cast<uintptr_t>(simulator->CallInt64(f, args)); |
| 168 } | 174 } |
| 169 | 175 |
| 170 template <typename R, typename F> | 176 template <typename R, typename F> |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 | 384 |
| 379 private: | 385 private: |
| 380 CallHelper* helper() { return static_cast<C*>(this); } | 386 CallHelper* helper() { return static_cast<C*>(this); } |
| 381 }; | 387 }; |
| 382 | 388 |
| 383 } // namespace compiler | 389 } // namespace compiler |
| 384 } // namespace internal | 390 } // namespace internal |
| 385 } // namespace v8 | 391 } // namespace v8 |
| 386 | 392 |
| 387 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_ | 393 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_ |
| OLD | NEW |