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;
|
||||||
|
|
||||||
@@ -62,14 +66,18 @@ deserialize_num_by_id (uint8_t id)
|
|||||||
data = bytecode_data + str_offset;
|
data = bytecode_data + str_offset;
|
||||||
|
|
||||||
while (*data)
|
while (*data)
|
||||||
|
{
|
||||||
data++;
|
data++;
|
||||||
|
}
|
||||||
|
|
||||||
num_size = *(++data);
|
num_size = *(++data);
|
||||||
num_data = (ecma_number_t *) ++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];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
assignment ... +
|
assignment ... +
|
||||||
call_n ...
|
call_n ...
|
||||||
var_?_end
|
var_?_end
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
optimize_calls (OPCODE *opcodes)
|
optimize_calls (OPCODE *opcodes)
|
||||||
{
|
{
|
||||||
@@ -60,10 +60,14 @@ 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)
|
||||||
{
|
{
|
||||||
@@ -97,7 +101,9 @@ optimizer_move_opcodes (OPCODE *from, OPCODE *to, uint16_t number)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -128,7 +134,9 @@ optimizer_adjust_jumps (OPCODE *first_opcode, OPCODE *last_opcode, int16_t value
|
|||||||
*/
|
*/
|
||||||
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
|
||||||
@@ -180,7 +188,9 @@ optimizer_adjust_jumps (OPCODE *first_opcode, OPCODE *last_opcode, int16_t value
|
|||||||
*/
|
*/
|
||||||
if (current_opcode->data.is_false_jmp.opcode >= opcode_to_counter (last_opcode)
|
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)
|
|| current_opcode->data.is_false_jmp.opcode < opcode_to_counter (first_opcode) - value)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* 19: is_false_jmp 20
|
/* 19: is_false_jmp 20
|
||||||
20: assignment
|
20: assignment
|
||||||
@@ -233,7 +243,9 @@ optimizer_adjust_jumps (OPCODE *first_opcode, OPCODE *last_opcode, int16_t value
|
|||||||
21: assignment
|
21: assignment
|
||||||
*/
|
*/
|
||||||
if (current_opcode->data.jmp_down.opcode_count < last_opcode - current_opcode)
|
if (current_opcode->data.jmp_down.opcode_count < last_opcode - current_opcode)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* 19: jmp_down 3
|
/* 19: jmp_down 3
|
||||||
20: assignment
|
20: assignment
|
||||||
@@ -286,7 +298,9 @@ optimizer_adjust_jumps (OPCODE *first_opcode, OPCODE *last_opcode, int16_t value
|
|||||||
21: jmp_up 1
|
21: jmp_up 1
|
||||||
*/
|
*/
|
||||||
if (current_opcode->data.jmp_up.opcode_count < current_opcode - first_opcode)
|
if (current_opcode->data.jmp_up.opcode_count < current_opcode - first_opcode)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* 19: jmp_up 1
|
/* 19: jmp_up 1
|
||||||
20: assignment
|
20: assignment
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -372,8 +386,10 @@ optimizer_reorder_scope (uint16_t scope_start, uint16_t scope_end)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
current_opcode++;
|
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++)
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
@@ -357,11 +359,15 @@ pp_opcode (opcode_counter_t oc, OPCODE opcode, bool is_rewrite)
|
|||||||
&& 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,7 +37,9 @@ 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++)
|
||||||
{
|
{
|
||||||
@@ -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);
|
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);
|
||||||
@@ -111,16 +117,18 @@ 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)
|
||||||
@@ -135,7 +143,9 @@ 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");
|
||||||
|
|
||||||
@@ -148,6 +158,6 @@ serializer_print_opcodes (void)
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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