@@ -60,10 +60,19 @@ static vm_idx_t jsp_reg_max_for_args;
60
60
61
61
bool is_print_instrs = false ;
62
62
scopes_tree current_scope_p = NULL ;
63
+ /* *
64
+ * Flag, indicating if bytecode should be generated
65
+ */
66
+ bool is_generate_bytecode = false ;
63
67
64
68
void dumper_dump_op_meta (op_meta);
65
69
void dumper_rewrite_op_meta (vm_instr_counter_t , op_meta);
66
70
71
+ void dumper_set_generate_bytecode (bool generate_bytecode)
72
+ {
73
+ is_generate_bytecode = generate_bytecode;
74
+ } /* dumper_set_generate_bytecode */
75
+
67
76
/* *
68
77
* Allocate next register for intermediate value
69
78
*
@@ -112,33 +121,51 @@ dumper_get_current_instr_counter (void)
112
121
return scopes_tree_instrs_num (current_scope_p);
113
122
}
114
123
124
+ static op_meta
125
+ dumper_get_op_meta (vm_instr_counter_t pos)
126
+ {
127
+ op_meta opm;
128
+ if (is_generate_bytecode)
129
+ {
130
+ opm = scopes_tree_op_meta (current_scope_p, pos);
131
+ }
132
+
133
+ return opm;
134
+ }
135
+
115
136
void
116
137
dumper_dump_op_meta (op_meta op)
117
138
{
118
139
JERRY_ASSERT (scopes_tree_instrs_num (current_scope_p) < MAX_OPCODES);
119
140
120
- scopes_tree_add_op_meta (current_scope_p, op);
141
+ if (is_generate_bytecode)
142
+ {
143
+ scopes_tree_add_op_meta (current_scope_p, op);
121
144
122
145
#ifdef JERRY_ENABLE_PRETTY_PRINTER
123
- if (is_print_instrs)
124
- {
125
- pp_op_meta (NULL , (vm_instr_counter_t ) (scopes_tree_instrs_num (current_scope_p) - 1 ), op, false );
126
- }
146
+ if (is_print_instrs)
147
+ {
148
+ pp_op_meta (NULL , (vm_instr_counter_t ) (scopes_tree_instrs_num (current_scope_p) - 1 ), op, false );
149
+ }
127
150
#endif
151
+ }
128
152
} /* dumper_dump_op_meta */
129
153
130
154
void
131
155
dumper_rewrite_op_meta (const vm_instr_counter_t loc,
132
156
op_meta op)
133
157
{
134
- scopes_tree_set_op_meta (current_scope_p, loc, op);
158
+ if (is_generate_bytecode)
159
+ {
160
+ scopes_tree_set_op_meta (current_scope_p, loc, op);
135
161
136
162
#ifdef JERRY_ENABLE_PRETTY_PRINTER
137
- if (is_print_instrs)
138
- {
139
- pp_op_meta (NULL , loc, op, true );
140
- }
163
+ if (is_print_instrs)
164
+ {
165
+ pp_op_meta (NULL , loc, op, true );
166
+ }
141
167
#endif
168
+ }
142
169
} /* dumper_rewrite_op_meta */
143
170
144
171
#ifdef CONFIG_PARSER_ENABLE_PARSE_TIME_BYTE_CODE_OPTIMIZER
@@ -807,6 +834,87 @@ dump_varg_header_for_rewrite (varg_list_type vlt, jsp_operand_t obj)
807
834
return pos;
808
835
}
809
836
837
+ typedef enum
838
+ {
839
+ REWRITE_VARG_HEADER,
840
+ REWRITE_FUNCTION_END,
841
+ REWRITE_CONDITIONAL_CHECK,
842
+ REWRITE_JUMP_TO_END,
843
+ REWRITE_SIMPLE_OR_NESTED_JUMP,
844
+ REWRITE_CASE_CLAUSE,
845
+ REWRITE_DEFAULT_CLAUSE,
846
+ REWRITE_WITH,
847
+ REWRITE_FOR_IN,
848
+ REWRITE_TRY,
849
+ REWRITE_CATCH,
850
+ REWRITE_FINALLY,
851
+ REWRITE_SCOPE_CODE_FLAGS,
852
+ REWRITE_REG_VAR_DECL,
853
+ } rewrite_type_t ;
854
+
855
+ static void
856
+ dumper_assert_op_fields (rewrite_type_t rewrite_type,
857
+ op_meta meta)
858
+ {
859
+ if (!is_generate_bytecode)
860
+ {
861
+ return ;
862
+ }
863
+
864
+ if (rewrite_type == REWRITE_FUNCTION_END)
865
+ {
866
+ JERRY_ASSERT (meta.op .op_idx == VM_OP_META);
867
+ JERRY_ASSERT (meta.op .data .meta .type == OPCODE_META_TYPE_FUNCTION_END);
868
+ JERRY_ASSERT (meta.op .data .meta .data_1 == VM_IDX_REWRITE_GENERAL_CASE);
869
+ JERRY_ASSERT (meta.op .data .meta .data_2 == VM_IDX_REWRITE_GENERAL_CASE);
870
+ }
871
+ else if (rewrite_type == REWRITE_CONDITIONAL_CHECK)
872
+ {
873
+ JERRY_ASSERT (meta.op .op_idx == VM_OP_IS_FALSE_JMP_DOWN);
874
+ }
875
+ else if (rewrite_type == REWRITE_JUMP_TO_END)
876
+ {
877
+ JERRY_ASSERT (meta.op .op_idx == VM_OP_JMP_DOWN);
878
+ }
879
+ else if (rewrite_type == REWRITE_CASE_CLAUSE)
880
+ {
881
+ JERRY_ASSERT (meta.op .op_idx == VM_OP_IS_TRUE_JMP_DOWN);
882
+ }
883
+ else if (rewrite_type == REWRITE_DEFAULT_CLAUSE)
884
+ {
885
+ JERRY_ASSERT (meta.op .op_idx == VM_OP_JMP_DOWN);
886
+ }
887
+ else if (rewrite_type == REWRITE_TRY)
888
+ {
889
+ JERRY_ASSERT (meta.op .op_idx == VM_OP_TRY_BLOCK);
890
+ }
891
+ else if (rewrite_type == REWRITE_CATCH)
892
+ {
893
+ JERRY_ASSERT (meta.op .op_idx == VM_OP_META
894
+ && meta.op .data .meta .type == OPCODE_META_TYPE_CATCH);
895
+ }
896
+ else if (rewrite_type == REWRITE_FINALLY)
897
+ {
898
+ JERRY_ASSERT (meta.op .op_idx == VM_OP_META
899
+ && meta.op .data .meta .type == OPCODE_META_TYPE_FINALLY);
900
+ }
901
+ else if (rewrite_type == REWRITE_SCOPE_CODE_FLAGS)
902
+ {
903
+ JERRY_ASSERT (meta.op .op_idx == VM_OP_META);
904
+ JERRY_ASSERT (meta.op .data .meta .type == OPCODE_META_TYPE_SCOPE_CODE_FLAGS);
905
+ JERRY_ASSERT (meta.op .data .meta .data_1 == VM_IDX_REWRITE_GENERAL_CASE);
906
+ JERRY_ASSERT (meta.op .data .meta .data_2 == VM_IDX_EMPTY);
907
+ }
908
+ else if (rewrite_type == REWRITE_REG_VAR_DECL)
909
+ {
910
+ JERRY_ASSERT (meta.op .op_idx == VM_OP_REG_VAR_DECL);
911
+ }
912
+ else
913
+ {
914
+ JERRY_UNREACHABLE ();
915
+ }
916
+ } /* dumper_assert_op_fields */
917
+
810
918
void
811
919
rewrite_varg_header_set_args_count (jsp_operand_t ret,
812
920
size_t args_count,
@@ -820,7 +928,12 @@ rewrite_varg_header_set_args_count (jsp_operand_t ret,
820
928
* argument / formal parameter name to values collection.
821
929
*/
822
930
823
- op_meta om = scopes_tree_op_meta (current_scope_p, pos);
931
+ if (!is_generate_bytecode)
932
+ {
933
+ return ;
934
+ }
935
+
936
+ op_meta om = dumper_get_op_meta (pos);
824
937
825
938
switch (om.op .op_idx )
826
939
{
@@ -990,11 +1103,8 @@ rewrite_function_end (vm_instr_counter_t pos)
990
1103
vm_idx_t id1, id2;
991
1104
split_instr_counter (oc, &id1, &id2);
992
1105
993
- op_meta function_end_op_meta = scopes_tree_op_meta (current_scope_p, pos);
994
- JERRY_ASSERT (function_end_op_meta.op .op_idx == VM_OP_META);
995
- JERRY_ASSERT (function_end_op_meta.op .data .meta .type == OPCODE_META_TYPE_FUNCTION_END);
996
- JERRY_ASSERT (function_end_op_meta.op .data .meta .data_1 == VM_IDX_REWRITE_GENERAL_CASE);
997
- JERRY_ASSERT (function_end_op_meta.op .data .meta .data_2 == VM_IDX_REWRITE_GENERAL_CASE);
1106
+ op_meta function_end_op_meta = dumper_get_op_meta (pos);
1107
+ dumper_assert_op_fields (REWRITE_FUNCTION_END, function_end_op_meta);
998
1108
999
1109
function_end_op_meta.op .data .meta .data_1 = id1;
1000
1110
function_end_op_meta.op .data .meta .data_2 = id2;
@@ -1220,8 +1330,8 @@ rewrite_conditional_check (vm_instr_counter_t pos)
1220
1330
vm_idx_t id1, id2;
1221
1331
split_instr_counter (get_diff_from (pos), &id1, &id2);
1222
1332
1223
- op_meta jmp_op_meta = scopes_tree_op_meta (current_scope_p, pos);
1224
- JERRY_ASSERT (jmp_op_meta. op . op_idx == VM_OP_IS_FALSE_JMP_DOWN );
1333
+ op_meta jmp_op_meta = dumper_get_op_meta ( pos);
1334
+ dumper_assert_op_fields (REWRITE_CONDITIONAL_CHECK, jmp_op_meta );
1225
1335
1226
1336
jmp_op_meta.op .data .is_false_jmp_down .oc_idx_1 = id1;
1227
1337
jmp_op_meta.op .data .is_false_jmp_down .oc_idx_2 = id2;
@@ -1247,8 +1357,8 @@ rewrite_jump_to_end (vm_instr_counter_t pos)
1247
1357
vm_idx_t id1, id2;
1248
1358
split_instr_counter (get_diff_from (pos), &id1, &id2);
1249
1359
1250
- op_meta jmp_op_meta = scopes_tree_op_meta (current_scope_p, pos);
1251
- JERRY_ASSERT (jmp_op_meta. op . op_idx == VM_OP_JMP_DOWN );
1360
+ op_meta jmp_op_meta = dumper_get_op_meta ( pos);
1361
+ dumper_assert_op_fields (REWRITE_JUMP_TO_END, jmp_op_meta );
1252
1362
1253
1363
jmp_op_meta.op .data .jmp_down .oc_idx_1 = id1;
1254
1364
jmp_op_meta.op .data .jmp_down .oc_idx_2 = id2;
@@ -1342,7 +1452,7 @@ vm_instr_counter_t
1342
1452
rewrite_simple_or_nested_jump_and_get_next (vm_instr_counter_t jump_oc, /* *< position of jump to rewrite */
1343
1453
vm_instr_counter_t target_oc) /* *< the jump's target */
1344
1454
{
1345
- op_meta jump_op_meta = scopes_tree_op_meta (current_scope_p, jump_oc);
1455
+ op_meta jump_op_meta = dumper_get_op_meta ( jump_oc);
1346
1456
1347
1457
vm_op_t jmp_opcode = (vm_op_t ) jump_op_meta.op .op_idx ;
1348
1458
@@ -1399,7 +1509,7 @@ rewrite_simple_or_nested_jump_and_get_next (vm_instr_counter_t jump_oc, /**< pos
1399
1509
}
1400
1510
else
1401
1511
{
1402
- JERRY_ASSERT (jmp_opcode == VM_OP_JMP_BREAK_CONTINUE);
1512
+ JERRY_ASSERT (!is_generate_bytecode || ( jmp_opcode == VM_OP_JMP_BREAK_CONTINUE) );
1403
1513
1404
1514
id1_prev = jump_op_meta.op .data .jmp_break_continue .oc_idx_1 ;
1405
1515
id2_prev = jump_op_meta.op .data .jmp_break_continue .oc_idx_2 ;
@@ -1449,8 +1559,8 @@ rewrite_case_clause (vm_instr_counter_t jmp_oc)
1449
1559
vm_idx_t id1, id2;
1450
1560
split_instr_counter (get_diff_from (jmp_oc), &id1, &id2);
1451
1561
1452
- op_meta jmp_op_meta = scopes_tree_op_meta (current_scope_p, jmp_oc);
1453
- JERRY_ASSERT (jmp_op_meta. op . op_idx == VM_OP_IS_TRUE_JMP_DOWN );
1562
+ op_meta jmp_op_meta = dumper_get_op_meta ( jmp_oc);
1563
+ dumper_assert_op_fields (REWRITE_CASE_CLAUSE, jmp_op_meta );
1454
1564
1455
1565
jmp_op_meta.op .data .is_true_jmp_down .oc_idx_1 = id1;
1456
1566
jmp_op_meta.op .data .is_true_jmp_down .oc_idx_2 = id2;
@@ -1464,8 +1574,8 @@ rewrite_default_clause (vm_instr_counter_t jmp_oc)
1464
1574
vm_idx_t id1, id2;
1465
1575
split_instr_counter (get_diff_from (jmp_oc), &id1, &id2);
1466
1576
1467
- op_meta jmp_op_meta = scopes_tree_op_meta (current_scope_p, jmp_oc);
1468
- JERRY_ASSERT (jmp_op_meta. op . op_idx == VM_OP_JMP_DOWN );
1577
+ op_meta jmp_op_meta = dumper_get_op_meta ( jmp_oc);
1578
+ dumper_assert_op_fields (REWRITE_DEFAULT_CLAUSE, jmp_op_meta );
1469
1579
1470
1580
jmp_op_meta.op .data .jmp_down .oc_idx_1 = id1;
1471
1581
jmp_op_meta.op .data .jmp_down .oc_idx_2 = id2;
@@ -1510,7 +1620,7 @@ rewrite_with (vm_instr_counter_t oc) /**< instr counter of the instruction templ
1510
1620
vm_idx_t id1, id2;
1511
1621
split_instr_counter (get_diff_from (oc), &id1, &id2);
1512
1622
1513
- op_meta with_op_meta = scopes_tree_op_meta (current_scope_p, oc);
1623
+ op_meta with_op_meta = dumper_get_op_meta ( oc);
1514
1624
1515
1625
with_op_meta.op .data .with .oc_idx_1 = id1;
1516
1626
with_op_meta.op .data .with .oc_idx_2 = id2;
@@ -1562,7 +1672,7 @@ rewrite_for_in (vm_instr_counter_t oc) /**< instr counter of the instruction tem
1562
1672
vm_idx_t id1, id2;
1563
1673
split_instr_counter (get_diff_from (oc), &id1, &id2);
1564
1674
1565
- op_meta for_in_op_meta = scopes_tree_op_meta (current_scope_p, oc);
1675
+ op_meta for_in_op_meta = dumper_get_op_meta ( oc);
1566
1676
1567
1677
for_in_op_meta.op .data .for_in .oc_idx_1 = id1;
1568
1678
for_in_op_meta.op .data .for_in .oc_idx_2 = id2;
@@ -1600,8 +1710,8 @@ rewrite_try (vm_instr_counter_t pos)
1600
1710
vm_idx_t id1, id2;
1601
1711
split_instr_counter (get_diff_from (pos), &id1, &id2);
1602
1712
1603
- op_meta try_op_meta = scopes_tree_op_meta (current_scope_p, pos);
1604
- JERRY_ASSERT (try_op_meta. op . op_idx == VM_OP_TRY_BLOCK );
1713
+ op_meta try_op_meta = dumper_get_op_meta ( pos);
1714
+ dumper_assert_op_fields (REWRITE_TRY, try_op_meta );
1605
1715
1606
1716
try_op_meta.op .data .try_block .oc_idx_1 = id1;
1607
1717
try_op_meta.op .data .try_block .oc_idx_2 = id2;
@@ -1635,9 +1745,8 @@ rewrite_catch (vm_instr_counter_t pos)
1635
1745
vm_idx_t id1, id2;
1636
1746
split_instr_counter (get_diff_from (pos), &id1, &id2);
1637
1747
1638
- op_meta catch_op_meta = scopes_tree_op_meta (current_scope_p, pos);
1639
- JERRY_ASSERT (catch_op_meta.op .op_idx == VM_OP_META
1640
- && catch_op_meta.op .data .meta .type == OPCODE_META_TYPE_CATCH);
1748
+ op_meta catch_op_meta = dumper_get_op_meta (pos);
1749
+ dumper_assert_op_fields (REWRITE_CATCH, catch_op_meta);
1641
1750
1642
1751
catch_op_meta.op .data .meta .data_1 = id1;
1643
1752
catch_op_meta.op .data .meta .data_2 = id2;
@@ -1664,9 +1773,8 @@ rewrite_finally (vm_instr_counter_t pos)
1664
1773
vm_idx_t id1, id2;
1665
1774
split_instr_counter (get_diff_from (pos), &id1, &id2);
1666
1775
1667
- op_meta finally_op_meta = scopes_tree_op_meta (current_scope_p, pos);
1668
- JERRY_ASSERT (finally_op_meta.op .op_idx == VM_OP_META
1669
- && finally_op_meta.op .data .meta .type == OPCODE_META_TYPE_FINALLY);
1776
+ op_meta finally_op_meta = dumper_get_op_meta (pos);
1777
+ dumper_assert_op_fields (REWRITE_FINALLY, finally_op_meta);
1670
1778
1671
1779
finally_op_meta.op .data .meta .data_1 = id1;
1672
1780
finally_op_meta.op .data .meta .data_2 = id2;
@@ -1735,11 +1843,8 @@ rewrite_scope_code_flags (vm_instr_counter_t scope_code_flags_oc, /**< position
1735
1843
{
1736
1844
JERRY_ASSERT ((vm_idx_t ) scope_flags == scope_flags);
1737
1845
1738
- op_meta opm = scopes_tree_op_meta (current_scope_p, scope_code_flags_oc);
1739
- JERRY_ASSERT (opm.op .op_idx == VM_OP_META);
1740
- JERRY_ASSERT (opm.op .data .meta .type == OPCODE_META_TYPE_SCOPE_CODE_FLAGS);
1741
- JERRY_ASSERT (opm.op .data .meta .data_1 == VM_IDX_REWRITE_GENERAL_CASE);
1742
- JERRY_ASSERT (opm.op .data .meta .data_2 == VM_IDX_EMPTY);
1846
+ op_meta opm = dumper_get_op_meta (scope_code_flags_oc);
1847
+ dumper_assert_op_fields (REWRITE_SCOPE_CODE_FLAGS, opm);
1743
1848
1744
1849
opm.op .data .meta .data_1 = (vm_idx_t ) scope_flags;
1745
1850
dumper_rewrite_op_meta (scope_code_flags_oc, opm);
@@ -1775,8 +1880,8 @@ dump_reg_var_decl_for_rewrite (void)
1775
1880
void
1776
1881
rewrite_reg_var_decl (vm_instr_counter_t reg_var_decl_oc) /* *< position of dumped 'reg_var_decl' template */
1777
1882
{
1778
- op_meta opm = scopes_tree_op_meta (current_scope_p, reg_var_decl_oc);
1779
- JERRY_ASSERT (opm. op . op_idx == VM_OP_REG_VAR_DECL );
1883
+ op_meta opm = dumper_get_op_meta ( reg_var_decl_oc);
1884
+ dumper_assert_op_fields (REWRITE_REG_VAR_DECL, opm );
1780
1885
1781
1886
opm.op .data .reg_var_decl .tmp_regs_num = (vm_idx_t ) (jsp_reg_max_for_temps - VM_REG_GENERAL_FIRST + 1 );
1782
1887
0 commit comments