Simplify code paths within PARSER_DUMP_BYTE_CODE (#2316)

Also fix an uncovered issue in the reporting of switching to strict
mode.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2018-05-10 12:37:19 +02:00
committed by yichoi
parent b0120423da
commit 134845e099
3 changed files with 27 additions and 65 deletions
+2 -8
View File
@@ -1670,9 +1670,6 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
{ {
lexer_lit_location_t lit_location; lexer_lit_location_t lit_location;
uint32_t status_flags = context_p->status_flags; uint32_t status_flags = context_p->status_flags;
#ifdef PARSER_DUMP_BYTE_CODE
bool switch_to_strict_mode = false;
#endif /* PARSER_DUMP_BYTE_CODE */
JERRY_ASSERT (context_p->stack_depth == 0); JERRY_ASSERT (context_p->stack_depth == 0);
@@ -1683,10 +1680,6 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
&& memcmp (PARSER_USE_STRICT_LITERAL, lit_location.char_p, PARSER_USE_STRICT_LENGTH) == 0) && memcmp (PARSER_USE_STRICT_LITERAL, lit_location.char_p, PARSER_USE_STRICT_LENGTH) == 0)
{ {
context_p->status_flags |= PARSER_IS_STRICT; context_p->status_flags |= PARSER_IS_STRICT;
#ifdef PARSER_DUMP_BYTE_CODE
switch_to_strict_mode = true;
#endif /* PARSER_DUMP_BYTE_CODE */
} }
lexer_next_token (context_p); lexer_next_token (context_p);
@@ -1731,7 +1724,8 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
#ifdef PARSER_DUMP_BYTE_CODE #ifdef PARSER_DUMP_BYTE_CODE
if (context_p->is_show_opcodes if (context_p->is_show_opcodes
&& switch_to_strict_mode) && !(status_flags & PARSER_IS_STRICT)
&& (context_p->status_flags & PARSER_IS_STRICT))
{ {
JERRY_DEBUG_MSG (" Note: switch to strict mode\n\n"); JERRY_DEBUG_MSG (" Note: switch to strict mode\n\n");
} }
+13 -32
View File
@@ -86,17 +86,18 @@ void
parser_flush_cbc (parser_context_t *context_p) /**< context */ parser_flush_cbc (parser_context_t *context_p) /**< context */
{ {
uint8_t flags; uint8_t flags;
uint16_t last_opcode = context_p->last_cbc_opcode;
if (context_p->last_cbc_opcode == PARSER_CBC_UNAVAILABLE) if (last_opcode == PARSER_CBC_UNAVAILABLE)
{ {
return; return;
} }
context_p->status_flags |= PARSER_NO_END_LABEL; context_p->status_flags |= PARSER_NO_END_LABEL;
if (PARSER_IS_BASIC_OPCODE (context_p->last_cbc_opcode)) if (PARSER_IS_BASIC_OPCODE (last_opcode))
{ {
cbc_opcode_t opcode = (cbc_opcode_t) context_p->last_cbc_opcode; cbc_opcode_t opcode = (cbc_opcode_t) last_opcode;
JERRY_ASSERT (opcode < CBC_END); JERRY_ASSERT (opcode < CBC_END);
flags = cbc_flags[opcode]; flags = cbc_flags[opcode];
@@ -106,7 +107,7 @@ parser_flush_cbc (parser_context_t *context_p) /**< context */
} }
else else
{ {
cbc_ext_opcode_t opcode = (cbc_ext_opcode_t) PARSER_GET_EXT_OPCODE (context_p->last_cbc_opcode); cbc_ext_opcode_t opcode = (cbc_ext_opcode_t) PARSER_GET_EXT_OPCODE (last_opcode);
JERRY_ASSERT (opcode < CBC_EXT_END); JERRY_ASSERT (opcode < CBC_EXT_END);
flags = cbc_ext_flags[opcode]; flags = cbc_ext_flags[opcode];
@@ -167,18 +168,10 @@ parser_flush_cbc (parser_context_t *context_p) /**< context */
#ifdef PARSER_DUMP_BYTE_CODE #ifdef PARSER_DUMP_BYTE_CODE
if (context_p->is_show_opcodes) if (context_p->is_show_opcodes)
{ {
const char *name_p; JERRY_DEBUG_MSG (" [%3d] %s",
(int) context_p->stack_depth,
if (PARSER_IS_BASIC_OPCODE (context_p->last_cbc_opcode)) PARSER_IS_BASIC_OPCODE (last_opcode) ? cbc_names[last_opcode]
{ : cbc_ext_names[PARSER_GET_EXT_OPCODE (last_opcode)]);
name_p = cbc_names[context_p->last_cbc_opcode];
}
else
{
name_p = cbc_ext_names[PARSER_GET_EXT_OPCODE (context_p->last_cbc_opcode)];
}
JERRY_DEBUG_MSG (" [%3d] %s", (int) context_p->stack_depth, name_p);
if (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2)) if (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2))
{ {
@@ -328,17 +321,10 @@ parser_emit_cbc_push_number (parser_context_t *context_p, /**< context */
#ifdef PARSER_DUMP_BYTE_CODE #ifdef PARSER_DUMP_BYTE_CODE
if (context_p->is_show_opcodes) if (context_p->is_show_opcodes)
{ {
int real_value = value;
if (is_negative_number)
{
real_value = -real_value;
}
JERRY_DEBUG_MSG (" [%3d] %s number:%d\n", JERRY_DEBUG_MSG (" [%3d] %s number:%d\n",
(int) context_p->stack_depth, (int) context_p->stack_depth,
cbc_names[opcode], cbc_names[opcode],
real_value); is_negative_number ? -(int) value : (int) value);
} }
#endif /* PARSER_DUMP_BYTE_CODE */ #endif /* PARSER_DUMP_BYTE_CODE */
@@ -453,14 +439,9 @@ parser_emit_cbc_forward_branch (parser_context_t *context_p, /**< context */
#ifdef PARSER_DUMP_BYTE_CODE #ifdef PARSER_DUMP_BYTE_CODE
if (context_p->is_show_opcodes) if (context_p->is_show_opcodes)
{ {
if (extra_byte_code_increase == 0) JERRY_DEBUG_MSG (" [%3d] %s\n",
{ (int) context_p->stack_depth,
JERRY_DEBUG_MSG (" [%3d] %s\n", (int) context_p->stack_depth, cbc_names[opcode]); extra_byte_code_increase == 0 ? cbc_names[opcode] : cbc_ext_names[opcode]);
}
else
{
JERRY_DEBUG_MSG (" [%3d] %s\n", (int) context_p->stack_depth, cbc_ext_names[opcode]);
}
} }
#endif /* PARSER_DUMP_BYTE_CODE */ #endif /* PARSER_DUMP_BYTE_CODE */
+12 -25
View File
@@ -1238,13 +1238,9 @@ parse_print_final_cbc (ecma_compiled_code_t *compiled_code_p, /**< compiled code
while (byte_code_p < byte_code_end_p) while (byte_code_p < byte_code_end_p)
{ {
cbc_opcode_t opcode; cbc_opcode_t opcode = (cbc_opcode_t) *byte_code_p;
cbc_ext_opcode_t ext_opcode; cbc_ext_opcode_t ext_opcode = CBC_EXT_NOP;
size_t cbc_offset; size_t cbc_offset = (size_t) (byte_code_p - byte_code_start_p);
opcode = (cbc_opcode_t) *byte_code_p;
ext_opcode = CBC_EXT_NOP;
cbc_offset = (size_t) (byte_code_p - byte_code_start_p);
if (opcode != CBC_EXT_OPCODE) if (opcode != CBC_EXT_OPCODE)
{ {
@@ -1274,15 +1270,15 @@ parse_print_final_cbc (ecma_compiled_code_t *compiled_code_p, /**< compiled code
if (opcode == CBC_PUSH_NUMBER_POS_BYTE) if (opcode == CBC_PUSH_NUMBER_POS_BYTE)
{ {
int value = *byte_code_p++; JERRY_DEBUG_MSG (" number:%d\n", *byte_code_p + 1);
JERRY_DEBUG_MSG (" number:%d\n", value + 1); byte_code_p++;
continue; continue;
} }
if (opcode == CBC_PUSH_NUMBER_NEG_BYTE) if (opcode == CBC_PUSH_NUMBER_NEG_BYTE)
{ {
int value = *byte_code_p++; JERRY_DEBUG_MSG (" number:%d\n", -(*byte_code_p + 1));
JERRY_DEBUG_MSG (" number:%d\n", -(value + 1)); byte_code_p++;
continue; continue;
} }
} }
@@ -1342,28 +1338,19 @@ parse_print_final_cbc (ecma_compiled_code_t *compiled_code_p, /**< compiled code
if (flags & CBC_HAS_BRANCH_ARG) if (flags & CBC_HAS_BRANCH_ARG)
{ {
size_t branch_offset_length = CBC_BRANCH_OFFSET_LENGTH (opcode); size_t branch_offset_length = (opcode != CBC_EXT_OPCODE ? CBC_BRANCH_OFFSET_LENGTH (opcode)
: CBC_BRANCH_OFFSET_LENGTH (ext_opcode));
size_t offset = 0; size_t offset = 0;
if (opcode == CBC_EXT_OPCODE)
{
branch_offset_length = CBC_BRANCH_OFFSET_LENGTH (ext_opcode);
}
do do
{ {
offset = (offset << 8) | *byte_code_p++; offset = (offset << 8) | *byte_code_p++;
} }
while (--branch_offset_length > 0); while (--branch_offset_length > 0);
if (CBC_BRANCH_IS_FORWARD (flags)) JERRY_DEBUG_MSG (" offset:%d(->%d)",
{ (int) offset,
JERRY_DEBUG_MSG (" offset:%d(->%d)", (int) offset, (int) (cbc_offset + offset)); (int) (cbc_offset + (CBC_BRANCH_IS_FORWARD (flags) ? offset : -offset)));
}
else
{
JERRY_DEBUG_MSG (" offset:%d(->%d)", (int) offset, (int) (cbc_offset - offset));
}
} }
JERRY_DEBUG_MSG ("\n"); JERRY_DEBUG_MSG ("\n");