Skip to content

Commit b6940b4

Browse files
committed
Add feature to remove parser.
Remove the parser so we can save space if we are only interested in running snapshots. Removing the parser enables the snapshot execution. JerryScript-DCO-1.0-Signed-off-by: Sergio Martinez [email protected]
1 parent 4f8b772 commit b6940b4

File tree

10 files changed

+56
-1
lines changed

10 files changed

+56
-1
lines changed

jerry-core/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(FEATURE_CPOINTER_32_BIT OFF CACHE BOOL "Enable 32 bit compressed pointe
2121
set(FEATURE_ERROR_MESSAGES OFF CACHE BOOL "Enable error messages?")
2222
set(FEATURE_MEM_STATS OFF CACHE BOOL "Enable memory statistics?")
2323
set(FEATURE_MEM_STRESS_TEST OFF CACHE BOOL "Enable mem-stress test?")
24+
set(FEATURE_PARSER_DISABLE OFF CACHE BOOL "Disable the parser and 'eval' and use only snapshots?")
2425
set(FEATURE_PARSER_DUMP OFF CACHE BOOL "Enable parser byte-code dumps?")
2526
set(FEATURE_PROFILE "es5.1" CACHE STRING "Profile types: es5.1, minimal, es2015-subset")
2627
set(FEATURE_REGEXP_DUMP OFF CACHE BOOL "Enable regexp byte-code dumps?")
@@ -35,6 +36,7 @@ message(STATUS "FEATURE_CPOINTER_32_BIT " ${FEATURE_CPOINTER_32_BIT})
3536
message(STATUS "FEATURE_ERROR_MESSAGES " ${FEATURE_ERROR_MESSAGES})
3637
message(STATUS "FEATURE_MEM_STATS " ${FEATURE_MEM_STATS})
3738
message(STATUS "FEATURE_MEM_STRESS_TEST " ${FEATURE_MEM_STRESS_TEST})
39+
message(STATUS "FEATURE_PARSER_DISABLE " ${FEATURE_PARSER_DISABLE})
3840
message(STATUS "FEATURE_PARSER_DUMP " ${FEATURE_PARSER_DUMP})
3941
message(STATUS "FEATURE_PROFILE " ${FEATURE_PROFILE})
4042
message(STATUS "FEATURE_REGEXP_DUMP " ${FEATURE_REGEXP_DUMP})
@@ -142,6 +144,15 @@ if(FEATURE_MEM_STRESS_TEST)
142144
set(DEFINES_JERRY ${DEFINES_JERRY} JMEM_GC_BEFORE_EACH_ALLOC)
143145
endif()
144146

147+
# Disable parser and enable snapshots
148+
if(FEATURE_PARSER_DISABLE)
149+
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_DISABLE_PARSER)
150+
if(NOT FEATURE_SNAPSHOT_EXEC MATCHES ON)
151+
set(FEATURE_SNAPSHOT_EXEC ON)
152+
message(STATUS "Parser has been disabled, snapshot is now on")
153+
endif()
154+
endif()
155+
145156
# Parser byte-code dumps
146157
if(FEATURE_PARSER_DUMP)
147158
set(DEFINES_JERRY ${DEFINES_JERRY} PARSER_DUMP_BYTE_CODE)

jerry-core/parser/js/byte-code.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "js-parser-internal.h"
1717

18+
#ifndef JERRY_DISABLE_PARSER
19+
1820
/** \addtogroup parser Parser
1921
* @{
2022
*
@@ -75,3 +77,5 @@ const char * const cbc_ext_names[] =
7577
* @}
7678
* @}
7779
*/
80+
81+
#endif /* !JERRY_DISABLE_PARSER */

jerry-core/parser/js/common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "common.h"
1717
#include "ecma-helpers.h"
1818

19+
#ifndef JERRY_DISABLE_PARSER
20+
1921
/** \addtogroup parser Parser
2022
* @{
2123
*
@@ -133,3 +135,5 @@ util_print_literal (lexer_literal_t *literal_p) /**< literal */
133135
* @}
134136
* @}
135137
*/
138+
139+
#endif /* !JERRY_DISABLE_PARSER */

jerry-core/parser/js/js-lexer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "js-parser-internal.h"
2121
#include "lit-char-helpers.h"
2222

23+
#ifndef JERRY_DISABLE_PARSER
24+
2325
/** \addtogroup parser Parser
2426
* @{
2527
*
@@ -2137,3 +2139,5 @@ lexer_compare_identifier_to_current (parser_context_t *context_p, /**< co
21372139
* @}
21382140
* @}
21392141
*/
2142+
2143+
#endif /* !JERRY_DISABLE_PARSER */

jerry-core/parser/js/js-parser-expr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "js-parser-internal.h"
1717

18+
#ifndef JERRY_DISABLE_PARSER
19+
1820
/** \addtogroup parser Parser
1921
* @{
2022
*
@@ -1528,3 +1530,5 @@ parser_parse_expression (parser_context_t *context_p, /**< context */
15281530
* @}
15291531
* @}
15301532
*/
1533+
1534+
#endif /* !JERRY_DISABLE_PARSER */

jerry-core/parser/js/js-parser-mem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "js-parser-internal.h"
1717

18+
#ifndef JERRY_DISABLE_PARSER
19+
1820
/** \addtogroup mem Memory allocation
1921
* @{
2022
*
@@ -675,3 +677,5 @@ parser_stack_iterator_write (parser_stack_iterator_t *iterator, /**< iterator */
675677
* @}
676678
* @}
677679
*/
680+
681+
#endif /* !JERRY_DISABLE_PARSER */

jerry-core/parser/js/js-parser-scanner.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "js-parser-internal.h"
1717

18+
#ifndef JERRY_DISABLE_PARSER
19+
1820
/** \addtogroup parser Parser
1921
* @{
2022
*
@@ -675,3 +677,5 @@ parser_scan_until (parser_context_t *context_p, /**< context */
675677
* @}
676678
* @}
677679
*/
680+
681+
#endif /* !JERRY_DISABLE_PARSER */

jerry-core/parser/js/js-parser-statm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "js-parser-internal.h"
1717

18+
#ifndef JERRY_DISABLE_PARSER
19+
1820
/** \addtogroup parser Parser
1921
* @{
2022
*
@@ -2143,3 +2145,5 @@ parser_free_jumps (parser_stack_iterator_t iterator) /**< iterator position */
21432145
* @}
21442146
* @}
21452147
*/
2148+
2149+
#endif /* !JERRY_DISABLE_PARSER */

jerry-core/parser/js/js-parser-util.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "js-parser-internal.h"
1717

18+
#ifndef JERRY_DISABLE_PARSER
19+
1820
/** \addtogroup parser Parser
1921
* @{
2022
*
@@ -937,3 +939,5 @@ parser_error_to_string (parser_error_t error) /**< error code */
937939
* @}
938940
* @}
939941
*/
942+
943+
#endif /* !JERRY_DISABLE_PARSER */

jerry-core/parser/js/js-parser.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "jcontext.h"
2020
#include "js-parser-internal.h"
2121

22+
#ifndef JERRY_DISABLE_PARSER
23+
2224
/** \addtogroup parser Parser
2325
* @{
2426
*
@@ -2228,6 +2230,8 @@ parser_raise_error (parser_context_t *context_p, /**< context */
22282230
#define PARSE_ERR_POS_END "]"
22292231
#define PARSE_ERR_POS_END_SIZE ((uint32_t) sizeof (PARSE_ERR_POS_END))
22302232

2233+
#endif /* !JERRY_DISABLE_PARSER */
2234+
22312235
/**
22322236
* Parse EcamScript source code
22332237
*
@@ -2243,6 +2247,7 @@ parser_parse_script (const uint8_t *source_p, /**< source code */
22432247
bool is_strict, /**< strict mode */
22442248
ecma_compiled_code_t **bytecode_data_p) /**< [out] JS bytecode */
22452249
{
2250+
#ifndef JERRY_DISABLE_PARSER
22462251
parser_error_location_t parser_error;
22472252
*bytecode_data_p = parser_parse_source (source_p, size, is_strict, &parser_error);
22482253

@@ -2305,8 +2310,15 @@ parser_parse_script (const uint8_t *source_p, /**< source code */
23052310
return ecma_raise_syntax_error ("");
23062311
#endif /* JERRY_ENABLE_ERROR_MESSAGES */
23072312
}
2308-
23092313
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
2314+
#else /* !JERRY_DISABLE_PARSER */
2315+
JERRY_UNUSED (source_p);
2316+
JERRY_UNUSED (size);
2317+
JERRY_UNUSED (is_strict);
2318+
JERRY_UNUSED (bytecode_data_p);
2319+
2320+
return ecma_raise_syntax_error (ECMA_ERR_MSG ("The parser has been disabled."));
2321+
#endif /* JERRY_DISABLE_PARSER */
23102322
} /* parser_parse_script */
23112323

23122324
/**

0 commit comments

Comments
 (0)