Modify the snapshot API functions to expect a 32-bit aligned buffer pointer (#1655)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
This commit is contained in:
@@ -3419,7 +3419,7 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p,
|
|||||||
size_t source_size,
|
size_t source_size,
|
||||||
bool is_for_global,
|
bool is_for_global,
|
||||||
bool is_strict,
|
bool is_strict,
|
||||||
uint8_t *buffer_p,
|
uint32_t *buffer_p,
|
||||||
size_t buffer_size);
|
size_t buffer_size);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -3441,7 +3441,7 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p,
|
|||||||
{
|
{
|
||||||
jerry_init (JERRY_INIT_EMPTY);
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
static uint8_t global_mode_snapshot_buffer[1024];
|
static uint32_t global_mode_snapshot_buffer[256];
|
||||||
const jerry_char_t *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
|
const jerry_char_t *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
|
||||||
|
|
||||||
size_t global_mode_snapshot_size = jerry_parse_and_save_snapshot (code_to_snapshot_p,
|
size_t global_mode_snapshot_size = jerry_parse_and_save_snapshot (code_to_snapshot_p,
|
||||||
@@ -3449,7 +3449,7 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p,
|
|||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
global_mode_snapshot_buffer,
|
global_mode_snapshot_buffer,
|
||||||
sizeof (global_mode_snapshot_buffer));
|
sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t));
|
||||||
|
|
||||||
jerry_cleanup ();
|
jerry_cleanup ();
|
||||||
}
|
}
|
||||||
@@ -3475,7 +3475,7 @@ is no longer needed.
|
|||||||
|
|
||||||
```c
|
```c
|
||||||
jerry_value_t
|
jerry_value_t
|
||||||
jerry_exec_snapshot (const void *snapshot_p,
|
jerry_exec_snapshot (const uint32_t *snapshot_p,
|
||||||
size_t snapshot_size,
|
size_t snapshot_size,
|
||||||
bool copy_bytecode);
|
bool copy_bytecode);
|
||||||
```
|
```
|
||||||
@@ -3495,7 +3495,7 @@ jerry_exec_snapshot (const void *snapshot_p,
|
|||||||
```c
|
```c
|
||||||
{
|
{
|
||||||
jerry_value_t res;
|
jerry_value_t res;
|
||||||
static uint8_t global_mode_snapshot_buffer[1024];
|
static uint32_t global_mode_snapshot_buffer[256];
|
||||||
const jerry_char_t *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
|
const jerry_char_t *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
|
||||||
|
|
||||||
jerry_init (JERRY_INIT_EMPTY);
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
@@ -3504,7 +3504,7 @@ jerry_exec_snapshot (const void *snapshot_p,
|
|||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
global_mode_snapshot_buffer,
|
global_mode_snapshot_buffer,
|
||||||
sizeof (global_mode_snapshot_buffer));
|
sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t));
|
||||||
jerry_cleanup ();
|
jerry_cleanup ();
|
||||||
|
|
||||||
jerry_init (JERRY_INIT_EMPTY);
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
@@ -3538,7 +3538,7 @@ size_t
|
|||||||
jerry_parse_and_save_literals (const jerry_char_t *source_p,
|
jerry_parse_and_save_literals (const jerry_char_t *source_p,
|
||||||
size_t source_size,
|
size_t source_size,
|
||||||
bool is_strict,
|
bool is_strict,
|
||||||
uint8_t *buffer_p,
|
uint32_t *buffer_p,
|
||||||
size_t buffer_size,
|
size_t buffer_size,
|
||||||
bool is_c_format);
|
bool is_c_format);
|
||||||
```
|
```
|
||||||
@@ -3560,14 +3560,14 @@ jerry_parse_and_save_literals (const jerry_char_t *source_p,
|
|||||||
{
|
{
|
||||||
jerry_init (JERRY_INIT_EMPTY);
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
static uint8_t save_literal_buffer[1024];
|
static uint32_t save_literal_buffer[256];
|
||||||
const jerry_char_t *code_for_literal_save_p = "var obj = { a:'aa', bb:'Bb' }";
|
const jerry_char_t *code_for_literal_save_p = "var obj = { a:'aa', bb:'Bb' }";
|
||||||
|
|
||||||
size_t literal_sizes = jerry_parse_and_save_literals (code_for_literal_save_p,
|
size_t literal_sizes = jerry_parse_and_save_literals (code_for_literal_save_p,
|
||||||
strlen ((const char *) code_for_literal_save_p),
|
strlen ((const char *) code_for_literal_save_p),
|
||||||
false,
|
false,
|
||||||
save_literal_buffer,
|
save_literal_buffer,
|
||||||
sizeof (save_literal_buffer),
|
sizeof (save_literal_buffer) / sizeof (uint32_t),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
if (literal_sizes != 0)
|
if (literal_sizes != 0)
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be
|
|||||||
* false - otherwise.
|
* false - otherwise.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot buffer */
|
ecma_save_literals_for_snapshot (uint32_t *buffer_p, /**< [out] output snapshot buffer */
|
||||||
size_t buffer_size, /**< size of the buffer */
|
size_t buffer_size, /**< size of the buffer */
|
||||||
size_t *in_out_buffer_offset_p, /**< [in,out] write position in the buffer */
|
size_t *in_out_buffer_offset_p, /**< [in,out] write position in the buffer */
|
||||||
lit_mem_to_snapshot_id_map_entry_t **out_map_p, /**< [out] map from literal identifiers
|
lit_mem_to_snapshot_id_map_entry_t **out_map_p, /**< [out] map from literal identifiers
|
||||||
@@ -294,7 +294,8 @@ ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot b
|
|||||||
map_p = jmem_heap_alloc_block (total_count * sizeof (lit_mem_to_snapshot_id_map_entry_t));
|
map_p = jmem_heap_alloc_block (total_count * sizeof (lit_mem_to_snapshot_id_map_entry_t));
|
||||||
|
|
||||||
/* Set return values (no error is possible from here). */
|
/* Set return values (no error is possible from here). */
|
||||||
buffer_p += *in_out_buffer_offset_p;
|
JERRY_ASSERT ((*in_out_buffer_offset_p % sizeof (uint32_t)) == 0);
|
||||||
|
buffer_p += *in_out_buffer_offset_p / sizeof (uint32_t);
|
||||||
*in_out_buffer_offset_p += lit_table_size;
|
*in_out_buffer_offset_p += lit_table_size;
|
||||||
*out_map_p = map_p;
|
*out_map_p = map_p;
|
||||||
*out_map_len_p = total_count;
|
*out_map_len_p = total_count;
|
||||||
@@ -306,12 +307,14 @@ ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot b
|
|||||||
* constant so the first literal must have offset one. */
|
* constant so the first literal must have offset one. */
|
||||||
uint32_t literal_offset = JERRY_SNAPSHOT_LITERAL_ALIGNMENT;
|
uint32_t literal_offset = JERRY_SNAPSHOT_LITERAL_ALIGNMENT;
|
||||||
|
|
||||||
((uint32_t *) buffer_p)[0] = string_count;
|
buffer_p[0] = string_count;
|
||||||
((uint32_t *) buffer_p)[1] = number_count;
|
buffer_p[1] = number_count;
|
||||||
buffer_p += 2 * sizeof (uint32_t);
|
buffer_p += 2;
|
||||||
|
|
||||||
string_list_p = JERRY_CONTEXT (string_list_first_p);
|
string_list_p = JERRY_CONTEXT (string_list_first_p);
|
||||||
|
|
||||||
|
uint16_t *destination_p = (uint16_t *) buffer_p;
|
||||||
|
|
||||||
while (string_list_p != NULL)
|
while (string_list_p != NULL)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||||
@@ -327,13 +330,14 @@ ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot b
|
|||||||
|
|
||||||
ecma_length_t length = ecma_string_get_size (string_p);
|
ecma_length_t length = ecma_string_get_size (string_p);
|
||||||
|
|
||||||
*((uint16_t *) buffer_p) = (uint16_t) length;
|
*destination_p = (uint16_t) length;
|
||||||
ecma_string_to_utf8_bytes (string_p, buffer_p + sizeof (uint16_t), length);
|
ecma_string_to_utf8_bytes (string_p, ((lit_utf8_byte_t *) destination_p) + sizeof (uint16_t), length);
|
||||||
|
|
||||||
length = JERRY_ALIGNUP (sizeof (uint16_t) + length,
|
length = JERRY_ALIGNUP (sizeof (uint16_t) + length,
|
||||||
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||||
|
|
||||||
buffer_p += length;
|
JERRY_ASSERT ((length % sizeof (uint16_t)) == 0);
|
||||||
|
destination_p += length / sizeof (uint16_t);
|
||||||
literal_offset += length;
|
literal_offset += length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,12 +363,13 @@ ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot b
|
|||||||
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (value_p) == ECMA_STRING_LITERAL_NUMBER);
|
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (value_p) == ECMA_STRING_LITERAL_NUMBER);
|
||||||
|
|
||||||
ecma_number_t num = ecma_get_number_from_value (value_p->u.lit_number);
|
ecma_number_t num = ecma_get_number_from_value (value_p->u.lit_number);
|
||||||
memcpy (buffer_p, &num, sizeof (ecma_number_t));
|
memcpy (destination_p, &num, sizeof (ecma_number_t));
|
||||||
|
|
||||||
ecma_length_t length = JERRY_ALIGNUP (sizeof (ecma_number_t),
|
ecma_length_t length = JERRY_ALIGNUP (sizeof (ecma_number_t),
|
||||||
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||||
|
|
||||||
buffer_p += length;
|
JERRY_ASSERT ((length % sizeof (uint16_t)) == 0);
|
||||||
|
destination_p += length / sizeof (uint16_t);
|
||||||
literal_offset += length;
|
literal_offset += length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,7 +393,7 @@ ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot b
|
|||||||
* false - otherwise (i.e. buffer length is incorrect).
|
* false - otherwise (i.e. buffer length is incorrect).
|
||||||
*/
|
*/
|
||||||
static inline bool __attr_always_inline___
|
static inline bool __attr_always_inline___
|
||||||
ecma_load_literals_from_buffer (const uint8_t *buffer_p, /**< buffer with literal table in snapshot */
|
ecma_load_literals_from_buffer (const uint16_t *buffer_p, /**< buffer with literal table in snapshot */
|
||||||
uint32_t lit_table_size, /**< size of literal table in snapshot */
|
uint32_t lit_table_size, /**< size of literal table in snapshot */
|
||||||
lit_mem_to_snapshot_id_map_entry_t *map_p, /**< literal map */
|
lit_mem_to_snapshot_id_map_entry_t *map_p, /**< literal map */
|
||||||
uint32_t string_count, /**< number of strings */
|
uint32_t string_count, /**< number of strings */
|
||||||
@@ -407,7 +412,7 @@ ecma_load_literals_from_buffer (const uint8_t *buffer_p, /**< buffer with litera
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
lit_utf8_size_t length = *((uint16_t *) buffer_p);
|
lit_utf8_size_t length = *buffer_p;
|
||||||
lit_utf8_size_t aligned_length = JERRY_ALIGNUP (sizeof (uint16_t) + length,
|
lit_utf8_size_t aligned_length = JERRY_ALIGNUP (sizeof (uint16_t) + length,
|
||||||
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||||
|
|
||||||
@@ -417,11 +422,12 @@ ecma_load_literals_from_buffer (const uint8_t *buffer_p, /**< buffer with litera
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
map_p->literal_id = ecma_find_or_create_literal_string (buffer_p + sizeof (uint16_t), length);
|
map_p->literal_id = ecma_find_or_create_literal_string (((lit_utf8_byte_t *) buffer_p) + sizeof (uint16_t), length);
|
||||||
map_p->literal_offset = (jmem_cpointer_t) (literal_offset >> JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG);
|
map_p->literal_offset = (jmem_cpointer_t) (literal_offset >> JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG);
|
||||||
map_p++;
|
map_p++;
|
||||||
|
|
||||||
buffer_p += aligned_length;
|
JERRY_ASSERT ((aligned_length % sizeof (uint16_t)) == 0);
|
||||||
|
buffer_p += aligned_length / sizeof (uint16_t);
|
||||||
literal_offset += aligned_length;
|
literal_offset += aligned_length;
|
||||||
|
|
||||||
string_count--;
|
string_count--;
|
||||||
@@ -446,7 +452,8 @@ ecma_load_literals_from_buffer (const uint8_t *buffer_p, /**< buffer with litera
|
|||||||
ecma_length_t length = JERRY_ALIGNUP (sizeof (ecma_number_t),
|
ecma_length_t length = JERRY_ALIGNUP (sizeof (ecma_number_t),
|
||||||
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||||
|
|
||||||
buffer_p += length;
|
JERRY_ASSERT ((length % sizeof (uint16_t)) == 0);
|
||||||
|
buffer_p += length / sizeof (uint16_t);
|
||||||
literal_offset += length;
|
literal_offset += length;
|
||||||
|
|
||||||
number_count--;
|
number_count--;
|
||||||
@@ -462,7 +469,7 @@ ecma_load_literals_from_buffer (const uint8_t *buffer_p, /**< buffer with litera
|
|||||||
* false - otherwise (i.e. snapshot is incorrect).
|
* false - otherwise (i.e. snapshot is incorrect).
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
ecma_load_literals_from_snapshot (const uint8_t *buffer_p, /**< buffer with literal table in snapshot */
|
ecma_load_literals_from_snapshot (const uint32_t *buffer_p, /**< buffer with literal table in snapshot */
|
||||||
uint32_t lit_table_size, /**< size of literal table in snapshot */
|
uint32_t lit_table_size, /**< size of literal table in snapshot */
|
||||||
lit_mem_to_snapshot_id_map_entry_t **out_map_p, /**< [out] map from literal offsets
|
lit_mem_to_snapshot_id_map_entry_t **out_map_p, /**< [out] map from literal offsets
|
||||||
* in snapshot to identifiers
|
* in snapshot to identifiers
|
||||||
@@ -478,9 +485,9 @@ ecma_load_literals_from_snapshot (const uint8_t *buffer_p, /**< buffer with lite
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t string_count = ((uint32_t *) buffer_p)[0];
|
uint32_t string_count = buffer_p[0];
|
||||||
uint32_t number_count = ((uint32_t *) buffer_p)[1];
|
uint32_t number_count = buffer_p[1];
|
||||||
buffer_p += 2 * sizeof (uint32_t);
|
buffer_p += 2;
|
||||||
|
|
||||||
uint32_t total_count = string_count + number_count;
|
uint32_t total_count = string_count + number_count;
|
||||||
lit_mem_to_snapshot_id_map_entry_t *map_p;
|
lit_mem_to_snapshot_id_map_entry_t *map_p;
|
||||||
@@ -495,7 +502,7 @@ ecma_load_literals_from_snapshot (const uint8_t *buffer_p, /**< buffer with lite
|
|||||||
map_p = jmem_heap_alloc_block (total_count * sizeof (lit_mem_to_snapshot_id_map_entry_t));
|
map_p = jmem_heap_alloc_block (total_count * sizeof (lit_mem_to_snapshot_id_map_entry_t));
|
||||||
*out_map_p = map_p;
|
*out_map_p = map_p;
|
||||||
|
|
||||||
if (ecma_load_literals_from_buffer (buffer_p, lit_table_size, map_p, string_count, number_count))
|
if (ecma_load_literals_from_buffer ((uint16_t *) buffer_p, lit_table_size, map_p, string_count, number_count))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,13 +43,13 @@ jmem_cpointer_t ecma_find_or_create_literal_number (ecma_number_t number_arg);
|
|||||||
|
|
||||||
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
|
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
|
||||||
bool
|
bool
|
||||||
ecma_save_literals_for_snapshot (uint8_t *, size_t, size_t *,
|
ecma_save_literals_for_snapshot (uint32_t *, size_t, size_t *,
|
||||||
lit_mem_to_snapshot_id_map_entry_t **, uint32_t *, uint32_t *);
|
lit_mem_to_snapshot_id_map_entry_t **, uint32_t *, uint32_t *);
|
||||||
#endif /* JERRY_ENABLE_SNAPSHOT_SAVE */
|
#endif /* JERRY_ENABLE_SNAPSHOT_SAVE */
|
||||||
|
|
||||||
#ifdef JERRY_ENABLE_SNAPSHOT_EXEC
|
#ifdef JERRY_ENABLE_SNAPSHOT_EXEC
|
||||||
bool
|
bool
|
||||||
ecma_load_literals_from_snapshot (const uint8_t *, uint32_t,
|
ecma_load_literals_from_snapshot (const uint32_t *, uint32_t,
|
||||||
lit_mem_to_snapshot_id_map_entry_t **, uint32_t *);
|
lit_mem_to_snapshot_id_map_entry_t **, uint32_t *);
|
||||||
#endif /* JERRY_ENABLE_SNAPSHOT_EXEC */
|
#endif /* JERRY_ENABLE_SNAPSHOT_EXEC */
|
||||||
|
|
||||||
|
|||||||
+51
-46
@@ -208,7 +208,7 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
|
|||||||
* Set the uint16_t offsets in the code area.
|
* Set the uint16_t offsets in the code area.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
jerry_snapshot_set_offsets (uint8_t *buffer_p, /**< buffer */
|
jerry_snapshot_set_offsets (uint32_t *buffer_p, /**< buffer */
|
||||||
uint32_t size, /**< buffer size */
|
uint32_t size, /**< buffer size */
|
||||||
lit_mem_to_snapshot_id_map_entry_t *lit_map_p) /**< literal map */
|
lit_mem_to_snapshot_id_map_entry_t *lit_map_p) /**< literal map */
|
||||||
{
|
{
|
||||||
@@ -228,7 +228,7 @@ jerry_snapshot_set_offsets (uint8_t *buffer_p, /**< buffer */
|
|||||||
|
|
||||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
if (bytecode_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
||||||
{
|
{
|
||||||
literal_start_p = (jmem_cpointer_t *) (buffer_p + sizeof (cbc_uint16_arguments_t));
|
literal_start_p = (jmem_cpointer_t *) (((uint8_t *) buffer_p) + sizeof (cbc_uint16_arguments_t));
|
||||||
|
|
||||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) buffer_p;
|
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) buffer_p;
|
||||||
argument_end = args_p->argument_end;
|
argument_end = args_p->argument_end;
|
||||||
@@ -237,7 +237,7 @@ jerry_snapshot_set_offsets (uint8_t *buffer_p, /**< buffer */
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
literal_start_p = (jmem_cpointer_t *) (buffer_p + sizeof (cbc_uint8_arguments_t));
|
literal_start_p = (jmem_cpointer_t *) (((uint8_t *) buffer_p) + sizeof (cbc_uint8_arguments_t));
|
||||||
|
|
||||||
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) buffer_p;
|
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) buffer_p;
|
||||||
argument_end = args_p->argument_end;
|
argument_end = args_p->argument_end;
|
||||||
@@ -292,7 +292,8 @@ jerry_snapshot_set_offsets (uint8_t *buffer_p, /**< buffer */
|
|||||||
bytecode_p->refs = 1;
|
bytecode_p->refs = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_p += code_size;
|
JERRY_ASSERT ((code_size % sizeof (uint32_t)) == 0);
|
||||||
|
buffer_p += code_size / sizeof (uint32_t);
|
||||||
size -= code_size;
|
size -= code_size;
|
||||||
}
|
}
|
||||||
while (size > 0);
|
while (size > 0);
|
||||||
@@ -458,7 +459,7 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p, /**< script source
|
|||||||
bool is_for_global, /**< snapshot would be executed as global (true)
|
bool is_for_global, /**< snapshot would be executed as global (true)
|
||||||
* or eval (false) */
|
* or eval (false) */
|
||||||
bool is_strict, /**< strict mode */
|
bool is_strict, /**< strict mode */
|
||||||
uint8_t *buffer_p, /**< buffer to save snapshot to */
|
uint32_t *buffer_p, /**< buffer to save snapshot to */
|
||||||
size_t buffer_size) /**< the buffer's size */
|
size_t buffer_size) /**< the buffer's size */
|
||||||
{
|
{
|
||||||
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
|
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
|
||||||
@@ -481,7 +482,7 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p, /**< script source
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot_add_compiled_code (bytecode_data_p, buffer_p, buffer_size, &globals);
|
snapshot_add_compiled_code (bytecode_data_p, (uint8_t *) buffer_p, buffer_size, &globals);
|
||||||
|
|
||||||
if (globals.snapshot_error_occured)
|
if (globals.snapshot_error_occured)
|
||||||
{
|
{
|
||||||
@@ -507,13 +508,14 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p, /**< script source
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
jerry_snapshot_set_offsets (buffer_p + JERRY_ALIGNUP (sizeof (jerry_snapshot_header_t), JMEM_ALIGNMENT),
|
jerry_snapshot_set_offsets (buffer_p + (JERRY_ALIGNUP (sizeof (jerry_snapshot_header_t),
|
||||||
|
JMEM_ALIGNMENT) / sizeof (uint32_t)),
|
||||||
(uint32_t) (header.lit_table_offset - sizeof (jerry_snapshot_header_t)),
|
(uint32_t) (header.lit_table_offset - sizeof (jerry_snapshot_header_t)),
|
||||||
lit_map_p);
|
lit_map_p);
|
||||||
|
|
||||||
size_t header_offset = 0;
|
size_t header_offset = 0;
|
||||||
|
|
||||||
snapshot_write_to_buffer_by_offset (buffer_p,
|
snapshot_write_to_buffer_by_offset ((uint8_t *) buffer_p,
|
||||||
buffer_size,
|
buffer_size,
|
||||||
&header_offset,
|
&header_offset,
|
||||||
&header,
|
&header,
|
||||||
@@ -549,7 +551,7 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p, /**< script source
|
|||||||
* thrown error - otherwise
|
* thrown error - otherwise
|
||||||
*/
|
*/
|
||||||
jerry_value_t
|
jerry_value_t
|
||||||
jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
|
jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
|
||||||
size_t snapshot_size, /**< size of snapshot */
|
size_t snapshot_size, /**< size of snapshot */
|
||||||
bool copy_bytecode) /**< flag, indicating whether the passed snapshot
|
bool copy_bytecode) /**< flag, indicating whether the passed snapshot
|
||||||
* buffer should be copied to the engine's memory.
|
* buffer should be copied to the engine's memory.
|
||||||
@@ -586,7 +588,8 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
|
|||||||
return ecma_raise_type_error (invalid_version_error_p);
|
return ecma_raise_type_error (invalid_version_error_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ecma_load_literals_from_snapshot (snapshot_data_p + header_p->lit_table_offset,
|
JERRY_ASSERT ((header_p->lit_table_offset % sizeof (uint32_t)) == 0);
|
||||||
|
if (!ecma_load_literals_from_snapshot ((uint32_t *) (snapshot_data_p + header_p->lit_table_offset),
|
||||||
header_p->lit_table_size,
|
header_p->lit_table_size,
|
||||||
&lit_map_p,
|
&lit_map_p,
|
||||||
&literals_num))
|
&literals_num))
|
||||||
@@ -882,7 +885,7 @@ size_t
|
|||||||
jerry_parse_and_save_literals (const jerry_char_t *source_p, /**< script source */
|
jerry_parse_and_save_literals (const jerry_char_t *source_p, /**< script source */
|
||||||
size_t source_size, /**< script source size */
|
size_t source_size, /**< script source size */
|
||||||
bool is_strict, /**< strict mode */
|
bool is_strict, /**< strict mode */
|
||||||
uint8_t *buffer_p, /**< [out] buffer to save literals to */
|
uint32_t *buffer_p, /**< [out] buffer to save literals to */
|
||||||
size_t buffer_size, /**< the buffer's size */
|
size_t buffer_size, /**< the buffer's size */
|
||||||
bool is_c_format) /**< format-flag */
|
bool is_c_format) /**< format-flag */
|
||||||
{
|
{
|
||||||
@@ -934,8 +937,10 @@ jerry_parse_and_save_literals (const jerry_char_t *source_p, /**< script source
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t * const buffer_start_p = buffer_p;
|
uint8_t *destination_p = (uint8_t *) buffer_p;
|
||||||
uint8_t * const buffer_end_p = buffer_p + buffer_size;
|
|
||||||
|
uint8_t *const buffer_start_p = destination_p;
|
||||||
|
uint8_t *const buffer_end_p = destination_p + buffer_size;
|
||||||
|
|
||||||
JMEM_DEFINE_LOCAL_ARRAY (literal_array, literal_count, ecma_string_t *);
|
JMEM_DEFINE_LOCAL_ARRAY (literal_array, literal_count, ecma_string_t *);
|
||||||
lit_utf8_size_t literal_idx = 0;
|
lit_utf8_size_t literal_idx = 0;
|
||||||
@@ -968,43 +973,43 @@ jerry_parse_and_save_literals (const jerry_char_t *source_p, /**< script source
|
|||||||
if (is_c_format)
|
if (is_c_format)
|
||||||
{
|
{
|
||||||
/* Save literal count. */
|
/* Save literal count. */
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p,
|
destination_p = jerry_append_chars_to_buffer (destination_p,
|
||||||
buffer_end_p,
|
buffer_end_p,
|
||||||
(const char *) "jerry_length_t literal_count = ",
|
(const char *) "jerry_length_t literal_count = ",
|
||||||
0);
|
0);
|
||||||
|
|
||||||
buffer_p = jerry_append_number_to_buffer (buffer_p, buffer_end_p, literal_count);
|
destination_p = jerry_append_number_to_buffer (destination_p, buffer_end_p, literal_count);
|
||||||
|
|
||||||
/* Save the array of literals. */
|
/* Save the array of literals. */
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p,
|
destination_p = jerry_append_chars_to_buffer (destination_p,
|
||||||
buffer_end_p,
|
buffer_end_p,
|
||||||
";\n\njerry_char_ptr_t literals[",
|
";\n\njerry_char_ptr_t literals[",
|
||||||
0);
|
0);
|
||||||
|
|
||||||
buffer_p = jerry_append_number_to_buffer (buffer_p, buffer_end_p, literal_count);
|
destination_p = jerry_append_number_to_buffer (destination_p, buffer_end_p, literal_count);
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, "] =\n{\n", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, "] =\n{\n", 0);
|
||||||
|
|
||||||
for (lit_utf8_size_t i = 0; i < literal_count; i++)
|
for (lit_utf8_size_t i = 0; i < literal_count; i++)
|
||||||
{
|
{
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, " \"", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, " \"", 0);
|
||||||
buffer_p = jerry_append_ecma_string_to_buffer (buffer_p, buffer_end_p, literal_array[i]);
|
destination_p = jerry_append_ecma_string_to_buffer (destination_p, buffer_end_p, literal_array[i]);
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, "\"", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, "\"", 0);
|
||||||
|
|
||||||
if (i < literal_count - 1)
|
if (i < literal_count - 1)
|
||||||
{
|
{
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, ",", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, ",", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, "\n", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, "\n", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p,
|
destination_p = jerry_append_chars_to_buffer (destination_p,
|
||||||
buffer_end_p,
|
buffer_end_p,
|
||||||
(const char *) "};\n\njerry_length_t literal_sizes[",
|
(const char *) "};\n\njerry_length_t literal_sizes[",
|
||||||
0);
|
0);
|
||||||
|
|
||||||
buffer_p = jerry_append_number_to_buffer (buffer_p, buffer_end_p, literal_count);
|
destination_p = jerry_append_number_to_buffer (destination_p, buffer_end_p, literal_count);
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, "] =\n{\n", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, "] =\n{\n", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the literal sizes respectively. */
|
/* Save the literal sizes respectively. */
|
||||||
@@ -1014,40 +1019,40 @@ jerry_parse_and_save_literals (const jerry_char_t *source_p, /**< script source
|
|||||||
|
|
||||||
if (is_c_format)
|
if (is_c_format)
|
||||||
{
|
{
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, " ", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, " ", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_p = jerry_append_number_to_buffer (buffer_p, buffer_end_p, str_size);
|
destination_p = jerry_append_number_to_buffer (destination_p, buffer_end_p, str_size);
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, " ", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, " ", 0);
|
||||||
|
|
||||||
if (is_c_format)
|
if (is_c_format)
|
||||||
{
|
{
|
||||||
/* Show the given string as a comment. */
|
/* Show the given string as a comment. */
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, "/* ", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, "/* ", 0);
|
||||||
buffer_p = jerry_append_ecma_string_to_buffer (buffer_p, buffer_end_p, literal_array[i]);
|
destination_p = jerry_append_ecma_string_to_buffer (destination_p, buffer_end_p, literal_array[i]);
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, " */", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, " */", 0);
|
||||||
|
|
||||||
if (i < literal_count - 1)
|
if (i < literal_count - 1)
|
||||||
{
|
{
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, ",", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, ",", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buffer_p = jerry_append_ecma_string_to_buffer (buffer_p, buffer_end_p, literal_array[i]);
|
destination_p = jerry_append_ecma_string_to_buffer (destination_p, buffer_end_p, literal_array[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, "\n", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, "\n", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_c_format)
|
if (is_c_format)
|
||||||
{
|
{
|
||||||
buffer_p = jerry_append_chars_to_buffer (buffer_p, buffer_end_p, (const char *) "};\n", 0);
|
destination_p = jerry_append_chars_to_buffer (destination_p, buffer_end_p, (const char *) "};\n", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
JMEM_FINALIZE_LOCAL_ARRAY (literal_array);
|
JMEM_FINALIZE_LOCAL_ARRAY (literal_array);
|
||||||
|
|
||||||
return buffer_p <= buffer_end_p ? (size_t) (buffer_p - buffer_start_p) : 0;
|
return destination_p <= buffer_end_p ? (size_t) (destination_p - buffer_start_p) : 0;
|
||||||
#else /* !JERRY_ENABLE_SNAPSHOT_SAVE */
|
#else /* !JERRY_ENABLE_SNAPSHOT_SAVE */
|
||||||
JERRY_UNUSED (source_p);
|
JERRY_UNUSED (source_p);
|
||||||
JERRY_UNUSED (source_size);
|
JERRY_UNUSED (source_size);
|
||||||
|
|||||||
@@ -339,10 +339,10 @@ bool jerry_is_valid_cesu8_string (const jerry_char_t *cesu8_buf_p, jerry_size_t
|
|||||||
* Snapshot functions
|
* Snapshot functions
|
||||||
*/
|
*/
|
||||||
size_t jerry_parse_and_save_snapshot (const jerry_char_t *source_p, size_t source_size, bool is_for_global,
|
size_t jerry_parse_and_save_snapshot (const jerry_char_t *source_p, size_t source_size, bool is_for_global,
|
||||||
bool is_strict, uint8_t *buffer_p, size_t buffer_size);
|
bool is_strict, uint32_t *buffer_p, size_t buffer_size);
|
||||||
jerry_value_t jerry_exec_snapshot (const void *snapshot_p, size_t snapshot_size, bool copy_bytecode);
|
jerry_value_t jerry_exec_snapshot (const uint32_t *snapshot_p, size_t snapshot_size, bool copy_bytecode);
|
||||||
size_t jerry_parse_and_save_literals (const jerry_char_t *source_p, size_t source_size, bool is_strict,
|
size_t jerry_parse_and_save_literals (const jerry_char_t *source_p, size_t source_size, bool is_strict,
|
||||||
uint8_t *buffer_p, size_t buffer_size, bool is_c_format);
|
uint32_t *buffer_p, size_t buffer_size, bool is_c_format);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
+14
-9
@@ -28,10 +28,15 @@
|
|||||||
#define JERRY_MAX_COMMAND_LINE_ARGS (64)
|
#define JERRY_MAX_COMMAND_LINE_ARGS (64)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum size of source code / snapshots buffer
|
* Maximum size of source code
|
||||||
*/
|
*/
|
||||||
#define JERRY_BUFFER_SIZE (1048576)
|
#define JERRY_BUFFER_SIZE (1048576)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum size of snapshots buffer
|
||||||
|
*/
|
||||||
|
#define JERRY_SNAPSHOT_BUFFER_SIZE (JERRY_BUFFER_SIZE / sizeof (uint32_t))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standalone Jerry exit codes
|
* Standalone Jerry exit codes
|
||||||
*/
|
*/
|
||||||
@@ -45,7 +50,7 @@
|
|||||||
|
|
||||||
static uint8_t buffer[ JERRY_BUFFER_SIZE ];
|
static uint8_t buffer[ JERRY_BUFFER_SIZE ];
|
||||||
|
|
||||||
static const uint8_t *
|
static const uint32_t *
|
||||||
read_file (const char *file_name,
|
read_file (const char *file_name,
|
||||||
size_t *out_size_p)
|
size_t *out_size_p)
|
||||||
{
|
{
|
||||||
@@ -75,7 +80,7 @@ read_file (const char *file_name,
|
|||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
*out_size_p = bytes_read;
|
*out_size_p = bytes_read;
|
||||||
return (const uint8_t *) buffer;
|
return (const uint32_t *) buffer;
|
||||||
} /* read_file */
|
} /* read_file */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -629,7 +634,7 @@ main (int argc,
|
|||||||
for (int i = 0; i < exec_snapshots_count; i++)
|
for (int i = 0; i < exec_snapshots_count; i++)
|
||||||
{
|
{
|
||||||
size_t snapshot_size;
|
size_t snapshot_size;
|
||||||
const uint8_t *snapshot_p = read_file (exec_snapshot_file_names[i], &snapshot_size);
|
const uint32_t *snapshot_p = read_file (exec_snapshot_file_names[i], &snapshot_size);
|
||||||
|
|
||||||
if (snapshot_p == NULL)
|
if (snapshot_p == NULL)
|
||||||
{
|
{
|
||||||
@@ -637,7 +642,7 @@ main (int argc,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret_value = jerry_exec_snapshot ((void *) snapshot_p,
|
ret_value = jerry_exec_snapshot (snapshot_p,
|
||||||
snapshot_size,
|
snapshot_size,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
@@ -654,7 +659,7 @@ main (int argc,
|
|||||||
for (int i = 0; i < files_counter; i++)
|
for (int i = 0; i < files_counter; i++)
|
||||||
{
|
{
|
||||||
size_t source_size;
|
size_t source_size;
|
||||||
const jerry_char_t *source_p = read_file (file_names[i], &source_size);
|
const jerry_char_t *source_p = (jerry_char_t *) read_file (file_names[i], &source_size);
|
||||||
|
|
||||||
if (source_p == NULL)
|
if (source_p == NULL)
|
||||||
{
|
{
|
||||||
@@ -670,7 +675,7 @@ main (int argc,
|
|||||||
|
|
||||||
if (jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) && (is_save_snapshot_mode || is_save_literals_mode))
|
if (jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) && (is_save_snapshot_mode || is_save_literals_mode))
|
||||||
{
|
{
|
||||||
static uint8_t snapshot_save_buffer[ JERRY_BUFFER_SIZE ];
|
static uint32_t snapshot_save_buffer[ JERRY_SNAPSHOT_BUFFER_SIZE ];
|
||||||
|
|
||||||
if (is_save_snapshot_mode)
|
if (is_save_snapshot_mode)
|
||||||
{
|
{
|
||||||
@@ -679,7 +684,7 @@ main (int argc,
|
|||||||
is_save_snapshot_mode_for_global_or_eval,
|
is_save_snapshot_mode_for_global_or_eval,
|
||||||
false,
|
false,
|
||||||
snapshot_save_buffer,
|
snapshot_save_buffer,
|
||||||
JERRY_BUFFER_SIZE);
|
JERRY_SNAPSHOT_BUFFER_SIZE);
|
||||||
if (snapshot_size == 0)
|
if (snapshot_size == 0)
|
||||||
{
|
{
|
||||||
ret_value = jerry_create_error (JERRY_ERROR_COMMON, (jerry_char_t *) "Snapshot saving failed!");
|
ret_value = jerry_create_error (JERRY_ERROR_COMMON, (jerry_char_t *) "Snapshot saving failed!");
|
||||||
@@ -698,7 +703,7 @@ main (int argc,
|
|||||||
source_size,
|
source_size,
|
||||||
false,
|
false,
|
||||||
snapshot_save_buffer,
|
snapshot_save_buffer,
|
||||||
JERRY_BUFFER_SIZE,
|
JERRY_SNAPSHOT_BUFFER_SIZE,
|
||||||
is_save_literals_mode_in_c_format_or_list);
|
is_save_literals_mode_in_c_format_or_list);
|
||||||
if (literal_buffer_size == 0)
|
if (literal_buffer_size == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
+14
-8
@@ -18,6 +18,11 @@
|
|||||||
|
|
||||||
#include "test-common.h"
|
#include "test-common.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum size of snapshots buffer
|
||||||
|
*/
|
||||||
|
#define SNAPSHOT_BUFFER_SIZE (256)
|
||||||
|
|
||||||
const char *test_source = (
|
const char *test_source = (
|
||||||
"function assert (arg) { "
|
"function assert (arg) { "
|
||||||
" if (!arg) { "
|
" if (!arg) { "
|
||||||
@@ -1026,8 +1031,8 @@ main (void)
|
|||||||
if (jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE)
|
if (jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE)
|
||||||
&& jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC))
|
&& jerry_is_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC))
|
||||||
{
|
{
|
||||||
static uint8_t global_mode_snapshot_buffer[1024];
|
static uint32_t global_mode_snapshot_buffer[SNAPSHOT_BUFFER_SIZE];
|
||||||
static uint8_t eval_mode_snapshot_buffer[1024];
|
static uint32_t eval_mode_snapshot_buffer[SNAPSHOT_BUFFER_SIZE];
|
||||||
|
|
||||||
const char *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
|
const char *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
|
||||||
|
|
||||||
@@ -1037,7 +1042,7 @@ main (void)
|
|||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
global_mode_snapshot_buffer,
|
global_mode_snapshot_buffer,
|
||||||
sizeof (global_mode_snapshot_buffer));
|
SNAPSHOT_BUFFER_SIZE);
|
||||||
TEST_ASSERT (global_mode_snapshot_size != 0);
|
TEST_ASSERT (global_mode_snapshot_size != 0);
|
||||||
jerry_cleanup ();
|
jerry_cleanup ();
|
||||||
|
|
||||||
@@ -1047,7 +1052,7 @@ main (void)
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
eval_mode_snapshot_buffer,
|
eval_mode_snapshot_buffer,
|
||||||
sizeof (eval_mode_snapshot_buffer));
|
SNAPSHOT_BUFFER_SIZE);
|
||||||
TEST_ASSERT (eval_mode_snapshot_size != 0);
|
TEST_ASSERT (eval_mode_snapshot_size != 0);
|
||||||
jerry_cleanup ();
|
jerry_cleanup ();
|
||||||
|
|
||||||
@@ -1088,14 +1093,14 @@ main (void)
|
|||||||
/* C format generation */
|
/* C format generation */
|
||||||
jerry_init (JERRY_INIT_EMPTY);
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
static jerry_char_t literal_buffer_c[256];
|
static uint32_t literal_buffer_c[SNAPSHOT_BUFFER_SIZE];
|
||||||
static const char *code_for_c_format_p = "var object = { aa:'fo o', Bb:'max', aaa:'xzy0' };";
|
static const char *code_for_c_format_p = "var object = { aa:'fo o', Bb:'max', aaa:'xzy0' };";
|
||||||
|
|
||||||
size_t literal_sizes_c_format = jerry_parse_and_save_literals ((jerry_char_t *) code_for_c_format_p,
|
size_t literal_sizes_c_format = jerry_parse_and_save_literals ((jerry_char_t *) code_for_c_format_p,
|
||||||
strlen (code_for_c_format_p),
|
strlen (code_for_c_format_p),
|
||||||
false,
|
false,
|
||||||
literal_buffer_c,
|
literal_buffer_c,
|
||||||
sizeof (literal_buffer_c),
|
SNAPSHOT_BUFFER_SIZE,
|
||||||
true);
|
true);
|
||||||
TEST_ASSERT (literal_sizes_c_format == 203);
|
TEST_ASSERT (literal_sizes_c_format == 203);
|
||||||
|
|
||||||
@@ -1123,15 +1128,16 @@ main (void)
|
|||||||
/* List format generation */
|
/* List format generation */
|
||||||
jerry_init (JERRY_INIT_EMPTY);
|
jerry_init (JERRY_INIT_EMPTY);
|
||||||
|
|
||||||
static jerry_char_t literal_buffer_list[256];
|
static uint32_t literal_buffer_list[SNAPSHOT_BUFFER_SIZE];
|
||||||
static const char *code_for_list_format_p = "var obj = { a:'aa', bb:'Bb' };";
|
static const char *code_for_list_format_p = "var obj = { a:'aa', bb:'Bb' };";
|
||||||
|
|
||||||
size_t literal_sizes_list_format = jerry_parse_and_save_literals ((jerry_char_t *) code_for_list_format_p,
|
size_t literal_sizes_list_format = jerry_parse_and_save_literals ((jerry_char_t *) code_for_list_format_p,
|
||||||
strlen (code_for_list_format_p),
|
strlen (code_for_list_format_p),
|
||||||
false,
|
false,
|
||||||
literal_buffer_list,
|
literal_buffer_list,
|
||||||
sizeof (literal_buffer_list),
|
SNAPSHOT_BUFFER_SIZE,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
TEST_ASSERT (literal_sizes_list_format == 25);
|
TEST_ASSERT (literal_sizes_list_format == 25);
|
||||||
TEST_ASSERT (!strncmp ((char *) literal_buffer_list, "1 a\n2 Bb\n2 aa\n2 bb\n3 obj\n", literal_sizes_list_format));
|
TEST_ASSERT (!strncmp ((char *) literal_buffer_list, "1 a\n2 Bb\n2 aa\n2 bb\n3 obj\n", literal_sizes_list_format));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user