summaryrefslogtreecommitdiff
path: root/regen
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2023-01-08 14:16:36 +0100
committerYves Orton <demerphq@gmail.com>2023-01-09 22:43:38 +0100
commit6f9328ca348b95ff60b2672e0c425242e6e87419 (patch)
tree03b62b9852452d8d1540fa105db610142ce85249 /regen
parent239136505f79898ae40cd38f706babe0f23f0993 (diff)
downloadperl-6f9328ca348b95ff60b2672e0c425242e6e87419.tar.gz
regcomp.pl - fixup intflags debug data to handle gaps properly
We were not handling gaps in the sequence properly, and effectively showing the wrong flag names or missing the last flag. Now we die if there are any collisions or if any of the PREGf defines set more than one bit. This also adds some crude tests to validate that intflags serialization is working properly. Note, extflags handles more complex scenarios and seems to handle this gracefully already, hence the reason I haven't touched it as well. This also tweaks a comment in lexical_debug.t which part of this was cribbed from.
Diffstat (limited to 'regen')
-rw-r--r--regen/regcomp.pl23
1 files changed, 19 insertions, 4 deletions
diff --git a/regen/regcomp.pl b/regen/regcomp.pl
index 4999cfa034..94a53dbbb6 100644
--- a/regen/regcomp.pl
+++ b/regen/regcomp.pl
@@ -726,8 +726,10 @@ EOP
my %reverse;
my $REG_INTFLAGS_NAME_SIZE= 0;
my $hp= HeaderParser->new();
+ my $last_val = 0;
foreach my $file ("regcomp.h") {
$hp->read_file($file);
+ my @bit_tuples;
foreach my $line_info (@{$hp->lines}) {
next unless $line_info->{type} eq "content"
and $line_info->{sub_type} eq "#define";
@@ -745,13 +747,26 @@ EOP
my $hex= $3;
my $comment= $4;
my $val= hex($hex);
+ my $bin= sprintf "%b", $val;
+ if ($bin=~/1.*?1/) { die "Not expecting multiple bits in PREGf" }
+ my $bit= length($bin) - 1 ;
$comment= $comment ? " - $comment" : "";
-
- printf $out qq(\t%-30s/* 0x%08x - %s%s */\n), qq("$abbr",),
- $val, $define, $comment;
- $REG_INTFLAGS_NAME_SIZE++;
+ if ($bit_tuples[$bit]) {
+ die "Duplicate PREGf bit '$bit': $define $val ($hex)";
+ }
+ $bit_tuples[$bit]= [ $bit, $val, $abbr, $define, $comment ];
+ }
+ }
+ foreach my $i (0..$#bit_tuples) {
+ my $bit_tuple= $bit_tuples[$i];
+ if (!$bit_tuple) {
+ $bit_tuple= [ $i, 1<<$i, "", "", "*UNUSED*" ];
}
+ my ($bit, $val, $abbr, $define, $comment)= @$bit_tuple;
+ printf $out qq(\t%-30s/* (1<<%2d) - 0x%08x - %s%s */\n),
+ qq("$abbr",), $bit, $val, $define, $comment;
}
+ $REG_INTFLAGS_NAME_SIZE=0+@bit_tuples;
}
print $out <<EOP;