#pragma once
#if ENABLE(WEBASSEMBLY)
#include "CompilationResult.h"
#include "WasmB3IRGenerator.h"
#include "WasmEntryPlan.h"
#include "WasmModuleInformation.h"
#include "WasmTierUpCount.h"
#include <wtf/Bag.h>
#include <wtf/Function.h>
#include <wtf/SharedTask.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/Vector.h>
namespace JSC {
class CallLinkInfo;
namespace Wasm {
class BBQCallee;
class CodeBlock;
class EmbedderEntrypointCallee;
class BBQPlan final : public EntryPlan {
public:
using Base = EntryPlan;
using Base::Base;
BBQPlan(Context*, Ref<ModuleInformation>, uint32_t functionIndex, CodeBlock*, CompletionTask&&);
bool hasWork() const final
{
if (m_asyncWork == AsyncWork::Validation)
return m_state < State::Validated;
return m_state < State::Compiled;
}
void work(CompilationEffort) final;
using CalleeInitializer = Function<void(uint32_t, RefPtr<EmbedderEntrypointCallee>&&, Ref<BBQCallee>&&)>;
void initializeCallees(const CalleeInitializer&);
bool didReceiveFunctionData(unsigned, const FunctionData&) final;
bool parseAndValidateModule()
{
return Base::parseAndValidateModule(m_source.data(), m_source.size());
}
private:
bool prepareImpl() final;
void compileFunction(uint32_t functionIndex) final;
void didCompleteCompilation(const AbstractLocker&) final;
std::unique_ptr<InternalFunction> compileFunction(uint32_t functionIndex, CompilationContext&, Vector<UnlinkedWasmToWasmCall>&, TierUpCount*);
Vector<std::unique_ptr<InternalFunction>> m_wasmInternalFunctions;
HashMap<uint32_t, std::unique_ptr<InternalFunction>, DefaultHash<uint32_t>, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> m_embedderToWasmInternalFunctions;
Vector<CompilationContext> m_compilationContexts;
Vector<std::unique_ptr<TierUpCount>> m_tierUpCounts;
RefPtr<CodeBlock> m_codeBlock { nullptr };
uint32_t m_functionIndex;
};
} }
#endif // ENABLE(WEBASSEMBLY)