Index: test/cctest/compiler/c-signature.h |
diff --git a/test/cctest/compiler/c-signature.h b/test/cctest/compiler/c-signature.h |
index 5d161dbe7ae3eed5bcd9601a9d7a81bbdb1fbf55..fee8cb946d05fc0e3e6e36b0c581a13af66b5cc3 100644 |
--- a/test/cctest/compiler/c-signature.h |
+++ b/test/cctest/compiler/c-signature.h |
@@ -11,76 +11,74 @@ namespace v8 { |
namespace internal { |
namespace compiler { |
+#define FOREACH_CTYPE_MACHINE_TYPE_MAPPING(V) \ |
+ V(void, kMachNone) \ |
+ V(bool, kMachBool) \ |
+ V(int8_t, kMachInt8) \ |
+ V(uint8_t, kMachUint8) \ |
+ V(int16_t, kMachInt16) \ |
+ V(uint16_t, kMachUint16) \ |
+ V(int32_t, kMachInt32) \ |
+ V(uint32_t, kMachUint32) \ |
+ V(int64_t, kMachInt64) \ |
+ V(uint64_t, kMachUint64) \ |
+ V(float, kMachFloat32) \ |
+ V(double, kMachFloat64) \ |
+ V(void*, kMachPtr) \ |
+ V(int*, kMachPtr) |
+ |
template <typename T> |
inline MachineType MachineTypeForC() { |
- CHECK(false); // Instantiated with invalid type. |
- return kMachNone; |
-} |
- |
-template <> |
-inline MachineType MachineTypeForC<void>() { |
- return kMachNone; |
-} |
- |
-template <> |
-inline MachineType MachineTypeForC<int8_t>() { |
- return kMachInt8; |
-} |
- |
-template <> |
-inline MachineType MachineTypeForC<uint8_t>() { |
- return kMachUint8; |
-} |
- |
-template <> |
-inline MachineType MachineTypeForC<int16_t>() { |
- return kMachInt16; |
-} |
- |
-template <> |
-inline MachineType MachineTypeForC<uint16_t>() { |
- return kMachUint16; |
-} |
- |
-template <> |
-inline MachineType MachineTypeForC<int32_t>() { |
- return kMachInt32; |
-} |
- |
-template <> |
-inline MachineType MachineTypeForC<uint32_t>() { |
- return kMachUint32; |
+ while (false) { |
+ // All other types T must be assignable to Object* |
+ *(static_cast<Object* volatile*>(0)) = static_cast<T>(0); |
+ } |
+ return kMachAnyTagged; |
} |
-template <> |
-inline MachineType MachineTypeForC<int64_t>() { |
- return kMachInt64; |
-} |
+#define DECLARE_TEMPLATE_SPECIALIZATION(ctype, mtype) \ |
+ template <> \ |
+ inline MachineType MachineTypeForC<ctype>() { \ |
+ return mtype; \ |
+ } |
+FOREACH_CTYPE_MACHINE_TYPE_MAPPING(DECLARE_TEMPLATE_SPECIALIZATION) |
+#undef DECLARE_TEMPLATE_SPECIALIZATION |
-template <> |
-inline MachineType MachineTypeForC<uint64_t>() { |
- return kMachUint64; |
-} |
+// Helper for building machine signatures from C types. |
+class CSignature : public MachineSignature { |
+ protected: |
+ CSignature(size_t return_count, size_t parameter_count, MachineType* reps) |
+ : MachineSignature(return_count, parameter_count, reps) {} |
-template <> |
-inline MachineType MachineTypeForC<double>() { |
- return kMachFloat64; |
-} |
+ public: |
+ template <typename P1 = void, typename P2 = void, typename P3 = void, |
+ typename P4 = void, typename P5 = void> |
+ void Verify() { |
+ // Verifies the C signature against the machine types. Maximum {5} params. |
+ CHECK_LT(parameter_count(), 6); |
+ const int kMax = 5; |
+ MachineType params[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>(), |
+ MachineTypeForC<P3>(), MachineTypeForC<P4>(), |
+ MachineTypeForC<P5>()}; |
+ for (int p = kMax - 1; p >= 0; p--) { |
+ if (p < parameter_count()) { |
+ CHECK_EQ(GetParam(p), params[p]); |
+ } else { |
+ CHECK_EQ(kMachNone, params[p]); |
+ } |
+ } |
+ } |
+}; |
-template <> |
-inline MachineType MachineTypeForC<Object*>() { |
- return kMachAnyTagged; |
-} |
template <typename Ret, uint16_t kParamCount> |
-class CSignatureOf : public MachineSignature { |
+class CSignatureOf : public CSignature { |
protected: |
MachineType storage_[1 + kParamCount]; |
CSignatureOf() |
- : MachineSignature(MachineTypeForC<Ret>() != kMachNone ? 1 : 0, |
- kParamCount, |
- reinterpret_cast<MachineType*>(&storage_)) { |
+ : CSignature(MachineTypeForC<Ret>() != kMachNone ? 1 : 0, kParamCount, |
+ reinterpret_cast<MachineType*>(&storage_)) { |
if (return_count_ == 1) storage_[0] = MachineTypeForC<Ret>(); |
} |
void Set(int index, MachineType type) { |
@@ -123,9 +121,11 @@ class CSignature3 : public CSignatureOf<Ret, 3> { |
} |
}; |
-static const CSignature2<int32_t, int32_t, int32_t> int32_int32_to_int32; |
-static const CSignature2<uint32_t, uint32_t, uint32_t> uint32_uint32_to_uint32; |
-static const CSignature2<double, double, double> float64_float64_to_float64; |
+typedef CSignature2<int32_t, int32_t, int32_t> CSignature_i_ii; |
+typedef CSignature2<uint32_t, uint32_t, uint32_t> CSignature_u_uu; |
+typedef CSignature2<float, float, float> CSignature_f_ff; |
+typedef CSignature2<double, double, double> CSignature_d_dd; |
+typedef CSignature2<Object*, Object*, Object*> CSignature_o_oo; |
} |
} |
} // namespace v8::internal::compiler |