This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Nit disabling dtrace on VMS (2 single quotes inside double quotes
[perl5.git] / regcomp.pl
index ed270e8..defbb5f 100644 (file)
@@ -48,19 +48,16 @@ while (<DESC>) {
                     $ind++;
                     $name[$ind]="$real$suffix";
                     $type[$ind]=$type;
-                    $rest[$ind]="Regmatch state for $type";
+                    $rest[$ind]="state for $type";
                 }
             }
         }
         
     }
 }
-my ($width,$rwidth,$twidth)=(0,0,0);
-for (1..@name) {
-    $width=length($name[$_]) if $name[$_] and $width<length($name[$_]);
-    $twidth=length($type[$_]) if $type[$_] and $twidth<length($type[$_]);
-    $rwidth=$width if $_ == $lastregop;
-}
+# use fixed width to keep the diffs between regcomp.pl recompiles
+# as small as possible.
+my ($width,$rwidth,$twidth)=(22,12,9);
 $lastregop ||= $ind;
 my $tot = $ind;
 close DESC;
@@ -82,6 +79,8 @@ printf OUT <<EOP,
    Any changes made here will be lost!
 */
 
+/* Regops and State definitions */
+
 #define %*s\t%d
 #define %*s\t%d
 
@@ -90,17 +89,21 @@ EOP
     -$width, REGMATCH_STATE_MAX => $tot - 1
 ;
 
-$ind = 0;
-while (++$ind <= $tot) {
+
+for ($ind=1; $ind <= $lastregop ; $ind++) {
   my $oind = $ind - 1;
   printf OUT "#define\t%*s\t%d\t/* %#04x %s */\n",
     -$width, $name[$ind], $ind-1, $ind-1, $rest[$ind];
-  print OUT "\n\t/* ------------ States ------------- */\n\n"
-    if $ind == $lastregop and $lastregop != $tot;
+}
+print OUT "\t/* ------------ States ------------- */\n";
+for ( ; $ind <= $tot ; $ind++) {
+  printf OUT "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n",
+    -$width, $name[$ind], $ind - $lastregop, $rest[$ind];
 }
 
 print OUT <<EOP;
 
+/* PL_regkind[] What type of regop or state is this. */
 
 #ifndef DOINIT
 EXTCONST U8 PL_regkind[];
@@ -120,6 +123,7 @@ print OUT <<EOP;
 };
 #endif
 
+/* regarglen[] - How large is the argument part of the node (in regnodes) */
 
 #ifdef REG_COMP_C
 static const U8 regarglen[] = {
@@ -137,6 +141,8 @@ while (++$ind <= $lastregop) {
 print OUT <<EOP;
 };
 
+/* reg_off_by_arg[] - Which argument holds the offset to the next node */
+
 static const char reg_off_by_arg[] = {
 EOP
 
@@ -151,32 +157,74 @@ while (++$ind <= $lastregop) {
 print OUT <<EOP;
 };
 
-#ifdef DEBUGGING
-const char * reg_name[] = {
+#endif /* REG_COMP_C */
+
+/* reg_name[] - Opcode/state names in string form, for debugging */
+
+#ifndef DOINIT
+EXTCONST char * PL_reg_name[];
+#else
+EXTCONST char * const PL_reg_name[] = {
 EOP
 
 $ind = 0;
+my $ofs = 1;
+my $sym = "";
 while (++$ind <= $tot) {
   my $size = $longj[$ind] || 0;
 
-  printf OUT "\t%*s\t/* %#04x */\n",
-       -3-$width,qq("$name[$ind]",),$ind-1;
-  print OUT "\t/* ------------ States ------------- */\n"
-    if $ind == $lastregop and $lastregop != $tot;
+  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";
+    $ofs = $lastregop;
+    $sym = 'REGNODE_MAX +';
+  }
+    
 }
 
 print OUT <<EOP;
 };
-#endif /* DEBUGGING */
+#endif /* DOINIT */
+
+/* PL_reg_extflags_name[] - Opcode/state names in string form, for debugging */
+
+#ifndef DOINIT
+EXTCONST char * PL_reg_extflags_name[];
 #else
-#ifdef DEBUGGING
-extern const char * reg_name[];
-#endif
-#endif /* REG_COMP_C */
+EXTCONST char * const PL_reg_extflags_name[] = {
+EOP
+
+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
-
 close OUT or die "close $tmp_h: $!";
 
 safer_rename $tmp_h, 'regnodes.h';