3 # Regenerate (overwriting only if changed):
8 # from information stored in
13 # pod/perldebguts.pod is not completely regenerated. Only the table of
14 # regexp nodes is replaced; other parts remain unchanged.
16 # Accepts the standard regen_lib -q and -v args.
18 # This script is normally invoked from regen.pl.
21 # Get function prototypes
22 require 'regen/regen_lib.pl';
26 open DESC, 'regcomp.sym';
29 my (@name,@rest,@type,@code,@args,@flags,@longj,@cmnt);
30 my ($longest_name_length,$desc,$lastregop) = 0;
32 # Special pod comments
33 if (/^#\* ?/) { $cmnt[$ind] .= "# $'"; }
34 # Truly blank lines possibly surrounding pod comments
35 elsif (/^\s*$/) { $cmnt[$ind] .= "\n" }
37 next if /^(?:#|\s*$)/;
38 chomp; # No \z in 5.004
45 ($name[$ind], $desc, $rest[$ind]) = /^(\S+)\s+([^\t]+?)\s*;\s*(.*)/;
46 ($type[$ind], $code[$ind], $args[$ind], $flags[$ind], $longj[$ind])
47 = split /[,\s]\s*/, $desc;
48 $longest_name_length = length $name[$ind]
49 if length $name[$ind] > $longest_name_length;
52 my ($type,@lists)=split /\s+/, $_;
53 die "No list? $type" if !@lists;
54 foreach my $list (@lists) {
55 my ($names,$special)=split /:/, $list , 2;
57 foreach my $name (split /,/,$names) {
58 my $real= $name eq 'resume'
64 } elsif ($special=~/\d/) {
65 @suffix=(1..$special);
66 } elsif ($special eq 'FAIL') {
69 die "unknown :type ':$special'";
71 foreach my $suffix (@suffix) {
72 $name[$ind]="$real$suffix";
74 $rest[$ind]="state for $type";
82 # use fixed width to keep the diffs between regcomp.pl recompiles
83 # as small as possible.
84 my ($width,$rwidth,$twidth)=(22,12,9);
88 die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!"
92 my ($flag, $varname, $comment) = @_;
93 $comment = '' unless defined $comment;
99 my $set = $flags[$ind] && $flags[$ind] eq $flag ? 1 : 0;
100 # Whilst I could do this with vec, I'd prefer to do longhand the arithmetic
105 substr $bitmap, ($ind >> 3);
108 substr($bitmap, ($ind >> 3), 1) = chr($current | ($set << ($ind & 7)));
110 push @selected, $name[$ind] if $set;
111 } while (++$ind < $lastregop);
112 my $out_string = join ', ', @selected, 0;
113 $out_string =~ s/(.{1,70},) /$1\n /g;
115 my $out_mask = join ', ', map {sprintf "0x%02X", ord $_} split '', $bitmap;
117 return $comment . <<"EOP";
118 #define REGNODE_\U$varname\E(node) (PL_${varname}_bitmask[(node) >> 3] & (1 << ((node) & 7)))
121 EXTCONST U8 PL_${varname}\[] __attribute__deprecated__;
123 EXTCONST U8 PL_${varname}\[] __attribute__deprecated__ = {
129 EXTCONST U8 PL_${varname}_bitmask[];
131 EXTCONST U8 PL_${varname}_bitmask[] = {
138 my $out = open_new('regnodes.h', '>',
139 { by => 'regen/regcomp.pl', from => 'regcomp.sym' });
141 /* Regops and State definitions */
147 -$width, REGNODE_MAX => $lastregop - 1,
148 -$width, REGMATCH_STATE_MAX => $tot - 1
152 for ($ind=0; $ind < $lastregop ; ++$ind) {
153 printf $out "#define\t%*s\t%d\t/* %#04x %s */\n",
154 -$width, $name[$ind], $ind, $ind, $rest[$ind];
156 print $out "\t/* ------------ States ------------- */\n";
157 for ( ; $ind < $tot ; $ind++) {
158 printf $out "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n",
159 -$width, $name[$ind], $ind - $lastregop + 1, $rest[$ind];
164 /* PL_regkind[] What type of regop or state is this. */
167 EXTCONST U8 PL_regkind[];
169 EXTCONST U8 PL_regkind[] = {
174 printf $out "\t%*s\t/* %*s */\n",
175 -1-$twidth, "$type[$ind],", -$width, $name[$ind];
176 print $out "\t/* ------------ States ------------- */\n"
177 if $ind + 1 == $lastregop and $lastregop != $tot;
178 } while (++$ind < $tot);
184 /* regarglen[] - How large is the argument part of the node (in regnodes) */
187 static const U8 regarglen[] = {
193 $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
195 printf $out "\t%*s\t/* %*s */\n",
196 -37, "$size,",-$rwidth,$name[$ind];
197 } while (++$ind < $lastregop);
202 /* reg_off_by_arg[] - Which argument holds the offset to the next node */
204 static const char reg_off_by_arg[] = {
209 my $size = $longj[$ind] || 0;
211 printf $out "\t%d,\t/* %*s */\n",
212 $size, -$rwidth, $name[$ind]
213 } while (++$ind < $lastregop);
218 #endif /* REG_COMP_C */
220 /* reg_name[] - Opcode/state names in string form, for debugging */
223 EXTCONST char * PL_reg_name[];
225 EXTCONST char * const PL_reg_name[] = {
232 my $size = $longj[$ind] || 0;
234 printf $out "\t%*s\t/* $sym%#04x */\n",
235 -3-$width,qq("$name[$ind]",), $ind - $ofs;
236 if ($ind + 1 == $lastregop and $lastregop != $tot) {
237 print $out "\t/* ------------ States ------------- */\n";
238 $ofs = $lastregop - 1;
239 $sym = 'REGNODE_MAX +';
242 } while (++$ind < $tot);
252 /* PL_reg_extflags_name[] - Opcode/state names in string form, for debugging */
255 EXTCONST char * PL_reg_extflags_name[];
257 EXTCONST char * const PL_reg_extflags_name[] = {
261 my %definitions; # Remember what the symbol definitions are
264 foreach my $file ("op_reg_common.h", "regexp.h") {
265 open FH,"<$file" or die "Can't read $file: $!";
268 # optional leading '_'. Return symbol in $1, and strip it from
270 if (s/^ \# \s* define \s+ ( _? RXf_ \w+ ) \s+ //xi) {
274 s{ /\* .*? \*/ }{ }x; # Replace comments by a blank
276 # Replace any prior defined symbols by their values
277 foreach my $key (keys %definitions) {
278 s/\b$key\b/$definitions{$key}/g;
281 # Remove the U suffix from unsigned int literals
282 s/\b([0-9]+)U\b/$1/g;
284 my $newval = eval $_; # Get numeric definition
286 $definitions{$define} = $newval;
288 next unless $_ =~ /<</; # Bit defines use left shift
290 my @names=($define, $reverse{$newval});
292 if ($names[0] ne $names[1]) {
293 die sprintf "ERROR: both $define and $reverse{$newval} use 0x%08X (%s:%s)", $newval, $orig, $_;
298 $rxfv{$define}= $newval;
299 $reverse{$newval} = $define;
303 my %vrxf=reverse %rxfv;
304 printf $out "\t/* Bits in extflags defined: %s */\n", unpack 'B*', pack 'N', $val;
307 my $power_of_2 = 2**$_;
308 my $n=$vrxf{$power_of_2};
312 # Here, there was no name that matched exactly the bit. It could be
313 # either that it is unused, or the name matches multiple bits.
314 if (! ($val & $power_of_2)) {
315 $n = "UNUSED_BIT_$_";
319 # Here, must be because it matches multiple bits. Look through
320 # all possibilities until find one that matches this one. Use
321 # that name, and all the bits it matches
322 foreach my $name (keys %rxfv) {
323 if ($rxfv{$name} & $power_of_2) {
324 $n = $name . ( $multibits{$name}++ );
325 $extra= sprintf qq{ : "%s" - 0x%08x}, $name, $rxfv{$name}
326 if $power_of_2 != $rxfv{$name};
332 s/\bRXf_(PMf_)?// for $n, $extra;
333 printf $out qq(\t%-20s/* 0x%08x%s */\n),
334 qq("$n",),$power_of_2, $extra;
345 /* PL_reg_intflags_name[] - Opcode/state names in string form, for debugging */
348 EXTCONST char * PL_reg_intflags_name[];
350 EXTCONST char * const PL_reg_intflags_name[] = {
354 my %definitions; # Remember what the symbol definitions are
357 foreach my $file ("regcomp.h") {
358 open my $fh, "<", $file or die "Can't read $file: $!";
360 # optional leading '_'. Return symbol in $1, and strip it from
362 if (m/^ \# \s* define \s+ ( PREGf_ ( \w+ ) ) \s+ 0x([0-9a-f]+)(?:\s*\/\*(.*)\*\/)?/xi) {
369 $comment= $comment ? " - $comment" : "";
371 printf $out qq(\t%-30s/* 0x%08x - %s%s */\n), qq("$abbr",), $val, $define, $comment;
384 print $out process_flags('V', 'varies', <<'EOC');
385 /* The following have no fixed length. U8 so we can do strchr() on it. */
388 print $out process_flags('S', 'simple', <<'EOC');
390 /* The following always have a length of 1. U8 we can do strchr() on it. */
391 /* (Note that length 1 means "one character" under UTF8, not "one octet".) */
394 read_only_bottom_close_and_rename($out);
396 my $guts = open_new('pod/perldebguts.pod', '>');
399 my $name_fmt = '<' x ($longest_name_length-1);
400 my $descr_fmt = '<' x (58-$longest_name_length);
405 ^$name_fmt ^<<<<<<<<< ^$descr_fmt~~
406 \$name[\$_], \$code, \$rest[\$_]
410 select +(select($guts), do {
413 open my $oldguts, "pod/perldebguts.pod"
414 or die "$0 cannot open pod/perldebguts.pod for reading: $!";
417 last if /=for regcomp.pl begin/;
422 # TYPE arg-description [num-args] [longjump-len] DESCRIPTION
424 for (0..$lastregop-1) {
425 $code = "$code[$_] ".($args[$_]||"");
426 $code .= " $longj[$_]" if $longj[$_];
427 if ($cmnt[$_] ||= "") {
428 # Trim multiple blanks
429 $cmnt[$_] =~ s/^\n\n+/\n/; $cmnt[$_] =~ s/\n\n+$/\n\n/
436 last if /=for regcomp.pl end/;
438 do { print } while <$oldguts>;
442 close_and_rename($guts);