Skip to content

Commit f0f2330

Browse files
committed
Revert "Refactor opcode.pl - use c99 array initialization (using op enum)"
This reverts commit ab28d72.
1 parent da6dccc commit f0f2330

File tree

1 file changed

+11
-45
lines changed

1 file changed

+11
-45
lines changed

regen/opcode.pl

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737

3838
sub generate_b_op_private_pm;
3939

40-
sub op_enum;
41-
4240
my $restrict_to_core = "if defined(PERL_CORE) || defined(PERL_EXT)";
4341

4442
BEGIN {
@@ -780,7 +778,7 @@ sub print_PL_op_private_tables {
780778
else {
781779
$index = -1;
782780
}
783-
$PL_op_private_bitdef_ix .= sprintf "\t${\ ::op_index ($op) } = %4d, /* %s */\n", $index, $op;
781+
$PL_op_private_bitdef_ix .= sprintf " %4d, /* %s */\n", $index, $op;
784782
}
785783
if (%not_seen) {
786784
die "panic: unprocessed ops: ". join(',', keys %not_seen);
@@ -818,7 +816,7 @@ sub print_PL_op_private_tables {
818816
# all bets are off
819817
@flags = '0xff' if $op eq 'null' or $op eq 'custom';
820818

821-
$PL_op_private_valid .= sprintf "\t${\ ::op_index ($op) } = /* %-10s */ (%s),\n", uc($op),
819+
$PL_op_private_valid .= sprintf " /* %-10s */ (%s),\n", uc($op),
822820
@flags ? join('|', @flags): '0';
823821
}
824822

@@ -1003,34 +1001,6 @@ sub gen_op_is_macro {
10031001
}
10041002
}
10051003

1006-
sub align {
1007-
my ($length, $str) = @_;
1008-
1009-
$str .= (' ' x ($length - length $str));
1010-
}
1011-
1012-
sub op_max_length () {
1013-
state $max = do {
1014-
my ($max) = sort { $b <=> $a } map { length op_enum $_ } @ops;
1015-
$max;
1016-
};
1017-
}
1018-
1019-
sub op_enum {
1020-
my ($op) = @_;
1021-
1022-
"OP_\U$op";
1023-
}
1024-
1025-
sub op_index {
1026-
state $align_at = do {
1027-
my $max = op_max_length + 2;
1028-
$max;
1029-
};
1030-
1031-
align $align_at, "[${\ op_enum $_[0] }]";
1032-
}
1033-
10341004
sub generate_opcode_h {
10351005
my $oc = open_new( 'opcode.h', '>', {
10361006
by => 'regen/opcode.pl',
@@ -1110,11 +1080,11 @@ sub generate_opcode_h_opnames {
11101080
END
11111081

11121082
for (@ops) {
1113-
print qq(\t${\ op_index $_ } = "$_",\n);
1083+
print qq(\t"$_",\n);
11141084
}
11151085

11161086
print <<~'END';
1117-
[OP_max] = "freed",
1087+
"freed",
11181088
});
11191089
11201090
EXTCONST char* const PL_op_desc[] INIT({
@@ -1126,11 +1096,11 @@ sub generate_opcode_h_opnames {
11261096
# Have to escape double quotes and escape characters.
11271097
$safe_desc =~ s/([\\"])/\\$1/g;
11281098

1129-
print qq(\t${\ op_index $_ } = "$safe_desc",\n);
1099+
print qq(\t"$safe_desc",\n);
11301100
}
11311101

11321102
print <<~'END';
1133-
[OP_max] = "freed op",
1103+
"freed op",
11341104
});
11351105
11361106
END_EXTERN_C
@@ -1144,12 +1114,8 @@ sub generate_opcode_h_pl_check {
11441114
INIT({
11451115
END
11461116

1147-
my ($max) = sort { $b cmp $a } map { length "Perl_$check{$_}" } @ops;
1148-
1149-
my $align = $max + 2; # comma and space
1150-
11511117
for (@ops) {
1152-
print "\t", op_index ($_), " = ", align ($align, "Perl_$check{$_},"), "/* $_ */\n";
1118+
print "\t", tab(3, "Perl_$check{$_},"), "\t/* $_ */\n";
11531119
}
11541120

11551121
print <<~'END';
@@ -1204,7 +1170,7 @@ sub generate_opcode_h_pl_opargs {
12041170
$argshift += 4;
12051171
}
12061172
$argsum = sprintf("0x%08x", $argsum);
1207-
print "\t", op_index ($op), " = $argsum,", " /* $op */\n";
1173+
print "\t", tab(3, "$argsum,"), "/* $op */\n";
12081174
}
12091175

12101176
print <<~'END';
@@ -1229,9 +1195,9 @@ sub generate_opcode_h_pl_ppaddr {
12291195
my $op_func = "Perl_pp_$_";
12301196
my $name = $alias{$_};
12311197
if ($name && $name->[0] ne $op_func) {
1232-
print "\t${\ op_index $_ } = $op_func,\t/* implemented by $name->[0] */\n";
1198+
print "\t$op_func,\t/* implemented by $name->[0] */\n";
12331199
} else {
1234-
print "\t${\ op_index $_ } = $op_func,\n";
1200+
print "\t$op_func,\n";
12351201
}
12361202
}
12371203

@@ -1263,7 +1229,7 @@ sub generate_opnames_h_opcode_enum {
12631229

12641230
my $i = 0;
12651231
for (@ops) {
1266-
print "\t", tab(3,op_enum ($_)), " = ", $i++, ",\n";
1232+
print "\t", tab(3,"OP_\U$_"), " = ", $i++, ",\n";
12671233
}
12681234

12691235
print "\t", tab(3,"OP_max"), "\n";

0 commit comments

Comments
 (0)