2 * Copyright (C) 2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #if ENABLE(WEBASSEMBLY)
30 #include "CompilationResult.h"
32 #include "WasmFormat.h"
34 #include <wtf/ThreadSafeRefCounted.h>
35 #include <wtf/Vector.h>
41 class JSWebAssemblyCallee;
47 JS_EXPORT_PRIVATE Plan(VM*, Vector<uint8_t>);
48 JS_EXPORT_PRIVATE Plan(VM*, const uint8_t*, size_t);
49 JS_EXPORT_PRIVATE ~Plan();
51 JS_EXPORT_PRIVATE void run();
53 JS_EXPORT_PRIVATE void initializeCallees(JSGlobalObject*, std::function<void(unsigned, JSWebAssemblyCallee*)>);
55 bool WARN_UNUSED_RETURN failed() const { return m_failed; }
56 const String& errorMessage() const
58 RELEASE_ASSERT(failed());
59 return m_errorMessage;
62 Vector<Export>& exports() const
64 RELEASE_ASSERT(!failed());
65 return m_moduleInformation->exports;
68 size_t internalFunctionCount() const
70 RELEASE_ASSERT(!failed());
71 return m_wasmInternalFunctions.size();
74 B3::Compilation* jsToWasmEntryPointForFunction(size_t i) const
76 ASSERT(i > m_wasmToJSStubs.size());
77 return m_wasmInternalFunctions.at(i - m_wasmToJSStubs.size())->jsToWasmEntryPoint.get();
80 std::unique_ptr<ModuleInformation>&& takeModuleInformation()
82 RELEASE_ASSERT(!failed());
83 return WTFMove(m_moduleInformation);
86 Bag<CallLinkInfo>&& takeCallLinkInfos()
88 RELEASE_ASSERT(!failed());
89 return WTFMove(m_callLinkInfos);
92 Vector<WasmToJSStub>&& takeWasmToJSStubs()
94 RELEASE_ASSERT(!failed());
95 return WTFMove(m_wasmToJSStubs);
98 ImmutableFunctionIndexSpace&& takeFunctionIndexSpace()
100 RELEASE_ASSERT(!failed());
101 return WTFMove(m_functionIndexSpace);
105 std::unique_ptr<ModuleInformation> m_moduleInformation;
106 Vector<FunctionLocationInBinary> m_functionLocationInBinary;
107 Bag<CallLinkInfo> m_callLinkInfos;
108 Vector<WasmToJSStub> m_wasmToJSStubs;
109 Vector<std::unique_ptr<WasmInternalFunction>> m_wasmInternalFunctions;
110 ImmutableFunctionIndexSpace m_functionIndexSpace;
113 const uint8_t* m_source;
114 const size_t m_sourceLength;
115 bool m_failed { true };
116 String m_errorMessage;
119 } } // namespace JSC::Wasm
121 #endif // ENABLE(WEBASSEMBLY)