1515
1616#include < stdio.h>
1717
18+ #include " bytecode-data.h"
1819#include " ecma-alloc.h"
1920#include " ecma-array-object.h"
2021#include " ecma-builtins.h"
2728#include " ecma-objects.h"
2829#include " ecma-objects-general.h"
2930#include " ecma-try-catch-macro.h"
31+ #include " lit-literal.h"
3032#include " lit-magic-strings.h"
3133#include " parser.h"
32- #include " serializer.h"
3334
3435#define JERRY_INTERNAL
3536#include " jerry-internal.h"
@@ -1420,7 +1421,7 @@ jerry_init (jerry_flag_t flags) /**< combination of Jerry flags */
14201421 jerry_make_api_available ();
14211422
14221423 mem_init ();
1423- serializer_init ();
1424+ lit_init ();
14241425 ecma_init ();
14251426} /* jerry_init */
14261427
@@ -1435,7 +1436,8 @@ jerry_cleanup (void)
14351436 bool is_show_mem_stats = ((jerry_flags & JERRY_FLAG_MEM_STATS) != 0 );
14361437
14371438 ecma_finalize ();
1438- serializer_free ();
1439+ lit_finalize ();
1440+ bc_finalize ();
14391441 mem_finalize (is_show_mem_stats);
14401442 vm_finalize ();
14411443} /* jerry_cleanup */
@@ -1684,11 +1686,11 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
16841686
16851687 size_t header_offset = buffer_write_offset;
16861688
1687- if (buffer_write_offset + sizeof (jerry_snapshot_header_t ) > buffer_size)
1689+ if (buffer_write_offset + JERRY_ALIGNUP ( sizeof (jerry_snapshot_header_t ), MEM_ALIGNMENT ) > buffer_size)
16881690 {
16891691 return 0 ;
16901692 }
1691- buffer_write_offset += sizeof (jerry_snapshot_header_t );
1693+ buffer_write_offset += JERRY_ALIGNUP ( sizeof (jerry_snapshot_header_t ), MEM_ALIGNMENT );
16921694
16931695 lit_mem_to_snapshot_id_map_entry_t * lit_map_p = NULL ;
16941696 uint32_t literals_num;
@@ -1704,17 +1706,21 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
17041706 return 0 ;
17051707 }
17061708
1707- size_t bytecode_offset = sizeof (version) + sizeof (jerry_snapshot_header_t ) + header.lit_table_size ;
1709+ size_t bytecode_offset = (sizeof (version)
1710+ + JERRY_ALIGNUP (sizeof (jerry_snapshot_header_t ), MEM_ALIGNMENT)
1711+ + header.lit_table_size );
1712+
17081713 JERRY_ASSERT (JERRY_ALIGNUP (bytecode_offset, MEM_ALIGNMENT) == bytecode_offset);
17091714
1710- bool is_ok = serializer_dump_bytecode_with_idx_map (buffer_p,
1711- buffer_size,
1712- &buffer_write_offset,
1713- bytecode_data_p,
1714- lit_map_p,
1715- literals_num,
1716- &header.bytecode_size ,
1717- &header.idx_to_lit_map_size );
1715+ bool is_ok = bc_save_bytecode_data (buffer_p,
1716+ buffer_size,
1717+ &buffer_write_offset,
1718+ bytecode_data_p,
1719+ lit_map_p,
1720+ literals_num,
1721+ &header.scopes_num );
1722+
1723+ JERRY_ASSERT (header.scopes_num != 0 );
17181724
17191725 if (lit_map_p != NULL )
17201726 {
@@ -1782,12 +1788,12 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
17821788 }
17831789
17841790 const jerry_snapshot_header_t *header_p = (const jerry_snapshot_header_t *) (snapshot_data_p + snapshot_read);
1785- if (snapshot_read + sizeof (jerry_snapshot_header_t ) > snapshot_size)
1791+ if (snapshot_read + JERRY_ALIGNUP ( sizeof (jerry_snapshot_header_t ), MEM_ALIGNMENT ) > snapshot_size)
17861792 {
17871793 return JERRY_COMPLETION_CODE_INVALID_SNAPSHOT_FORMAT;
17881794 }
17891795
1790- snapshot_read += sizeof (jerry_snapshot_header_t );
1796+ snapshot_read += JERRY_ALIGNUP ( sizeof (jerry_snapshot_header_t ), MEM_ALIGNMENT );
17911797
17921798 if (snapshot_read + header_p->lit_table_size > snapshot_size)
17931799 {
@@ -1809,19 +1815,19 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
18091815
18101816 snapshot_read += header_p->lit_table_size ;
18111817
1812- if (snapshot_read + header_p-> bytecode_size + header_p-> idx_to_lit_map_size > snapshot_size)
1818+ if (snapshot_read > snapshot_size)
18131819 {
18141820 mem_heap_free_block (lit_map_p);
18151821 return JERRY_COMPLETION_CODE_INVALID_SNAPSHOT_FORMAT;
18161822 }
18171823
18181824 const bytecode_data_header_t *bytecode_data_p;
1819- bytecode_data_p = serializer_load_bytecode_with_idx_map (snapshot_data_p + snapshot_read,
1820- header_p-> bytecode_size ,
1821- header_p-> idx_to_lit_map_size ,
1822- lit_map_p ,
1823- literals_num ,
1824- is_copy );
1825+ bytecode_data_p = bc_load_bytecode_data (snapshot_data_p + snapshot_read,
1826+ snapshot_size - snapshot_read ,
1827+ lit_map_p ,
1828+ literals_num ,
1829+ is_copy ,
1830+ header_p-> scopes_num );
18251831
18261832 if (lit_map_p != NULL )
18271833 {
0 commit comments