Replace vera++ with clang-format (#4518)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik robert.fancsik@h-lab.eu
This commit is contained in:
@@ -40,8 +40,8 @@ int gettimeofday (struct timeval *, void *);
|
||||
* Useless but stable gettimeofday implementation. Returns Epoch. Ensures that
|
||||
* test cases relying on "now" yield stable results.
|
||||
*/
|
||||
int gettimeofday (struct timeval *tv,
|
||||
void *tz)
|
||||
int
|
||||
gettimeofday (struct timeval *tv, void *tz)
|
||||
{
|
||||
(void) tz;
|
||||
tv->tv_sec = 0;
|
||||
@@ -56,7 +56,8 @@ int rand (void);
|
||||
* Useless but stable rand implementation. Returns 4. Ensures that test cases
|
||||
* relying on randomness yield stable results.
|
||||
*/
|
||||
int rand (void)
|
||||
int
|
||||
rand (void)
|
||||
{
|
||||
return 4; /* Chosen by fair dice roll. Guaranteed to be random. */
|
||||
} /* rand */
|
||||
|
||||
+6
-14
@@ -13,11 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
/*
|
||||
* Fixed layout settings
|
||||
*/
|
||||
@@ -46,10 +46,10 @@
|
||||
* @param PROGNAME string containing the name of the program.
|
||||
* @param CMD string continaing the name of the sub-command.
|
||||
*/
|
||||
#define CLI_CMD_NAME(CMDNAME, PROGNAME, CMD) \
|
||||
#define CLI_CMD_NAME(CMDNAME, PROGNAME, CMD) \
|
||||
char CMDNAME[strlen ((PROGNAME)) + strlen ((CMD)) + 2]; \
|
||||
strncpy (CMDNAME, (PROGNAME), strlen ((PROGNAME))); \
|
||||
CMDNAME[strlen ((PROGNAME))] = ' '; \
|
||||
strncpy (CMDNAME, (PROGNAME), strlen ((PROGNAME))); \
|
||||
CMDNAME[strlen ((PROGNAME))] = ' '; \
|
||||
strncpy (CMDNAME + strlen ((PROGNAME)) + 1, (CMD), strlen ((CMD)) + 1)
|
||||
|
||||
/*
|
||||
@@ -66,15 +66,7 @@ cli_init (const cli_opt_t *options_p, /**< array of option definitions, terminat
|
||||
int argc, /**< number of command line arguments */
|
||||
char **argv) /**< array of command line arguments */
|
||||
{
|
||||
return (cli_state_t)
|
||||
{
|
||||
.error = NULL,
|
||||
.arg = NULL,
|
||||
.index = 1,
|
||||
.argc = argc,
|
||||
.argv = argv,
|
||||
.opts = options_p
|
||||
};
|
||||
return (cli_state_t){ .error = NULL, .arg = NULL, .index = 1, .argc = argc, .argv = argv, .opts = options_p };
|
||||
} /* cli_init */
|
||||
|
||||
/**
|
||||
|
||||
+6
-3
@@ -16,8 +16,8 @@
|
||||
#ifndef CLI_H
|
||||
#define CLI_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Command line option definition.
|
||||
@@ -62,7 +62,10 @@ typedef struct
|
||||
/**
|
||||
* Macro for writing command line option definition struct literals.
|
||||
*/
|
||||
#define CLI_OPT_DEF(...) /*(cli_opt_t)*/ { __VA_ARGS__ }
|
||||
#define CLI_OPT_DEF(...) /*(cli_opt_t)*/ \
|
||||
{ \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Functions for CLI.
|
||||
@@ -71,7 +74,7 @@ typedef struct
|
||||
cli_state_t cli_init (const cli_opt_t *options_p, int argc, char **argv);
|
||||
void cli_change_opts (cli_state_t *state_p, const cli_opt_t *options_p);
|
||||
int cli_consume_option (cli_state_t *state_p);
|
||||
const char * cli_consume_string (cli_state_t *state_p);
|
||||
const char *cli_consume_string (cli_state_t *state_p);
|
||||
int cli_consume_int (cli_state_t *state_p);
|
||||
uint32_t cli_consume_path (cli_state_t *state_p);
|
||||
void cli_help (const char *prog_name_p, const char *command_name_p, const cli_opt_t *options_p);
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
|
||||
#include "jerryscript.h"
|
||||
|
||||
int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||
int
|
||||
LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||
{
|
||||
srand (0);
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jerryscript.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
@@ -46,13 +46,12 @@ static const char *output_file_name_p = "js.snapshot";
|
||||
static jerry_length_t magic_string_lengths[JERRY_LITERAL_LENGTH];
|
||||
static const jerry_char_t *magic_string_items[JERRY_LITERAL_LENGTH];
|
||||
|
||||
#if defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
#if defined(JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
/**
|
||||
* The alloc function passed to jerry_create_context
|
||||
*/
|
||||
static void *
|
||||
context_alloc (size_t size,
|
||||
void *cb_data_p)
|
||||
context_alloc (size_t size, void *cb_data_p)
|
||||
{
|
||||
(void) cb_data_p; /* unused */
|
||||
return malloc (size);
|
||||
@@ -206,24 +205,24 @@ typedef enum
|
||||
/**
|
||||
* Generate command line options
|
||||
*/
|
||||
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_STATIC, .opt = "s", .longopt = "static",
|
||||
.help = "generate static snapshot"),
|
||||
CLI_OPT_DEF (.id = OPT_GENERATE_FUNCTION, .opt = "f", .longopt = "generate-function-snapshot",
|
||||
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_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",
|
||||
CLI_OPT_DEF (.id = OPT_IMPORT_LITERAL_LIST,
|
||||
.longopt = "load-literals-list-format",
|
||||
.meta = "FILE",
|
||||
.help = "import literals from list format (for static snapshots)"),
|
||||
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",
|
||||
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",
|
||||
.help = "input source file")
|
||||
CLI_OPT_DEF (.id = CLI_OPT_DEFAULT, .meta = "FILE", .help = "input source file")
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -328,7 +327,7 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */
|
||||
return JERRY_STANDALONE_EXIT_CODE_FAIL;
|
||||
}
|
||||
|
||||
#if defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
#if defined(JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
context_init ();
|
||||
#endif /* defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1) */
|
||||
|
||||
@@ -363,13 +362,11 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */
|
||||
num_of_lit++;
|
||||
}
|
||||
sp_buffer_p = sp_buffer_end_p + mstr_size + 1;
|
||||
}
|
||||
while ((size_t) (sp_buffer_p - (char *) sp_buffer_start_p) < sp_buffer_size);
|
||||
} while ((size_t) (sp_buffer_p - (char *) sp_buffer_start_p) < sp_buffer_size);
|
||||
|
||||
if (num_of_lit > 0)
|
||||
{
|
||||
jerry_register_magic_strings (magic_string_items, num_of_lit,
|
||||
magic_string_lengths);
|
||||
jerry_register_magic_strings (magic_string_items, num_of_lit, magic_string_lengths);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -378,8 +375,8 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */
|
||||
parse_options.options = JERRY_PARSE_HAS_RESOURCE;
|
||||
/* To avoid cppcheck warning. */
|
||||
parse_options.argument_list = 0;
|
||||
parse_options.resource_name = jerry_create_string_sz ((const jerry_char_t *) file_name_p,
|
||||
(jerry_size_t) strlen (file_name_p));
|
||||
parse_options.resource_name =
|
||||
jerry_create_string_sz ((const jerry_char_t *) file_name_p, (jerry_size_t) strlen (file_name_p));
|
||||
|
||||
if (function_args_p != NULL)
|
||||
{
|
||||
@@ -387,17 +384,13 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */
|
||||
parse_options.argument_list = jerry_create_string_from_utf8 ((const jerry_char_t *) function_args_p);
|
||||
}
|
||||
|
||||
jerry_value_t snapshot_result = jerry_parse ((jerry_char_t *) source_p,
|
||||
source_length,
|
||||
&parse_options);
|
||||
jerry_value_t snapshot_result = jerry_parse ((jerry_char_t *) source_p, source_length, &parse_options);
|
||||
|
||||
if (!jerry_value_is_error (snapshot_result))
|
||||
{
|
||||
jerry_value_t parse_result = snapshot_result;
|
||||
snapshot_result = jerry_generate_snapshot (parse_result,
|
||||
snapshot_flags,
|
||||
output_buffer,
|
||||
sizeof (output_buffer) / sizeof (uint32_t));
|
||||
snapshot_result =
|
||||
jerry_generate_snapshot (parse_result, snapshot_flags, output_buffer, sizeof (output_buffer) / sizeof (uint32_t));
|
||||
jerry_release_value (parse_result);
|
||||
}
|
||||
|
||||
@@ -454,17 +447,14 @@ typedef enum
|
||||
/**
|
||||
* Literal dump command line options
|
||||
*/
|
||||
static const cli_opt_t literal_dump_opts[] =
|
||||
{
|
||||
CLI_OPT_DEF (.id = OPT_LITERAL_DUMP_HELP, .opt = "h", .longopt = "help",
|
||||
.help = "print this help and exit"),
|
||||
CLI_OPT_DEF (.id = OPT_LITERAL_DUMP_FORMAT, .longopt = "format",
|
||||
static const cli_opt_t literal_dump_opts[] = {
|
||||
CLI_OPT_DEF (.id = OPT_LITERAL_DUMP_HELP, .opt = "h", .longopt = "help", .help = "print this help and exit"),
|
||||
CLI_OPT_DEF (.id = OPT_LITERAL_DUMP_FORMAT,
|
||||
.longopt = "format",
|
||||
.meta = "[c|list]",
|
||||
.help = "specify output format (default: list)"),
|
||||
CLI_OPT_DEF (.id = OPT_LITERAL_DUMP_OUT, .opt = "o",
|
||||
.help = "specify output file name (default: literals.[h|list])"),
|
||||
CLI_OPT_DEF (.id = CLI_OPT_DEFAULT, .meta = "FILE(S)",
|
||||
.help = "input snapshot files")
|
||||
CLI_OPT_DEF (.id = OPT_LITERAL_DUMP_OUT, .opt = "o", .help = "specify output file name (default: literals.[h|list])"),
|
||||
CLI_OPT_DEF (.id = CLI_OPT_DEFAULT, .meta = "FILE(S)", .help = "input snapshot files")
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -560,7 +550,7 @@ process_literal_dump (cli_state_t *cli_state_p, /**< cli state */
|
||||
return JERRY_STANDALONE_EXIT_CODE_FAIL;
|
||||
}
|
||||
|
||||
#if defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
#if defined(JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
context_init ();
|
||||
#endif /* defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1) */
|
||||
|
||||
@@ -645,14 +635,10 @@ typedef enum
|
||||
/**
|
||||
* Merge command line options
|
||||
*/
|
||||
static const cli_opt_t merge_opts[] =
|
||||
{
|
||||
CLI_OPT_DEF (.id = OPT_MERGE_HELP, .opt = "h", .longopt = "help",
|
||||
.help = "print this help and exit"),
|
||||
CLI_OPT_DEF (.id = OPT_MERGE_OUT, .opt = "o",
|
||||
.help = "specify output file name (default: js.snapshot)"),
|
||||
CLI_OPT_DEF (.id = CLI_OPT_DEFAULT, .meta = "FILE",
|
||||
.help = "input snapshot files, minimum two")
|
||||
static const cli_opt_t merge_opts[] = {
|
||||
CLI_OPT_DEF (.id = OPT_MERGE_HELP, .opt = "h", .longopt = "help", .help = "print this help and exit"),
|
||||
CLI_OPT_DEF (.id = OPT_MERGE_OUT, .opt = "o", .help = "specify output file name (default: js.snapshot)"),
|
||||
CLI_OPT_DEF (.id = CLI_OPT_DEFAULT, .meta = "FILE", .help = "input snapshot files, minimum two")
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -728,7 +714,7 @@ process_merge (cli_state_t *cli_state_p, /**< cli state */
|
||||
return JERRY_STANDALONE_EXIT_CODE_FAIL;
|
||||
}
|
||||
|
||||
#if defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
#if defined(JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
context_init ();
|
||||
#endif /* defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1) */
|
||||
|
||||
@@ -780,12 +766,9 @@ typedef enum
|
||||
/**
|
||||
* Command line options
|
||||
*/
|
||||
static const cli_opt_t main_opts[] =
|
||||
{
|
||||
CLI_OPT_DEF (.id = OPT_HELP, .opt = "h", .longopt = "help",
|
||||
.help = "print this help and exit"),
|
||||
CLI_OPT_DEF (.id = CLI_OPT_DEFAULT, .meta = "COMMAND",
|
||||
.help = "specify the command")
|
||||
static const cli_opt_t main_opts[] = {
|
||||
CLI_OPT_DEF (.id = OPT_HELP, .opt = "h", .longopt = "help", .help = "print this help and exit"),
|
||||
CLI_OPT_DEF (.id = CLI_OPT_DEFAULT, .meta = "COMMAND", .help = "specify the command")
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jerryscript.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
/**
|
||||
* Maximum size of source code / snapshots buffer
|
||||
@@ -30,11 +30,10 @@
|
||||
#define JERRY_STANDALONE_EXIT_CODE_OK (0)
|
||||
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
|
||||
|
||||
static uint8_t buffer[ JERRY_BUFFER_SIZE ];
|
||||
static uint8_t buffer[JERRY_BUFFER_SIZE];
|
||||
|
||||
static const uint8_t *
|
||||
read_file (const char *file_name,
|
||||
size_t *out_size_p)
|
||||
read_file (const char *file_name, size_t *out_size_p)
|
||||
{
|
||||
FILE *file = fopen (file_name, "rb");
|
||||
if (file == NULL)
|
||||
@@ -119,7 +118,7 @@ run (void)
|
||||
return ret_code;
|
||||
} /* run */
|
||||
|
||||
#if defined (JERRY_TEST_STACK_MEASURE) && (JERRY_TEST_STACK_MEASURE)
|
||||
#if defined(JERRY_TEST_STACK_MEASURE) && (JERRY_TEST_STACK_MEASURE)
|
||||
|
||||
/**
|
||||
* How this stack measuring works:
|
||||
@@ -156,16 +155,25 @@ run (void)
|
||||
*
|
||||
*/
|
||||
|
||||
#if !(defined (__linux__) && __linux__)
|
||||
#if !(defined(__linux__) && __linux__)
|
||||
#error "Unsupported stack measurement platform!"
|
||||
#endif /* !(defined ( __linux__) && __linux__) */
|
||||
|
||||
#if defined (__x86_64__)
|
||||
#define STACK_SAVE(TARGET) { __asm volatile ("mov %%rsp, %0" : "=m" (TARGET)); }
|
||||
#elif defined (__i386__)
|
||||
#define STACK_SAVE(TARGET) { __asm volatile ("mov %%esp, %0" : "=m" (TARGET)); }
|
||||
#elif defined (__arm__)
|
||||
#define STACK_SAVE(TARGET) { __asm volatile ("mov %0, sp" : "=r" (TARGET)); }
|
||||
#if defined(__x86_64__)
|
||||
#define STACK_SAVE(TARGET) \
|
||||
{ \
|
||||
__asm volatile("mov %%rsp, %0" : "=m"(TARGET)); \
|
||||
}
|
||||
#elif defined(__i386__)
|
||||
#define STACK_SAVE(TARGET) \
|
||||
{ \
|
||||
__asm volatile("mov %%esp, %0" : "=m"(TARGET)); \
|
||||
}
|
||||
#elif defined(__arm__)
|
||||
#define STACK_SAVE(TARGET) \
|
||||
{ \
|
||||
__asm volatile("mov %0, sp" : "=r"(TARGET)); \
|
||||
}
|
||||
#else /* !defined (__x86_64__) && !defined (__i386__) && !defined (__arm__) */
|
||||
#error "Unsupported stack measurement target!"
|
||||
#endif /* !defined (__x86_64__) && !defined (__i386__) && !defined (__arm__) */
|
||||
@@ -173,16 +181,17 @@ run (void)
|
||||
static void *g_stack_bottom = 0x0;
|
||||
|
||||
#define STACK_MEASURE_RANGE ((2 * 1024 * 1024))
|
||||
#define STACK_PATTERN (0xDEADBEEF)
|
||||
#define STACK_INIT(TARGET, SIZE) do \
|
||||
#define STACK_PATTERN (0xDEADBEEF)
|
||||
#define STACK_INIT(TARGET, SIZE) \
|
||||
do \
|
||||
{ \
|
||||
for (size_t idx = 0; idx < (SIZE / sizeof (uint32_t)); idx++) \
|
||||
{ \
|
||||
((uint32_t*)(TARGET))[idx] = STACK_PATTERN; \
|
||||
((uint32_t *) (TARGET))[idx] = STACK_PATTERN; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define STACK_USAGE(TARGET, SIZE) stack_usage (TARGET, SIZE)
|
||||
#define STACK_USAGE(TARGET, SIZE) stack_usage (TARGET, SIZE)
|
||||
#define STACK_TOP_PTR(TARGET, SIZE) (uint32_t *) (((uint8_t *) TARGET) - SIZE)
|
||||
|
||||
static void
|
||||
@@ -209,8 +218,8 @@ stack_usage (uint32_t *stack_top_p, size_t length_in_bytes)
|
||||
#define STACK_USAGE(TARGET, SIZE)
|
||||
#endif /* #if defined (JERRY_TEST_STACK_MEASURE) && (JERRY_TEST_STACK_MEASURE) */
|
||||
|
||||
int main (int main_argc,
|
||||
char **main_argv)
|
||||
int
|
||||
main (int main_argc, char **main_argv)
|
||||
{
|
||||
union
|
||||
{
|
||||
|
||||
+15
-23
@@ -18,27 +18,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include "jerryscript-ext/debugger.h"
|
||||
#include "jerryscript-ext/handler.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
|
||||
#include "main-utils.h"
|
||||
#include "main-options.h"
|
||||
#include "main-utils.h"
|
||||
|
||||
/**
|
||||
* Temporal buffer size.
|
||||
*/
|
||||
#define JERRY_BUFFER_SIZE 256u
|
||||
|
||||
#if defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
#if defined(JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
/**
|
||||
* The alloc function passed to jerry_create_context
|
||||
*/
|
||||
static void *
|
||||
context_alloc (size_t size,
|
||||
void *cb_data_p)
|
||||
context_alloc (size_t size, void *cb_data_p)
|
||||
{
|
||||
(void) cb_data_p; /* unused */
|
||||
return malloc (size);
|
||||
@@ -46,8 +45,7 @@ context_alloc (size_t size,
|
||||
#endif /* defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1) */
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char **argv)
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
union
|
||||
{
|
||||
@@ -63,7 +61,7 @@ main (int argc,
|
||||
|
||||
main_parse_args (argc, argv, &arguments);
|
||||
|
||||
#if defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
#if defined(JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
jerry_context_t *context_p = jerry_create_context (JERRY_GLOBAL_HEAP_SIZE * 1024, context_alloc, NULL);
|
||||
jerry_port_default_set_current_context (context_p);
|
||||
#endif /* defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1) */
|
||||
@@ -145,8 +143,7 @@ restart:
|
||||
}
|
||||
default:
|
||||
{
|
||||
assert (source_file_p->type == SOURCE_SCRIPT
|
||||
|| source_file_p->type == SOURCE_MODULE);
|
||||
assert (source_file_p->type == SOURCE_SCRIPT || source_file_p->type == SOURCE_MODULE);
|
||||
|
||||
if (!jerry_is_valid_utf8_string ((jerry_char_t *) source_p, (jerry_size_t) source_size))
|
||||
{
|
||||
@@ -157,12 +154,10 @@ restart:
|
||||
|
||||
jerry_parse_options_t parse_options;
|
||||
parse_options.options = JERRY_PARSE_HAS_RESOURCE;
|
||||
parse_options.resource_name = jerry_create_string_sz ((const jerry_char_t *) file_path_p,
|
||||
(jerry_size_t) strlen (file_path_p));
|
||||
parse_options.resource_name =
|
||||
jerry_create_string_sz ((const jerry_char_t *) file_path_p, (jerry_size_t) strlen (file_path_p));
|
||||
|
||||
ret_value = jerry_parse (source_p,
|
||||
source_size,
|
||||
&parse_options);
|
||||
ret_value = jerry_parse (source_p, source_size, &parse_options);
|
||||
|
||||
jerry_release_value (parse_options.resource_name);
|
||||
jerry_port_release_source (source_p);
|
||||
@@ -199,9 +194,7 @@ restart:
|
||||
while (true)
|
||||
{
|
||||
jerry_debugger_wait_for_source_status_t receive_status;
|
||||
receive_status = jerry_debugger_wait_for_client_source (main_wait_for_source_callback,
|
||||
NULL,
|
||||
&ret_value);
|
||||
receive_status = jerry_debugger_wait_for_client_source (main_wait_for_source_callback, NULL, &ret_value);
|
||||
|
||||
if (receive_status == JERRY_DEBUGGER_SOURCE_RECEIVE_FAILED)
|
||||
{
|
||||
@@ -218,8 +211,7 @@ restart:
|
||||
assert (receive_status == JERRY_DEBUGGER_CONTEXT_RESET_RECEIVED
|
||||
|| receive_status == JERRY_DEBUGGER_SOURCE_RECEIVED);
|
||||
|
||||
if (receive_status == JERRY_DEBUGGER_CONTEXT_RESET_RECEIVED
|
||||
|| main_is_value_reset (ret_value))
|
||||
if (receive_status == JERRY_DEBUGGER_CONTEXT_RESET_RECEIVED || main_is_value_reset (ret_value))
|
||||
{
|
||||
jerry_cleanup ();
|
||||
goto restart;
|
||||
@@ -370,7 +362,7 @@ restart:
|
||||
exit:
|
||||
jerry_cleanup ();
|
||||
|
||||
#if defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
#if defined(JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1)
|
||||
free (context_p);
|
||||
#endif /* defined (JERRY_EXTERNAL_CONTEXT) && (JERRY_EXTERNAL_CONTEXT == 1) */
|
||||
|
||||
|
||||
+49
-38
@@ -13,16 +13,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "main-options.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "jerryscript-port.h"
|
||||
|
||||
#include "cli.h"
|
||||
#include "main-utils.h"
|
||||
#include "main-options.h"
|
||||
|
||||
/**
|
||||
* Command line option IDs
|
||||
@@ -54,49 +55,53 @@ typedef enum
|
||||
/**
|
||||
* Command line options
|
||||
*/
|
||||
static const cli_opt_t main_opts[] =
|
||||
{
|
||||
CLI_OPT_DEF (.id = OPT_HELP, .opt = "h", .longopt = "help",
|
||||
.help = "print this help and exit"),
|
||||
CLI_OPT_DEF (.id = OPT_VERSION, .opt = "v", .longopt = "version",
|
||||
.help = "print tool and library version and exit"),
|
||||
CLI_OPT_DEF (.id = OPT_MEM_STATS, .longopt = "mem-stats",
|
||||
.help = "dump memory statistics"),
|
||||
CLI_OPT_DEF (.id = OPT_TEST262_OBJECT, .longopt = "test262-object",
|
||||
.help = "create test262 object"),
|
||||
CLI_OPT_DEF (.id = OPT_PARSE_ONLY, .longopt = "parse-only",
|
||||
.help = "don't execute JS input"),
|
||||
CLI_OPT_DEF (.id = OPT_SHOW_OP, .longopt = "show-opcodes",
|
||||
.help = "dump parser byte-code"),
|
||||
CLI_OPT_DEF (.id = OPT_SHOW_RE_OP, .longopt = "show-regexp-opcodes",
|
||||
.help = "dump regexp byte-code"),
|
||||
CLI_OPT_DEF (.id = OPT_DEBUG_SERVER, .longopt = "start-debug-server",
|
||||
static const cli_opt_t main_opts[] = {
|
||||
CLI_OPT_DEF (.id = OPT_HELP, .opt = "h", .longopt = "help", .help = "print this help and exit"),
|
||||
CLI_OPT_DEF (.id = OPT_VERSION, .opt = "v", .longopt = "version", .help = "print tool and library version and exit"),
|
||||
CLI_OPT_DEF (.id = OPT_MEM_STATS, .longopt = "mem-stats", .help = "dump memory statistics"),
|
||||
CLI_OPT_DEF (.id = OPT_TEST262_OBJECT, .longopt = "test262-object", .help = "create test262 object"),
|
||||
CLI_OPT_DEF (.id = OPT_PARSE_ONLY, .longopt = "parse-only", .help = "don't execute JS input"),
|
||||
CLI_OPT_DEF (.id = OPT_SHOW_OP, .longopt = "show-opcodes", .help = "dump parser byte-code"),
|
||||
CLI_OPT_DEF (.id = OPT_SHOW_RE_OP, .longopt = "show-regexp-opcodes", .help = "dump regexp byte-code"),
|
||||
CLI_OPT_DEF (.id = OPT_DEBUG_SERVER,
|
||||
.longopt = "start-debug-server",
|
||||
.help = "start debug server and wait for a connecting client"),
|
||||
CLI_OPT_DEF (.id = OPT_DEBUG_PORT, .longopt = "debug-port", .meta = "NUM",
|
||||
CLI_OPT_DEF (.id = OPT_DEBUG_PORT,
|
||||
.longopt = "debug-port",
|
||||
.meta = "NUM",
|
||||
.help = "debug server port (default: 5001)"),
|
||||
CLI_OPT_DEF (.id = OPT_DEBUG_CHANNEL, .longopt = "debug-channel", .meta = "[websocket|rawpacket]",
|
||||
CLI_OPT_DEF (.id = OPT_DEBUG_CHANNEL,
|
||||
.longopt = "debug-channel",
|
||||
.meta = "[websocket|rawpacket]",
|
||||
.help = "Specify the debugger transmission channel (default: websocket)"),
|
||||
CLI_OPT_DEF (.id = OPT_DEBUG_PROTOCOL, .longopt = "debug-protocol", .meta = "PROTOCOL",
|
||||
CLI_OPT_DEF (.id = OPT_DEBUG_PROTOCOL,
|
||||
.longopt = "debug-protocol",
|
||||
.meta = "PROTOCOL",
|
||||
.help = "Specify the transmission protocol over the communication channel (tcp|serial, default: tcp)"),
|
||||
CLI_OPT_DEF (.id = OPT_DEBUG_SERIAL_CONFIG, .longopt = "serial-config", .meta = "OPTIONS_STRING",
|
||||
CLI_OPT_DEF (.id = OPT_DEBUG_SERIAL_CONFIG,
|
||||
.longopt = "serial-config",
|
||||
.meta = "OPTIONS_STRING",
|
||||
.help = "Configure parameters for serial port (default: /dev/ttyS0,115200,8,N,1)"),
|
||||
CLI_OPT_DEF (.id = OPT_DEBUGGER_WAIT_SOURCE, .longopt = "debugger-wait-source",
|
||||
CLI_OPT_DEF (.id = OPT_DEBUGGER_WAIT_SOURCE,
|
||||
.longopt = "debugger-wait-source",
|
||||
.help = "wait for an executable source from the client"),
|
||||
CLI_OPT_DEF (.id = OPT_EXEC_SNAP, .longopt = "exec-snapshot", .meta = "FILE",
|
||||
CLI_OPT_DEF (.id = OPT_EXEC_SNAP,
|
||||
.longopt = "exec-snapshot",
|
||||
.meta = "FILE",
|
||||
.help = "execute input snapshot file(s)"),
|
||||
CLI_OPT_DEF (.id = OPT_EXEC_SNAP_FUNC, .longopt = "exec-snapshot-func", .meta = "FILE NUM",
|
||||
CLI_OPT_DEF (.id = OPT_EXEC_SNAP_FUNC,
|
||||
.longopt = "exec-snapshot-func",
|
||||
.meta = "FILE NUM",
|
||||
.help = "execute specific function from input snapshot file(s)"),
|
||||
CLI_OPT_DEF (.id = OPT_MODULE, .opt = "m", .longopt = "module", .meta = "FILE",
|
||||
.help = "execute module file"),
|
||||
CLI_OPT_DEF (.id = OPT_LOG_LEVEL, .longopt = "log-level", .meta = "NUM",
|
||||
.help = "set log level (0-3)"),
|
||||
CLI_OPT_DEF (.id = OPT_NO_PROMPT, .longopt = "no-prompt",
|
||||
.help = "don't print prompt in REPL mode"),
|
||||
CLI_OPT_DEF (.id = OPT_CALL_ON_EXIT, .longopt = "call-on-exit", .meta = "STRING",
|
||||
CLI_OPT_DEF (.id = OPT_MODULE, .opt = "m", .longopt = "module", .meta = "FILE", .help = "execute module file"),
|
||||
CLI_OPT_DEF (.id = OPT_LOG_LEVEL, .longopt = "log-level", .meta = "NUM", .help = "set log level (0-3)"),
|
||||
CLI_OPT_DEF (.id = OPT_NO_PROMPT, .longopt = "no-prompt", .help = "don't print prompt in REPL mode"),
|
||||
CLI_OPT_DEF (.id = OPT_CALL_ON_EXIT,
|
||||
.longopt = "call-on-exit",
|
||||
.meta = "STRING",
|
||||
.help = "invoke the specified function when the process is just about to exit"),
|
||||
CLI_OPT_DEF (.id = OPT_USE_STDIN, .opt = "", .help = "read from standard input"),
|
||||
CLI_OPT_DEF (.id = CLI_OPT_DEFAULT, .meta = "FILE",
|
||||
.help = "input JS file(s)")
|
||||
CLI_OPT_DEF (.id = CLI_OPT_DEFAULT, .meta = "FILE", .help = "input JS file(s)")
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -241,7 +246,9 @@ main_parse_args (int argc, /**< argc */
|
||||
{
|
||||
const char *debug_channel = cli_consume_string (&cli_state);
|
||||
check_usage (!strcmp (debug_channel, "websocket") || !strcmp (debug_channel, "rawpacket"),
|
||||
argv[0], "Error: invalid value for --debug-channel: ", cli_state.arg);
|
||||
argv[0],
|
||||
"Error: invalid value for --debug-channel: ",
|
||||
cli_state.arg);
|
||||
|
||||
arguments_p->debug_channel = debug_channel;
|
||||
}
|
||||
@@ -253,7 +260,9 @@ main_parse_args (int argc, /**< argc */
|
||||
{
|
||||
const char *debug_protocol = cli_consume_string (&cli_state);
|
||||
check_usage (!strcmp (debug_protocol, "tcp") || !strcmp (debug_protocol, "serial"),
|
||||
argv[0], "Error: invalid value for --debug-protocol: ", cli_state.arg);
|
||||
argv[0],
|
||||
"Error: invalid value for --debug-protocol: ",
|
||||
cli_state.arg);
|
||||
|
||||
arguments_p->debug_protocol = debug_protocol;
|
||||
}
|
||||
@@ -327,7 +336,9 @@ main_parse_args (int argc, /**< argc */
|
||||
{
|
||||
long int log_level = cli_consume_int (&cli_state);
|
||||
check_usage (log_level >= 0 && log_level <= 3,
|
||||
argv[0], "Error: invalid value for --log-level: ", cli_state.arg);
|
||||
argv[0],
|
||||
"Error: invalid value for --log-level: ",
|
||||
cli_state.arg);
|
||||
|
||||
jerry_port_default_set_log_level ((jerry_log_level_t) log_level);
|
||||
break;
|
||||
|
||||
@@ -23,12 +23,12 @@
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
OPT_FLAG_EMPTY = 0,
|
||||
OPT_FLAG_PARSE_ONLY = (1 << 0),
|
||||
OPT_FLAG_DEBUG_SERVER = (1 << 1),
|
||||
OPT_FLAG_WAIT_SOURCE = (1 << 2),
|
||||
OPT_FLAG_NO_PROMPT = (1 << 3),
|
||||
OPT_FLAG_USE_STDIN = (1 << 4),
|
||||
OPT_FLAG_EMPTY = 0,
|
||||
OPT_FLAG_PARSE_ONLY = (1 << 0),
|
||||
OPT_FLAG_DEBUG_SERVER = (1 << 1),
|
||||
OPT_FLAG_WAIT_SOURCE = (1 << 2),
|
||||
OPT_FLAG_NO_PROMPT = (1 << 3),
|
||||
OPT_FLAG_USE_STDIN = (1 << 4),
|
||||
OPT_FLAG_TEST262_OBJECT = (1u << 5),
|
||||
} main_option_flags_t;
|
||||
|
||||
@@ -71,7 +71,6 @@ typedef struct
|
||||
uint16_t init_flags;
|
||||
} main_args_t;
|
||||
|
||||
void
|
||||
main_parse_args (int argc, char **argv, main_args_t *arguments_p);
|
||||
void main_parse_args (int argc, char **argv, main_args_t *arguments_p);
|
||||
|
||||
#endif /* !MAIN_OPTIONS_H */
|
||||
|
||||
+13
-15
@@ -13,18 +13,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "main-utils.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include "jerryscript-ext/debugger.h"
|
||||
#include "jerryscript-ext/handler.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
|
||||
#include "main-utils.h"
|
||||
#include "main-options.h"
|
||||
|
||||
/**
|
||||
@@ -142,8 +143,7 @@ test262_eval_script (const jerry_call_info_t *call_info_p, /**< call information
|
||||
return ret_value;
|
||||
} /* test262_eval_script */
|
||||
|
||||
static jerry_value_t
|
||||
create_test262 (jerry_value_t global_obj);
|
||||
static jerry_value_t create_test262 (jerry_value_t global_obj);
|
||||
|
||||
/**
|
||||
* $262.createRealm
|
||||
@@ -385,13 +385,13 @@ main_print_unhandled_exception (jerry_value_t error_value) /**< error value */
|
||||
}
|
||||
|
||||
/* Print character if:
|
||||
* - The max line length is not reached.
|
||||
* - The current position is valid (it is not the end of the source).
|
||||
* - The current character is not a newline.
|
||||
**/
|
||||
* - The max line length is not reached.
|
||||
* - The current position is valid (it is not the end of the source).
|
||||
* - The current character is not a newline.
|
||||
**/
|
||||
for (uint32_t char_count = 0;
|
||||
(char_count < SYNTAX_ERROR_MAX_LINE_LENGTH) && (pos < source_size) && (source_p[pos] != '\n');
|
||||
char_count++, pos++)
|
||||
(char_count < SYNTAX_ERROR_MAX_LINE_LENGTH) && (pos < source_size) && (source_p[pos] != '\n');
|
||||
char_count++, pos++)
|
||||
{
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "%c", source_p[pos]);
|
||||
}
|
||||
@@ -479,9 +479,7 @@ main_wait_for_source_callback (const jerry_char_t *resource_name_p, /**< resourc
|
||||
parse_options.options = JERRY_PARSE_HAS_RESOURCE;
|
||||
parse_options.resource_name = jerry_create_string_sz (resource_name_p, (jerry_size_t) resource_name_size);
|
||||
|
||||
jerry_value_t ret_val = jerry_parse (source_p,
|
||||
source_size,
|
||||
&parse_options);
|
||||
jerry_value_t ret_val = jerry_parse (source_p, source_size, &parse_options);
|
||||
|
||||
jerry_release_value (parse_options.resource_name);
|
||||
|
||||
|
||||
+10
-12
@@ -16,6 +16,8 @@
|
||||
#ifndef MAIN_UTILS_H
|
||||
#define MAIN_UTILS_H
|
||||
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include "main-options.h"
|
||||
|
||||
/**
|
||||
@@ -24,19 +26,15 @@
|
||||
#define JERRY_STANDALONE_EXIT_CODE_OK (0)
|
||||
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
|
||||
|
||||
void
|
||||
main_init_engine (main_args_t *arguments_p);
|
||||
void
|
||||
main_print_unhandled_exception (jerry_value_t error_value);
|
||||
void main_init_engine (main_args_t *arguments_p);
|
||||
void main_print_unhandled_exception (jerry_value_t error_value);
|
||||
|
||||
jerry_value_t
|
||||
main_wait_for_source_callback (const jerry_char_t *resource_name_p,
|
||||
size_t resource_name_size,
|
||||
const jerry_char_t *source_p,
|
||||
size_t source_size,
|
||||
void *user_p);
|
||||
jerry_value_t main_wait_for_source_callback (const jerry_char_t *resource_name_p,
|
||||
size_t resource_name_size,
|
||||
const jerry_char_t *source_p,
|
||||
size_t source_size,
|
||||
void *user_p);
|
||||
|
||||
bool
|
||||
main_is_value_reset (jerry_value_t value);
|
||||
bool main_is_value_reset (jerry_value_t value);
|
||||
|
||||
#endif /* !MAIN_UTILS_H */
|
||||
|
||||
Reference in New Issue
Block a user