diff --git a/jerry-main/main-unix-snapshot.c b/jerry-main/main-unix-snapshot.c index af66e2626..244f7ee62 100644 --- a/jerry-main/main-unix-snapshot.c +++ b/jerry-main/main-unix-snapshot.c @@ -198,6 +198,7 @@ typedef enum OPT_GENERATE_HELP, OPT_GENERATE_STATIC, OPT_GENERATE_SHOW_OP, + OPT_GENERATE_FUNCTION, OPT_GENERATE_OUT, OPT_IMPORT_LITERAL_LIST } generate_opt_id_t; @@ -211,6 +212,9 @@ static const cli_opt_t generate_opts[] = .help = "print this help and exit"), CLI_OPT_DEF (.id = OPT_GENERATE_STATIC, .opt = "s", .longopt = "static", .help = "generate static snapshot"), + CLI_OPT_DEF (.id = OPT_GENERATE_FUNCTION, .opt = "f", .longopt = "generate-function-snapshot", + .meta = "ARGUMENTS", + .help = "generate function snapshot with given arguments"), CLI_OPT_DEF (.id = OPT_IMPORT_LITERAL_LIST, .longopt = "load-literals-list-format", .meta = "FILE", .help = "import literals from list format (for static snapshots)"), @@ -241,6 +245,7 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */ uint8_t *source_p = input_buffer; size_t source_length = 0; const char *literals_file_name_p = NULL; + const char *function_args_p = NULL; cli_change_opts (cli_state_p, generate_opts); @@ -258,6 +263,11 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */ snapshot_flags |= JERRY_SNAPSHOT_SAVE_STATIC; break; } + case OPT_GENERATE_FUNCTION: + { + function_args_p = cli_consume_string (cli_state_p); + break; + } case OPT_IMPORT_LITERAL_LIST: { literals_file_name_p = cli_consume_string (cli_state_p); @@ -365,13 +375,29 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */ } jerry_value_t snapshot_result; - snapshot_result = jerry_generate_snapshot ((jerry_char_t *) file_name_p, - (size_t) strlen (file_name_p), - (jerry_char_t *) source_p, - source_length, - snapshot_flags, - output_buffer, - sizeof (output_buffer) / sizeof (uint32_t)); + + if (function_args_p != NULL) + { + snapshot_result = jerry_generate_function_snapshot ((jerry_char_t *) file_name_p, + (size_t) strlen (file_name_p), + (jerry_char_t *) source_p, + source_length, + (const jerry_char_t *) function_args_p, + strlen (function_args_p), + snapshot_flags, + output_buffer, + sizeof (output_buffer) / sizeof (uint32_t)); + } + else + { + snapshot_result = jerry_generate_snapshot ((jerry_char_t *) file_name_p, + (size_t) strlen (file_name_p), + (jerry_char_t *) source_p, + source_length, + snapshot_flags, + output_buffer, + sizeof (output_buffer) / sizeof (uint32_t)); + } if (jerry_value_is_error (snapshot_result)) {