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

Side by Side Diff: test/cctest/compiler/c-signature.h

Issue 1150083006: [turbofan] Tester improvements; use CSignature and simplify ReturnValueTraits. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | test/cctest/compiler/call-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_COMPILER_C_SIGNATURE_H_ 5 #ifndef V8_COMPILER_C_SIGNATURE_H_
6 #define V8_COMPILER_C_SIGNATURE_H_ 6 #define V8_COMPILER_C_SIGNATURE_H_
7 7
8 #include "src/compiler/machine-type.h" 8 #include "src/compiler/machine-type.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 namespace compiler { 12 namespace compiler {
13 13
14 #define FOREACH_CTYPE_MACHINE_TYPE_MAPPING(V) \
15 V(void, kMachNone) \
16 V(bool, kMachBool) \
17 V(int8_t, kMachInt8) \
18 V(uint8_t, kMachUint8) \
19 V(int16_t, kMachInt16) \
20 V(uint16_t, kMachUint16) \
21 V(int32_t, kMachInt32) \
22 V(uint32_t, kMachUint32) \
23 V(int64_t, kMachInt64) \
24 V(uint64_t, kMachUint64) \
25 V(float, kMachFloat32) \
26 V(double, kMachFloat64) \
27 V(void*, kMachPtr) \
28 V(int*, kMachPtr)
29
14 template <typename T> 30 template <typename T>
15 inline MachineType MachineTypeForC() { 31 inline MachineType MachineTypeForC() {
16 CHECK(false); // Instantiated with invalid type. 32 while (false) {
17 return kMachNone; 33 // All other types T must be assignable to Object*
18 } 34 *(static_cast<Object* volatile*>(0)) = static_cast<T>(0);
19 35 }
20 template <>
21 inline MachineType MachineTypeForC<void>() {
22 return kMachNone;
23 }
24
25 template <>
26 inline MachineType MachineTypeForC<int8_t>() {
27 return kMachInt8;
28 }
29
30 template <>
31 inline MachineType MachineTypeForC<uint8_t>() {
32 return kMachUint8;
33 }
34
35 template <>
36 inline MachineType MachineTypeForC<int16_t>() {
37 return kMachInt16;
38 }
39
40 template <>
41 inline MachineType MachineTypeForC<uint16_t>() {
42 return kMachUint16;
43 }
44
45 template <>
46 inline MachineType MachineTypeForC<int32_t>() {
47 return kMachInt32;
48 }
49
50 template <>
51 inline MachineType MachineTypeForC<uint32_t>() {
52 return kMachUint32;
53 }
54
55 template <>
56 inline MachineType MachineTypeForC<int64_t>() {
57 return kMachInt64;
58 }
59
60 template <>
61 inline MachineType MachineTypeForC<uint64_t>() {
62 return kMachUint64;
63 }
64
65 template <>
66 inline MachineType MachineTypeForC<double>() {
67 return kMachFloat64;
68 }
69
70 template <>
71 inline MachineType MachineTypeForC<Object*>() {
72 return kMachAnyTagged; 36 return kMachAnyTagged;
73 } 37 }
74 38
39 #define DECLARE_TEMPLATE_SPECIALIZATION(ctype, mtype) \
40 template <> \
41 inline MachineType MachineTypeForC<ctype>() { \
42 return mtype; \
43 }
44 FOREACH_CTYPE_MACHINE_TYPE_MAPPING(DECLARE_TEMPLATE_SPECIALIZATION)
45 #undef DECLARE_TEMPLATE_SPECIALIZATION
46
47 // Helper for building machine signatures from C types.
48 class CSignature : public MachineSignature {
49 protected:
50 CSignature(size_t return_count, size_t parameter_count, MachineType* reps)
51 : MachineSignature(return_count, parameter_count, reps) {}
52
53 public:
54 template <typename P1 = void, typename P2 = void, typename P3 = void,
55 typename P4 = void, typename P5 = void>
56 void Verify() {
57 // Verifies the C signature against the machine types. Maximum {5} params.
58 CHECK_LT(parameter_count(), 6);
59 const int kMax = 5;
60 MachineType params[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>(),
61 MachineTypeForC<P3>(), MachineTypeForC<P4>(),
62 MachineTypeForC<P5>()};
63 for (int p = kMax - 1; p >= 0; p--) {
64 if (p < parameter_count()) {
65 CHECK_EQ(GetParam(p), params[p]);
66 } else {
67 CHECK_EQ(kMachNone, params[p]);
68 }
69 }
70 }
71 };
72
73
75 template <typename Ret, uint16_t kParamCount> 74 template <typename Ret, uint16_t kParamCount>
76 class CSignatureOf : public MachineSignature { 75 class CSignatureOf : public CSignature {
77 protected: 76 protected:
78 MachineType storage_[1 + kParamCount]; 77 MachineType storage_[1 + kParamCount];
79 78
80 CSignatureOf() 79 CSignatureOf()
81 : MachineSignature(MachineTypeForC<Ret>() != kMachNone ? 1 : 0, 80 : CSignature(MachineTypeForC<Ret>() != kMachNone ? 1 : 0, kParamCount,
82 kParamCount, 81 reinterpret_cast<MachineType*>(&storage_)) {
83 reinterpret_cast<MachineType*>(&storage_)) {
84 if (return_count_ == 1) storage_[0] = MachineTypeForC<Ret>(); 82 if (return_count_ == 1) storage_[0] = MachineTypeForC<Ret>();
85 } 83 }
86 void Set(int index, MachineType type) { 84 void Set(int index, MachineType type) {
87 DCHECK(index >= 0 && index < kParamCount); 85 DCHECK(index >= 0 && index < kParamCount);
88 reps_[return_count_ + index] = type; 86 reps_[return_count_ + index] = type;
89 } 87 }
90 }; 88 };
91 89
92 // Helper classes for instantiating Signature objects to be callable from C. 90 // Helper classes for instantiating Signature objects to be callable from C.
93 template <typename Ret> 91 template <typename Ret>
(...skipping 22 matching lines...) Expand all
116 template <typename Ret, typename P1, typename P2, typename P3> 114 template <typename Ret, typename P1, typename P2, typename P3>
117 class CSignature3 : public CSignatureOf<Ret, 3> { 115 class CSignature3 : public CSignatureOf<Ret, 3> {
118 public: 116 public:
119 CSignature3() : CSignatureOf<Ret, 3>() { 117 CSignature3() : CSignatureOf<Ret, 3>() {
120 this->Set(0, MachineTypeForC<P1>()); 118 this->Set(0, MachineTypeForC<P1>());
121 this->Set(1, MachineTypeForC<P2>()); 119 this->Set(1, MachineTypeForC<P2>());
122 this->Set(2, MachineTypeForC<P3>()); 120 this->Set(2, MachineTypeForC<P3>());
123 } 121 }
124 }; 122 };
125 123
126 static const CSignature2<int32_t, int32_t, int32_t> int32_int32_to_int32; 124 typedef CSignature2<int32_t, int32_t, int32_t> CSignature_i_ii;
127 static const CSignature2<uint32_t, uint32_t, uint32_t> uint32_uint32_to_uint32; 125 typedef CSignature2<uint32_t, uint32_t, uint32_t> CSignature_u_uu;
128 static const CSignature2<double, double, double> float64_float64_to_float64; 126 typedef CSignature2<float, float, float> CSignature_f_ff;
127 typedef CSignature2<double, double, double> CSignature_d_dd;
128 typedef CSignature2<Object*, Object*, Object*> CSignature_o_oo;
129 } 129 }
130 } 130 }
131 } // namespace v8::internal::compiler 131 } // namespace v8::internal::compiler
132 132
133 #endif // V8_COMPILER_C_SIGNATURE_H_ 133 #endif // V8_COMPILER_C_SIGNATURE_H_
OLDNEW
« no previous file with comments | « no previous file | test/cctest/compiler/call-tester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698