aboutsummaryrefslogtreecommitdiff
path: root/jerry-main
diff options
context:
space:
mode:
authorZoltan Herczeg <zherczeg.u-szeged@partner.samsung.com>2018-03-19 23:46:52 +0100
committeryichoi <duddlf.choi@samsung.com>2018-03-20 07:46:52 +0900
commitbb84466fcf7928abd8cefcc09b2ef95235df1f59 (patch)
tree5771066dd29a28e07830300996fe560fc7e58e38 /jerry-main
parentdde09cc4b681e1ad8022e342ff7df6c4cda1a59a (diff)
Support static snapshots. (#2239)
Unlike normal snapshots, no part of a static snapshot is loaded into the RAM when executed from ROM. Static snapshots rely heavily on external magic strings. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
Diffstat (limited to 'jerry-main')
-rw-r--r--jerry-main/main-unix-snapshot.c90
1 files changed, 57 insertions, 33 deletions
diff --git a/jerry-main/main-unix-snapshot.c b/jerry-main/main-unix-snapshot.c
index e5faaf5b..94ee4c53 100644
--- a/jerry-main/main-unix-snapshot.c
+++ b/jerry-main/main-unix-snapshot.c
@@ -126,10 +126,11 @@ read_file (uint8_t *input_pos_p, /**< next position in the input buffer */
typedef enum
{
OPT_GENERATE_HELP,
+ OPT_GENERATE_STATIC,
OPT_GENERATE_CONTEXT,
- OPT_GENERATE_SHOW_OP,
OPT_GENERATE_LITERAL_LIST,
OPT_GENERATE_LITERAL_C,
+ OPT_GENERATE_SHOW_OP,
OPT_GENERATE_OUT,
} generate_opt_id_t;
@@ -140,8 +141,8 @@ static const cli_opt_t generate_opts[] =
{
CLI_OPT_DEF (.id = OPT_GENERATE_HELP, .opt = "h", .longopt = "help",
.help = "print this help and exit"),
- CLI_OPT_DEF (.id = OPT_GENERATE_SHOW_OP, .longopt = "show-opcodes",
- .help = "print generated opcodes"),
+ CLI_OPT_DEF (.id = OPT_GENERATE_STATIC, .opt = "s", .longopt = "static",
+ .help = "generate static snapshot"),
CLI_OPT_DEF (.id = OPT_GENERATE_CONTEXT, .opt = "c", .longopt = "context",
.meta = "MODE",
.help = "specify the execution context of the snapshot: "
@@ -152,6 +153,8 @@ static const cli_opt_t generate_opts[] =
CLI_OPT_DEF (.id = OPT_GENERATE_LITERAL_C, .longopt = "save-literals-c-format",
.meta = "FILE",
.help = "export literals found in parsed JS input (in C source format)"),
+ CLI_OPT_DEF (.id = OPT_GENERATE_SHOW_OP, .longopt = "show-opcodes",
+ .help = "print generated opcodes"),
CLI_OPT_DEF (.id = OPT_GENERATE_OUT, .opt = "o", .meta="FILE",
.help = "specify output file name (default: js.snapshot)"),
CLI_OPT_DEF (.id = CLI_OPT_DEFAULT, .meta = "FILE",
@@ -178,6 +181,7 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */
uint8_t *source_p = input_buffer;
size_t source_length = 0;
const char *save_literals_file_name_p = NULL;
+ bool static_snapshot = false;
cli_change_opts (cli_state_p, generate_opts);
@@ -190,9 +194,33 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */
cli_help (prog_name_p, "generate", generate_opts);
return JERRY_STANDALONE_EXIT_CODE_OK;
}
- case OPT_GENERATE_OUT:
+ case OPT_GENERATE_STATIC:
{
- output_file_name_p = cli_consume_string (cli_state_p);
+ static_snapshot = true;
+ break;
+ }
+ case OPT_GENERATE_CONTEXT:
+ {
+ const char *mode_str_p = cli_consume_string (cli_state_p);
+
+ if (cli_state_p->error != NULL)
+ {
+ break;
+ }
+
+ if (!strcmp ("global", mode_str_p))
+ {
+ is_snapshot_mode_for_global = true;
+ }
+ else if (!strcmp ("eval", mode_str_p))
+ {
+ is_snapshot_mode_for_global = false;
+ }
+ else
+ {
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Incorrect argument for context mode: %s\n", mode_str_p);
+ return JERRY_STANDALONE_EXIT_CODE_FAIL;
+ }
break;
}
case OPT_GENERATE_LITERAL_LIST:
@@ -217,28 +245,9 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */
}
break;
}
- case OPT_GENERATE_CONTEXT:
+ case OPT_GENERATE_OUT:
{
- const char *mode_str_p = cli_consume_string (cli_state_p);
-
- if (cli_state_p->error != NULL)
- {
- break;
- }
-
- if (!strcmp ("global", mode_str_p))
- {
- is_snapshot_mode_for_global = true;
- }
- else if (!strcmp ("eval", mode_str_p))
- {
- is_snapshot_mode_for_global = false;
- }
- else
- {
- jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Incorrect argument for context mode: %s\n", mode_str_p);
- return JERRY_STANDALONE_EXIT_CODE_FAIL;
- }
+ output_file_name_p = cli_consume_string (cli_state_p);
break;
}
case CLI_OPT_DEFAULT:
@@ -274,7 +283,7 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */
if (number_of_files != 1)
{
- jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: No input file specified!\n");
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: Exactly one input file must be specified\n");
return JERRY_STANDALONE_EXIT_CODE_FAIL;
}
@@ -286,12 +295,27 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */
return JERRY_STANDALONE_EXIT_CODE_FAIL;
}
- size_t snapshot_size = jerry_parse_and_save_snapshot ((jerry_char_t *) source_p,
- source_length,
- is_snapshot_mode_for_global,
- false,
- output_buffer,
- sizeof (output_buffer) / sizeof (uint32_t));
+ size_t snapshot_size;
+
+ if (static_snapshot)
+ {
+ snapshot_size = jerry_parse_and_save_static_snapshot ((jerry_char_t *) source_p,
+ source_length,
+ is_snapshot_mode_for_global,
+ false,
+ output_buffer,
+ sizeof (output_buffer) / sizeof (uint32_t));
+ }
+ else
+ {
+ snapshot_size = jerry_parse_and_save_snapshot ((jerry_char_t *) source_p,
+ source_length,
+ is_snapshot_mode_for_global,
+ false,
+ output_buffer,
+ sizeof (output_buffer) / sizeof (uint32_t));
+ }
+
if (snapshot_size == 0)
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: Generating snapshot failed!\n");