Improve line info construction (#4718)

- Simplify small encoding
- Better line info for some corner cases

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-07-16 16:08:38 +02:00
committed by GitHub
parent d5a7839632
commit 252d68936f
7 changed files with 61 additions and 64 deletions
@@ -38,8 +38,9 @@
* The format is big endian.
*
* Small:
* First byte can encode signed values between 127 and -125 in 1 byte.
* Large values requires more bytes than vlq.
* One byte can encode signed values between 127 and -126.
* Two byte can encode signed values between 319 and -318.
* Large values are encoded with vlq with a prefix byte.
*
* The line-info data structure is a sequence of chunks:
*
@@ -87,7 +88,7 @@
/**
* Maximum number of bytes requires to encode a number.
*/
#define PARSER_LINE_INFO_BUFFER_MAX_SIZE 5
#define PARSER_LINE_INFO_BUFFER_MAX_SIZE 6
/**
* Stream generation ends after this size is reached,
@@ -160,41 +161,21 @@ static uint32_t
parser_line_info_encode_small (uint8_t *buffer_p, /**< target buffer */
uint32_t value) /**< encoded value */
{
if (value < ECMA_LINE_INFO_ENCODE_TWO_BYTE_MIN)
if (JERRY_LIKELY (value < ECMA_LINE_INFO_ENCODE_TWO_BYTE_MIN))
{
buffer_p[0] = (uint8_t) value;
return 1;
}
uint32_t length;
if (JERRY_LIKELY (value < ECMA_LINE_INFO_ENCODE_THREE_BYTE_MIN))
if (JERRY_LIKELY (value < ECMA_LINE_INFO_ENCODE_VLQ_MIN))
{
value -= ECMA_LINE_INFO_ENCODE_TWO_BYTE_MIN;
buffer_p[0] = ECMA_LINE_INFO_ENCODE_TWO_BYTE;
length = 2;
}
else
{
if (value <= (ECMA_LINE_INFO_ENCODE_THREE_BYTE_MIN + UINT16_MAX))
{
value -= ECMA_LINE_INFO_ENCODE_THREE_BYTE_MIN;
buffer_p[0] = ECMA_LINE_INFO_ENCODE_THREE_BYTE;
length = 3;
}
else
{
buffer_p[0] = ECMA_LINE_INFO_ENCODE_FIVE_BYTE;
buffer_p[3] = (uint8_t) (value >> 16);
buffer_p[4] = (uint8_t) (value >> 24);
length = 5;
}
buffer_p[2] = (uint8_t) (value >> 8);
buffer_p[1] = (uint8_t) (value - ECMA_LINE_INFO_ENCODE_TWO_BYTE_MIN);
return 2;
}
buffer_p[1] = (uint8_t) value;
return length;
*buffer_p++ = ECMA_LINE_INFO_ENCODE_VLQ;
return parser_line_info_encode_vlq (buffer_p, value - ECMA_LINE_INFO_ENCODE_VLQ_MIN) + 1;
} /* parser_line_info_encode_small */
/**
+14
View File
@@ -3339,6 +3339,13 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
{
if (context_p->status_flags & PARSER_IS_CLOSURE)
{
#if JERRY_LINE_INFO
if (context_p->line_info.first_page_p == NULL)
{
parser_line_info_append (context_p, context_p->token.line, context_p->token.column);
}
#endif /* JERRY_LINE_INFO */
parser_stack_pop_uint8 (context_p);
context_p->last_statement.current_p = NULL;
/* There is no lexer_next_token here, since the
@@ -3501,6 +3508,13 @@ consume_last_statement:
{
parser_raise_error (context_p, PARSER_ERR_STATEMENT_EXPECTED);
}
#if JERRY_LINE_INFO
if (context_p->line_info.first_page_p == NULL)
{
parser_line_info_append (context_p, context_p->token.line, context_p->token.column);
}
#endif /* JERRY_LINE_INFO */
} /* parser_parse_statements */
/**
+15 -6
View File
@@ -650,10 +650,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
#endif /* JERRY_ESNEXT */
#if JERRY_LINE_INFO
if (context_p->line_info.first_page_p == NULL)
{
parser_line_info_append (context_p, context_p->token.line, context_p->token.column);
}
JERRY_ASSERT (context_p->line_info.first_page_p != NULL);
#endif /* JERRY_LINE_INFO */
JERRY_ASSERT (context_p->stack_depth == 0);
@@ -2484,6 +2481,10 @@ parser_parse_arrow_function (parser_context_t *context_p, /**< context */
parser_raise_error (context_p, PARSER_ERR_NON_STRICT_ARG_DEFINITION);
}
#if JERRY_LINE_INFO
parser_line_info_append (context_p, context_p->token.line, context_p->token.column);
#endif /* JERRY_LINE_INFO */
parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA);
if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL)
@@ -2600,12 +2601,13 @@ parser_parse_class_fields (parser_context_t *context_p) /**< context */
scanner_seek (context_p);
}
context_p->source_end_p = range.source_end_p;
lexer_next_token (context_p);
#if JERRY_LINE_INFO
parser_line_info_append (context_p, context_p->token.line, context_p->token.column);
#endif /* JERRY_LINE_INFO */
context_p->source_end_p = range.source_end_p;
lexer_next_token (context_p);
parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA);
if (context_p->token.type != LEXER_EOS)
@@ -2657,6 +2659,13 @@ parser_parse_class_fields (parser_context_t *context_p) /**< context */
context_p->source_end_p = source_end_p;
scanner_set_location (context_p, &end_location);
#if JERRY_LINE_INFO
if (context_p->line_info.first_page_p == NULL)
{
parser_line_info_append (context_p, context_p->token.line, context_p->token.column);
}
#endif /* JERRY_LINE_INFO */
compiled_code_p = parser_post_processing (context_p);
#if JERRY_PARSER_DUMP_BYTE_CODE