Skip to content

Fix receiving of byte-code instructions from serializer #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jerry-core/parser/js/bytecode-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct __attribute__ ((aligned (MEM_ALIGNMENT)))
mem_cpointer_t lit_id_hash_cp; /**< pointer to literal identifiers hash table
* See also: lit_id_hash_table_init */
mem_cpointer_t next_opcodes_cp; /**< pointer to next byte-code memory region */
opcode_counter_t instructions_number; /**< number of instructions in the byte-code array */
} opcodes_header_t;

typedef struct
Expand Down
30 changes: 21 additions & 9 deletions jerry-core/parser/js/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,27 @@ serializer_get_op_meta (opcode_counter_t oc)
return scopes_tree_op_meta (current_scope, oc);
}

/**
* Get byte-code instruction from current scope, or specified byte-code array
*
* @return byte-code instruction
*/
opcode_t
serializer_get_opcode (opcode_counter_t oc)
serializer_get_opcode (const opcode_t *opcodes_p, /**< pointer to byte-code array (or NULL,
* if instruction should be taken from
* instruction list of current scope) */
opcode_counter_t oc) /**< opcode counter of the intruction */
{
if (bytecode_data.opcodes == NULL)
if (opcodes_p == NULL)
{
return serializer_get_op_meta (oc).op;
}
JERRY_ASSERT (oc < bytecode_data.opcodes_count);
return bytecode_data.opcodes[oc];
}
else
{
JERRY_ASSERT (oc < GET_BYTECODE_HEADER (opcodes_p)->instructions_number);
return opcodes_p[oc];
}
} /* serializer_get_opcode */

/**
* Convert literal id (operand value of instruction) to compressed pointer to literal
Expand Down Expand Up @@ -85,7 +96,7 @@ serializer_merge_scopes_into_bytecode (void)

const size_t buckets_count = scopes_tree_count_literals_in_blocks (current_scope);
const size_t blocks_count = (size_t) bytecode_data.opcodes_count / BLOCK_SIZE + 1;
const size_t opcodes_count = scopes_tree_count_opcodes (current_scope);
const opcode_counter_t opcodes_count = scopes_tree_count_opcodes (current_scope);

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

opcodes_header_t *header_p = (opcodes_header_t*) buffer_p;
MEM_CP_SET_POINTER (header_p->next_opcodes_cp, bytecode_data.opcodes);
header_p->instructions_number = opcodes_count;
bytecode_data.opcodes = opcodes_p;

if (print_opcodes)
Expand All @@ -125,7 +137,7 @@ serializer_dump_op_meta (op_meta op)
#ifdef JERRY_ENABLE_PRETTY_PRINTER
if (print_opcodes)
{
pp_op_meta ((opcode_counter_t) (scopes_tree_opcodes_num (current_scope) - 1), op, false);
pp_op_meta (NULL, (opcode_counter_t) (scopes_tree_opcodes_num (current_scope) - 1), op, false);
}
#endif
}
Expand Down Expand Up @@ -156,7 +168,7 @@ serializer_rewrite_op_meta (const opcode_counter_t loc, op_meta op)
#ifdef JERRY_ENABLE_PRETTY_PRINTER
if (print_opcodes)
{
pp_op_meta (loc, op, true);
pp_op_meta (NULL, loc, op, true);
}
#endif
}
Expand All @@ -176,7 +188,7 @@ serializer_print_opcodes (const opcode_t *opcodes_p,
opm.lit_id[i] = NOT_A_LITERAL;
}

pp_op_meta (loc, opm, false);
pp_op_meta (opcodes_p, loc, opm, false);
}
#else
(void) opcodes_p;
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/parser/js/serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
void serializer_init ();
void serializer_set_show_opcodes (bool show_opcodes);
op_meta serializer_get_op_meta (opcode_counter_t);
opcode_t serializer_get_opcode (opcode_counter_t);
opcode_t serializer_get_opcode (const opcode_t*, opcode_counter_t);
lit_cpointer_t serializer_get_literal_cp_by_uid (uint8_t, const opcode_t*, opcode_counter_t);
void serializer_set_strings_buffer (const ecma_char_t *);
void serializer_set_scope (scopes_tree);
Expand Down
11 changes: 7 additions & 4 deletions jerry-core/vm/pretty-printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ dump_asm (opcode_counter_t oc, opcode_t opcode)
}

void
pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
pp_op_meta (const opcode_t *opcodes_p,
opcode_counter_t oc,
op_meta opm,
bool rewrite)
{
dump_asm (oc, opm.op);
printf (" // ");
Expand Down Expand Up @@ -393,7 +396,7 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
while ((int16_t) start >= 0 && !found)
{
start--;
switch (serializer_get_opcode (start).op_idx)
switch (serializer_get_opcode (opcodes_p, start).op_idx)
{
case NAME_TO_ID (call_n):
case NAME_TO_ID (native_call):
Expand All @@ -408,7 +411,7 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
}
}
}
opcode_t start_op = serializer_get_opcode (start);
opcode_t start_op = serializer_get_opcode (opcodes_p, start);
switch (start_op.op_idx)
{
case NAME_TO_ID (call_n):
Expand Down Expand Up @@ -470,7 +473,7 @@ pp_op_meta (opcode_counter_t oc, op_meta opm, bool rewrite)
}
for (opcode_counter_t counter = start; counter <= oc; counter++)
{
opcode_t meta_op = serializer_get_opcode (counter);
opcode_t meta_op = serializer_get_opcode (opcodes_p, counter);

switch (meta_op.op_idx)
{
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/vm/pretty-printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "scopes-tree.h"

void pp_opcode (opcode_counter_t, opcode_t, bool);
void pp_op_meta (opcode_counter_t, op_meta, bool);
void pp_op_meta (const opcode_t*, opcode_counter_t, op_meta, bool);
#endif // JERRY_ENABLE_PRETTY_PRINTER

#endif // PRETTY_PRINTER