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
+8
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;
@@ -62,14 +66,18 @@ deserialize_num_by_id (uint8_t id)
data = bytecode_data + str_offset;
while (*data)
{
data++;
}
num_size = *(++data);
num_data = (ecma_number_t *) ++data;
}
if (id >= num_size)
{
return 0;
}
return num_data[id];
}
+18 -2
View File
@@ -32,7 +32,7 @@
assignment ... +
call_n ...
var_?_end
*/
*/
static void
optimize_calls (OPCODE *opcodes)
{
@@ -60,10 +60,14 @@ 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)
{
@@ -97,7 +101,9 @@ optimizer_move_opcodes (OPCODE *from, OPCODE *to, uint16_t number)
}
for (i = 0; i < number; i++)
{
to[i] = temp[i];
}
}
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)
|| current_opcode->data.is_true_jmp.opcode < opcode_to_counter (first_opcode) - value)
{
continue;
}
/* 19: is_true_jmp 20
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)
|| current_opcode->data.is_false_jmp.opcode < opcode_to_counter (first_opcode) - value)
{
continue;
}
/* 19: is_false_jmp 20
20: assignment
@@ -233,7 +243,9 @@ optimizer_adjust_jumps (OPCODE *first_opcode, OPCODE *last_opcode, int16_t value
21: assignment
*/
if (current_opcode->data.jmp_down.opcode_count < last_opcode - current_opcode)
{
continue;
}
/* 19: jmp_down 3
20: assignment
@@ -286,7 +298,9 @@ optimizer_adjust_jumps (OPCODE *first_opcode, OPCODE *last_opcode, int16_t value
21: jmp_up 1
*/
if (current_opcode->data.jmp_up.opcode_count < current_opcode - first_opcode)
{
continue;
}
/* 19: jmp_up 1
20: assignment
@@ -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)
{
@@ -372,8 +386,10 @@ optimizer_reorder_scope (uint16_t scope_start, uint16_t scope_end)
continue;
}
else
{
current_opcode++;
}
}
var_decls_start = processed_opcode;
for (current_opcode = processed_opcode; current_opcode != last_opcode; current_opcode++)
+11 -3
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
};
@@ -357,11 +359,15 @@ pp_opcode (opcode_counter_t oc, OPCODE opcode, bool is_rewrite)
&& opcode_num != NAME_TO_ID (end_with))
{
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");
}
+13 -3
View File
@@ -37,7 +37,9 @@ 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++)
{
@@ -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);
@@ -111,16 +117,18 @@ 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)
@@ -135,7 +143,9 @@ serializer_print_opcodes (void)
opcode_counter_t loc;
if (!print_opcodes)
{
return;
}
__printf ("AFTER OPTIMIZER:\n");
@@ -148,6 +158,6 @@ serializer_print_opcodes (void)
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