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_lib.pl';
20 #use Fatal qw(open close rename chmod unlink);
23 open DESC, 'regcomp.sym';
26 my (@name,@rest,@type,@code,@args,@flags,@longj);
27 my ($desc,$lastregop);
31 chomp; # No \z in 5.004
38 ($name[$ind], $desc, $rest[$ind]) = /^(\S+)\s+([^\t]+)\s*;\s*(.*)/;
39 ($type[$ind], $code[$ind], $args[$ind], $flags[$ind], $longj[$ind])
40 = split /[,\s]\s*/, $desc;
43 my ($type,@lists)=split /\s+/, $_;
44 die "No list? $type" if !@lists;
45 foreach my $list (@lists) {
46 my ($names,$special)=split /:/, $list , 2;
48 foreach my $name (split /,/,$names) {
49 my $real= $name eq 'resume'
55 } elsif ($special=~/\d/) {
56 @suffix=(1..$special);
57 } elsif ($special eq 'FAIL') {
60 die "unknown :type ':$special'";
62 foreach my $suffix (@suffix) {
63 $name[$ind]="$real$suffix";
65 $rest[$ind]="state for $type";
73 # use fixed width to keep the diffs between regcomp.pl recompiles
74 # as small as possible.
75 my ($width,$rwidth,$twidth)=(22,12,9);
79 die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!"
83 my ($flag, $varname, $comment) = @_;
84 $comment = '' unless defined $comment;
90 my $set = $flags[$ind] && $flags[$ind] eq $flag ? 1 : 0;
91 # Whilst I could do this with vec, I'd prefer to do longhand the arithmetic
96 substr $bitmap, ($ind >> 3);
99 substr($bitmap, ($ind >> 3), 1) = chr($current | ($set << ($ind & 7)));
101 push @selected, $name[$ind] if $set;
102 } while (++$ind < $lastregop);
103 my $out_string = join ', ', @selected, 0;
104 $out_string =~ s/(.{1,70},) /$1\n /g;
106 my $out_mask = join ', ', map {sprintf "0x%02X", ord $_} split '', $bitmap;
108 return $comment . <<"EOP";
109 #define REGNODE_\U$varname\E(node) (PL_${varname}_bitmask[(node) >> 3] & (1 << ((node) & 7)))
112 EXTCONST U8 PL_${varname}\[] __attribute__deprecated__;
114 EXTCONST U8 PL_${varname}\[] __attribute__deprecated__ = {
120 EXTCONST U8 PL_${varname}_bitmask[];
122 EXTCONST U8 PL_${varname}_bitmask[] = {
130 my $tmp_h = 'regnodes.h-new';
132 unlink $tmp_h if -f $tmp_h;
134 my $out = safer_open($tmp_h);
137 /* -*- buffer-read-only: t -*-
138 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
139 This file is built by regcomp.pl from regcomp.sym.
140 Any changes made here will be lost!
143 /* Regops and State definitions */
149 -$width, REGNODE_MAX => $lastregop - 1,
150 -$width, REGMATCH_STATE_MAX => $tot - 1
154 for ($ind=0; $ind < $lastregop ; ++$ind) {
155 printf $out "#define\t%*s\t%d\t/* %#04x %s */\n",
156 -$width, $name[$ind], $ind, $ind, $rest[$ind];
158 print $out "\t/* ------------ States ------------- */\n";
159 for ( ; $ind < $tot ; $ind++) {
160 printf $out "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n",
161 -$width, $name[$ind], $ind - $lastregop + 1, $rest[$ind];
166 /* PL_regkind[] What type of regop or state is this. */
169 EXTCONST U8 PL_regkind[];
171 EXTCONST U8 PL_regkind[] = {
176 printf $out "\t%*s\t/* %*s */\n",
177 -1-$twidth, "$type[$ind],", -$width, $name[$ind];
178 print $out "\t/* ------------ States ------------- */\n"
179 if $ind + 1 == $lastregop and $lastregop != $tot;
180 } while (++$ind < $tot);
186 /* regarglen[] - How large is the argument part of the node (in regnodes) */
189 static const U8 regarglen[] = {
195 $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind];
197 printf $out "\t%*s\t/* %*s */\n",
198 -37, "$size,",-$rwidth,$name[$ind];
199 } while (++$ind < $lastregop);
204 /* reg_off_by_arg[] - Which argument holds the offset to the next node */
206 static const char reg_off_by_arg[] = {
211 my $size = $longj[$ind] || 0;
213 printf $out "\t%d,\t/* %*s */\n",
214 $size, -$rwidth, $name[$ind]
215 } while (++$ind < $lastregop);
220 #endif /* REG_COMP_C */
222 /* reg_name[] - Opcode/state names in string form, for debugging */
225 EXTCONST char * PL_reg_name[];
227 EXTCONST char * const PL_reg_name[] = {
234 my $size = $longj[$ind] || 0;
236 printf $out "\t%*s\t/* $sym%#04x */\n",
237 -3-$width,qq("$name[$ind]",), $ind - $ofs;
238 if ($ind + 1 == $lastregop and $lastregop != $tot) {
239 print $out "\t/* ------------ States ------------- */\n";
240 $ofs = $lastregop - 1;
241 $sym = 'REGNODE_MAX +';
244 } while (++$ind < $tot);
250 /* PL_reg_extflags_name[] - Opcode/state names in string form, for debugging */
253 EXTCONST char * PL_reg_extflags_name[];
255 EXTCONST char * const PL_reg_extflags_name[] = {
259 my %definitions; # Remember what the symbol definitions are
262 foreach my $file ("op_reg_common.h", "regexp.h") {
263 open FH,"<$file" or die "Can't read $file: $!";
266 # optional leading '_'. Return symbol in $1, and strip it from
268 if (s/ \#define \s+ ( _? RXf_ \w+ ) \s+ //xi) {
271 s: / \s* \* .*? \* \s* / : :x; # Replace comments by a blank
273 # Replace any prior defined symbols by their values
274 foreach my $key (keys %definitions) {
275 s/\b$key\b/$definitions{$key}/g;
277 my $newval = eval $_; # Get numeric definition
279 $definitions{$define} = $newval;
281 next unless $_ =~ /<</; # Bit defines use left shift
283 die sprintf "Both $define and $reverse{$newval} use %08X", $newval;
286 $rxfv{$define}= $newval;
287 $reverse{$newval} = $define;
291 my %vrxf=reverse %rxfv;
292 printf $out "\t/* Bits in extflags defined: %s */\n", unpack 'B*', pack 'N', $val;
294 my $n=$vrxf{2**$_}||"UNUSED_BIT_$_";
295 $n=~s/^RXf_(PMf_)?//;
296 printf $out qq(\t%-20s/* 0x%08x */\n),
306 print $out process_flags('V', 'varies', <<'EOC');
307 /* The following have no fixed length. U8 so we can do strchr() on it. */
310 print $out process_flags('S', 'simple', <<'EOC');
311 /* The following always have a length of 1. U8 we can do strchr() on it. */
312 /* (Note that length 1 means "one character" under UTF8, not "one octet".) */
320 rename_if_different $tmp_h, 'regnodes.h';