3 # Regenerate (overwriting only if changed):
7 # from information stored in
12 # Accepts the standard regen_lib -q and -v args.
14 # This script is normally invoked from regen.pl.
17 # Get function prototypes
18 require 'regen/regen_lib.pl';
22 open DESC, 'regcomp.sym';
25 my (@name,@rest,@type,@code,@args,@flags,@longj);
26 my ($desc,$lastregop);
30 chomp; # No \z in 5.004
37 ($name[$ind], $desc, $rest[$ind]) = /^(\S+)\s+([^\t]+?)\s*;\s*(.*)/;
38 ($type[$ind], $code[$ind], $args[$ind], $flags[$ind], $longj[$ind])
39 = split /[,\s]\s*/, $desc;
42 my ($type,@lists)=split /\s+/, $_;
43 die "No list? $type" if !@lists;
44 foreach my $list (@lists) {
45 my ($names,$special)=split /:/, $list , 2;
47 foreach my $name (split /,/,$names) {
48 my $real= $name eq 'resume'
54 } elsif ($special=~/\d/) {
55 @suffix=(1..$special);
56 } elsif ($special eq 'FAIL') {
59 die "unknown :type ':$special'";
61 foreach my $suffix (@suffix) {
62 $name[$ind]="$real$suffix";
64 $rest[$ind]="state for $type";
72 # use fixed width to keep the diffs between regcomp.pl recompiles
73 # as small as possible.
74 my ($width,$rwidth,$twidth)=(22,12,9);
78 die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!"
82 my ($flag, $varname, $comment) = @_;
83 $comment = '' unless defined $comment;
89 my $set = $flags[$ind] && $flags[$ind] eq $flag ? 1 : 0;
90 # Whilst I could do this with vec, I'd prefer to do longhand the arithmetic
95 substr $bitmap, ($ind >> 3);
98 substr($bitmap, ($ind >> 3), 1) = chr($current | ($set << ($ind & 7)));
100 push @selected, $name[$ind] if $set;
101 } while (++$ind < $lastregop);
102 my $out_string = join ', ', @selected, 0;
103 $out_string =~ s/(.{1,70},) /$1\n /g;
105 my $out_mask = join ', ', map {sprintf "0x%02X", ord $_} split '', $bitmap;
107 return $comment . <<"EOP";
108 #define REGNODE_\U$varname\E(node) (PL_${varname}_bitmask[(node) >> 3] & (1 << ((node) & 7)))
111 EXTCONST U8 PL_${varname}\[] __attribute__deprecated__;
113 EXTCONST U8 PL_${varname}\[] __attribute__deprecated__ = {
119 EXTCONST U8 PL_${varname}_bitmask[];
121 EXTCONST U8 PL_${varname}_bitmask[] = {
128 my $out = open_new('regnodes.h', '>',
129 { by => 'regen/regcomp.pl', from => 'regcomp.sym' });
131 /* Regops and State definitions */
137 -$width, REGNODE_MAX => $lastregop - 1,
138 -$width, REGMATCH_STATE_MAX => $tot - 1
142 for ($ind=0; $ind < $lastregop ; ++$ind) {
143 printf $out "#define\t%*s\t%d\t/* %#04x %s */\n",
144 -$width, $name[$ind], $ind, $ind, $rest[$ind];
146 print $out "\t/* ------------ States ------------- */\n";
147 for ( ; $ind < $tot ; $ind++) {
148 printf $out "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n",
149 -$width, $name[$ind], $ind - $lastregop + 1, $rest[$ind];
154 /* PL_regkind[] What type of regop or state is this. */
157 EXTCONST U8 PL_regkind[];
159 EXTCONST U8 PL_regkind[] = {
164 printf $out "\t%*s\t/* %*s */\n",
165 -1-$twidth, "$type[$ind],", -$width, $name[$ind];
166 print $out "\t/* ------------ States ------------- */\n"
167 if $ind + 1 == $lastregop and $lastregop != $tot;
168 } while (++$ind < $tot);
174 /* regarglen[] - How large is the argument part of the node (in regnodes) */
177 static const U8 regarglen[] = {
183 $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
185 printf $out "\t%*s\t/* %*s */\n",
186 -37, "$size,",-$rwidth,$name[$ind];
187 } while (++$ind < $lastregop);
192 /* reg_off_by_arg[] - Which argument holds the offset to the next node */
194 static const char reg_off_by_arg[] = {
199 my $size = $longj[$ind] || 0;
201 printf $out "\t%d,\t/* %*s */\n",
202 $size, -$rwidth, $name[$ind]
203 } while (++$ind < $lastregop);
208 #endif /* REG_COMP_C */
210 /* reg_name[] - Opcode/state names in string form, for debugging */
213 EXTCONST char * PL_reg_name[];
215 EXTCONST char * const PL_reg_name[] = {
222 my $size = $longj[$ind] || 0;
224 printf $out "\t%*s\t/* $sym%#04x */\n",
225 -3-$width,qq("$name[$ind]",), $ind - $ofs;
226 if ($ind + 1 == $lastregop and $lastregop != $tot) {
227 print $out "\t/* ------------ States ------------- */\n";
228 $ofs = $lastregop - 1;
229 $sym = 'REGNODE_MAX +';
232 } while (++$ind < $tot);
238 /* PL_reg_extflags_name[] - Opcode/state names in string form, for debugging */
241 EXTCONST char * PL_reg_extflags_name[];
243 EXTCONST char * const PL_reg_extflags_name[] = {
247 my %definitions; # Remember what the symbol definitions are
250 foreach my $file ("op_reg_common.h", "regexp.h") {
251 open FH,"<$file" or die "Can't read $file: $!";
254 # optional leading '_'. Return symbol in $1, and strip it from
256 if (s/ \#define \s+ ( _? RXf_ \w+ ) \s+ //xi) {
259 s: / \s* \* .*? \* \s* / : :x; # Replace comments by a blank
261 # Replace any prior defined symbols by their values
262 foreach my $key (keys %definitions) {
263 s/\b$key\b/$definitions{$key}/g;
266 # Remove the U suffix from unsigned int literals
267 s/\b([0-9]+)U\b/$1/g;
269 my $newval = eval $_; # Get numeric definition
271 $definitions{$define} = $newval;
273 next unless $_ =~ /<</; # Bit defines use left shift
275 die sprintf "Both $define and $reverse{$newval} use %08X", $newval;
278 $rxfv{$define}= $newval;
279 $reverse{$newval} = $define;
283 my %vrxf=reverse %rxfv;
284 printf $out "\t/* Bits in extflags defined: %s */\n", unpack 'B*', pack 'N', $val;
286 my $power_of_2 = 2**$_;
287 my $n=$vrxf{$power_of_2};
290 # Here, there was no name that matched exactly the bit. It could be
291 # either that it is unused, or the name matches multiple bits.
292 if (! ($val & $power_of_2)) {
293 $n = "UNUSED_BIT_$_";
297 # Here, must be because it matches multiple bits. Look through
298 # all possibilities until find one that matches this one. Use
299 # that name, and all the bits it matches
300 foreach my $name (keys %rxfv) {
301 if ($rxfv{$name} & $power_of_2) {
303 $power_of_2 = $rxfv{$name};
309 $n=~s/^RXf_(PMf_)?//;
310 printf $out qq(\t%-20s/* 0x%08x */\n),
311 qq("$n",),$power_of_2;
320 print $out process_flags('V', 'varies', <<'EOC');
321 /* The following have no fixed length. U8 so we can do strchr() on it. */
324 print $out process_flags('S', 'simple', <<'EOC');
326 /* The following always have a length of 1. U8 we can do strchr() on it. */
327 /* (Note that length 1 means "one character" under UTF8, not "one octet".) */
330 read_only_bottom_close_and_rename($out);