OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 SRC_ASMJS_ASM_TYPES_H_ | 5 #ifndef SRC_ASMJS_ASM_TYPES_H_ |
6 #define SRC_ASMJS_ASM_TYPES_H_ | 6 #define SRC_ASMJS_ASM_TYPES_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "src/base/macros.h" | 10 #include "src/base/macros.h" |
11 #include "src/zone-containers.h" | 11 #include "src/zone-containers.h" |
12 #include "src/zone.h" | 12 #include "src/zone.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 namespace wasm { | 16 namespace wasm { |
17 | 17 |
18 class AsmType; | 18 class AsmType; |
19 class AsmFFIType; | 19 class AsmFFIType; |
20 class AsmFunctionType; | 20 class AsmFunctionType; |
21 class AsmOverloadedFunctionType; | 21 class AsmOverloadedFunctionType; |
22 class AsmFunctionTableType; | 22 class AsmFunctionTableType; |
23 | 23 |
24 // List of V(CamelName, string_name, number, parent_types) | 24 // List of V(CamelName, string_name, number, parent_types) |
25 #define FOR_EACH_ASM_VALUE_TYPE_LIST(V) \ | 25 #define FOR_EACH_ASM_VALUE_TYPE_LIST(V) \ |
26 /* These tags are not types that are expressable in the asm source. They */ \ | 26 /* These tags are not types that are expressable in the asm source. They */ \ |
27 /* are used to express semantic information about the types they tag. */ \ | 27 /* are used to express semantic information about the types they tag. */ \ |
28 V(Heap, "[]", 1, 0) \ | 28 V(Heap, "[]", 1, 0) \ |
29 /*The following are actual types that appear in the asm source. */ \ | 29 V(FloatishDoubleQ, "floatish|double?", 2, 0) \ |
30 V(Void, "void", 2, 0) \ | 30 V(FloatQDoubleQ, "float?|double?", 3, 0) \ |
31 V(Extern, "extern", 3, 0) \ | 31 /* The following are actual types that appear in the asm source. */ \ |
32 V(DoubleQ, "double?", 4, 0) \ | 32 V(Void, "void", 4, 0) \ |
33 V(Double, "double", 5, kAsmDoubleQ | kAsmExtern) \ | 33 V(Extern, "extern", 5, 0) \ |
34 V(Intish, "intish", 6, 0) \ | 34 V(DoubleQ, "double?", 6, kAsmFloatishDoubleQ | kAsmFloatQDoubleQ) \ |
35 V(Int, "int", 7, kAsmIntish) \ | 35 V(Double, "double", 7, kAsmDoubleQ | kAsmExtern) \ |
36 V(Signed, "signed", 8, kAsmInt | kAsmExtern) \ | 36 V(Intish, "intish", 8, 0) \ |
37 V(Unsigned, "unsigned", 9, kAsmInt) \ | 37 V(Int, "int", 9, kAsmIntish) \ |
38 V(FixNum, "fixnum", 10, kAsmSigned | kAsmUnsigned) \ | 38 V(Signed, "signed", 10, kAsmInt | kAsmExtern) \ |
39 V(Floatish, "floatish", 11, 0) \ | 39 V(Unsigned, "unsigned", 11, kAsmInt) \ |
40 V(FloatQ, "float?", 12, kAsmFloatish) \ | 40 V(FixNum, "fixnum", 12, kAsmSigned | kAsmUnsigned) \ |
41 V(Float, "float", 13, kAsmFloatQ) \ | 41 V(Floatish, "floatish", 13, kAsmFloatishDoubleQ) \ |
| 42 V(FloatQ, "float?", 14, kAsmFloatQDoubleQ | kAsmFloatish) \ |
| 43 V(Float, "float", 15, kAsmFloatQ) \ |
42 /* Types used for expressing the Heap accesses. */ \ | 44 /* Types used for expressing the Heap accesses. */ \ |
43 V(Uint8Array, "Uint8Array", 14, kAsmHeap) \ | 45 V(Uint8Array, "Uint8Array", 16, kAsmHeap) \ |
44 V(Int8Array, "Int8Array", 15, kAsmHeap) \ | 46 V(Int8Array, "Int8Array", 17, kAsmHeap) \ |
45 V(Uint16Array, "Uint16Array", 16, kAsmHeap) \ | 47 V(Uint16Array, "Uint16Array", 18, kAsmHeap) \ |
46 V(Int16Array, "Int16Array", 17, kAsmHeap) \ | 48 V(Int16Array, "Int16Array", 19, kAsmHeap) \ |
47 V(Uint32Array, "Uint32Array", 18, kAsmHeap) \ | 49 V(Uint32Array, "Uint32Array", 20, kAsmHeap) \ |
48 V(Int32Array, "Int32Array", 19, kAsmHeap) \ | 50 V(Int32Array, "Int32Array", 21, kAsmHeap) \ |
49 V(Float32Array, "Float32Array", 20, kAsmHeap) \ | 51 V(Float32Array, "Float32Array", 22, kAsmHeap) \ |
50 V(Float64Array, "Float64Array", 21, kAsmHeap) \ | 52 V(Float64Array, "Float64Array", 23, kAsmHeap) \ |
51 /* Pseudo-types used in representing heap access for fp types.*/ \ | |
52 /* TODO(jpp): FloatishDoubleQ should be a base type.*/ \ | |
53 V(FloatishDoubleQ, "floatish|double?", 22, kAsmFloatish | kAsmDoubleQ) \ | |
54 /* TODO(jpp): FloatQDoubleQ should be a base type.*/ \ | |
55 V(FloatQDoubleQ, "float?|double?", 23, kAsmFloatQ | kAsmDoubleQ) \ | |
56 /* None is used to represent errors in the type checker. */ \ | 53 /* None is used to represent errors in the type checker. */ \ |
57 V(None, "<none>", 31, 0) | 54 V(None, "<none>", 31, 0) |
58 | 55 |
59 // List of V(CamelName) | 56 // List of V(CamelName) |
60 #define FOR_EACH_ASM_CALLABLE_TYPE_LIST(V) \ | 57 #define FOR_EACH_ASM_CALLABLE_TYPE_LIST(V) \ |
61 V(FunctionType) \ | 58 V(FunctionType) \ |
62 V(FFIType) \ | 59 V(FFIType) \ |
63 V(OverloadedFunctionType) \ | 60 V(OverloadedFunctionType) \ |
64 V(FunctionTableType) | 61 V(FunctionTableType) |
65 | 62 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 static_cast<uintptr_t>(bits | kAsmValueTypeTag)); | 97 static_cast<uintptr_t>(bits | kAsmValueTypeTag)); |
101 } | 98 } |
102 | 99 |
103 // AsmValueTypes can't be created except through AsmValueType::New. | 100 // AsmValueTypes can't be created except through AsmValueType::New. |
104 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmValueType); | 101 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmValueType); |
105 }; | 102 }; |
106 | 103 |
107 class AsmCallableType : public ZoneObject { | 104 class AsmCallableType : public ZoneObject { |
108 public: | 105 public: |
109 virtual std::string Name() = 0; | 106 virtual std::string Name() = 0; |
110 virtual AsmType* ValidateCall(AsmType* return_type, | |
111 const ZoneVector<AsmType*>& args) = 0; | |
112 | 107 |
113 virtual bool CanBeInvokedWith(AsmType* return_type, | 108 virtual bool CanBeInvokedWith(AsmType* return_type, |
114 const ZoneVector<AsmType*>& args) = 0; | 109 const ZoneVector<AsmType*>& args) = 0; |
115 | 110 |
116 #define DECLARE_CAST(CamelName) \ | 111 #define DECLARE_CAST(CamelName) \ |
117 virtual Asm##CamelName* As##CamelName() { return nullptr; } | 112 virtual Asm##CamelName* As##CamelName() { return nullptr; } |
118 FOR_EACH_ASM_CALLABLE_TYPE_LIST(DECLARE_CAST) | 113 FOR_EACH_ASM_CALLABLE_TYPE_LIST(DECLARE_CAST) |
119 #undef DECLARE_CAST | 114 #undef DECLARE_CAST |
120 | 115 |
121 protected: | 116 protected: |
122 AsmCallableType() = default; | 117 AsmCallableType() = default; |
123 virtual ~AsmCallableType() = default; | 118 virtual ~AsmCallableType() = default; |
| 119 virtual bool IsA(AsmType* other); |
124 | 120 |
125 private: | 121 private: |
| 122 friend class AsmType; |
| 123 |
126 DISALLOW_COPY_AND_ASSIGN(AsmCallableType); | 124 DISALLOW_COPY_AND_ASSIGN(AsmCallableType); |
127 }; | 125 }; |
128 | 126 |
129 class AsmFunctionType : public AsmCallableType { | 127 class AsmFunctionType final : public AsmCallableType { |
130 public: | 128 public: |
131 AsmFunctionType* AsFunctionType() final { return this; } | 129 AsmFunctionType* AsFunctionType() final { return this; } |
132 | 130 |
133 void AddArgument(AsmType* type) { args_.push_back(type); } | 131 void AddArgument(AsmType* type) { args_.push_back(type); } |
134 const ZoneVector<AsmType*> Arguments() const { return args_; } | 132 const ZoneVector<AsmType*> Arguments() const { return args_; } |
135 AsmType* ReturnType() const { return return_type_; } | 133 AsmType* ReturnType() const { return return_type_; } |
136 | 134 |
137 virtual bool IsMinMaxType() const { return false; } | |
138 virtual bool IsFroundType() const { return false; } | |
139 | |
140 AsmType* ValidateCall(AsmType* return_type, | |
141 const ZoneVector<AsmType*>& args) override; | |
142 bool CanBeInvokedWith(AsmType* return_type, | 135 bool CanBeInvokedWith(AsmType* return_type, |
143 const ZoneVector<AsmType*>& args) override; | 136 const ZoneVector<AsmType*>& args) override; |
144 | 137 |
145 protected: | 138 protected: |
146 AsmFunctionType(Zone* zone, AsmType* return_type) | 139 AsmFunctionType(Zone* zone, AsmType* return_type) |
147 : return_type_(return_type), args_(zone) {} | 140 : return_type_(return_type), args_(zone) {} |
148 | 141 |
149 private: | 142 private: |
150 friend AsmType; | 143 friend AsmType; |
151 | 144 |
152 std::string Name() override; | 145 std::string Name() override; |
| 146 bool IsA(AsmType* other) override; |
153 | 147 |
154 AsmType* return_type_; | 148 AsmType* return_type_; |
155 ZoneVector<AsmType*> args_; | 149 ZoneVector<AsmType*> args_; |
156 | 150 |
157 DISALLOW_COPY_AND_ASSIGN(AsmFunctionType); | 151 DISALLOW_COPY_AND_ASSIGN(AsmFunctionType); |
158 }; | 152 }; |
159 | 153 |
160 class AsmOverloadedFunctionType final : public AsmCallableType { | 154 class AsmOverloadedFunctionType final : public AsmCallableType { |
161 public: | 155 public: |
162 AsmOverloadedFunctionType* AsOverloadedFunctionType() override { | 156 AsmOverloadedFunctionType* AsOverloadedFunctionType() override { |
163 return this; | 157 return this; |
164 } | 158 } |
165 | 159 |
166 void AddOverload(AsmType* overload); | 160 void AddOverload(AsmType* overload); |
167 | 161 |
168 private: | 162 private: |
169 friend AsmType; | 163 friend AsmType; |
170 | 164 |
171 explicit AsmOverloadedFunctionType(Zone* zone) : overloads_(zone) {} | 165 explicit AsmOverloadedFunctionType(Zone* zone) : overloads_(zone) {} |
172 | 166 |
173 std::string Name() override; | 167 std::string Name() override; |
174 AsmType* ValidateCall(AsmType* return_type, | |
175 const ZoneVector<AsmType*>& args) override; | |
176 bool CanBeInvokedWith(AsmType* return_type, | 168 bool CanBeInvokedWith(AsmType* return_type, |
177 const ZoneVector<AsmType*>& args) override; | 169 const ZoneVector<AsmType*>& args) override; |
178 | 170 |
179 ZoneVector<AsmType*> overloads_; | 171 ZoneVector<AsmType*> overloads_; |
180 | 172 |
181 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmOverloadedFunctionType); | 173 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmOverloadedFunctionType); |
182 }; | 174 }; |
183 | 175 |
184 class AsmFFIType final : public AsmCallableType { | 176 class AsmFFIType final : public AsmCallableType { |
185 public: | 177 public: |
186 AsmFFIType* AsFFIType() override { return this; } | 178 AsmFFIType* AsFFIType() override { return this; } |
187 | 179 |
188 std::string Name() override { return "Function"; } | 180 std::string Name() override { return "Function"; } |
189 AsmType* ValidateCall(AsmType* return_type, | |
190 const ZoneVector<AsmType*>& args) override; | |
191 bool CanBeInvokedWith(AsmType* return_type, | 181 bool CanBeInvokedWith(AsmType* return_type, |
192 const ZoneVector<AsmType*>& args) override; | 182 const ZoneVector<AsmType*>& args) override; |
193 | 183 |
194 private: | 184 private: |
195 friend AsmType; | 185 friend AsmType; |
196 | 186 |
197 AsmFFIType() = default; | 187 AsmFFIType() = default; |
198 | 188 |
199 DISALLOW_COPY_AND_ASSIGN(AsmFFIType); | 189 DISALLOW_COPY_AND_ASSIGN(AsmFFIType); |
200 }; | 190 }; |
201 | 191 |
202 class AsmFunctionTableType : public AsmCallableType { | 192 class AsmFunctionTableType : public AsmCallableType { |
203 public: | 193 public: |
204 AsmFunctionTableType* AsFunctionTableType() override { return this; } | 194 AsmFunctionTableType* AsFunctionTableType() override { return this; } |
205 | 195 |
206 std::string Name() override; | 196 std::string Name() override; |
207 | 197 |
208 AsmType* ValidateCall(AsmType* return_type, | |
209 const ZoneVector<AsmType*>& args) override; | |
210 bool CanBeInvokedWith(AsmType* return_type, | 198 bool CanBeInvokedWith(AsmType* return_type, |
211 const ZoneVector<AsmType*>& args) override; | 199 const ZoneVector<AsmType*>& args) override; |
212 | 200 |
213 size_t length() const { return length_; } | 201 size_t length() const { return length_; } |
214 AsmType* signature() { return signature_; } | 202 AsmType* signature() { return signature_; } |
215 | 203 |
216 private: | 204 private: |
217 friend class AsmType; | 205 friend class AsmType; |
218 | 206 |
219 AsmFunctionTableType(size_t length, AsmType* signature); | 207 AsmFunctionTableType(size_t length, AsmType* signature); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // Returns the store type if this is a heap type. AsmType::None is returned if | 338 // Returns the store type if this is a heap type. AsmType::None is returned if |
351 // this is not a heap type. | 339 // this is not a heap type. |
352 AsmType* StoreType(); | 340 AsmType* StoreType(); |
353 }; | 341 }; |
354 | 342 |
355 } // namespace wasm | 343 } // namespace wasm |
356 } // namespace internal | 344 } // namespace internal |
357 } // namespace v8 | 345 } // namespace v8 |
358 | 346 |
359 #endif // SRC_ASMJS_ASM_TYPES_H_ | 347 #endif // SRC_ASMJS_ASM_TYPES_H_ |
OLD | NEW |