mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
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:
parent
cbdc48a1fc
commit
a00079e8ff
File diff suppressed because it is too large
Load Diff
@ -33,6 +33,8 @@ public:
|
|||||||
EMPTY, /**< empty operand */
|
EMPTY, /**< empty operand */
|
||||||
LITERAL, /**< operand contains literal value */
|
LITERAL, /**< operand contains literal value */
|
||||||
TMP, /**< operand contains byte-code register index */
|
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
|
UNINITIALIZED /**< uninitialized operand
|
||||||
*
|
*
|
||||||
* Note:
|
* Note:
|
||||||
@ -65,6 +67,37 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
} /* make_empty_operand */
|
} /* 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
|
* Construct literal operand
|
||||||
*
|
*
|
||||||
@ -124,6 +157,32 @@ public:
|
|||||||
return (_type == jsp_operand_t::EMPTY);
|
return (_type == jsp_operand_t::EMPTY);
|
||||||
} /* is_empty_operand */
|
} /* 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?
|
* Is it byte-code register operand?
|
||||||
*
|
*
|
||||||
@ -204,9 +263,22 @@ public:
|
|||||||
}
|
}
|
||||||
} /* get_literal */
|
} /* 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:
|
private:
|
||||||
union
|
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) */
|
vm_idx_t uid; /**< byte-code register index (for jsp_operand_t::TMP) */
|
||||||
lit_cpointer_t lit_id; /**< literal (for jsp_operand_t::LITERAL) */
|
lit_cpointer_t lit_id; /**< literal (for jsp_operand_t::LITERAL) */
|
||||||
} _data;
|
} _data;
|
||||||
|
|||||||
@ -24,10 +24,17 @@
|
|||||||
#include "lit-id-hash-table.h"
|
#include "lit-id-hash-table.h"
|
||||||
#include "lit-literal.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
|
typedef struct
|
||||||
{
|
{
|
||||||
lit_cpointer_t lit_id[3];
|
lit_cpointer_t lit_id[3]; /**< literals, corresponding to arguments
|
||||||
vm_instr_t op;
|
* (NOT_A_LITERAL - if not literal is associated
|
||||||
|
* with corresponding argument) */
|
||||||
|
vm_instr_t op; /**< byte-code instruction */
|
||||||
} op_meta;
|
} op_meta;
|
||||||
|
|
||||||
typedef struct tree_header
|
typedef struct tree_header
|
||||||
|
|||||||
@ -1805,43 +1805,3 @@ vm_read_instr_counter_from_meta (opcode_meta_type expected_type, /**< expected t
|
|||||||
|
|
||||||
return vm_calc_instr_counter_from_idx_idx (data_1, data_2);
|
return vm_calc_instr_counter_from_idx_idx (data_1, data_2);
|
||||||
} /* vm_read_instr_counter_from_meta */
|
} /* vm_read_instr_counter_from_meta */
|
||||||
|
|
||||||
#define VM_OP_0(opcode_name, opcode_name_uppercase) \
|
|
||||||
vm_instr_t getop_##opcode_name (void) \
|
|
||||||
{ \
|
|
||||||
vm_instr_t instr; \
|
|
||||||
memset (&instr, 0, sizeof(instr)); \
|
|
||||||
instr.op_idx = VM_OP_##opcode_name_uppercase; \
|
|
||||||
return instr; \
|
|
||||||
}
|
|
||||||
#define VM_OP_1(opcode_name, opcode_name_uppercase, arg1, arg1_type) \
|
|
||||||
vm_instr_t getop_##opcode_name (vm_idx_t arg1_v) \
|
|
||||||
{ \
|
|
||||||
vm_instr_t instr; \
|
|
||||||
memset (&instr, 0, sizeof(instr)); \
|
|
||||||
instr.op_idx = VM_OP_##opcode_name_uppercase; \
|
|
||||||
instr.data.opcode_name.arg1 = arg1_v; \
|
|
||||||
return instr; \
|
|
||||||
}
|
|
||||||
#define VM_OP_2(opcode_name, opcode_name_uppercase, arg1, arg1_type, arg2, arg2_type) \
|
|
||||||
vm_instr_t getop_##opcode_name (vm_idx_t arg1_v, vm_idx_t arg2_v) \
|
|
||||||
{ \
|
|
||||||
vm_instr_t instr; \
|
|
||||||
memset (&instr, 0, sizeof(instr)); \
|
|
||||||
instr.op_idx = VM_OP_##opcode_name_uppercase; \
|
|
||||||
instr.data.opcode_name.arg1 = arg1_v; \
|
|
||||||
instr.data.opcode_name.arg2 = arg2_v; \
|
|
||||||
return instr; \
|
|
||||||
}
|
|
||||||
#define VM_OP_3(opcode_name, opcode_name_uppercase, arg1, arg1_type, arg2, arg2_type, arg3, arg3_type) \
|
|
||||||
vm_instr_t getop_##opcode_name (vm_idx_t arg1_v, vm_idx_t arg2_v, vm_idx_t arg3_v) \
|
|
||||||
{ \
|
|
||||||
vm_instr_t instr; \
|
|
||||||
instr.op_idx = VM_OP_##opcode_name_uppercase; \
|
|
||||||
instr.data.opcode_name.arg1 = arg1_v; \
|
|
||||||
instr.data.opcode_name.arg2 = arg2_v; \
|
|
||||||
instr.data.opcode_name.arg3 = arg3_v; \
|
|
||||||
return instr; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "vm-opcodes.inc.h"
|
|
||||||
|
|||||||
@ -297,15 +297,4 @@ typedef enum
|
|||||||
|
|
||||||
typedef ecma_completion_value_t (*opfunc) (vm_instr_t, vm_frame_ctx_t *);
|
typedef ecma_completion_value_t (*opfunc) (vm_instr_t, vm_frame_ctx_t *);
|
||||||
|
|
||||||
#define VM_OP_0(opcode_name, opcode_name_uppercase) \
|
|
||||||
vm_instr_t getop_##opcode_name (void);
|
|
||||||
#define VM_OP_1(opcode_name, opcode_name_uppercase, arg1, arg1_type) \
|
|
||||||
vm_instr_t getop_##opcode_name (vm_idx_t);
|
|
||||||
#define VM_OP_2(opcode_name, opcode_name_uppercase, arg1, arg1_type, arg2, arg2_type) \
|
|
||||||
vm_instr_t getop_##opcode_name (vm_idx_t, vm_idx_t);
|
|
||||||
#define VM_OP_3(opcode_name, opcode_name_uppercase, arg1, arg1_type, arg2, arg2_type, arg3, arg3_type) \
|
|
||||||
vm_instr_t getop_##opcode_name (vm_idx_t, vm_idx_t, vm_idx_t);
|
|
||||||
|
|
||||||
#include "vm-opcodes.inc.h"
|
|
||||||
|
|
||||||
#endif /* OPCODES_H */
|
#endif /* OPCODES_H */
|
||||||
|
|||||||
@ -49,6 +49,49 @@ instrs_equal (const vm_instr_t *instrs1, vm_instr_t *instrs2, uint16_t size)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define VM_OP_0(opcode_name, opcode_name_uppercase) \
|
||||||
|
static vm_instr_t __attr_unused___ getop_##opcode_name (void) \
|
||||||
|
{ \
|
||||||
|
vm_instr_t instr; \
|
||||||
|
instr.op_idx = VM_OP_##opcode_name_uppercase; \
|
||||||
|
instr.data.raw_args[0] = VM_IDX_EMPTY; \
|
||||||
|
instr.data.raw_args[1] = VM_IDX_EMPTY; \
|
||||||
|
instr.data.raw_args[2] = VM_IDX_EMPTY; \
|
||||||
|
return instr; \
|
||||||
|
}
|
||||||
|
#define VM_OP_1(opcode_name, opcode_name_uppercase, arg_1, arg1_type) \
|
||||||
|
static vm_instr_t __attr_unused___ getop_##opcode_name (vm_idx_t arg1_v) \
|
||||||
|
{ \
|
||||||
|
vm_instr_t instr; \
|
||||||
|
instr.op_idx = VM_OP_##opcode_name_uppercase; \
|
||||||
|
instr.data.raw_args[0] = arg1_v; \
|
||||||
|
instr.data.raw_args[1] = VM_IDX_EMPTY; \
|
||||||
|
instr.data.raw_args[2] = VM_IDX_EMPTY; \
|
||||||
|
return instr; \
|
||||||
|
}
|
||||||
|
#define VM_OP_2(opcode_name, opcode_name_uppercase, arg_1, arg1_type, arg_2, arg2_type) \
|
||||||
|
static vm_instr_t __attr_unused___ getop_##opcode_name (vm_idx_t arg1_v, vm_idx_t arg2_v) \
|
||||||
|
{ \
|
||||||
|
vm_instr_t instr; \
|
||||||
|
instr.op_idx = VM_OP_##opcode_name_uppercase; \
|
||||||
|
instr.data.raw_args[0] = arg1_v; \
|
||||||
|
instr.data.raw_args[1] = arg2_v; \
|
||||||
|
instr.data.raw_args[2] = VM_IDX_EMPTY; \
|
||||||
|
return instr; \
|
||||||
|
}
|
||||||
|
#define VM_OP_3(opcode_name, opcode_name_uppercase, arg_1, arg1_type, arg_2, arg2_type, arg3_name, arg3_type) \
|
||||||
|
static vm_instr_t __attr_unused___ getop_##opcode_name (vm_idx_t arg1_v, vm_idx_t arg2_v, vm_idx_t arg3_v) \
|
||||||
|
{ \
|
||||||
|
vm_instr_t instr; \
|
||||||
|
instr.op_idx = VM_OP_##opcode_name_uppercase; \
|
||||||
|
instr.data.raw_args[0] = arg1_v; \
|
||||||
|
instr.data.raw_args[1] = arg2_v; \
|
||||||
|
instr.data.raw_args[2] = arg3_v; \
|
||||||
|
return instr; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "vm-opcodes.inc.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test's main function.
|
* Unit test's main function.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user