From 6f9328ca348b95ff60b2672e0c425242e6e87419 Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Sun, 8 Jan 2023 14:16:36 +0100 Subject: 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. --- regen/regcomp.pl | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'regen') 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 <