Chromium Code Reviews| Index: src/wasm/asm-types.h |
| diff --git a/src/wasm/asm-types.h b/src/wasm/asm-types.h |
| index 88f9103a2f19ca5efe3ed986576c17cd8fd56b96..f978a2ed4210fbd3b6acb6a666a8510b89ce5286 100644 |
| --- a/src/wasm/asm-types.h |
| +++ b/src/wasm/asm-types.h |
| @@ -16,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) \ |
| @@ -55,7 +57,9 @@ class AsmOverloadedFunctionType; |
| // 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); |
|
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
|
| + 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) \ |
| @@ -205,6 +246,18 @@ class AsmType { |
| // The (variadic) type for min and max. |
| 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 |
| // non-value types (e.g., callables), this returns this == that. |
| @@ -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() || |