Chromium Code Reviews| Index: src/wasm/asm-types.h |
| diff --git a/src/wasm/asm-types.h b/src/wasm/asm-types.h |
| index 303e5cdf8893ae26e0d780dedbc0a9ddafc3b654..f978a2ed4210fbd3b6acb6a666a8510b89ce5286 100644 |
| --- a/src/wasm/asm-types.h |
| +++ b/src/wasm/asm-types.h |
| @@ -6,7 +6,6 @@ |
| #define SRC_WASM_ASM_TYPES_H_ |
| #include <string> |
| -#include <type_traits> |
| #include "src/base/macros.h" |
| #include "src/zone-containers.h" |
| @@ -17,8 +16,10 @@ namespace internal { |
| namespace wasm { |
| class AsmType; |
| +class AsmFFIType; |
| class AsmFunctionType; |
| class AsmOverloadedFunctionType; |
| +class AsmFunctionTableType; |
| // List of V(CamelName, string_name, number, parent_types) |
| #define FOR_EACH_ASM_VALUE_TYPE_LIST(V) \ |
| @@ -47,15 +48,18 @@ class AsmOverloadedFunctionType; |
| V(Int32Array, "Int32Array", 19, kAsmHeap) \ |
| V(Float32Array, "Float32Array", 20, kAsmHeap) \ |
| V(Float64Array, "Float64Array", 21, kAsmHeap) \ |
| - V(FloatishDoubleQ, "floatish|double?", 22, kAsmFloatish | kAsmDoubleQ) \ |
| - V(FloatQDoubleQ, "float?|double?", 23, kAsmFloatQ | kAsmDoubleQ) \ |
| + /* 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.
|
| + V(FloatishDoubleQ, "floatish|double?", 23, kAsmFloatish | kAsmDoubleQ) \ |
| + V(FloatQDoubleQ, "float?|double?", 24, kAsmFloatQ | kAsmDoubleQ) \ |
| /* None is used to represent errors in the type checker. */ \ |
| V(None, "<none>", 31, 0) |
| // List of V(CamelName) |
| #define FOR_EACH_ASM_CALLABLE_TYPE_LIST(V) \ |
| V(FunctionType) \ |
| - V(OverloadedFunctionType) |
| + V(FFIType) \ |
| + V(OverloadedFunctionType) \ |
| + V(FunctionTableType) |
| class AsmValueType { |
| public: |
| @@ -164,6 +168,43 @@ class AsmOverloadedFunctionType final : public AsmCallableType { |
| DISALLOW_IMPLICIT_CONSTRUCTORS(AsmOverloadedFunctionType); |
| }; |
| +class AsmFFIType final : public AsmCallableType { |
| + public: |
| + AsmFFIType* AsFFIType() override { return this; } |
| + |
| + std::string Name() override { return "Function"; } |
| + AsmType* ValidateCall(AsmType* function_type) override; |
| + |
| + private: |
| + friend AsmType; |
| + |
| + AsmFFIType() = default; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AsmFFIType); |
| +}; |
| + |
| +class AsmFunctionTableType : public AsmCallableType { |
| + public: |
| + AsmFunctionTableType* AsFunctionTableType() override { return this; } |
| + |
| + std::string Name() override; |
| + |
| + AsmType* ValidateCall(AsmType* function_type) override; |
| + |
| + void set_signature(AsmType* function_type); |
| + size_t length() const { return length_; } |
| + |
| + private: |
| + friend class AsmType; |
| + |
| + explicit AsmFunctionTableType(size_t length) : length_(length) {} |
| + |
| + size_t length_; |
| + AsmType* signature_ = nullptr; |
| + |
| + DISALLOW_IMPLICIT_CONSTRUCTORS(AsmFunctionTableType); |
| +}; |
| + |
| class AsmType { |
| public: |
| #define DEFINE_CONSTRUCTOR(CamelName, string_name, number, parent_types) \ |
| @@ -200,10 +241,22 @@ class AsmType { |
| } |
| // The type for fround(src). |
| - static AsmType* FroundType(Zone* zone, AsmType* src); |
| + static AsmType* FroundType(Zone* zone); |
| // The (variadic) type for min and max. |
| - static AsmType* MinMaxType(Zone* zone, AsmType* type); |
| + static AsmType* MinMaxType(Zone* zone, AsmType* dest, AsmType* src); |
| + |
| + // The type for foreign functions. |
| + static AsmType* FFIType(Zone* zone) { |
| + auto* f = new (zone) AsmFFIType(); |
| + return reinterpret_cast<AsmType*>(f); |
| + } |
| + |
| + // The type for function tables. |
| + static AsmType* FunctionTableType(Zone* zone, size_t length) { |
| + auto* f = new (zone) AsmFunctionTableType(length); |
| + return reinterpret_cast<AsmType*>(f); |
| + } |
| std::string Name(); |
| // IsExactly returns true if this is the exact same type as that. For |
| @@ -221,12 +274,43 @@ class AsmType { |
| this == AsmType::Signed() || this == AsmType::Float(); |
| } |
| + // Converts this to the corresponding valid argument type. |
| + AsmType* ToReturnType() { |
| + if (this->IsA(AsmType::Signed())) { |
| + return AsmType::Signed(); |
| + } |
| + if (this->IsA(AsmType::Double())) { |
| + return AsmType::Double(); |
| + } |
| + if (this->IsA(AsmType::Float())) { |
| + return AsmType::Float(); |
| + } |
| + if (this->IsA(AsmType::Void())) { |
| + return AsmType::Void(); |
| + } |
| + return AsmType::None(); |
| + } |
| + |
| // Types allowed to be parameters in asm functions. |
| bool IsParameterType() { |
| return this == AsmType::Double() || this == AsmType::Int() || |
| this == AsmType::Float(); |
| } |
| + // Converts this to the corresponding valid argument type. |
| + AsmType* ToParameterType() { |
| + if (this->IsA(AsmType::Int())) { |
| + return AsmType::Int(); |
| + } |
| + if (this->IsA(AsmType::Double())) { |
| + return AsmType::Double(); |
| + } |
| + if (this->IsA(AsmType::Float())) { |
| + return AsmType::Float(); |
| + } |
| + return AsmType::None(); |
| + } |
| + |
| // Types allowed to be compared using the comparison operators. |
| bool IsComparableType() { |
| return this == AsmType::Double() || this == AsmType::Signed() || |