This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / regcomp.pl
index 89bbbe0..239787a 100644 (file)
@@ -68,11 +68,9 @@ my $tmp_h = 'tmp_reg.h';
 
 unlink $tmp_h if -f $tmp_h;
 
-open OUT, ">$tmp_h";
-#*OUT=\*STDOUT;
-binmode OUT;
+my $out = safer_open($tmp_h);
 
-printf OUT <<EOP,
+printf $out <<EOP,
 /* -*- buffer-read-only: t -*-
    !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
    This file is built by regcomp.pl from regcomp.sym.
@@ -92,16 +90,16 @@ EOP
 
 for ($ind=1; $ind <= $lastregop ; $ind++) {
   my $oind = $ind - 1;
-  printf OUT "#define\t%*s\t%d\t/* %#04x %s */\n",
+  printf $out "#define\t%*s\t%d\t/* %#04x %s */\n",
     -$width, $name[$ind], $ind-1, $ind-1, $rest[$ind];
 }
-print OUT "\t/* ------------ States ------------- */\n";
+print $out "\t/* ------------ States ------------- */\n";
 for ( ; $ind <= $tot ; $ind++) {
-  printf OUT "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n",
+  printf $out "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n",
     -$width, $name[$ind], $ind - $lastregop, $rest[$ind];
 }
 
-print OUT <<EOP;
+print $out <<EOP;
 
 /* PL_regkind[] What type of regop or state is this. */
 
@@ -113,13 +111,13 @@ EOP
 
 $ind = 0;
 while (++$ind <= $tot) {
-  printf OUT "\t%*s\t/* %*s */\n",
+  printf $out "\t%*s\t/* %*s */\n",
              -1-$twidth, "$type[$ind],", -$width, $name[$ind];
-  print OUT "\t/* ------------ States ------------- */\n"
+  print $out "\t/* ------------ States ------------- */\n"
     if $ind == $lastregop and $lastregop != $tot;
 }
 
-print OUT <<EOP;
+print $out <<EOP;
 };
 #endif
 
@@ -134,11 +132,11 @@ while (++$ind <= $lastregop) {
   my $size = 0;
   $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
   
-  printf OUT "\t%*s\t/* %*s */\n",
+  printf $out "\t%*s\t/* %*s */\n",
        -37, "$size,",-$rwidth,$name[$ind];
 }
 
-print OUT <<EOP;
+print $out <<EOP;
 };
 
 /* reg_off_by_arg[] - Which argument holds the offset to the next node */
@@ -150,22 +148,21 @@ $ind = 0;
 while (++$ind <= $lastregop) {
   my $size = $longj[$ind] || 0;
 
-  printf OUT "\t%d,\t/* %*s */\n",
+  printf $out "\t%d,\t/* %*s */\n",
        $size, -$rwidth, $name[$ind]
 }
 
-print OUT <<EOP;
+print $out <<EOP;
 };
 
 #endif /* REG_COMP_C */
 
 /* reg_name[] - Opcode/state names in string form, for debugging */
 
-#ifdef DEBUGGING
-#  ifndef DOINIT
+#ifndef DOINIT
 EXTCONST char * PL_reg_name[];
-#  else
-EXTCONST char * PL_reg_name[] = {
+#else
+EXTCONST char * const PL_reg_name[] = {
 EOP
 
 $ind = 0;
@@ -174,24 +171,58 @@ my $sym = "";
 while (++$ind <= $tot) {
   my $size = $longj[$ind] || 0;
 
-  printf OUT "\t%*s\t/* $sym%#04x */\n",
+  printf $out "\t%*s\t/* $sym%#04x */\n",
        -3-$width,qq("$name[$ind]",), $ind - $ofs;
   if ($ind == $lastregop and $lastregop != $tot) {
-    print OUT "\t/* ------------ States ------------- */\n";
+    print $out "\t/* ------------ States ------------- */\n";
     $ofs = $lastregop;
     $sym = 'REGNODE_MAX +';
   }
     
 }
 
-print OUT <<EOP;
+print $out <<EOP;
 };
-#  endif /* DOINIT */
-#endif /* DEBUGGING */
+#endif /* DOINIT */
 
-/* ex: set ro: */
+/* PL_reg_extflags_name[] - Opcode/state names in string form, for debugging */
+
+#ifndef DOINIT
+EXTCONST char * PL_reg_extflags_name[];
+#else
+EXTCONST char * const PL_reg_extflags_name[] = {
 EOP
 
-close OUT or die "close $tmp_h: $!";
+open my $fh,"<","regexp.h" or die "Can't read regexp.h: $!";
+my %rxfv;
+my $val = 0;
+my %reverse;
+while (<$fh>) {
+    if (/#define\s+(RXf_\w+)\s+(0x[A-F\d]+)/i) {
+       my $newval = eval $2;
+       if($val & $newval) {
+           die sprintf "Both $1 and $reverse{$newval} use %08X", $newval;
+       }
+        $val|=$newval;
+        $rxfv{$1}= $newval;
+       $reverse{$newval} = $1;
+    }
+}    
+my %vrxf=reverse %rxfv;
+printf $out "\t/* Bits in extflags defined: %032b */\n",$val;
+for (0..31) {
+    my $n=$vrxf{2**$_}||"UNUSED_BIT_$_";
+    $n=~s/^RXf_(PMf_)?//;
+    printf $out qq(\t%-20s/* 0x%08x */\n), 
+        qq("$n",),2**$_;
+}  
+print $out <<EOP;
+};
+#endif /* DOINIT */
+
+/* ex: set ro: */
+EOP
+safer_close($out);
 
-safer_rename $tmp_h, 'regnodes.h';
+rename_if_different $tmp_h, 'regnodes.h';