Update bytecode header structure so that bytecode could be stored independently from hash table and bytecode header.

JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
Andrey Shitov 2015-09-03 18:11:27 +03:00 committed by Ruben Ayrapetyan
parent 6a6fb3fdfa
commit 443673fc5d
22 changed files with 207 additions and 194 deletions

View File

@ -271,13 +271,13 @@ ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p,
utf8_string_buffer_pos += sz;
}
const vm_instr_t* instrs_p;
const bytecode_data_header_t* bytecode_data_p;
jsp_status_t parse_status;
parse_status = parser_parse_new_function ((const jerry_api_char_t **) utf8_string_params_p,
utf8_string_params_size,
params_count,
&instrs_p);
&bytecode_data_p);
if (parse_status == JSP_STATUS_SYNTAX_ERROR)
{
@ -293,7 +293,7 @@ ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p,
bool is_strict = false;
bool do_instantiate_arguments_object = true;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (instrs_p,
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (bytecode_data_p->instrs_p,
0);
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
@ -321,7 +321,7 @@ ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p,
glob_lex_env_p,
is_strict,
do_instantiate_arguments_object,
instrs_p,
bytecode_data_p,
1);
ecma_deref_object (glob_lex_env_p);

View File

@ -86,7 +86,7 @@ ecma_op_eval_chars_buffer (const jerry_api_char_t *code_p, /**< code characters
ecma_completion_value_t completion;
const vm_instr_t *instrs_p;
const bytecode_data_header_t *bytecode_data_p;
jsp_status_t parse_status;
bool is_strict_call = (is_direct && is_called_from_strict_mode_code);
@ -95,7 +95,7 @@ ecma_op_eval_chars_buffer (const jerry_api_char_t *code_p, /**< code characters
parse_status = parser_parse_eval (code_p,
code_buffer_size,
is_strict_call,
&instrs_p,
&bytecode_data_p,
&code_contains_functions);
if (parse_status == JSP_STATUS_SYNTAX_ERROR)
@ -110,11 +110,11 @@ ecma_op_eval_chars_buffer (const jerry_api_char_t *code_p, /**< code characters
{
JERRY_ASSERT (parse_status == JSP_STATUS_OK);
completion = vm_run_eval (instrs_p, is_direct);
completion = vm_run_eval (bytecode_data_p, is_direct);
if (!code_contains_functions)
{
serializer_remove_instructions (instrs_p);
serializer_remove_bytecode_data (bytecode_data_p);
}
}

View File

@ -216,7 +216,7 @@ ecma_op_create_function_object (ecma_collection_header_t *formal_params_collecti
bool is_strict, /**< 'strict' flag */
bool do_instantiate_arguments_object, /**< should an Arguments object be instantiated
* for the function object upon call */
const vm_instr_t *instrs_p, /**< byte-code array */
const bytecode_data_header_t *bytecode_data_p, /**< byte-code array */
vm_instr_counter_t first_instr_pos) /**< position of first instruction
* of function's body */
{
@ -252,7 +252,7 @@ ecma_op_create_function_object (ecma_collection_header_t *formal_params_collecti
// 12.
ecma_property_t *bytecode_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_CODE_BYTECODE);
MEM_CP_SET_NON_NULL_POINTER (bytecode_prop_p->u.internal_property.value, instrs_p);
MEM_CP_SET_NON_NULL_POINTER (bytecode_prop_p->u.internal_property.value, bytecode_data_p);
ecma_property_t *code_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_CODE_FLAGS_AND_OFFSET);
code_prop_p->u.internal_property.value = ecma_pack_code_internal_property_value (is_strict,
@ -824,7 +824,8 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
// 8.
bool is_strict;
bool do_instantiate_args_obj;
const vm_instr_t *instrs_p = MEM_CP_GET_POINTER (const vm_instr_t, bytecode_prop_p->u.internal_property.value);
const bytecode_data_header_t *bytecode_data_p;
bytecode_data_p = MEM_CP_GET_POINTER (const bytecode_data_header_t, bytecode_prop_p->u.internal_property.value);
vm_instr_counter_t code_first_instr_pos = ecma_unpack_code_internal_property_value (code_prop_value,
&is_strict,
&do_instantiate_args_obj);
@ -862,7 +863,7 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
do_instantiate_args_obj),
ret_value);
ecma_completion_value_t completion = vm_run_from_pos (instrs_p,
ecma_completion_value_t completion = vm_run_from_pos (bytecode_data_p,
code_first_instr_pos,
this_binding,
local_env_p,
@ -1105,7 +1106,7 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
ecma_completion_value_t
ecma_op_function_declaration (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_string_t *function_name_p, /**< function name */
const vm_instr_t *instrs_p, /**< byte-code array */
const bytecode_data_header_t *bytecode_data_p, /**< byte-code data */
vm_instr_counter_t function_first_instr_pos, /**< position of first instruction
* of function code */
ecma_collection_header_t *formal_params_collection_p, /**< formal parameters collection
@ -1126,7 +1127,7 @@ ecma_op_function_declaration (ecma_object_t *lex_env_p, /**< lexical environment
lex_env_p,
is_strict,
do_instantiate_arguments_object,
instrs_p,
bytecode_data_p,
function_first_instr_pos);
// c.

View File

@ -34,7 +34,7 @@ ecma_op_create_function_object (ecma_collection_header_t *formal_params_collecti
ecma_object_t *scope_p,
bool is_strict,
bool do_instantiate_arguments_object,
const vm_instr_t *instrs_p,
const bytecode_data_header_t *bytecode_data_p,
vm_instr_counter_t first_opcode_idx);
extern ecma_object_t*
ecma_op_create_external_function_object (ecma_external_pointer_t code_p);
@ -66,7 +66,7 @@ ecma_op_function_has_instance (ecma_object_t *func_obj_p,
extern ecma_completion_value_t
ecma_op_function_declaration (ecma_object_t *lex_env_p,
ecma_string_t *function_name_p,
const vm_instr_t *instrs_p,
const bytecode_data_header_t *bytecode_data_p,
vm_instr_counter_t function_code_opcode_idx,
ecma_collection_header_t *formal_params_collection_p,
bool is_strict,

View File

@ -1403,12 +1403,12 @@ jerry_parse (const jerry_api_char_t* source_p, /**< script source */
parser_set_show_instrs (is_show_instructions);
const vm_instr_t *instrs_p;
const bytecode_data_header_t *bytecode_data_p;
jsp_status_t parse_status;
parse_status = parser_parse_script (source_p,
source_size,
&instrs_p);
&bytecode_data_p);
if (parse_status != JSP_STATUS_OK)
{
@ -1427,7 +1427,7 @@ jerry_parse (const jerry_api_char_t* source_p, /**< script source */
bool is_show_mem_stats_per_instruction = ((jerry_flags & JERRY_FLAG_MEM_STATS_PER_OPCODE) != 0);
vm_init (instrs_p, is_show_mem_stats_per_instruction);
vm_init (bytecode_data_p, is_show_mem_stats_per_instruction);
return true;
} /* jerry_parse */

View File

@ -17,7 +17,6 @@
#define BYTECODE_DATA_H
#include "opcodes.h"
#include "lit-id-hash-table.h"
#include "mem-allocator.h"
/*
@ -33,36 +32,18 @@
*
* To map uid to literal id 'lit_id_hash' table is used.
*/
#define BLOCK_SIZE 64
#define BLOCK_SIZE 64u
/**
* Header of byte-code memory region, containing byte-code array and literal identifiers hash table
*/
typedef struct __attribute__ ((aligned (MEM_ALIGNMENT)))
typedef struct __attribute__ ((aligned (MEM_ALIGNMENT))) bytecode_data_header_t
{
vm_instr_t *instrs_p; /**< pointer to the bytecode */
vm_instr_counter_t instrs_count; /**< number of instructions in the byte-code array */
mem_cpointer_t lit_id_hash_cp; /**< pointer to literal identifiers hash table
* See also: lit_id_hash_table_init */
mem_cpointer_t next_instrs_cp; /**< pointer to next byte-code memory region */
vm_instr_counter_t instructions_number; /**< number of instructions in the byte-code array */
} insts_data_header_t;
mem_cpointer_t next_header_cp; /**< pointer to next instructions data header */
} bytecode_data_header_t;
typedef struct
{
const ecma_char_t *strings_buffer;
const vm_instr_t *instrs_p;
vm_instr_counter_t instrs_count;
} bytecode_data_t;
/**
* Macros to get a pointer to bytecode header by pointer to instructions array start
*/
#define GET_BYTECODE_HEADER(instrs) ((insts_data_header_t *) (((uint8_t *) (instrs)) - sizeof (insts_data_header_t)))
/**
* Macros to get a hash table corresponding to a bytecode region
*/
#define GET_HASH_TABLE_FOR_BYTECODE(instrs) (MEM_CP_GET_POINTER (lit_id_hash_table, \
GET_BYTECODE_HEADER (instrs)->lit_id_hash_cp))
#endif // BYTECODE_DATA_H
#endif /* BYTECODE_DATA_H */

View File

@ -3101,13 +3101,13 @@ parser_parse_program (const jerry_api_char_t *source_p, /**< source code buffer
bool in_eval, /**< flag indicating if we are parsing body of eval code */
bool is_strict, /**< flag, indicating whether current code
* inherited strict mode from code of an outer scope */
const vm_instr_t **out_instrs_p, /**< out: generated byte-code array
* (in case there were no syntax errors) */
const bytecode_data_header_t **out_bytecode_data_p, /**< out: generated byte-code array
* (in case there were no syntax errors) */
bool *out_contains_functions_p) /**< out: optional (can be NULL, if the output is not needed)
* flag, indicating whether the compiled byte-code
* contains a function declaration / expression */
{
JERRY_ASSERT (out_instrs_p != NULL);
JERRY_ASSERT (out_bytecode_data_p != NULL);
JERRY_ASSERT (!(in_dyn_constructed_function && in_eval));
@ -3189,7 +3189,7 @@ parser_parse_program (const jerry_api_char_t *source_p, /**< source code buffer
jsp_early_error_free ();
*out_instrs_p = serializer_merge_scopes_into_bytecode ();
*out_bytecode_data_p = serializer_merge_scopes_into_bytecode ();
dumper_free ();
@ -3215,7 +3215,7 @@ parser_parse_program (const jerry_api_char_t *source_p, /**< source code buffer
JERRY_ASSERT (!is_parse_finished);
#endif /* !JERRY_NDEBUG */
*out_instrs_p = NULL;
*out_bytecode_data_p = NULL;
jsp_label_remove_all_labels ();
jsp_mm_free_all ();
@ -3249,10 +3249,10 @@ parser_parse_program (const jerry_api_char_t *source_p, /**< source code buffer
jsp_status_t
parser_parse_script (const jerry_api_char_t *source, /**< source script */
size_t source_size, /**< source script size it bytes */
const vm_instr_t **out_instrs_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
const bytecode_data_header_t **out_bytecode_data_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
{
return parser_parse_program (source, source_size, false, false, false, out_instrs_p, NULL);
return parser_parse_program (source, source_size, false, false, false, out_bytecode_data_p, NULL);
} /* parser_parse_script */
/**
@ -3266,14 +3266,20 @@ parser_parse_eval (const jerry_api_char_t *source, /**< string passed to eval()
size_t source_size, /**< string size in bytes */
bool is_strict, /**< flag, indicating whether eval is called
* from strict code in direct mode */
const vm_instr_t **out_instrs_p, /**< out: generated byte-code array
* (in case there were no syntax errors) */
const bytecode_data_header_t **out_bytecode_data_p, /**< out: generated byte-code array
* (in case there were no syntax errors) */
bool *out_contains_functions_p) /**< out: flag, indicating whether the compiled byte-code
* contains a function declaration / expression */
{
JERRY_ASSERT (out_contains_functions_p != NULL);
return parser_parse_program (source, source_size, false, true, is_strict, out_instrs_p, out_contains_functions_p);
return parser_parse_program (source,
source_size,
false,
true,
is_strict,
out_bytecode_data_p,
out_contains_functions_p);
} /* parser_parse_eval */
/**
@ -3291,8 +3297,9 @@ parser_parse_new_function (const jerry_api_char_t **params, /**< array of argume
* body) call */
const size_t *params_size, /**< sizes of arguments strings */
size_t params_count, /**< total number of arguments passed to new Function (...) */
const vm_instr_t **out_instrs_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
const bytecode_data_header_t **out_bytecode_data_p) /**< out: generated byte-code array
* (in case there were no syntax
* errors) */
{
// Process arguments
JERRY_ASSERT (params_count > 0);
@ -3306,7 +3313,7 @@ parser_parse_new_function (const jerry_api_char_t **params, /**< array of argume
true,
false,
false,
out_instrs_p,
out_bytecode_data_p,
NULL);
} /* parser_parse_new_function */

View File

@ -29,8 +29,9 @@ typedef enum
} jsp_status_t;
void parser_set_show_instrs (bool);
jsp_status_t parser_parse_script (const jerry_api_char_t *, size_t, const vm_instr_t **);
jsp_status_t parser_parse_eval (const jerry_api_char_t *, size_t, bool, const vm_instr_t **, bool *);
jsp_status_t parser_parse_new_function (const jerry_api_char_t **, const size_t *, size_t, const vm_instr_t **);
jsp_status_t parser_parse_script (const jerry_api_char_t *, size_t, const bytecode_data_header_t **);
jsp_status_t parser_parse_eval (const jerry_api_char_t *, size_t, bool, const bytecode_data_header_t **, bool *);
jsp_status_t parser_parse_new_function (const jerry_api_char_t **, const size_t *, size_t,
const bytecode_data_header_t **);
#endif /* PARSER_H */

View File

@ -691,13 +691,11 @@ scopes_tree_raw_data (scopes_tree tree, /**< scopes tree to convert to byte-code
global_oc = 0;
/* Dump bytecode and fill literal indexes 'hash' table. */
JERRY_ASSERT (instructions_array_size >=
sizeof (insts_data_header_t) + (size_t) (scopes_tree_count_instructions (tree)) * sizeof (vm_instr_t));
JERRY_ASSERT (instructions_array_size >= (size_t) (scopes_tree_count_instructions (tree)) * sizeof (vm_instr_t));
insts_data_header_t *opcodes_data = (insts_data_header_t *) buffer_p;
memset (opcodes_data, 0, instructions_array_size);
vm_instr_t *instrs = (vm_instr_t *) buffer_p;
memset (instrs, 0, instructions_array_size);
vm_instr_t *instrs = (vm_instr_t *)(((uint8_t*) opcodes_data) + sizeof (insts_data_header_t));
merge_subscopes (tree, instrs, lit_ids);
if (lit_id_to_uid != null_hash)
{
@ -705,8 +703,6 @@ scopes_tree_raw_data (scopes_tree tree, /**< scopes tree to convert to byte-code
lit_id_to_uid = null_hash;
}
MEM_CP_SET_POINTER (opcodes_data->lit_id_hash_cp, lit_ids);
return instrs;
} /* scopes_tree_raw_data */

View File

@ -19,13 +19,12 @@
#include "array-list.h"
#include "scopes-tree.h"
static bytecode_data_t bytecode_data;
static bytecode_data_header_t *first_bytecode_header_p;
static scopes_tree current_scope;
static bool print_instrs;
static void
serializer_print_instrs (const vm_instr_t *instrs_p,
size_t instrs_count);
serializer_print_instrs (const bytecode_data_header_t *);
op_meta
serializer_get_op_meta (vm_instr_counter_t oc)
@ -52,19 +51,19 @@ serializer_get_var_decl (vm_instr_counter_t oc) /**< index of variable declarati
* @return byte-code instruction
*/
vm_instr_t
serializer_get_instr (const vm_instr_t *instrs_p, /**< pointer to byte-code array (or NULL,
* if instruction should be taken from
* instruction list of current scope) */
serializer_get_instr (const bytecode_data_header_t *bytecode_data_p, /**< pointer to byte-code data (or NULL,
* if instruction should be taken from
* instruction list of current scope) */
vm_instr_counter_t oc) /**< position of the intruction */
{
if (instrs_p == NULL)
if (bytecode_data_p == NULL)
{
return serializer_get_op_meta (oc).op;
}
else
{
JERRY_ASSERT (oc < GET_BYTECODE_HEADER (instrs_p)->instructions_number);
return instrs_p[oc];
JERRY_ASSERT (oc < bytecode_data_p->instrs_count);
return bytecode_data_p->instrs_p[oc];
}
} /* serializer_get_instr */
@ -79,23 +78,27 @@ serializer_get_instr (const vm_instr_t *instrs_p, /**< pointer to byte-code arra
*/
lit_cpointer_t
serializer_get_literal_cp_by_uid (uint8_t id, /**< literal idx */
const vm_instr_t *instrs_p, /**< pointer to bytecode */
const bytecode_data_header_t *bytecode_data_p, /**< pointer to bytecode */
vm_instr_counter_t oc) /**< position in the bytecode */
{
lit_id_hash_table *lit_id_hash = GET_HASH_TABLE_FOR_BYTECODE (instrs_p == NULL ? bytecode_data.instrs_p : instrs_p);
lit_id_hash_table *lit_id_hash = null_hash;
if (bytecode_data_p)
{
lit_id_hash = MEM_CP_GET_POINTER (lit_id_hash_table, bytecode_data_p->lit_id_hash_cp);
}
else
{
lit_id_hash = MEM_CP_GET_POINTER (lit_id_hash_table, first_bytecode_header_p->lit_id_hash_cp);
}
if (lit_id_hash == null_hash)
{
return INVALID_LITERAL;
}
return lit_id_hash_table_lookup (lit_id_hash, id, oc);
} /* serializer_get_literal_cp_by_uid */
void
serializer_set_strings_buffer (const ecma_char_t *s)
{
bytecode_data.strings_buffer = s;
}
void
serializer_set_scope (scopes_tree new_scope)
{
@ -145,43 +148,52 @@ serializer_dump_subscope (scopes_tree tree) /**< scope to dump */
}
} /* serializer_dump_subscope */
const vm_instr_t *
/**
* Merge scopes tree into bytecode
*
* @return pointer to generated bytecode
*/
const bytecode_data_header_t *
serializer_merge_scopes_into_bytecode (void)
{
bytecode_data.instrs_count = scopes_tree_count_instructions (current_scope);
const size_t buckets_count = scopes_tree_count_literals_in_blocks (current_scope);
const size_t blocks_count = (size_t) bytecode_data.instrs_count / BLOCK_SIZE + 1;
const vm_instr_counter_t instrs_count = scopes_tree_count_instructions (current_scope);
const size_t blocks_count = JERRY_ALIGNUP (instrs_count, BLOCK_SIZE) / BLOCK_SIZE;
const size_t bytecode_array_size = JERRY_ALIGNUP (sizeof (insts_data_header_t) + instrs_count * sizeof (vm_instr_t),
MEM_ALIGNMENT);
const size_t lit_id_hash_table_size = JERRY_ALIGNUP (lit_id_hash_table_get_size_for_table (buckets_count,
blocks_count),
MEM_ALIGNMENT);
const size_t bytecode_size = JERRY_ALIGNUP (instrs_count * sizeof (vm_instr_t), MEM_ALIGNMENT);
const size_t hash_table_size = lit_id_hash_table_get_size_for_table (buckets_count, blocks_count);
const size_t header_and_hash_table_size = JERRY_ALIGNUP (sizeof (bytecode_data_header_t) + hash_table_size,
MEM_ALIGNMENT);
uint8_t *buffer_p = (uint8_t*) mem_heap_alloc_block (bytecode_array_size + lit_id_hash_table_size,
uint8_t *buffer_p = (uint8_t*) mem_heap_alloc_block (bytecode_size + header_and_hash_table_size,
MEM_HEAP_ALLOC_LONG_TERM);
lit_id_hash_table *lit_id_hash = lit_id_hash_table_init (buffer_p + bytecode_array_size,
lit_id_hash_table_size,
lit_id_hash_table *lit_id_hash = lit_id_hash_table_init (buffer_p + sizeof (bytecode_data_header_t),
hash_table_size,
buckets_count, blocks_count);
const vm_instr_t *instrs_p = scopes_tree_raw_data (current_scope, buffer_p, bytecode_array_size, lit_id_hash);
vm_instr_t *bytecode_p = scopes_tree_raw_data (current_scope,
buffer_p + header_and_hash_table_size,
bytecode_size,
lit_id_hash);
insts_data_header_t *header_p = (insts_data_header_t*) buffer_p;
MEM_CP_SET_POINTER (header_p->next_instrs_cp, bytecode_data.instrs_p);
header_p->instructions_number = instrs_count;
bytecode_data.instrs_p = instrs_p;
bytecode_data_header_t *header_p = (bytecode_data_header_t *) buffer_p;
MEM_CP_SET_POINTER (header_p->lit_id_hash_cp, lit_id_hash);
header_p->instrs_p = bytecode_p;
header_p->instrs_count = instrs_count;
MEM_CP_SET_POINTER (header_p->next_header_cp, first_bytecode_header_p);
first_bytecode_header_p = header_p;
if (print_instrs)
{
lit_dump_literals ();
serializer_print_instrs (instrs_p, bytecode_data.instrs_count);
serializer_print_instrs (header_p);
}
return instrs_p;
}
return header_p;
} /* serializer_merge_scopes_into_bytecode */
void
serializer_dump_op_meta (op_meta op)
@ -252,25 +264,23 @@ serializer_rewrite_op_meta (const vm_instr_counter_t loc, op_meta op)
}
static void
serializer_print_instrs (const vm_instr_t *instrs_p,
size_t instrs_count)
serializer_print_instrs (const bytecode_data_header_t *bytecode_data_p)
{
#ifdef JERRY_ENABLE_PRETTY_PRINTER
for (vm_instr_counter_t loc = 0; loc < instrs_count; loc++)
for (vm_instr_counter_t loc = 0; loc < bytecode_data_p->instrs_count; loc++)
{
op_meta opm;
opm.op = instrs_p[loc];
opm.op = bytecode_data_p->instrs_p[loc];
for (int i = 0; i < 3; i++)
{
opm.lit_id[i] = NOT_A_LITERAL;
}
pp_op_meta (instrs_p, loc, opm, false);
pp_op_meta (bytecode_data_p, loc, opm, false);
}
#else
(void) instrs_p;
(void) instrs_count;
(void) bytecode_data_p;
#endif
}
@ -280,8 +290,7 @@ serializer_init ()
current_scope = NULL;
print_instrs = false;
bytecode_data.strings_buffer = NULL;
bytecode_data.instrs_p = NULL;
first_bytecode_header_p = NULL;
lit_init ();
}
@ -295,47 +304,41 @@ void serializer_set_show_instrs (bool show_instrs)
* Deletes bytecode and associated hash table
*/
void
serializer_remove_instructions (const vm_instr_t *instrs_p) /**< pointer to instructions which should be deleted */
serializer_remove_bytecode_data (const bytecode_data_header_t *bytecode_data_p) /**< pointer to bytecode data which
* should be deleted */
{
insts_data_header_t *prev_header = NULL;
const vm_instr_t *cur_instrs_p = bytecode_data.instrs_p;
while (cur_instrs_p != NULL)
{
insts_data_header_t *cur_header_p = GET_BYTECODE_HEADER (cur_instrs_p);
bytecode_data_header_t *prev_header = NULL;
bytecode_data_header_t *cur_header_p = first_bytecode_header_p;
if (cur_instrs_p == instrs_p)
while (cur_header_p != NULL)
{
if (cur_header_p == bytecode_data_p)
{
if (prev_header)
{
prev_header->next_instrs_cp = cur_header_p->next_instrs_cp;
prev_header->next_header_cp = cur_header_p->next_header_cp;
}
else
{
bytecode_data.instrs_p = MEM_CP_GET_POINTER (vm_instr_t, cur_header_p->next_instrs_cp);
first_bytecode_header_p = MEM_CP_GET_POINTER (bytecode_data_header_t, cur_header_p->next_header_cp);
}
mem_heap_free_block (cur_header_p);
break;
}
prev_header = GET_BYTECODE_HEADER (cur_instrs_p);
cur_instrs_p = MEM_CP_GET_POINTER (vm_instr_t, cur_header_p->next_instrs_cp);
prev_header = cur_header_p;
}
} /* serializer_remove_instructions */
void
serializer_free (void)
{
if (bytecode_data.strings_buffer)
{
mem_heap_free_block ((uint8_t *) bytecode_data.strings_buffer);
}
lit_finalize ();
while (bytecode_data.instrs_p != NULL)
while (first_bytecode_header_p != NULL)
{
insts_data_header_t *header_p = GET_BYTECODE_HEADER (bytecode_data.instrs_p);
bytecode_data.instrs_p = MEM_CP_GET_POINTER (vm_instr_t, header_p->next_instrs_cp);
bytecode_data_header_t *header_p = first_bytecode_header_p;
first_bytecode_header_p = MEM_CP_GET_POINTER (bytecode_data_header_t, header_p->next_header_cp);
mem_heap_free_block (header_p);
}

View File

@ -16,6 +16,7 @@
#ifndef SERIALIZER_H
#define SERIALIZER_H
#include "bytecode-data.h"
#include "jrt.h"
#include "ecma-globals.h"
#include "opcodes.h"
@ -28,12 +29,11 @@ void serializer_init ();
void serializer_set_show_instrs (bool show_instrs);
op_meta serializer_get_op_meta (vm_instr_counter_t);
op_meta serializer_get_var_decl (vm_instr_counter_t);
vm_instr_t serializer_get_instr (const vm_instr_t*, vm_instr_counter_t);
lit_cpointer_t serializer_get_literal_cp_by_uid (uint8_t, const vm_instr_t*, vm_instr_counter_t);
void serializer_set_strings_buffer (const ecma_char_t *);
vm_instr_t serializer_get_instr (const bytecode_data_header_t *, vm_instr_counter_t);
lit_cpointer_t serializer_get_literal_cp_by_uid (uint8_t, const bytecode_data_header_t *, vm_instr_counter_t);
void serializer_set_scope (scopes_tree);
void serializer_dump_subscope (scopes_tree);
const vm_instr_t *serializer_merge_scopes_into_bytecode (void);
const bytecode_data_header_t *serializer_merge_scopes_into_bytecode (void);
void serializer_dump_op_meta (op_meta);
void serializer_dump_var_decl (op_meta);
vm_instr_counter_t serializer_get_current_instr_counter (void);
@ -41,7 +41,7 @@ vm_instr_counter_t serializer_get_current_var_decls_counter (void);
vm_instr_counter_t serializer_count_instrs_in_subscopes (void);
void serializer_set_writing_position (vm_instr_counter_t);
void serializer_rewrite_op_meta (vm_instr_counter_t, op_meta);
void serializer_remove_instructions (const vm_instr_t *instrs_p);
void serializer_remove_bytecode_data (const bytecode_data_header_t *);
void serializer_free (void);
#endif // SERIALIZER_H

View File

@ -43,7 +43,7 @@ opfunc_try_block (vm_instr_t instr, /**< instruction */
|| (ecma_is_completion_value_empty (try_completion) && frame_ctx_p->pos == try_end_oc));
frame_ctx_p->pos = try_end_oc;
vm_instr_t next_instr = vm_get_instr (frame_ctx_p->instrs_p, frame_ctx_p->pos);
vm_instr_t next_instr = vm_get_instr (frame_ctx_p->bytecode_header_p->instrs_p, frame_ctx_p->pos);
JERRY_ASSERT (next_instr.op_idx == VM_OP_META);
if (next_instr.data.meta.type == OPCODE_META_TYPE_CATCH)
@ -54,12 +54,12 @@ opfunc_try_block (vm_instr_t instr, /**< instruction */
if (ecma_is_completion_value_throw (try_completion))
{
next_instr = vm_get_instr (frame_ctx_p->instrs_p, frame_ctx_p->pos);
next_instr = vm_get_instr (frame_ctx_p->bytecode_header_p->instrs_p, frame_ctx_p->pos);
JERRY_ASSERT (next_instr.op_idx == VM_OP_META);
JERRY_ASSERT (next_instr.data.meta.type == OPCODE_META_TYPE_CATCH_EXCEPTION_IDENTIFIER);
lit_cpointer_t catch_exc_val_var_name_lit_cp = serializer_get_literal_cp_by_uid (next_instr.data.meta.data_1,
frame_ctx_p->instrs_p,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);
frame_ctx_p->pos++;
@ -98,7 +98,7 @@ opfunc_try_block (vm_instr_t instr, /**< instruction */
frame_ctx_p->pos = catch_end_oc;
}
next_instr = vm_get_instr (frame_ctx_p->instrs_p, frame_ctx_p->pos);
next_instr = vm_get_instr (frame_ctx_p->bytecode_header_p->instrs_p, frame_ctx_p->pos);
JERRY_ASSERT (next_instr.op_idx == VM_OP_META);
if (next_instr.data.meta.type == OPCODE_META_TYPE_FINALLY)
@ -121,7 +121,7 @@ opfunc_try_block (vm_instr_t instr, /**< instruction */
}
}
next_instr = vm_get_instr (frame_ctx_p->instrs_p, frame_ctx_p->pos++);
next_instr = vm_get_instr (frame_ctx_p->bytecode_header_p->instrs_p, frame_ctx_p->pos++);
JERRY_ASSERT (next_instr.op_idx == VM_OP_META);
JERRY_ASSERT (next_instr.data.meta.type == OPCODE_META_TYPE_END_TRY_CATCH_FINALLY);

View File

@ -203,7 +203,7 @@ opfunc_for_in (vm_instr_t instr, /**< instruction */
int_data_p->pos++;
vm_instr_t meta_instr = vm_get_instr (int_data_p->instrs_p, for_in_end_oc);
vm_instr_t meta_instr = vm_get_instr (int_data_p->bytecode_header_p->instrs_p, for_in_end_oc);
JERRY_ASSERT (meta_instr.op_idx == VM_OP_META);
JERRY_ASSERT (meta_instr.data.meta.type == OPCODE_META_TYPE_END_FOR_IN);

View File

@ -14,6 +14,7 @@
*/
#include "opcodes-ecma-support.h"
#include "opcodes.h"
#ifndef JERRY_NDEBUG
/**
@ -91,7 +92,9 @@ get_variable_value (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
else
{
ecma_string_t var_name_string;
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (var_idx, frame_ctx_p->instrs_p, frame_ctx_p->pos);
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (var_idx,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);
JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
ecma_new_ecma_string_on_stack_from_lit_cp (&var_name_string, lit_cp);
@ -158,7 +161,7 @@ set_variable_value (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
else
{
ecma_string_t var_name_string;
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (var_idx, frame_ctx_p->instrs_p, lit_oc);
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (var_idx, frame_ctx_p->bytecode_header_p, lit_oc);
JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
ecma_new_ecma_string_on_stack_from_lit_cp (&var_name_string, lit_cp);

View File

@ -42,7 +42,7 @@ vm_fill_varg_list (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
vm_loop (frame_ctx_p, NULL),
ret_value);
vm_instr_t next_instr = vm_get_instr (frame_ctx_p->instrs_p, frame_ctx_p->pos);
vm_instr_t next_instr = vm_get_instr (frame_ctx_p->bytecode_header_p->instrs_p, frame_ctx_p->pos);
JERRY_ASSERT (next_instr.op_idx == VM_OP_META);
JERRY_ASSERT (next_instr.data.meta.type == OPCODE_META_TYPE_VARG);
@ -80,12 +80,12 @@ vm_fill_params_list (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
param_index < params_number;
param_index++)
{
vm_instr_t next_instr = vm_get_instr (frame_ctx_p->instrs_p, frame_ctx_p->pos);
vm_instr_t next_instr = vm_get_instr (frame_ctx_p->bytecode_header_p->instrs_p, frame_ctx_p->pos);
JERRY_ASSERT (next_instr.op_idx == VM_OP_META);
JERRY_ASSERT (next_instr.data.meta.type == OPCODE_META_TYPE_VARG);
const lit_cpointer_t param_name_lit_idx = serializer_get_literal_cp_by_uid (next_instr.data.meta.data_1,
frame_ctx_p->instrs_p,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);

View File

@ -77,7 +77,9 @@ opfunc_assignment (vm_instr_t instr, /**< instruction */
}
else if (type_value_right == OPCODE_ARG_TYPE_STRING)
{
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (src_val_descr, frame_ctx_p->instrs_p, frame_ctx_p->pos);
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (src_val_descr,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);
ecma_string_t *string_p = ecma_new_ecma_string_from_lit_cp (lit_cp);
ret_value = set_variable_value (frame_ctx_p,
@ -106,7 +108,9 @@ opfunc_assignment (vm_instr_t instr, /**< instruction */
{
ecma_number_t *num_p = frame_ctx_p->tmp_num_p;
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (src_val_descr, frame_ctx_p->instrs_p, frame_ctx_p->pos);
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (src_val_descr,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);
literal_t lit = lit_get_literal_by_cp (lit_cp);
JERRY_ASSERT (lit->get_type () == LIT_NUMBER_T);
@ -121,7 +125,9 @@ opfunc_assignment (vm_instr_t instr, /**< instruction */
{
ecma_number_t *num_p = frame_ctx_p->tmp_num_p;
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (src_val_descr, frame_ctx_p->instrs_p, frame_ctx_p->pos);
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (src_val_descr,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);
literal_t lit = lit_get_literal_by_cp (lit_cp);
JERRY_ASSERT (lit->get_type () == LIT_NUMBER_T);
@ -147,7 +153,7 @@ opfunc_assignment (vm_instr_t instr, /**< instruction */
{
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (src_val_descr,
frame_ctx_p->instrs_p,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);
ecma_string_t *string_p = ecma_new_ecma_string_from_lit_cp (lit_cp);
@ -438,7 +444,7 @@ opfunc_var_decl (vm_instr_t instr, /**< instruction */
vm_frame_ctx_t *frame_ctx_p) /**< interpreter context */
{
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (instr.data.var_decl.variable_name,
frame_ctx_p->instrs_p,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);
JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
@ -489,7 +495,8 @@ function_declaration (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
vm_read_instr_counter_from_meta (OPCODE_META_TYPE_FUNCTION_END, frame_ctx_p) + frame_ctx_p->pos);
frame_ctx_p->pos++;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (frame_ctx_p->instrs_p, frame_ctx_p->pos++);
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (frame_ctx_p->bytecode_header_p->instrs_p,
frame_ctx_p->pos++);
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
{
@ -508,7 +515,7 @@ function_declaration (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
ecma_completion_value_t ret_value = ecma_op_function_declaration (frame_ctx_p->lex_env_p,
function_name_string_p,
frame_ctx_p->instrs_p,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos,
formal_params_collection_p,
is_strict,
@ -535,7 +542,7 @@ opfunc_func_decl_n (vm_instr_t instr, /**< instruction */
const ecma_length_t params_number = instr.data.func_decl_n.arg_list;
lit_cpointer_t function_name_lit_cp = serializer_get_literal_cp_by_uid (function_name_idx,
frame_ctx_p->instrs_p,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);
frame_ctx_p->pos++;
@ -587,7 +594,7 @@ opfunc_func_expr_n (vm_instr_t instr, /**< instruction */
frame_ctx_p) + frame_ctx_p->pos);
frame_ctx_p->pos++;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (frame_ctx_p->instrs_p,
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (frame_ctx_p->bytecode_header_p->instrs_p,
frame_ctx_p->pos++);
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
@ -610,7 +617,7 @@ opfunc_func_expr_n (vm_instr_t instr, /**< instruction */
scope_p = ecma_create_decl_lex_env (frame_ctx_p->lex_env_p);
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (function_name_lit_idx,
frame_ctx_p->instrs_p,
frame_ctx_p->bytecode_header_p,
lit_oc);
JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
@ -627,7 +634,7 @@ opfunc_func_expr_n (vm_instr_t instr, /**< instruction */
scope_p,
is_strict,
do_instantiate_arguments_object,
frame_ctx_p->instrs_p,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);
ret_value = set_variable_value (frame_ctx_p, lit_oc,
@ -673,7 +680,7 @@ vm_helper_call_get_call_flags_and_this_arg (vm_frame_ctx_t *int_data_p, /**< int
opcode_call_flags_t call_flags = OPCODE_CALL_FLAGS__EMPTY;
vm_idx_t this_arg_var_idx = VM_IDX_EMPTY;
vm_instr_t next_opcode = vm_get_instr (int_data_p->instrs_p, int_data_p->pos);
vm_instr_t next_opcode = vm_get_instr (int_data_p->bytecode_header_p->instrs_p, int_data_p->pos);
if (next_opcode.op_idx == VM_OP_META
&& next_opcode.data.meta.type == OPCODE_META_TYPE_CALL_SITE_INFO)
{
@ -732,7 +739,9 @@ vm_helper_call_get_call_flags_and_this_arg (vm_frame_ctx_t *int_data_p, /**< int
/* 6.b.i */
ecma_string_t var_name_string;
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (var_idx, int_data_p->instrs_p, var_idx_lit_oc);
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (var_idx,
int_data_p->bytecode_header_p,
var_idx_lit_oc);
ecma_new_ecma_string_on_stack_from_lit_cp (&var_name_string, lit_cp);
ecma_object_t *ref_base_lex_env_p = ecma_op_resolve_reference_base (int_data_p->lex_env_p,
@ -1032,7 +1041,7 @@ opfunc_obj_decl (vm_instr_t instr, /**< instruction */
if (ecma_is_completion_value_empty (evaluate_prop_completion))
{
vm_instr_t next_opcode = vm_get_instr (frame_ctx_p->instrs_p, frame_ctx_p->pos);
vm_instr_t next_opcode = vm_get_instr (frame_ctx_p->bytecode_header_p->instrs_p, frame_ctx_p->pos);
JERRY_ASSERT (next_opcode.op_idx == VM_OP_META);
const opcode_meta_type type = (opcode_meta_type) next_opcode.data.meta.type;
@ -1407,7 +1416,7 @@ opfunc_with (vm_instr_t instr, /**< instruction */
frame_ctx_p->lex_env_p = new_env_p;
#ifndef JERRY_NDEBUG
vm_instr_t meta_opcode = vm_get_instr (frame_ctx_p->instrs_p, with_end_oc);
vm_instr_t meta_opcode = vm_get_instr (frame_ctx_p->bytecode_header_p->instrs_p, with_end_oc);
JERRY_ASSERT (meta_opcode.op_idx == VM_OP_META);
JERRY_ASSERT (meta_opcode.data.meta.type == OPCODE_META_TYPE_END_WITH);
#endif /* !JERRY_NDEBUG */
@ -1496,7 +1505,9 @@ evaluate_arg_for_typeof (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context *
}
else
{
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (var_idx, frame_ctx_p->instrs_p, frame_ctx_p->pos);
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (var_idx,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);
JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
ecma_string_t *var_name_string_p = ecma_new_ecma_string_from_lit_cp (lit_cp);
@ -1612,7 +1623,7 @@ opfunc_delete_var (vm_instr_t instr, /**< instruction */
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (name_lit_idx, frame_ctx_p->instrs_p, lit_oc);
lit_cpointer_t lit_cp = serializer_get_literal_cp_by_uid (name_lit_idx, frame_ctx_p->bytecode_header_p, lit_oc);
JERRY_ASSERT (lit_cp.packed_value != MEM_CP_NULL);
ecma_string_t *name_string_p = ecma_new_ecma_string_from_lit_cp (lit_cp);
@ -1798,7 +1809,7 @@ vm_instr_counter_t
vm_read_instr_counter_from_meta (opcode_meta_type expected_type, /**< expected type of meta instruction */
vm_frame_ctx_t *frame_ctx_p) /**< interpreter context */
{
vm_instr_t meta_opcode = vm_get_instr (frame_ctx_p->instrs_p, frame_ctx_p->pos);
vm_instr_t meta_opcode = vm_get_instr (frame_ctx_p->bytecode_header_p->instrs_p, frame_ctx_p->pos);
JERRY_ASSERT (meta_opcode.data.meta.type == expected_type);
const vm_idx_t data_1 = meta_opcode.data.meta.data_1;

View File

@ -183,12 +183,17 @@ typedef enum
*/
struct vm_instr_t;
/**
* Forward declaration of bytecode data header structure
*/
struct bytecode_data_header_t;
/**
* Context of interpreter, related to a JS stack frame
*/
typedef struct
{
const vm_instr_t *instrs_p; /**< currently executed byte-code array */
const bytecode_data_header_t *bytecode_header_p; /**< currently executed byte-code data */
vm_instr_counter_t pos; /**< current position instruction to execute */
ecma_value_t this_binding; /**< this binding for current context */
ecma_object_t *lex_env_p; /**< current lexical environment */

View File

@ -181,7 +181,7 @@ dump_asm (vm_instr_counter_t oc, vm_instr_t instr)
}
void
pp_op_meta (const vm_instr_t *instrs_p,
pp_op_meta (const bytecode_data_header_t *bytecode_data_p,
vm_instr_counter_t oc,
op_meta opm,
bool rewrite)
@ -379,7 +379,7 @@ pp_op_meta (const vm_instr_t *instrs_p,
while ((int16_t) start >= 0 && !found)
{
start--;
switch (serializer_get_instr (instrs_p, start).op_idx)
switch (serializer_get_instr (bytecode_data_p, start).op_idx)
{
case VM_OP_CALL_N:
case VM_OP_CONSTRUCT_N:
@ -393,7 +393,7 @@ pp_op_meta (const vm_instr_t *instrs_p,
}
}
}
vm_instr_t start_op = serializer_get_instr (instrs_p, start);
vm_instr_t start_op = serializer_get_instr (bytecode_data_p, start);
switch (start_op.op_idx)
{
case VM_OP_CALL_N:
@ -440,7 +440,7 @@ pp_op_meta (const vm_instr_t *instrs_p,
}
for (vm_instr_counter_t counter = start; counter <= oc; counter++)
{
vm_instr_t meta_op = serializer_get_instr (instrs_p, counter);
vm_instr_t meta_op = serializer_get_instr (bytecode_data_p, counter);
switch (meta_op.op_idx)
{

View File

@ -18,10 +18,11 @@
#include "jrt.h"
#ifdef JERRY_ENABLE_PRETTY_PRINTER
#include "bytecode-data.h"
#include "vm.h"
#include "scopes-tree.h"
void pp_op_meta (const vm_instr_t*, vm_instr_counter_t, op_meta, bool);
void pp_op_meta (const bytecode_data_header_t *, vm_instr_counter_t, op_meta, bool);
#endif // JERRY_ENABLE_PRETTY_PRINTER
#endif // PRETTY_PRINTER

View File

@ -13,6 +13,7 @@
* limitations under the License.
*/
#include "bytecode-data.h"
#include "ecma-alloc.h"
#include "ecma-builtins.h"
#include "ecma-gc.h"
@ -24,6 +25,7 @@
#include "mem-allocator.h"
#include "vm.h"
#include "vm-stack.h"
#include "opcodes.h"
/**
* Top (current) interpreter context
@ -46,7 +48,7 @@ static const opfunc __opfuncs[VM_OP__COUNT] =
JERRY_STATIC_ASSERT (sizeof (vm_instr_t) <= 4);
const vm_instr_t *__program = NULL;
const bytecode_data_header_t *__program = NULL;
#ifdef MEM_STATS
static const char *__op_names[VM_OP__COUNT] =
@ -295,7 +297,7 @@ interp_mem_stats_opcode_exit (vm_frame_ctx_t *frame_ctx_p,
frame_ctx_p->context_peak_allocated_pool_chunks = JERRY_MAX (frame_ctx_p->context_peak_allocated_pool_chunks,
pools_stats_after.allocated_chunks);
vm_instr_t instr = vm_get_instr (frame_ctx_p->instrs_p, instr_position);
vm_instr_t instr = vm_get_instr (frame_ctx_p->bytecode_header_p->instrs_p, instr_position);
printf ("%s Allocated heap bytes: %5u -> %5u (%+5d, local %5u, peak %5u)\n",
indent_prefix,
@ -351,7 +353,7 @@ interp_mem_stats_opcode_exit (vm_frame_ctx_t *frame_ctx_p,
* Initialize interpreter.
*/
void
vm_init (const vm_instr_t *program_p, /**< pointer to byte-code program */
vm_init (const bytecode_data_header_t *program_p, /**< pointer to byte-code data */
bool dump_mem_stats) /** dump per-instruction memory usage change statistics */
{
#ifdef MEM_STATS
@ -394,7 +396,7 @@ vm_run_global (void)
bool is_strict = false;
vm_instr_counter_t start_pos = 0;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (__program,
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (__program->instrs_p,
start_pos++);
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
@ -443,11 +445,11 @@ vm_run_global (void)
* @return completion value
*/
ecma_completion_value_t
vm_run_eval (const vm_instr_t *instrs_p, /**< instructions array */
vm_run_eval (const bytecode_data_header_t *bytecode_data_p, /**< byte-code data header */
bool is_direct) /**< is eval called directly? */
{
vm_instr_counter_t first_instr_index = 0u;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (instrs_p,
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (bytecode_data_p->instrs_p,
first_instr_index++);
bool is_strict = ((scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT) != 0);
@ -474,7 +476,7 @@ vm_run_eval (const vm_instr_t *instrs_p, /**< instructions array */
lex_env_p = strict_lex_env_p;
}
ecma_completion_value_t completion = vm_run_from_pos (instrs_p,
ecma_completion_value_t completion = vm_run_from_pos (bytecode_data_p,
first_instr_index,
this_binding,
lex_env_p,
@ -529,12 +531,12 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
|| (run_scope_p->start_oc <= frame_ctx_p->pos
&& frame_ctx_p->pos <= run_scope_p->end_oc));
const vm_instr_t *curr = &frame_ctx_p->instrs_p[frame_ctx_p->pos];
const vm_instr_t *curr = &frame_ctx_p->bytecode_header_p->instrs_p[frame_ctx_p->pos];
#ifdef MEM_STATS
const vm_instr_counter_t instr_pos = frame_ctx_p->pos;
interp_mem_stats_opcode_enter (frame_ctx_p->instrs_p,
interp_mem_stats_opcode_enter (frame_ctx_p->bytecode_header_p->instrs_p,
instr_pos,
&heap_stats_before,
&pools_stats_before);
@ -590,7 +592,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
* Run the code, starting from specified instruction position
*/
ecma_completion_value_t
vm_run_from_pos (const vm_instr_t *instrs_p, /**< byte-code array */
vm_run_from_pos (const bytecode_data_header_t *header_p, /**< byte-code data header */
vm_instr_counter_t start_pos, /**< position of starting instruction */
ecma_value_t this_binding_value, /**< value of 'ThisBinding' */
ecma_object_t *lex_env_p, /**< lexical environment to use */
@ -599,6 +601,7 @@ vm_run_from_pos (const vm_instr_t *instrs_p, /**< byte-code array */
{
ecma_completion_value_t completion;
const vm_instr_t *instrs_p = header_p->instrs_p;
const vm_instr_t *curr = &instrs_p[start_pos];
JERRY_ASSERT (curr->op_idx == VM_OP_REG_VAR_DECL);
@ -612,7 +615,7 @@ vm_run_from_pos (const vm_instr_t *instrs_p, /**< byte-code array */
MEM_DEFINE_LOCAL_ARRAY (regs, regs_num, ecma_value_t);
vm_frame_ctx_t frame_ctx;
frame_ctx.instrs_p = instrs_p;
frame_ctx.bytecode_header_p = header_p;
frame_ctx.pos = (vm_instr_counter_t) (start_pos + 1);
frame_ctx.this_binding = this_binding_value;
frame_ctx.lex_env_p = lex_env_p;

View File

@ -16,17 +16,18 @@
#ifndef VM_H
#define VM_H
#include "bytecode-data.h"
#include "ecma-globals.h"
#include "jrt.h"
#include "opcodes.h"
extern void vm_init (const vm_instr_t* program_p, bool dump_mem_stats);
extern void vm_init (const bytecode_data_header_t *program_p, bool dump_mem_stats);
extern void vm_finalize (void);
extern jerry_completion_code_t vm_run_global (void);
extern ecma_completion_value_t vm_run_eval (const vm_instr_t *instrs_p,
extern ecma_completion_value_t vm_run_eval (const bytecode_data_header_t *bytecode_data_p,
bool is_direct);
extern ecma_completion_value_t vm_loop (vm_frame_ctx_t *frame_ctx_p, vm_run_scope_t *run_scope_p);
extern ecma_completion_value_t vm_run_from_pos (const vm_instr_t *instrs_p,
extern ecma_completion_value_t vm_run_from_pos (const bytecode_data_header_t *header_p,
vm_instr_counter_t start_pos,
ecma_value_t this_binding_value,
ecma_object_t *lex_env_p,

View File

@ -101,7 +101,7 @@ main (int __attr_unused___ argc,
{
TEST_INIT ();
const vm_instr_t *instrs_p;
const bytecode_data_header_t *bytecode_data_p;
jsp_status_t parse_status;
mem_init ();
@ -111,9 +111,9 @@ main (int __attr_unused___ argc,
serializer_init ();
parser_set_show_instrs (true);
parse_status = parser_parse_script ((jerry_api_char_t *) program1, strlen (program1), &instrs_p);
parse_status = parser_parse_script ((jerry_api_char_t *) program1, strlen (program1), &bytecode_data_p);
JERRY_ASSERT (parse_status == JSP_STATUS_OK && instrs_p != NULL);
JERRY_ASSERT (parse_status == JSP_STATUS_OK && bytecode_data_p != NULL);
vm_instr_t instrs[] =
{
@ -128,7 +128,7 @@ main (int __attr_unused___ argc,
getop_ret () // return;
};
JERRY_ASSERT (instrs_equal (instrs_p, instrs, 5));
JERRY_ASSERT (instrs_equal (bytecode_data_p->instrs_p, instrs, 5));
serializer_free ();
@ -137,9 +137,9 @@ main (int __attr_unused___ argc,
serializer_init ();
parser_set_show_instrs (true);
parse_status = parser_parse_script ((jerry_api_char_t *) program2, strlen (program2), &instrs_p);
parse_status = parser_parse_script ((jerry_api_char_t *) program2, strlen (program2), &bytecode_data_p);
JERRY_ASSERT (parse_status == JSP_STATUS_SYNTAX_ERROR && instrs_p == NULL);
JERRY_ASSERT (parse_status == JSP_STATUS_SYNTAX_ERROR && bytecode_data_p == NULL);
serializer_free ();