1/* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef JERRYSCRIPT_SNAPSHOT_H
17#define JERRYSCRIPT_SNAPSHOT_H
18
19#include "jerryscript-core.h"
20
21#ifdef __cplusplus
22extern "C"
23{
24#endif /* __cplusplus */
25
26/** \addtogroup jerry-snapshot Jerry engine interface - Snapshot feature
27 * @{
28 */
29
30/**
31 * Jerry snapshot format version.
32 */
33#define JERRY_SNAPSHOT_VERSION (49u)
34
35/**
36 * Flags for jerry_generate_snapshot and jerry_generate_function_snapshot.
37 */
38typedef enum
39{
40  JERRY_SNAPSHOT_SAVE_STATIC = (1u << 0), /**< static snapshot */
41  JERRY_SNAPSHOT_SAVE_STRICT = (1u << 1), /**< strict mode code */
42} jerry_generate_snapshot_opts_t;
43
44/**
45 * Flags for jerry_exec_snapshot_at and jerry_load_function_snapshot_at.
46 */
47typedef enum
48{
49  JERRY_SNAPSHOT_EXEC_COPY_DATA = (1u << 0), /**< copy snashot data */
50  JERRY_SNAPSHOT_EXEC_ALLOW_STATIC = (1u << 1), /**< static snapshots allowed */
51} jerry_exec_snapshot_opts_t;
52
53/**
54 * Snapshot functions.
55 */
56jerry_value_t jerry_generate_snapshot (const jerry_char_t *resource_name_p, size_t resource_name_length,
57                                       const jerry_char_t *source_p, size_t source_size,
58                                       uint32_t generate_snapshot_opts, uint32_t *buffer_p, size_t buffer_size);
59jerry_value_t jerry_generate_function_snapshot (const jerry_char_t *resource_name_p, size_t resource_name_length,
60                                                const jerry_char_t *source_p, size_t source_size,
61                                                const jerry_char_t *args_p, size_t args_size,
62                                                uint32_t generate_snapshot_opts, uint32_t *buffer_p,
63                                                size_t buffer_size);
64
65jerry_value_t jerry_exec_snapshot (const uint32_t *snapshot_p, size_t snapshot_size,
66                                   size_t func_index, uint32_t exec_snapshot_opts);
67jerry_value_t jerry_load_function_snapshot (const uint32_t *function_snapshot_p,
68                                            const size_t function_snapshot_size,
69                                            size_t func_index, uint32_t exec_snapshot_opts);
70
71size_t jerry_merge_snapshots (const uint32_t **inp_buffers_p, size_t *inp_buffer_sizes_p, size_t number_of_snapshots,
72                              uint32_t *out_buffer_p, size_t out_buffer_size, const char **error_p);
73size_t jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, size_t snapshot_size,
74                                         jerry_char_t *lit_buf_p, size_t lit_buf_size, bool is_c_format);
75/**
76 * @}
77 */
78
79#ifdef __cplusplus
80}
81#endif /* __cplusplus */
82#endif /* !JERRYSCRIPT_SNAPSHOT_H */
83