Postparser landing patch: add tree of scopes

This commit is contained in:
Ilmir Usmanov
2014-10-12 17:53:02 +04:00
parent cb7e54fe22
commit 63662dfb35
12 changed files with 305 additions and 48 deletions
+4 -5
View File
@@ -20,6 +20,7 @@
#include "stack.h"
#include "jerry-libc.h"
#include "lp-string.h"
#include "scopes-tree.h"
/* bytecode_data contains identifiers, string and num literals.
Memory map if the following.
@@ -36,17 +37,15 @@ struct
{
uint8_t strs_count;
uint8_t nums_count;
opcode_counter_t opcodes_count;
const lp_string *strings;
const ecma_number_t *nums;
const opcode_t *opcodes;
}
__packed
bytecode_data;
enum
{
bytecode_opcodes_global_size
};
STACK (bytecode_opcodes, opcode_counter_t, opcode_t)
scopes_tree *current_scope;
#endif // BYTECODE_DATA_H
+4 -16
View File
@@ -16,8 +16,6 @@
#include "deserializer.h"
#include "bytecode-data.h"
static opcode_t *raw_bytecode;
const ecma_char_t *
deserialize_string_by_id (uint8_t id)
{
@@ -42,18 +40,14 @@ deserialize_num_by_id (uint8_t id)
const void *
deserialize_bytecode (void)
{
JERRY_ASSERT (STACK_SIZE (bytecode_opcodes) > 0);
JERRY_ASSERT (raw_bytecode == NULL);
STACK_CONVERT_TO_RAW_DATA (bytecode_opcodes, raw_bytecode);
return raw_bytecode;
JERRY_ASSERT (bytecode_data.opcodes != NULL);
return bytecode_data.opcodes;
}
opcode_t
deserialize_opcode (opcode_counter_t oc)
{
JERRY_ASSERT (STACK_SIZE (bytecode_opcodes) > 0);
JERRY_ASSERT (oc < STACK_SIZE (bytecode_opcodes));
return STACK_ELEMENT (bytecode_opcodes, oc);
return scopes_tree_opcode (current_scope, oc);
}
uint8_t
@@ -65,18 +59,12 @@ deserialize_min_temp (void)
void
deserializer_init (void)
{
raw_bytecode = NULL;
STACK_INIT (opcode_t, bytecode_opcodes);
}
void
deserializer_free (void)
{
STACK_FREE (bytecode_opcodes);
if (raw_bytecode)
{
mem_heap_free_block ((uint8_t *) raw_bytecode);
}
mem_heap_free_block ((uint8_t *) bytecode_data.strings);
mem_heap_free_block ((uint8_t *) bytecode_data.nums);
mem_heap_free_block ((uint8_t *) bytecode_data.opcodes);
}
+21 -9
View File
@@ -22,6 +22,19 @@
static bool print_opcodes;
void
serializer_set_scope (scopes_tree *new_scope)
{
current_scope = new_scope;
}
void
serializer_merge_scopes_into_bytecode (void)
{
bytecode_data.opcodes = scopes_tree_raw_data (current_scope, &bytecode_data.opcodes_count);
}
void
serializer_dump_strings_and_nums (const lp_string strings[], uint8_t strs_count,
const ecma_number_t nums[], uint8_t nums_count)
@@ -40,28 +53,26 @@ serializer_dump_strings_and_nums (const lp_string strings[], uint8_t strs_count,
void
serializer_dump_opcode (opcode_t opcode)
{
JERRY_ASSERT (STACK_SIZE (bytecode_opcodes) < MAX_OPCODES);
JERRY_ASSERT (scopes_tree_opcodes_num (current_scope) < MAX_OPCODES);
if (print_opcodes)
{
pp_opcode (STACK_SIZE (bytecode_opcodes), opcode, false);
pp_opcode (scopes_tree_opcodes_num (current_scope), opcode, false);
}
STACK_PUSH (bytecode_opcodes, opcode);
scopes_tree_add_opcode (current_scope, opcode);
}
void
serializer_set_writing_position (opcode_counter_t oc)
{
JERRY_ASSERT (oc < STACK_SIZE (bytecode_opcodes));
STACK_DROP (bytecode_opcodes, STACK_SIZE (bytecode_opcodes) - oc);
scopes_tree_set_opcodes_num (current_scope, oc);
}
void
serializer_rewrite_opcode (const opcode_counter_t loc, opcode_t opcode)
{
JERRY_ASSERT (loc < STACK_SIZE (bytecode_opcodes));
STACK_SET_ELEMENT (bytecode_opcodes, loc, opcode);
scopes_tree_set_opcode (current_scope, loc, opcode);
if (print_opcodes)
{
@@ -81,9 +92,9 @@ serializer_print_opcodes (void)
__printf ("AFTER OPTIMIZER:\n");
for (loc = 0; loc < STACK_SIZE (bytecode_opcodes); loc++)
for (loc = 0; loc < bytecode_data.opcodes_count; loc++)
{
pp_opcode (loc, STACK_ELEMENT (bytecode_opcodes, loc), false);
pp_opcode (loc, bytecode_data.opcodes[loc], false);
}
}
@@ -102,6 +113,7 @@ serializer_adjust_strings (void)
void
serializer_init (bool show_opcodes)
{
current_scope = NULL;
print_opcodes = show_opcodes;
}
+3
View File
@@ -20,10 +20,13 @@
#include "opcodes.h"
#include "interpreter.h"
#include "lp-string.h"
#include "scopes-tree.h"
void serializer_init (bool show_opcodes);
void serializer_dump_strings_and_nums (const lp_string *, uint8_t,
const ecma_number_t *, uint8_t);
void serializer_set_scope (scopes_tree *);
void serializer_merge_scopes_into_bytecode (void);
void serializer_dump_opcode (opcode_t);
void serializer_set_writing_position (opcode_counter_t);
void serializer_rewrite_opcode (const opcode_counter_t, opcode_t);