Introduce explicit description of registers (temporary variables) ranges.

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
Ruben Ayrapetyan
2015-06-23 19:01:33 +03:00
parent e027b4d65d
commit 9b414deb8d
2 changed files with 40 additions and 9 deletions
+28 -9
View File
@@ -20,7 +20,6 @@
#include "syntax-errors.h" #include "syntax-errors.h"
#include "opcodes-native-call.h" #include "opcodes-native-call.h"
#define MIN_TEMP_NAME 128
static idx_t temp_name, max_temp_name; static idx_t temp_name, max_temp_name;
#define OPCODE(name) (__op__idx_##name) #define OPCODE(name) (__op__idx_##name)
@@ -115,22 +114,42 @@ enum
}; };
STATIC_STACK (reg_var_decls, opcode_counter_t) STATIC_STACK (reg_var_decls, opcode_counter_t)
/**
* Reset counter of register variables allocator
* to identifier of first general register
*/
static void static void
reset_temp_name (void) reset_temp_name (void)
{ {
temp_name = MIN_TEMP_NAME; temp_name = OPCODE_REG_GENERAL_FIRST;
} } /* reset_temp_name */
/**
* Allocate next register variable
*
* @return identifier of the allocated variable
*/
static idx_t static idx_t
next_temp_name (void) next_temp_name (void)
{ {
temp_name++; idx_t next_reg = temp_name++;
if (max_temp_name < temp_name)
if (next_reg > OPCODE_REG_GENERAL_LAST)
{ {
max_temp_name = temp_name; /*
* FIXME:
* Implement mechanism, allowing reusage of register variables
*/
PARSE_ERROR ("Not enough register variables", 0);
} }
return temp_name;
} if (max_temp_name < next_reg)
{
max_temp_name = next_reg;
}
return next_reg;
} /* next_temp_name */
static op_meta static op_meta
create_op_meta (opcode_t op, lit_cpointer_t lit_id1, lit_cpointer_t lit_id2, lit_cpointer_t lit_id3) create_op_meta (opcode_t op, lit_cpointer_t lit_id1, lit_cpointer_t lit_id2, lit_cpointer_t lit_id3)
@@ -2500,7 +2519,7 @@ void
dump_reg_var_decl_for_rewrite (void) dump_reg_var_decl_for_rewrite (void)
{ {
STACK_PUSH (reg_var_decls, serializer_get_current_opcode_counter ()); STACK_PUSH (reg_var_decls, serializer_get_current_opcode_counter ());
serializer_dump_op_meta (create_op_meta_000 (getop_reg_var_decl (MIN_TEMP_NAME, INVALID_VALUE))); serializer_dump_op_meta (create_op_meta_000 (getop_reg_var_decl (OPCODE_REG_FIRST, INVALID_VALUE)));
} }
void void
+12
View File
@@ -102,6 +102,18 @@ typedef enum : idx_t
* 'eval' identifier */ * 'eval' identifier */
} opcode_scope_code_flags_t; } opcode_scope_code_flags_t;
/**
* Enumeration of registers (temp variables) ranges
*/
typedef enum : idx_t
{
OPCODE_REG_FIRST = 128, /** identifier of first special register */
OPCODE_REG_SPECIAL_EVAL_RET = OPCODE_REG_FIRST, /**< eval return value */
OPCODE_REG_GENERAL_FIRST, /** identifier of first non-special register */
OPCODE_REG_GENERAL_LAST = 253, /** identifier of last non-special register */
OPCODE_REG_LAST = OPCODE_REG_GENERAL_FIRST /**< identifier of last register */
} opcode_special_reg_t;
/** /**
* Forward declaration of opcode structure * Forward declaration of opcode structure
*/ */