Skip to content

Commit ff21777

Browse files
committed
Integrate JS parser module better with JRT
The fact that the JS parser had been developed as a separate component for a while is still visible from some macros that mirror things from JRT. This patch removes those duplicates and makes the JS parser rely on jrt.h. (The removed macros are: `PARSER_DEBUG`, `PARSER_INLINE`, `PARSER_NOINLINE`.) JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent 48812b4 commit ff21777

File tree

5 files changed

+49
-58
lines changed

5 files changed

+49
-58
lines changed

jerry-core/parser/js/common.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
* @{
3434
*/
3535

36-
#ifndef JERRY_NDEBUG
37-
#define PARSER_DEBUG
38-
#endif /* !JERRY_NDEBUG */
39-
4036
#ifndef JERRY_NDEBUG
4137
/* Note: This flag is independent from debug mode. */
4238
#define PARSER_DUMP_BYTE_CODE
@@ -137,11 +133,6 @@ void util_print_literal (lexer_literal_t *);
137133
} \
138134
}
139135

140-
/* Other */
141-
142-
#define PARSER_INLINE inline
143-
#define PARSER_NOINLINE __attribute__ ((noinline))
144-
145136
/**
146137
* @}
147138
* @}

jerry-core/parser/js/js-parser-expr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static const uint8_t parser_binary_precedence_table[36] =
4343
/**
4444
* Generate byte code for operators with lvalue.
4545
*/
46-
static PARSER_INLINE void
46+
static inline void
4747
parser_push_result (parser_context_t *context_p) /**< context */
4848
{
4949
if (CBC_NO_RESULT_COMPOUND_ASSIGMENT (context_p->last_cbc_opcode))

jerry-core/parser/js/js-parser-internal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ typedef struct parser_saved_context_t
223223
uint32_t byte_code_size; /**< byte code size for branches */
224224
parser_mem_data_t literal_pool_data; /**< literal list */
225225

226-
#ifdef PARSER_DEBUG
226+
#ifndef JERRY_NDEBUG
227227
uint16_t context_stack_depth; /**< current context stack depth */
228-
#endif /* PARSER_DEBUG */
228+
#endif /* !JERRY_NDEBUG */
229229
} parser_saved_context_t;
230230

231231
/**
@@ -271,10 +271,10 @@ typedef struct
271271
parser_mem_page_t *free_page_p; /**< space for fast allocation */
272272
uint8_t stack_top_uint8; /**< top byte stored on the stack */
273273

274-
#ifdef PARSER_DEBUG
274+
#ifndef JERRY_NDEBUG
275275
/* Variables for debugging / logging. */
276276
uint16_t context_stack_depth; /**< current context stack depth */
277-
#endif /* PARSER_DEBUG */
277+
#endif /* !JERRY_NDEBUG */
278278

279279
#ifdef PARSER_DUMP_BYTE_CODE
280280
int is_show_opcodes; /**< show opcodes */

jerry-core/parser/js/js-parser-statm.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ typedef struct
171171
*
172172
* @return size consumed by a statement.
173173
*/
174-
static PARSER_INLINE size_t
174+
static inline size_t
175175
parser_statement_length (uint8_t type) /**< type of statement */
176176
{
177177
static const uint8_t statement_lengths[12] =
@@ -211,7 +211,7 @@ parser_statement_length (uint8_t type) /**< type of statement */
211211
/**
212212
* Initialize a range from the current location.
213213
*/
214-
static PARSER_INLINE void
214+
static inline void
215215
parser_save_range (parser_context_t *context_p, /**< context */
216216
lexer_range_t *range_p, /**< destination range */
217217
const uint8_t *source_end_p) /**< source end */
@@ -225,7 +225,7 @@ parser_save_range (parser_context_t *context_p, /**< context */
225225
/**
226226
* Set the current location on the stack.
227227
*/
228-
static PARSER_INLINE void
228+
static inline void
229229
parser_set_range (parser_context_t *context_p, /**< context */
230230
lexer_range_t *range_p) /**< destination range */
231231
{
@@ -238,7 +238,7 @@ parser_set_range (parser_context_t *context_p, /**< context */
238238
/**
239239
* Initialize stack iterator.
240240
*/
241-
static PARSER_INLINE void
241+
static inline void
242242
parser_stack_iterator_init (parser_context_t *context_p, /**< context */
243243
parser_stack_iterator_t *iterator) /**< iterator */
244244
{
@@ -249,7 +249,7 @@ parser_stack_iterator_init (parser_context_t *context_p, /**< context */
249249
/**
250250
* Read the next byte from the stack.
251251
*/
252-
static PARSER_INLINE uint8_t
252+
static inline uint8_t
253253
parser_stack_iterator_read_uint8 (parser_stack_iterator_t *iterator) /**< iterator */
254254
{
255255
JERRY_ASSERT (iterator->current_position > 0 && iterator->current_position <= PARSER_STACK_PAGE_SIZE);
@@ -259,7 +259,7 @@ parser_stack_iterator_read_uint8 (parser_stack_iterator_t *iterator) /**< iterat
259259
/**
260260
* Change last byte of the stack.
261261
*/
262-
static PARSER_INLINE void
262+
static inline void
263263
parser_stack_change_last_uint8 (parser_context_t *context_p, /**< context */
264264
uint8_t new_value) /**< new value */
265265
{
@@ -275,7 +275,7 @@ parser_stack_change_last_uint8 (parser_context_t *context_p, /**< context */
275275
/**
276276
* Parse expression enclosed in parens.
277277
*/
278-
static PARSER_INLINE void
278+
static inline void
279279
parser_parse_enclosed_expr (parser_context_t *context_p) /**< context */
280280
{
281281
lexer_next_token (context_p);
@@ -494,9 +494,9 @@ parser_parse_with_statement_start (parser_context_t *context_p) /**< context */
494494

495495
parser_parse_enclosed_expr (context_p);
496496

497-
#ifdef PARSER_DEBUG
497+
#ifndef JERRY_NDEBUG
498498
PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_WITH_CONTEXT_STACK_ALLOCATION);
499-
#endif /* PARSER_DEBUG */
499+
#endif /* !JERRY_NDEBUG */
500500

501501
context_p->status_flags |= PARSER_INSIDE_WITH | PARSER_LEXICAL_ENV_NEEDED;
502502
parser_emit_cbc_ext_forward_branch (context_p,
@@ -525,9 +525,9 @@ parser_parse_with_statement_end (parser_context_t *context_p) /**< context */
525525

526526
parser_flush_cbc (context_p);
527527
PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_WITH_CONTEXT_STACK_ALLOCATION);
528-
#ifdef PARSER_DEBUG
528+
#ifndef JERRY_NDEBUG
529529
PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_WITH_CONTEXT_STACK_ALLOCATION);
530-
#endif /* PARSER_DEBUG */
530+
#endif /* !JERRY_NDEBUG */
531531

532532
parser_emit_cbc (context_p, CBC_CONTEXT_END);
533533
parser_set_branch_to_current_position (context_p, &with_statement.branch);
@@ -638,7 +638,7 @@ parser_parse_while_statement_start (parser_context_t *context_p) /**< context */
638638
/**
639639
* Parse while statement (ending part).
640640
*/
641-
static void PARSER_NOINLINE
641+
static void __attr_noinline___
642642
parser_parse_while_statement_end (parser_context_t *context_p) /**< context */
643643
{
644644
parser_while_statement_t while_statement;
@@ -720,9 +720,9 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */
720720
parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED);
721721
}
722722

723-
#ifdef PARSER_DEBUG
723+
#ifndef JERRY_NDEBUG
724724
PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION);
725-
#endif /* PARSER_DEBUG */
725+
#endif /* !JERRY_NDEBUG */
726726

727727
parser_emit_cbc_ext_forward_branch (context_p,
728728
CBC_EXT_FOR_IN_CREATE_CONTEXT,
@@ -878,7 +878,7 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */
878878
/**
879879
* Parse for statement (ending part).
880880
*/
881-
static void PARSER_NOINLINE
881+
static void __attr_noinline___
882882
parser_parse_for_statement_end (parser_context_t *context_p) /**< context */
883883
{
884884
parser_for_statement_t for_statement;
@@ -953,7 +953,7 @@ parser_parse_for_statement_end (parser_context_t *context_p) /**< context */
953953
/**
954954
* Parse switch statement (starting part).
955955
*/
956-
static void PARSER_NOINLINE
956+
static void __attr_noinline___
957957
parser_parse_switch_statement_start (parser_context_t *context_p) /**< context */
958958
{
959959
parser_switch_statement_t switch_statement;
@@ -1120,9 +1120,9 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */
11201120
{
11211121
parser_flush_cbc (context_p);
11221122
PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION);
1123-
#ifdef PARSER_DEBUG
1123+
#ifndef JERRY_NDEBUG
11241124
PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION);
1125-
#endif /* PARSER_DEBUG */
1125+
#endif /* !JERRY_NDEBUG */
11261126

11271127
parser_emit_cbc (context_p, CBC_CONTEXT_END);
11281128
parser_set_branch_to_current_position (context_p, &try_statement.branch);
@@ -1137,9 +1137,9 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */
11371137
{
11381138
parser_flush_cbc (context_p);
11391139
PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION);
1140-
#ifdef PARSER_DEBUG
1140+
#ifndef JERRY_NDEBUG
11411141
PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION);
1142-
#endif /* PARSER_DEBUG */
1142+
#endif /* !JERRY_NDEBUG */
11431143

11441144
parser_emit_cbc (context_p, CBC_CONTEXT_END);
11451145
parser_flush_cbc (context_p);
@@ -1641,9 +1641,9 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
16411641
while (context_p->token.type != LEXER_EOS
16421642
|| context_p->stack_top_uint8 != PARSER_STATEMENT_START)
16431643
{
1644-
#ifdef PARSER_DEBUG
1644+
#ifndef JERRY_NDEBUG
16451645
JERRY_ASSERT (context_p->stack_depth == context_p->context_stack_depth);
1646-
#endif /* PARSER_DEBUG */
1646+
#endif /* !JERRY_NDEBUG */
16471647

16481648
switch (context_p->token.type)
16491649
{
@@ -1747,9 +1747,9 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
17471747
parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED);
17481748
}
17491749

1750-
#ifdef PARSER_DEBUG
1750+
#ifndef JERRY_NDEBUG
17511751
PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION);
1752-
#endif /* PARSER_DEBUG */
1752+
#endif /* !JERRY_NDEBUG */
17531753

17541754
try_statement.type = parser_try_block;
17551755
parser_emit_cbc_ext_forward_branch (context_p,
@@ -1922,9 +1922,9 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
19221922
parser_stack_pop_uint8 (context_p);
19231923
context_p->last_statement.current_p = NULL;
19241924
JERRY_ASSERT (context_p->stack_depth == 0);
1925-
#ifdef PARSER_DEBUG
1925+
#ifndef JERRY_NDEBUG
19261926
JERRY_ASSERT (context_p->context_stack_depth == 0);
1927-
#endif /* PARSER_DEBUG */
1927+
#endif /* !JERRY_NDEBUG */
19281928
/* There is no lexer_next_token here, since the
19291929
* next token belongs to the parent context. */
19301930
return;
@@ -2015,9 +2015,9 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
20152015

20162016
parser_flush_cbc (context_p);
20172017
PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION);
2018-
#ifdef PARSER_DEBUG
2018+
#ifndef JERRY_NDEBUG
20192019
PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION);
2020-
#endif /* PARSER_DEBUG */
2020+
#endif /* !JERRY_NDEBUG */
20212021

20222022
parser_emit_cbc_ext_backward_branch (context_p,
20232023
CBC_EXT_BRANCH_IF_FOR_IN_HAS_NEXT,
@@ -2044,9 +2044,9 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
20442044
}
20452045

20462046
JERRY_ASSERT (context_p->stack_depth == 0);
2047-
#ifdef PARSER_DEBUG
2047+
#ifndef JERRY_NDEBUG
20482048
JERRY_ASSERT (context_p->context_stack_depth == 0);
2049-
#endif /* PARSER_DEBUG */
2049+
#endif /* !JERRY_NDEBUG */
20502050

20512051
parser_stack_pop_uint8 (context_p);
20522052
context_p->last_statement.current_p = NULL;
@@ -2060,7 +2060,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
20602060
/**
20612061
* Free jumps stored on the stack if a parse error is occured.
20622062
*/
2063-
void PARSER_NOINLINE
2063+
void __attr_noinline___
20642064
parser_free_jumps (parser_stack_iterator_t iterator) /**< iterator position */
20652065
{
20662066
while (PARSER_TRUE)

jerry-core/parser/js/js-parser.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ parser_compute_indicies (parser_context_t *context_p, /**< context */
388388
*
389389
* @return position after the encoded values
390390
*/
391-
static PARSER_INLINE uint8_t *
391+
static inline uint8_t *
392392
parser_encode_literal (uint8_t *dst_p, /**< destination buffer */
393393
uint16_t literal_index, /**< literal index */
394394
uint16_t literal_one_byte_limit) /**< maximum value of a literal
@@ -445,9 +445,9 @@ parser_generate_initializers (parser_context_t *context_p, /**< context */
445445
if (context_p->status_flags & PARSER_HAS_INITIALIZED_VARS)
446446
{
447447
const uint8_t expected_status_flags = LEXER_FLAG_VAR | LEXER_FLAG_NO_REG_STORE | LEXER_FLAG_INITIALIZED;
448-
#ifdef PARSER_DEBUG
448+
#ifndef JERRY_NDEBUG
449449
uint16_t next_index = uninitialized_var_end;
450-
#endif
450+
#endif /* !JERRY_NDEBUG */
451451

452452
context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED;
453453

@@ -474,10 +474,10 @@ parser_generate_initializers (parser_context_t *context_p, /**< context */
474474
uint16_t init_index;
475475

476476
JERRY_ASSERT (literal_p->type == LEXER_IDENT_LITERAL);
477-
#ifdef PARSER_DEBUG
477+
#ifndef JERRY_NDEBUG
478478
JERRY_ASSERT (literal_p->prop.index == next_index);
479479
next_index++;
480-
#endif
480+
#endif /* !JERRY_NDEBUG */
481481
literal_p->status_flags = (uint8_t) (literal_p->status_flags & ~LEXER_FLAG_INITIALIZED);
482482

483483

@@ -1849,9 +1849,9 @@ parser_parse_source (const uint8_t *source_p, /**< valid UTF-8 source code */
18491849
(uint32_t) ((128 - sizeof (void *)) / sizeof (lexer_literal_t)));
18501850
parser_stack_init (&context);
18511851

1852-
#ifdef PARSER_DEBUG
1852+
#ifndef JERRY_NDEBUG
18531853
context.context_stack_depth = 0;
1854-
#endif /* PARSER_DEBUG */
1854+
#endif /* !JERRY_NDEBUG */
18551855

18561856
#ifdef PARSER_DUMP_BYTE_CODE
18571857
context.is_show_opcodes = parser_show_instrs;
@@ -1967,9 +1967,9 @@ parser_parse_function (parser_context_t *context_p, /**< context */
19671967
saved_context.byte_code_size = context_p->byte_code_size;
19681968
saved_context.literal_pool_data = context_p->literal_pool.data;
19691969

1970-
#ifdef PARSER_DEBUG
1970+
#ifndef JERRY_NDEBUG
19711971
saved_context.context_stack_depth = context_p->context_stack_depth;
1972-
#endif /* PARSER_DEBUG */
1972+
#endif /* !JERRY_NDEBUG */
19731973

19741974
/* Reset private part of the context. */
19751975

@@ -1990,9 +1990,9 @@ parser_parse_function (parser_context_t *context_p, /**< context */
19901990
context_p->byte_code_size = 0;
19911991
parser_list_reset (&context_p->literal_pool);
19921992

1993-
#ifdef PARSER_DEBUG
1993+
#ifndef JERRY_NDEBUG
19941994
context_p->context_stack_depth = 0;
1995-
#endif /* PARSER_DEBUG */
1995+
#endif /* !JERRY_NDEBUG */
19961996

19971997
#ifdef PARSER_DUMP_BYTE_CODE
19981998
if (context_p->is_show_opcodes)
@@ -2184,9 +2184,9 @@ parser_parse_function (parser_context_t *context_p, /**< context */
21842184
context_p->byte_code_size = saved_context.byte_code_size;
21852185
context_p->literal_pool.data = saved_context.literal_pool_data;
21862186

2187-
#ifdef PARSER_DEBUG
2187+
#ifndef JERRY_NDEBUG
21882188
context_p->context_stack_depth = saved_context.context_stack_depth;
2189-
#endif /* PARSER_DEBUG */
2189+
#endif /* !JERRY_NDEBUG */
21902190

21912191
return compiled_code_p;
21922192
} /* parser_parse_function */

0 commit comments

Comments
 (0)