Refactor opcodes-dumper to not use C++ features.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.u-szeged@partner.samsung.com
This commit is contained in:
Roland Takacs
2016-01-18 16:03:39 +01:00
parent 18d0d8c376
commit 70a67797d2
4 changed files with 784 additions and 762 deletions
+7 -7
View File
@@ -116,8 +116,8 @@ jsp_early_error_start_checking_of_prop_names (void)
void
jsp_early_error_add_prop_name (jsp_operand_t op, prop_type pt)
{
JERRY_ASSERT (op.is_string_lit_operand ());
STACK_PUSH (props, create_prop_literal (lit_get_literal_by_cp (op.get_literal ()), pt));
JERRY_ASSERT (jsp_is_string_lit_operand (op));
STACK_PUSH (props, create_prop_literal (lit_get_literal_by_cp (jsp_operand_get_literal (op)), pt));
}
void
@@ -210,14 +210,14 @@ jsp_early_error_check_for_eval_and_arguments_in_strict_mode (jsp_operand_t op, b
{
lit_cpointer_t lit_cp;
if (op.is_string_lit_operand ()
|| op.is_number_lit_operand ())
if (jsp_is_string_lit_operand (op)
|| jsp_is_number_lit_operand (op))
{
lit_cp = op.get_literal ();
lit_cp = jsp_operand_get_literal (op);
}
else if (op.is_identifier_operand ())
else if (jsp_is_identifier_operand (op))
{
lit_cp = op.get_identifier_name ();
lit_cp = jsp_operand_get_identifier_name (op);
}
else
{
+587 -107
View File
@@ -64,6 +64,484 @@ static vm_idx_t jsp_reg_max_for_args;
*/
bool is_print_instrs = false;
/**
* Construct uninitialized operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_uninitialized_operand (void)
{
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_UNINITIALIZED;
return ret;
} /* jsp_make_uninitialized_operand */
/**
* Construct empty operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_empty_operand (void)
{
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_EMPTY;
return ret;
} /* jsp_make_empty_operand */
/**
* Construct ThisBinding operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_this_operand (void)
{
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_THIS_BINDING;
return ret;
} /* jsp_make_this_operand */
/**
* Construct unknown operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_unknown_operand (void)
{
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_UNKNOWN;
return ret;
} /* jsp_make_unknown_operand */
/**
* Construct idx-constant operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_idx_const_operand (vm_idx_t cnst) /**< integer in vm_idx_t range */
{
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_IDX_CONST;
ret.data.idx_const = cnst;
return ret;
} /* jsp_make_idx_const_operand */
/**
* Construct small integer operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_smallint_operand (uint8_t integer_value) /**< small integer value */
{
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_SMALLINT;
ret.data.smallint_value = integer_value;
return ret;
} /* jsp_make_smallint_operand */
/**
* Construct simple ecma value operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_simple_value_operand (ecma_simple_value_t simple_value) /**< simple ecma value */
{
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_SIMPLE_VALUE;
ret.data.simple_value = simple_value;
return ret;
} /* jsp_make_simple_value_operand */
/**
* Construct string literal operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_string_lit_operand (lit_cpointer_t lit_id) /**< literal identifier */
{
JERRY_ASSERT (lit_id.packed_value != NOT_A_LITERAL.packed_value);
#ifndef JERRY_NDEBUG
lit_literal_t lit = lit_get_literal_by_cp (lit_id);
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit)
|| RCS_RECORD_IS_MAGIC_STR (lit)
|| RCS_RECORD_IS_MAGIC_STR_EX (lit));
#endif /* !JERRY_NDEBUG */
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_STRING_LITERAL;
ret.data.lit_id = lit_id;
return ret;
} /* jsp_make_string_lit_operand */
/**
* Construct RegExp literal operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_regexp_lit_operand (lit_cpointer_t lit_id) /**< literal identifier */
{
JERRY_ASSERT (lit_id.packed_value != NOT_A_LITERAL.packed_value);
#ifndef JERRY_NDEBUG
lit_literal_t lit = lit_get_literal_by_cp (lit_id);
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit)
|| RCS_RECORD_IS_MAGIC_STR (lit)
|| RCS_RECORD_IS_MAGIC_STR_EX (lit));
#endif /* !JERRY_NDEBUG */
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_REGEXP_LITERAL;
ret.data.lit_id = lit_id;
return ret;
} /* jsp_make_regexp_lit_operand */
/**
* Construct number literal operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_number_lit_operand (lit_cpointer_t lit_id) /**< literal identifier */
{
JERRY_ASSERT (lit_id.packed_value != NOT_A_LITERAL.packed_value);
#ifndef JERRY_NDEBUG
lit_literal_t lit = lit_get_literal_by_cp (lit_id);
JERRY_ASSERT (RCS_RECORD_IS_NUMBER (lit));
#endif /* !JERRY_NDEBUG */
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_NUMBER_LITERAL;
ret.data.lit_id = lit_id;
return ret;
} /* jsp_make_number_lit_operand */
/**
* Construct identifier reference operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_identifier_operand (lit_cpointer_t lit_id) /**< literal identifier */
{
JERRY_ASSERT (lit_id.packed_value != NOT_A_LITERAL.packed_value);
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_IDENTIFIER;
ret.data.identifier = lit_id;
return ret;
} /* jsp_make_identifier_operand */
/**
* Construct register operand
*
* @return constructed operand
*/
jsp_operand_t
jsp_make_reg_operand (vm_idx_t reg_index) /**< register index */
{
/*
* The following check currently leads to 'comparison is always true
* due to limited range of data type' warning, so it is turned off.
*
* If VM_IDX_GENERAL_VALUE_FIRST is changed to value greater than 0,
* the check should be restored.
*/
// JERRY_ASSERT (reg_index >= VM_IDX_GENERAL_VALUE_FIRST);
JERRY_STATIC_ASSERT (VM_IDX_GENERAL_VALUE_FIRST == 0);
JERRY_ASSERT (reg_index <= VM_IDX_GENERAL_VALUE_LAST);
jsp_operand_t ret;
ret.type = JSP_OPERAND_TYPE_TMP;
ret.data.uid = reg_index;
return ret;
} /* jsp_make_reg_operand */
/**
* Is it empty operand?
*
* @return true / false
*/
bool
jsp_is_empty_operand (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
return (operand.type == JSP_OPERAND_TYPE_EMPTY);
} /* jsp_is_empty_operand */
/**
* Is it ThisBinding operand?
*
* @return true / false
*/
bool
jsp_is_this_operand (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
return (operand.type == JSP_OPERAND_TYPE_THIS_BINDING);
} /* jsp_is_this_operand */
/**
* Is it unknown operand?
*
* @return true / false
*/
bool
jsp_is_unknown_operand (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
return (operand.type == JSP_OPERAND_TYPE_UNKNOWN);
} /* jsp_is_unknown_operand */
/**
* Is it idx-constant operand?
*
* @return true / false
*/
bool
jsp_is_idx_const_operand (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
return (operand.type == JSP_OPERAND_TYPE_IDX_CONST);
} /* jsp_is_idx_const_operand */
/**
* Is it byte-code register operand?
*
* @return true / false
*/
bool
jsp_is_register_operand (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
return (operand.type == JSP_OPERAND_TYPE_TMP);
} /* jsp_is_register_operand */
/**
* Is it simple ecma value operand?
*
* @return true / false
*/
bool
jsp_is_simple_value_operand (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
return (operand.type == JSP_OPERAND_TYPE_SIMPLE_VALUE);
} /* jsp_is_simple_value_operand */
/**
* Is it small integer operand?
*
* @return true / false
*/
bool
jsp_is_smallint_operand (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
return (operand.type == JSP_OPERAND_TYPE_SMALLINT);
} /* jsp_is_smallint_operand */
/**
* Is it number literal operand?
*
* @return true / false
*/
bool
jsp_is_number_lit_operand (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
return (operand.type == JSP_OPERAND_TYPE_NUMBER_LITERAL);
} /* jsp_is_number_lit_operand */
/**
* Is it string literal operand?
*
* @return true / false
*/
bool
jsp_is_string_lit_operand (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
return (operand.type == JSP_OPERAND_TYPE_STRING_LITERAL);
} /* jsp_is_string_lit_operand */
/**
* Is it RegExp literal operand?
*
* @return true / false
*/
bool
jsp_is_regexp_lit_operand (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
return (operand.type == JSP_OPERAND_TYPE_REGEXP_LITERAL);
} /* jsp_is_regexp_lit_operand */
/**
* Is it identifier reference operand?
*
* @return true / false
*/
bool
jsp_is_identifier_operand (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
return (operand.type == JSP_OPERAND_TYPE_IDENTIFIER);
} /* jsp_is_identifier_operand */
/**
* Get string literal - name of Identifier reference
*
* @return literal identifier
*/
lit_cpointer_t
jsp_operand_get_identifier_name (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (jsp_is_identifier_operand (operand));
return (operand.data.identifier);
} /* jsp_operand_get_identifier_name */
/**
* Get idx for operand
*
* @return VM_IDX_REWRITE_LITERAL_UID (for LITERAL),
* or register index (for TMP).
*/
vm_idx_t
jsp_operand_get_idx (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
if (operand.type == JSP_OPERAND_TYPE_TMP)
{
return operand.data.uid;
}
if (operand.type == JSP_OPERAND_TYPE_STRING_LITERAL || operand.type == JSP_OPERAND_TYPE_NUMBER_LITERAL)
{
return VM_IDX_REWRITE_LITERAL_UID;
}
if (operand.type == JSP_OPERAND_TYPE_THIS_BINDING)
{
return VM_REG_SPECIAL_THIS_BINDING;
}
JERRY_ASSERT (operand.type == JSP_OPERAND_TYPE_EMPTY);
return VM_IDX_EMPTY;
} /* jsp_operand_get_idx */
/**
* Get literal from operand
*
* @return literal identifier (for LITERAL),
* or NOT_A_LITERAL (for TMP).
*/
lit_cpointer_t
jsp_operand_get_literal (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (operand.type != JSP_OPERAND_TYPE_UNINITIALIZED);
if (operand.type == JSP_OPERAND_TYPE_TMP)
{
return NOT_A_LITERAL;
}
if (operand.type == JSP_OPERAND_TYPE_STRING_LITERAL
|| operand.type == JSP_OPERAND_TYPE_NUMBER_LITERAL
|| operand.type == JSP_OPERAND_TYPE_REGEXP_LITERAL)
{
return operand.data.lit_id;
}
JERRY_ASSERT (operand.type == JSP_OPERAND_TYPE_EMPTY);
return NOT_A_LITERAL;
} /* jsp_operand_get_literal */
/**
* Get constant from idx-constant operand
*
* @return an integer
*/
vm_idx_t
jsp_operand_get_idx_const (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (jsp_is_idx_const_operand (operand));
return operand.data.idx_const;
} /* jsp_operand_get_idx_const */
/**
* Get small integer constant from operand
*
* @return an integer
*/
uint8_t
jsp_operand_get_smallint_value (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (jsp_is_smallint_operand (operand));
return operand.data.smallint_value;
} /* jsp_operand_get_smallint_value */
/**
* Get simple value from operand
*
* @return a simple ecma value
*/
ecma_simple_value_t
jsp_operand_get_simple_value (jsp_operand_t operand) /**< operand */
{
JERRY_ASSERT (jsp_is_simple_value_operand (operand));
return (ecma_simple_value_t) operand.data.simple_value;
} /* jsp_operand_get_simple_value */
/**
* Determine if operand with specified index could be encoded as a literal
*
@@ -290,8 +768,6 @@ count_new_literals_in_instr (jsp_ctx_t *ctx_p, /**< parser context */
}
} /* count_new_literals_in_instr */
static void dumper_dump_op_meta (jsp_ctx_t *, op_meta);
/**
* Allocate next register for intermediate value
*
@@ -544,7 +1020,7 @@ dumper_dump_op_meta (jsp_ctx_t *ctx_p, /**< parser context */
{
pp_op_meta (bc_header_p, bc_header_p->instrs_count, opm, false);
}
#endif
#endif /* JERRY_ENABLE_PRETTY_PRINTER */
vm_instr_t *new_instr_place_p = bc_header_p->instrs_p + bc_header_p->instrs_count;
@@ -584,7 +1060,7 @@ dumper_rewrite_op_meta (jsp_ctx_t *ctx_p, /**< parser context */
{
pp_op_meta (bc_header_p, loc, opm, true);
}
#endif
#endif /* JERRY_ENABLE_PRETTY_PRINTER */
}
} /* dumper_rewrite_op_meta */
@@ -826,45 +1302,45 @@ jsp_dmp_gen_instr (jsp_ctx_t *ctx_p, /**< parser context */
for (size_t i = 0; i < ops_num; i++)
{
if (ops[i].is_empty_operand ())
if (jsp_is_empty_operand (ops[i]))
{
instr.data.raw_args[i] = VM_IDX_EMPTY;
}
else if (ops[i].is_unknown_operand ())
else if (jsp_is_unknown_operand (ops[i]))
{
instr.data.raw_args[i] = VM_IDX_REWRITE_GENERAL_CASE;
}
else if (ops[i].is_idx_const_operand ())
else if (jsp_is_idx_const_operand (ops[i]))
{
instr.data.raw_args[i] = ops[i].get_idx_const ();
instr.data.raw_args[i] = jsp_operand_get_idx_const (ops[i]);
}
else if (ops[i].is_smallint_operand ())
else if (jsp_is_smallint_operand (ops[i]))
{
instr.data.raw_args[i] = ops[i].get_smallint_value ();
instr.data.raw_args[i] = jsp_operand_get_smallint_value (ops[i]);
}
else if (ops[i].is_simple_value_operand ())
else if (jsp_is_simple_value_operand (ops[i]))
{
instr.data.raw_args[i] = ops[i].get_simple_value ();
instr.data.raw_args[i] = jsp_operand_get_simple_value (ops[i]);
}
else if (ops[i].is_register_operand () || ops[i].is_this_operand ())
else if (jsp_is_register_operand (ops[i]) || jsp_is_this_operand (ops[i]))
{
instr.data.raw_args[i] = ops[i].get_idx ();
instr.data.raw_args[i] = jsp_operand_get_idx (ops[i]);
}
else
{
lit_cpointer_t lit_cp;
if (ops[i].is_identifier_operand ())
if (jsp_is_identifier_operand (ops[i]))
{
lit_cp = ops[i].get_identifier_name ();
lit_cp = jsp_operand_get_identifier_name (ops[i]);
}
else
{
JERRY_ASSERT (ops[i].is_number_lit_operand ()
|| ops[i].is_string_lit_operand ()
|| ops[i].is_regexp_lit_operand ());
JERRY_ASSERT (jsp_is_number_lit_operand (ops[i])
|| jsp_is_string_lit_operand (ops[i])
|| jsp_is_regexp_lit_operand (ops[i]));
lit_cp = ops[i].get_literal ();
lit_cp = jsp_operand_get_literal (ops[i]);
}
vm_idx_t idx = VM_IDX_REWRITE_LITERAL_UID;
@@ -908,15 +1384,15 @@ jsp_dmp_create_op_meta (jsp_ctx_t *ctx_p, /**< parser context */
for (size_t i = 0; i < ops_num; i++)
{
if (ops[i].is_number_lit_operand ()
|| ops[i].is_string_lit_operand ()
|| ops[i].is_regexp_lit_operand ())
if (jsp_is_number_lit_operand (ops[i])
|| jsp_is_string_lit_operand (ops[i])
|| jsp_is_regexp_lit_operand (ops[i]))
{
ret.lit_id[i] = ops[i].get_literal ();
ret.lit_id[i] = jsp_operand_get_literal (ops[i]);
}
else if (ops[i].is_identifier_operand ())
else if (jsp_is_identifier_operand (ops[i]))
{
ret.lit_id[i] = ops[i].get_identifier_name ();
ret.lit_id[i] = jsp_operand_get_identifier_name (ops[i]);
}
else
{
@@ -1006,7 +1482,7 @@ jsp_dmp_create_op_meta_3 (jsp_ctx_t *ctx_p, /**< parser context */
jsp_operand_t
tmp_operand (void)
{
return jsp_operand_t::make_reg_operand (jsp_alloc_reg_for_temp ());
return jsp_make_reg_operand (jsp_alloc_reg_for_temp ());
} /* tmp_operand */
/**
@@ -1078,7 +1554,7 @@ get_diff_from (jsp_ctx_t *ctx_p, /**< parser context */
jsp_operand_t
empty_operand (void)
{
return jsp_operand_t::make_empty_operand ();
return jsp_make_empty_operand ();
} /* empty_operand */
/**
@@ -1087,7 +1563,7 @@ empty_operand (void)
bool
operand_is_empty (jsp_operand_t op) /**< operand */
{
return op.is_empty_operand ();
return jsp_is_empty_operand (op);
} /* operand_is_empty */
/**
@@ -1183,10 +1659,14 @@ dumper_is_eval_literal (jsp_operand_t obj) /**< byte-code operand */
/*
* FIXME: Switch to corresponding magic string
*/
bool is_eval_lit = (obj.is_identifier_operand ()
&& lit_literal_equal_type_cstr (lit_get_literal_by_cp (obj.get_identifier_name ()), "eval"));
if (jsp_is_identifier_operand (obj))
{
lit_literal_t lit = lit_get_literal_by_cp (jsp_operand_get_identifier_name (obj));
return is_eval_lit;
return lit_literal_equal_type_cstr (lit, "eval");
}
return false;
} /* dumper_is_eval_literal */
/**
@@ -1199,33 +1679,33 @@ dump_variable_assignment (jsp_ctx_t *ctx_p, /**< parser context */
{
jsp_operand_t type_operand;
if (var.is_string_lit_operand ())
if (jsp_is_string_lit_operand (var))
{
type_operand = jsp_operand_t::make_idx_const_operand (OPCODE_ARG_TYPE_STRING);
type_operand = jsp_make_idx_const_operand (OPCODE_ARG_TYPE_STRING);
}
else if (var.is_number_lit_operand ())
else if (jsp_is_number_lit_operand (var))
{
type_operand = jsp_operand_t::make_idx_const_operand (OPCODE_ARG_TYPE_NUMBER);
type_operand = jsp_make_idx_const_operand (OPCODE_ARG_TYPE_NUMBER);
}
else if (var.is_regexp_lit_operand ())
else if (jsp_is_regexp_lit_operand (var))
{
type_operand = jsp_operand_t::make_idx_const_operand (OPCODE_ARG_TYPE_REGEXP);
type_operand = jsp_make_idx_const_operand (OPCODE_ARG_TYPE_REGEXP);
}
else if (var.is_smallint_operand ())
else if (jsp_is_smallint_operand (var))
{
type_operand = jsp_operand_t::make_idx_const_operand (OPCODE_ARG_TYPE_SMALLINT);
type_operand = jsp_make_idx_const_operand (OPCODE_ARG_TYPE_SMALLINT);
}
else if (var.is_simple_value_operand ())
else if (jsp_is_simple_value_operand (var))
{
type_operand = jsp_operand_t::make_idx_const_operand (OPCODE_ARG_TYPE_SIMPLE);
type_operand = jsp_make_idx_const_operand (OPCODE_ARG_TYPE_SIMPLE);
}
else
{
JERRY_ASSERT (var.is_identifier_operand ()
|| var.is_register_operand ()
|| var.is_this_operand ());
JERRY_ASSERT (jsp_is_identifier_operand (var)
|| jsp_is_register_operand (var)
|| jsp_is_this_operand (var));
type_operand = jsp_operand_t::make_idx_const_operand (OPCODE_ARG_TYPE_VARIABLE);
type_operand = jsp_make_idx_const_operand (OPCODE_ARG_TYPE_VARIABLE);
}
dump_triple_address (ctx_p, VM_OP_ASSIGNMENT, res, type_operand, var);
@@ -1250,7 +1730,7 @@ dump_varg_header_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
VM_OP_FUNC_EXPR_N,
res,
obj,
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand ());
break;
}
case VARG_CONSTRUCT_EXPR:
@@ -1259,7 +1739,7 @@ dump_varg_header_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
VM_OP_CONSTRUCT_N,
res,
obj,
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand ());
break;
}
case VARG_CALL_EXPR:
@@ -1268,7 +1748,7 @@ dump_varg_header_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
VM_OP_CALL_N,
res,
obj,
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand ());
break;
}
case VARG_FUNC_DECL:
@@ -1276,7 +1756,7 @@ dump_varg_header_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
dump_double_address (ctx_p,
VM_OP_FUNC_DECL_N,
obj,
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand ());
break;
}
case VARG_ARRAY_DECL:
@@ -1284,7 +1764,7 @@ dump_varg_header_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
dump_double_address (ctx_p,
VM_OP_ARRAY_DECL,
res,
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand ());
break;
}
case VARG_OBJ_DECL:
@@ -1292,7 +1772,7 @@ dump_varg_header_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
dump_double_address (ctx_p,
VM_OP_OBJ_DECL,
res,
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand ());
break;
}
}
@@ -1472,7 +1952,7 @@ dump_call_additional_info (jsp_ctx_t *ctx_p, /**< parser context */
{
if (flags & OPCODE_CALL_FLAGS_HAVE_THIS_ARG)
{
JERRY_ASSERT (this_arg.is_register_operand () || this_arg.is_this_operand ());
JERRY_ASSERT (jsp_is_register_operand (this_arg) || jsp_is_this_operand (this_arg));
JERRY_ASSERT (!operand_is_empty (this_arg));
}
else
@@ -1482,8 +1962,8 @@ dump_call_additional_info (jsp_ctx_t *ctx_p, /**< parser context */
dump_triple_address (ctx_p,
VM_OP_META,
jsp_operand_t::make_idx_const_operand (OPCODE_META_TYPE_CALL_SITE_INFO),
jsp_operand_t::make_idx_const_operand (flags),
jsp_make_idx_const_operand (OPCODE_META_TYPE_CALL_SITE_INFO),
jsp_make_idx_const_operand (flags),
this_arg);
} /* dump_call_additional_info */
@@ -1496,9 +1976,9 @@ dump_varg (jsp_ctx_t *ctx_p, /**< parser context */
{
dump_triple_address (ctx_p,
VM_OP_META,
jsp_operand_t::make_idx_const_operand (OPCODE_META_TYPE_VARG),
jsp_make_idx_const_operand (OPCODE_META_TYPE_VARG),
op,
jsp_operand_t::make_empty_operand ());
jsp_make_empty_operand ());
} /* dump_varg */
void
@@ -1506,11 +1986,11 @@ dump_prop_name_and_value (jsp_ctx_t *ctx_p, /**< parser context */
jsp_operand_t name, /**< property name */
jsp_operand_t value) /**< property value */
{
JERRY_ASSERT (name.is_string_lit_operand ());
JERRY_ASSERT (jsp_is_string_lit_operand (name));
dump_triple_address (ctx_p,
VM_OP_META,
jsp_operand_t::make_idx_const_operand (OPCODE_META_TYPE_VARG_PROP_DATA),
jsp_make_idx_const_operand (OPCODE_META_TYPE_VARG_PROP_DATA),
name,
value);
} /* dump_prop_name_and_value */
@@ -1520,12 +2000,12 @@ dump_prop_getter_decl (jsp_ctx_t *ctx_p, /**< parser context */
jsp_operand_t name, /**< property name */
jsp_operand_t func) /**< property getter */
{
JERRY_ASSERT (name.is_string_lit_operand ());
JERRY_ASSERT (func.is_register_operand ());
JERRY_ASSERT (jsp_is_string_lit_operand (name));
JERRY_ASSERT (jsp_is_register_operand (func));
dump_triple_address (ctx_p,
VM_OP_META,
jsp_operand_t::make_idx_const_operand (OPCODE_META_TYPE_VARG_PROP_GETTER),
jsp_make_idx_const_operand (OPCODE_META_TYPE_VARG_PROP_GETTER),
name,
func);
} /* dump_prop_getter_decl */
@@ -1535,12 +2015,12 @@ dump_prop_setter_decl (jsp_ctx_t *ctx_p, /**< parser context */
jsp_operand_t name, /**< property name */
jsp_operand_t func) /**< property setter */
{
JERRY_ASSERT (name.is_string_lit_operand ());
JERRY_ASSERT (func.is_register_operand ());
JERRY_ASSERT (jsp_is_string_lit_operand (name));
JERRY_ASSERT (jsp_is_register_operand (func));
dump_triple_address (ctx_p,
VM_OP_META,
jsp_operand_t::make_idx_const_operand (OPCODE_META_TYPE_VARG_PROP_SETTER),
jsp_make_idx_const_operand (OPCODE_META_TYPE_VARG_PROP_SETTER),
name,
func);
} /* dump_prop_setter_decl */
@@ -1620,8 +2100,8 @@ dump_conditional_check_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
dump_triple_address (ctx_p,
VM_OP_IS_FALSE_JMP_DOWN,
op,
jsp_operand_t::make_unknown_operand (),
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand (),
jsp_make_unknown_operand ());
return pos;
} /* dump_conditional_check_for_rewrite */
@@ -1655,8 +2135,8 @@ dump_jump_to_end_for_rewrite (jsp_ctx_t *ctx_p) /**< parser context */
dump_double_address (ctx_p,
VM_OP_JMP_DOWN,
jsp_operand_t::make_unknown_operand (),
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand (),
jsp_make_unknown_operand ());
return pos;
} /* dump_jump_to_end_for_rewrite */
@@ -1707,16 +2187,16 @@ dump_continue_iterations_check (jsp_ctx_t *ctx_p, /**< parser context */
{
dump_double_address (ctx_p,
VM_OP_JMP_UP,
jsp_operand_t::make_idx_const_operand (id1),
jsp_operand_t::make_idx_const_operand (id2));
jsp_make_idx_const_operand (id1),
jsp_make_idx_const_operand (id2));
}
else
{
dump_triple_address (ctx_p,
VM_OP_IS_TRUE_JMP_UP,
op,
jsp_operand_t::make_idx_const_operand (id1),
jsp_operand_t::make_idx_const_operand (id2));
jsp_make_idx_const_operand (id1),
jsp_make_idx_const_operand (id2));
}
}
@@ -1773,16 +2253,16 @@ dump_simple_or_nested_jump_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
if (jmp_opcode == VM_OP_JMP_DOWN
|| jmp_opcode == VM_OP_JMP_BREAK_CONTINUE)
{
JERRY_ASSERT (cond.is_empty_operand ());
JERRY_ASSERT (jsp_is_empty_operand (cond));
dump_double_address (ctx_p,
jmp_opcode,
jsp_operand_t::make_idx_const_operand (id1),
jsp_operand_t::make_idx_const_operand (id2));
jsp_make_idx_const_operand (id1),
jsp_make_idx_const_operand (id2));
}
else
{
JERRY_ASSERT (!cond.is_empty_operand ());
JERRY_ASSERT (!jsp_is_empty_operand (cond));
JERRY_ASSERT (jmp_opcode == VM_OP_IS_FALSE_JMP_DOWN
|| jmp_opcode == VM_OP_IS_TRUE_JMP_DOWN);
@@ -1790,8 +2270,8 @@ dump_simple_or_nested_jump_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
dump_triple_address (ctx_p,
jmp_opcode,
cond,
jsp_operand_t::make_idx_const_operand (id1),
jsp_operand_t::make_idx_const_operand (id2));
jsp_make_idx_const_operand (id1),
jsp_make_idx_const_operand (id2));
}
return ret;
@@ -1925,8 +2405,8 @@ dump_with_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
dump_triple_address (ctx_p,
VM_OP_WITH,
op,
jsp_operand_t::make_unknown_operand (),
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand (),
jsp_make_unknown_operand ());
return oc;
} /* dump_with_for_rewrite */
@@ -1958,9 +2438,9 @@ dump_with_end (jsp_ctx_t *ctx_p) /**< parser context */
{
dump_triple_address (ctx_p,
VM_OP_META,
jsp_operand_t::make_idx_const_operand (OPCODE_META_TYPE_END_WITH),
jsp_operand_t::make_empty_operand (),
jsp_operand_t::make_empty_operand ());
jsp_make_idx_const_operand (OPCODE_META_TYPE_END_WITH),
jsp_make_empty_operand (),
jsp_make_empty_operand ());
} /* dump_with_end */
/**
@@ -1981,8 +2461,8 @@ dump_for_in_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
dump_triple_address (ctx_p,
VM_OP_FOR_IN,
op,
jsp_operand_t::make_unknown_operand (),
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand (),
jsp_make_unknown_operand ());
return oc;
} /* dump_for_in_for_rewrite */
@@ -2014,9 +2494,9 @@ dump_for_in_end (jsp_ctx_t *ctx_p) /**< parser context */
{
dump_triple_address (ctx_p,
VM_OP_META,
jsp_operand_t::make_idx_const_operand (OPCODE_META_TYPE_END_FOR_IN),
jsp_operand_t::make_empty_operand (),
jsp_operand_t::make_empty_operand ());
jsp_make_idx_const_operand (OPCODE_META_TYPE_END_FOR_IN),
jsp_make_empty_operand (),
jsp_make_empty_operand ());
} /* dump_for_in_end */
/**
@@ -2031,8 +2511,8 @@ dump_try_for_rewrite (jsp_ctx_t *ctx_p) /**< parser context */
dump_double_address (ctx_p,
VM_OP_TRY_BLOCK,
jsp_operand_t::make_unknown_operand (),
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand (),
jsp_make_unknown_operand ());
return pos;
} /* dump_try_for_rewrite */
@@ -2067,19 +2547,19 @@ dump_catch_for_rewrite (jsp_ctx_t *ctx_p, /**< parser context */
{
vm_instr_counter_t pos = dumper_get_current_instr_counter (ctx_p);
JERRY_ASSERT (op.is_string_lit_operand ());
JERRY_ASSERT (jsp_is_string_lit_operand (op));
dump_triple_address (ctx_p,
VM_OP_META,
jsp_operand_t::make_idx_const_operand (OPCODE_META_TYPE_CATCH),
jsp_operand_t::make_unknown_operand (),
jsp_operand_t::make_unknown_operand ());
jsp_make_idx_const_operand (OPCODE_META_TYPE_CATCH),
jsp_make_unknown_operand (),
jsp_make_unknown_operand ());
dump_triple_address (ctx_p,
VM_OP_META,
jsp_operand_t::make_idx_const_operand (OPCODE_META_TYPE_CATCH_EXCEPTION_IDENTIFIER),
jsp_make_idx_const_operand (OPCODE_META_TYPE_CATCH_EXCEPTION_IDENTIFIER),
op,
jsp_operand_t::make_empty_operand ());
jsp_make_empty_operand ());
return pos;
} /* dump_catch_for_rewrite */
@@ -2115,9 +2595,9 @@ dump_finally_for_rewrite (jsp_ctx_t *ctx_p) /**< parser context */
dump_triple_address (ctx_p,
VM_OP_META,
jsp_operand_t::make_idx_const_operand (OPCODE_META_TYPE_FINALLY),
jsp_operand_t::make_unknown_operand (),
jsp_operand_t::make_unknown_operand ());
jsp_make_idx_const_operand (OPCODE_META_TYPE_FINALLY),
jsp_make_unknown_operand (),
jsp_make_unknown_operand ());
return pos;
} /* dump_finally_for_rewrite */
@@ -2149,9 +2629,9 @@ dump_end_try_catch_finally (jsp_ctx_t *ctx_p) /**< parser context */
{
dump_triple_address (ctx_p,
VM_OP_META,
jsp_operand_t::make_idx_const_operand (OPCODE_META_TYPE_END_TRY_CATCH_FINALLY),
jsp_operand_t::make_empty_operand (),
jsp_operand_t::make_empty_operand ());
jsp_make_idx_const_operand (OPCODE_META_TYPE_END_TRY_CATCH_FINALLY),
jsp_make_empty_operand (),
jsp_make_empty_operand ());
} /* dump_end_try_catch_finally */
/**
@@ -2171,7 +2651,7 @@ void
dump_variable_declaration (jsp_ctx_t *ctx_p, /**< parser context */
lit_cpointer_t lit_id) /**< literal which holds variable's name */
{
jsp_operand_t op_var_name = jsp_operand_t::make_string_lit_operand (lit_id);
jsp_operand_t op_var_name = jsp_make_string_lit_operand (lit_id);
op_meta op = jsp_dmp_create_op_meta (ctx_p, VM_OP_VAR_DECL, &op_var_name, 1);
JERRY_ASSERT (!jsp_is_dump_mode (ctx_p));
@@ -2199,9 +2679,9 @@ dump_reg_var_decl_for_rewrite (jsp_ctx_t *ctx_p) /**< parser context */
dump_triple_address (ctx_p,
VM_OP_REG_VAR_DECL,
jsp_operand_t::make_unknown_operand (),
jsp_operand_t::make_unknown_operand (),
jsp_operand_t::make_unknown_operand ());
jsp_make_unknown_operand (),
jsp_make_unknown_operand (),
jsp_make_unknown_operand ());
return oc;
} /* dump_reg_var_decl_for_rewrite */
+121 -564
View File
@@ -24,511 +24,34 @@
#include "rcs-records.h"
#include "scopes-tree.h"
/**
* Operand types
*/
typedef enum __attr_packed___
{
JSP_OPERAND_TYPE_EMPTY, /**< empty operand */
JSP_OPERAND_TYPE_STRING_LITERAL, /**< operand contains string literal value */
JSP_OPERAND_TYPE_NUMBER_LITERAL, /**< operand contains number literal value */
JSP_OPERAND_TYPE_REGEXP_LITERAL, /**< operand contains regexp literal value */
JSP_OPERAND_TYPE_SIMPLE_VALUE, /**< operand contains a simple ecma value */
JSP_OPERAND_TYPE_SMALLINT, /**< operand contains small integer value (less than 256) */
JSP_OPERAND_TYPE_IDENTIFIER, /**< Identifier reference */
JSP_OPERAND_TYPE_THIS_BINDING, /**< ThisBinding operand */
JSP_OPERAND_TYPE_TMP, /**< operand contains byte-code register index */
JSP_OPERAND_TYPE_IDX_CONST, /**< operand contains an integer constant that fits vm_idx_t */
JSP_OPERAND_TYPE_UNKNOWN, /**< operand, representing unknown value that would be rewritten later */
JSP_OPERAND_TYPE_UNINITIALIZED /**< uninitialized operand
*
* Note:
* For use only in assertions to check that operands
* are initialized before actual usage */
} jsp_operand_type_t;
/**
* Operand (descriptor of value or reference in context of parser)
*/
class jsp_operand_t
typedef struct
{
public:
enum type_t : uint8_t
{
EMPTY, /**< empty operand */
STRING_LITERAL, /**< operand contains string literal value */
NUMBER_LITERAL, /**< operand contains number literal value */
REGEXP_LITERAL, /**< operand contains regexp literal value */
SIMPLE_VALUE, /**< operand contains a simple ecma value */
SMALLINT, /**< operand contains small integer value (less than 256) */
IDENTIFIER, /**< Identifier reference */
THIS_BINDING, /**< ThisBinding operand */
TMP, /**< operand contains byte-code register index */
IDX_CONST, /**< operand contains an integer constant that fits vm_idx_t */
UNKNOWN, /**< operand, representing unknown value that would be rewritten later */
UNINITIALIZED /**< uninitialized operand
*
* Note:
* For use only in assertions to check that operands
* are initialized before actual usage */
};
/**
* Construct operand template
*/
jsp_operand_t (void)
{
#ifndef JERRY_NDEBUG
_type = jsp_operand_t::UNINITIALIZED;
#endif /* !JERRY_NDEBUG */
} /* jsp_operand_t */
/**
* Construct empty operand
*
* @return constructed operand
*/
static jsp_operand_t
make_empty_operand (void)
{
jsp_operand_t ret;
ret._type = jsp_operand_t::EMPTY;
return ret;
} /* make_empty_operand */
/**
* Construct ThisBinding operand
*
* @return constructed operand
*/
static jsp_operand_t
make_this_operand (void)
{
jsp_operand_t ret;
ret._type = jsp_operand_t::THIS_BINDING;
return ret;
} /* make_this_operand */
/**
* Construct unknown operand
*
* @return constructed operand
*/
static jsp_operand_t
make_unknown_operand (void)
{
jsp_operand_t ret;
ret._type = jsp_operand_t::UNKNOWN;
return ret;
} /* make_unknown_operand */
/**
* Construct idx-constant operand
*
* @return constructed operand
*/
static jsp_operand_t
make_idx_const_operand (vm_idx_t cnst) /**< integer in vm_idx_t range */
{
jsp_operand_t ret;
ret._type = jsp_operand_t::IDX_CONST;
ret._data.idx_const = cnst;
return ret;
} /* make_idx_const_operand */
/**
* Construct small integer operand
*
* @return constructed operand
*/
static jsp_operand_t
make_smallint_operand (uint8_t integer_value) /**< small integer value */
{
jsp_operand_t ret;
ret._type = jsp_operand_t::SMALLINT;
ret._data.smallint_value = integer_value;
return ret;
} /* make_smallint_operand */
/**
* Construct simple ecma value operand
*
* @return constructed operand
*/
static jsp_operand_t
make_simple_value_operand (ecma_simple_value_t simple_value) /**< simple ecma value */
{
jsp_operand_t ret;
ret._type = jsp_operand_t::SIMPLE_VALUE;
ret._data.simple_value = simple_value;
return ret;
} /* make_simple_value_operand */
/**
* Construct string literal operand
*
* @return constructed operand
*/
static jsp_operand_t
make_string_lit_operand (lit_cpointer_t lit_id) /**< literal identifier */
{
JERRY_ASSERT (lit_id.packed_value != NOT_A_LITERAL.packed_value);
#ifndef JERRY_NDEBUG
lit_literal_t lit = lit_get_literal_by_cp (lit_id);
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit)
|| RCS_RECORD_IS_MAGIC_STR (lit)
|| RCS_RECORD_IS_MAGIC_STR_EX (lit));
#endif /* !JERRY_NDEBUG */
jsp_operand_t ret;
ret._type = jsp_operand_t::STRING_LITERAL;
ret._data.lit_id = lit_id;
return ret;
} /* make_string_lit_operand */
/**
* Construct RegExp literal operand
*
* @return constructed operand
*/
static jsp_operand_t
make_regexp_lit_operand (lit_cpointer_t lit_id) /**< literal identifier */
{
JERRY_ASSERT (lit_id.packed_value != NOT_A_LITERAL.packed_value);
#ifndef JERRY_NDEBUG
lit_literal_t lit = lit_get_literal_by_cp (lit_id);
JERRY_ASSERT (RCS_RECORD_IS_CHARSET (lit)
|| RCS_RECORD_IS_MAGIC_STR (lit)
|| RCS_RECORD_IS_MAGIC_STR_EX (lit));
#endif /* !JERRY_NDEBUG */
jsp_operand_t ret;
ret._type = jsp_operand_t::REGEXP_LITERAL;
ret._data.lit_id = lit_id;
return ret;
} /* make_regexp_lit_operand */
/**
* Construct number literal operand
*
* @return constructed operand
*/
static jsp_operand_t
make_number_lit_operand (lit_cpointer_t lit_id) /**< literal identifier */
{
JERRY_ASSERT (lit_id.packed_value != NOT_A_LITERAL.packed_value);
#ifndef JERRY_NDEBUG
lit_literal_t lit = lit_get_literal_by_cp (lit_id);
JERRY_ASSERT (RCS_RECORD_IS_NUMBER (lit));
#endif /* !JERRY_NDEBUG */
jsp_operand_t ret;
ret._type = jsp_operand_t::NUMBER_LITERAL;
ret._data.lit_id = lit_id;
return ret;
} /* make_number_lit_operand */
/**
* Construct identifier reference operand
*
* @return constructed operand
*/
static jsp_operand_t
make_identifier_operand (lit_cpointer_t lit_id) /**< literal identifier */
{
JERRY_ASSERT (lit_id.packed_value != NOT_A_LITERAL.packed_value);
jsp_operand_t ret;
ret._type = jsp_operand_t::IDENTIFIER;
ret._data.identifier = lit_id;
return ret;
} /* make_identifier_operand */
/**
* Construct register operand
*
* @return constructed operand
*/
static jsp_operand_t
make_reg_operand (vm_idx_t reg_index) /**< register index */
{
/*
* The following check currently leads to 'comparison is always true
* due to limited range of data type' warning, so it is turned off.
*
* If VM_IDX_GENERAL_VALUE_FIRST is changed to value greater than 0,
* the check should be restored.
*/
// JERRY_ASSERT (reg_index >= VM_IDX_GENERAL_VALUE_FIRST);
static_assert (VM_IDX_GENERAL_VALUE_FIRST == 0, "See comment above");
JERRY_ASSERT (reg_index <= VM_IDX_GENERAL_VALUE_LAST);
jsp_operand_t ret;
ret._type = jsp_operand_t::TMP;
ret._data.uid = reg_index;
return ret;
} /* make_reg_operand */
/**
* Is it empty operand?
*
* @return true / false
*/
bool
is_empty_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::EMPTY);
} /* is_empty_operand */
/**
* Is it ThisBinding operand?
*
* @return true / false
*/
bool
is_this_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::THIS_BINDING);
} /* is_this_operand */
/**
* Is it unknown operand?
*
* @return true / false
*/
bool
is_unknown_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::UNKNOWN);
} /* is_unknown_operand */
/**
* Is it idx-constant operand?
*
* @return true / false
*/
bool
is_idx_const_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::IDX_CONST);
} /* is_idx_const_operand */
/**
* Is it byte-code register operand?
*
* @return true / false
*/
bool
is_register_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::TMP);
} /* is_register_operand */
/**
* Is it simple ecma value operand?
*
* @return true / false
*/
bool
is_simple_value_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::SIMPLE_VALUE);
} /* is_simple_value_operand */
/**
* Is it small integer operand?
*
* @return true / false
*/
bool
is_smallint_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::SMALLINT);
} /* is_smallint_operand */
/**
* Is it number literal operand?
*
* @return true / false
*/
bool
is_number_lit_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::NUMBER_LITERAL);
} /* is_number_lit_operand */
/**
* Is it string literal operand?
*
* @return true / false
*/
bool
is_string_lit_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::STRING_LITERAL);
} /* is_string_lit_operand */
/**
* Is it RegExp literal operand?
*
* @return true / false
*/
bool
is_regexp_lit_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::REGEXP_LITERAL);
} /* is_regexp_lit_operand */
/**
* Is it identifier reference operand?
*
* @return true / false
*/
bool is_identifier_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::IDENTIFIER);
} /* is_identifier_operand */
/**
* Get string literal - name of Identifier reference
*
* @return literal identifier
*/
lit_cpointer_t get_identifier_name (void) const
{
JERRY_ASSERT (is_identifier_operand ());
return (_data.identifier);
} /* get_identifier_name */
/**
* Get idx for operand
*
* @return VM_IDX_REWRITE_LITERAL_UID (for jsp_operand_t::LITERAL),
* or register index (for jsp_operand_t::TMP).
*/
vm_idx_t
get_idx (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
if (_type == jsp_operand_t::TMP)
{
return _data.uid;
}
else if (_type == jsp_operand_t::STRING_LITERAL
|| _type == jsp_operand_t::NUMBER_LITERAL)
{
return VM_IDX_REWRITE_LITERAL_UID;
}
else if (_type == jsp_operand_t::THIS_BINDING)
{
return VM_REG_SPECIAL_THIS_BINDING;
}
else
{
JERRY_ASSERT (_type == jsp_operand_t::EMPTY);
return VM_IDX_EMPTY;
}
} /* get_idx */
/**
* Get literal from operand
*
* @return literal identifier (for jsp_operand_t::LITERAL),
* or NOT_A_LITERAL (for jsp_operand_t::TMP).
*/
lit_cpointer_t
get_literal (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
if (_type == jsp_operand_t::TMP)
{
return NOT_A_LITERAL;
}
else if (_type == jsp_operand_t::STRING_LITERAL
|| _type == jsp_operand_t::NUMBER_LITERAL
|| _type == jsp_operand_t::REGEXP_LITERAL)
{
return _data.lit_id;
}
else
{
JERRY_ASSERT (_type == jsp_operand_t::EMPTY);
return NOT_A_LITERAL;
}
} /* get_literal */
/**
* Get constant from idx-constant operand
*
* @return an integer
*/
vm_idx_t
get_idx_const (void) const
{
JERRY_ASSERT (is_idx_const_operand ());
return _data.idx_const;
} /* get_idx_const */
/**
* Get small integer constant from operand
*
* @return an integer
*/
uint8_t
get_smallint_value (void) const
{
JERRY_ASSERT (is_smallint_operand ());
return _data.smallint_value;
} /* get_smallint_value */
/**
* Get simple value from operand
*
* @return a simple ecma value
*/
ecma_simple_value_t
get_simple_value (void) const
{
JERRY_ASSERT (is_simple_value_operand ());
return (ecma_simple_value_t) _data.simple_value;
} /* get_simple_value */
private:
union
{
vm_idx_t idx_const; /**< idx constant value (for jsp_operand_t::IDX_CONST) */
@@ -537,12 +60,44 @@ private:
lit_cpointer_t identifier; /**< Identifier reference (is_value_based_ref flag not set) */
uint8_t smallint_value; /**< small integer value */
uint8_t simple_value; /**< simple ecma value */
} _data;
} data;
type_t _type; /**< type of operand */
};
jsp_operand_type_t type; /**< type of operand */
} jsp_operand_t;
static_assert (sizeof (jsp_operand_t) == 4, "");
extern jsp_operand_t jsp_make_uninitialized_operand (void);
extern jsp_operand_t jsp_make_empty_operand (void);
extern jsp_operand_t jsp_make_this_operand (void);
extern jsp_operand_t jsp_make_unknown_operand (void);
extern jsp_operand_t jsp_make_idx_const_operand (vm_idx_t);
extern jsp_operand_t jsp_make_smallint_operand (uint8_t);
extern jsp_operand_t jsp_make_simple_value_operand (ecma_simple_value_t);
extern jsp_operand_t jsp_make_string_lit_operand (lit_cpointer_t);
extern jsp_operand_t jsp_make_regexp_lit_operand (lit_cpointer_t);
extern jsp_operand_t jsp_make_number_lit_operand (lit_cpointer_t);
extern jsp_operand_t jsp_make_identifier_operand (lit_cpointer_t);
extern jsp_operand_t jsp_make_reg_operand (vm_idx_t);
extern bool jsp_is_empty_operand (jsp_operand_t);
extern bool jsp_is_this_operand (jsp_operand_t);
extern bool jsp_is_unknown_operand (jsp_operand_t);
extern bool jsp_is_idx_const_operand (jsp_operand_t);
extern bool jsp_is_register_operand (jsp_operand_t);
extern bool jsp_is_simple_value_operand (jsp_operand_t);
extern bool jsp_is_smallint_operand (jsp_operand_t);
extern bool jsp_is_number_lit_operand (jsp_operand_t);
extern bool jsp_is_string_lit_operand (jsp_operand_t);
extern bool jsp_is_regexp_lit_operand (jsp_operand_t);
extern bool jsp_is_identifier_operand (jsp_operand_t);
extern lit_cpointer_t jsp_operand_get_identifier_name (jsp_operand_t);
extern lit_cpointer_t jsp_operand_get_literal (jsp_operand_t);
extern vm_idx_t jsp_operand_get_idx (jsp_operand_t);
extern vm_idx_t jsp_operand_get_idx_const (jsp_operand_t);
extern ecma_simple_value_t jsp_operand_get_simple_value (jsp_operand_t);
extern uint8_t jsp_operand_get_smallint_value (jsp_operand_t);
JERRY_STATIC_ASSERT (sizeof (jsp_operand_t) == 4);
typedef enum __attr_packed___
{
@@ -554,89 +109,91 @@ typedef enum __attr_packed___
VARG_CALL_EXPR
} varg_list_type;
jsp_operand_t empty_operand (void);
jsp_operand_t tmp_operand (void);
bool operand_is_empty (jsp_operand_t);
extern jsp_operand_t empty_operand (void);
extern jsp_operand_t tmp_operand (void);
extern bool operand_is_empty (jsp_operand_t);
void dumper_init (jsp_ctx_t *, bool);
extern void dumper_init (jsp_ctx_t *, bool);
vm_instr_counter_t dumper_get_current_instr_counter (jsp_ctx_t *);
extern vm_instr_counter_t dumper_get_current_instr_counter (jsp_ctx_t *);
void dumper_start_move_of_vars_to_regs (jsp_ctx_t *);
bool dumper_start_move_of_args_to_regs (jsp_ctx_t *, uint32_t args_num);
bool dumper_try_replace_identifier_name_with_reg (jsp_ctx_t *, bytecode_data_header_t *, op_meta *);
void dumper_alloc_reg_for_unused_arg (jsp_ctx_t *);
extern void dumper_start_move_of_vars_to_regs (jsp_ctx_t *);
extern bool dumper_start_move_of_args_to_regs (jsp_ctx_t *, uint32_t args_num);
extern bool dumper_try_replace_identifier_name_with_reg (jsp_ctx_t *, bytecode_data_header_t *, op_meta *);
extern void dumper_alloc_reg_for_unused_arg (jsp_ctx_t *);
void dumper_new_statement (jsp_ctx_t *);
void dumper_save_reg_alloc_ctx (jsp_ctx_t *, vm_idx_t *, vm_idx_t *);
void dumper_restore_reg_alloc_ctx (jsp_ctx_t *, vm_idx_t, vm_idx_t, bool);
vm_idx_t dumper_save_reg_alloc_counter (jsp_ctx_t *);
void dumper_restore_reg_alloc_counter (jsp_ctx_t *, vm_idx_t);
extern void dumper_new_statement (jsp_ctx_t *);
extern void dumper_save_reg_alloc_ctx (jsp_ctx_t *, vm_idx_t *, vm_idx_t *);
extern void dumper_restore_reg_alloc_ctx (jsp_ctx_t *, vm_idx_t, vm_idx_t, bool);
extern vm_idx_t dumper_save_reg_alloc_counter (jsp_ctx_t *);
extern void dumper_restore_reg_alloc_counter (jsp_ctx_t *, vm_idx_t);
extern bool dumper_is_eval_literal (jsp_operand_t);
void dump_variable_assignment (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
extern void dump_variable_assignment (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
vm_instr_counter_t dump_varg_header_for_rewrite (jsp_ctx_t *, varg_list_type, jsp_operand_t, jsp_operand_t);
void rewrite_varg_header_set_args_count (jsp_ctx_t *, size_t, vm_instr_counter_t);
void dump_call_additional_info (jsp_ctx_t *, opcode_call_flags_t, jsp_operand_t);
void dump_varg (jsp_ctx_t *, jsp_operand_t);
extern vm_instr_counter_t dump_varg_header_for_rewrite (jsp_ctx_t *, varg_list_type, jsp_operand_t, jsp_operand_t);
extern void rewrite_varg_header_set_args_count (jsp_ctx_t *, size_t, vm_instr_counter_t);
extern void dump_call_additional_info (jsp_ctx_t *, opcode_call_flags_t, jsp_operand_t);
extern void dump_varg (jsp_ctx_t *, jsp_operand_t);
void dump_prop_name_and_value (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
void dump_prop_getter_decl (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
void dump_prop_setter_decl (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
void dump_prop_getter (jsp_ctx_t *, jsp_operand_t, jsp_operand_t, jsp_operand_t);
void dump_prop_setter (jsp_ctx_t *, jsp_operand_t, jsp_operand_t, jsp_operand_t);
extern void dump_prop_name_and_value (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
extern void dump_prop_getter_decl (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
extern void dump_prop_setter_decl (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
extern void dump_prop_getter (jsp_ctx_t *, jsp_operand_t, jsp_operand_t, jsp_operand_t);
extern void dump_prop_setter (jsp_ctx_t *, jsp_operand_t, jsp_operand_t, jsp_operand_t);
vm_instr_counter_t dump_conditional_check_for_rewrite (jsp_ctx_t *, jsp_operand_t);
void rewrite_conditional_check (jsp_ctx_t *, vm_instr_counter_t);
vm_instr_counter_t dump_jump_to_end_for_rewrite (jsp_ctx_t *);
void rewrite_jump_to_end (jsp_ctx_t *, vm_instr_counter_t);
extern vm_instr_counter_t dump_conditional_check_for_rewrite (jsp_ctx_t *, jsp_operand_t);
extern void rewrite_conditional_check (jsp_ctx_t *, vm_instr_counter_t);
extern vm_instr_counter_t dump_jump_to_end_for_rewrite (jsp_ctx_t *);
extern void rewrite_jump_to_end (jsp_ctx_t *, vm_instr_counter_t);
vm_instr_counter_t dumper_set_next_iteration_target (jsp_ctx_t *);
vm_instr_counter_t dump_simple_or_nested_jump_for_rewrite (jsp_ctx_t *,
extern vm_instr_counter_t dumper_set_next_iteration_target (jsp_ctx_t *);
extern vm_instr_counter_t dump_simple_or_nested_jump_for_rewrite (jsp_ctx_t *,
bool,
bool,
bool,
jsp_operand_t,
vm_instr_counter_t);
vm_instr_counter_t rewrite_simple_or_nested_jump_and_get_next (jsp_ctx_t *, vm_instr_counter_t, vm_instr_counter_t);
void dump_continue_iterations_check (jsp_ctx_t *, vm_instr_counter_t, jsp_operand_t);
extern vm_instr_counter_t rewrite_simple_or_nested_jump_and_get_next (jsp_ctx_t *,
vm_instr_counter_t,
vm_instr_counter_t);
extern void dump_continue_iterations_check (jsp_ctx_t *, vm_instr_counter_t, jsp_operand_t);
void dump_delete (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
void dump_delete_prop (jsp_ctx_t *, jsp_operand_t, jsp_operand_t, jsp_operand_t);
extern void dump_delete (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
extern void dump_delete_prop (jsp_ctx_t *, jsp_operand_t, jsp_operand_t, jsp_operand_t);
void dump_typeof (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
extern void dump_typeof (jsp_ctx_t *, jsp_operand_t, jsp_operand_t);
void dump_unary_op (jsp_ctx_t *, vm_op_t, jsp_operand_t, jsp_operand_t);
void dump_binary_op (jsp_ctx_t *, vm_op_t, jsp_operand_t, jsp_operand_t, jsp_operand_t);
extern void dump_unary_op (jsp_ctx_t *, vm_op_t, jsp_operand_t, jsp_operand_t);
extern void dump_binary_op (jsp_ctx_t *, vm_op_t, jsp_operand_t, jsp_operand_t, jsp_operand_t);
vm_instr_counter_t dump_with_for_rewrite (jsp_ctx_t *, jsp_operand_t);
void rewrite_with (jsp_ctx_t *, vm_instr_counter_t);
void dump_with_end (jsp_ctx_t *);
extern vm_instr_counter_t dump_with_for_rewrite (jsp_ctx_t *, jsp_operand_t);
extern void rewrite_with (jsp_ctx_t *, vm_instr_counter_t);
extern void dump_with_end (jsp_ctx_t *);
vm_instr_counter_t dump_for_in_for_rewrite (jsp_ctx_t *, jsp_operand_t);
void rewrite_for_in (jsp_ctx_t *, vm_instr_counter_t);
void dump_for_in_end (jsp_ctx_t *);
extern vm_instr_counter_t dump_for_in_for_rewrite (jsp_ctx_t *, jsp_operand_t);
extern void rewrite_for_in (jsp_ctx_t *, vm_instr_counter_t);
extern void dump_for_in_end (jsp_ctx_t *);
vm_instr_counter_t dump_try_for_rewrite (jsp_ctx_t *);
vm_instr_counter_t dump_catch_for_rewrite (jsp_ctx_t *, jsp_operand_t);
vm_instr_counter_t dump_finally_for_rewrite (jsp_ctx_t *);
void rewrite_try (jsp_ctx_t *, vm_instr_counter_t);
void rewrite_catch (jsp_ctx_t *, vm_instr_counter_t);
void rewrite_finally (jsp_ctx_t *, vm_instr_counter_t);
void dump_end_try_catch_finally (jsp_ctx_t *);
void dump_throw (jsp_ctx_t *, jsp_operand_t);
extern vm_instr_counter_t dump_try_for_rewrite (jsp_ctx_t *);
extern vm_instr_counter_t dump_catch_for_rewrite (jsp_ctx_t *, jsp_operand_t);
extern vm_instr_counter_t dump_finally_for_rewrite (jsp_ctx_t *);
extern void rewrite_try (jsp_ctx_t *, vm_instr_counter_t);
extern void rewrite_catch (jsp_ctx_t *, vm_instr_counter_t);
extern void rewrite_finally (jsp_ctx_t *, vm_instr_counter_t);
extern void dump_end_try_catch_finally (jsp_ctx_t *);
extern void dump_throw (jsp_ctx_t *, jsp_operand_t);
void dump_variable_declaration (jsp_ctx_t *, lit_cpointer_t);
extern void dump_variable_declaration (jsp_ctx_t *, lit_cpointer_t);
vm_instr_counter_t dump_reg_var_decl_for_rewrite (jsp_ctx_t *);
void rewrite_reg_var_decl (jsp_ctx_t *, vm_instr_counter_t);
extern vm_instr_counter_t dump_reg_var_decl_for_rewrite (jsp_ctx_t *);
extern void rewrite_reg_var_decl (jsp_ctx_t *, vm_instr_counter_t);
void dump_ret (jsp_ctx_t *);
void dump_retval (jsp_ctx_t *, jsp_operand_t);
extern void dump_ret (jsp_ctx_t *);
extern void dump_retval (jsp_ctx_t *, jsp_operand_t);
op_meta dumper_get_op_meta (jsp_ctx_t *, vm_instr_counter_t);
void dumper_rewrite_op_meta (jsp_ctx_t *, vm_instr_counter_t, op_meta);
extern op_meta dumper_get_op_meta (jsp_ctx_t *, vm_instr_counter_t);
extern void dumper_rewrite_op_meta (jsp_ctx_t *, vm_instr_counter_t, op_meta);
#endif /* OPCODES_DUMPER_H */
#endif /* !OPCODES_DUMPER_H */
+69 -84
View File
@@ -979,7 +979,7 @@ parse_property_name (void)
const char *s = lexer_token_type_to_string (lexer_get_token_type (tok));
lit_literal_t lit = lit_find_or_create_literal_from_utf8_string ((const lit_utf8_byte_t *) s,
(lit_utf8_size_t)strlen (s));
return jsp_operand_t::make_string_lit_operand (rcs_cpointer_compress (lit));
return jsp_make_string_lit_operand (rcs_cpointer_compress (lit));
}
else
{
@@ -988,7 +988,7 @@ parse_property_name (void)
case TOK_NAME:
case TOK_STRING:
{
return jsp_operand_t::make_string_lit_operand (token_data_as_lit_cp ());
return jsp_make_string_lit_operand (token_data_as_lit_cp ());
}
case TOK_NUMBER:
case TOK_SMALL_INT:
@@ -1011,7 +1011,7 @@ parse_property_name (void)
JERRY_ASSERT (sz <= ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER);
lit_literal_t str_lit = lit_find_or_create_literal_from_utf8_string (buff, sz);
return jsp_operand_t::make_string_lit_operand (rcs_cpointer_compress (str_lit));
return jsp_make_string_lit_operand (rcs_cpointer_compress (str_lit));
}
case TOK_NULL:
case TOK_BOOL:
@@ -1021,7 +1021,7 @@ parse_property_name (void)
: (tok.uid ? LIT_MAGIC_STRING_TRUE : LIT_MAGIC_STRING_FALSE));
lit_literal_t lit = lit_find_or_create_literal_from_utf8_string (lit_get_magic_string_utf8 (id),
lit_get_magic_string_size (id));
return jsp_operand_t::make_string_lit_operand (rcs_cpointer_compress (lit));
return jsp_make_string_lit_operand (rcs_cpointer_compress (lit));
}
default:
{
@@ -1250,8 +1250,8 @@ jsp_start_parse_source_element_list (jsp_ctx_t *ctx_p,
if (scope_type == SCOPE_TYPE_EVAL)
{
dump_variable_assignment (ctx_p,
jsp_operand_t::make_reg_operand (VM_REG_SPECIAL_EVAL_RET),
jsp_operand_t::make_simple_value_operand (ECMA_SIMPLE_VALUE_UNDEFINED));
jsp_make_reg_operand (VM_REG_SPECIAL_EVAL_RET),
jsp_make_simple_value_operand (ECMA_SIMPLE_VALUE_UNDEFINED));
}
} /* jsp_start_parse_source_element_list */
@@ -1261,7 +1261,7 @@ jsp_start_parse_function_scope (jsp_ctx_t *ctx_p,
bool is_function_expression,
size_t *out_formal_parameters_num_p)
{
jsp_operand_t func;
jsp_operand_t func = empty_operand ();
uint16_t index;
@@ -1284,12 +1284,8 @@ jsp_start_parse_function_scope (jsp_ctx_t *ctx_p,
dump_binary_op (ctx_p,
VM_OP_FUNC_EXPR_REF,
func,
jsp_operand_t::make_idx_const_operand (idx1),
jsp_operand_t::make_idx_const_operand (idx2));
}
else
{
func = empty_operand ();
jsp_make_idx_const_operand (idx1),
jsp_make_idx_const_operand (idx2));
}
mem_cpointer_t parent_scope_or_bc_header_cp;
@@ -1336,8 +1332,8 @@ jsp_start_parse_function_scope (jsp_ctx_t *ctx_p,
current_token_must_be_check_and_skip_it (ctx_p, TOK_OPEN_PAREN);
JERRY_ASSERT (func_name.is_empty_operand ()
|| func_name.is_string_lit_operand ());
JERRY_ASSERT (jsp_is_empty_operand (func_name)
|| jsp_is_string_lit_operand (func_name));
varg_list_type vlt = is_function_expression ? VARG_FUNC_EXPR : VARG_FUNC_DECL;
@@ -1348,7 +1344,7 @@ jsp_start_parse_function_scope (jsp_ctx_t *ctx_p,
while (!token_is (TOK_CLOSE_PAREN))
{
current_token_must_be (TOK_NAME);
jsp_operand_t formal_parameter_name = jsp_operand_t::make_string_lit_operand (token_data_as_lit_cp ());
jsp_operand_t formal_parameter_name = jsp_make_string_lit_operand (token_data_as_lit_cp ());
skip_token (ctx_p);
dump_varg (ctx_p, formal_parameter_name);
@@ -1481,11 +1477,11 @@ dump_get_value_for_state_if_const (jsp_ctx_t *ctx_p,
&& state_p->state < JSP_STATE_EXPR__END);
JERRY_ASSERT (!state_p->is_value_based_reference);
if (state_p->u.expression.operand.is_string_lit_operand ()
|| state_p->u.expression.operand.is_number_lit_operand ()
|| state_p->u.expression.operand.is_regexp_lit_operand ()
|| state_p->u.expression.operand.is_smallint_operand ()
|| state_p->u.expression.operand.is_simple_value_operand ())
if (jsp_is_string_lit_operand (state_p->u.expression.operand)
|| jsp_is_number_lit_operand (state_p->u.expression.operand)
|| jsp_is_regexp_lit_operand (state_p->u.expression.operand)
|| jsp_is_smallint_operand (state_p->u.expression.operand)
|| jsp_is_simple_value_operand (state_p->u.expression.operand))
{
jsp_operand_t reg = tmp_operand ();
@@ -1508,7 +1504,7 @@ dump_get_value_for_state_if_ref (jsp_ctx_t *ctx_p,
jsp_operand_t prop_name = state_p->u.expression.prop_name_operand;
bool is_value_based_reference = state_p->is_value_based_reference;
jsp_operand_t val;
jsp_operand_t val = jsp_make_uninitialized_operand ();
bool is_dump = false;
@@ -1520,7 +1516,7 @@ dump_get_value_for_state_if_ref (jsp_ctx_t *ctx_p,
{
JERRY_ASSERT (!state_p->is_get_value_dumped_for_prop_operand);
/* FIXME:
if (obj.is_identifier_operand ())
if (jsp_is_identifier_operand (obj))
{
is_dump = true;
@@ -1535,7 +1531,7 @@ dump_get_value_for_state_if_ref (jsp_ctx_t *ctx_p,
}
}
if (prop_name.is_identifier_operand ())
if (jsp_is_identifier_operand (prop_name))
{
is_dump = true;
@@ -1559,7 +1555,7 @@ dump_get_value_for_state_if_ref (jsp_ctx_t *ctx_p,
{
is_dump = true;
JERRY_ASSERT (!prop_name.is_empty_operand ());
JERRY_ASSERT (!jsp_is_empty_operand (prop_name));
if (!is_check_only)
{
@@ -1574,7 +1570,7 @@ dump_get_value_for_state_if_ref (jsp_ctx_t *ctx_p,
}
}
else if (!is_dump_for_value_based_refs_only
&& (obj.is_identifier_operand () || obj.is_this_operand ()))
&& (jsp_is_identifier_operand (obj) || jsp_is_this_operand (obj)))
{
if (!state_p->is_get_value_dumped_for_main_operand)
{
@@ -1671,7 +1667,7 @@ jsp_start_call_dump (jsp_ctx_t *ctx_p,
obj = state_p->u.expression.operand;
jsp_operand_t prop_name = state_p->u.expression.prop_name_operand;
if (obj.is_identifier_operand ()
if (jsp_is_identifier_operand (obj)
&& !state_p->is_get_value_dumped_for_main_operand)
{
jsp_operand_t reg = tmp_operand ();
@@ -1936,7 +1932,7 @@ jsp_dump_unary_op (jsp_ctx_t *ctx_p,
{
if (!jsp_is_dump_mode (ctx_p))
{
if (substate_p->u.expression.operand.is_identifier_operand ())
if (jsp_is_identifier_operand (substate_p->u.expression.operand))
{
jsp_early_error_check_for_eval_and_arguments_in_strict_mode (substate_p->u.expression.operand,
jsp_is_strict_mode (ctx_p),
@@ -1986,7 +1982,7 @@ jsp_dump_unary_op (jsp_ctx_t *ctx_p,
{
opcode = VM_OP_DELETE_PROP;
}
else if (substate_p->u.expression.operand.is_identifier_operand ())
else if (jsp_is_identifier_operand (substate_p->u.expression.operand))
{
if (!jsp_is_dump_mode (ctx_p))
{
@@ -2025,7 +2021,7 @@ jsp_dump_unary_op (jsp_ctx_t *ctx_p,
}
}
jsp_operand_t dst;
jsp_operand_t dst = tmp_operand ();
if (!substate_p->is_value_based_reference)
{
@@ -2046,20 +2042,16 @@ jsp_dump_unary_op (jsp_ctx_t *ctx_p,
is_combined_with_assignment = true;
}
else
{
dst = tmp_operand ();
}
if (is_dump_simple_assignment)
{
if (is_dump_undefined_or_boolean_true)
{
dump_variable_assignment (ctx_p, dst, jsp_operand_t::make_simple_value_operand (ECMA_SIMPLE_VALUE_UNDEFINED));
dump_variable_assignment (ctx_p, dst, jsp_make_simple_value_operand (ECMA_SIMPLE_VALUE_UNDEFINED));
}
else
{
dump_variable_assignment (ctx_p, dst, jsp_operand_t::make_simple_value_operand (ECMA_SIMPLE_VALUE_TRUE));
dump_variable_assignment (ctx_p, dst, jsp_make_simple_value_operand (ECMA_SIMPLE_VALUE_TRUE));
}
}
else
@@ -2265,7 +2257,7 @@ jsp_dump_binary_op (jsp_ctx_t *ctx_p,
is_combined_with_assignment = true;
}
else if (op1.is_register_operand ())
else if (jsp_is_register_operand (op1))
{
dst = op1;
}
@@ -2797,7 +2789,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
{
JERRY_ASSERT (scope_type == SCOPE_TYPE_EVAL);
dump_retval (ctx_p, jsp_operand_t::make_reg_operand (VM_REG_SPECIAL_EVAL_RET));
dump_retval (ctx_p, jsp_make_reg_operand (VM_REG_SPECIAL_EVAL_RET));
}
jsp_set_scope_type (ctx_p, state_p->u.source_elements.parent_scope_type);
@@ -2918,7 +2910,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
}
case TOK_KW_THIS:
{
state_p->u.expression.operand = jsp_operand_t::make_this_operand ();
state_p->u.expression.operand = jsp_make_this_operand ();
break;
}
case TOK_KW_NEW:
@@ -2944,39 +2936,39 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
}
}
state_p->u.expression.operand = jsp_operand_t::make_identifier_operand (token_data_as_lit_cp ());
state_p->u.expression.operand = jsp_make_identifier_operand (token_data_as_lit_cp ());
break;
}
case TOK_REGEXP:
{
state_p->u.expression.operand = jsp_operand_t::make_regexp_lit_operand (token_data_as_lit_cp ());
state_p->u.expression.operand = jsp_make_regexp_lit_operand (token_data_as_lit_cp ());
break;
}
case TOK_NULL:
{
state_p->u.expression.operand = jsp_operand_t::make_simple_value_operand (ECMA_SIMPLE_VALUE_NULL);
state_p->u.expression.operand = jsp_make_simple_value_operand (ECMA_SIMPLE_VALUE_NULL);
break;
}
case TOK_BOOL:
{
ecma_simple_value_t simple_value = (bool) token_data () ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE;
state_p->u.expression.operand = jsp_operand_t::make_simple_value_operand (simple_value);
state_p->u.expression.operand = jsp_make_simple_value_operand (simple_value);
break;
}
case TOK_SMALL_INT:
{
state_p->u.expression.operand = jsp_operand_t::make_smallint_operand ((uint8_t) token_data ());
state_p->u.expression.operand = jsp_make_smallint_operand ((uint8_t) token_data ());
break;
}
case TOK_NUMBER:
{
state_p->u.expression.operand = jsp_operand_t::make_number_lit_operand (token_data_as_lit_cp ());
state_p->u.expression.operand = jsp_make_number_lit_operand (token_data_as_lit_cp ());
break;
}
case TOK_STRING:
{
state_p->u.expression.operand = jsp_operand_t::make_string_lit_operand (token_data_as_lit_cp ());
state_p->u.expression.operand = jsp_make_string_lit_operand (token_data_as_lit_cp ());
break;
}
default:
@@ -3002,16 +2994,13 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
}
else
{
jsp_operand_t name;
jsp_operand_t name = empty_operand ();
if (token_is (TOK_NAME))
{
name = jsp_operand_t::make_string_lit_operand (token_data_as_lit_cp ());
name = jsp_make_string_lit_operand (token_data_as_lit_cp ());
skip_token (ctx_p);
}
else
{
name = empty_operand ();
}
state_p->u.expression.operand = jsp_start_parse_function_scope (ctx_p, name, true, NULL);
}
@@ -3030,7 +3019,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
jsp_operand_t prop_name = state_p->u.expression.operand;
jsp_operand_t value = substate_p->u.expression.operand;
JERRY_ASSERT (prop_name.is_string_lit_operand ());
JERRY_ASSERT (jsp_is_string_lit_operand (prop_name));
dump_prop_name_and_value (ctx_p, prop_name, value);
@@ -3045,7 +3034,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
}
else
{
JERRY_ASSERT (state_p->u.expression.operand.is_empty_operand ());
JERRY_ASSERT (jsp_is_empty_operand (state_p->u.expression.operand));
state_p->u.expression.operand = parse_property_name ();
skip_token (ctx_p);
@@ -3122,7 +3111,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
EMIT_ERROR (JSP_EARLY_ERROR_SYNTAX, "Invalid number of formal parameters");
}
JERRY_ASSERT (state_p->u.expression.operand.is_empty_operand ());
JERRY_ASSERT (jsp_is_empty_operand (state_p->u.expression.operand));
state_p->u.expression.operand = func;
state_p->u.expression.u.accessor_prop_decl.prop_name = prop_name;
@@ -3250,7 +3239,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
jsp_operand_t reg = tmp_operand ();
dump_variable_assignment (ctx_p,
reg,
jsp_operand_t::make_simple_value_operand (ECMA_SIMPLE_VALUE_ARRAY_HOLE));
jsp_make_simple_value_operand (ECMA_SIMPLE_VALUE_ARRAY_HOLE));
dump_varg (ctx_p, reg);
state_p->u.expression.u.varg_sequence.list_length++;
@@ -3331,7 +3320,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
}
else if (state_p->u.expression.token_type == TOK_OPEN_PAREN)
{
JERRY_ASSERT (state_p->u.expression.operand.is_empty_operand ());
JERRY_ASSERT (jsp_is_empty_operand (state_p->u.expression.operand));
state_p->u.expression.operand = substate_p->u.expression.operand;
state_p->u.expression.prop_name_operand = substate_p->u.expression.prop_name_operand;
@@ -3346,8 +3335,8 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
else if (state_p->u.expression.token_type == TOK_KW_NEW)
{
JERRY_ASSERT (substate_p->state == JSP_STATE_EXPR_MEMBER);
JERRY_ASSERT (state_p->u.expression.operand.is_empty_operand ());
JERRY_ASSERT (!substate_p->u.expression.operand.is_empty_operand ());
JERRY_ASSERT (jsp_is_empty_operand (state_p->u.expression.operand));
JERRY_ASSERT (!jsp_is_empty_operand (substate_p->u.expression.operand));
state_p->u.expression.operand = substate_p->u.expression.operand;
state_p->u.expression.prop_name_operand = substate_p->u.expression.prop_name_operand;
@@ -3447,7 +3436,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
state_p->u.expression.prop_name_operand = tmp_operand ();
dump_variable_assignment (ctx_p,
state_p->u.expression.prop_name_operand,
jsp_operand_t::make_string_lit_operand (prop_name));
jsp_make_string_lit_operand (prop_name));
state_p->is_value_based_reference = true;
}
@@ -3573,7 +3562,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
state_p->u.expression.prop_name_operand = tmp_operand ();
dump_variable_assignment (ctx_p,
state_p->u.expression.prop_name_operand,
jsp_operand_t::make_string_lit_operand (prop_name));
jsp_make_string_lit_operand (prop_name));
state_p->is_value_based_reference = true;
}
@@ -3625,7 +3614,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
if (state_p->is_need_retval)
{
JERRY_ASSERT (state_p->u.expression.operand.is_register_operand ());
JERRY_ASSERT (jsp_is_register_operand (state_p->u.expression.operand));
}
else
{
@@ -3751,7 +3740,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
state_p->u.expression.prop_name_operand = empty_operand ();
state_p->is_value_based_reference = false;
}
else if (state_p->u.expression.operand.is_identifier_operand ())
else if (jsp_is_identifier_operand (state_p->u.expression.operand))
{
if (!jsp_is_dump_mode (ctx_p))
{
@@ -3793,7 +3782,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
state_p->u.expression.prop_name_operand = empty_operand ();
state_p->is_value_based_reference = false;
}
else if (state_p->u.expression.operand.is_identifier_operand ())
else if (jsp_is_identifier_operand (state_p->u.expression.operand))
{
if (!jsp_is_dump_mode (ctx_p))
{
@@ -3826,7 +3815,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
{
if (!jsp_is_dump_mode (ctx_p))
{
if (!state_p->u.expression.operand.is_identifier_operand ())
if (!jsp_is_identifier_operand (state_p->u.expression.operand))
{
PARSE_ERROR (JSP_EARLY_ERROR_REFERENCE, "Invalid left-hand-side expression", tok.loc);
}
@@ -4023,7 +4012,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
JERRY_ASSERT (state_p->u.expression.token_type == TOK_DOUBLE_AND);
JERRY_ASSERT (state_p->u.expression.operand.is_register_operand ());
JERRY_ASSERT (jsp_is_register_operand (state_p->u.expression.operand));
dump_variable_assignment (ctx_p, state_p->u.expression.operand, substate_p->u.expression.operand);
@@ -4132,7 +4121,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
JERRY_ASSERT (state_p->u.expression.token_type == TOK_DOUBLE_OR);
JERRY_ASSERT (state_p->u.expression.operand.is_register_operand ());
JERRY_ASSERT (jsp_is_register_operand (state_p->u.expression.operand));
dump_variable_assignment (ctx_p, state_p->u.expression.operand, substate_p->u.expression.operand);
state_p->u.expression.token_type = TOK_EMPTY;
@@ -4163,7 +4152,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
if (state_p->is_fixed_ret_operand)
{
JERRY_ASSERT (state_p->u.expression.operand.is_register_operand ());
JERRY_ASSERT (jsp_is_register_operand (state_p->u.expression.operand));
ret = state_p->u.expression.operand;
}
@@ -4229,7 +4218,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
current_token_must_be_check_and_skip_it (ctx_p, TOK_COLON);
JERRY_ASSERT (state_p->is_fixed_ret_operand);
JERRY_ASSERT (state_p->u.expression.operand.is_register_operand ());
JERRY_ASSERT (jsp_is_register_operand (state_p->u.expression.operand));
JERRY_ASSERT (substate_p->state == JSP_STATE_EXPR_ASSIGNMENT);
dump_get_value_if_ref (ctx_p, substate_p, true);
@@ -4251,7 +4240,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
JERRY_ASSERT (state_p->u.expression.token_type == TOK_COLON);
JERRY_ASSERT (state_p->is_fixed_ret_operand);
JERRY_ASSERT (state_p->u.expression.operand.is_register_operand ());
JERRY_ASSERT (jsp_is_register_operand (state_p->u.expression.operand));
JERRY_ASSERT (substate_p->state == JSP_STATE_EXPR_ASSIGNMENT);
dump_get_value_if_ref (ctx_p, substate_p, true);
@@ -4288,7 +4277,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
* 11.14, step 2
*/
JERRY_ASSERT (!state_p->is_value_based_reference
&& !state_p->u.expression.operand.is_identifier_operand ());
&& !jsp_is_identifier_operand (state_p->u.expression.operand));
state_p->u.expression.operand = substate_p->u.expression.operand;
}
@@ -4631,7 +4620,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
current_token_must_be (TOK_NAME);
const jsp_operand_t func_name = jsp_operand_t::make_string_lit_operand (token_data_as_lit_cp ());
const jsp_operand_t func_name = jsp_make_string_lit_operand (token_data_as_lit_cp ());
skip_token (ctx_p);
state_p->state = JSP_STATE_FUNC_DECL_FINISH;
@@ -4775,7 +4764,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
current_token_must_be (TOK_NAME);
const lit_cpointer_t lit_cp = token_data_as_lit_cp ();
const jsp_operand_t name = jsp_operand_t::make_string_lit_operand (lit_cp);
const jsp_operand_t name = jsp_make_string_lit_operand (lit_cp);
skip_token (ctx_p);
@@ -5036,7 +5025,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
current_token_must_be (TOK_NAME);
const lit_cpointer_t lit_cp = token_data_as_lit_cp ();
const jsp_operand_t name = jsp_operand_t::make_string_lit_operand (lit_cp);
const jsp_operand_t name = jsp_make_string_lit_operand (lit_cp);
skip_token (ctx_p);
@@ -5077,7 +5066,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
seek_token (ctx_p, state_p->u.statement.u.iterational.u.loop_for_in.u.body_loc);
jsp_operand_t for_in_special_reg = jsp_operand_t::make_reg_operand (VM_REG_SPECIAL_FOR_IN_PROPERTY_NAME);
jsp_operand_t for_in_special_reg = jsp_make_reg_operand (VM_REG_SPECIAL_FOR_IN_PROPERTY_NAME);
if (!state_p->is_var_decl_no_in)
{
@@ -5103,7 +5092,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
lit_cpointer_t var_name_lit_cp = state_p->u.statement.u.iterational.u.loop_for_in.var_name_lit_cp;
dump_variable_assignment (ctx_p, jsp_operand_t::make_identifier_operand (var_name_lit_cp), for_in_special_reg);
dump_variable_assignment (ctx_p, jsp_make_identifier_operand (var_name_lit_cp), for_in_special_reg);
}
state_p->is_simply_jumpable_border = true;
@@ -5178,17 +5167,13 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
current_token_must_be_check_and_skip_it (ctx_p, TOK_COLON);
jsp_operand_t switch_expr = state_p->u.statement.u.switch_statement.expr;
jsp_operand_t condition_reg = tmp_operand ();
jsp_operand_t condition_reg;
if (case_expr.is_register_operand ())
if (jsp_is_register_operand (case_expr))
{
/* reuse the register */
condition_reg = case_expr;
}
else
{
condition_reg = tmp_operand ();
}
dump_binary_op (ctx_p, VM_OP_EQUAL_VALUE_TYPE, condition_reg, switch_expr, case_expr);
@@ -5315,7 +5300,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
current_token_must_be (TOK_NAME);
const jsp_operand_t name = jsp_operand_t::make_string_lit_operand (token_data_as_lit_cp ());
const jsp_operand_t name = jsp_make_string_lit_operand (token_data_as_lit_cp ());
if (!jsp_is_dump_mode (ctx_p))
{
@@ -5447,7 +5432,7 @@ jsp_parse_source_element_list (jsp_ctx_t *ctx_p,
JERRY_ASSERT (substate_p->is_need_retval);
dump_variable_assignment (ctx_p,
jsp_operand_t::make_reg_operand (VM_REG_SPECIAL_EVAL_RET),
jsp_make_reg_operand (VM_REG_SPECIAL_EVAL_RET),
substate_p->u.expression.operand);
}