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_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/machine-type.h" | 8 #include "src/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) \ | 14 #define FOREACH_CTYPE_MACHINE_TYPE_MAPPING(V) \ |
15 V(void, kMachNone) \ | 15 V(void, MachineType::None()) \ |
16 V(bool, kMachUint8) \ | 16 V(bool, MachineType::Uint8()) \ |
17 V(int8_t, kMachInt8) \ | 17 V(int8_t, MachineType::Int8()) \ |
18 V(uint8_t, kMachUint8) \ | 18 V(uint8_t, MachineType::Uint8()) \ |
19 V(int16_t, kMachInt16) \ | 19 V(int16_t, MachineType::Int16()) \ |
20 V(uint16_t, kMachUint16) \ | 20 V(uint16_t, MachineType::Uint16()) \ |
21 V(int32_t, kMachInt32) \ | 21 V(int32_t, MachineType::Int32()) \ |
22 V(uint32_t, kMachUint32) \ | 22 V(uint32_t, MachineType::Uint32()) \ |
23 V(int64_t, kMachInt64) \ | 23 V(int64_t, MachineType::Int64()) \ |
24 V(uint64_t, kMachUint64) \ | 24 V(uint64_t, MachineType::Uint64()) \ |
25 V(float, kMachFloat32) \ | 25 V(float, MachineType::Float32()) \ |
26 V(double, kMachFloat64) \ | 26 V(double, MachineType::Float64()) \ |
27 V(void*, kMachPtr) \ | 27 V(void*, MachineType::Pointer()) \ |
28 V(int*, kMachPtr) | 28 V(int*, MachineType::Pointer()) |
29 | 29 |
30 template <typename T> | 30 template <typename T> |
31 inline MachineType MachineTypeForC() { | 31 inline MachineType MachineTypeForC() { |
32 while (false) { | 32 while (false) { |
33 // All other types T must be assignable to Object* | 33 // All other types T must be assignable to Object* |
34 *(static_cast<Object* volatile*>(0)) = static_cast<T>(0); | 34 *(static_cast<Object* volatile*>(0)) = static_cast<T>(0); |
35 } | 35 } |
36 return kMachAnyTagged; | 36 return MachineType::AnyTagged(); |
37 } | 37 } |
38 | 38 |
39 #define DECLARE_TEMPLATE_SPECIALIZATION(ctype, mtype) \ | 39 #define DECLARE_TEMPLATE_SPECIALIZATION(ctype, mtype) \ |
40 template <> \ | 40 template <> \ |
41 inline MachineType MachineTypeForC<ctype>() { \ | 41 inline MachineType MachineTypeForC<ctype>() { \ |
42 return mtype; \ | 42 return mtype; \ |
43 } | 43 } |
44 FOREACH_CTYPE_MACHINE_TYPE_MAPPING(DECLARE_TEMPLATE_SPECIALIZATION) | 44 FOREACH_CTYPE_MACHINE_TYPE_MAPPING(DECLARE_TEMPLATE_SPECIALIZATION) |
45 #undef DECLARE_TEMPLATE_SPECIALIZATION | 45 #undef DECLARE_TEMPLATE_SPECIALIZATION |
46 | 46 |
(...skipping 10 matching lines...) Expand all Loading... |
57 // Verifies the C signature against the machine types. Maximum {5} params. | 57 // Verifies the C signature against the machine types. Maximum {5} params. |
58 CHECK_LT(parameter_count(), 6u); | 58 CHECK_LT(parameter_count(), 6u); |
59 const int kMax = 5; | 59 const int kMax = 5; |
60 MachineType params[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>(), | 60 MachineType params[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>(), |
61 MachineTypeForC<P3>(), MachineTypeForC<P4>(), | 61 MachineTypeForC<P3>(), MachineTypeForC<P4>(), |
62 MachineTypeForC<P5>()}; | 62 MachineTypeForC<P5>()}; |
63 for (int p = kMax - 1; p >= 0; p--) { | 63 for (int p = kMax - 1; p >= 0; p--) { |
64 if (p < static_cast<int>(parameter_count())) { | 64 if (p < static_cast<int>(parameter_count())) { |
65 CHECK_EQ(GetParam(p), params[p]); | 65 CHECK_EQ(GetParam(p), params[p]); |
66 } else { | 66 } else { |
67 CHECK_EQ(kMachNone, params[p]); | 67 CHECK_EQ(MachineType::None(), params[p]); |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 static CSignature* FromMachine(Zone* zone, MachineSignature* msig) { | 72 static CSignature* FromMachine(Zone* zone, MachineSignature* msig) { |
73 return reinterpret_cast<CSignature*>(msig); | 73 return reinterpret_cast<CSignature*>(msig); |
74 } | 74 } |
75 | 75 |
76 static CSignature* New(Zone* zone, MachineType ret, | 76 static CSignature* New(Zone* zone, MachineType ret, |
77 MachineType p1 = kMachNone, MachineType p2 = kMachNone, | 77 MachineType p1 = MachineType::None(), |
78 MachineType p3 = kMachNone, MachineType p4 = kMachNone, | 78 MachineType p2 = MachineType::None(), |
79 MachineType p5 = kMachNone) { | 79 MachineType p3 = MachineType::None(), |
| 80 MachineType p4 = MachineType::None(), |
| 81 MachineType p5 = MachineType::None()) { |
80 MachineType* buffer = zone->NewArray<MachineType>(6); | 82 MachineType* buffer = zone->NewArray<MachineType>(6); |
81 int pos = 0; | 83 int pos = 0; |
82 size_t return_count = 0; | 84 size_t return_count = 0; |
83 if (ret != kMachNone) { | 85 if (ret != MachineType::None()) { |
84 buffer[pos++] = ret; | 86 buffer[pos++] = ret; |
85 return_count++; | 87 return_count++; |
86 } | 88 } |
87 buffer[pos++] = p1; | 89 buffer[pos++] = p1; |
88 buffer[pos++] = p2; | 90 buffer[pos++] = p2; |
89 buffer[pos++] = p3; | 91 buffer[pos++] = p3; |
90 buffer[pos++] = p4; | 92 buffer[pos++] = p4; |
91 buffer[pos++] = p5; | 93 buffer[pos++] = p5; |
92 size_t param_count = 5; | 94 size_t param_count = 5; |
93 if (p5 == kMachNone) param_count--; | 95 if (p5 == MachineType::None()) param_count--; |
94 if (p4 == kMachNone) param_count--; | 96 if (p4 == MachineType::None()) param_count--; |
95 if (p3 == kMachNone) param_count--; | 97 if (p3 == MachineType::None()) param_count--; |
96 if (p2 == kMachNone) param_count--; | 98 if (p2 == MachineType::None()) param_count--; |
97 if (p1 == kMachNone) param_count--; | 99 if (p1 == MachineType::None()) param_count--; |
98 for (size_t i = 0; i < param_count; i++) { | 100 for (size_t i = 0; i < param_count; i++) { |
99 // Check that there are no kMachNone's in the middle of parameters. | 101 // Check that there are no MachineType::None()'s in the middle of |
100 CHECK_NE(kMachNone, buffer[return_count + i]); | 102 // parameters. |
| 103 CHECK_NE(MachineType::None(), buffer[return_count + i]); |
101 } | 104 } |
102 return new (zone) CSignature(return_count, param_count, buffer); | 105 return new (zone) CSignature(return_count, param_count, buffer); |
103 } | 106 } |
104 }; | 107 }; |
105 | 108 |
106 | 109 |
107 template <typename Ret, uint16_t kParamCount> | 110 template <typename Ret, uint16_t kParamCount> |
108 class CSignatureOf : public CSignature { | 111 class CSignatureOf : public CSignature { |
109 protected: | 112 protected: |
110 MachineType storage_[1 + kParamCount]; | 113 MachineType storage_[1 + kParamCount]; |
111 | 114 |
112 CSignatureOf() | 115 CSignatureOf() |
113 : CSignature(MachineTypeForC<Ret>() != kMachNone ? 1 : 0, kParamCount, | 116 : CSignature(MachineTypeForC<Ret>() != MachineType::None() ? 1 : 0, |
114 reinterpret_cast<MachineType*>(&storage_)) { | 117 kParamCount, reinterpret_cast<MachineType*>(&storage_)) { |
115 if (return_count_ == 1) storage_[0] = MachineTypeForC<Ret>(); | 118 if (return_count_ == 1) storage_[0] = MachineTypeForC<Ret>(); |
116 } | 119 } |
117 void Set(int index, MachineType type) { | 120 void Set(int index, MachineType type) { |
118 CHECK_LE(0, index); | 121 CHECK_LE(0, index); |
119 CHECK_LT(index, kParamCount); | 122 CHECK_LT(index, kParamCount); |
120 reps_[return_count_ + index] = type; | 123 reps_[return_count_ + index] = type; |
121 } | 124 } |
122 }; | 125 }; |
123 | 126 |
124 // Helper classes for instantiating Signature objects to be callable from C. | 127 // Helper classes for instantiating Signature objects to be callable from C. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 typedef CSignature2<int32_t, int32_t, int32_t> CSignature_i_ii; | 161 typedef CSignature2<int32_t, int32_t, int32_t> CSignature_i_ii; |
159 typedef CSignature2<uint32_t, uint32_t, uint32_t> CSignature_u_uu; | 162 typedef CSignature2<uint32_t, uint32_t, uint32_t> CSignature_u_uu; |
160 typedef CSignature2<float, float, float> CSignature_f_ff; | 163 typedef CSignature2<float, float, float> CSignature_f_ff; |
161 typedef CSignature2<double, double, double> CSignature_d_dd; | 164 typedef CSignature2<double, double, double> CSignature_d_dd; |
162 typedef CSignature2<Object*, Object*, Object*> CSignature_o_oo; | 165 typedef CSignature2<Object*, Object*, Object*> CSignature_o_oo; |
163 } // namespace compiler | 166 } // namespace compiler |
164 } // namespace internal | 167 } // namespace internal |
165 } // namespace v8 | 168 } // namespace v8 |
166 | 169 |
167 #endif // V8_COMPILER_C_SIGNATURE_H_ | 170 #endif // V8_COMPILER_C_SIGNATURE_H_ |
OLD | NEW |