WebAssemblyFunction.h [plain text]
#pragma once
#if ENABLE(WEBASSEMBLY)
#include "ArityCheckMode.h"
#include "JSToWasmICCallee.h"
#include "MacroAssemblerCodeRef.h"
#include "WasmCallee.h"
#include "WebAssemblyFunctionBase.h"
#include <wtf/Noncopyable.h>
namespace JSC {
class JSGlobalObject;
struct ProtoCallFrame;
class WebAssemblyInstance;
using Wasm::WasmToWasmImportableFunction;
namespace B3 {
class Compilation;
}
class WebAssemblyFunction final : public WebAssemblyFunctionBase {
public:
using Base = WebAssemblyFunctionBase;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static constexpr bool needsDestruction = true;
static void destroy(JSCell*);
template<typename CellType, SubspaceAccess mode>
static IsoSubspace* subspaceFor(VM& vm)
{
return vm.webAssemblyFunctionSpace<mode>();
}
DECLARE_EXPORT_INFO;
JS_EXPORT_PRIVATE static WebAssemblyFunction* create(VM&, JSGlobalObject*, Structure*, unsigned, const String&, JSWebAssemblyInstance*, Wasm::Callee& jsEntrypoint, WasmToWasmImportableFunction::LoadLocation, Wasm::SignatureIndex);
static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
Wasm::SignatureIndex signatureIndex() const { return m_importableFunction.signatureIndex; }
WasmToWasmImportableFunction::LoadLocation entrypointLoadLocation() const { return m_importableFunction.entrypointLoadLocation; }
WasmToWasmImportableFunction importableFunction() const { return m_importableFunction; }
MacroAssemblerCodePtr<WasmEntryPtrTag> jsEntrypoint(ArityCheckMode arity)
{
if (arity == ArityCheckNotRequired)
return m_jsEntrypoint;
ASSERT(arity == MustCheckArity);
return m_jsEntrypoint;
}
static ptrdiff_t offsetOfEntrypointLoadLocation() { return OBJECT_OFFSETOF(WebAssemblyFunction, m_importableFunction) + WasmToWasmImportableFunction::offsetOfEntrypointLoadLocation(); }
MacroAssemblerCodePtr<JSEntryPtrTag> jsCallEntrypoint()
{
if (m_jsCallEntrypoint)
return m_jsCallEntrypoint.code();
return jsCallEntrypointSlow();
}
RegisterAtOffsetList usedCalleeSaveRegisters() const;
Wasm::Instance* previousInstance(CallFrame*);
private:
static void visitChildren(JSCell*, SlotVisitor&);
WebAssemblyFunction(VM&, NativeExecutable*, JSGlobalObject*, Structure*, Wasm::Callee& jsEntrypoint, WasmToWasmImportableFunction::LoadLocation entrypointLoadLocation, Wasm::SignatureIndex);
MacroAssemblerCodePtr<JSEntryPtrTag> jsCallEntrypointSlow();
ptrdiff_t previousInstanceOffset() const;
bool usesTagRegisters() const;
RegisterSet calleeSaves() const;
MacroAssemblerCodePtr<WasmEntryPtrTag> m_jsEntrypoint;
WasmToWasmImportableFunction m_importableFunction;
WriteBarrier<JSToWasmICCallee> m_jsToWasmICCallee;
MacroAssemblerCodeRef<JSEntryPtrTag> m_jsCallEntrypoint;
};
}
#endif // ENABLE(WEBASSEMBLY)