Skip to content

Commit cbdc48a

Browse files
Remove raw_instr.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
1 parent 173becc commit cbdc48a

File tree

4 files changed

+29
-33
lines changed

4 files changed

+29
-33
lines changed

jerry-core/parser/js/opcodes-dumper.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,8 @@ dumper_try_replace_var_with_reg (scopes_tree tree, /**< a function scope, create
311311
{
312312
om.lit_id[arg_index] = NOT_A_LITERAL;
313313

314-
raw_instr *raw_p = (raw_instr *) (&om.op);
315-
JERRY_ASSERT (raw_p->uids[arg_index + 1] == VM_IDX_REWRITE_LITERAL_UID);
316-
raw_p->uids[arg_index + 1] = reg;
314+
JERRY_ASSERT (om.op.data.raw_args[arg_index] == VM_IDX_REWRITE_LITERAL_UID);
315+
om.op.data.raw_args[arg_index] = reg;
317316
}
318317
}
319318

jerry-core/parser/js/scopes-tree.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,17 @@ assert_tree (scopes_tree t)
3030
}
3131

3232
static vm_idx_t
33-
get_uid (op_meta *op, uint8_t i)
33+
get_uid (op_meta *op, size_t i)
3434
{
35-
JERRY_ASSERT (i < 4);
36-
raw_instr *raw = (raw_instr *) &op->op;
37-
return raw->uids[i + 1];
35+
JERRY_ASSERT (i < 3);
36+
return op->op.data.raw_args[i];
3837
}
3938

4039
static void
41-
set_uid (op_meta *op, uint8_t i, vm_idx_t uid)
40+
set_uid (op_meta *op, size_t i, vm_idx_t uid)
4241
{
43-
JERRY_ASSERT (i < 4);
44-
raw_instr *raw = (raw_instr *) &op->op;
45-
raw->uids[i + 1] = uid;
42+
JERRY_ASSERT (i < 3);
43+
op->op.data.raw_args[i] = uid;
4644
}
4745

4846
vm_instr_counter_t

jerry-core/vm/opcodes.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ typedef struct vm_instr_t
257257
} opcode_name;
258258

259259
#include "vm-opcodes.inc.h"
260+
261+
/**
262+
* Opcode-independent arguments accessor
263+
*
264+
* Note:
265+
* If opcode is statically known, opcode-specific way of accessing arguments should be used.
266+
*/
267+
vm_idx_t raw_args[3];
260268
} data;
261269
} vm_instr_t;
262270

@@ -300,10 +308,4 @@ typedef ecma_completion_value_t (*opfunc) (vm_instr_t, vm_frame_ctx_t *);
300308

301309
#include "vm-opcodes.inc.h"
302310

303-
304-
typedef struct
305-
{
306-
uint8_t uids[4];
307-
} raw_instr;
308-
309311
#endif /* OPCODES_H */

jerry-core/vm/pretty-printer.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,22 @@ tmp_id_to_str (vm_idx_t id)
9595
static const char *
9696
var_to_str (vm_instr_t instr, lit_cpointer_t lit_ids[], vm_instr_counter_t oc, uint8_t current_arg)
9797
{
98-
raw_instr raw = *(raw_instr*) &instr;
99-
if (raw.uids[current_arg] == VM_IDX_REWRITE_LITERAL_UID)
98+
JERRY_ASSERT (current_arg >= 1 && current_arg <= 3);
99+
100+
if (instr.data.raw_args[current_arg - 1] == VM_IDX_REWRITE_LITERAL_UID)
100101
{
101-
if (lit_ids == NULL)
102-
{
103-
return "hz";
104-
}
102+
JERRY_ASSERT (lit_ids != NULL);
105103
JERRY_ASSERT (lit_ids[current_arg - 1].packed_value != MEM_CP_NULL);
104+
106105
return lit_cp_to_str (lit_ids[current_arg - 1]);
107106
}
108-
else if (raw.uids[current_arg] >= 128)
107+
else if (instr.data.raw_args[current_arg - 1] >= 128)
109108
{
110-
return tmp_id_to_str (raw.uids[current_arg]);
109+
return tmp_id_to_str (instr.data.raw_args[current_arg - 1]);
111110
}
112111
else
113112
{
114-
return lit_cp_to_str (serializer_get_literal_cp_by_uid (raw.uids[current_arg], NULL, oc));
113+
return lit_cp_to_str (serializer_get_literal_cp_by_uid (instr.data.raw_args[current_arg - 1], NULL, oc));
115114
}
116115
}
117116

@@ -134,14 +133,12 @@ pp_printf (const char *format, vm_instr_t instr, lit_cpointer_t lit_ids[], vm_in
134133
{
135134
case 'd':
136135
{
137-
JERRY_ASSERT (current_arg <= 3);
138-
raw_instr raw = *(raw_instr*) &instr;
139-
printf ("%d", raw.uids[current_arg]);
136+
JERRY_ASSERT (current_arg >= 1 && current_arg <= 3);
137+
printf ("%d", instr.data.raw_args[current_arg - 1]);
140138
break;
141139
}
142140
case 's':
143141
{
144-
JERRY_ASSERT (current_arg <= 3);
145142
printf ("%s", var_to_str (instr, lit_ids, oc, current_arg));
146143
break;
147144
}
@@ -159,8 +156,8 @@ pp_printf (const char *format, vm_instr_t instr, lit_cpointer_t lit_ids[], vm_in
159156
#define PP_OP(op_name, format) \
160157
case op_name: pp_printf (format, opm.op, opm.lit_id, oc, 1); break;
161158
#define VAR(i) var_to_str (opm.op, opm.lit_id, oc, i)
162-
#define OC(i, j) __extension__({ raw_instr* raw = (raw_instr *) &opm.op; \
163-
vm_calc_instr_counter_from_idx_idx (raw->uids[i], raw->uids[j]); })
159+
#define OC(i, j) __extension__({ vm_calc_instr_counter_from_idx_idx (opm.op.data.raw_args[i - 1], \
160+
opm.op.data.raw_args[j - 1]); })
164161

165162
static int vargs_num = 0;
166163
static int seen_vargs = 0;
@@ -174,7 +171,7 @@ dump_asm (vm_instr_counter_t oc, vm_instr_t instr)
174171

175172
for (i = 1; i <= opcode_sizes[opcode_id]; i++)
176173
{
177-
printf ("%4d ", ((raw_instr *) &instr)->uids[i]);
174+
printf ("%4d ", instr.data.raw_args[i - 1]);
178175
}
179176

180177
for (; i < 4; i++)

0 commit comments

Comments
 (0)