@@ -1259,7 +1259,7 @@ jerry_merge_snapshots (const uint32_t **inp_buffers_p, /**< array of (pointers t
1259
1259
functions_size += header_p -> lit_table_offset - start_offset ;
1260
1260
1261
1261
scan_snapshot_functions (data_p + start_offset ,
1262
- data_p + header_p -> lit_table_offset ,
1262
+ literal_base_p ,
1263
1263
lit_pool_p ,
1264
1264
literal_base_p );
1265
1265
}
@@ -1582,48 +1582,44 @@ ecma_string_is_valid_identifier (const ecma_string_t *string_p)
1582
1582
#endif /* JERRY_ENABLE_SNAPSHOT_SAVE */
1583
1583
1584
1584
/**
1585
- * Copy certain string literals into the given buffer in a specified format,
1586
- * which are valid identifiers and none of them are magic string.
1585
+ * Get the literals from a snapshot. Copies certain string literals into the given
1586
+ * buffer in a specified format.
1587
+ *
1588
+ * Note:
1589
+ * Only valid identifiers are saved in C format.
1587
1590
*
1588
1591
* @return size of the literal-list in bytes, at most equal to the buffer size,
1589
- * if the source parsed successfully and the list of the literals isn't empty,
1592
+ * if the list of the literals isn't empty,
1590
1593
* 0 - otherwise.
1591
1594
*/
1592
1595
size_t
1593
- jerry_parse_and_save_literals (const jerry_char_t * source_p , /**< script source */
1594
- size_t source_size , /**< script source size */
1595
- bool is_strict , /**< strict mode */
1596
- uint32_t * buffer_p , /**< [out] buffer to save literals to */
1597
- size_t buffer_size , /**< the buffer's size */
1598
- bool is_c_format ) /**< format-flag */
1596
+ jerry_get_literals_from_snapshot (const uint32_t * snapshot_p , /**< input snapshot buffer */
1597
+ size_t snapshot_size , /**< size of the input snapshot buffer */
1598
+ jerry_char_t * lit_buf_p , /**< [out] buffer to save literals to */
1599
+ size_t lit_buf_size , /**< the buffer's size */
1600
+ bool is_c_format ) /**< format-flag */
1599
1601
{
1600
1602
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
1601
- ecma_value_t parse_status ;
1602
- ecma_compiled_code_t * bytecode_data_p ;
1603
-
1604
- #ifdef JERRY_ENABLE_LINE_INFO
1605
- JERRY_CONTEXT (resource_name ) = ECMA_VALUE_UNDEFINED ;
1606
- #endif /* JERRY_ENABLE_LINE_INFO */
1607
-
1608
- parse_status = parser_parse_script (NULL ,
1609
- 0 ,
1610
- source_p ,
1611
- source_size ,
1612
- is_strict ,
1613
- & bytecode_data_p );
1603
+ const uint8_t * snapshot_data_p = (uint8_t * ) snapshot_p ;
1604
+ const jerry_snapshot_header_t * header_p = (const jerry_snapshot_header_t * ) snapshot_data_p ;
1614
1605
1615
- if (ECMA_IS_VALUE_ERROR (parse_status ))
1606
+ if (snapshot_size <= sizeof (jerry_snapshot_header_t )
1607
+ || header_p -> magic != JERRY_SNAPSHOT_MAGIC
1608
+ || header_p -> version != JERRY_SNAPSHOT_VERSION
1609
+ || !snapshot_check_global_flags (header_p -> global_flags ))
1616
1610
{
1617
- ecma_free_value ( JERRY_CONTEXT ( error_value ));
1611
+ /* Invalid snapshot format */
1618
1612
return 0 ;
1619
1613
}
1620
1614
1621
- ecma_free_value (parse_status );
1615
+ JERRY_ASSERT ((header_p -> lit_table_offset % sizeof (uint32_t )) == 0 );
1616
+ const uint8_t * literal_base_p = snapshot_data_p + header_p -> lit_table_offset ;
1622
1617
1623
1618
ecma_collection_header_t * lit_pool_p = ecma_new_values_collection ();
1624
- ecma_save_literals_add_compiled_code (bytecode_data_p , lit_pool_p );
1625
-
1626
- ecma_bytecode_deref (bytecode_data_p );
1619
+ scan_snapshot_functions (snapshot_data_p + header_p -> func_offsets [0 ],
1620
+ literal_base_p ,
1621
+ lit_pool_p ,
1622
+ literal_base_p );
1627
1623
1628
1624
lit_utf8_size_t literal_count = 0 ;
1629
1625
ecma_value_t * iterator_p = ecma_collection_iterator_init (lit_pool_p );
@@ -1657,10 +1653,8 @@ jerry_parse_and_save_literals (const jerry_char_t *source_p, /**< script source
1657
1653
return 0 ;
1658
1654
}
1659
1655
1660
- uint8_t * destination_p = (uint8_t * ) buffer_p ;
1661
-
1662
- uint8_t * const buffer_start_p = destination_p ;
1663
- uint8_t * const buffer_end_p = destination_p + buffer_size ;
1656
+ jerry_char_t * const buffer_start_p = lit_buf_p ;
1657
+ jerry_char_t * const buffer_end_p = lit_buf_p + lit_buf_size ;
1664
1658
1665
1659
JMEM_DEFINE_LOCAL_ARRAY (literal_array , literal_count , ecma_string_t * );
1666
1660
lit_utf8_size_t literal_idx = 0 ;
@@ -1697,43 +1691,43 @@ jerry_parse_and_save_literals (const jerry_char_t *source_p, /**< script source
1697
1691
if (is_c_format )
1698
1692
{
1699
1693
/* Save literal count. */
1700
- destination_p = jerry_append_chars_to_buffer (destination_p ,
1701
- buffer_end_p ,
1702
- "jerry_length_t literal_count = " ,
1703
- 0 );
1694
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p ,
1695
+ buffer_end_p ,
1696
+ "jerry_length_t literal_count = " ,
1697
+ 0 );
1704
1698
1705
- destination_p = jerry_append_number_to_buffer (destination_p , buffer_end_p , literal_count );
1699
+ lit_buf_p = jerry_append_number_to_buffer (lit_buf_p , buffer_end_p , literal_count );
1706
1700
1707
1701
/* Save the array of literals. */
1708
- destination_p = jerry_append_chars_to_buffer (destination_p ,
1709
- buffer_end_p ,
1710
- ";\n\njerry_char_t *literals[" ,
1711
- 0 );
1702
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p ,
1703
+ buffer_end_p ,
1704
+ ";\n\njerry_char_t *literals[" ,
1705
+ 0 );
1712
1706
1713
- destination_p = jerry_append_number_to_buffer (destination_p , buffer_end_p , literal_count );
1714
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , "] =\n{\n" , 0 );
1707
+ lit_buf_p = jerry_append_number_to_buffer (lit_buf_p , buffer_end_p , literal_count );
1708
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , "] =\n{\n" , 0 );
1715
1709
1716
1710
for (lit_utf8_size_t i = 0 ; i < literal_count ; i ++ )
1717
1711
{
1718
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , " \"" , 0 );
1719
- destination_p = jerry_append_ecma_string_to_buffer (destination_p , buffer_end_p , literal_array [i ]);
1720
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , "\"" , 0 );
1712
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , " \"" , 0 );
1713
+ lit_buf_p = jerry_append_ecma_string_to_buffer (lit_buf_p , buffer_end_p , literal_array [i ]);
1714
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , "\"" , 0 );
1721
1715
1722
1716
if (i < literal_count - 1 )
1723
1717
{
1724
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , "," , 0 );
1718
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , "," , 0 );
1725
1719
}
1726
1720
1727
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , "\n" , 0 );
1721
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , "\n" , 0 );
1728
1722
}
1729
1723
1730
- destination_p = jerry_append_chars_to_buffer (destination_p ,
1731
- buffer_end_p ,
1732
- "};\n\njerry_length_t literal_sizes[" ,
1733
- 0 );
1724
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p ,
1725
+ buffer_end_p ,
1726
+ "};\n\njerry_length_t literal_sizes[" ,
1727
+ 0 );
1734
1728
1735
- destination_p = jerry_append_number_to_buffer (destination_p , buffer_end_p , literal_count );
1736
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , "] =\n{\n" , 0 );
1729
+ lit_buf_p = jerry_append_number_to_buffer (lit_buf_p , buffer_end_p , literal_count );
1730
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , "] =\n{\n" , 0 );
1737
1731
}
1738
1732
1739
1733
/* Save the literal sizes respectively. */
@@ -1743,51 +1737,51 @@ jerry_parse_and_save_literals (const jerry_char_t *source_p, /**< script source
1743
1737
1744
1738
if (is_c_format )
1745
1739
{
1746
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , " " , 0 );
1740
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , " " , 0 );
1747
1741
}
1748
1742
1749
- destination_p = jerry_append_number_to_buffer (destination_p , buffer_end_p , str_size );
1750
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , " " , 0 );
1743
+ lit_buf_p = jerry_append_number_to_buffer (lit_buf_p , buffer_end_p , str_size );
1744
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , " " , 0 );
1751
1745
1752
1746
if (is_c_format )
1753
1747
{
1754
1748
/* Show the given string as a comment. */
1755
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , "/* " , 0 );
1756
- destination_p = jerry_append_ecma_string_to_buffer (destination_p , buffer_end_p , literal_array [i ]);
1757
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , " */" , 0 );
1749
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , "/* " , 0 );
1750
+ lit_buf_p = jerry_append_ecma_string_to_buffer (lit_buf_p , buffer_end_p , literal_array [i ]);
1751
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , " */" , 0 );
1758
1752
1759
1753
if (i < literal_count - 1 )
1760
1754
{
1761
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , "," , 0 );
1755
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , "," , 0 );
1762
1756
}
1763
1757
}
1764
1758
else
1765
1759
{
1766
- destination_p = jerry_append_ecma_string_to_buffer (destination_p , buffer_end_p , literal_array [i ]);
1760
+ lit_buf_p = jerry_append_ecma_string_to_buffer (lit_buf_p , buffer_end_p , literal_array [i ]);
1767
1761
}
1768
1762
1769
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , "\n" , 0 );
1763
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , "\n" , 0 );
1770
1764
}
1771
1765
1772
1766
if (is_c_format )
1773
1767
{
1774
- destination_p = jerry_append_chars_to_buffer (destination_p , buffer_end_p , "};\n" , 0 );
1768
+ lit_buf_p = jerry_append_chars_to_buffer (lit_buf_p , buffer_end_p , "};\n" , 0 );
1775
1769
}
1776
1770
1777
1771
JMEM_FINALIZE_LOCAL_ARRAY (literal_array );
1778
1772
1779
- return destination_p <= buffer_end_p ? (size_t ) (destination_p - buffer_start_p ) : 0 ;
1773
+ return lit_buf_p <= buffer_end_p ? (size_t ) (lit_buf_p - buffer_start_p ) : 0 ;
1780
1774
#else /* !JERRY_ENABLE_SNAPSHOT_SAVE */
1781
- JERRY_UNUSED (source_p );
1782
- JERRY_UNUSED (source_size );
1783
- JERRY_UNUSED (is_strict );
1784
- JERRY_UNUSED (buffer_p );
1785
- JERRY_UNUSED (buffer_size );
1775
+ JERRY_UNUSED (snapshot_p );
1776
+ JERRY_UNUSED (snapshot_size );
1777
+ JERRY_UNUSED (lit_buf_p );
1778
+ JERRY_UNUSED (lit_buf_size );
1786
1779
JERRY_UNUSED (is_c_format );
1787
1780
1788
1781
return 0 ;
1789
1782
#endif /* JERRY_ENABLE_SNAPSHOT_SAVE */
1790
- } /* jerry_parse_and_save_literals */
1783
+ } /* jerry_get_literals_from_snapshot */
1784
+
1791
1785
1792
1786
/**
1793
1787
* Generate snapshot function from specified source and arguments
0 commit comments