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

Side by Side Diff: src/wasm/asm-types.h

Issue 2078053002: V8. ASM-2-WASM. Another asm-types.h revision. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: git pull Created 4 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 | src/wasm/asm-types.cc » ('j') | src/wasm/asm-types.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_WASM_ASM_TYPES_H_ 5 #ifndef SRC_WASM_ASM_TYPES_H_
6 #define SRC_WASM_ASM_TYPES_H_ 6 #define SRC_WASM_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 AsmFunctionType; 20 class AsmFunctionType;
20 class AsmOverloadedFunctionType; 21 class AsmOverloadedFunctionType;
22 class AsmFunctionTableType;
21 23
22 // List of V(CamelName, string_name, number, parent_types) 24 // List of V(CamelName, string_name, number, parent_types)
23 #define FOR_EACH_ASM_VALUE_TYPE_LIST(V) \ 25 #define FOR_EACH_ASM_VALUE_TYPE_LIST(V) \
24 /* 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 */ \
25 /* are used to express semantic information about the types they tag. */ \ 27 /* are used to express semantic information about the types they tag. */ \
26 V(Heap, "[]", 1, 0) \ 28 V(Heap, "[]", 1, 0) \
27 /*The following are actual types that appear in the asm source. */ \ 29 /*The following are actual types that appear in the asm source. */ \
28 V(Void, "void", 2, 0) \ 30 V(Void, "void", 2, 0) \
29 V(Extern, "extern", 3, 0) \ 31 V(Extern, "extern", 3, 0) \
30 V(DoubleQ, "double?", 4, 0) \ 32 V(DoubleQ, "double?", 4, 0) \
(...skipping 17 matching lines...) Expand all
48 V(Float64Array, "Float64Array", 21, kAsmHeap) \ 50 V(Float64Array, "Float64Array", 21, kAsmHeap) \
49 /* Pseudo-types used in representing heap access for fp types.*/ \ 51 /* Pseudo-types used in representing heap access for fp types.*/ \
50 V(FloatishDoubleQ, "floatish|double?", 23, kAsmFloatish | kAsmDoubleQ) \ 52 V(FloatishDoubleQ, "floatish|double?", 23, kAsmFloatish | kAsmDoubleQ) \
51 V(FloatQDoubleQ, "float?|double?", 24, kAsmFloatQ | kAsmDoubleQ) \ 53 V(FloatQDoubleQ, "float?|double?", 24, kAsmFloatQ | kAsmDoubleQ) \
52 /* None is used to represent errors in the type checker. */ \ 54 /* None is used to represent errors in the type checker. */ \
53 V(None, "<none>", 31, 0) 55 V(None, "<none>", 31, 0)
54 56
55 // List of V(CamelName) 57 // List of V(CamelName)
56 #define FOR_EACH_ASM_CALLABLE_TYPE_LIST(V) \ 58 #define FOR_EACH_ASM_CALLABLE_TYPE_LIST(V) \
57 V(FunctionType) \ 59 V(FunctionType) \
58 V(OverloadedFunctionType) 60 V(FFIType) \
61 V(OverloadedFunctionType) \
62 V(FunctionTableType)
59 63
60 class AsmValueType { 64 class AsmValueType {
61 public: 65 public:
62 typedef uint32_t bitset_t; 66 typedef uint32_t bitset_t;
63 67
64 enum : uint32_t { 68 enum : uint32_t {
65 #define DEFINE_TAG(CamelName, string_name, number, parent_types) \ 69 #define DEFINE_TAG(CamelName, string_name, number, parent_types) \
66 kAsm##CamelName = ((1u << (number)) | (parent_types)), 70 kAsm##CamelName = ((1u << (number)) | (parent_types)),
67 FOR_EACH_ASM_VALUE_TYPE_LIST(DEFINE_TAG) 71 FOR_EACH_ASM_VALUE_TYPE_LIST(DEFINE_TAG)
68 #undef DEFINE_TAG 72 #undef DEFINE_TAG
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 explicit AsmOverloadedFunctionType(Zone* zone) : overloads_(zone) {} 161 explicit AsmOverloadedFunctionType(Zone* zone) : overloads_(zone) {}
158 162
159 std::string Name() override; 163 std::string Name() override;
160 AsmType* ValidateCall(AsmType* function_type) override; 164 AsmType* ValidateCall(AsmType* function_type) override;
161 165
162 ZoneVector<AsmType*> overloads_; 166 ZoneVector<AsmType*> overloads_;
163 167
164 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmOverloadedFunctionType); 168 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmOverloadedFunctionType);
165 }; 169 };
166 170
171 class AsmFFIType final : public AsmCallableType {
172 public:
173 AsmFFIType* AsFFIType() override { return this; }
174
175 std::string Name() override { return "Function"; }
176 AsmType* ValidateCall(AsmType* function_type) override;
177
178 private:
179 friend AsmType;
180
181 AsmFFIType() = default;
182
183 DISALLOW_COPY_AND_ASSIGN(AsmFFIType);
184 };
185
186 class AsmFunctionTableType : public AsmCallableType {
187 public:
188 AsmFunctionTableType* AsFunctionTableType() override { return this; }
189
190 std::string Name() override;
191
192 AsmType* ValidateCall(AsmType* function_type) override;
193
194 void set_signature(AsmType* function_type);
bradnelson 2016/06/17 23:38:50 Will you need a method to check if the signature w
John 2016/06/20 15:09:52 Not really. tl;dr Looking at how this class is us
195 size_t length() const { return length_; }
196
197 private:
198 friend class AsmType;
199
200 explicit AsmFunctionTableType(size_t length) : length_(length) {}
201
202 size_t length_;
203 AsmType* signature_ = nullptr;
204
205 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmFunctionTableType);
206 };
207
167 class AsmType { 208 class AsmType {
168 public: 209 public:
169 #define DEFINE_CONSTRUCTOR(CamelName, string_name, number, parent_types) \ 210 #define DEFINE_CONSTRUCTOR(CamelName, string_name, number, parent_types) \
170 static AsmType* CamelName() { \ 211 static AsmType* CamelName() { \
171 return AsmValueType::New(AsmValueType::kAsm##CamelName); \ 212 return AsmValueType::New(AsmValueType::kAsm##CamelName); \
172 } 213 }
173 FOR_EACH_ASM_VALUE_TYPE_LIST(DEFINE_CONSTRUCTOR) 214 FOR_EACH_ASM_VALUE_TYPE_LIST(DEFINE_CONSTRUCTOR)
174 #undef DEFINE_CONSTRUCTOR 215 #undef DEFINE_CONSTRUCTOR
175 216
176 #define DEFINE_CAST(CamelCase) \ 217 #define DEFINE_CAST(CamelCase) \
(...skipping 21 matching lines...) Expand all
198 auto* f = new (zone) AsmOverloadedFunctionType(zone); 239 auto* f = new (zone) AsmOverloadedFunctionType(zone);
199 return reinterpret_cast<AsmType*>(f); 240 return reinterpret_cast<AsmType*>(f);
200 } 241 }
201 242
202 // The type for fround(src). 243 // The type for fround(src).
203 static AsmType* FroundType(Zone* zone); 244 static AsmType* FroundType(Zone* zone);
204 245
205 // The (variadic) type for min and max. 246 // The (variadic) type for min and max.
206 static AsmType* MinMaxType(Zone* zone, AsmType* dest, AsmType* src); 247 static AsmType* MinMaxType(Zone* zone, AsmType* dest, AsmType* src);
207 248
249 // The type for foreign functions.
250 static AsmType* FFIType(Zone* zone) {
251 auto* f = new (zone) AsmFFIType();
252 return reinterpret_cast<AsmType*>(f);
253 }
254
255 // The type for function tables.
256 static AsmType* FunctionTableType(Zone* zone, size_t length) {
257 auto* f = new (zone) AsmFunctionTableType(length);
258 return reinterpret_cast<AsmType*>(f);
259 }
260
208 std::string Name(); 261 std::string Name();
209 // IsExactly returns true if this is the exact same type as that. For 262 // IsExactly returns true if this is the exact same type as that. For
210 // non-value types (e.g., callables), this returns this == that. 263 // non-value types (e.g., callables), this returns this == that.
211 bool IsExactly(AsmType* that); 264 bool IsExactly(AsmType* that);
212 // IsA is used to query whether this is an instance of that (i.e., if this is 265 // IsA is used to query whether this is an instance of that (i.e., if this is
213 // a type derived from that.) For non-value types (e.g., callables), this 266 // a type derived from that.) For non-value types (e.g., callables), this
214 // returns this == that. 267 // returns this == that.
215 bool IsA(AsmType* that); 268 bool IsA(AsmType* that);
216 269
217 // Types allowed in return statements. void is the type for returns without 270 // Types allowed in return statements. void is the type for returns without
218 // an expression. 271 // an expression.
219 bool IsReturnType() { 272 bool IsReturnType() {
220 return this == AsmType::Void() || this == AsmType::Double() || 273 return this == AsmType::Void() || this == AsmType::Double() ||
221 this == AsmType::Signed() || this == AsmType::Float(); 274 this == AsmType::Signed() || this == AsmType::Float();
222 } 275 }
223 276
277 // Converts this to the corresponding valid argument type.
278 AsmType* ToReturnType() {
279 if (this->IsA(AsmType::Signed())) {
280 return AsmType::Signed();
281 }
282 if (this->IsA(AsmType::Double())) {
283 return AsmType::Double();
284 }
285 if (this->IsA(AsmType::Float())) {
286 return AsmType::Float();
287 }
288 if (this->IsA(AsmType::Void())) {
289 return AsmType::Void();
290 }
291 return AsmType::None();
292 }
293
224 // Types allowed to be parameters in asm functions. 294 // Types allowed to be parameters in asm functions.
225 bool IsParameterType() { 295 bool IsParameterType() {
226 return this == AsmType::Double() || this == AsmType::Int() || 296 return this == AsmType::Double() || this == AsmType::Int() ||
227 this == AsmType::Float(); 297 this == AsmType::Float();
228 } 298 }
229 299
300 // Converts this to the corresponding valid argument type.
301 AsmType* ToParameterType() {
302 if (this->IsA(AsmType::Int())) {
303 return AsmType::Int();
304 }
305 if (this->IsA(AsmType::Double())) {
306 return AsmType::Double();
307 }
308 if (this->IsA(AsmType::Float())) {
309 return AsmType::Float();
310 }
311 return AsmType::None();
312 }
313
230 // Types allowed to be compared using the comparison operators. 314 // Types allowed to be compared using the comparison operators.
231 bool IsComparableType() { 315 bool IsComparableType() {
232 return this == AsmType::Double() || this == AsmType::Signed() || 316 return this == AsmType::Double() || this == AsmType::Signed() ||
233 this == AsmType::Unsigned() || this == AsmType::Float(); 317 this == AsmType::Unsigned() || this == AsmType::Float();
234 } 318 }
235 319
236 // The following methods are meant to be used for inspecting the traits of 320 // The following methods are meant to be used for inspecting the traits of
237 // element types for the heap view types. 321 // element types for the heap view types.
238 enum : int32_t { kNotHeapType = -1 }; 322 enum : int32_t { kNotHeapType = -1 };
239 323
240 // Returns the element size if this is a heap type. Otherwise returns 324 // Returns the element size if this is a heap type. Otherwise returns
241 // kNotHeapType. 325 // kNotHeapType.
242 int32_t ElementSizeInBytes(); 326 int32_t ElementSizeInBytes();
243 // Returns the load type if this is a heap type. AsmType::None is returned if 327 // Returns the load type if this is a heap type. AsmType::None is returned if
244 // this is not a heap type. 328 // this is not a heap type.
245 AsmType* LoadType(); 329 AsmType* LoadType();
246 // Returns the store type if this is a heap type. AsmType::None is returned if 330 // Returns the store type if this is a heap type. AsmType::None is returned if
247 // this is not a heap type. 331 // this is not a heap type.
248 AsmType* StoreType(); 332 AsmType* StoreType();
249 }; 333 };
250 334
251 } // namespace wasm 335 } // namespace wasm
252 } // namespace internal 336 } // namespace internal
253 } // namespace v8 337 } // namespace v8
254 338
255 #endif // SRC_WASM_ASM_TYPES_H_ 339 #endif // SRC_WASM_ASM_TYPES_H_
OLDNEW
« no previous file with comments | « no previous file | src/wasm/asm-types.cc » ('j') | src/wasm/asm-types.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698