Skip to content

Commit ab2abfa

Browse files
Fix receiving of byte-code instructions from serializer.
Related issue: #203 JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
1 parent d1055f9 commit ab2abfa

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

jerry-core/parser/js/bytecode-data.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef struct __attribute__ ((aligned (MEM_ALIGNMENT)))
4343
mem_cpointer_t lit_id_hash_cp; /**< pointer to literal identifiers hash table
4444
* See also: lit_id_hash_table_init */
4545
mem_cpointer_t next_opcodes_cp; /**< pointer to next byte-code memory region */
46+
opcode_counter_t instructions_number; /**< number of instructions in the byte-code array */
4647
} opcodes_header_t;
4748

4849
typedef struct

jerry-core/parser/js/serializer.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,27 @@ serializer_get_op_meta (opcode_counter_t oc)
3333
return scopes_tree_op_meta (current_scope, oc);
3434
}
3535

36+
/**
37+
* Get byte-code instruction from current scope, or specified byte-code array
38+
*
39+
* @return byte-code instruction
40+
*/
3641
opcode_t
37-
serializer_get_opcode (opcode_counter_t oc)
42+
serializer_get_opcode (const opcode_t *opcodes_p, /**< pointer to byte-code array (or NULL,
43+
* if instruction should be taken from
44+
* instruction list of current scope) */
45+
opcode_counter_t oc) /**< opcode counter of the intruction */
3846
{
39-
if (bytecode_data.opcodes == NULL)
47+
if (opcodes_p == NULL)
4048
{
4149
return serializer_get_op_meta (oc).op;
4250
}
43-
JERRY_ASSERT (oc < bytecode_data.opcodes_count);
44-
return bytecode_data.opcodes[oc];
45-
}
51+
else
52+
{
53+
JERRY_ASSERT (oc < GET_BYTECODE_HEADER (opcodes_p)->instructions_number);
54+
return opcodes_p[oc];
55+
}
56+
} /* serializer_get_opcode */
4657

4758
/**
4859
* Convert literal id (operand value of instruction) to compressed pointer to literal
@@ -85,7 +96,7 @@ serializer_merge_scopes_into_bytecode (void)
8596

8697
const size_t buckets_count = scopes_tree_count_literals_in_blocks (current_scope);
8798
const size_t blocks_count = (size_t) bytecode_data.opcodes_count / BLOCK_SIZE + 1;
88-
const size_t opcodes_count = scopes_tree_count_opcodes (current_scope);
99+
const opcode_counter_t opcodes_count = scopes_tree_count_opcodes (current_scope);
89100

90101
const size_t opcodes_array_size = JERRY_ALIGNUP (sizeof (opcodes_header_t) + opcodes_count * sizeof (opcode_t),
91102
MEM_ALIGNMENT);
@@ -104,6 +115,7 @@ serializer_merge_scopes_into_bytecode (void)
104115

105116
opcodes_header_t *header_p = (opcodes_header_t*) buffer_p;
106117
MEM_CP_SET_POINTER (header_p->next_opcodes_cp, bytecode_data.opcodes);
118+
header_p->instructions_number = opcodes_count;
107119
bytecode_data.opcodes = opcodes_p;
108120

109121
if (print_opcodes)
@@ -125,7 +137,7 @@ serializer_dump_op_meta (op_meta op)
125137
#ifdef JERRY_ENABLE_PRETTY_PRINTER
126138
if (print_opcodes)
127139
{
128-
pp_op_meta ((opcode_counter_t) (scopes_tree_opcodes_num (current_scope) - 1), op, false);
140+
pp_op_meta (NULL, (opcode_counter_t) (scopes_tree_opcodes_num (current_scope) - 1), op, false);
129141
}
130142
#endif
131143
}
@@ -156,7 +168,7 @@ serializer_rewrite_op_meta (const opcode_counter_t loc, op_meta op)
156168
#ifdef JERRY_ENABLE_PRETTY_PRINTER
157169
if (print_opcodes)
158170
{
159-
pp_op_meta (loc, op, true);
171+
pp_op_meta (NULL, loc, op, true);
160172
}
161173
#endif
162174
}
@@ -176,7 +188,7 @@ serializer_print_opcodes (const opcode_t *opcodes_p,
176188
opm.lit_id[i] = NOT_A_LITERAL;
177189
}
178190

179-
pp_op_meta (loc, opm, false);
191+
pp_op_meta (opcodes_p, loc, opm, false);
180192
}
181193
#else
182194
(void) opcodes_p;

jerry-core/parser/js/serializer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
void serializer_init ();
2626
void serializer_set_show_opcodes (bool show_opcodes);
2727
op_meta serializer_get_op_meta (opcode_counter_t);
28-
opcode_t serializer_get_opcode (opcode_counter_t);
28+
opcode_t serializer_get_opcode (const opcode_t*, opcode_counter_t);
2929
lit_cpointer_t serializer_get_literal_cp_by_uid (uint8_t, const opcode_t*, opcode_counter_t);
3030
void serializer_set_strings_buffer (const ecma_char_t *);
3131
void serializer_set_scope (scopes_tree);

jerry-core/vm/pretty-printer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ dump_asm (opcode_counter_t oc, opcode_t opcode)
179179
}
180180

181181
void
182-
pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
182+
pp_op_meta (const opcode_t *opcodes_p,
183+
opcode_counter_t oc,
184+
op_meta opm,
185+
bool rewrite)
183186
{
184187
dump_asm (oc, opm.op);
185188
printf (" // ");
@@ -393,7 +396,7 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
393396
while ((int16_t) start >= 0 && !found)
394397
{
395398
start--;
396-
switch (serializer_get_opcode (start).op_idx)
399+
switch (serializer_get_opcode (opcodes_p, start).op_idx)
397400
{
398401
case NAME_TO_ID (call_n):
399402
case NAME_TO_ID (native_call):
@@ -408,7 +411,7 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
408411
}
409412
}
410413
}
411-
opcode_t start_op = serializer_get_opcode (start);
414+
opcode_t start_op = serializer_get_opcode (opcodes_p, start);
412415
switch (start_op.op_idx)
413416
{
414417
case NAME_TO_ID (call_n):
@@ -470,7 +473,7 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
470473
}
471474
for (opcode_counter_t counter = start; counter <= oc; counter++)
472475
{
473-
opcode_t meta_op = serializer_get_opcode (counter);
476+
opcode_t meta_op = serializer_get_opcode (opcodes_p, counter);
474477

475478
switch (meta_op.op_idx)
476479
{

jerry-core/vm/pretty-printer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "scopes-tree.h"
2323

2424
void pp_opcode (opcode_counter_t, opcode_t, bool);
25-
void pp_op_meta (opcode_counter_t, op_meta, bool);
25+
void pp_op_meta (const opcode_t*, opcode_counter_t, op_meta, bool);
2626
#endif // JERRY_ENABLE_PRETTY_PRINTER
2727

2828
#endif // PRETTY_PRINTER

0 commit comments

Comments
 (0)