Split opcode and instruction entities and perform related renamings: opcode_t is now vm_instr_t, opcode position is instruction position, etc.

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
Ruben Ayrapetyan
2015-07-21 19:14:06 +03:00
committed by Evgeny Gavrin
parent 1990762cf0
commit 502f4c4623
43 changed files with 1096 additions and 1085 deletions
+10 -10
View File
@@ -27,7 +27,7 @@
*
* Literal id is its index in 'literals' array of bytecode_data_t structure.
*
* Bytecode, which is kept in the 'opcodes' field, is divided into blocks
* Bytecode, which is kept in the 'instrs' field, is divided into blocks
* of 'BLOCK_SIZE' operands. Every block has its own numbering of literals.
* Literal uid could be in range [0, 127] in every block.
*
@@ -42,27 +42,27 @@ typedef struct __attribute__ ((aligned (MEM_ALIGNMENT)))
{
mem_cpointer_t lit_id_hash_cp; /**< pointer to literal identifiers hash table
* See also: lit_id_hash_table_init */
mem_cpointer_t next_opcodes_cp; /**< pointer to next byte-code memory region */
opcode_counter_t instructions_number; /**< number of instructions in the byte-code array */
} opcodes_header_t;
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;
typedef struct
{
const ecma_char_t *strings_buffer;
const opcode_t *opcodes;
opcode_counter_t opcodes_count;
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 opcodes start
* Macros to get a pointer to bytecode header by pointer to instructions array start
*/
#define GET_BYTECODE_HEADER(opcodes) ((opcodes_header_t *) (((uint8_t *) (opcodes)) - sizeof (opcodes_header_t)))
#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(opcodes) (MEM_CP_GET_POINTER (lit_id_hash_table, \
GET_BYTECODE_HEADER (opcodes)->lit_id_hash_cp))
#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
@@ -23,7 +23,7 @@
* @{
*
* \addtogroup lit_id_hash_table Literal identifiers hash table
* The hash table connects pairs (opcode block, idx_t value) with literal identifiers.
* The hash table connects pairs (instruction block, idx_t value) with literal identifiers.
* @{
*/
@@ -36,7 +36,7 @@ lit_id_hash_table *
lit_id_hash_table_init (uint8_t *table_buffer_p, /**< buffer to initialize hash table in */
size_t buffer_size, /**< size of the buffer */
size_t buckets_count, /**< number of pairs */
size_t blocks_count) /**< number of opcode blocks */
size_t blocks_count) /**< number of instruction blocks */
{
const size_t header_size = JERRY_ALIGNUP (sizeof (lit_id_hash_table), MEM_ALIGNMENT);
const size_t raw_buckets_size = JERRY_ALIGNUP (sizeof (lit_cpointer_t) * buckets_count, MEM_ALIGNMENT);
@@ -62,7 +62,7 @@ lit_id_hash_table_init (uint8_t *table_buffer_p, /**< buffer to initialize hash
*/
size_t
lit_id_hash_table_get_size_for_table (size_t buckets_count, /**< number of pairs */
size_t blocks_count) /**< number of opcode blocks */
size_t blocks_count) /**< number of instructions blocks */
{
const size_t header_size = JERRY_ALIGNUP (sizeof (lit_id_hash_table), MEM_ALIGNMENT);
const size_t raw_buckets_size = JERRY_ALIGNUP (sizeof (lit_cpointer_t) * buckets_count, MEM_ALIGNMENT);
@@ -88,7 +88,7 @@ lit_id_hash_table_free (lit_id_hash_table *table_p) /**< table's header */
void
lit_id_hash_table_insert (lit_id_hash_table *table_p, /**< table's header */
idx_t uid, /**< value of byte-code instruction's argument */
opcode_counter_t oc, /**< opcode counter of the instruction */
vm_instr_counter_t oc, /**< instruction counter of the instruction */
lit_cpointer_t lit_cp) /**< literal identifier */
{
JERRY_ASSERT (table_p != NULL);
@@ -112,7 +112,7 @@ lit_id_hash_table_insert (lit_id_hash_table *table_p, /**< table's header */
lit_cpointer_t
lit_id_hash_table_lookup (lit_id_hash_table *table_p, /**< table's header */
idx_t uid, /**< value of byte-code instruction's argument */
opcode_counter_t oc) /**< opcode counter of the instruction */
vm_instr_counter_t oc) /**< instruction counter of the instruction */
{
JERRY_ASSERT (table_p != NULL);
@@ -31,7 +31,7 @@ typedef struct
lit_id_hash_table *lit_id_hash_table_init (uint8_t*, size_t, size_t, size_t);
size_t lit_id_hash_table_get_size_for_table (size_t, size_t);
void lit_id_hash_table_free (lit_id_hash_table *);
void lit_id_hash_table_insert (lit_id_hash_table *, idx_t, opcode_counter_t, lit_cpointer_t);
lit_cpointer_t lit_id_hash_table_lookup (lit_id_hash_table *, idx_t, opcode_counter_t);
void lit_id_hash_table_insert (lit_id_hash_table *, idx_t, vm_instr_counter_t, lit_cpointer_t);
lit_cpointer_t lit_id_hash_table_lookup (lit_id_hash_table *, idx_t, vm_instr_counter_t);
#endif /* LIT_ID_HASH_TABLE */
+3 -3
View File
@@ -105,8 +105,8 @@ jsp_label_push (jsp_label_t *out_label_p, /**< out: place where label structure
*/
void
jsp_label_rewrite_jumps_and_pop (jsp_label_t *label_p, /**< label to remove (should be on top of stack) */
opcode_counter_t break_tgt_oc) /**< target opcode counter
* for breaks on the label */
vm_instr_counter_t break_tgt_oc) /**< target instruction counter
* for breaks on the label */
{
JERRY_ASSERT (label_p != NULL);
JERRY_ASSERT (break_tgt_oc != MAX_OPCODES);
@@ -228,7 +228,7 @@ jsp_label_add_jump (jsp_label_t *label_p, /**< label to register jump for */
*/
void
jsp_label_setup_continue_target (jsp_label_t *outermost_label_p, /**< the outermost label to setup target for */
opcode_counter_t tgt_oc) /**< target */
vm_instr_counter_t tgt_oc) /**< target */
{
/* There are no labels that could not be targeted with 'break' jumps */
JERRY_ASSERT (tgt_oc != MAX_OPCODES);
+10 -10
View File
@@ -43,7 +43,7 @@ typedef enum
* Jump instructions with target identified by some specific label,
* are linked into singly-linked list.
*
* Pointer to a next element of the list is represented with opcode counter.
* Pointer to a next element of the list is represented with instruction counter.
* stored in instructions linked into the list.
*
*/
@@ -51,13 +51,13 @@ typedef struct jsp_label_t
{
jsp_label_type_flag_t type_mask; /**< label type mask */
token id; /**< label name (TOK_NAME), if type is LABEL_NAMED */
opcode_counter_t continue_tgt_oc; /**< target opcode counter for continues on the label */
opcode_counter_t breaks_list_oc; /**< opcode counter of first 'break' instruction in the list
* of instructions with the target identified by the label */
opcode_counter_t breaks_number; /**< number of 'break' instructions in the list */
opcode_counter_t continues_list_oc; /**< opcode counter of first 'continue' instruction in the list
* of instructions with the target identified by the label */
opcode_counter_t continues_number; /**< number of 'continue' instructions in the list */
vm_instr_counter_t continue_tgt_oc; /**< target instruction counter for continues on the label */
vm_instr_counter_t breaks_list_oc; /**< instruction counter of first 'break' instruction in the list
* of instructions with the target identified by the label */
vm_instr_counter_t breaks_number; /**< number of 'break' instructions in the list */
vm_instr_counter_t continues_list_oc; /**< instruction counter of first 'continue' instruction in the list
* of instructions with the target identified by the label */
vm_instr_counter_t continues_number; /**< number of 'continue' instructions in the list */
jsp_label_t *next_label_p; /**< next label in current label set stack */
bool is_nested_jumpable_border : 1; /**< flag, indicating that this and outer labels
* are not currently accessible with simple jumps,
@@ -70,12 +70,12 @@ extern void jsp_label_finalize (void);
extern void jsp_label_remove_all_labels (void);
extern void jsp_label_push (jsp_label_t *out_label_p, jsp_label_type_flag_t type_mask, token id);
extern void jsp_label_rewrite_jumps_and_pop (jsp_label_t *label_p, opcode_counter_t break_tgt_oc);
extern void jsp_label_rewrite_jumps_and_pop (jsp_label_t *label_p, vm_instr_counter_t break_tgt_oc);
extern jsp_label_t *jsp_label_find (jsp_label_type_flag_t type_mask, token id, bool *out_is_simply_jumpable_p);
extern void jsp_label_add_jump (jsp_label_t *label_p, bool is_simply_jumpable, bool is_break);
extern void jsp_label_setup_continue_target (jsp_label_t *outermost_label_p, opcode_counter_t tgt_oc);
extern void jsp_label_setup_continue_target (jsp_label_t *outermost_label_p, vm_instr_counter_t tgt_oc);
extern bool jsp_label_raise_nested_jumpable_border (void);
extern void jsp_label_remove_nested_jumpable_border (void);
+4 -3
View File
@@ -1826,7 +1826,8 @@ lexer_is_no_escape_sequences_in_token_string (token tok) /**< token of type TOK_
void
lexer_init (const jerry_api_char_t *source, /**< script source */
size_t source_size, /**< script source size in bytes */
bool show_opcodes) /**< flag indicating if to dump opcodes */
bool is_print_source_code) /**< flag indicating whether to dump
* processed source code */
{
empty_token.type = TOK_EMPTY;
empty_token.uid = 0;
@@ -1848,9 +1849,9 @@ lexer_init (const jerry_api_char_t *source, /**< script source */
lexer_set_strict_mode (false);
#ifndef JERRY_NDEBUG
allow_dump_lines = show_opcodes;
allow_dump_lines = is_print_source_code;
#else /* JERRY_NDEBUG */
(void) show_opcodes;
(void) is_print_source_code;
allow_dump_lines = false;
#endif /* JERRY_NDEBUG */
} /* lexer_init */
File diff suppressed because it is too large Load Diff
+11 -11
View File
@@ -186,12 +186,12 @@ operand dump_prop_setter_or_bitwise_or_res (operand, operand);
void dumper_set_break_target (void);
void dumper_set_continue_target (void);
void dumper_set_next_interation_target (void);
opcode_counter_t
vm_instr_counter_t
dump_simple_or_nested_jump_for_rewrite (bool is_simple_jump,
opcode_counter_t next_jump_for_tg_oc);
opcode_counter_t
rewrite_simple_or_nested_jump_and_get_next (opcode_counter_t jump_oc,
opcode_counter_t target_oc);
vm_instr_counter_t next_jump_for_tg_oc);
vm_instr_counter_t
rewrite_simple_or_nested_jump_and_get_next (vm_instr_counter_t jump_oc,
vm_instr_counter_t target_oc);
void dump_continue_iterations_check (operand);
void start_dumping_case_clauses (void);
@@ -207,12 +207,12 @@ operand dump_delete_res (operand, bool, locus);
void dump_typeof (operand, operand);
operand dump_typeof_res (operand);
opcode_counter_t dump_with_for_rewrite (operand);
void rewrite_with (opcode_counter_t);
vm_instr_counter_t dump_with_for_rewrite (operand);
void rewrite_with (vm_instr_counter_t);
void dump_with_end (void);
opcode_counter_t dump_for_in_for_rewrite (operand);
void rewrite_for_in (opcode_counter_t);
vm_instr_counter_t dump_for_in_for_rewrite (operand);
void rewrite_for_in (vm_instr_counter_t);
void dump_for_in_end (void);
void dump_try_for_rewrite (void);
@@ -227,8 +227,8 @@ void dump_throw (operand);
bool dumper_variable_declaration_exists (lit_cpointer_t);
void dump_variable_declaration (lit_cpointer_t);
opcode_counter_t dump_scope_code_flags_for_rewrite (void);
void rewrite_scope_code_flags (opcode_counter_t scope_code_flags_oc,
vm_instr_counter_t dump_scope_code_flags_for_rewrite (void);
void rewrite_scope_code_flags (vm_instr_counter_t scope_code_flags_oc,
opcode_scope_code_flags_t scope_flags);
void dump_reg_var_decl_for_rewrite (void);
+32 -32
View File
@@ -50,7 +50,7 @@ typedef enum
static token tok;
static bool inside_eval = false;
static bool inside_function = false;
static bool parser_show_opcodes = false;
static bool parser_show_instrs = false;
enum
{
@@ -1920,7 +1920,7 @@ jsp_parse_for_statement (jsp_label_t *outermost_stmt_label_p, /**< outermost (fi
// Setup ContinueTarget
jsp_label_setup_continue_target (outermost_stmt_label_p,
serializer_get_current_opcode_counter ());
serializer_get_current_instr_counter ());
// Increment
lexer_seek (increment_loc);
@@ -2027,7 +2027,7 @@ jsp_parse_for_in_statement_iterator (operand *base_p, /**< out: base value of me
* Note:
* Layout of generate byte-code is the following:
* tmp <- Collection (Expression)
* for_in instruction (tmp, opcode counter of for-in end mark)
* for_in instruction (tmp, instruction counter of for-in end mark)
* {
* Assignment of OPCODE_REG_SPECIAL_FOR_IN_PROPERTY_NAME to
* Iterator (VariableDeclarationNoIn / LeftHandSideExpression)
@@ -2081,7 +2081,7 @@ jsp_parse_for_in_statement (jsp_label_t *outermost_stmt_label_p, /**< outermost
skip_token ();
// Dump for-in instruction
opcode_counter_t for_in_oc = dump_for_in_for_rewrite (collection);
vm_instr_counter_t for_in_oc = dump_for_in_for_rewrite (collection);
// Dump assignment VariableDeclarationNoIn / LeftHandSideExpression <- OPCODE_REG_SPECIAL_FOR_IN_PROPERTY_NAME
lexer_seek (iterator_loc);
@@ -2111,7 +2111,7 @@ jsp_parse_for_in_statement (jsp_label_t *outermost_stmt_label_p, /**< outermost
// Setup ContinueTarget
jsp_label_setup_continue_target (outermost_stmt_label_p,
serializer_get_current_opcode_counter ());
serializer_get_current_instr_counter ());
// Write position of for-in end to for_in instruction
rewrite_for_in (for_in_oc);
@@ -2261,7 +2261,7 @@ parse_do_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (f
parse_statement (NULL);
jsp_label_setup_continue_target (outermost_stmt_label_p,
serializer_get_current_opcode_counter ());
serializer_get_current_instr_counter ());
token_after_newlines_must_be_keyword (KW_WHILE);
const operand cond = parse_expression_inside_parens ();
@@ -2290,7 +2290,7 @@ parse_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (firs
parse_statement (NULL);
jsp_label_setup_continue_target (outermost_stmt_label_p,
serializer_get_current_opcode_counter ());
serializer_get_current_instr_counter ());
rewrite_jump_to_end ();
@@ -2318,7 +2318,7 @@ parse_with_statement (void)
bool is_raised = jsp_label_raise_nested_jumpable_border ();
opcode_counter_t with_begin_oc = dump_with_for_rewrite (expr);
vm_instr_counter_t with_begin_oc = dump_with_for_rewrite (expr);
skip_newlines ();
parse_statement (NULL);
rewrite_with (with_begin_oc);
@@ -2442,7 +2442,7 @@ parse_switch_statement (void)
skip_token ();
jsp_label_rewrite_jumps_and_pop (&label,
serializer_get_current_opcode_counter ());
serializer_get_current_instr_counter ());
finish_dumping_case_clauses ();
}
@@ -2595,7 +2595,7 @@ parse_iterational_statement (jsp_label_t *outermost_named_stmt_label_p) /**< out
}
jsp_label_rewrite_jumps_and_pop (&label,
serializer_get_current_opcode_counter ());
serializer_get_current_instr_counter ());
} /* parse_iterational_statement */
/* statement
@@ -2831,7 +2831,7 @@ parse_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (first) lab
parse_statement (outermost_stmt_label_p != NULL ? outermost_stmt_label_p : &label);
jsp_label_rewrite_jumps_and_pop (&label,
serializer_get_current_opcode_counter ());
serializer_get_current_instr_counter ());
}
else
{
@@ -2921,7 +2921,7 @@ preparse_scope (bool is_global)
const locus start_loc = tok.loc;
const token_type end_tt = is_global ? TOK_EOF : TOK_CLOSE_BRACE;
opcode_counter_t scope_code_flags_oc = dump_scope_code_flags_for_rewrite ();
vm_instr_counter_t scope_code_flags_oc = dump_scope_code_flags_for_rewrite ();
bool is_use_strict = false;
bool is_ref_arguments_identifier = false;
@@ -3169,10 +3169,10 @@ 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 opcode_t **out_opcodes_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
const vm_instr_t **out_instrs_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
{
JERRY_ASSERT (out_opcodes_p != NULL);
JERRY_ASSERT (out_instrs_p != NULL);
inside_function = in_function;
inside_eval = in_eval;
@@ -3186,7 +3186,7 @@ parser_parse_program (const jerry_api_char_t *source_p, /**< source code buffer
jsp_mm_init ();
jsp_label_init ();
serializer_set_show_opcodes (parser_show_opcodes);
serializer_set_show_instrs (parser_show_instrs);
dumper_init ();
jsp_early_error_init ();
@@ -3205,7 +3205,7 @@ parser_parse_program (const jerry_api_char_t *source_p, /**< source code buffer
* Operations that could raise an early error can be performed only during execution of the block.
*/
lexer_init (source_p, source_size, parser_show_opcodes);
lexer_init (source_p, source_size, parser_show_instrs);
lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes)));
skip_newlines ();
@@ -3233,7 +3233,7 @@ parser_parse_program (const jerry_api_char_t *source_p, /**< source code buffer
jsp_early_error_free ();
*out_opcodes_p = serializer_merge_scopes_into_bytecode ();
*out_instrs_p = serializer_merge_scopes_into_bytecode ();
dumper_free ();
@@ -3252,7 +3252,7 @@ parser_parse_program (const jerry_api_char_t *source_p, /**< source code buffer
JERRY_ASSERT (!is_parse_finished);
#endif /* !JERRY_NDEBUG */
*out_opcodes_p = NULL;
*out_instrs_p = NULL;
jsp_label_remove_all_labels ();
jsp_mm_free_all ();
@@ -3286,10 +3286,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 opcode_t **opcodes_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
const vm_instr_t **out_instrs_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
{
return parser_parse_program (source, source_size, false, false, false, opcodes_p);
return parser_parse_program (source, source_size, false, false, false, out_instrs_p);
} /* parser_parse_script */
/**
@@ -3303,10 +3303,10 @@ 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 opcode_t **opcodes_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
const vm_instr_t **out_instrs_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
{
return parser_parse_program (source, source_size, false, true, is_strict, opcodes_p);
return parser_parse_program (source, source_size, false, true, is_strict, out_instrs_p);
} /* parser_parse_eval */
/**
@@ -3324,8 +3324,8 @@ 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 opcode_t **out_opcodes_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
const vm_instr_t **out_instrs_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
{
// Process arguments
JERRY_ASSERT (params_count > 0);
@@ -3339,14 +3339,14 @@ parser_parse_new_function (const jerry_api_char_t **params, /**< array of argume
true,
false,
false,
out_opcodes_p);
out_instrs_p);
} /* parser_parse_new_function */
/**
* Tell parser to dump bytecode
* Tell parser whether to dump bytecode
*/
void
parser_set_show_opcodes (bool show_opcodes) /**< flag indicating if to dump bytecode */
parser_set_show_instrs (bool show_instrs) /**< flag indicating whether to dump bytecode */
{
parser_show_opcodes = show_opcodes;
} /* parser_set_show_opcodes */
parser_show_instrs = show_instrs;
} /* parser_set_show_instrs */
+4 -4
View File
@@ -28,9 +28,9 @@ typedef enum
JSP_STATUS_REFERENCE_ERROR /**< ReferenceError early error occured */
} jsp_status_t;
void parser_set_show_opcodes (bool);
jsp_status_t parser_parse_script (const jerry_api_char_t *, size_t, const opcode_t **);
jsp_status_t parser_parse_eval (const jerry_api_char_t *, size_t, bool, const opcode_t **);
jsp_status_t parser_parse_new_function (const jerry_api_char_t **, const size_t *, size_t, const opcode_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 **);
jsp_status_t parser_parse_new_function (const jerry_api_char_t **, const size_t *, size_t, const vm_instr_t **);
#endif /* PARSER_H */
+58 -58
View File
@@ -20,7 +20,7 @@
#define HASH_SIZE 128
static hash_table lit_id_to_uid = null_hash;
static opcode_counter_t global_oc;
static vm_instr_counter_t global_oc;
static idx_t next_uid;
static void
@@ -33,7 +33,7 @@ static idx_t
get_uid (op_meta *op, uint8_t i)
{
JERRY_ASSERT (i < 4);
raw_opcode *raw = (raw_opcode *) &op->op;
raw_instr *raw = (raw_instr *) &op->op;
return raw->uids[i + 1];
}
@@ -41,57 +41,57 @@ static void
set_uid (op_meta *op, uint8_t i, idx_t uid)
{
JERRY_ASSERT (i < 4);
raw_opcode *raw = (raw_opcode *) &op->op;
raw_instr *raw = (raw_instr *) &op->op;
raw->uids[i + 1] = uid;
}
opcode_counter_t
scopes_tree_opcodes_num (scopes_tree t)
vm_instr_counter_t
scopes_tree_instrs_num (scopes_tree t)
{
assert_tree (t);
return t->opcodes_num;
return t->instrs_num;
}
void
scopes_tree_add_op_meta (scopes_tree tree, op_meta op)
{
assert_tree (tree);
linked_list_set_element (tree->opcodes, tree->opcodes_num++, &op);
linked_list_set_element (tree->instrs, tree->instrs_num++, &op);
}
void
scopes_tree_set_op_meta (scopes_tree tree, opcode_counter_t oc, op_meta op)
scopes_tree_set_op_meta (scopes_tree tree, vm_instr_counter_t oc, op_meta op)
{
assert_tree (tree);
JERRY_ASSERT (oc < tree->opcodes_num);
linked_list_set_element (tree->opcodes, oc, &op);
JERRY_ASSERT (oc < tree->instrs_num);
linked_list_set_element (tree->instrs, oc, &op);
}
void
scopes_tree_set_opcodes_num (scopes_tree tree, opcode_counter_t oc)
scopes_tree_set_instrs_num (scopes_tree tree, vm_instr_counter_t oc)
{
assert_tree (tree);
JERRY_ASSERT (oc < tree->opcodes_num);
tree->opcodes_num = oc;
JERRY_ASSERT (oc < tree->instrs_num);
tree->instrs_num = oc;
}
op_meta
scopes_tree_op_meta (scopes_tree tree, opcode_counter_t oc)
scopes_tree_op_meta (scopes_tree tree, vm_instr_counter_t oc)
{
assert_tree (tree);
JERRY_ASSERT (oc < tree->opcodes_num);
return *(op_meta *) linked_list_element (tree->opcodes, oc);
JERRY_ASSERT (oc < tree->instrs_num);
return *(op_meta *) linked_list_element (tree->instrs, oc);
}
opcode_counter_t
scopes_tree_count_opcodes (scopes_tree t)
vm_instr_counter_t
scopes_tree_count_instructions (scopes_tree t)
{
assert_tree (t);
opcode_counter_t res = t->opcodes_num;
vm_instr_counter_t res = t->instrs_num;
for (uint8_t i = 0; i < t->t.children_num; i++)
{
res = (opcode_counter_t) (
res + scopes_tree_count_opcodes (
res = (vm_instr_counter_t) (
res + scopes_tree_count_instructions (
*(scopes_tree *) linked_list_element (t->t.children, i)));
}
return res;
@@ -213,18 +213,18 @@ insert_uids_to_lit_id_map (op_meta *om, uint16_t mask)
}
static op_meta *
extract_op_meta (scopes_tree tree, opcode_counter_t opc_index)
extract_op_meta (scopes_tree tree, vm_instr_counter_t instr_pos)
{
return (op_meta *) linked_list_element (tree->opcodes, opc_index);
return (op_meta *) linked_list_element (tree->instrs, instr_pos);
}
static opcode_t
generate_opcode (scopes_tree tree, opcode_counter_t opc_index, lit_id_hash_table *lit_ids)
static vm_instr_t
generate_instr (scopes_tree tree, vm_instr_counter_t instr_pos, lit_id_hash_table *lit_ids)
{
start_new_block_if_necessary ();
op_meta *om = extract_op_meta (tree, opc_index);
/* Now we should change uids of opcodes.
Since different opcodes has different literals/tmps in different places,
op_meta *om = extract_op_meta (tree, instr_pos);
/* Now we should change uids of instructions.
Since different instructions has different literals/tmps in different places,
we should change only them.
For each case possible literal positions are shown as 0xYYY literal,
where Y is set to '1' when there is a possible literal in this position,
@@ -363,11 +363,11 @@ generate_opcode (scopes_tree tree, opcode_counter_t opc_index, lit_id_hash_table
}
static idx_t
count_new_literals_in_opcode (scopes_tree tree, opcode_counter_t opc_index)
count_new_literals_in_instr (scopes_tree tree, vm_instr_counter_t instr_pos)
{
start_new_block_if_necessary ();
idx_t current_uid = next_uid;
op_meta *om = extract_op_meta (tree, opc_index);
op_meta *om = extract_op_meta (tree, instr_pos);
switch (om->op.op_idx)
{
case VM_OP_PROP_GETTER:
@@ -517,11 +517,11 @@ scopes_tree_count_literals_in_blocks (scopes_tree tree)
global_oc = 0;
assert_tree (tree);
opcode_counter_t opc_index;
vm_instr_counter_t instr_pos;
bool header = true;
for (opc_index = 0; opc_index < tree->opcodes_num; opc_index++)
for (instr_pos = 0; instr_pos < tree->instrs_num; instr_pos++)
{
op_meta *om = extract_op_meta (tree, opc_index);
op_meta *om = extract_op_meta (tree, instr_pos);
if (om->op.op_idx != VM_OP_VAR_DECL
&& om->op.op_idx != VM_OP_META && !header)
{
@@ -531,15 +531,15 @@ scopes_tree_count_literals_in_blocks (scopes_tree tree)
{
header = false;
}
result += count_new_literals_in_opcode (tree, opc_index);
result += count_new_literals_in_instr (tree, instr_pos);
}
for (uint8_t child_id = 0; child_id < tree->t.children_num; child_id++)
{
result += scopes_tree_count_literals_in_blocks (*(scopes_tree *) linked_list_element (tree->t.children, child_id));
}
for (; opc_index < tree->opcodes_num; opc_index++)
for (; instr_pos < tree->instrs_num; instr_pos++)
{
result += count_new_literals_in_opcode (tree, opc_index);
result += count_new_literals_in_instr (tree, instr_pos);
}
return result;
@@ -555,20 +555,20 @@ scopes_tree_count_literals_in_blocks (scopes_tree tree)
Header and var_decls are dumped first,
then we shall recursively dump function declaration,
and finally, other opcodes.
and finally, other instructions.
For each opcodes block (size of block is defined in bytecode-data.h)
For each instructions block (size of block is defined in bytecode-data.h)
literal indexes 'hash' table is filled. */
static void
merge_subscopes (scopes_tree tree, opcode_t *data, lit_id_hash_table *lit_ids)
merge_subscopes (scopes_tree tree, vm_instr_t *data, lit_id_hash_table *lit_ids)
{
assert_tree (tree);
JERRY_ASSERT (data);
opcode_counter_t opc_index;
vm_instr_counter_t instr_pos;
bool header = true;
for (opc_index = 0; opc_index < tree->opcodes_num; opc_index++)
for (instr_pos = 0; instr_pos < tree->instrs_num; instr_pos++)
{
op_meta *om = extract_op_meta (tree, opc_index);
op_meta *om = extract_op_meta (tree, instr_pos);
if (om->op.op_idx != VM_OP_VAR_DECL
&& om->op.op_idx != VM_OP_META && !header)
{
@@ -578,7 +578,7 @@ merge_subscopes (scopes_tree tree, opcode_t *data, lit_id_hash_table *lit_ids)
{
header = false;
}
data[global_oc] = generate_opcode (tree, opc_index, lit_ids);
data[global_oc] = generate_instr (tree, instr_pos, lit_ids);
global_oc++;
}
for (uint8_t child_id = 0; child_id < tree->t.children_num; child_id++)
@@ -586,9 +586,9 @@ merge_subscopes (scopes_tree tree, opcode_t *data, lit_id_hash_table *lit_ids)
merge_subscopes (*(scopes_tree *) linked_list_element (tree->t.children, child_id),
data, lit_ids);
}
for (; opc_index < tree->opcodes_num; opc_index++)
for (; instr_pos < tree->instrs_num; instr_pos++)
{
data[global_oc] = generate_opcode (tree, opc_index, lit_ids);
data[global_oc] = generate_instr (tree, instr_pos, lit_ids);
global_oc++;
}
}
@@ -596,11 +596,11 @@ merge_subscopes (scopes_tree tree, opcode_t *data, lit_id_hash_table *lit_ids)
/* Postparser.
Init literal indexes 'hash' table.
Reorder function declarations.
Rewrite opcodes' temporary uids with their keys in literal indexes 'hash' table. */
opcode_t *
Rewrite instructions' temporary uids with their keys in literal indexes 'hash' table. */
vm_instr_t *
scopes_tree_raw_data (scopes_tree tree, /**< scopes tree to convert to byte-code array */
uint8_t *buffer_p, /**< buffer for byte-code array and literal identifiers hash table */
size_t opcodes_array_size, /**< size of space for byte-code array */
size_t instructions_array_size, /**< size of space for byte-code array */
lit_id_hash_table *lit_ids) /**< literal identifiers hash table */
{
JERRY_ASSERT (lit_ids);
@@ -614,14 +614,14 @@ 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 (opcodes_array_size >=
sizeof (opcodes_header_t) + (size_t) (scopes_tree_count_opcodes (tree)) * sizeof (opcode_t));
JERRY_ASSERT (instructions_array_size >=
sizeof (insts_data_header_t) + (size_t) (scopes_tree_count_instructions (tree)) * sizeof (vm_instr_t));
opcodes_header_t *opcodes_data = (opcodes_header_t *) buffer_p;
memset (opcodes_data, 0, opcodes_array_size);
insts_data_header_t *opcodes_data = (insts_data_header_t *) buffer_p;
memset (opcodes_data, 0, instructions_array_size);
opcode_t *opcodes = (opcode_t *)(((uint8_t*) opcodes_data) + sizeof (opcodes_header_t));
merge_subscopes (tree, opcodes, lit_ids);
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)
{
hash_table_free (lit_id_to_uid);
@@ -630,7 +630,7 @@ scopes_tree_raw_data (scopes_tree tree, /**< scopes tree to convert to byte-code
MEM_CP_SET_POINTER (opcodes_data->lit_id_hash_cp, lit_ids);
return opcodes;
return instrs;
} /* scopes_tree_raw_data */
void
@@ -666,9 +666,9 @@ scopes_tree_init (scopes_tree parent)
JERRY_ASSERT (*(scopes_tree *) added == tree);
parent->t.children_num++;
}
tree->opcodes_num = 0;
tree->instrs_num = 0;
tree->strict_mode = 0;
tree->opcodes = linked_list_init (sizeof (op_meta));
tree->instrs = linked_list_init (sizeof (op_meta));
return tree;
}
@@ -684,6 +684,6 @@ scopes_tree_free (scopes_tree tree)
}
linked_list_free (tree->t.children);
}
linked_list_free (tree->opcodes);
linked_list_free (tree->instrs);
jsp_mm_free (tree);
}
+9 -9
View File
@@ -29,7 +29,7 @@
typedef struct
{
lit_cpointer_t lit_id[3];
opcode_t op;
vm_instr_t op;
} op_meta;
typedef struct tree_header
@@ -42,8 +42,8 @@ typedef struct tree_header
typedef struct
{
tree_header t;
linked_list opcodes;
opcode_counter_t opcodes_num;
linked_list instrs;
vm_instr_counter_t instrs_num;
unsigned strict_mode:1;
} scopes_tree_int;
@@ -51,14 +51,14 @@ typedef scopes_tree_int * scopes_tree;
scopes_tree scopes_tree_init (scopes_tree);
void scopes_tree_free (scopes_tree);
opcode_counter_t scopes_tree_opcodes_num (scopes_tree);
vm_instr_counter_t scopes_tree_instrs_num (scopes_tree);
void scopes_tree_add_op_meta (scopes_tree, op_meta);
void scopes_tree_set_op_meta (scopes_tree, opcode_counter_t, op_meta);
void scopes_tree_set_opcodes_num (scopes_tree, opcode_counter_t);
op_meta scopes_tree_op_meta (scopes_tree, opcode_counter_t);
void scopes_tree_set_op_meta (scopes_tree, vm_instr_counter_t, op_meta);
void scopes_tree_set_instrs_num (scopes_tree, vm_instr_counter_t);
op_meta scopes_tree_op_meta (scopes_tree, vm_instr_counter_t);
size_t scopes_tree_count_literals_in_blocks (scopes_tree);
opcode_counter_t scopes_tree_count_opcodes (scopes_tree);
opcode_t *scopes_tree_raw_data (scopes_tree, uint8_t *, size_t, lit_id_hash_table *);
vm_instr_counter_t scopes_tree_count_instructions (scopes_tree);
vm_instr_t *scopes_tree_raw_data (scopes_tree, uint8_t *, size_t, lit_id_hash_table *);
void scopes_tree_set_strict_mode (scopes_tree, bool);
bool scopes_tree_strict_mode (scopes_tree);
+57 -57
View File
@@ -20,14 +20,14 @@
static bytecode_data_t bytecode_data;
static scopes_tree current_scope;
static bool print_opcodes;
static bool print_instrs;
static void
serializer_print_opcodes (const opcode_t *opcodes_p,
size_t opcodes_count);
serializer_print_instrs (const vm_instr_t *instrs_p,
size_t instrs_count);
op_meta
serializer_get_op_meta (opcode_counter_t oc)
serializer_get_op_meta (vm_instr_counter_t oc)
{
JERRY_ASSERT (current_scope);
return scopes_tree_op_meta (current_scope, oc);
@@ -38,22 +38,22 @@ serializer_get_op_meta (opcode_counter_t oc)
*
* @return byte-code instruction
*/
opcode_t
serializer_get_opcode (const opcode_t *opcodes_p, /**< pointer to byte-code array (or NULL,
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) */
opcode_counter_t oc) /**< opcode counter of the intruction */
vm_instr_counter_t oc) /**< position of the intruction */
{
if (opcodes_p == NULL)
if (instrs_p == NULL)
{
return serializer_get_op_meta (oc).op;
}
else
{
JERRY_ASSERT (oc < GET_BYTECODE_HEADER (opcodes_p)->instructions_number);
return opcodes_p[oc];
JERRY_ASSERT (oc < GET_BYTECODE_HEADER (instrs_p)->instructions_number);
return instrs_p[oc];
}
} /* serializer_get_opcode */
} /* serializer_get_instr */
/**
* Convert literal id (operand value of instruction) to compressed pointer to literal
@@ -66,10 +66,10 @@ serializer_get_opcode (const opcode_t *opcodes_p, /**< pointer to byte-code arra
*/
lit_cpointer_t
serializer_get_literal_cp_by_uid (uint8_t id, /**< literal idx */
const opcode_t *opcodes_p, /**< pointer to bytecode */
opcode_counter_t oc) /**< position in the bytecode */
const vm_instr_t *instrs_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 (opcodes_p == NULL ? bytecode_data.opcodes : opcodes_p);
lit_id_hash_table *lit_id_hash = GET_HASH_TABLE_FOR_BYTECODE (instrs_p == NULL ? bytecode_data.instrs_p : instrs_p);
if (lit_id_hash == null_hash)
{
return INVALID_LITERAL;
@@ -89,84 +89,84 @@ serializer_set_scope (scopes_tree new_scope)
current_scope = new_scope;
}
const opcode_t *
const vm_instr_t *
serializer_merge_scopes_into_bytecode (void)
{
bytecode_data.opcodes_count = scopes_tree_count_opcodes (current_scope);
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.opcodes_count / BLOCK_SIZE + 1;
const opcode_counter_t opcodes_count = scopes_tree_count_opcodes (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 opcodes_array_size = JERRY_ALIGNUP (sizeof (opcodes_header_t) + opcodes_count * sizeof (opcode_t),
MEM_ALIGNMENT);
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);
uint8_t *buffer_p = (uint8_t*) mem_heap_alloc_block (opcodes_array_size + lit_id_hash_table_size,
uint8_t *buffer_p = (uint8_t*) mem_heap_alloc_block (bytecode_array_size + lit_id_hash_table_size,
MEM_HEAP_ALLOC_LONG_TERM);
lit_id_hash_table *lit_id_hash = lit_id_hash_table_init (buffer_p + opcodes_array_size,
lit_id_hash_table *lit_id_hash = lit_id_hash_table_init (buffer_p + bytecode_array_size,
lit_id_hash_table_size,
buckets_count, blocks_count);
const opcode_t *opcodes_p = scopes_tree_raw_data (current_scope, buffer_p, opcodes_array_size, lit_id_hash);
const vm_instr_t *instrs_p = scopes_tree_raw_data (current_scope, buffer_p, bytecode_array_size, lit_id_hash);
opcodes_header_t *header_p = (opcodes_header_t*) buffer_p;
MEM_CP_SET_POINTER (header_p->next_opcodes_cp, bytecode_data.opcodes);
header_p->instructions_number = opcodes_count;
bytecode_data.opcodes = opcodes_p;
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;
if (print_opcodes)
if (print_instrs)
{
lit_dump_literals ();
serializer_print_opcodes (opcodes_p, bytecode_data.opcodes_count);
serializer_print_instrs (instrs_p, bytecode_data.instrs_count);
}
return opcodes_p;
return instrs_p;
}
void
serializer_dump_op_meta (op_meta op)
{
JERRY_ASSERT (scopes_tree_opcodes_num (current_scope) < MAX_OPCODES);
JERRY_ASSERT (scopes_tree_instrs_num (current_scope) < MAX_OPCODES);
scopes_tree_add_op_meta (current_scope, op);
#ifdef JERRY_ENABLE_PRETTY_PRINTER
if (print_opcodes)
if (print_instrs)
{
pp_op_meta (NULL, (opcode_counter_t) (scopes_tree_opcodes_num (current_scope) - 1), op, false);
pp_op_meta (NULL, (vm_instr_counter_t) (scopes_tree_instrs_num (current_scope) - 1), op, false);
}
#endif
}
opcode_counter_t
serializer_get_current_opcode_counter (void)
vm_instr_counter_t
serializer_get_current_instr_counter (void)
{
return scopes_tree_opcodes_num (current_scope);
return scopes_tree_instrs_num (current_scope);
}
opcode_counter_t
serializer_count_opcodes_in_subscopes (void)
vm_instr_counter_t
serializer_count_instrs_in_subscopes (void)
{
return (opcode_counter_t) (scopes_tree_count_opcodes (current_scope) - scopes_tree_opcodes_num (current_scope));
return (vm_instr_counter_t) (scopes_tree_count_instructions (current_scope) - scopes_tree_instrs_num (current_scope));
}
void
serializer_set_writing_position (opcode_counter_t oc)
serializer_set_writing_position (vm_instr_counter_t oc)
{
scopes_tree_set_opcodes_num (current_scope, oc);
scopes_tree_set_instrs_num (current_scope, oc);
}
void
serializer_rewrite_op_meta (const opcode_counter_t loc, op_meta op)
serializer_rewrite_op_meta (const vm_instr_counter_t loc, op_meta op)
{
scopes_tree_set_op_meta (current_scope, loc, op);
#ifdef JERRY_ENABLE_PRETTY_PRINTER
if (print_opcodes)
if (print_instrs)
{
pp_op_meta (NULL, loc, op, true);
}
@@ -174,25 +174,25 @@ serializer_rewrite_op_meta (const opcode_counter_t loc, op_meta op)
}
static void
serializer_print_opcodes (const opcode_t *opcodes_p,
size_t opcodes_count)
serializer_print_instrs (const vm_instr_t *instrs_p,
size_t instrs_count)
{
#ifdef JERRY_ENABLE_PRETTY_PRINTER
for (opcode_counter_t loc = 0; loc < opcodes_count; loc++)
for (vm_instr_counter_t loc = 0; loc < instrs_count; loc++)
{
op_meta opm;
opm.op = opcodes_p[loc];
opm.op = instrs_p[loc];
for (int i = 0; i < 3; i++)
{
opm.lit_id[i] = NOT_A_LITERAL;
}
pp_op_meta (opcodes_p, loc, opm, false);
pp_op_meta (instrs_p, loc, opm, false);
}
#else
(void) opcodes_p;
(void) opcodes_count;
(void) instrs_p;
(void) instrs_count;
#endif
}
@@ -200,17 +200,17 @@ void
serializer_init ()
{
current_scope = NULL;
print_opcodes = false;
print_instrs = false;
bytecode_data.strings_buffer = NULL;
bytecode_data.opcodes = NULL;
bytecode_data.instrs_p = NULL;
lit_init ();
}
void serializer_set_show_opcodes (bool show_opcodes)
void serializer_set_show_instrs (bool show_instrs)
{
print_opcodes = show_opcodes;
print_instrs = show_instrs;
}
void
@@ -223,10 +223,10 @@ serializer_free (void)
lit_finalize ();
while (bytecode_data.opcodes != NULL)
while (bytecode_data.instrs_p != NULL)
{
opcodes_header_t *header_p = GET_BYTECODE_HEADER (bytecode_data.opcodes);
bytecode_data.opcodes = MEM_CP_GET_POINTER (opcode_t, header_p->next_opcodes_cp);
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);
mem_heap_free_block (header_p);
}
+9 -9
View File
@@ -23,18 +23,18 @@
#include "scopes-tree.h"
void serializer_init ();
void serializer_set_show_opcodes (bool show_opcodes);
op_meta serializer_get_op_meta (opcode_counter_t);
opcode_t serializer_get_opcode (const opcode_t*, opcode_counter_t);
lit_cpointer_t serializer_get_literal_cp_by_uid (uint8_t, const opcode_t*, opcode_counter_t);
void serializer_set_show_instrs (bool show_instrs);
op_meta serializer_get_op_meta (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 *);
void serializer_set_scope (scopes_tree);
const opcode_t *serializer_merge_scopes_into_bytecode (void);
const vm_instr_t *serializer_merge_scopes_into_bytecode (void);
void serializer_dump_op_meta (op_meta);
opcode_counter_t serializer_get_current_opcode_counter (void);
opcode_counter_t serializer_count_opcodes_in_subscopes (void);
void serializer_set_writing_position (opcode_counter_t);
void serializer_rewrite_op_meta (opcode_counter_t, op_meta);
vm_instr_counter_t serializer_get_current_instr_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_free (void);
#endif // SERIALIZER_H