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

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) \
31 V(Double, "double", 5, kAsmDoubleQ | kAsmExtern) \ 33 V(Double, "double", 5, kAsmDoubleQ | kAsmExtern) \
32 V(Intish, "intish", 6, 0) \ 34 V(Intish, "intish", 6, 0) \
33 V(Int, "int", 7, kAsmIntish) \ 35 V(Int, "int", 7, kAsmIntish) \
34 V(Signed, "signed", 8, kAsmInt | kAsmExtern) \ 36 V(Signed, "signed", 8, kAsmInt | kAsmExtern) \
35 V(Unsigned, "unsigned", 9, kAsmInt) \ 37 V(Unsigned, "unsigned", 9, kAsmInt) \
36 V(FixNum, "fixnum", 10, kAsmSigned | kAsmUnsigned) \ 38 V(FixNum, "fixnum", 10, kAsmSigned | kAsmUnsigned) \
37 V(Floatish, "floatish", 11, 0) \ 39 V(Floatish, "floatish", 11, 0) \
38 V(FloatQ, "float?", 12, kAsmFloatish) \ 40 V(FloatQ, "float?", 12, kAsmFloatish) \
39 V(Float, "float", 13, kAsmFloatQ) \ 41 V(Float, "float", 13, kAsmFloatQ) \
40 /* Types used for expressing the Heap accesses. */ \ 42 /* Types used for expressing the Heap accesses. */ \
41 V(Uint8Array, "Uint8Array", 14, kAsmHeap) \ 43 V(Uint8Array, "Uint8Array", 14, kAsmHeap) \
42 V(Int8Array, "Int8Array", 15, kAsmHeap) \ 44 V(Int8Array, "Int8Array", 15, kAsmHeap) \
43 V(Uint16Array, "Uint16Array", 16, kAsmHeap) \ 45 V(Uint16Array, "Uint16Array", 16, kAsmHeap) \
44 V(Int16Array, "Int16Array", 17, kAsmHeap) \ 46 V(Int16Array, "Int16Array", 17, kAsmHeap) \
45 V(Uint32Array, "Uint32Array", 18, kAsmHeap) \ 47 V(Uint32Array, "Uint32Array", 18, kAsmHeap) \
46 V(Int32Array, "Int32Array", 19, kAsmHeap) \ 48 V(Int32Array, "Int32Array", 19, kAsmHeap) \
47 V(Float32Array, "Float32Array", 20, kAsmHeap) \ 49 V(Float32Array, "Float32Array", 20, kAsmHeap) \
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?", 22, kAsmFloatish | kAsmDoubleQ) \
51 V(FloatQDoubleQ, "float?|double?", 24, kAsmFloatQ | kAsmDoubleQ) \ 53 V(FloatQDoubleQ, "float?|double?", 23, 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 25 matching lines...) Expand all
94 static_cast<uintptr_t>(bits | kAsmValueTypeTag)); 98 static_cast<uintptr_t>(bits | kAsmValueTypeTag));
95 } 99 }
96 100
97 // AsmValueTypes can't be created except through AsmValueType::New. 101 // AsmValueTypes can't be created except through AsmValueType::New.
98 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmValueType); 102 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmValueType);
99 }; 103 };
100 104
101 class AsmCallableType : public ZoneObject { 105 class AsmCallableType : public ZoneObject {
102 public: 106 public:
103 virtual std::string Name() = 0; 107 virtual std::string Name() = 0;
104 virtual AsmType* ValidateCall(AsmType* function_type) = 0; 108 virtual AsmType* ValidateCall(AsmType* return_type,
109 const ZoneVector<AsmType*>& args) = 0;
105 110
106 #define DECLARE_CAST(CamelName) \ 111 #define DECLARE_CAST(CamelName) \
107 virtual Asm##CamelName* As##CamelName() { return nullptr; } 112 virtual Asm##CamelName* As##CamelName() { return nullptr; }
108 FOR_EACH_ASM_CALLABLE_TYPE_LIST(DECLARE_CAST) 113 FOR_EACH_ASM_CALLABLE_TYPE_LIST(DECLARE_CAST)
109 #undef DECLARE_CAST 114 #undef DECLARE_CAST
110 115
111 protected: 116 protected:
112 AsmCallableType() = default; 117 AsmCallableType() = default;
113 virtual ~AsmCallableType() = default; 118 virtual ~AsmCallableType() = default;
114 119
(...skipping 13 matching lines...) Expand all
128 virtual bool IsFroundType() const { return false; } 133 virtual bool IsFroundType() const { return false; }
129 134
130 protected: 135 protected:
131 AsmFunctionType(Zone* zone, AsmType* return_type) 136 AsmFunctionType(Zone* zone, AsmType* return_type)
132 : return_type_(return_type), args_(zone) {} 137 : return_type_(return_type), args_(zone) {}
133 138
134 private: 139 private:
135 friend AsmType; 140 friend AsmType;
136 141
137 std::string Name() override; 142 std::string Name() override;
138 AsmType* ValidateCall(AsmType* function_type) override; 143 AsmType* ValidateCall(AsmType* return_type,
144 const ZoneVector<AsmType*>& args) override;
139 145
140 AsmType* return_type_; 146 AsmType* return_type_;
141 ZoneVector<AsmType*> args_; 147 ZoneVector<AsmType*> args_;
142 148
143 DISALLOW_COPY_AND_ASSIGN(AsmFunctionType); 149 DISALLOW_COPY_AND_ASSIGN(AsmFunctionType);
144 }; 150 };
145 151
146 class AsmOverloadedFunctionType final : public AsmCallableType { 152 class AsmOverloadedFunctionType final : public AsmCallableType {
147 public: 153 public:
148 AsmOverloadedFunctionType* AsOverloadedFunctionType() override { 154 AsmOverloadedFunctionType* AsOverloadedFunctionType() override {
149 return this; 155 return this;
150 } 156 }
151 157
152 void AddOverload(AsmType* overload); 158 void AddOverload(AsmType* overload);
153 159
154 private: 160 private:
155 friend AsmType; 161 friend AsmType;
156 162
157 explicit AsmOverloadedFunctionType(Zone* zone) : overloads_(zone) {} 163 explicit AsmOverloadedFunctionType(Zone* zone) : overloads_(zone) {}
158 164
159 std::string Name() override; 165 std::string Name() override;
160 AsmType* ValidateCall(AsmType* function_type) override; 166 AsmType* ValidateCall(AsmType* return_type,
167 const ZoneVector<AsmType*>& args) override;
161 168
162 ZoneVector<AsmType*> overloads_; 169 ZoneVector<AsmType*> overloads_;
163 170
164 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmOverloadedFunctionType); 171 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmOverloadedFunctionType);
165 }; 172 };
166 173
174 class AsmFFIType final : public AsmCallableType {
175 public:
176 AsmFFIType* AsFFIType() override { return this; }
177
178 std::string Name() override { return "Function"; }
179 AsmType* ValidateCall(AsmType* return_type,
180 const ZoneVector<AsmType*>& args) override;
181
182 private:
183 friend AsmType;
184
185 AsmFFIType() = default;
186
187 DISALLOW_COPY_AND_ASSIGN(AsmFFIType);
188 };
189
190 class AsmFunctionTableType : public AsmCallableType {
191 public:
192 AsmFunctionTableType* AsFunctionTableType() override { return this; }
193
194 std::string Name() override;
195
196 AsmType* ValidateCall(AsmType* return_type,
197 const ZoneVector<AsmType*>& args) override;
198
199 size_t length() const { return length_; }
200
201 private:
202 friend class AsmType;
203
204 AsmFunctionTableType(size_t length, AsmType* signature);
205
206 size_t length_;
207 AsmType* signature_;
208
209 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmFunctionTableType);
210 };
211
167 class AsmType { 212 class AsmType {
168 public: 213 public:
169 #define DEFINE_CONSTRUCTOR(CamelName, string_name, number, parent_types) \ 214 #define DEFINE_CONSTRUCTOR(CamelName, string_name, number, parent_types) \
170 static AsmType* CamelName() { \ 215 static AsmType* CamelName() { \
171 return AsmValueType::New(AsmValueType::kAsm##CamelName); \ 216 return AsmValueType::New(AsmValueType::kAsm##CamelName); \
172 } 217 }
173 FOR_EACH_ASM_VALUE_TYPE_LIST(DEFINE_CONSTRUCTOR) 218 FOR_EACH_ASM_VALUE_TYPE_LIST(DEFINE_CONSTRUCTOR)
174 #undef DEFINE_CONSTRUCTOR 219 #undef DEFINE_CONSTRUCTOR
175 220
176 #define DEFINE_CAST(CamelCase) \ 221 #define DEFINE_CAST(CamelCase) \
(...skipping 21 matching lines...) Expand all
198 auto* f = new (zone) AsmOverloadedFunctionType(zone); 243 auto* f = new (zone) AsmOverloadedFunctionType(zone);
199 return reinterpret_cast<AsmType*>(f); 244 return reinterpret_cast<AsmType*>(f);
200 } 245 }
201 246
202 // The type for fround(src). 247 // The type for fround(src).
203 static AsmType* FroundType(Zone* zone); 248 static AsmType* FroundType(Zone* zone);
204 249
205 // The (variadic) type for min and max. 250 // The (variadic) type for min and max.
206 static AsmType* MinMaxType(Zone* zone, AsmType* dest, AsmType* src); 251 static AsmType* MinMaxType(Zone* zone, AsmType* dest, AsmType* src);
207 252
253 // The type for foreign functions.
254 static AsmType* FFIType(Zone* zone) {
255 auto* f = new (zone) AsmFFIType();
256 return reinterpret_cast<AsmType*>(f);
257 }
258
259 // The type for function tables.
260 static AsmType* FunctionTableType(Zone* zone, size_t length,
261 AsmType* signature) {
262 auto* f = new (zone) AsmFunctionTableType(length, signature);
263 return reinterpret_cast<AsmType*>(f);
264 }
265
208 std::string Name(); 266 std::string Name();
209 // IsExactly returns true if this is the exact same type as that. For 267 // IsExactly returns true if this is the exact same type as that. For
210 // non-value types (e.g., callables), this returns this == that. 268 // non-value types (e.g., callables), this returns this == that.
211 bool IsExactly(AsmType* that); 269 bool IsExactly(AsmType* that);
212 // IsA is used to query whether this is an instance of that (i.e., if this is 270 // 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 271 // a type derived from that.) For non-value types (e.g., callables), this
214 // returns this == that. 272 // returns this == that.
215 bool IsA(AsmType* that); 273 bool IsA(AsmType* that);
216 274
217 // Types allowed in return statements. void is the type for returns without 275 // Types allowed in return statements. void is the type for returns without
218 // an expression. 276 // an expression.
219 bool IsReturnType() { 277 bool IsReturnType() {
220 return this == AsmType::Void() || this == AsmType::Double() || 278 return this == AsmType::Void() || this == AsmType::Double() ||
221 this == AsmType::Signed() || this == AsmType::Float(); 279 this == AsmType::Signed() || this == AsmType::Float();
222 } 280 }
223 281
282 // Converts this to the corresponding valid argument type.
283 AsmType* ToReturnType() {
284 if (this->IsA(AsmType::Signed())) {
285 return AsmType::Signed();
286 }
287 if (this->IsA(AsmType::Double())) {
288 return AsmType::Double();
289 }
290 if (this->IsA(AsmType::Float())) {
291 return AsmType::Float();
292 }
293 if (this->IsA(AsmType::Void())) {
294 return AsmType::Void();
295 }
296 return AsmType::None();
297 }
298
224 // Types allowed to be parameters in asm functions. 299 // Types allowed to be parameters in asm functions.
225 bool IsParameterType() { 300 bool IsParameterType() {
226 return this == AsmType::Double() || this == AsmType::Int() || 301 return this == AsmType::Double() || this == AsmType::Int() ||
227 this == AsmType::Float(); 302 this == AsmType::Float();
228 } 303 }
229 304
305 // Converts this to the corresponding valid argument type.
306 AsmType* ToParameterType() {
307 if (this->IsA(AsmType::Int())) {
308 return AsmType::Int();
309 }
310 if (this->IsA(AsmType::Double())) {
311 return AsmType::Double();
312 }
313 if (this->IsA(AsmType::Float())) {
314 return AsmType::Float();
315 }
316 return AsmType::None();
317 }
318
230 // Types allowed to be compared using the comparison operators. 319 // Types allowed to be compared using the comparison operators.
231 bool IsComparableType() { 320 bool IsComparableType() {
232 return this == AsmType::Double() || this == AsmType::Signed() || 321 return this == AsmType::Double() || this == AsmType::Signed() ||
233 this == AsmType::Unsigned() || this == AsmType::Float(); 322 this == AsmType::Unsigned() || this == AsmType::Float();
234 } 323 }
235 324
236 // The following methods are meant to be used for inspecting the traits of 325 // The following methods are meant to be used for inspecting the traits of
237 // element types for the heap view types. 326 // element types for the heap view types.
238 enum : int32_t { kNotHeapType = -1 }; 327 enum : int32_t { kNotHeapType = -1 };
239 328
240 // Returns the element size if this is a heap type. Otherwise returns 329 // Returns the element size if this is a heap type. Otherwise returns
241 // kNotHeapType. 330 // kNotHeapType.
242 int32_t ElementSizeInBytes(); 331 int32_t ElementSizeInBytes();
243 // Returns the load type if this is a heap type. AsmType::None is returned if 332 // Returns the load type if this is a heap type. AsmType::None is returned if
244 // this is not a heap type. 333 // this is not a heap type.
245 AsmType* LoadType(); 334 AsmType* LoadType();
246 // Returns the store type if this is a heap type. AsmType::None is returned if 335 // Returns the store type if this is a heap type. AsmType::None is returned if
247 // this is not a heap type. 336 // this is not a heap type.
248 AsmType* StoreType(); 337 AsmType* StoreType();
249 }; 338 };
250 339
251 } // namespace wasm 340 } // namespace wasm
252 } // namespace internal 341 } // namespace internal
253 } // namespace v8 342 } // namespace v8
254 343
255 #endif // SRC_WASM_ASM_TYPES_H_ 344 #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