Skip to content

Commit db062ac

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 0511091 commit db062ac

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

jerry-core/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ set(FEATURE_PARSER_DUMP OFF CACHE BOOL "Enable parser byte-code dumps?"
2828
set(FEATURE_REGEXP_DUMP OFF CACHE BOOL "Enable regexp byte-code dumps?")
2929
set(FEATURE_SNAPSHOT_SAVE OFF CACHE BOOL "Enable saving snapshot files?")
3030
set(FEATURE_SNAPSHOT_EXEC OFF CACHE BOOL "Enable executing snapshot files?")
31+
set(FEATURE_PARSER_DISABLE OFF CACHE BOOL "Disable the parser and 'eval' and use only snapshots?")
3132
set(MEM_HEAP_SIZE_KB "512" CACHE STRING "Size of memory heap, in kilobytes")
3233

3334
# Status messages
@@ -42,6 +43,7 @@ message(STATUS "FEATURE_PARSER_DUMP " ${FEATURE_PARSER_DUMP})
4243
message(STATUS "FEATURE_REGEXP_DUMP " ${FEATURE_REGEXP_DUMP})
4344
message(STATUS "FEATURE_SNAPSHOT_SAVE " ${FEATURE_SNAPSHOT_SAVE})
4445
message(STATUS "FEATURE_SNAPSHOT_EXEC " ${FEATURE_SNAPSHOT_EXEC})
46+
message(STATUS "FEATURE_PARSER_DISABLE " ${FEATURE_PARSER_DISABLE})
4547
message(STATUS "MEM_HEAP_SIZE_KB " ${MEM_HEAP_SIZE_KB})
4648

4749
# Include directories
@@ -140,6 +142,12 @@ elseif(NOT FEATURE_PROFILE STREQUAL "es2015-subset")
140142
message(FATAL_ERROR "FEATURE_PROFILE='${FEATURE_PROFILE}' isn't supported")
141143
endif()
142144

145+
# Disable parser and enable snapshots
146+
if(FEATURE_PARSER_DISABLE)
147+
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_DISABLE_PARSER)
148+
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ENABLE_SNAPSHOT_EXEC)
149+
endif()
150+
143151
# Jerry heap-section
144152
if(DEFINED JERRY_HEAP_SECTION_ATTR)
145153
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_HEAP_SECTION_ATTR=${JERRY_HEAP_SECTION_ATTR})

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 ("");
2321+
#endif /* JERRY_DISABLE_PARSER */
23102322
} /* parser_parse_script */
23112323

23122324
/**

0 commit comments

Comments
 (0)