Fix style in liboptimizer

This commit is contained in:
e.gavrin
2014-08-13 16:41:39 +04:00
parent c5f33d184d
commit 350580c49e
5 changed files with 418 additions and 376 deletions
+24 -16
View File
@@ -26,12 +26,16 @@ deserialize_string_by_id (uint8_t id)
uint16_t offset;
if (bytecode_data == NULL)
{
return NULL;
}
size = *bytecode_data;
if (id >= size)
{
return NULL;
}
data = bytecode_data;
@@ -49,27 +53,31 @@ deserialize_num_by_id (uint8_t id)
str_size = *bytecode_data;
if (id < str_size)
{
return 0;
}
{
return 0;
}
id = (uint8_t) (id - str_size);
if (num_data == NULL)
{
// Go to last string's offset
uint8_t *data = (uint8_t *) (bytecode_data + str_size * 2 - 1);
str_offset = *((uint16_t *) data);
data = bytecode_data + str_offset;
while (*data)
{
// Go to last string's offset
uint8_t *data = (uint8_t *) (bytecode_data + str_size * 2 - 1);
str_offset = *((uint16_t *) data);
data = bytecode_data + str_offset;
while (*data)
data++;
num_size = *(++data);
num_data = (ecma_number_t *) ++data;
data++;
}
num_size = *(++data);
num_data = (ecma_number_t *) ++data;
}
if (id >= num_size)
{
return 0;
}
return num_data[id];
}
@@ -86,9 +94,9 @@ deserialize_min_temp (void)
uint8_t str_size = *bytecode_data;
if (num_size == 0)
{
deserialize_num_by_id (str_size); // Init num_data and num_size
}
{
deserialize_num_by_id (str_size); // Init num_data and num_size
}
return (uint8_t) (str_size + num_size);
}
+301 -285
View File
@@ -32,7 +32,7 @@
assignment ... +
call_n ...
var_?_end
*/
*/
static void
optimize_calls (OPCODE *opcodes)
{
@@ -41,15 +41,15 @@ optimize_calls (OPCODE *opcodes)
for (current_opcode = opcodes;
current_opcode->op_idx != NAME_TO_ID (exitval);
current_opcode++)
{
if (current_opcode->op_idx == NAME_TO_ID (call_n)
&& (current_opcode + 1)->op_idx == NAME_TO_ID (assignment))
{
if (current_opcode->op_idx == NAME_TO_ID (call_n)
&& (current_opcode + 1)->op_idx == NAME_TO_ID (assignment))
{
OPCODE temp = *current_opcode;
*current_opcode = *(current_opcode + 1);
*(current_opcode + 1) = temp;
}
OPCODE temp = *current_opcode;
*current_opcode = *(current_opcode + 1);
*(current_opcode + 1) = temp;
}
}
}
/* Move NUMBER opcodes from FROM to TO and adjust opcodes beetwen FROM and TO. */
@@ -60,44 +60,50 @@ optimizer_move_opcodes (OPCODE *from, OPCODE *to, uint16_t number)
uint16_t i;
if (to == from)
{
return;
}
for (i = 0; i < number; i++)
{
temp[i] = from[i];
}
if (to > from)
{
if (number <= to - from)
{
if (number <= to - from)
{
// Adjust opcodes up
for (current_opcode = from; current_opcode != to; current_opcode++)
{
*current_opcode = *(current_opcode + number);
}
}
else
{
optimizer_move_opcodes (from + number, from, (uint16_t) (to - from));
}
// Adjust opcodes up
for (current_opcode = from; current_opcode != to; current_opcode++)
{
*current_opcode = *(current_opcode + number);
}
}
else
{
optimizer_move_opcodes (from + number, from, (uint16_t) (to - from));
}
}
else
{
if (number <= from - to)
{
if (number <= from - to)
{
// Adjust opcodes down
for (current_opcode = from; current_opcode != to; current_opcode--)
{
*current_opcode = *(current_opcode - number);
}
}
else
{
optimizer_move_opcodes (to, to + number, (uint16_t) (from - to));
}
// Adjust opcodes down
for (current_opcode = from; current_opcode != to; current_opcode--)
{
*current_opcode = *(current_opcode - number);
}
}
else
{
optimizer_move_opcodes (to, to + number, (uint16_t) (from - to));
}
}
for (i = 0; i < number; i++)
{
to[i] = temp[i];
}
}
static uint16_t
@@ -115,198 +121,206 @@ optimizer_adjust_jumps (OPCODE *first_opcode, OPCODE *last_opcode, int16_t value
JERRY_ASSERT (first_opcode <= last_opcode);
for (current_opcode = first_opcode; current_opcode != last_opcode; current_opcode++)
{
if (current_opcode->op_idx == NAME_TO_ID (is_true_jmp))
{
if (current_opcode->op_idx == NAME_TO_ID (is_true_jmp))
{
/* 19: is_true_jmp 2
20: var_decl ...
/* 19: is_true_jmp 2
20: var_decl ...
becomes
becomes
19: var_decl ...
20: is_true_jmp 2
*/
if (current_opcode->data.is_true_jmp.opcode >= opcode_to_counter (last_opcode)
|| current_opcode->data.is_true_jmp.opcode < opcode_to_counter (first_opcode) - value)
continue;
19: var_decl ...
20: is_true_jmp 2
*/
if (current_opcode->data.is_true_jmp.opcode >= opcode_to_counter (last_opcode)
|| current_opcode->data.is_true_jmp.opcode < opcode_to_counter (first_opcode) - value)
{
continue;
}
/* 19: is_true_jmp 20
20: assignment
21: var_decl
/* 19: is_true_jmp 20
20: assignment
21: var_decl
becomes
becomes
19: var_decl
20: is_true_jmp 21
21: assignment
*/
if (current_opcode->data.is_true_jmp.opcode >= opcode_to_counter (first_opcode)
&& current_opcode->data.is_true_jmp.opcode <= opcode_to_counter (last_opcode) - value)
{
current_opcode->data.is_true_jmp.opcode = (T_IDX) (current_opcode->data.is_true_jmp.opcode + value);
continue;
}
19: var_decl
20: is_true_jmp 21
21: assignment
*/
if (current_opcode->data.is_true_jmp.opcode >= opcode_to_counter (first_opcode)
&& current_opcode->data.is_true_jmp.opcode <= opcode_to_counter (last_opcode) - value)
{
current_opcode->data.is_true_jmp.opcode = (T_IDX) (current_opcode->data.is_true_jmp.opcode + value);
continue;
}
/* 19: is_true_jmp 22
20: assignment
21: var_decl
22: var_decl
/* 19: is_true_jmp 22
20: assignment
21: var_decl
22: var_decl
becomes
becomes
19: var_decl
20: var_decl
21: is_true_jmp 23
22: assignment
*/
if (current_opcode->data.is_true_jmp.opcode < opcode_to_counter (last_opcode))
{
current_opcode->data.is_true_jmp.opcode = (T_IDX) opcode_to_counter (last_opcode);
continue;
}
19: var_decl
20: var_decl
21: is_true_jmp 23
22: assignment
*/
if (current_opcode->data.is_true_jmp.opcode < opcode_to_counter (last_opcode))
{
current_opcode->data.is_true_jmp.opcode = (T_IDX) opcode_to_counter (last_opcode);
continue;
}
JERRY_UNREACHABLE ();
}
if (current_opcode->op_idx == NAME_TO_ID (is_false_jmp))
{
/* 19: is_false_jmp 2
20: var_decl ...
becomes
19: var_decl ...
20: is_false_jmp 2
*/
if (current_opcode->data.is_false_jmp.opcode >= opcode_to_counter (last_opcode)
|| current_opcode->data.is_false_jmp.opcode < opcode_to_counter (first_opcode) - value)
continue;
/* 19: is_false_jmp 20
20: assignment
21: var_decl
becomes
19: var_decl
20: is_false_jmp 21
21: assignment
*/
if (current_opcode->data.is_false_jmp.opcode >= opcode_to_counter (first_opcode)
&& current_opcode->data.is_false_jmp.opcode <= opcode_to_counter (last_opcode) - value)
{
current_opcode->data.is_false_jmp.opcode = (T_IDX) (current_opcode->data.is_false_jmp.opcode + value);
continue;
}
/* 19: is_false_jmp 22
20: assignment
21: var_decl
22: var_decl
becomes
19: var_decl
20: var_decl
21: is_false_jmp 23
22: assignment
*/
if (current_opcode->data.is_false_jmp.opcode < opcode_to_counter (last_opcode))
{
current_opcode->data.is_false_jmp.opcode = (T_IDX) opcode_to_counter (last_opcode);
continue;
}
JERRY_UNREACHABLE ();
}
if (current_opcode->op_idx == NAME_TO_ID (jmp_down))
{
/* 19: jmp_down 1
20: assignment
21: var_decl ...
becomes
19: var_decl ...
20: jmp_down 1
21: assignment
*/
if (current_opcode->data.jmp_down.opcode_count < last_opcode - current_opcode)
continue;
/* 19: jmp_down 3
20: assignment
21: var_decl
becomes
19: var_decl
20: jmp_down 2
21: assignment
*/
if (current_opcode->data.jmp_down.opcode_count >= last_opcode - current_opcode + value)
{
current_opcode->data.jmp_down.opcode_count = (T_IDX) (current_opcode->data.jmp_down.opcode_count - value);
continue;
}
/* 19: jmp_down 3
20: assignment
21: var_decl
22: var_decl
becomes
19: var_decl
20: var_decl
21: jmp_down 2
22: assignment
*/
if (current_opcode->data.jmp_down.opcode_count >= last_opcode - current_opcode
&& current_opcode->data.jmp_down.opcode_count < last_opcode - current_opcode + value)
{
current_opcode->data.jmp_down.opcode_count = (T_IDX) (last_opcode - current_opcode);
continue;
}
JERRY_UNREACHABLE ();
}
if (current_opcode->op_idx == NAME_TO_ID (jmp_up))
{
/* 19: assignment
20: jmp_up 1
21: var_decl ...
becomes
19: var_decl ...
20: assignment
21: jmp_up 1
*/
if (current_opcode->data.jmp_up.opcode_count < current_opcode - first_opcode)
continue;
/* 19: jmp_up 1
20: assignment
21: var_decl
becomes
19: var_decl
20: jmp_up 2
21: assignment
*/
if (current_opcode->data.jmp_up.opcode_count >= current_opcode - first_opcode)
{
current_opcode->data.jmp_up.opcode_count = (T_IDX) (current_opcode->data.jmp_up.opcode_count + value);
continue;
}
JERRY_UNREACHABLE ();
}
JERRY_UNREACHABLE ();
}
if (current_opcode->op_idx == NAME_TO_ID (is_false_jmp))
{
/* 19: is_false_jmp 2
20: var_decl ...
becomes
19: var_decl ...
20: is_false_jmp 2
*/
if (current_opcode->data.is_false_jmp.opcode >= opcode_to_counter (last_opcode)
|| current_opcode->data.is_false_jmp.opcode < opcode_to_counter (first_opcode) - value)
{
continue;
}
/* 19: is_false_jmp 20
20: assignment
21: var_decl
becomes
19: var_decl
20: is_false_jmp 21
21: assignment
*/
if (current_opcode->data.is_false_jmp.opcode >= opcode_to_counter (first_opcode)
&& current_opcode->data.is_false_jmp.opcode <= opcode_to_counter (last_opcode) - value)
{
current_opcode->data.is_false_jmp.opcode = (T_IDX) (current_opcode->data.is_false_jmp.opcode + value);
continue;
}
/* 19: is_false_jmp 22
20: assignment
21: var_decl
22: var_decl
becomes
19: var_decl
20: var_decl
21: is_false_jmp 23
22: assignment
*/
if (current_opcode->data.is_false_jmp.opcode < opcode_to_counter (last_opcode))
{
current_opcode->data.is_false_jmp.opcode = (T_IDX) opcode_to_counter (last_opcode);
continue;
}
JERRY_UNREACHABLE ();
}
if (current_opcode->op_idx == NAME_TO_ID (jmp_down))
{
/* 19: jmp_down 1
20: assignment
21: var_decl ...
becomes
19: var_decl ...
20: jmp_down 1
21: assignment
*/
if (current_opcode->data.jmp_down.opcode_count < last_opcode - current_opcode)
{
continue;
}
/* 19: jmp_down 3
20: assignment
21: var_decl
becomes
19: var_decl
20: jmp_down 2
21: assignment
*/
if (current_opcode->data.jmp_down.opcode_count >= last_opcode - current_opcode + value)
{
current_opcode->data.jmp_down.opcode_count = (T_IDX) (current_opcode->data.jmp_down.opcode_count - value);
continue;
}
/* 19: jmp_down 3
20: assignment
21: var_decl
22: var_decl
becomes
19: var_decl
20: var_decl
21: jmp_down 2
22: assignment
*/
if (current_opcode->data.jmp_down.opcode_count >= last_opcode - current_opcode
&& current_opcode->data.jmp_down.opcode_count < last_opcode - current_opcode + value)
{
current_opcode->data.jmp_down.opcode_count = (T_IDX) (last_opcode - current_opcode);
continue;
}
JERRY_UNREACHABLE ();
}
if (current_opcode->op_idx == NAME_TO_ID (jmp_up))
{
/* 19: assignment
20: jmp_up 1
21: var_decl ...
becomes
19: var_decl ...
20: assignment
21: jmp_up 1
*/
if (current_opcode->data.jmp_up.opcode_count < current_opcode - first_opcode)
{
continue;
}
/* 19: jmp_up 1
20: assignment
21: var_decl
becomes
19: var_decl
20: jmp_up 2
21: assignment
*/
if (current_opcode->data.jmp_up.opcode_count >= current_opcode - first_opcode)
{
current_opcode->data.jmp_up.opcode_count = (T_IDX) (current_opcode->data.jmp_up.opcode_count + value);
continue;
}
JERRY_UNREACHABLE ();
}
}
}
/* Reorder scope like
@@ -314,7 +328,7 @@ optimizer_adjust_jumps (OPCODE *first_opcode, OPCODE *last_opcode, int16_t value
func_decl
var_decl
other opcodes
*/
*/
void
optimizer_reorder_scope (uint16_t scope_start, uint16_t scope_end)
{
@@ -325,92 +339,94 @@ optimizer_reorder_scope (uint16_t scope_start, uint16_t scope_end)
OPCODE *var_decls_start;
for (current_opcode = processed_opcode; current_opcode != last_opcode; current_opcode++)
{
if (current_opcode->op_idx == NAME_TO_ID (assignment)
&& current_opcode->data.assignment.type_value_right == OPCODE_ARG_TYPE_STRING
&& !__strcmp ("use strict", (char *) deserialize_string_by_id (current_opcode->data.assignment.value_right)))
{
if (current_opcode->op_idx == NAME_TO_ID (assignment)
&& current_opcode->data.assignment.type_value_right == OPCODE_ARG_TYPE_STRING
&& !__strcmp ("use strict", (char *) deserialize_string_by_id (current_opcode->data.assignment.value_right)))
{
optimizer_move_opcodes (current_opcode, processed_opcode, 1);
optimizer_adjust_jumps (processed_opcode + 1, current_opcode + 1, 1);
processed_opcode++;
break;
}
optimizer_move_opcodes (current_opcode, processed_opcode, 1);
optimizer_adjust_jumps (processed_opcode + 1, current_opcode + 1, 1);
processed_opcode++;
break;
}
}
for (current_opcode = processed_opcode; current_opcode != last_opcode;)
{
if (current_opcode->op_idx == NAME_TO_ID (func_decl_0)
|| current_opcode->op_idx == NAME_TO_ID (func_decl_1)
|| current_opcode->op_idx == NAME_TO_ID (func_decl_2)
|| current_opcode->op_idx == NAME_TO_ID (func_decl_n))
{
if (current_opcode->op_idx == NAME_TO_ID (func_decl_0)
|| current_opcode->op_idx == NAME_TO_ID (func_decl_1)
|| current_opcode->op_idx == NAME_TO_ID (func_decl_2)
|| current_opcode->op_idx == NAME_TO_ID (func_decl_n))
__printf ("%p\n", processed_opcode);
OPCODE *fun_opcode;
int16_t value, jmp_offset = 0;
for (fun_opcode = current_opcode + 1; fun_opcode != last_opcode; fun_opcode++)
{
if (fun_opcode->op_idx == NAME_TO_ID (jmp_down))
{
__printf ("%p\n", processed_opcode);
OPCODE *fun_opcode;
int16_t value, jmp_offset = 0;
for (fun_opcode = current_opcode + 1; fun_opcode != last_opcode; fun_opcode++)
{
if (fun_opcode->op_idx == NAME_TO_ID (jmp_down))
{
jmp_offset = (int16_t) (fun_opcode - current_opcode);
fun_opcode += fun_opcode->data.jmp_down.opcode_count;
break;
}
}
JERRY_ASSERT (fun_opcode <= last_opcode);
value = (int16_t) (fun_opcode - current_opcode);
optimizer_move_opcodes (current_opcode, processed_opcode, (uint16_t) value);
// Adjust jumps inside func_decl except end's jmp_down
optimizer_adjust_jumps (processed_opcode + jmp_offset + 1,
processed_opcode + value,
(int16_t) (processed_opcode - current_opcode));
optimizer_adjust_jumps (processed_opcode + value,
fun_opcode,
value);
processed_opcode += value;
current_opcode = fun_opcode;
continue;
jmp_offset = (int16_t) (fun_opcode - current_opcode);
fun_opcode += fun_opcode->data.jmp_down.opcode_count;
break;
}
else
current_opcode++;
}
JERRY_ASSERT (fun_opcode <= last_opcode);
value = (int16_t) (fun_opcode - current_opcode);
optimizer_move_opcodes (current_opcode, processed_opcode, (uint16_t) value);
// Adjust jumps inside func_decl except end's jmp_down
optimizer_adjust_jumps (processed_opcode + jmp_offset + 1,
processed_opcode + value,
(int16_t) (processed_opcode - current_opcode));
optimizer_adjust_jumps (processed_opcode + value,
fun_opcode,
value);
processed_opcode += value;
current_opcode = fun_opcode;
continue;
}
else
{
current_opcode++;
}
}
var_decls_start = processed_opcode;
for (current_opcode = processed_opcode; current_opcode != last_opcode; current_opcode++)
{
if (current_opcode->op_idx == NAME_TO_ID (var_decl))
{
if (current_opcode->op_idx == NAME_TO_ID (var_decl))
// If variable already declared, replace it with nop
bool was_decl = false;
if (var_decls_start->op_idx == NAME_TO_ID (var_decl) && var_decls_start != current_opcode)
{
OPCODE *var_decls_iterator;
for (var_decls_iterator = var_decls_start;
var_decls_iterator != processed_opcode;
var_decls_iterator++)
{
// If variable already declared, replace it with nop
bool was_decl = false;
if (var_decls_start->op_idx == NAME_TO_ID (var_decl) && var_decls_start != current_opcode)
{
OPCODE *var_decls_iterator;
for (var_decls_iterator = var_decls_start;
var_decls_iterator != processed_opcode;
var_decls_iterator++)
{
JERRY_ASSERT (var_decls_iterator->op_idx == NAME_TO_ID (var_decl));
if (var_decls_iterator->data.var_decl.variable_name
== current_opcode->data.var_decl.variable_name)
{
was_decl = true;
break;
}
}
}
if (was_decl)
{
current_opcode->op_idx = NAME_TO_ID (nop);
}
else
{
optimizer_move_opcodes (current_opcode, processed_opcode, 1);
optimizer_adjust_jumps (processed_opcode + 1, current_opcode + 1, 1);
processed_opcode++;
}
JERRY_ASSERT (var_decls_iterator->op_idx == NAME_TO_ID (var_decl));
if (var_decls_iterator->data.var_decl.variable_name
== current_opcode->data.var_decl.variable_name)
{
was_decl = true;
break;
}
}
}
if (was_decl)
{
current_opcode->op_idx = NAME_TO_ID (nop);
}
else
{
optimizer_move_opcodes (current_opcode, processed_opcode, 1);
optimizer_adjust_jumps (processed_opcode + 1, current_opcode + 1, 1);
processed_opcode++;
}
}
}
}
void
+19 -11
View File
@@ -27,12 +27,14 @@
#define OPCODE_SIZE(op) \
sizeof (struct __op_##op) + 1,
static char* opcode_names[] = {
static char* opcode_names[] =
{
OP_LIST (OPCODE_STR)
""
};
static uint8_t opcode_sizes[] = {
static uint8_t opcode_sizes[] =
{
OP_LIST (OPCODE_SIZE)
0
};
@@ -45,10 +47,10 @@ pp_strings (const char *strings[], uint8_t size)
__printf ("STRINGS %d:\n", size);
for (i = 0; i < size; i++)
{
__printf ("%3d %5d %20s\n", i, offset, strings[i]);
offset = (uint16_t) (offset + __strlen (strings[i]) + 1);
}
{
__printf ("%3d %5d %20s\n", i, offset, strings[i]);
offset = (uint16_t) (offset + __strlen (strings[i]) + 1);
}
}
void
@@ -58,9 +60,9 @@ pp_nums (const ecma_number_t nums[], uint8_t size, uint8_t strings_num)
__printf ("NUMS %d:\n", size);
for (i = 0; i < size; i++)
{
__printf ("%3d %7d\n", i + strings_num, (int) nums[i]);
}
{
__printf ("%3d %7d\n", i + strings_num, (int) nums[i]);
}
__printf ("\n");
}
@@ -355,13 +357,17 @@ pp_opcode (opcode_counter_t oc, OPCODE opcode, bool is_rewrite)
__printf ("%03d: %20s ", oc, opcode_names[opcode_num]);
if (opcode_num != NAME_TO_ID (nop) && opcode_num != NAME_TO_ID (ret)
&& opcode_num != NAME_TO_ID (end_with))
{
for (i = 1; i < opcode_sizes[opcode_num]; i++)
{
for (i = 1; i < opcode_sizes[opcode_num]; i++)
__printf ("%4d ", ((uint8_t*)&opcode)[i]);
__printf ("%4d ", ((uint8_t*) & opcode)[i]);
}
}
for (; i < 4; i++)
{
__printf (" ");
}
__printf (" // ");
@@ -447,7 +453,9 @@ pp_opcode (opcode_counter_t oc, OPCODE opcode, bool is_rewrite)
}
if (is_rewrite)
{
__printf (" // REWRITE");
}
__printf ("\n");
}
+40 -30
View File
@@ -37,12 +37,14 @@ serializer_dump_strings (const char *strings[], uint8_t size)
uint16_t offset = (uint16_t) (size * 2 + 1), res;
if (print_opcodes)
{
pp_strings (strings, size);
}
for (i = 0; i < size; i++)
{
offset = (uint16_t) (offset + __strlen (strings[i]) + 1);
}
{
offset = (uint16_t) (offset + __strlen (strings[i]) + 1);
}
bytecode_data = mem_heap_alloc_block (offset, MEM_HEAP_ALLOC_SHORT_TERM);
res = offset;
@@ -50,22 +52,22 @@ serializer_dump_strings (const char *strings[], uint8_t size)
bytecode_data[0] = size;
offset = (uint16_t) (size * 2 + 1);
for (i = 0; i < size; i++)
{
*((uint16_t *) (bytecode_data + i * 2 + 1)) = offset;
offset = (uint16_t) (offset + __strlen (strings[i]) + 1);
}
{
*((uint16_t *) (bytecode_data + i * 2 + 1)) = offset;
offset = (uint16_t) (offset + __strlen (strings[i]) + 1);
}
for (i = 0; i < size; i++)
{
offset = *((uint16_t *) (bytecode_data + i * 2 + 1));
__strncpy ((char *) (bytecode_data + offset), strings[i], __strlen (strings[i]) + 1);
}
{
offset = *((uint16_t *) (bytecode_data + i * 2 + 1));
__strncpy ((char *) (bytecode_data + offset), strings[i], __strlen (strings[i]) + 1);
}
#ifndef JERRY_NDEBUG
for (i = 0; i < size; i++)
{
JERRY_ASSERT (!__strcmp (strings[i], (const char *) deserialize_string_by_id (i)));
}
{
JERRY_ASSERT (!__strcmp (strings[i], (const char *) deserialize_string_by_id (i)));
}
#endif
return res;
@@ -77,11 +79,15 @@ serializer_dump_nums (const ecma_number_t nums[], uint8_t size, uint16_t offset,
uint8_t i, *data, type_size = sizeof (ecma_number_t);
if (print_opcodes)
{
pp_nums (nums, size, strings_num);
}
data = mem_heap_alloc_block ((size_t) (offset + size * type_size + 1), MEM_HEAP_ALLOC_LONG_TERM);
if (!data)
{
parser_fatal (ERR_MEMORY);
}
__memcpy (data, bytecode_data, offset);
mem_heap_free_block (bytecode_data);
@@ -90,16 +96,16 @@ serializer_dump_nums (const ecma_number_t nums[], uint8_t size, uint16_t offset,
data[0] = size;
data++;
for (i = 0; i < size; i++)
{
__memcpy (data, nums + i, type_size);
data += type_size;
}
{
__memcpy (data, nums + i, type_size);
data += type_size;
}
#ifndef JERRY_NDEBUG
for (i = 0; i < size; i++)
{
JERRY_ASSERT (nums[i] == deserialize_num_by_id ((uint8_t) (i + strings_num)));
}
{
JERRY_ASSERT (nums[i] == deserialize_num_by_id ((uint8_t) (i + strings_num)));
}
JERRY_ASSERT (deserialize_min_temp () == (uint8_t) (size + strings_num));
#endif
@@ -111,22 +117,24 @@ void
serializer_dump_opcode (OPCODE opcode)
{
if (print_opcodes)
{
pp_opcode (opcode_counter, opcode, false);
}
JERRY_ASSERT( opcode_counter < MAX_OPCODES );
JERRY_ASSERT (opcode_counter < MAX_OPCODES);
bytecode_opcodes[opcode_counter++] = opcode;
}
void
serializer_rewrite_opcode (const opcode_counter_t loc, OPCODE opcode)
{
JERRY_ASSERT( loc < MAX_OPCODES );
JERRY_ASSERT (loc < MAX_OPCODES);
bytecode_opcodes[loc] = opcode;
if (print_opcodes)
{
pp_opcode (loc, opcode, true);
}
{
pp_opcode (loc, opcode, true);
}
}
void
@@ -135,19 +143,21 @@ serializer_print_opcodes (void)
opcode_counter_t loc;
if (!print_opcodes)
{
return;
}
__printf ("AFTER OPTIMIZER:\n");
for (loc = 0; (*(uint32_t *) (bytecode_opcodes + loc) != 0x0); loc++)
{
pp_opcode (loc, bytecode_opcodes[loc], false);
}
{
pp_opcode (loc, bytecode_opcodes[loc], false);
}
}
void
serializer_free (void)
{
mem_heap_free_block( bytecode_data);
mem_heap_free_block (bytecode_data);
bytecode_data = NULL;
}
+1 -1
View File
@@ -32,6 +32,6 @@ void serializer_rewrite_opcode (const opcode_counter_t, OPCODE);
void serializer_print_opcodes (void);
void serializer_free(void);
void serializer_free (void);
#endif // SERIALIZER_H