1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_WASM_WASM_SERIALIZATION_H_
6 #define V8_WASM_WASM_SERIALIZATION_H_
7 
8 #include "src/wasm/wasm-objects.h"
9 
10 namespace v8 {
11 namespace internal {
12 namespace wasm {
13 
14 // Support to serialize WebAssembly {NativeModule} objects. This class intends
15 // to be thread-safe in that it takes a consistent snapshot of the module state
16 // at instantiation, allowing other threads to mutate the module concurrently.
17 class WasmSerializer {
18  public:
19   WasmSerializer(Isolate* isolate, NativeModule* native_module);
20 
21   // Measure the required buffer size needed for serialization.
22   size_t GetSerializedNativeModuleSize() const;
23 
24   // Serialize the {NativeModule} into the provided {buffer}. Returns true on
25   // success and false if the given buffer it too small for serialization.
26   bool SerializeNativeModule(Vector<byte> buffer) const;
27 
28  private:
29   Isolate* isolate_;
30   NativeModule* native_module_;
31   std::vector<WasmCode*> code_table_;
32 };
33 
34 // Support to deserialize WebAssembly {NativeModule} objects.
35 MaybeHandle<WasmModuleObject> DeserializeNativeModule(
36     Isolate* isolate, Vector<const byte> data, Vector<const byte> wire_bytes);
37 
38 }  // namespace wasm
39 }  // namespace internal
40 }  // namespace v8
41 
42 #endif  // V8_WASM_WASM_SERIALIZATION_H_
43