This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.pl: Add capability for fields to be > 1 bit
authorKarl Williamson <public@khwilliamson.com>
Sun, 26 Dec 2010 17:30:40 +0000 (10:30 -0700)
committerKarl Williamson <public@khwilliamson.com>
Sun, 16 Jan 2011 23:36:43 +0000 (16:36 -0700)
Currently, it doesn't generate a good dump structure if a field has more
than one bit.

regen/regcomp.pl

index 41cbc6e..2a1fb03 100644 (file)
@@ -291,10 +291,32 @@ foreach my $file ("op_reg_common.h", "regexp.h") {
 my %vrxf=reverse %rxfv;
 printf $out "\t/* Bits in extflags defined: %s */\n", unpack 'B*', pack 'N', $val;
 for (0..31) {
-    my $n=$vrxf{2**$_}||"UNUSED_BIT_$_";
+    my $power_of_2 = 2**$_;
+    my $n=$vrxf{$power_of_2};
+    if (! $n) {
+
+        # Here, there was no name that matched exactly the bit.  It could be
+        # either that it is unused, or the name matches multiple bits.
+        if (! ($val & $power_of_2)) {
+            $n = "UNUSED_BIT_$_";
+        }
+        else {
+
+            # Here, must be because it matches multiple bits.  Look through
+            # all possibilities until find one that matches this one.  Use
+            # that name, and all the bits it matches
+            foreach my $name (keys %rxfv) {
+                if ($rxfv{$name} & $power_of_2) {
+                    $n = $name;
+                    $power_of_2 = $rxfv{$name};
+                    last;
+                }
+            }
+        }
+    }
     $n=~s/^RXf_(PMf_)?//;
     printf $out qq(\t%-20s/* 0x%08x */\n), 
-        qq("$n",),2**$_;
+        qq("$n",),$power_of_2;
 }  
  
 print $out <<EOP;