Create function variables using the data produced by the pre-scanner. (#3199)

The pre-scanner now is able to track all variable declarations and produces a compressed
stream which store this data for each function and catch block. When a function or
catch block is parsed, this information is decoded and the appropriate variables are
created. Furthermore a stack scope is created which contains the currently available
local variables and their register or literal index.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2019-10-17 15:20:04 +02:00
committed by GitHub
parent fd1f7eab9f
commit 7df87b7778
20 changed files with 2098 additions and 1219 deletions
+75 -17
View File
@@ -85,6 +85,51 @@ parser_emit_two_bytes (parser_context_t *context_p, /**< context */
} \
(context_p)->byte_code.last_p->bytes[(context_p)->byte_code.last_position++] = (uint8_t) (byte)
#if ENABLED (JERRY_PARSER_DUMP_BYTE_CODE)
/**
* Print literal corresponding to the current index
*/
static void
parser_print_literal (parser_context_t *context_p, /**< context */
uint16_t literal_index) /**< index of literal */
{
parser_scope_stack *scope_stack_p = context_p->scope_stack_p;
parser_scope_stack *scope_stack_end_p = scope_stack_p + context_p->scope_stack_top;
int32_t scope_literal_index = -1;
while (scope_stack_p < scope_stack_end_p)
{
scope_stack_end_p--;
if (literal_index == scope_stack_end_p->map_to)
{
scope_literal_index = scope_stack_end_p->map_from;
}
}
if (literal_index < PARSER_REGISTER_START)
{
JERRY_DEBUG_MSG (scope_literal_index != -1 ? " IDX:%d->" : " idx:%d->", literal_index);
lexer_literal_t *literal_p = PARSER_GET_LITERAL (literal_index);
util_print_literal (literal_p);
return;
}
if (scope_literal_index == -1)
{
JERRY_DEBUG_MSG (" reg:%d", (int) (literal_index - PARSER_REGISTER_START));
return;
}
JERRY_DEBUG_MSG (" REG:%d->", (int) (literal_index - PARSER_REGISTER_START));
lexer_literal_t *literal_p = PARSER_GET_LITERAL (scope_stack_end_p->map_from);
util_print_literal (literal_p);
} /* parser_print_literal */
#endif /* ENABLED (JERRY_PARSER_DUMP_BYTE_CODE) */
/**
* Append the current byte code to the stream
*/
@@ -181,26 +226,16 @@ parser_flush_cbc (parser_context_t *context_p) /**< context */
if (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2))
{
uint16_t literal_index = context_p->last_cbc.literal_index;
lexer_literal_t *literal_p = PARSER_GET_LITERAL (literal_index);
JERRY_DEBUG_MSG (" idx:%d->", literal_index);
util_print_literal (literal_p);
parser_print_literal (context_p, context_p->last_cbc.literal_index);
}
if (flags & CBC_HAS_LITERAL_ARG2)
{
uint16_t literal_index = context_p->last_cbc.value;
lexer_literal_t *literal_p = PARSER_GET_LITERAL (literal_index);
JERRY_DEBUG_MSG (" idx:%d->", literal_index);
util_print_literal (literal_p);
parser_print_literal (context_p, context_p->last_cbc.value);
if (!(flags & CBC_HAS_LITERAL_ARG))
{
literal_index = context_p->last_cbc.third_literal_index;
literal_p = PARSER_GET_LITERAL (literal_index);
JERRY_DEBUG_MSG (" idx:%d->", literal_index);
util_print_literal (literal_p);
parser_print_literal (context_p, context_p->last_cbc.third_literal_index);
}
}
@@ -276,6 +311,29 @@ parser_emit_cbc_literal (parser_context_t *context_p, /**< context */
context_p->last_cbc.literal_object_type = LEXER_LITERAL_OBJECT_ANY;
} /* parser_emit_cbc_literal */
/**
* Append a byte code with a literal and value argument
*/
void
parser_emit_cbc_literal_value (parser_context_t *context_p, /**< context */
uint16_t opcode, /**< opcode */
uint16_t literal_index, /**< literal index */
uint16_t value) /**< value */
{
JERRY_ASSERT (PARSER_ARGS_EQ (opcode, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2));
if (context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE)
{
parser_flush_cbc (context_p);
}
context_p->last_cbc_opcode = opcode;
context_p->last_cbc.literal_index = literal_index;
context_p->last_cbc.literal_type = LEXER_UNUSED_LITERAL;
context_p->last_cbc.literal_object_type = LEXER_LITERAL_OBJECT_ANY;
context_p->last_cbc.value = value;
} /* parser_emit_cbc_literal_value */
/**
* Append a byte code with the current literal argument
*/
@@ -754,6 +812,10 @@ parser_error_to_string (parser_error_t error) /**< error code */
{
return "Maximum number of literals reached.";
}
case PARSER_ERR_SCOPE_STACK_LIMIT_REACHED:
{
return "Maximum depth of scope stack reached.";
}
case PARSER_ERR_ARGUMENT_LIMIT_REACHED:
{
return "Maximum number of function arguments reached.";
@@ -762,10 +824,6 @@ parser_error_to_string (parser_error_t error) /**< error code */
{
return "Maximum function stack size reached.";
}
case PARSER_ERR_REGISTER_LIMIT_REACHED:
{
return "Maximum number of registers is reached.";
}
case PARSER_ERR_INVALID_CHARACTER:
{
return "Invalid (unexpected) character.";