Reduce number of operand type handling conditional blocks in byte-code dumper, by extracting them to several separate routines that can be used for most cases, remove getop_* routines from vm.

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
Ruben Ayrapetyan
2015-08-12 15:21:59 +03:00
parent cbdc48a1fc
commit a00079e8ff
6 changed files with 608 additions and 837 deletions
File diff suppressed because it is too large Load Diff
+72
View File
@@ -33,6 +33,8 @@ public:
EMPTY, /**< empty operand */
LITERAL, /**< operand contains literal value */
TMP, /**< operand contains byte-code register index */
IDX_CONST, /**< operand contains an integer constant that fits vm_idx_t */
UNKNOWN, /**< operand, representing unknown value that would be rewritten later */
UNINITIALIZED /**< uninitialized operand
*
* Note:
@@ -65,6 +67,37 @@ public:
return ret;
} /* make_empty_operand */
/**
* Construct unknown operand
*
* @return constructed operand
*/
static jsp_operand_t
make_unknown_operand (void)
{
jsp_operand_t ret;
ret._type = jsp_operand_t::UNKNOWN;
return ret;
} /* make_unknown_operand */
/**
* Construct idx-constant operand
*
* @return constructed operand
*/
static jsp_operand_t
make_idx_const_operand (vm_idx_t cnst) /**< integer in vm_idx_t range */
{
jsp_operand_t ret;
ret._type = jsp_operand_t::IDX_CONST;
ret._data.idx_const = cnst;
return ret;
} /* make_idx_const_operand */
/**
* Construct literal operand
*
@@ -124,6 +157,32 @@ public:
return (_type == jsp_operand_t::EMPTY);
} /* is_empty_operand */
/**
* Is it unknown operand?
*
* @return true / false
*/
bool
is_unknown_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::UNKNOWN);
} /* is_unknown_operand */
/**
* Is it idx-constant operand?
*
* @return true / false
*/
bool
is_idx_const_operand (void) const
{
JERRY_ASSERT (_type != jsp_operand_t::UNINITIALIZED);
return (_type == jsp_operand_t::IDX_CONST);
} /* is_idx_const_operand */
/**
* Is it byte-code register operand?
*
@@ -204,9 +263,22 @@ public:
}
} /* get_literal */
/**
* Get constant from idx-constant operand
*
* @return an integer
*/
vm_idx_t
get_idx_const (void) const
{
JERRY_ASSERT (is_idx_const_operand ());
return _data.idx_const;
} /* get_idx_const */
private:
union
{
vm_idx_t idx_const; /**< idx constant value (for jsp_operand_t::IDX_CONST) */
vm_idx_t uid; /**< byte-code register index (for jsp_operand_t::TMP) */
lit_cpointer_t lit_id; /**< literal (for jsp_operand_t::LITERAL) */
} _data;
+9 -2
View File
@@ -24,10 +24,17 @@
#include "lit-id-hash-table.h"
#include "lit-literal.h"
/**
* Intermediate instruction descriptor that additionally to byte-code instruction
* holds information about literals, associated with corresponding arguments
* of the instruction.
*/
typedef struct
{
lit_cpointer_t lit_id[3];
vm_instr_t op;
lit_cpointer_t lit_id[3]; /**< literals, corresponding to arguments
* (NOT_A_LITERAL - if not literal is associated
* with corresponding argument) */
vm_instr_t op; /**< byte-code instruction */
} op_meta;
typedef struct tree_header