Fix style in liboptimizer
This commit is contained in:
@@ -26,12 +26,16 @@ deserialize_string_by_id (uint8_t id)
|
|||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
|
|
||||||
if (bytecode_data == NULL)
|
if (bytecode_data == NULL)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
size = *bytecode_data;
|
size = *bytecode_data;
|
||||||
|
|
||||||
if (id >= size)
|
if (id >= size)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
data = bytecode_data;
|
data = bytecode_data;
|
||||||
|
|
||||||
@@ -42,34 +46,38 @@ deserialize_string_by_id (uint8_t id)
|
|||||||
return ((const ecma_char_t *) bytecode_data + offset);
|
return ((const ecma_char_t *) bytecode_data + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_number_t
|
ecma_number_t
|
||||||
deserialize_num_by_id (uint8_t id)
|
deserialize_num_by_id (uint8_t id)
|
||||||
{
|
{
|
||||||
uint16_t str_size, str_offset;
|
uint16_t str_size, str_offset;
|
||||||
|
|
||||||
str_size = *bytecode_data;
|
str_size = *bytecode_data;
|
||||||
if (id < str_size)
|
if (id < str_size)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
id = (uint8_t) (id - str_size);
|
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)
|
if (num_data == NULL)
|
||||||
data++;
|
{
|
||||||
|
// Go to last string's offset
|
||||||
num_size = *(++data);
|
uint8_t *data = (uint8_t *) (bytecode_data + str_size * 2 - 1);
|
||||||
num_data = (ecma_number_t *) ++data;
|
str_offset = *((uint16_t *) data);
|
||||||
|
data = bytecode_data + str_offset;
|
||||||
|
|
||||||
|
while (*data)
|
||||||
|
{
|
||||||
|
data++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
num_size = *(++data);
|
||||||
|
num_data = (ecma_number_t *) ++data;
|
||||||
|
}
|
||||||
|
|
||||||
if (id >= num_size)
|
if (id >= num_size)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return num_data[id];
|
return num_data[id];
|
||||||
}
|
}
|
||||||
@@ -80,15 +88,15 @@ deserialize_bytecode (void)
|
|||||||
return bytecode_opcodes;
|
return bytecode_opcodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t
|
uint8_t
|
||||||
deserialize_min_temp (void)
|
deserialize_min_temp (void)
|
||||||
{
|
{
|
||||||
uint8_t str_size = *bytecode_data;
|
uint8_t str_size = *bytecode_data;
|
||||||
|
|
||||||
if (num_size == 0)
|
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);
|
return (uint8_t) (str_size + num_size);
|
||||||
}
|
}
|
||||||
|
|||||||
+306
-290
@@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
#define NAME_TO_ID(op) (__op__idx_##op)
|
#define NAME_TO_ID(op) (__op__idx_##op)
|
||||||
|
|
||||||
/* Reorder bytecode like
|
/* Reorder bytecode like
|
||||||
|
|
||||||
call_n ...
|
call_n ...
|
||||||
assignment ... +
|
assignment ... +
|
||||||
var_?_end
|
var_?_end
|
||||||
@@ -32,24 +32,24 @@
|
|||||||
assignment ... +
|
assignment ... +
|
||||||
call_n ...
|
call_n ...
|
||||||
var_?_end
|
var_?_end
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
optimize_calls (OPCODE *opcodes)
|
optimize_calls (OPCODE *opcodes)
|
||||||
{
|
{
|
||||||
OPCODE *current_opcode;
|
OPCODE *current_opcode;
|
||||||
|
|
||||||
for (current_opcode = opcodes;
|
for (current_opcode = opcodes;
|
||||||
current_opcode->op_idx != NAME_TO_ID (exitval);
|
current_opcode->op_idx != NAME_TO_ID (exitval);
|
||||||
current_opcode++)
|
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)
|
OPCODE temp = *current_opcode;
|
||||||
&& (current_opcode + 1)->op_idx == NAME_TO_ID (assignment))
|
*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. */
|
/* 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;
|
uint16_t i;
|
||||||
|
|
||||||
if (to == from)
|
if (to == from)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < number; i++)
|
for (i = 0; i < number; i++)
|
||||||
|
{
|
||||||
temp[i] = from[i];
|
temp[i] = from[i];
|
||||||
|
}
|
||||||
|
|
||||||
if (to > from)
|
if (to > from)
|
||||||
|
{
|
||||||
|
if (number <= to - from)
|
||||||
{
|
{
|
||||||
if (number <= to - from)
|
// Adjust opcodes up
|
||||||
{
|
for (current_opcode = from; current_opcode != to; current_opcode++)
|
||||||
// Adjust opcodes up
|
{
|
||||||
for (current_opcode = from; current_opcode != to; current_opcode++)
|
*current_opcode = *(current_opcode + number);
|
||||||
{
|
}
|
||||||
*current_opcode = *(current_opcode + number);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
optimizer_move_opcodes (from + number, from, (uint16_t) (to - from));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
optimizer_move_opcodes (from + number, from, (uint16_t) (to - from));
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (number <= from - to)
|
||||||
{
|
{
|
||||||
if (number <= from - to)
|
// Adjust opcodes down
|
||||||
{
|
for (current_opcode = from; current_opcode != to; current_opcode--)
|
||||||
// Adjust opcodes down
|
{
|
||||||
for (current_opcode = from; current_opcode != to; current_opcode--)
|
*current_opcode = *(current_opcode - number);
|
||||||
{
|
}
|
||||||
*current_opcode = *(current_opcode - number);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
optimizer_move_opcodes (to, to + number, (uint16_t) (from - to));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
optimizer_move_opcodes (to, to + number, (uint16_t) (from - to));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < number; i++)
|
for (i = 0; i < number; i++)
|
||||||
|
{
|
||||||
to[i] = temp[i];
|
to[i] = temp[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t
|
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);
|
JERRY_ASSERT (first_opcode <= last_opcode);
|
||||||
|
|
||||||
for (current_opcode = first_opcode; current_opcode != last_opcode; current_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 ...
|
19: var_decl ...
|
||||||
20: is_true_jmp 2
|
20: is_true_jmp 2
|
||||||
*/
|
*/
|
||||||
if (current_opcode->data.is_true_jmp.opcode >= opcode_to_counter (last_opcode)
|
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)
|
|| current_opcode->data.is_true_jmp.opcode < opcode_to_counter (first_opcode) - value)
|
||||||
continue;
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* 19: is_true_jmp 20
|
/* 19: is_true_jmp 20
|
||||||
20: assignment
|
20: assignment
|
||||||
21: var_decl
|
21: var_decl
|
||||||
|
|
||||||
becomes
|
becomes
|
||||||
|
|
||||||
19: var_decl
|
19: var_decl
|
||||||
20: is_true_jmp 21
|
20: is_true_jmp 21
|
||||||
21: assignment
|
21: assignment
|
||||||
*/
|
*/
|
||||||
if (current_opcode->data.is_true_jmp.opcode >= opcode_to_counter (first_opcode)
|
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 <= opcode_to_counter (last_opcode) - value)
|
||||||
{
|
{
|
||||||
current_opcode->data.is_true_jmp.opcode = (T_IDX) (current_opcode->data.is_true_jmp.opcode + value);
|
current_opcode->data.is_true_jmp.opcode = (T_IDX) (current_opcode->data.is_true_jmp.opcode + value);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 19: is_true_jmp 22
|
/* 19: is_true_jmp 22
|
||||||
20: assignment
|
20: assignment
|
||||||
21: var_decl
|
21: var_decl
|
||||||
22: var_decl
|
22: var_decl
|
||||||
|
|
||||||
becomes
|
becomes
|
||||||
|
|
||||||
19: var_decl
|
19: var_decl
|
||||||
20: var_decl
|
20: var_decl
|
||||||
21: is_true_jmp 23
|
21: is_true_jmp 23
|
||||||
22: assignment
|
22: assignment
|
||||||
*/
|
*/
|
||||||
if (current_opcode->data.is_true_jmp.opcode < opcode_to_counter (last_opcode))
|
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);
|
current_opcode->data.is_true_jmp.opcode = (T_IDX) opcode_to_counter (last_opcode);
|
||||||
continue;
|
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 ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
/* Reorder scope like
|
||||||
@@ -314,7 +328,7 @@ optimizer_adjust_jumps (OPCODE *first_opcode, OPCODE *last_opcode, int16_t value
|
|||||||
func_decl
|
func_decl
|
||||||
var_decl
|
var_decl
|
||||||
other opcodes
|
other opcodes
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
optimizer_reorder_scope (uint16_t scope_start, uint16_t scope_end)
|
optimizer_reorder_scope (uint16_t scope_start, uint16_t scope_end)
|
||||||
{
|
{
|
||||||
@@ -325,96 +339,98 @@ optimizer_reorder_scope (uint16_t scope_start, uint16_t scope_end)
|
|||||||
OPCODE *var_decls_start;
|
OPCODE *var_decls_start;
|
||||||
|
|
||||||
for (current_opcode = processed_opcode; current_opcode != last_opcode; current_opcode++)
|
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)
|
optimizer_move_opcodes (current_opcode, processed_opcode, 1);
|
||||||
&& current_opcode->data.assignment.type_value_right == OPCODE_ARG_TYPE_STRING
|
optimizer_adjust_jumps (processed_opcode + 1, current_opcode + 1, 1);
|
||||||
&& !__strcmp ("use strict", (char *) deserialize_string_by_id (current_opcode->data.assignment.value_right)))
|
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;)
|
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)
|
__printf ("%p\n", processed_opcode);
|
||||||
|| current_opcode->op_idx == NAME_TO_ID (func_decl_1)
|
OPCODE *fun_opcode;
|
||||||
|| current_opcode->op_idx == NAME_TO_ID (func_decl_2)
|
int16_t value, jmp_offset = 0;
|
||||||
|| current_opcode->op_idx == NAME_TO_ID (func_decl_n))
|
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);
|
jmp_offset = (int16_t) (fun_opcode - current_opcode);
|
||||||
OPCODE *fun_opcode;
|
fun_opcode += fun_opcode->data.jmp_down.opcode_count;
|
||||||
int16_t value, jmp_offset = 0;
|
break;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
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;
|
var_decls_start = processed_opcode;
|
||||||
for (current_opcode = processed_opcode; current_opcode != last_opcode; current_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
|
JERRY_ASSERT (var_decls_iterator->op_idx == NAME_TO_ID (var_decl));
|
||||||
bool was_decl = false;
|
if (var_decls_iterator->data.var_decl.variable_name
|
||||||
if (var_decls_start->op_idx == NAME_TO_ID (var_decl) && var_decls_start != current_opcode)
|
== current_opcode->data.var_decl.variable_name)
|
||||||
{
|
{
|
||||||
OPCODE *var_decls_iterator;
|
was_decl = true;
|
||||||
for (var_decls_iterator = var_decls_start;
|
break;
|
||||||
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++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
void
|
||||||
optimizer_run_passes (OPCODE* opcodes)
|
optimizer_run_passes (OPCODE* opcodes)
|
||||||
{
|
{
|
||||||
optimize_calls (opcodes);
|
optimize_calls (opcodes);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,12 +27,14 @@
|
|||||||
#define OPCODE_SIZE(op) \
|
#define OPCODE_SIZE(op) \
|
||||||
sizeof (struct __op_##op) + 1,
|
sizeof (struct __op_##op) + 1,
|
||||||
|
|
||||||
static char* opcode_names[] = {
|
static char* opcode_names[] =
|
||||||
|
{
|
||||||
OP_LIST (OPCODE_STR)
|
OP_LIST (OPCODE_STR)
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint8_t opcode_sizes[] = {
|
static uint8_t opcode_sizes[] =
|
||||||
|
{
|
||||||
OP_LIST (OPCODE_SIZE)
|
OP_LIST (OPCODE_SIZE)
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
@@ -45,22 +47,22 @@ pp_strings (const char *strings[], uint8_t size)
|
|||||||
|
|
||||||
__printf ("STRINGS %d:\n", size);
|
__printf ("STRINGS %d:\n", size);
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
__printf ("%3d %5d %20s\n", i, offset, strings[i]);
|
__printf ("%3d %5d %20s\n", i, offset, strings[i]);
|
||||||
offset = (uint16_t) (offset + __strlen (strings[i]) + 1);
|
offset = (uint16_t) (offset + __strlen (strings[i]) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pp_nums (const ecma_number_t nums[], uint8_t size, uint8_t strings_num)
|
pp_nums (const ecma_number_t nums[], uint8_t size, uint8_t strings_num)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
__printf ("NUMS %d:\n", size);
|
__printf ("NUMS %d:\n", size);
|
||||||
for (i = 0; i < size; i++)
|
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");
|
__printf ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +169,7 @@ dump_variable (T_IDX id)
|
|||||||
__printf (" " equals " " new " "); \
|
__printf (" " equals " " new " "); \
|
||||||
dump_variable (opcode.data.op.name); \
|
dump_variable (opcode.data.op.name); \
|
||||||
__printf (start end ";"); \
|
__printf (start end ";"); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_1_NAME_LHS(op, lhs, equals, new, name, start, arg, end) \
|
#define CASE_VARG_1_NAME_LHS(op, lhs, equals, new, name, start, arg, end) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -177,7 +179,7 @@ dump_variable (T_IDX id)
|
|||||||
__printf (start); \
|
__printf (start); \
|
||||||
dump_variable (opcode.data.op.arg); \
|
dump_variable (opcode.data.op.arg); \
|
||||||
__printf (end ";"); \
|
__printf (end ";"); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_N_NAME_LHS(op, lhs, equals, new, name, start, arg, end) \
|
#define CASE_VARG_N_NAME_LHS(op, lhs, equals, new, name, start, arg, end) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -188,14 +190,14 @@ dump_variable (T_IDX id)
|
|||||||
dump_variable (opcode.data.op.arg); \
|
dump_variable (opcode.data.op.arg); \
|
||||||
__printf (" ..."); \
|
__printf (" ..."); \
|
||||||
varg_end = end; \
|
varg_end = end; \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_0_NAME(op, new, name, start, end) \
|
#define CASE_VARG_0_NAME(op, new, name, start, end) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
__printf (new " "); \
|
__printf (new " "); \
|
||||||
dump_variable (opcode.data.op.name); \
|
dump_variable (opcode.data.op.name); \
|
||||||
__printf (start end ";"); \
|
__printf (start end ";"); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_1_NAME(op, new, name, start, arg1, end) \
|
#define CASE_VARG_1_NAME(op, new, name, start, arg1, end) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -204,7 +206,7 @@ dump_variable (T_IDX id)
|
|||||||
__printf (start); \
|
__printf (start); \
|
||||||
dump_variable (opcode.data.op.arg1); \
|
dump_variable (opcode.data.op.arg1); \
|
||||||
__printf (end ";"); \
|
__printf (end ";"); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_2_NAME(op, new, name, start, arg1, arg2, end) \
|
#define CASE_VARG_2_NAME(op, new, name, start, arg1, arg2, end) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -215,7 +217,7 @@ dump_variable (T_IDX id)
|
|||||||
__printf (", "); \
|
__printf (", "); \
|
||||||
dump_variable (opcode.data.op.arg2); \
|
dump_variable (opcode.data.op.arg2); \
|
||||||
__printf (end ";"); \
|
__printf (end ";"); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_N_NAME(op, new, name, start, arg1, arg2, end) \
|
#define CASE_VARG_N_NAME(op, new, name, start, arg1, arg2, end) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -227,14 +229,14 @@ dump_variable (T_IDX id)
|
|||||||
dump_variable (opcode.data.op.arg2); \
|
dump_variable (opcode.data.op.arg2); \
|
||||||
__printf (" ..."); \
|
__printf (" ..."); \
|
||||||
varg_end = end; \
|
varg_end = end; \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_0_LHS(op, lhs, equals, start, end) \
|
#define CASE_VARG_0_LHS(op, lhs, equals, start, end) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
dump_variable (opcode.data.op.lhs); \
|
dump_variable (opcode.data.op.lhs); \
|
||||||
__printf (" " equals " " start); \
|
__printf (" " equals " " start); \
|
||||||
__printf (end ";"); \
|
__printf (end ";"); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_1_LHS(op, lhs, equals, start, arg1, end) \
|
#define CASE_VARG_1_LHS(op, lhs, equals, start, arg1, end) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -242,7 +244,7 @@ dump_variable (T_IDX id)
|
|||||||
__printf (" " equals " " start); \
|
__printf (" " equals " " start); \
|
||||||
dump_variable (opcode.data.op.arg1); \
|
dump_variable (opcode.data.op.arg1); \
|
||||||
__printf (end ";"); \
|
__printf (end ";"); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_2_LHS(op, lhs, equals, start, arg1, arg2, end) \
|
#define CASE_VARG_2_LHS(op, lhs, equals, start, arg1, arg2, end) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -252,7 +254,7 @@ dump_variable (T_IDX id)
|
|||||||
__printf (", "); \
|
__printf (", "); \
|
||||||
dump_variable (opcode.data.op.arg2); \
|
dump_variable (opcode.data.op.arg2); \
|
||||||
__printf (end ";"); \
|
__printf (end ";"); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_N_LHS(op, lhs, equals, start, arg1, arg2, end) \
|
#define CASE_VARG_N_LHS(op, lhs, equals, start, arg1, arg2, end) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -263,14 +265,14 @@ dump_variable (T_IDX id)
|
|||||||
dump_variable (opcode.data.op.arg2); \
|
dump_variable (opcode.data.op.arg2); \
|
||||||
__printf (" ..."); \
|
__printf (" ..."); \
|
||||||
varg_end = end; \
|
varg_end = end; \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_1_END(op, arg1) \
|
#define CASE_VARG_1_END(op, arg1) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
__printf ("... "); \
|
__printf ("... "); \
|
||||||
dump_variable (opcode.data.op.arg1); \
|
dump_variable (opcode.data.op.arg1); \
|
||||||
__printf ("%s;", varg_end); \
|
__printf ("%s;", varg_end); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_2_END(op, arg1, arg2) \
|
#define CASE_VARG_2_END(op, arg1, arg2) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -279,7 +281,7 @@ dump_variable (T_IDX id)
|
|||||||
__printf (", "); \
|
__printf (", "); \
|
||||||
dump_variable (opcode.data.op.arg2); \
|
dump_variable (opcode.data.op.arg2); \
|
||||||
__printf ("%s;", varg_end); \
|
__printf ("%s;", varg_end); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_3_END(op, arg1, arg2, arg3) \
|
#define CASE_VARG_3_END(op, arg1, arg2, arg3) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -290,7 +292,7 @@ dump_variable (T_IDX id)
|
|||||||
__printf (", "); \
|
__printf (", "); \
|
||||||
dump_variable (opcode.data.op.arg3); \
|
dump_variable (opcode.data.op.arg3); \
|
||||||
__printf ("%s;", varg_end); \
|
__printf ("%s;", varg_end); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_VARG_3(op, arg1, arg2, arg3) \
|
#define CASE_VARG_3(op, arg1, arg2, arg3) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -301,20 +303,20 @@ dump_variable (T_IDX id)
|
|||||||
__printf (", "); \
|
__printf (", "); \
|
||||||
dump_variable (opcode.data.op.arg3); \
|
dump_variable (opcode.data.op.arg3); \
|
||||||
__printf (" ..."); \
|
__printf (" ..."); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_EXIT(op, name, field) \
|
#define CASE_EXIT(op, name, field) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
__printf (name " "); \
|
__printf (name " "); \
|
||||||
__printf ("%d;", opcode.data.op.field); \
|
__printf ("%d;", opcode.data.op.field); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_SINGLE_ADDRESS(op, name, field) \
|
#define CASE_SINGLE_ADDRESS(op, name, field) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
__printf (name " "); \
|
__printf (name " "); \
|
||||||
dump_variable (opcode.data.op.field); \
|
dump_variable (opcode.data.op.field); \
|
||||||
__printf (";"); \
|
__printf (";"); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#define CASE_ZERO_ADDRESS(op, name) \
|
#define CASE_ZERO_ADDRESS(op, name) \
|
||||||
case NAME_TO_ID (op): \
|
case NAME_TO_ID (op): \
|
||||||
@@ -353,15 +355,19 @@ pp_opcode (opcode_counter_t oc, OPCODE opcode, bool is_rewrite)
|
|||||||
uint8_t opcode_num = opcode.op_idx;
|
uint8_t opcode_num = opcode.op_idx;
|
||||||
|
|
||||||
__printf ("%03d: %20s ", oc, opcode_names[opcode_num]);
|
__printf ("%03d: %20s ", oc, opcode_names[opcode_num]);
|
||||||
if (opcode_num != NAME_TO_ID (nop) && opcode_num != NAME_TO_ID (ret)
|
if (opcode_num != NAME_TO_ID (nop) && opcode_num != NAME_TO_ID (ret)
|
||||||
&& opcode_num != NAME_TO_ID (end_with))
|
&& 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++)
|
for (; i < 4; i++)
|
||||||
|
{
|
||||||
__printf (" ");
|
__printf (" ");
|
||||||
|
}
|
||||||
|
|
||||||
__printf (" // ");
|
__printf (" // ");
|
||||||
|
|
||||||
@@ -447,7 +453,9 @@ pp_opcode (opcode_counter_t oc, OPCODE opcode, bool is_rewrite)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_rewrite)
|
if (is_rewrite)
|
||||||
|
{
|
||||||
__printf (" // REWRITE");
|
__printf (" // REWRITE");
|
||||||
|
}
|
||||||
|
|
||||||
__printf ("\n");
|
__printf ("\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,12 +37,14 @@ serializer_dump_strings (const char *strings[], uint8_t size)
|
|||||||
uint16_t offset = (uint16_t) (size * 2 + 1), res;
|
uint16_t offset = (uint16_t) (size * 2 + 1), res;
|
||||||
|
|
||||||
if (print_opcodes)
|
if (print_opcodes)
|
||||||
|
{
|
||||||
pp_strings (strings, size);
|
pp_strings (strings, size);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < size; i++)
|
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);
|
bytecode_data = mem_heap_alloc_block (offset, MEM_HEAP_ALLOC_SHORT_TERM);
|
||||||
res = offset;
|
res = offset;
|
||||||
@@ -50,38 +52,42 @@ serializer_dump_strings (const char *strings[], uint8_t size)
|
|||||||
bytecode_data[0] = size;
|
bytecode_data[0] = size;
|
||||||
offset = (uint16_t) (size * 2 + 1);
|
offset = (uint16_t) (size * 2 + 1);
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
*((uint16_t *) (bytecode_data + i * 2 + 1)) = offset;
|
*((uint16_t *) (bytecode_data + i * 2 + 1)) = offset;
|
||||||
offset = (uint16_t) (offset + __strlen (strings[i]) + 1);
|
offset = (uint16_t) (offset + __strlen (strings[i]) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
offset = *((uint16_t *) (bytecode_data + i * 2 + 1));
|
offset = *((uint16_t *) (bytecode_data + i * 2 + 1));
|
||||||
__strncpy ((char *) (bytecode_data + offset), strings[i], __strlen (strings[i]) + 1);
|
__strncpy ((char *) (bytecode_data + offset), strings[i], __strlen (strings[i]) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef JERRY_NDEBUG
|
#ifndef JERRY_NDEBUG
|
||||||
for (i = 0; i < size; i++)
|
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
|
#endif
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
serializer_dump_nums (const ecma_number_t nums[], uint8_t size, uint16_t offset, uint8_t strings_num)
|
serializer_dump_nums (const ecma_number_t nums[], uint8_t size, uint16_t offset, uint8_t strings_num)
|
||||||
{
|
{
|
||||||
uint8_t i, *data, type_size = sizeof (ecma_number_t);
|
uint8_t i, *data, type_size = sizeof (ecma_number_t);
|
||||||
|
|
||||||
if (print_opcodes)
|
if (print_opcodes)
|
||||||
|
{
|
||||||
pp_nums (nums, size, strings_num);
|
pp_nums (nums, size, strings_num);
|
||||||
|
}
|
||||||
|
|
||||||
data = mem_heap_alloc_block ((size_t) (offset + size * type_size + 1), MEM_HEAP_ALLOC_LONG_TERM);
|
data = mem_heap_alloc_block ((size_t) (offset + size * type_size + 1), MEM_HEAP_ALLOC_LONG_TERM);
|
||||||
if (!data)
|
if (!data)
|
||||||
|
{
|
||||||
parser_fatal (ERR_MEMORY);
|
parser_fatal (ERR_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
__memcpy (data, bytecode_data, offset);
|
__memcpy (data, bytecode_data, offset);
|
||||||
mem_heap_free_block (bytecode_data);
|
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[0] = size;
|
||||||
data++;
|
data++;
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
__memcpy (data, nums + i, type_size);
|
__memcpy (data, nums + i, type_size);
|
||||||
data += type_size;
|
data += type_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef JERRY_NDEBUG
|
#ifndef JERRY_NDEBUG
|
||||||
for (i = 0; i < size; i++)
|
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));
|
JERRY_ASSERT (deserialize_min_temp () == (uint8_t) (size + strings_num));
|
||||||
#endif
|
#endif
|
||||||
@@ -111,22 +117,24 @@ void
|
|||||||
serializer_dump_opcode (OPCODE opcode)
|
serializer_dump_opcode (OPCODE opcode)
|
||||||
{
|
{
|
||||||
if (print_opcodes)
|
if (print_opcodes)
|
||||||
|
{
|
||||||
pp_opcode (opcode_counter, opcode, false);
|
pp_opcode (opcode_counter, opcode, false);
|
||||||
|
}
|
||||||
|
|
||||||
JERRY_ASSERT( opcode_counter < MAX_OPCODES );
|
JERRY_ASSERT (opcode_counter < MAX_OPCODES);
|
||||||
bytecode_opcodes[opcode_counter++] = opcode;
|
bytecode_opcodes[opcode_counter++] = opcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
serializer_rewrite_opcode (const opcode_counter_t loc, OPCODE opcode)
|
serializer_rewrite_opcode (const opcode_counter_t loc, OPCODE opcode)
|
||||||
{
|
{
|
||||||
JERRY_ASSERT( loc < MAX_OPCODES );
|
JERRY_ASSERT (loc < MAX_OPCODES);
|
||||||
bytecode_opcodes[loc] = opcode;
|
bytecode_opcodes[loc] = opcode;
|
||||||
|
|
||||||
if (print_opcodes)
|
if (print_opcodes)
|
||||||
{
|
{
|
||||||
pp_opcode (loc, opcode, true);
|
pp_opcode (loc, opcode, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -135,19 +143,21 @@ serializer_print_opcodes (void)
|
|||||||
opcode_counter_t loc;
|
opcode_counter_t loc;
|
||||||
|
|
||||||
if (!print_opcodes)
|
if (!print_opcodes)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
__printf ("AFTER OPTIMIZER:\n");
|
__printf ("AFTER OPTIMIZER:\n");
|
||||||
|
|
||||||
for (loc = 0; (*(uint32_t *) (bytecode_opcodes + loc) != 0x0); loc++)
|
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
|
void
|
||||||
serializer_free (void)
|
serializer_free (void)
|
||||||
{
|
{
|
||||||
mem_heap_free_block( bytecode_data);
|
mem_heap_free_block (bytecode_data);
|
||||||
bytecode_data = NULL;
|
bytecode_data = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SERIALIZER_H
|
#ifndef SERIALIZER_H
|
||||||
#define SERIALIZER_H
|
#define SERIALIZER_H
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
@@ -32,6 +32,6 @@ void serializer_rewrite_opcode (const opcode_counter_t, OPCODE);
|
|||||||
|
|
||||||
void serializer_print_opcodes (void);
|
void serializer_print_opcodes (void);
|
||||||
|
|
||||||
void serializer_free(void);
|
void serializer_free (void);
|
||||||
|
|
||||||
#endif // SERIALIZER_H
|
#endif // SERIALIZER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user