Use symbolic constants for code size checks. (#3682)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-04-17 13:05:07 +02:00
committed by GitHub
parent 895973ca82
commit 4be9ffda84
3 changed files with 34 additions and 40 deletions
+12
View File
@@ -124,6 +124,18 @@ typedef enum
*/
#define PARSER_FUNCTION_CLOSURE (PARSER_IS_FUNCTION | PARSER_IS_CLOSURE)
#if PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX
/**
* Maximum number of bytes for branch target.
*/
#define PARSER_MAX_BRANCH_LENGTH 2
#else /* PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX */
/**
* Maximum number of bytes for branch target.
*/
#define PARSER_MAX_BRANCH_LENGTH 3
#endif /* PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX */
#if ENABLED (JERRY_ES2015)
/**
* Offset between PARSER_CLASS_CONSTRUCTOR and ECMA_PARSE_CLASS_CONSTRUCTOR
+19 -28
View File
@@ -566,11 +566,7 @@ parser_emit_cbc_forward_branch (parser_context_t *context_p, /**< context */
}
#endif /* ENABLED (JERRY_PARSER_DUMP_BYTE_CODE) */
#if PARSER_MAXIMUM_CODE_SIZE <= 65535
opcode++;
#else /* PARSER_MAXIMUM_CODE_SIZE > 65535 */
PARSER_PLUS_EQUAL_U16 (opcode, 2);
#endif /* PARSER_MAXIMUM_CODE_SIZE <= 65535 */
PARSER_PLUS_EQUAL_U16 (opcode, PARSER_MAX_BRANCH_LENGTH - 1);
parser_emit_two_bytes (context_p, (uint8_t) opcode, 0);
branch_p->page_p = context_p->byte_code.last_p;
@@ -578,13 +574,13 @@ parser_emit_cbc_forward_branch (parser_context_t *context_p, /**< context */
context_p->byte_code_size += extra_byte_code_increase;
#if PARSER_MAXIMUM_CODE_SIZE <= 65535
#if PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX
PARSER_APPEND_TO_BYTE_CODE (context_p, 0);
context_p->byte_code_size += 3;
#else /* PARSER_MAXIMUM_CODE_SIZE > 65535 */
#else /* PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX */
parser_emit_two_bytes (context_p, 0, 0);
context_p->byte_code_size += 4;
#endif /* PARSER_MAXIMUM_CODE_SIZE <= 65535 */
#endif /* PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX */
context_p->byte_code_size += PARSER_MAX_BRANCH_LENGTH + 1;
if (context_p->stack_depth > context_p->stack_limit)
{
@@ -681,35 +677,30 @@ parser_emit_cbc_backward_branch (parser_context_t *context_p, /**< context */
#endif /* ENABLED (JERRY_PARSER_DUMP_BYTE_CODE) */
context_p->byte_code_size += 2;
#if PARSER_MAXIMUM_CODE_SIZE <= 65535
if (offset > 255)
#if PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX
if (offset > UINT16_MAX)
{
opcode++;
context_p->byte_code_size++;
}
#else /* PARSER_MAXIMUM_CODE_SIZE > 65535 */
if (offset > 65535)
{
PARSER_PLUS_EQUAL_U16 (opcode, 2);
context_p->byte_code_size += 2;
}
else if (offset > 255)
#endif /* PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX */
if (offset > UINT8_MAX)
{
opcode++;
context_p->byte_code_size++;
}
#endif /* PARSER_MAXIMUM_CODE_SIZE <= 65535 */
PARSER_APPEND_TO_BYTE_CODE (context_p, (uint8_t) opcode);
#if PARSER_MAXIMUM_CODE_SIZE > 65535
if (offset > 65535)
#if PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX
if (offset > UINT16_MAX)
{
PARSER_APPEND_TO_BYTE_CODE (context_p, offset >> 16);
}
#endif /* PARSER_MAXIMUM_CODE_SIZE > 65535 */
#endif /* PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX */
if (offset > 255)
if (offset > UINT8_MAX)
{
PARSER_APPEND_TO_BYTE_CODE (context_p, (offset >> 8) & 0xff);
}
@@ -745,14 +736,14 @@ parser_set_branch_to_current_position (parser_context_t *context_p, /**< context
JERRY_ASSERT (delta <= PARSER_MAXIMUM_CODE_SIZE);
#if PARSER_MAXIMUM_CODE_SIZE <= 65535
#if PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX
page_p->bytes[offset++] = (uint8_t) (delta >> 8);
if (offset >= PARSER_CBC_STREAM_PAGE_SIZE)
{
page_p = page_p->next_p;
offset = 0;
}
#else /* PARSER_MAXIMUM_CODE_SIZE > 65535 */
#else /* PARSER_MAXIMUM_CODE_SIZE > UINT16_MAX */
page_p->bytes[offset++] = (uint8_t) (delta >> 16);
if (offset >= PARSER_CBC_STREAM_PAGE_SIZE)
{
@@ -765,8 +756,8 @@ parser_set_branch_to_current_position (parser_context_t *context_p, /**< context
page_p = page_p->next_p;
offset = 0;
}
#endif /* PARSER_MAXIMUM_CODE_SIZE <= 65535 */
page_p->bytes[offset++] = delta & 0xff;
#endif /* PARSER_MAXIMUM_CODE_SIZE <= UINT16_MAX */
page_p->bytes[offset] = delta & 0xff;
} /* parser_set_branch_to_current_position */
/**
+3 -12
View File
@@ -1087,11 +1087,6 @@ parser_post_processing (parser_context_t *context_p) /**< context */
if (flags & CBC_HAS_BRANCH_ARG)
{
bool prefix_zero = true;
#if PARSER_MAXIMUM_CODE_SIZE <= 65535
cbc_opcode_t jump_forward = CBC_JUMP_FORWARD_2;
#else /* PARSER_MAXIMUM_CODE_SIZE > 65535 */
cbc_opcode_t jump_forward = CBC_JUMP_FORWARD_3;
#endif /* PARSER_MAXIMUM_CODE_SIZE <= 65535 */
/* The leading zeroes are dropped from the stream.
* Although dropping these zeroes for backward
@@ -1114,9 +1109,9 @@ parser_post_processing (parser_context_t *context_p) /**< context */
PARSER_NEXT_BYTE (page_p, offset);
}
if (last_opcode == jump_forward
if (last_opcode == (cbc_opcode_t) (CBC_JUMP_FORWARD + PARSER_MAX_BRANCH_LENGTH - 1)
&& prefix_zero
&& page_p->bytes[offset] == CBC_BRANCH_OFFSET_LENGTH (jump_forward) + 1)
&& page_p->bytes[offset] == PARSER_MAX_BRANCH_LENGTH + 1)
{
/* Uncoditional jumps which jump right after the instruction
* are effectively NOPs. These jumps are removed from the
@@ -1345,11 +1340,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
if (opcode == CBC_JUMP_FORWARD)
{
/* These opcodes are deleted from the stream. */
#if PARSER_MAXIMUM_CODE_SIZE <= 65535
size_t counter = 3;
#else /* PARSER_MAXIMUM_CODE_SIZE > 65535 */
size_t counter = 4;
#endif /* PARSER_MAXIMUM_CODE_SIZE <= 65535 */
size_t counter = PARSER_MAX_BRANCH_LENGTH + 1;
do
{