diff options
Diffstat (limited to 'js/src/wasm/WasmBuiltinModule.h')
-rw-r--r-- | js/src/wasm/WasmBuiltinModule.h | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/js/src/wasm/WasmBuiltinModule.h b/js/src/wasm/WasmBuiltinModule.h index 42faffec73..8646e789e6 100644 --- a/js/src/wasm/WasmBuiltinModule.h +++ b/js/src/wasm/WasmBuiltinModule.h @@ -62,25 +62,60 @@ struct MOZ_STACK_CLASS BuiltinModuleInstances { // An builtin module func is a natively implemented function that may be // compiled into a 'builtin module', which may be instantiated with a provided // memory yielding an exported WebAssembly function wrapping the builtin module. -struct BuiltinModuleFunc { +class BuiltinModuleFunc { + private: + SharedRecGroup recGroup_; + const char* exportName_; + const SymbolicAddressSignature* sig_; + bool usesMemory_; + + public: + // Default constructor so this can be used in an EnumeratedArray. + BuiltinModuleFunc() = default; + + // Initialize this builtin. Must only be called once. + [[nodiscard]] bool init(const RefPtr<TypeContext>& types, + mozilla::Span<const ValType> params, + Maybe<ValType> result, bool usesMemory, + const SymbolicAddressSignature* sig, + const char* exportName); + + // The rec group for the function type for this builtin. + const RecGroup* recGroup() const { return recGroup_.get(); } + // The type definition for the function type for this builtin. + const TypeDef* typeDef() const { return &recGroup_->type(0); } + // The function type for this builtin. + const FuncType* funcType() const { return &typeDef()->funcType(); } + // The name of the func as it is exported - const char* exportName; - // The params taken by the func. - mozilla::Span<const ValType> params; - // The optional result returned by the func. - mozilla::Maybe<const ValType> result; - // The signature of the builtin that implements the func - const SymbolicAddressSignature& signature; + const char* exportName() const { return exportName_; } + // The signature of the builtin that implements this function. + const SymbolicAddressSignature* sig() const { return sig_; } // Whether this function takes a pointer to the memory base as a hidden final - // parameter. - bool usesMemory; + // parameter. This parameter will show up in the SymbolicAddressSignature, + // but not the function type. Compilers must pass the memoryBase to the + // function call as the last parameter. + bool usesMemory() const { return usesMemory_; } +}; + +// Static storage for all builtin module funcs in the system. +class BuiltinModuleFuncs { + using Storage = + mozilla::EnumeratedArray<BuiltinModuleFuncId, BuiltinModuleFunc, + size_t(BuiltinModuleFuncId::Limit)>; + Storage funcs_; - // Allocate a FuncType for this func, returning false for OOM - bool funcType(FuncType* type) const; + static BuiltinModuleFuncs* singleton_; + + public: + [[nodiscard]] static bool init(); + static void destroy(); // Get the BuiltinModuleFunc for an BuiltinModuleFuncId. BuiltinModuleFuncId // must be validated. - static const BuiltinModuleFunc& getFromId(BuiltinModuleFuncId id); + static const BuiltinModuleFunc& getFromId(BuiltinModuleFuncId id) { + return singleton_->funcs_[id]; + } }; Maybe<BuiltinModuleId> ImportMatchesBuiltinModule( |