Chromium Code Reviews| 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_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 #include <type_traits> | |
| 10 | 9 |
| 11 #include "src/base/macros.h" | 10 #include "src/base/macros.h" |
| 12 #include "src/zone-containers.h" | 11 #include "src/zone-containers.h" |
| 13 #include "src/zone.h" | 12 #include "src/zone.h" |
| 14 | 13 |
| 15 namespace v8 { | 14 namespace v8 { |
| 16 namespace internal { | 15 namespace internal { |
| 17 namespace wasm { | 16 namespace wasm { |
| 18 | 17 |
| 19 class AsmType; | 18 class AsmType; |
| 19 class AsmFFIType; | |
| 20 class AsmFunctionType; | 20 class AsmFunctionType; |
| 21 class AsmOverloadedFunctionType; | 21 class AsmOverloadedFunctionType; |
| 22 class AsmFunctionTableType; | |
| 22 | 23 |
| 23 // List of V(CamelName, string_name, number, parent_types) | 24 // List of V(CamelName, string_name, number, parent_types) |
| 24 #define FOR_EACH_ASM_VALUE_TYPE_LIST(V) \ | 25 #define FOR_EACH_ASM_VALUE_TYPE_LIST(V) \ |
| 25 /* 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 */ \ |
| 26 /* are used to express semantic information about the types they tag. */ \ | 27 /* are used to express semantic information about the types they tag. */ \ |
| 27 V(Heap, "[]", 1, 0) \ | 28 V(Heap, "[]", 1, 0) \ |
| 28 /*The following are actual types that appear in the asm source. */ \ | 29 /*The following are actual types that appear in the asm source. */ \ |
| 29 V(Void, "void", 2, 0) \ | 30 V(Void, "void", 2, 0) \ |
| 30 V(Extern, "extern", 3, 0) \ | 31 V(Extern, "extern", 3, 0) \ |
| 31 V(DoubleQ, "double?", 4, 0) \ | 32 V(DoubleQ, "double?", 4, 0) \ |
| 32 V(Double, "double", 5, kAsmDoubleQ | kAsmExtern) \ | 33 V(Double, "double", 5, kAsmDoubleQ | kAsmExtern) \ |
| 33 V(Intish, "intish", 6, 0) \ | 34 V(Intish, "intish", 6, 0) \ |
| 34 V(Int, "int", 7, kAsmIntish) \ | 35 V(Int, "int", 7, kAsmIntish) \ |
| 35 V(Signed, "signed", 8, kAsmInt | kAsmExtern) \ | 36 V(Signed, "signed", 8, kAsmInt | kAsmExtern) \ |
| 36 V(Unsigned, "unsigned", 9, kAsmInt) \ | 37 V(Unsigned, "unsigned", 9, kAsmInt) \ |
| 37 V(FixNum, "fixnum", 10, kAsmSigned | kAsmUnsigned) \ | 38 V(FixNum, "fixnum", 10, kAsmSigned | kAsmUnsigned) \ |
| 38 V(Floatish, "floatish", 11, 0) \ | 39 V(Floatish, "floatish", 11, 0) \ |
| 39 V(FloatQ, "float?", 12, kAsmFloatish) \ | 40 V(FloatQ, "float?", 12, kAsmFloatish) \ |
| 40 V(Float, "float", 13, kAsmFloatQ) \ | 41 V(Float, "float", 13, kAsmFloatQ) \ |
| 41 /* Types used for expressing the Heap accesses. */ \ | 42 /* Types used for expressing the Heap accesses. */ \ |
| 42 V(Uint8Array, "Uint8Array", 14, kAsmHeap) \ | 43 V(Uint8Array, "Uint8Array", 14, kAsmHeap) \ |
| 43 V(Int8Array, "Int8Array", 15, kAsmHeap) \ | 44 V(Int8Array, "Int8Array", 15, kAsmHeap) \ |
| 44 V(Uint16Array, "Uint16Array", 16, kAsmHeap) \ | 45 V(Uint16Array, "Uint16Array", 16, kAsmHeap) \ |
| 45 V(Int16Array, "Int16Array", 17, kAsmHeap) \ | 46 V(Int16Array, "Int16Array", 17, kAsmHeap) \ |
| 46 V(Uint32Array, "Uint32Array", 18, kAsmHeap) \ | 47 V(Uint32Array, "Uint32Array", 18, kAsmHeap) \ |
| 47 V(Int32Array, "Int32Array", 19, kAsmHeap) \ | 48 V(Int32Array, "Int32Array", 19, kAsmHeap) \ |
| 48 V(Float32Array, "Float32Array", 20, kAsmHeap) \ | 49 V(Float32Array, "Float32Array", 20, kAsmHeap) \ |
| 49 V(Float64Array, "Float64Array", 21, kAsmHeap) \ | 50 V(Float64Array, "Float64Array", 21, kAsmHeap) \ |
| 50 V(FloatishDoubleQ, "floatish|double?", 22, kAsmFloatish | kAsmDoubleQ) \ | 51 /* Pseudo-types used in representing heap access for fp types.*/ \ |
|
bradnelson
2016/06/17 23:15:33
What happened to 22?
John
2016/06/17 23:23:02
Done.
| |
| 51 V(FloatQDoubleQ, "float?|double?", 23, kAsmFloatQ | kAsmDoubleQ) \ | 52 V(FloatishDoubleQ, "floatish|double?", 23, kAsmFloatish | 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 Loading... | |
| 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); | |
| 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 16 matching lines...) Expand all Loading... | |
| 193 } | 234 } |
| 194 | 235 |
| 195 // Overloaded function types. Not creatable by asm source, but useful to | 236 // Overloaded function types. Not creatable by asm source, but useful to |
| 196 // represent the overloaded stdlib functions. | 237 // represent the overloaded stdlib functions. |
| 197 static AsmType* OverloadedFunction(Zone* zone) { | 238 static AsmType* OverloadedFunction(Zone* zone) { |
| 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, AsmType* src); | 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* type); | 247 static AsmType* MinMaxType(Zone* zone, AsmType* dest, AsmType* src); |
| 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 } | |
| 207 | 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_ |
| OLD | NEW |